/// <summary>
        /// Use the asset set information at path to load assets
        /// </summary>
        /// <param name="path"></param>
        /// <param name="assets"></param>
        protected void LoadLibraries(string iarFileName)
        {
            RegionInfo regInfo     = new RegionInfo();
            Scene      m_MockScene = null;

            //Make the scene for the IAR loader
            if (m_registry is Scene)
            {
                m_MockScene = (Scene)m_registry;
            }
            else
            {
                m_MockScene = new Scene();
                m_MockScene.Initialize(regInfo);
                m_MockScene.AddModuleInterfaces(m_registry.GetInterfaces());
            }

            UserAccount uinfo = m_MockScene.UserAccountService.GetUserAccount(UUID.Zero, m_service.LibraryOwner);

            //Make the user account for the default IAR
            if (uinfo == null)
            {
                m_log.Warn("Creating user " + m_service.LibraryOwnerName);
                m_MockScene.UserAccountService.CreateUser(m_service.LibraryOwnerName, "", "");
                uinfo = m_MockScene.UserAccountService.GetUserAccount(UUID.Zero, m_service.LibraryOwnerName);
                m_MockScene.InventoryService.CreateUserInventory(uinfo.PrincipalID);
            }
            if (m_MockScene.InventoryService.GetRootFolder(m_service.LibraryOwner) == null)
            {
                m_MockScene.InventoryService.CreateUserInventory(uinfo.PrincipalID);
            }

            InventoryCollection col = m_MockScene.InventoryService.GetFolderContent(uinfo.PrincipalID, UUID.Zero);
            bool alreadyExists      = false;

            foreach (InventoryFolderBase folder in col.Folders)
            {
                if (folder.Name == iarFileName)
                {
                    alreadyExists = true;
                    break;
                }
            }
            if (alreadyExists)
            {
                m_log.InfoFormat("[LIBRARY INVENTORY]: Found previously loaded iar file {0}, ignoring.", iarFileName);
                return;
            }

            m_log.InfoFormat("[LIBRARY INVENTORY]: Loading iar file {0}", iarFileName);
            InventoryFolderBase rootFolder = m_MockScene.InventoryService.GetRootFolder(uinfo.PrincipalID);

            if (null == rootFolder)
            {
                //We need to create the root folder, otherwise the IAR freaks
                m_MockScene.InventoryService.CreateUserInventory(uinfo.PrincipalID);
            }

            InventoryArchiveReadRequest archread = new InventoryArchiveReadRequest(m_MockScene, uinfo, "/", iarFileName, false);

            try
            {
                List <InventoryNodeBase> nodes = new List <InventoryNodeBase>(archread.Execute(true));
                if (nodes.Count == 0)
                {
                    return;
                }
                InventoryFolderImpl f = new InventoryFolderImpl((InventoryFolderBase)nodes[0]);

                TraverseFolders(f, nodes[0].ID, m_MockScene);
                //This is our loaded folder
                //Fix the name for later
                f.Name     = iarFileName;
                f.ParentID = UUID.Zero;
                m_MockScene.InventoryService.UpdateFolder(f);
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[LIBRARY MODULE]: Exception when processing archive {0}: {1}", iarFileName, e.StackTrace);
            }
            finally
            {
                archread.Close();
            }
        }
