* Refactor: break out loading of archive paths into inventory into a separate method

0.6.5-rc1
Justin Clarke Casey 2009-04-24 19:10:13 +00:00
parent 35c7aae455
commit eeb1908bce
1 changed files with 139 additions and 110 deletions

View File

@ -144,10 +144,68 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
}
else if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH))
{
string fsPath = filePath.Substring(ArchiveConstants.INVENTORY_PATH.Length);
InventoryFolderImpl foundFolder
= ReplicateArchivePathToUserInventory(
filePath, TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType,
rootDestinationFolder, foldersCreated, nodesLoaded);
if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType)
{
InventoryItemBase item = UserInventoryItemSerializer.Deserialize(data);
// Don't use the item ID that's in the file
item.ID = UUID.Random();
item.CreatorId = m_userInfo.UserProfile.ID.ToString();
item.Owner = m_userInfo.UserProfile.ID;
// Reset folder ID to the one in which we want to load it
item.Folder = foundFolder.ID;
m_userInfo.AddItem(item);
successfulItemRestores++;
// If we're loading an item directly into the given destination folder then we need to record
// it separately from any loaded root folders
if (rootDestinationFolder == foundFolder)
nodesLoaded.Add(item);
}
}
}
archive.Close();
m_log.DebugFormat("[INVENTORY ARCHIVER]: Restored {0} assets", successfulAssetRestores);
m_log.InfoFormat("[INVENTORY ARCHIVER]: Restored {0} items", successfulItemRestores);
return nodesLoaded;
}
/// <summary>
/// Replicate the inventory paths in the archive to the user's inventory as necessary.
/// </summary>
/// <param name="fsPath"></param>
/// <param name="isDir">Is the path we're dealing with a directory?</param>
/// <param name="rootDestinationFolder">The root folder for the inventory load</param>
/// <param name="foldersCreated">
/// The folders created so far. This method will add more folders if necessary
/// </param>
/// <param name="nodesLoaded">
/// Track the inventory nodes created. This is distinct from the folders created since for a particular folder
/// chain, only the root node needs to be recorded
/// </param>
/// <returns>The last user inventory folder created or found for the archive path</returns>
public InventoryFolderImpl ReplicateArchivePathToUserInventory(
string fsPath,
bool isDir,
InventoryFolderImpl rootDestinationFolder,
Dictionary <string, InventoryFolderImpl> foldersCreated,
List<InventoryNodeBase> nodesLoaded)
{
fsPath = fsPath.Substring(ArchiveConstants.INVENTORY_PATH.Length);
// Remove the file portion if we aren't already dealing with a directory path
if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType)
if (!isDir)
fsPath = fsPath.Remove(fsPath.LastIndexOf("/") + 1);
string originalFsPath = fsPath;
@ -221,6 +279,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
i++;
}
return foundFolder;
/*
string[] rawFolders = filePath.Split(new char[] { '/' });
@ -254,37 +314,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
foundFolder = foundFolder.GetChildFolder(newFolderId);
}
*/
if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType)
{
InventoryItemBase item = UserInventoryItemSerializer.Deserialize(data);
// Don't use the item ID that's in the file
item.ID = UUID.Random();
item.CreatorId = m_userInfo.UserProfile.ID.ToString();
item.Owner = m_userInfo.UserProfile.ID;
// Reset folder ID to the one in which we want to load it
item.Folder = foundFolder.ID;
m_userInfo.AddItem(item);
successfulItemRestores++;
// If we're loading an item directly into the given destination folder then we need to record
// it separately from any loaded root folders
if (rootDestinationFolder == foundFolder)
nodesLoaded.Add(item);
}
}
}
archive.Close();
m_log.DebugFormat("[INVENTORY ARCHIVER]: Restored {0} assets", successfulAssetRestores);
m_log.InfoFormat("[INVENTORY ARCHIVER]: Restored {0} items", successfulItemRestores);
return nodesLoaded;
}
/// <summary>