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
afrisby
Justin Clarke Casey 2007-12-31 23:20:49 +00:00
parent 3180432deb
commit b8975ecbd9
6 changed files with 163 additions and 98 deletions

View File

@ -64,35 +64,9 @@ namespace OpenSim.Framework.Communications.Cache
libraryFolders.Add(folderID, this); libraryFolders.Add(folderID, this);
string foldersPath = Path.Combine(Util.configDir(), "inventory/OpenSimLibrary/OpenSimLibraryFolders.xml"); LoadLibraries(Path.Combine(Util.inventoryDir(), "Libraries.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());
}
}
CreateLibraryItems(); 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());
}
}
} }
/// <summary> /// <summary>
@ -155,15 +129,43 @@ namespace OpenSim.Framework.Communications.Cache
} }
/// <summary> /// <summary>
/// Read library inventory folders from an external source /// Use the asset set information at path to load assets
/// </summary>
/// <param name="path"></param>
/// <param name="assets"></param>
protected void LoadLibraries(string librariesControlPath)
{
MainLog.Instance.Verbose(
"LIBRARYINVENTORY", "Loading libraries control file {0}", librariesControlPath);
LoadFromFile(librariesControlPath, "Libraries control", ReadLibraryFromConfig);
}
/// <summary>
/// Read a library set from config
/// </summary>
/// <param name="config"></param>
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);
}
/// <summary>
/// Read a library inventory folder from a loaded configuration
/// </summary> /// </summary>
/// <param name="source"></param> /// <param name="source"></param>
private void ReadFoldersFromFile(IConfigSource source) private void ReadFolderFromConfig(IConfig config)
{ {
for (int i = 0; i < source.Configs.Count; i++)
{
IConfig config = source.Configs[i];
InventoryFolderImpl folderInfo = new InventoryFolderImpl(); InventoryFolderImpl folderInfo = new InventoryFolderImpl();
folderInfo.folderID = new LLUUID(config.GetString("folderID", folderID.ToString())); folderInfo.folderID = new LLUUID(config.GetString("folderID", folderID.ToString()));
@ -192,32 +194,27 @@ namespace OpenSim.Framework.Communications.Cache
folderInfo.name, folderInfo.folderID, folderInfo.parentID); folderInfo.name, folderInfo.folderID, folderInfo.parentID);
} }
} }
}
/// <summary> /// <summary>
/// Read library inventory items metadata from an external source /// Read a library inventory item metadata from a loaded configuration
/// </summary> /// </summary>
/// <param name="source"></param> /// <param name="source"></param>
private void ReadItemsFromFile(IConfigSource source) private void ReadItemFromConfig(IConfig config)
{
for (int i = 0; i < source.Configs.Count; i++)
{ {
InventoryItemBase item = new InventoryItemBase(); InventoryItemBase item = new InventoryItemBase();
item.avatarID = libOwner; item.avatarID = libOwner;
item.creatorsID = libOwner; item.creatorsID = libOwner;
item.inventoryID = item.inventoryID = new LLUUID(config.GetString("inventoryID", folderID.ToString()));
new LLUUID(source.Configs[i].GetString("inventoryID", folderID.ToString())); item.assetID = new LLUUID(config.GetString("assetID", LLUUID.Random().ToString()));
item.assetID = new LLUUID(source.Configs[i].GetString("assetID", LLUUID.Random().ToString())); item.parentFolderID = new LLUUID(config.GetString("folderID", folderID.ToString()));
item.parentFolderID item.inventoryDescription = config.GetString("description", "");
= new LLUUID(source.Configs[i].GetString("folderID", folderID.ToString())); item.inventoryName = config.GetString("name", "");
item.inventoryDescription = source.Configs[i].GetString("description", ""); item.assetType = config.GetInt("assetType", 0);
item.inventoryName = source.Configs[i].GetString("name", ""); item.invType = config.GetInt("inventoryType", 0);
item.assetType = source.Configs[i].GetInt("assetType", 0); item.inventoryCurrentPermissions = (uint)config.GetLong("currentPermissions", 0x7FFFFFFF);
item.invType = source.Configs[i].GetInt("inventoryType", 0); item.inventoryNextPermissions = (uint)config.GetLong("nextPermissions", 0x7FFFFFFF);
item.inventoryCurrentPermissions = (uint) source.Configs[i].GetLong("currentPermissions", 0x7FFFFFFF); item.inventoryEveryOnePermissions = (uint)config.GetLong("everyonePermissions", 0x7FFFFFFF);
item.inventoryNextPermissions = (uint) source.Configs[i].GetLong("nextPermissions", 0x7FFFFFFF); item.inventoryBasePermissions = (uint)config.GetLong("basePermissions", 0x7FFFFFFF);
item.inventoryEveryOnePermissions = (uint) source.Configs[i].GetLong("everyonePermissions", 0x7FFFFFFF);
item.inventoryBasePermissions = (uint) source.Configs[i].GetLong("basePermissions", 0x7FFFFFFF);
if (libraryFolders.ContainsKey(item.parentFolderID)) if (libraryFolders.ContainsKey(item.parentFolderID))
{ {
@ -233,6 +230,39 @@ namespace OpenSim.Framework.Communications.Cache
item.inventoryName, item.inventoryID, item.parentFolderID); item.inventoryName, item.inventoryID, item.parentFolderID);
} }
} }
private delegate void ConfigAction(IConfig config);
/// <summary>
/// Load the given configuration at a path and perform an action on each Config contained within it
/// </summary>
/// <param name="path"></param>
/// <param name="fileDescription"></param>
/// <param name="action"></param>
private void LoadFromFile(string path, string fileDescription, ConfigAction action)
{
if (File.Exists(path))
{
try
{
XmlConfigSource source = new XmlConfigSource(path);
for (int i = 0; i < source.Configs.Count; i++)
{
action(source.Configs[i]);
}
}
catch (XmlException e)
{
MainLog.Instance.Error(
"LIBRARYINVENTORY", "Error loading {0} : {1}", path, e);
}
}
else
{
MainLog.Instance.Error(
"LIBRARYINVENTORY", "{0} file {1} does not exist!", fileDescription, path);
}
} }
/// <summary> /// <summary>

