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); } 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); List <InventoryItemBase> items = new List <InventoryItemBase>(); 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> /// Create a set of folders for the given path. /// </summary> /// <param name="destFolder"> /// The root folder from which the creation will take place. /// </param> /// <param name="iarPathExisting"> /// the part of the iar path that already exists /// </param> /// <param name="iarPathToReplicate"> /// The path to replicate in the user's inventory from iar /// </param> /// <param name="resolvedFolders"> /// The folders that we have resolved so far for a given archive path. /// </param> /// <param name="loadedNodes"> /// Track the inventory nodes created. /// </param> private void CreateFoldersForPath( InventoryFolderBase destFolder, string iarPathExisting, string iarPathToReplicate, Dictionary <string, InventoryFolderBase> resolvedFolders, HashSet <InventoryNodeBase> loadedNodes) { string[] rawDirsToCreate = iarPathToReplicate.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < rawDirsToCreate.Length; i++) { // m_log.DebugFormat("[INVENTORY ARCHIVER]: Creating folder {0} from IAR", rawDirsToCreate[i]); if (!rawDirsToCreate[i].Contains(ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR)) { continue; } int identicalNameIdentifierIndex = rawDirsToCreate[i].LastIndexOf( ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR); UUID oldFolderId = UUID.Zero; string newFolderName = rawDirsToCreate[i].Remove(identicalNameIdentifierIndex); newFolderName = InventoryArchiveUtils.UnescapeArchivePath(newFolderName); UUID newFolderId = UUID.Random(); if (UUID.TryParse(rawDirsToCreate[i].Substring(identicalNameIdentifierIndex + 2), out oldFolderId)) { m_MapIarFolders[oldFolderId] = newFolderId; } // Asset type has to be Unknown here rather than Folder, otherwise the created folder can't be // deleted once the client has relogged. // The root folder appears to be labelled AssetType.Folder (shows up as "Category" in the client) // even though there is a AssetType.RootCategory destFolder = new InventoryFolderBase( newFolderId, newFolderName, m_userInfo.PrincipalID, (short)AssetType.Unknown, destFolder.ID, 1); m_InventoryService.AddFolder(destFolder); // Record that we have now created this folder iarPathExisting += rawDirsToCreate[i] + "/"; m_log.DebugFormat("[INVENTORY ARCHIVER]: Created folder {0} from IAR", iarPathExisting); resolvedFolders[iarPathExisting] = destFolder; if (0 == i) { loadedNodes.Add(destFolder); } } }
/// <summary> /// Create a folder in this agent's inventory. /// </summary> /// /// If the inventory service has not yet delievered the inventory /// for this user then the request will be queued. /// /// <param name="parentID"></param> /// <returns></returns> public bool CreateFolder(string folderName, UUID folderID, ushort folderType, UUID parentID) { // m_log.DebugFormat( // "[AGENT INVENTORY]: Creating inventory folder {0} {1} for {2} {3}", folderID, folderName, remoteClient.Name, remoteClient.AgentId); if (m_hasReceivedInventory) { InventoryFolderImpl parentFolder = RootFolder.FindFolder(parentID); if (null == parentFolder) { m_log.WarnFormat( "[AGENT INVENTORY]: Tried to create folder {0} {1} but the parent {2} does not exist", folderName, folderID, parentID); return(false); } InventoryFolderImpl createdFolder = parentFolder.CreateChildFolder(folderID, folderName, folderType); if (createdFolder != null) { InventoryFolderBase createdBaseFolder = new InventoryFolderBase(); createdBaseFolder.Owner = createdFolder.Owner; createdBaseFolder.ID = createdFolder.ID; createdBaseFolder.Name = createdFolder.Name; createdBaseFolder.ParentID = createdFolder.ParentID; createdBaseFolder.Type = createdFolder.Type; createdBaseFolder.Version = createdFolder.Version; m_InventoryService.AddFolder(createdBaseFolder); return(true); } else { m_log.WarnFormat( "[AGENT INVENTORY]: Tried to create folder {0} {1} but the folder already exists", folderName, folderID); return(false); } } else { AddRequest( new InventoryRequest( Delegate.CreateDelegate(typeof(CreateFolderDelegate), this, "CreateFolder"), new object[] { folderName, folderID, folderType, parentID })); return(true); } }
byte[] HandleAddFolder(Dictionary <string, object> request) { InventoryFolderBase folder = BuildFolder(request); if (m_InventoryService.AddFolder(folder)) { return(SuccessResult()); } else { return(FailureResult()); } }
/// <summary> /// Read a library inventory folder from a loaded configuration /// </summary> /// <param name="source"></param> private void ReadFolderFromConfig(IConfig config, string path) { InventoryFolderImpl folderInfo = new InventoryFolderImpl(); folderInfo.ID = new UUID(config.GetString("folderID", UUID.Random().ToString())); folderInfo.Name = config.GetString("name", "unknown"); folderInfo.ParentID = new UUID(config.GetString("parentFolderID", UUID.Zero.ToString())); folderInfo.Type = (short)config.GetInt("type", 8); folderInfo.Owner = m_service.LibraryOwner; folderInfo.Version = 1; m_inventoryService.AddFolder(folderInfo); }
public bool AddFolder(InventoryFolderBase folder) { if (folder == null) return false; //m_log.Debug("[HG INVENTORY CONNECTOR]: AddFolder " + folder.ID); string invURL = GetInventoryServiceURL(folder.Owner); if (invURL == null) // not there, forward to local inventory connector to resolve return m_LocalGridInventoryService.AddFolder(folder); IInventoryService connector = GetConnector(invURL); return connector.AddFolder(folder); }
/// <summary> /// Create inventory folders starting from a given parent folder /// </summary> /// <remarks> /// If any stem of the path names folders that already exist then these are not recreated. This includes the /// final folder. /// TODO: May need to make it an option to create duplicate folders. /// </remarks> /// <param name="inventoryService"></param> /// <param name="folderId">ID of the folder to create</param> /// <param name="parentFolder"></param> /// <param name="path"> /// The folder to create. /// </param> /// <param name="useExistingFolders"> /// If true, then folders in the path which already the same name are /// used. This applies to the terminal folder as well. /// If false, then all folders in the path are created, even if there is already a folder at a particular /// level with the same name. /// </param> /// <returns> /// The folder created. If the path contains multiple folders then the last one created is returned. /// </returns> public static InventoryFolderBase CreateInventoryFolder( IInventoryService inventoryService, UUID folderId, InventoryFolderBase parentFolder, string path, bool useExistingFolders) { string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None); InventoryFolderBase folder = null; if (useExistingFolders) { folder = InventoryArchiveUtils.FindFolderByPath(inventoryService, parentFolder, components[0]); } if (folder == null) { // Console.WriteLine("Creating folder {0} at {1}", components[0], parentFolder.Name); UUID folderIdForCreate; if (components.Length > 1) { folderIdForCreate = UUID.Random(); } else { folderIdForCreate = folderId; } folder = new InventoryFolderBase( folderIdForCreate, components[0], parentFolder.Owner, (short)AssetType.Unknown, parentFolder.ID, 0); inventoryService.AddFolder(folder); } // else // { // Console.WriteLine("Found existing folder {0}", folder.Name); // } if (components.Length > 1) { return(CreateInventoryFolder(inventoryService, folderId, folder, components[1], useExistingFolders)); } else { return(folder); } }
public bool AddFolder(InventoryFolderBase folder) { if (folder == null) { return(false); } if (IsLocalGridUser(folder.Owner)) { return(m_GridService.AddFolder(folder)); } else { UUID sessionID = GetSessionID(folder.Owner); string uri = GetUserInventoryURI(folder.Owner) + "/" + folder.Owner.ToString(); return(m_HGService.AddFolder(uri, folder, sessionID)); } }
/// <summary> /// Create a set of folders for the given path. /// </summary> /// <param name="destFolder"> /// The root folder from which the creation will take place. /// </param> /// <param name="iarPathExisting"> /// the part of the iar path that already exists /// </param> /// <param name="iarPathToReplicate"> /// The path to replicate in the user's inventory from iar /// </param> /// <param name="resolvedFolders"> /// The folders that we have resolved so far for a given archive path. /// </param> /// <param name="loadedNodes"> /// Track the inventory nodes created. /// </param> protected void CreateFoldersForPath( InventoryFolderBase destFolder, string iarPathExisting, string iarPathToReplicate, Dictionary <string, InventoryFolderBase> resolvedFolders, Dictionary <UUID, InventoryNodeBase> loadedNodes) { string[] rawDirsToCreate = iarPathToReplicate.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < rawDirsToCreate.Length; i++) { // m_log.DebugFormat("[INVENTORY ARCHIVER]: Creating folder {0} from IAR", rawDirsToCreate[i]); if (!rawDirsToCreate[i].Contains(ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR)) { continue; } int identicalNameIdentifierIndex = rawDirsToCreate[i].LastIndexOf( ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR); string newFolderName = rawDirsToCreate[i].Remove(identicalNameIdentifierIndex); newFolderName = InventoryArchiveUtils.UnescapeArchivePath(newFolderName); UUID newFolderId = UUID.Random(); destFolder = new InventoryFolderBase( newFolderId, newFolderName, m_userInfo.PrincipalID, (short)FolderType.None, destFolder.ID, 1); m_InventoryService.AddFolder(destFolder); // Record that we have now created this folder iarPathExisting += rawDirsToCreate[i] + "/"; m_log.DebugFormat("[INVENTORY ARCHIVER]: Created folder {0} from IAR", iarPathExisting); resolvedFolders[iarPathExisting] = destFolder; if (0 == i) { loadedNodes[destFolder.ID] = destFolder; } } }
/// <summary> /// Create inventory folders starting from a given parent folder /// </summary> /// /// Ignores any existing folders with the same name /// /// <param name="inventoryService"></param> /// <param name="parentFolder"></param> /// <param name="path"> /// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER /// </param> /// <returns> /// The folder created. If the path contains multiple folders then the last one created is returned. /// </returns> public static InventoryFolderBase CreateInventoryFolder( IInventoryService inventoryService, InventoryFolderBase parentFolder, string path) { string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None); InventoryFolderBase newFolder = new InventoryFolderBase(UUID.Random(), components[0], parentFolder.Owner, parentFolder.ID); inventoryService.AddFolder(newFolder); if (components.Length > 1) { return(CreateInventoryFolder(inventoryService, newFolder, components[1])); } else { return(newFolder); } }
public UUID MoveInventory(Scene scene, UUID destID, string fname, SceneObjectPart host, List <UUID> items) { InventoryFolderBase BaseFolder = new InventoryFolderBase(); List <InventoryFolderBase> m_invbase = new List <InventoryFolderBase>(); inventoryService = scene.InventoryService; m_invbase = inventoryService.GetInventorySkeleton(destID); foreach (InventoryFolderBase current in m_invbase) { if (current.Name.ToString() == "Objects") { BaseFolder = current; } } UUID newFolderID = UUID.Random(); InventoryFolderBase newFolder = new InventoryFolderBase(newFolderID, fname, destID, -1, BaseFolder.ID, BaseFolder.Version); inventoryService.AddFolder(newFolder); foreach (UUID itemID in items) { InventoryItemBase agentItem = CreateAgentInventoryItemFromTask(scene, destID, host, itemID); if (agentItem != null) { agentItem.Folder = newFolderID; scene.AddInventoryItem(agentItem); } } ScenePresence avatar = null; if (scene.TryGetScenePresence(destID, out avatar)) { scene.SendInventoryUpdate(avatar.ControllingClient, BaseFolder, true, false); scene.SendInventoryUpdate(avatar.ControllingClient, newFolder, false, true); } return(newFolderID); }
/// <summary> /// Add a new folder to the user's inventory /// </summary> /// <param name="folder"></param> /// <returns>true if the folder was successfully added</returns> public bool AddFolder(InventoryFolderBase folder) { return(m_InventoryService.AddFolder(folder)); }
public AvatarAppearance LoadAvatarArchive(string FileName, string Name) { UserAccount account = UserAccountService.GetUserAccount(null, Name); MainConsole.Instance.Info("[AvatarArchive] Loading archive from " + FileName); if (account == null) { MainConsole.Instance.Error("[AvatarArchive] User not found!"); return(null); } string archiveXML = ""; if (FileName.EndsWith(".database")) { IAvatarArchiverConnector archiver = DataManager.DataManager.RequestPlugin <IAvatarArchiverConnector>(); if (archiver != null) { AvatarArchive archive = archiver.GetAvatarArchive(FileName.Substring(0, FileName.LastIndexOf(".database"))); archiveXML = archive.ArchiveXML; } else { MainConsole.Instance.Error("[AvatarArchive] Unable to load from database!"); return(null); } } else { StreamReader reader = new StreamReader(FileName); archiveXML = reader.ReadToEnd(); reader.Close(); reader.Dispose(); } IScenePresence SP = null; ISceneManager manager = m_registry.RequestModuleInterface <ISceneManager>(); if (manager != null) { foreach (IScene scene in manager.GetAllScenes()) { if (scene.TryGetScenePresence(account.PrincipalID, out SP)) { break; } } if (SP == null) { return(null); //Bad people! } } if (SP != null) { SP.ControllingClient.SendAlertMessage("Appearance loading in progress..."); } string FolderNameToLoadInto = ""; OSDMap map = ((OSDMap)OSDParser.DeserializeLLSDXml(archiveXML)); OSDMap assetsMap = ((OSDMap)map["Assets"]); //OSDMap itemsMap = ((OSDMap)map["Items"]); OSDMap bodyMap = ((OSDMap)map["Body"]); AvatarAppearance appearance = ConvertXMLToAvatarAppearance(bodyMap, out FolderNameToLoadInto); appearance.Owner = account.PrincipalID; InventoryFolderBase AppearanceFolder = InventoryService.GetFolderForType(account.PrincipalID, InventoryType.Wearable, AssetType.Clothing); List <InventoryItemBase> items = new List <InventoryItemBase>(); InventoryFolderBase folderForAppearance = new InventoryFolderBase( UUID.Random(), FolderNameToLoadInto, account.PrincipalID, -1, AppearanceFolder.ID, 1); InventoryService.AddFolder(folderForAppearance); folderForAppearance = InventoryService.GetFolder(folderForAppearance); try { LoadAssets(assetsMap); appearance = CopyWearablesAndAttachments(account.PrincipalID, UUID.Zero, appearance, folderForAppearance, account.PrincipalID, out items); } catch (Exception ex) { MainConsole.Instance.Warn("[AvatarArchiver]: Error loading assets and items, " + ex); } //Now update the client about the new items if (SP != null) { SP.ControllingClient.SendBulkUpdateInventory(folderForAppearance); } MainConsole.Instance.Info("[AvatarArchive] Loaded archive from " + FileName); return(appearance); }
public AvatarAppearance LoadAvatarArchive(string FileName, string Name) { UserAccount account = UserAccountService.GetUserAccount(UUID.Zero, Name); MainConsole.Instance.Info("[AvatarArchive] Loading archive from " + FileName); if (account == null) { MainConsole.Instance.Error("[AvatarArchive] User not found!"); return(null); } StreamReader reader = new StreamReader(FileName); string file = reader.ReadToEnd(); reader.Close(); reader.Dispose(); IScenePresence SP = null; SceneManager manager = m_registry.RequestModuleInterface <SceneManager>(); if (manager != null) { foreach (IScene scene in manager.Scenes) { if (scene.TryGetScenePresence(account.PrincipalID, out SP)) { break; } } if (SP == null) { return(null); //Bad people! } } if (SP != null) { SP.ControllingClient.SendAlertMessage("Appearance loading in progress..."); } string FolderNameToLoadInto = ""; OSDMap map = ((OSDMap)OSDParser.DeserializeLLSDXml(file)); OSDMap assetsMap = ((OSDMap)map["Assets"]); OSDMap itemsMap = ((OSDMap)map["Items"]); OSDMap bodyMap = ((OSDMap)map["Body"]); AvatarAppearance appearance = ConvertXMLToAvatarAppearance(bodyMap, out FolderNameToLoadInto); appearance.Owner = account.PrincipalID; List <InventoryItemBase> items = new List <InventoryItemBase>(); InventoryFolderBase AppearanceFolder = InventoryService.GetFolderForType(account.PrincipalID, InventoryType.Wearable, AssetType.Clothing); InventoryFolderBase folderForAppearance = new InventoryFolderBase( UUID.Random(), FolderNameToLoadInto, account.PrincipalID, -1, AppearanceFolder.ID, 1); InventoryService.AddFolder(folderForAppearance); folderForAppearance = InventoryService.GetFolder(folderForAppearance); try { LoadAssets(assetsMap); appearance = CopyWearablesAndAttachments(account.PrincipalID, UUID.Zero, appearance, folderForAppearance); } catch (Exception ex) { MainConsole.Instance.Warn("[AvatarArchiver]: Error loading assets and items, " + ex); } //Now update the client about the new items if (SP != null) { SP.ControllingClient.SendBulkUpdateInventory(folderForAppearance); foreach (InventoryItemBase itemCopy in items) { if (itemCopy == null) { SP.ControllingClient.SendAgentAlertMessage("Can't find item to give. Nothing given.", false); continue; } if (!SP.IsChildAgent) { SP.ControllingClient.SendBulkUpdateInventory(itemCopy); } } } MainConsole.Instance.Info("[AvatarArchive] Loaded archive from " + FileName); return(appearance); }
/// <summary> /// Create inventory folders starting from a given parent folder /// </summary> /// <remarks> /// If any stem of the path names folders that already exist then these are not recreated. This includes the /// final folder. /// TODO: May need to make it an option to create duplicate folders. /// </remarks> /// <param name="inventoryService"></param> /// <param name="parentFolder"></param> /// <param name="path"> /// The folder to create. /// </param> /// <param name="useExistingFolders"> /// If true, then folders in the path which already the same name are /// used. This applies to the terminal folder as well. /// If false, then all folders in the path are created, even if there is already a folder at a particular /// level with the same name. /// </param> /// <returns> /// The folder created. If the path contains multiple folders then the last one created is returned. /// </returns> public static InventoryFolderBase CreateInventoryFolder( IInventoryService inventoryService, InventoryFolderBase parentFolder, string path, bool useExistingFolders) { string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None); InventoryFolderBase folder = null; if (useExistingFolders) folder = InventoryArchiveUtils.FindFolderByPath(inventoryService, parentFolder, components[0]); if (folder == null) { // Console.WriteLine("Creating folder {0} at {1}", components[0], parentFolder.Name); folder = new InventoryFolderBase( UUID.Random(), components[0], parentFolder.Owner, (short)AssetType.Unknown, parentFolder.ID, 0); inventoryService.AddFolder(folder); } // else // { // Console.WriteLine("Found existing folder {0}", folder.Name); // } if (components.Length > 1) return CreateInventoryFolder(inventoryService, folder, components[1], useExistingFolders); else return folder; }
/// <summary> /// Execute the request /// </summary> /// <returns> /// A list of the inventory nodes loaded. If folders were loaded then only the root folders are /// returned /// </returns> public HashSet <InventoryNodeBase> Execute(bool loadAll) { if (m_loadStream == null) { return(new HashSet <InventoryNodeBase> ()); } string filePath = "ERROR"; int successfulAssetRestores = 0; int failedAssetRestores = 0; int successfulItemRestores = 0; HashSet <InventoryNodeBase> loadedNodes = loadAll ? new HashSet <InventoryNodeBase> () : null; try { List <InventoryFolderBase> folderCandidates = InventoryArchiveUtils.FindFolderByPath(m_inventoryService, m_userInfo.PrincipalID, m_invPath); if (folderCandidates.Count == 0) { // try and create requested folder var rootFolder = m_inventoryService.GetRootFolder(m_userInfo.PrincipalID); if (rootFolder == null) { if (m_inventoryService.CreateUserInventory(m_userInfo.PrincipalID, true)) { rootFolder = m_inventoryService.GetRootFolder(m_userInfo.PrincipalID); } else { MainConsole.Instance.Error("[Inventory Archiver]: Unable to create Inventory root folder"); return(loadedNodes); // major bummer } } InventoryFolderBase iarImportFolder = new InventoryFolderBase(); iarImportFolder.ID = UUID.Random(); iarImportFolder.Name = m_invPath; // the path iarImportFolder.Owner = m_userInfo.PrincipalID; // owner iarImportFolder.ParentID = rootFolder.ID; // the root folder iarImportFolder.Type = (short)FolderType.None; // user defined folder iarImportFolder.Version = 1; // initial version m_inventoryService.AddFolder(iarImportFolder); // ensure that it now exists... folderCandidates = InventoryArchiveUtils.FindFolderByPath(m_inventoryService, m_userInfo.PrincipalID, m_invPath); if (folderCandidates.Count == 0) { MainConsole.Instance.ErrorFormat("[Inventory Archiver]: Unable to create Inventory path {0}", m_invPath); return(loadedNodes); } } // we have the base folder... do it... InventoryFolderBase rootDestinationFolder = folderCandidates [0]; archive = new TarArchiveReader(m_loadStream); // In order to load identically named folders, we need to keep track of the folders that we have already // resolved Dictionary <string, InventoryFolderBase> resolvedFolders = new Dictionary <string, InventoryFolderBase> (); MainConsole.Instance.Info("[Archiver]: Commencing load from archive"); int ticker = 0; byte [] data; TarArchiveReader.TarEntryType entryType; while ((data = archive.ReadEntry(out filePath, out entryType)) != null) { if (TarArchiveReader.TarEntryType.TYPE_NORMAL_FILE == entryType) { string fName; try { fName = Path.GetFileName(filePath); if (fName.StartsWith(".", StringComparison.Ordinal)) // ignore hidden files { continue; } } catch { MainConsole.Instance.ErrorFormat("[Archiver]: Invalid file name in archive: {0}", filePath); continue; } } ticker++; if (ticker % 5 == 0) { MainConsole.Instance.Ticker(); } if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH, StringComparison.Ordinal)) { if (LoadAsset(filePath, data)) { successfulAssetRestores++; } else { failedAssetRestores++; } if ((successfulAssetRestores) % 50 == 0) { MainConsole.Instance.Ticker( string.Format(" [Inventory Archiver]: Loaded {0} assets...", successfulAssetRestores), true); } } else if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH, StringComparison.Ordinal)) { filePath = filePath.Substring(ArchiveConstants.INVENTORY_PATH.Length); // Trim off the file portion if we aren't already dealing with a directory path if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType) { filePath = filePath.Remove(filePath.LastIndexOf("/", StringComparison.Ordinal) + 1); } InventoryFolderBase foundFolder = ReplicateArchivePathToUserInventory( filePath, rootDestinationFolder, ref resolvedFolders, ref loadedNodes); if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType) { InventoryItemBase item = LoadItem(data, foundFolder); if (item != null) { successfulItemRestores++; if ((successfulItemRestores) % 50 == 0) { MainConsole.Instance.Ticker( string.Format("[Inventory Archiver]: Restored {0} items...", successfulItemRestores), true); } // If we aren't loading the folder containing the item then well need to update the // viewer separately for that item. if (loadAll && !loadedNodes.Contains(foundFolder)) { loadedNodes.Add(item); } } item = null; } } else if (filePath == ArchiveConstants.CONTROL_FILE_PATH) { LoadControlFile(data); } data = null; } MainConsole.Instance.CleanInfo(""); MainConsole.Instance.Info("[Inventory Archiver]: Saving loaded inventory items"); ticker = 0; int successfulItemLoaded = 0; foreach (InventoryItemBase item in itemsSavedOff) { ticker++; if (ticker % 5 == 0) { MainConsole.Instance.Ticker(); } AddInventoryItem(item); successfulItemLoaded++; if ((successfulItemLoaded) % 50 == 0) { MainConsole.Instance.Ticker( string.Format("[Inventory Archiver]: Restored {0} items of {1}...", successfulItemLoaded, itemsSavedOff.Count), true); } } itemsSavedOff.Clear(); assets2Save.Clear(); MainConsole.Instance.CleanInfo(""); MainConsole.Instance.InfoFormat( "[Inventory Archiver]: Successfully loaded {0} assets with {1} failures", successfulAssetRestores, failedAssetRestores); MainConsole.Instance.InfoFormat("[Inventory Archiver]: Successfully loaded {0} items", successfulItemRestores); } finally { m_loadStream.Close(); } return(loadedNodes); }
/// <summary> /// Create inventory folders starting from a given parent folder /// </summary> /// /// Ignores any existing folders with the same name /// /// <param name="inventoryService"></param> /// <param name="parentFolder"></param> /// <param name="path"> /// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER /// </param> /// <returns> /// The folder created. If the path contains multiple folders then the last one created is returned. /// </returns> public static InventoryFolderBase CreateInventoryFolder( IInventoryService inventoryService, InventoryFolderBase parentFolder, string path) { string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None); InventoryFolderBase newFolder = new InventoryFolderBase(UUID.Random(), components[0], parentFolder.Owner, parentFolder.ID); inventoryService.AddFolder(newFolder); if (components.Length > 1) return CreateInventoryFolder(inventoryService, newFolder, components[1]); else return newFolder; }
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); }
/// <summary> /// This method is called by EstablishAppearance to do a copy all inventory items /// worn or attached to the Clothing inventory folder of the receiving avatar. /// In parallel the avatar wearables and attachments are updated. /// </summary> private void CopyWearablesAndAttachments(UUID destination, UUID source, AvatarAppearance avatarAppearance) { // Get Clothing folder of receiver InventoryFolderBase destinationFolder = m_InventoryService.GetFolderForType(destination, FolderType.Clothing); if (destinationFolder == null) { throw new Exception("Cannot locate folder(s)"); } // Missing destination folder? This should *never* be the case if (destinationFolder.Type != (short)FolderType.Clothing) { destinationFolder = new InventoryFolderBase(); destinationFolder.ID = UUID.Random(); destinationFolder.Name = "Clothing"; destinationFolder.Owner = destination; destinationFolder.Type = (short)AssetType.Clothing; destinationFolder.ParentID = m_InventoryService.GetRootFolder(destination).ID; destinationFolder.Version = 1; m_InventoryService.AddFolder(destinationFolder); // store base record m_log.ErrorFormat("[USER ACCOUNT SERVICE]: Created folder for destination {0}", source); } // Wearables AvatarWearable[] wearables = avatarAppearance.Wearables; AvatarWearable wearable; for (int i = 0; i < wearables.Length; i++) { wearable = wearables[i]; if (wearable[0].ItemID != UUID.Zero) { // Get inventory item and copy it InventoryItemBase item = m_InventoryService.GetItem(source, wearable[0].ItemID); if (item != null) { InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination); destinationItem.Name = item.Name; destinationItem.Owner = destination; destinationItem.Description = item.Description; destinationItem.InvType = item.InvType; destinationItem.CreatorId = item.CreatorId; destinationItem.CreatorData = item.CreatorData; destinationItem.NextPermissions = item.NextPermissions; destinationItem.CurrentPermissions = item.CurrentPermissions; destinationItem.BasePermissions = item.BasePermissions; destinationItem.EveryOnePermissions = item.EveryOnePermissions; destinationItem.GroupPermissions = item.GroupPermissions; destinationItem.AssetType = item.AssetType; destinationItem.AssetID = item.AssetID; destinationItem.GroupID = item.GroupID; destinationItem.GroupOwned = item.GroupOwned; destinationItem.SalePrice = item.SalePrice; destinationItem.SaleType = item.SaleType; destinationItem.Flags = item.Flags; destinationItem.CreationDate = item.CreationDate; destinationItem.Folder = destinationFolder.ID; ApplyNextOwnerPermissions(destinationItem); m_InventoryService.AddItem(destinationItem); m_log.DebugFormat("[USER ACCOUNT SERVICE]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID); // Wear item AvatarWearable newWearable = new AvatarWearable(); newWearable.Wear(destinationItem.ID, wearable[0].AssetID); avatarAppearance.SetWearable(i, newWearable); } else { m_log.WarnFormat("[USER ACCOUNT SERVICE]: Error transferring {0} to folder {1}", wearable[0].ItemID, destinationFolder.ID); } } } // Attachments List <AvatarAttachment> attachments = avatarAppearance.GetAttachments(); foreach (AvatarAttachment attachment in attachments) { int attachpoint = attachment.AttachPoint; UUID itemID = attachment.ItemID; if (itemID != UUID.Zero) { // Get inventory item and copy it InventoryItemBase item = m_InventoryService.GetItem(source, itemID); if (item != null) { InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination); destinationItem.Name = item.Name; destinationItem.Owner = destination; destinationItem.Description = item.Description; destinationItem.InvType = item.InvType; destinationItem.CreatorId = item.CreatorId; destinationItem.CreatorData = item.CreatorData; destinationItem.NextPermissions = item.NextPermissions; destinationItem.CurrentPermissions = item.CurrentPermissions; destinationItem.BasePermissions = item.BasePermissions; destinationItem.EveryOnePermissions = item.EveryOnePermissions; destinationItem.GroupPermissions = item.GroupPermissions; destinationItem.AssetType = item.AssetType; destinationItem.AssetID = item.AssetID; destinationItem.GroupID = item.GroupID; destinationItem.GroupOwned = item.GroupOwned; destinationItem.SalePrice = item.SalePrice; destinationItem.SaleType = item.SaleType; destinationItem.Flags = item.Flags; destinationItem.CreationDate = item.CreationDate; destinationItem.Folder = destinationFolder.ID; ApplyNextOwnerPermissions(destinationItem); m_InventoryService.AddItem(destinationItem); m_log.DebugFormat("[USER ACCOUNT SERVICE]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID); // Attach item avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID); m_log.DebugFormat("[USER ACCOUNT SERVICE]: Attached {0}", destinationItem.ID); } else { m_log.WarnFormat("[USER ACCOUNT SERVICE]: Error transferring {0} to folder {1}", itemID, destinationFolder.ID); } } } }
public void LoadAvatarArchive(string FileName, string Name) { UserAccount account = UserAccountService.GetUserAccount(UUID.Zero, Name); m_log.Info("[AvatarArchive] Loading archive from " + FileName); if (account == null) { m_log.Error("[AvatarArchive] User not found!"); return; } StreamReader reader = new StreamReader(FileName); string file = reader.ReadToEnd(); reader.Close(); reader.Dispose(); IScenePresence SP; m_scene.TryGetScenePresence(account.PrincipalID, out SP); if (SP == null) { return; //Bad people! } SP.ControllingClient.SendAlertMessage("Appearance loading in progress..."); string FolderNameToLoadInto = ""; OSDMap map = ((OSDMap)OSDParser.DeserializeLLSDXml(file)); OSDMap assetsMap = ((OSDMap)map["Assets"]); OSDMap itemsMap = ((OSDMap)map["Items"]); OSDMap bodyMap = ((OSDMap)map["Body"]); AvatarAppearance appearance = ConvertXMLToAvatarAppearance(bodyMap, out FolderNameToLoadInto); appearance.Owner = account.PrincipalID; List <InventoryItemBase> items = new List <InventoryItemBase>(); InventoryFolderBase AppearanceFolder = InventoryService.GetFolderForType(account.PrincipalID, AssetType.Clothing); InventoryFolderBase folderForAppearance = new InventoryFolderBase( UUID.Random(), FolderNameToLoadInto, account.PrincipalID, -1, AppearanceFolder.ID, 1); InventoryService.AddFolder(folderForAppearance); folderForAppearance = InventoryService.GetFolder(folderForAppearance); try { LoadAssets(assetsMap); LoadItems(itemsMap, account.PrincipalID, folderForAppearance, out items); } catch (Exception ex) { m_log.Warn("[AvatarArchiver]: Error loading assets and items, " + ex.ToString()); } //Now update the client about the new items SP.ControllingClient.SendBulkUpdateInventory(folderForAppearance); foreach (InventoryItemBase itemCopy in items) { if (itemCopy == null) { SP.ControllingClient.SendAgentAlertMessage("Can't find item to give. Nothing given.", false); continue; } if (!SP.IsChildAgent) { SP.ControllingClient.SendBulkUpdateInventory(itemCopy); } } m_log.Info("[AvatarArchive] Loaded archive from " + FileName); }
private void DoStoreFolderCheck(IClientAPI client) { bool hasfolder = false; List<InventoryFolderBase> m_invbase = new List<InventoryFolderBase> (); Scene scene = (Scene)client.Scene; inventoryService = scene.InventoryService; m_invbase = inventoryService.GetInventorySkeleton (client.AgentId); InventoryFolderBase rootFolder = inventoryService.GetRootFolder (client.AgentId); InventoryFolderBase folder = new InventoryFolderBase(); foreach (InventoryFolderBase current in m_invbase) { if (current.Name.ToString () == "Web Store Items") { hasfolder = true; } } if (!hasfolder) { UUID id = UUID.Random (); folder = new InventoryFolderBase (id, "Web Store Items", client.AgentId, 8, rootFolder.ID, rootFolder.Version); inventoryService.AddFolder (folder); } ScenePresence avatar = null; if (scene.TryGetScenePresence(client.AgentId, out avatar)) { scene.SendInventoryUpdate(avatar.ControllingClient, rootFolder, true, false); } }