Get "save oar" and "save iar" to tell you in a more friendly manner if the filename to save already exists, rather than exception throwing.

Also changes ConsoleUtil.CheckFileExists to CheckFileDoesNotExist() since this is more meaningful in the context, even though it does result in double negatives.
integration
Justin Clark-Casey (justincc) 2012-10-24 03:08:58 +01:00
parent 73db057fa1
commit f76dceb90b
6 changed files with 41 additions and 11 deletions

View File

@ -27,6 +27,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using log4net;
@ -60,6 +61,24 @@ namespace OpenSim.Framework.Console
public const string VectorSeparator = ",";
public static char[] VectorSeparatorChars = VectorSeparator.ToCharArray();
/// <summary>
/// Check if the given file path exists.
/// </summary>
/// <remarks>If not, warning is printed to the given console.</remarks>
/// <returns>true if the file does not exist, false otherwise.</returns>
/// <param name='console'></param>
/// <param name='path'></param>
public static bool CheckFileDoesNotExist(ICommandConsole console, string path)
{
if (File.Exists(path))
{
console.OutputFormat("File {0} already exists. Please move or remove it.", path);
return false;
}
return true;
}
/// <summary>
/// Try to parse a console UUID from the console.

View File

@ -35,6 +35,7 @@ using Nini.Config;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Framework.Communications;
using OpenSim.Framework.Console;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces;
@ -209,6 +210,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
Guid id, string firstName, string lastName, string invPath, string pass, string savePath,
Dictionary<string, object> options)
{
if (!ConsoleUtil.CheckFileDoesNotExist(MainConsole.Instance, savePath))
return false;
if (m_scenes.Count > 0)
{
UserAccount userInfo = GetUserInfo(firstName, lastName, pass);

View File

@ -32,6 +32,8 @@ using System.Reflection;
using log4net;
using NDesk.Options;
using Nini.Config;
using OpenSim.Framework;
using OpenSim.Framework.Console;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
@ -117,7 +119,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
//
// foreach (string param in mainParams)
// m_log.DebugFormat("GOT PARAM [{0}]", param);
if (mainParams.Count > 2)
{
DearchiveRegion(mainParams[2], mergeOar, skipAssets, Guid.Empty);
@ -150,14 +152,16 @@ namespace OpenSim.Region.CoreModules.World.Archiver
List<string> mainParams = ops.Parse(cmdparams);
string path;
if (mainParams.Count > 2)
{
ArchiveRegion(mainParams[2], options);
}
path = mainParams[2];
else
{
ArchiveRegion(DEFAULT_OAR_BACKUP_FILENAME, options);
}
path = DEFAULT_OAR_BACKUP_FILENAME;
if (!ConsoleUtil.CheckFileDoesNotExist(MainConsole.Instance, path))
return;
ArchiveRegion(path, options);
}
public void ArchiveRegion(string savePath, Dictionary<string, object> options)

View File

@ -485,11 +485,8 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
string fileName = string.Format("{0}.xml", objectUuid);
if (File.Exists(fileName))
{
m_console.OutputFormat("File {0} already exists. Please move or remove it.", fileName);
if (!ConsoleUtil.CheckFileDoesNotExist(m_console, fileName))
return;
}
using (XmlTextWriter xtw = new XmlTextWriter(fileName, Encoding.UTF8))
{

View File

@ -127,6 +127,9 @@ namespace OpenSim.Region.OptionalModules.Asset
}
string fileName = rawAssetId;
if (!ConsoleUtil.CheckFileDoesNotExist(MainConsole.Instance, fileName))
return;
using (FileStream fs = new FileStream(fileName, FileMode.CreateNew))
{

View File

@ -141,6 +141,9 @@ namespace OpenSim.Server.Handlers.Asset
}
string fileName = rawAssetId;
if (!ConsoleUtil.CheckFileDoesNotExist(MainConsole.Instance, fileName))
return;
using (FileStream fs = new FileStream(fileName, FileMode.CreateNew))
{