public AvatarArchive LoadAvatarArchive (string fileName, UUID principalID)
{
AvatarArchive archive = new AvatarArchive ();
UserAccount account = userAccountService.GetUserAccount (null, principalID);
if (account == null) {
MainConsole.Instance.Error ("[Avatar Archiver]: User not found!");
return null;
}
// need to be smart here...
fileName = PathHelpers.VerifyReadFile (fileName, ".aa", m_storeDirectory);
if (!File.Exists (fileName)) {
MainConsole.Instance.Error ("[Avatar Archiver]: Unable to load from file: file does not exist!");
return null;
}
MainConsole.Instance.Info ("[Avatar Archiver]: Loading archive from " + fileName);
archive.FromOSD ((OSDMap)OSDParser.DeserializeLLSDXml (File.ReadAllText (fileName)));
AvatarAppearance appearance = ConvertXMLToAvatarAppearance (archive.BodyMap);
appearance.Owner = principalID;
InventoryFolderBase AppearanceFolder = inventoryService.GetFolderForType (account.PrincipalID,
InventoryType.Wearable,
FolderType.Clothing);
if (AppearanceFolder == null) {
AppearanceFolder = new InventoryFolderBase (); // does not exist so...
AppearanceFolder.Owner = account.PrincipalID;
AppearanceFolder.ID = UUID.Random ();
AppearanceFolder.Type = (short)FolderType.Clothing;
}
List<InventoryItemBase> items;
InventoryFolderBase folderForAppearance
= new InventoryFolderBase (
UUID.Random (), archive.FolderName, account.PrincipalID,
(short)FolderType.None, AppearanceFolder.ID, 1);
inventoryService.AddFolder (folderForAppearance);
folderForAppearance = inventoryService.GetFolder (folderForAppearance);
try {
LoadAssets (archive.AssetsMap);
appearance = CopyWearablesAndAttachments (account.PrincipalID, UUID.Zero, appearance, folderForAppearance,
account.PrincipalID, archive.ItemsMap, out items);
} catch (Exception ex) {
MainConsole.Instance.Warn ("[AvatarArchiver]: Error loading assets and items, " + ex);
}
/* implement fully if we need to
// inform the client if needed
ScenePresence SP;
MainConsole.Instance.ConsoleScenes[0].TryGetScenePresence(account.PrincipalID, out SP);
if (SP == null)
return; // nobody home!
SP.ControllingClient.SendAlertMessage("Appearance loading in progress...");
SP.ControllingClient.SendBulkUpdateInventory(folderForAppearance);
*/
MainConsole.Instance.Info ("[Avatar Archiver]: Loaded archive from " + fileName);
archive.Appearance = appearance;
return archive;
}