Example #2
0
        /// <summary>
        ///   Use the asset set information at path to load assets
        /// </summary>
        /// <param name = "path"></param>
        /// <param name = "assets"></param>
        protected void LoadLibraries(string iarFileName)
        {
            RegionInfo regInfo     = new RegionInfo();
            IScene     m_MockScene = null;

            //Make the scene for the IAR loader
            if (m_registry is IScene)
            {
                m_MockScene = (IScene)m_registry;
            }
            else
            {
                m_MockScene = new Scene();
                m_MockScene.Initialize(regInfo);
                m_MockScene.AddModuleInterfaces(m_registry.GetInterfaces());
            }

            UserAccount uinfo = m_MockScene.UserAccountService.GetUserAccount(null, m_service.LibraryOwner);

            //Make the user account for the default IAR
            if (uinfo == null)
            {
                MainConsole.Instance.Warn("Creating user " + m_service.LibraryOwnerName);
                m_MockScene.UserAccountService.CreateUser(m_service.LibraryOwner, UUID.Zero, m_service.LibraryOwnerName, "", "");
                uinfo = m_MockScene.UserAccountService.GetUserAccount(null, m_service.LibraryOwner);
                m_MockScene.InventoryService.CreateUserInventory(uinfo.PrincipalID, false);
            }
            if (m_MockScene.InventoryService.GetRootFolder(m_service.LibraryOwner) == null)
            {
                m_MockScene.InventoryService.CreateUserInventory(uinfo.PrincipalID, false);
            }

            List <InventoryFolderBase> rootFolders = m_MockScene.InventoryService.GetFolderFolders(uinfo.PrincipalID,
                                                                                                   UUID.Zero);

#if (!ISWIN)
            bool alreadyExists = false;
            foreach (InventoryFolderBase folder in rootFolders)
            {
                if (folder.Name == iarFileName)
                {
                    alreadyExists = true;
                    break;
                }
            }
#else
            bool alreadyExists = rootFolders.Any(folder => folder.Name == iarFileName);
#endif
            if (alreadyExists)
            {
                MainConsole.Instance.InfoFormat("[LIBRARY INVENTORY]: Found previously loaded iar file {0}, ignoring.", iarFileName);
                return;
            }

            MainConsole.Instance.InfoFormat("[LIBRARY INVENTORY]: Loading iar file {0}", iarFileName);
            InventoryFolderBase rootFolder = m_MockScene.InventoryService.GetRootFolder(uinfo.PrincipalID);

            if (null == rootFolder)
            {
                //We need to create the root folder, otherwise the IAR freaks
                m_MockScene.InventoryService.CreateUserInventory(uinfo.PrincipalID, false);
            }

            InventoryArchiveReadRequest archread = new InventoryArchiveReadRequest(m_MockScene, uinfo, "/", iarFileName,
                                                                                   false, m_service.LibraryOwner);

            try
            {
                archread.ReplaceAssets = true;//Replace any old assets
                List <InventoryNodeBase> nodes = new List <InventoryNodeBase>(archread.Execute(true));
                if (nodes.Count == 0)
                {
                    return;
                }
                InventoryFolderBase f = (InventoryFolderBase)nodes[0];
                UUID IARRootID        = f.ID;

                TraverseFolders(IARRootID, m_MockScene);
                FixParent(IARRootID, m_MockScene, m_service.LibraryRootFolderID);
                f.Name     = iarFileName;
                f.ParentID = UUID.Zero;
                f.ID       = m_service.LibraryRootFolderID;
                f.Type     = (int)AssetType.RootFolder;
                f.Version  = 1;
                m_MockScene.InventoryService.UpdateFolder(f);
            }
            catch (Exception e)
            {
                MainConsole.Instance.DebugFormat("[LIBRARY MODULE]: Exception when processing archive {0}: {1}", iarFileName,
                                                 e.StackTrace);
            }
            finally
            {
                archread.Close();
            }
        }
        /// <summary>
        ///     Use the asset set information at path to load assets
        /// </summary>
        /// <param name="iarFileName"></param>
        protected void LoadLibraries(string iarFileName)
        {
            RegionInfo regInfo = new RegionInfo();
            IScene     m_MockScene;

            //Make the scene for the IAR loader
            if (m_registry is IScene)
            {
                m_MockScene = (IScene)m_registry;
            }
            else
            {
                m_MockScene = new Scene();
                m_MockScene.Initialize(regInfo);
                m_MockScene.AddModuleInterfaces(m_registry.GetInterfaces());
            }

            UserAccount libAcct = m_MockScene.UserAccountService.GetUserAccount(null, m_libService.LibraryOwnerUUID);

            // Make the user account for the default IAR
            if (!libAcct.Valid)
            {
                // this should not happen as the Library account should have been created with the system accounts
                MainConsole.Instance.Error("[Library Inventory]: Creating library user for load" + m_libService.LibraryOwnerName);
                m_MockScene.UserAccountService.CreateUser(m_libService.LibraryOwnerUUID,
                                                          UUID.Zero,
                                                          m_libService.LibraryOwnerName,
                                                          Util.Md5Hash("library"),
                                                          "");
                libAcct = m_MockScene.UserAccountService.GetUserAccount(null, m_libService.LibraryOwnerUUID);
                m_MockScene.InventoryService.CreateUserInventory(m_libService.LibraryOwnerUUID, false);
            }

            if (m_MockScene.InventoryService.GetRootFolder(m_libService.LibraryOwnerUUID) == null)
            {
                // Try again...
                m_MockScene.InventoryService.CreateUserInventory(m_libService.LibraryOwnerUUID, false);
            }

            List <InventoryFolderBase> rootFolders = m_MockScene.InventoryService.GetFolderFolders(m_libService.LibraryOwnerUUID, UUID.Zero);
            bool alreadyExists = rootFolders.Any(folder => folder.Name == iarFileName);

            if (alreadyExists)
            {
                MainConsole.Instance.InfoFormat("[Library Inventory]: Found previously loaded IAR file {0}, ignoring.",
                                                iarFileName);
                return;
            }

            MainConsole.Instance.InfoFormat("[Library Inventory]: Loading IAR file {0}", iarFileName);
            InventoryFolderBase rootFolder = m_MockScene.InventoryService.GetRootFolder(m_libService.LibraryOwnerUUID);

            if (rootFolder == null)
            {
                // We need to create the root folder, otherwise the IAR freaks
                m_MockScene.InventoryService.CreateUserInventory(m_libService.LibraryOwnerUUID, false);
            }

            var archread = new InventoryArchiveReadRequest(m_MockScene, libAcct, "/", iarFileName,
                                                           false, m_libService.LibraryOwnerUUID);

            try {
                archread.ReplaceAssets = true;      // Replace any old assets
                var nodes = new List <InventoryNodeBase> (archread.Execute(true));
                if (nodes.Count == 0)
                {
                    return;
                }

                InventoryFolderBase f = (InventoryFolderBase)nodes [0];
                UUID IARRootID        = f.ID;

                TraverseFolders(IARRootID, m_MockScene);
                FixParent(IARRootID, m_MockScene, m_libService.LibraryRootFolderID);
                f.Name     = iarFileName;
                f.ParentID = UUID.Zero;
                f.ID       = m_libService.LibraryRootFolderID;
                f.Type     = (short)FolderType.Root;
                f.Version  = 1;
                m_MockScene.InventoryService.UpdateFolder(f);
            } catch (Exception e) {
                MainConsole.Instance.DebugFormat("[Library Inventory]: Exception when processing archive {0}: {1}",
                                                 iarFileName,
                                                 e.StackTrace);
            } finally {
                archread.Close();
            }
        }
        public void Start(IConfigSource config, IRegistryCore registry)
        {
            string IARName = "DefaultInventory.iar";
            IniConfigSource iniSource = null;
            try
            {
                iniSource = new IniConfigSource("DefaultInventory/Inventory.ini", Nini.Ini.IniFileType.AuroraStyle);
            }
            catch
            {
            }
            IConfig libConfig = config.Configs["DefaultAssetsIARCreator"];
            if (libConfig == null)
                libConfig = iniSource.Configs["DefaultAssetsIARCreator"];
            if (libConfig != null)
            {
                if (!libConfig.GetBoolean("Enabled", false))
                    return;
                IARName = libConfig.GetString("NameOfIAR", IARName);
            }
            else
                return;
            m_service = registry.RequestModuleInterface<ILibraryService>();

            RegionInfo regInfo = new RegionInfo();
            IScene m_MockScene = null;
            //Make the scene for the IAR loader
            if (registry is IScene)
                m_MockScene = (IScene)registry;
            else
            {
                m_MockScene = new Scene();
                m_MockScene.Initialize(regInfo);
                m_MockScene.AddModuleInterfaces(registry.GetInterfaces());
            }

            UserAccount uinfo = m_MockScene.UserAccountService.GetUserAccount(UUID.Zero, m_service.LibraryOwner);
            //Make the user account for the default IAR
            if (uinfo == null)
            {
                uinfo = new UserAccount(m_service.LibraryOwner);
                uinfo.Name = m_service.LibraryOwnerName;
                m_MockScene.InventoryService.CreateUserInventory(m_service.LibraryOwner, false);
            }

            List<AssetBase> assets = new List<AssetBase> ();
            if (m_MockScene.InventoryService != null)
            {
                //Add the folders to the user's inventory
                InventoryCollection i = m_MockScene.InventoryService.GetFolderContent (m_service.LibraryOwner, UUID.Zero);
                if (i != null)
                {
                    foreach (InventoryItemBase item in i.Items)
                    {
                        AssetBase asset = m_MockScene.RequestModuleInterface<IAssetService> ().Get (item.AssetID.ToString ());
                        if (asset != null)
                            assets.Add (asset);
                    }
                }
            }
            InventoryFolderBase rootFolder = null;
            List<InventoryFolderBase> rootFolders = m_MockScene.InventoryService.GetRootFolders (m_service.LibraryOwner);
            foreach (InventoryFolderBase folder in rootFolders)
            {
                if (folder.Name == "My Inventory")
                    continue;

                rootFolder = folder;
                break;
            }
            if (rootFolder != null)
            {
                //Save the IAR of the default assets
                InventoryArchiveWriteRequest write = new InventoryArchiveWriteRequest (Guid.NewGuid (), null, m_MockScene,
                    uinfo, "/", new GZipStream (new FileStream (IARName, FileMode.Create), CompressionMode.Compress), true, rootFolder, assets);
                write.Execute ();
            }
        }
        public void FinishedStartup()
        {
            string          IARName   = "DefaultInventory.iar";
            IniConfigSource iniSource = null;

            try
            {
                iniSource = new IniConfigSource("DefaultInventory/Inventory.ini", Nini.Ini.IniFileType.AuroraStyle);
            }
            catch
            {
            }
            IConfig libConfig = m_config.Configs["DefaultAssetsIARCreator"];

            if (libConfig == null)
            {
                libConfig = iniSource.Configs["DefaultAssetsIARCreator"];
            }
            if (libConfig != null)
            {
                if (!libConfig.GetBoolean("Enabled", false))
                {
                    return;
                }
                IARName = libConfig.GetString("NameOfIAR", IARName);
            }
            else
            {
                return;
            }
            m_service = m_registry.RequestModuleInterface <ILibraryService>();

            RegionInfo regInfo     = new RegionInfo();
            IScene     m_MockScene = null;

            //Make the scene for the IAR loader
            if (m_registry is IScene)
            {
                m_MockScene = (IScene)m_registry;
            }
            else
            {
                m_MockScene = new Scene();
                m_MockScene.Initialize(regInfo);
                m_MockScene.AddModuleInterfaces(m_registry.GetInterfaces());
            }

            UserAccount uinfo = m_MockScene.UserAccountService.GetUserAccount(null, m_service.LibraryOwner);

            //Make the user account for the default IAR
            if (uinfo == null)
            {
                uinfo      = new UserAccount(m_service.LibraryOwner);
                uinfo.Name = m_service.LibraryOwnerName;
                //m_MockScene.InventoryService.CreateUserInventory(m_service.LibraryOwner, false);
                MainConsole.Instance.InfoFormat("[DefaultInventoryToIARConverter]: 1,1");
                InventoryFolderBase newFolder = new InventoryFolderBase
                {
                    Name     = "My Inventory",
                    Type     = 9,
                    Version  = 1,
                    ID       = new UUID("00000112-000f-0000-0000-000100bba000"),
                    Owner    = m_service.LibraryOwner,
                    ParentID = UUID.Zero
                };
                MainConsole.Instance.InfoFormat("[DefaultInventoryToIARConverter]: 1,3");
            }

            MainConsole.Instance.InfoFormat("[DefaultInventoryToIARConverter]: 1,4");
            List <AssetBase> assets = new List <AssetBase> ();

            if (m_MockScene.InventoryService != null)
            {
                //Add the folders to the user's inventory
                InventoryCollection i = m_MockScene.InventoryService.GetFolderContent(m_service.LibraryOwner, UUID.Zero);
                if (i != null)
                {
                    foreach (InventoryItemBase item in i.Items)
                    {
                        AssetBase asset = m_MockScene.RequestModuleInterface <IAssetService> ().Get(item.AssetID.ToString());
                        if (asset != null)
                        {
                            assets.Add(asset);
                        }
                    }
                }
            }
            InventoryFolderBase        rootFolder  = null;
            List <InventoryFolderBase> rootFolders = m_MockScene.InventoryService.GetRootFolders(m_service.LibraryOwner);

            foreach (InventoryFolderBase folder in rootFolders)
            {
                if (folder.Name == "My Inventory")
                {
                    continue;
                }

                rootFolder = folder;
                break;
            }
            if (rootFolder != null)
            {
                //Save the IAR of the default assets
                InventoryArchiveWriteRequest write = new InventoryArchiveWriteRequest(Guid.NewGuid(), null, m_MockScene,
                                                                                      uinfo, "/", new GZipStream(new FileStream(IARName, FileMode.Create), CompressionMode.Compress), true, rootFolder, assets);
                write.Execute();
            }
        }
