FromOSD() public method

public FromOSD ( OSDMap map ) : void
map OSDMap
return void
        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;
        }
        public AvatarArchive LoadAvatarArchive(string fileName, UUID principalID)
        {
            AvatarArchive archive = new AvatarArchive();
            UserAccount account = userAccountService.GetUserAccount(null, principalID);
            if (account == null)
            {
                MainConsole.Instance.Error("[AvatarArchive]: User not found!");
                return null;
            }

            // need to be smart here...
            fileName = PathHelpers.VerifyReadFile (fileName, ".aa", m_storeDirectory);
            if (!File.Exists(fileName))
            {
                MainConsole.Instance.Error("[AvatarArchive]: Unable to load from file: file does not exist!");
                return null;
            }
            MainConsole.Instance.Info("[AvatarArchive]: 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,
                                                                                     AssetType.Clothing);

            if (AppearanceFolder == null)
            {
                AppearanceFolder = new InventoryFolderBase (); // does not exist so...
                AppearanceFolder.Owner = account.PrincipalID;
                AppearanceFolder.ID = UUID.Random ();
                AppearanceFolder.Type = (short) InventoryType.Wearable;
            }

            List<InventoryItemBase> items;

            InventoryFolderBase folderForAppearance
                = new InventoryFolderBase(
                    UUID.Random(), archive.FolderName, account.PrincipalID,
                    -1, 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);
            }

            MainConsole.Instance.Info("[AvatarArchive]: Loaded archive from " + fileName);
            archive.Appearance = appearance;
            return archive;
        }
        /// <summary>
        /// Gets all public avatar archives
        /// </summary>
        /// <returns></returns>
        public List<AvatarArchive> GetAvatarArchives ()
        {
            var archives = new List<AvatarArchive> ();

            if (Directory.Exists (m_storeDirectory)) {
                foreach (string file in Directory.GetFiles (m_storeDirectory, "*.aa")) {
                    try {
                        AvatarArchive archive = new AvatarArchive ();
                        archive.FromOSD ((OSDMap)OSDParser.DeserializeLLSDXml (File.ReadAllText (file)));
                        if (archive.IsPublic) {
                            //check for a local snapshot
                            var localPic = Path.ChangeExtension (file, "jpg");
                            if (File.Exists (localPic))
                                archive.LocalSnapshot = localPic;
                            else
                                archive.LocalSnapshot = string.Empty;

                            archives.Add (archive);
                        }
                    } catch {
                        MainConsole.Instance.ErrorFormat ("[Avatar Archiver]: error deserializing {0} archive", file);
                    }
                }
            }

            return archives;
        }
        /// <summary>
        /// Gets all public avatar archives
        /// </summary>
        /// <returns></returns>
        public List<AvatarArchive> GetAvatarArchives()
        {
            var archives = new List<AvatarArchive>();

            if (Directory.Exists(m_storeDirectory))
            {
                foreach (string file in Directory.GetFiles(m_storeDirectory, "*.aa"))
                {
                    try
                    {
                        AvatarArchive archive = new AvatarArchive();
                        archive.FromOSD((OSDMap)OSDParser.DeserializeLLSDXml(File.ReadAllText(file)));
                        if (archive.IsPublic)
                            archives.Add(archive);
                    }
                    catch
                    {
                    }
                }
            }

            return archives;
        }