* move command line parsing code from inventory archive modules to opensim server

* use default inventory archive name if none is given
* other minor cleanups
* this facility is not useable yet
0.6.0-stable
Justin Clarke Casey 2008-10-19 17:51:42 +00:00
parent ed8a20dd60
commit f7205da1d9
3 changed files with 44 additions and 29 deletions

View File

@ -686,7 +686,7 @@ namespace OpenSim
#endregion
/// <summary>
/// Save inventory to a file.
/// Save inventory to a file archive
/// </summary>
/// <param name="cmdparams"></param>
protected void SaveInv(string[] cmdparams)
@ -697,11 +697,19 @@ namespace OpenSim
m_log.Error("[CONSOLE]: usage is save-inv <first name> <last name> <inventory path> [<save file path>]");
return;
}
new InventoryArchiveWriteRequest(m_sceneManager.CurrentOrFirstScene,m_commsManager).execute(cmdparams);
string firstName = cmdparams[0];
string lastName = cmdparams[1];
string invPath = cmdparams[2];
string savePath = (cmdparams.Length > 3 ? cmdparams[3] : DEFAULT_INV_BACKUP_FILENAME);
new InventoryArchiveWriteRequest(
m_sceneManager.CurrentOrFirstScene,m_commsManager).execute(
firstName, lastName, invPath, savePath);
}
/// <summary>
/// Load inventory from a tar.gz file.
/// Load inventory from an inventory file archive
/// </summary>
/// <param name="cmdparams"></param>
protected void LoadInv(string[] cmdparams)
@ -712,7 +720,15 @@ namespace OpenSim
m_log.Error("[CONSOLE]: usage is load-inv <first name> <last name> <inventory path> [<load file path>]");
return;
}
new InventoryArchiveReadRequest(m_sceneManager.CurrentOrFirstScene, m_commsManager).execute(cmdparams);
string firstName = cmdparams[0];
string lastName = cmdparams[1];
string invPath = cmdparams[2];
string loadPath = (cmdparams.Length > 3 ? cmdparams[3] : DEFAULT_INV_BACKUP_FILENAME);
new InventoryArchiveReadRequest(
m_sceneManager.CurrentOrFirstScene, m_commsManager).execute(
firstName, lastName, invPath, loadPath);
}
/// <summary>

View File

@ -45,14 +45,15 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Inventory.Archiver
{
public class InventoryArchiveReadRequest
{
private static ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
protected Scene scene;
protected TarArchiveReader archive;
private static System.Text.ASCIIEncoding m_asciiEncoding = new System.Text.ASCIIEncoding();
ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
CachedUserInfo userInfo;
UserProfileData userProfile;
CommunicationsManager commsManager;
string loadPath;
public InventoryArchiveReadRequest(Scene currentScene, CommunicationsManager commsManager)
{
@ -142,22 +143,17 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Inventory.Archiver
return item;
}
public void execute(string[] cmdparams)
public void execute(string firstName, string lastName, string invPath, string loadPath)
{
string filePath = "ERROR";
int successfulAssetRestores = 0;
int failedAssetRestores = 0;
string firstName = cmdparams[0];
string lastName = cmdparams[1];
//string invPath = cmdparams[2];
loadPath = (cmdparams.Length > 3 ? cmdparams[3] : "inventory.tar.gz");
int successfulItemRestores = 0;
archive
= new TarArchiveReader(new GZipStream(
new FileStream(loadPath, FileMode.Open), CompressionMode.Decompress));
userProfile = commsManager.UserService.GetUserProfile(firstName, lastName);
userInfo = commsManager.UserProfileCacheService.GetUserDetails(userProfile.ID);
@ -175,13 +171,18 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Inventory.Archiver
{
//Load the item
InventoryItemBase item = loadInvItem(filePath, m_asciiEncoding.GetString(data));
if (item != null) userInfo.AddItem(item);
if (item != null)
{
userInfo.AddItem(item);
successfulItemRestores++;
}
}
}
archive.Close();
m_log.InfoFormat("[ARCHIVER]: Restored {0} assets", successfulAssetRestores);
m_log.DebugFormat("[ARCHIVER]: Restored {0} assets", successfulAssetRestores);
m_log.InfoFormat("[ARCHIVER]: Restored {0} items", successfulItemRestores);
}
/// <summary>

View File

@ -41,15 +41,20 @@ using log4net;
namespace OpenSim.Region.Environment.Modules.Avatar.Inventory.Archiver
{
{
public class InventoryArchiveWriteRequest
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
protected Scene scene;
protected TarArchiveWriter archive;
protected CommunicationsManager commsManager;
Dictionary<UUID, int> assetUuids;
string savePath;
/// <value>
/// The path to which the inventory archive will be saved.
/// </value>
private string m_savePath;
public InventoryArchiveWriteRequest(Scene currentScene, CommunicationsManager commsManager)
{
@ -63,7 +68,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Inventory.Archiver
{
AssetsArchiver assetsArchiver = new AssetsArchiver(assetsFound);
assetsArchiver.Archive(archive);
archive.WriteTar(new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress));
archive.WriteTar(new GZipStream(new FileStream(m_savePath, FileMode.Create), CompressionMode.Compress));
}
protected void saveInvItem(InventoryItemBase inventoryItem, string path)
@ -156,15 +161,10 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Inventory.Archiver
}
}
public void execute(string[] cmdparams)
public void execute(string firstName, string lastName, string invPath, string savePath)
{
ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
string firstName = cmdparams[0];
string lastName = cmdparams[1];
string invPath = cmdparams[2];
savePath = (cmdparams.Length > 3 ? cmdparams[3] : "inventory.tar.gz");
m_savePath = savePath;
UserProfileData userProfile = commsManager.UserService.GetUserProfile(firstName, lastName);
if (null == userProfile)
{
@ -242,8 +242,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Inventory.Archiver
}
new AssetsRequest(assetUuids.Keys, scene.AssetCache, ReceivedAllAssets).Execute();
}
}
}