Example #6
0
        public void Start(IConfigSource config, IRegistryCore registry)
        {
            string          IARName   = "DefaultInventory.iar";
            IniConfigSource iniSource = null;

            try
            {
                iniSource = new IniConfigSource("DefaultInventory/Inventory.ini", Nini.Ini.IniFileType.AuroraStyle);
            }
            catch
            {
            }
            IConfig libConfig = config.Configs["DefaultAssetsIARCreator"];

            if (libConfig == null)
            {
                libConfig = iniSource.Configs["DefaultAssetsIARCreator"];
            }
            if (libConfig != null)
            {
                if (!libConfig.GetBoolean("Enabled", false))
                {
                    return;
                }
                IARName = libConfig.GetString("NameOfIAR", IARName);
            }
            else
            {
                return;
            }
            m_service = registry.RequestModuleInterface <ILibraryService>();

            RegionInfo regInfo     = new RegionInfo();
            Scene      m_MockScene = null;

            //Make the scene for the IAR loader
            if (registry is Scene)
            {
                m_MockScene = (Scene)registry;
            }
            else
            {
                m_MockScene = new Scene();
                m_MockScene.Initialize(regInfo);
                m_MockScene.AddModuleInterfaces(registry.GetInterfaces());
            }

            UserAccount uinfo = m_MockScene.UserAccountService.GetUserAccount(UUID.Zero, m_service.LibraryOwner);

            //Make the user account for the default IAR
            if (uinfo == null)
            {
                uinfo             = new UserAccount(m_service.LibraryOwner);
                uinfo.Name        = m_service.LibraryOwnerName;
                uinfo.ServiceURLs = new Dictionary <string, object>();
                m_MockScene.InventoryService.CreateUserInventory(m_service.LibraryOwner);
            }

            if (m_MockScene.InventoryService != null)
            {
                //Add the folders to the user's inventory
                InventoryFolderBase i = m_MockScene.InventoryService.GetFolder(m_service.LibraryRootFolder);
                if (i == null)
                {
                    BuildInventoryFolder(m_MockScene, m_service.LibraryRootFolder);
                }
            }

            List <AssetBase> assets      = new List <AssetBase>();
            IConfig          assetConfig = config.Configs["DefaultXMLAssetLoader"];

            if (assetConfig == null)
            {
                assetConfig = iniSource.Configs["DefaultXMLAssetLoader"];
            }
            if (assetConfig != null)
            {
                string loaderArgs = assetConfig.GetString("AssetLoaderArgs",
                                                          String.Empty);
                ForEachDefaultXmlAsset(loaderArgs, delegate(AssetBase asset)
                {
                    assets.Add(asset);
                });
            }

            //Save the IAR of the default assets
            InventoryArchiveWriteRequest write = new InventoryArchiveWriteRequest(Guid.NewGuid(), null, m_MockScene,
                                                                                  uinfo, "/", new GZipStream(new FileStream(IARName, FileMode.Create), CompressionMode.Compress), true, m_service.LibraryRootFolder, assets);

            write.Execute();
        }