View File

@ -280,6 +280,7 @@ namespace OpenSim.Framework.UserManagement
} }
return buddylistreturn; return buddylistreturn;
} }
/// <summary> /// <summary>
/// Converts the inventory library skeleton into the form required by the rpc request. /// Converts the inventory library skeleton into the form required by the rpc request.
/// </summary> /// </summary>

View File

@ -321,7 +321,12 @@ namespace OpenSim.Framework
public static string assetsDir() public static string assetsDir()
{ {
return "assets"; return Path.Combine(configDir(), "assets");
}
public static string inventoryDir()
{
return Path.Combine(configDir(), "inventory");
} }
public static string configDir() public static string configDir()

View File

@ -1,10 +1,15 @@
<Nini> <Nini>
<!-- You probably don't want to remove the OpenSim asset set <!-- You probably don't want to remove the OpenSim asset set
since it contains various default assets which are currently hardcoded --> since it contains various default assets which are currently hardcoded
However, you can remove the corresponding inventory library in bin/inventory if you wish
-->
<Section Name="OpenSim Asset Set"> <Section Name="OpenSim Asset Set">
<Key Name="file" Value="OpenSimAssetSet/OpenSimAssetSet.xml"/> <Key Name="file" Value="OpenSimAssetSet/OpenSimAssetSet.xml"/>
</Section> </Section>
<!-- New asset sets can be added as shown below --> <!-- New asset sets can be added as shown below -->
<!-- <!--
<Section Name="My Asset Set"> <Section Name="My Asset Set">
<Key Name="file" Value="MyAssetSet/MyAssetSet.xml"/> <Key Name="file" Value="MyAssetSet/MyAssetSet.xml"/>

View File

@ -0,0 +1,17 @@
<Nini>
<Section Name="OpenSim Standard Library">
<Key Name="foldersFile" Value="OpenSimLibrary/OpenSimLibraryFolders.xml"/>
<Key Name="itemsFile" Value="OpenSimLibrary/OpenSimLibrary.xml"/>
</Section>
<!-- Additional libraries can be added as shown below. These folders and items can appear underneath
the hardcoded root library folder ("OpenSim Library")
You can also add folders and items to the folders of libraries defined earlier on in this file -->
<!--
<Section Name="My Site Library">
<Key Name="foldersFile" Value="MySiteLibrary/MySiteLibraryFolders.xml"/>
<Key Name="itemsFile" Value="MySiteLibrary/MySiteLibraryItems.xml"/>
</Section>
-->
</Nini>

View File

@ -1,14 +1,21 @@
README README
The standard common inventory library is configured here. You can add new inventory Folders and items which will appear in the standard common library for all
folders to the standard library by editing OpenSimLibary/OpenSimLibraryFolders.xml avatars can be configured here. The root folder (currently called OpenSim
You can also add new inventory items to OpenSimLibrary/OpenSimLibrary.xml, Library) is hardcoded, but you can add your own configuration of folders and
as long as they have a corresponding asset entry in bin/OpenSimAssetSet.xml. 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 To add a new library, edit Libraries.xml. The entry in here needs to point to
the grid servers and all the regions. The reasons for this are historical - two further xml files, one which details your library inventory folders and another
this restriction will probably be lifted in the future, at which point the which details your library inventory items. Each inventory item will need to be
inventory items and folders will only need to be configured on the grid inventory associated with an asset. Assets are configured separately in the bin/assets
server (assuming you are running in grid mode rather than standalone) 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. Files in the attic directory are currently unused.