From b8975ecbd9510bd8e766cb4ca06c5a70110187cd Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Mon, 31 Dec 2007 23:20:49 +0000 Subject: [PATCH] Make it possible for new inventory 'libraries' to be added without changing the default OpenSimLibrary files. Additional library folders and items can be added in a separate directory and linked in by an entry to inventory/Libraries.xml --- .../Communications/Cache/LibraryRootFolder.cs | 200 ++++++++++-------- .../Framework/Communications/LoginService.cs | 1 + OpenSim/Framework/Util.cs | 7 +- bin/assets/AssetSets.xml | 11 +- bin/inventory/Libraries.xml | 17 ++ bin/inventory/README.txt | 25 ++- 6 files changed, 163 insertions(+), 98 deletions(-) create mode 100644 bin/inventory/Libraries.xml diff --git a/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs b/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs index cb122df251..38cffebd6f 100644 --- a/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs +++ b/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs @@ -64,35 +64,9 @@ namespace OpenSim.Framework.Communications.Cache libraryFolders.Add(folderID, this); - string foldersPath = Path.Combine(Util.configDir(), "inventory/OpenSimLibrary/OpenSimLibraryFolders.xml"); - if (File.Exists(foldersPath)) - { - try - { - XmlConfigSource source = new XmlConfigSource(foldersPath); - ReadFoldersFromFile(source); - } - catch (XmlException e) - { - MainLog.Instance.Error("AGENTINVENTORY", "Error loading " + foldersPath + ": " + e.ToString()); - } - } + LoadLibraries(Path.Combine(Util.inventoryDir(), "Libraries.xml")); CreateLibraryItems(); - - string itemsPath = Path.Combine(Util.configDir(), "inventory/OpenSimLibrary/OpenSimLibrary.xml"); - if (File.Exists(itemsPath)) - { - try - { - XmlConfigSource source = new XmlConfigSource(itemsPath); - ReadItemsFromFile(source); - } - catch (XmlException e) - { - MainLog.Instance.Error("AGENTINVENTORY", "Error loading " + itemsPath + ": " + e.ToString()); - } - } } /// @@ -155,84 +129,140 @@ namespace OpenSim.Framework.Communications.Cache } /// - /// Read library inventory folders from an external source + /// Use the asset set information at path to load assets + /// + /// + /// + protected void LoadLibraries(string librariesControlPath) + { + MainLog.Instance.Verbose( + "LIBRARYINVENTORY", "Loading libraries control file {0}", librariesControlPath); + + LoadFromFile(librariesControlPath, "Libraries control", ReadLibraryFromConfig); + } + + /// + /// Read a library set from config + /// + /// + protected void ReadLibraryFromConfig(IConfig config) + { + string foldersPath + = Path.Combine( + Util.inventoryDir(), config.GetString("foldersFile", "")); + + LoadFromFile(foldersPath, "Library folders", ReadFolderFromConfig); + + string itemsPath + = Path.Combine( + Util.inventoryDir(), config.GetString("itemsFile", "")); + + LoadFromFile(itemsPath, "Library items", ReadItemFromConfig); + } + + /// + /// Read a library inventory folder from a loaded configuration /// /// - private void ReadFoldersFromFile(IConfigSource source) - { - for (int i = 0; i < source.Configs.Count; i++) - { - IConfig config = source.Configs[i]; + private void ReadFolderFromConfig(IConfig config) + { + InventoryFolderImpl folderInfo = new InventoryFolderImpl(); + + folderInfo.folderID = new LLUUID(config.GetString("folderID", folderID.ToString())); + folderInfo.name = config.GetString("name", "unknown"); + folderInfo.parentID = new LLUUID(config.GetString("parentFolderID", folderID.ToString())); + folderInfo.type = (short)config.GetInt("type", 8); + + folderInfo.agentID = libOwner; + folderInfo.version = 1; + + if (libraryFolders.ContainsKey(folderInfo.parentID)) + { + InventoryFolderImpl parentFolder = libraryFolders[folderInfo.parentID]; - InventoryFolderImpl folderInfo = new InventoryFolderImpl(); + libraryFolders.Add(folderInfo.folderID, folderInfo); + parentFolder.SubFolders.Add(folderInfo.folderID, folderInfo); - folderInfo.folderID = new LLUUID(config.GetString("folderID", folderID.ToString())); - folderInfo.name = config.GetString("name", "unknown"); - folderInfo.parentID = new LLUUID(config.GetString("parentFolderID", folderID.ToString())); - folderInfo.type = (short)config.GetInt("type", 8); - - folderInfo.agentID = libOwner; - folderInfo.version = 1; - - if (libraryFolders.ContainsKey(folderInfo.parentID)) - { - InventoryFolderImpl parentFolder = libraryFolders[folderInfo.parentID]; - - libraryFolders.Add(folderInfo.folderID, folderInfo); - parentFolder.SubFolders.Add(folderInfo.folderID, folderInfo); - // MainLog.Instance.Verbose( // "LIBRARYINVENTORY", "Adding folder {0} ({1})", folderInfo.name, folderInfo.folderID); - } - else - { - MainLog.Instance.Warn( - "LIBRARYINVENTORY", - "Couldn't add folder {0} ({1}) since parent folder with ID {2} does not exist!", - folderInfo.name, folderInfo.folderID, folderInfo.parentID); - } + } + else + { + MainLog.Instance.Warn( + "LIBRARYINVENTORY", + "Couldn't add folder {0} ({1}) since parent folder with ID {2} does not exist!", + folderInfo.name, folderInfo.folderID, folderInfo.parentID); } } /// - /// Read library inventory items metadata from an external source + /// Read a library inventory item metadata from a loaded configuration /// /// - private void ReadItemsFromFile(IConfigSource source) + private void ReadItemFromConfig(IConfig config) { - for (int i = 0; i < source.Configs.Count; i++) + InventoryItemBase item = new InventoryItemBase(); + item.avatarID = libOwner; + item.creatorsID = libOwner; + item.inventoryID = new LLUUID(config.GetString("inventoryID", folderID.ToString())); + item.assetID = new LLUUID(config.GetString("assetID", LLUUID.Random().ToString())); + item.parentFolderID = new LLUUID(config.GetString("folderID", folderID.ToString())); + item.inventoryDescription = config.GetString("description", ""); + item.inventoryName = config.GetString("name", ""); + item.assetType = config.GetInt("assetType", 0); + item.invType = config.GetInt("inventoryType", 0); + item.inventoryCurrentPermissions = (uint)config.GetLong("currentPermissions", 0x7FFFFFFF); + item.inventoryNextPermissions = (uint)config.GetLong("nextPermissions", 0x7FFFFFFF); + item.inventoryEveryOnePermissions = (uint)config.GetLong("everyonePermissions", 0x7FFFFFFF); + item.inventoryBasePermissions = (uint)config.GetLong("basePermissions", 0x7FFFFFFF); + + if (libraryFolders.ContainsKey(item.parentFolderID)) { - InventoryItemBase item = new InventoryItemBase(); - item.avatarID = libOwner; - item.creatorsID = libOwner; - item.inventoryID = - new LLUUID(source.Configs[i].GetString("inventoryID", folderID.ToString())); - item.assetID = new LLUUID(source.Configs[i].GetString("assetID", LLUUID.Random().ToString())); - item.parentFolderID - = new LLUUID(source.Configs[i].GetString("folderID", folderID.ToString())); - item.inventoryDescription = source.Configs[i].GetString("description", ""); - item.inventoryName = source.Configs[i].GetString("name", ""); - item.assetType = source.Configs[i].GetInt("assetType", 0); - item.invType = source.Configs[i].GetInt("inventoryType", 0); - item.inventoryCurrentPermissions = (uint) source.Configs[i].GetLong("currentPermissions", 0x7FFFFFFF); - item.inventoryNextPermissions = (uint) source.Configs[i].GetLong("nextPermissions", 0x7FFFFFFF); - item.inventoryEveryOnePermissions = (uint) source.Configs[i].GetLong("everyonePermissions", 0x7FFFFFFF); - item.inventoryBasePermissions = (uint) source.Configs[i].GetLong("basePermissions", 0x7FFFFFFF); + InventoryFolderImpl parentFolder = libraryFolders[item.parentFolderID]; - if (libraryFolders.ContainsKey(item.parentFolderID)) + parentFolder.Items.Add(item.inventoryID, item); + } + else + { + MainLog.Instance.Warn( + "LIBRARYINVENTORY", + "Couldn't add item {0} ({1}) since parent folder with ID {2} does not exist!", + item.inventoryName, item.inventoryID, item.parentFolderID); + } + } + + private delegate void ConfigAction(IConfig config); + + /// + /// Load the given configuration at a path and perform an action on each Config contained within it + /// + /// + /// + /// + private void LoadFromFile(string path, string fileDescription, ConfigAction action) + { + if (File.Exists(path)) + { + try { - InventoryFolderImpl parentFolder = libraryFolders[item.parentFolderID]; - - parentFolder.Items.Add(item.inventoryID, item); + XmlConfigSource source = new XmlConfigSource(path); + + for (int i = 0; i < source.Configs.Count; i++) + { + action(source.Configs[i]); + } } - else + catch (XmlException e) { - MainLog.Instance.Warn( - "LIBRARYINVENTORY", - "Couldn't add item {0} ({1}) since parent folder with ID {2} does not exist!", - item.inventoryName, item.inventoryID, item.parentFolderID); + MainLog.Instance.Error( + "LIBRARYINVENTORY", "Error loading {0} : {1}", path, e); } } + else + { + MainLog.Instance.Error( + "LIBRARYINVENTORY", "{0} file {1} does not exist!", fileDescription, path); + } } /// diff --git a/OpenSim/Framework/Communications/LoginService.cs b/OpenSim/Framework/Communications/LoginService.cs index afc6c9ae82..0531d6a786 100644 --- a/OpenSim/Framework/Communications/LoginService.cs +++ b/OpenSim/Framework/Communications/LoginService.cs @@ -280,6 +280,7 @@ namespace OpenSim.Framework.UserManagement } return buddylistreturn; } + /// /// Converts the inventory library skeleton into the form required by the rpc request. /// diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index c742cf3cdd..0f413800ef 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -321,7 +321,12 @@ namespace OpenSim.Framework public static string assetsDir() { - return "assets"; + return Path.Combine(configDir(), "assets"); + } + + public static string inventoryDir() + { + return Path.Combine(configDir(), "inventory"); } public static string configDir() diff --git a/bin/assets/AssetSets.xml b/bin/assets/AssetSets.xml index b827e59b8c..c94cd59d03 100644 --- a/bin/assets/AssetSets.xml +++ b/bin/assets/AssetSets.xml @@ -1,13 +1,18 @@ + since it contains various default assets which are currently hardcoded + However, you can remove the corresponding inventory library in bin/inventory if you wish + --> +
+ - +-->
diff --git a/bin/inventory/Libraries.xml b/bin/inventory/Libraries.xml new file mode 100644 index 0000000000..09270b57e4 --- /dev/null +++ b/bin/inventory/Libraries.xml @@ -0,0 +1,17 @@ + +
+ + +
+ + + +
diff --git a/bin/inventory/README.txt b/bin/inventory/README.txt index f32f1aaafe..ecd81d13c0 100644 --- a/bin/inventory/README.txt +++ b/bin/inventory/README.txt @@ -1,14 +1,21 @@ README -The standard common inventory library is configured here. You can add new inventory -folders to the standard library by editing OpenSimLibary/OpenSimLibraryFolders.xml -You can also add new inventory items to OpenSimLibrary/OpenSimLibrary.xml, -as long as they have a corresponding asset entry in bin/OpenSimAssetSet.xml. +Folders and items which will appear in the standard common library for all +avatars can be configured here. The root folder (currently called OpenSim +Library) is hardcoded, but you can add your own configuration of folders and +items directly beneath this, in addition to (or instead of) the contents of the +default OpenSim library. -The same set of folders and items must be present in the configuration of both -the grid servers and all the regions. The reasons for this are historical - -this restriction will probably be lifted in the future, at which point the -inventory items and folders will only need to be configured on the grid inventory -server (assuming you are running in grid mode rather than standalone) +To add a new library, edit Libraries.xml. The entry in here needs to point to +two further xml files, one which details your library inventory folders and another +which details your library inventory items. Each inventory item will need to be +associated with an asset. Assets are configured separately in the bin/assets +directory. + +If you are running in grid mode, any library you add must be present in both +your grid servers installation and in +every region installation, otherwise library items will fail in the regions +where the inventory configuration is not present. The reasons for this are historical +and will probably be lifted in a future revision. Files in the attic directory are currently unused.