From 1b1649791fbfdd57173c16f0bf2353898ceb8852 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Sat, 29 Dec 2007 19:01:55 +0000 Subject: [PATCH] Allow OpenSim operators to specify their own asset sets without needing to change the default OpenSim set. Equivalent changes to allow operators to also specify their own standard inventory library directories and items to follow. --- .../Filesystem/AssetLoaderFileSystem.cs | 78 ++++++++++++++----- OpenSim/Framework/Util.cs | 5 ++ bin/assets/AssetSets.xml | 13 ++++ bin/assets/README.txt | 12 +++ 4 files changed, 89 insertions(+), 19 deletions(-) create mode 100644 bin/assets/AssetSets.xml create mode 100644 bin/assets/README.txt diff --git a/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs b/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs index bffced842b..46e6ae1077 100644 --- a/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs +++ b/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs @@ -44,18 +44,18 @@ namespace OpenSim.Framework.AssetLoader.Filesystem { public class AssetLoaderFileSystem : IAssetLoader { - protected AssetBase CreateAsset(string assetIdStr, string name, string filename, bool isImage) + protected AssetBase CreateAsset(string assetIdStr, string name, string path, bool isImage) { AssetBase asset = new AssetBase( new LLUUID(assetIdStr), name ); - if (!String.IsNullOrEmpty(filename)) + if (!String.IsNullOrEmpty(path)) { - MainLog.Instance.Verbose("ASSETS", "Loading: [{0}][{1}]", name, filename); + MainLog.Instance.Verbose("ASSETS", "Loading: [{0}][{1}]", name, path); - LoadAsset(asset, isImage, filename); + LoadAsset(asset, isImage, path); } else { @@ -65,13 +65,11 @@ namespace OpenSim.Framework.AssetLoader.Filesystem return asset; } - protected void LoadAsset(AssetBase info, bool image, string filename) + protected void LoadAsset(AssetBase info, bool image, string path) { - string dataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "assets/OpenSimAssetSet"); //+ folder; - string fileName = Path.Combine(dataPath, filename); - FileInfo fInfo = new FileInfo(fileName); + FileInfo fInfo = new FileInfo(path); long numBytes = fInfo.Length; - FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); + FileStream fStream = new FileStream(path, FileMode.Open, FileAccess.Read); byte[] idata = new byte[numBytes]; BinaryReader br = new BinaryReader(fStream); idata = br.ReadBytes((int) numBytes); @@ -83,25 +81,64 @@ namespace OpenSim.Framework.AssetLoader.Filesystem public void ForEachXmlAsset(Action action) { - List assets = new List(); - // System.Console.WriteLine("trying loading asset into database"); - string filePath = Path.Combine(Util.configDir(), "assets/OpenSimAssetSet/OpenSimAssetSet.xml"); - if (File.Exists(filePath)) + List assets = new List(); + string assetSetsPath = Path.Combine(Util.assetsDir(), "AssetSets.xml"); + + if (File.Exists(assetSetsPath)) + { + string assetSetPath = "ERROR"; + + try + { + XmlConfigSource source = new XmlConfigSource(assetSetsPath); + + for (int i = 0; i < source.Configs.Count; i++) + { + assetSetPath = source.Configs[i].GetString("file", ""); + + LoadXmlAssetSet(Path.Combine(Util.assetsDir(), assetSetPath), assets); + } + } + catch (XmlException e) + { + MainLog.Instance.Error("ASSETS", "Error loading {0} : {1}", assetSetPath, e); + } + } + else + { + MainLog.Instance.Error( + "ASSETS", + "Asset set control file assets/AssetSets.xml does not exist! No assets loaded."); + } + + assets.ForEach(action); + } + + /// + /// Use the asset set information at path to load assets + /// + /// + /// + protected void LoadXmlAssetSet(string assetSetPath, List assets) + { + MainLog.Instance.Verbose("ASSETS", "Loading asset set {0}", assetSetPath); + + if (File.Exists(assetSetPath)) { try { - XmlConfigSource source = new XmlConfigSource(filePath); + XmlConfigSource source = new XmlConfigSource(assetSetPath); + String dir = Path.GetDirectoryName(assetSetPath); for (int i = 0; i < source.Configs.Count; i++) { - // System.Console.WriteLine("loading asset into database"); string assetIdStr = source.Configs[i].GetString("assetID", LLUUID.Random().ToString()); string name = source.Configs[i].GetString("name", ""); sbyte type = (sbyte) source.Configs[i].GetInt("assetType", 0); sbyte invType = (sbyte) source.Configs[i].GetInt("inventoryType", 0); - string fileName = source.Configs[i].GetString("fileName", ""); + string assetPath = Path.Combine(dir, source.Configs[i].GetString("fileName", "")); - AssetBase newAsset = CreateAsset(assetIdStr, name, fileName, false); + AssetBase newAsset = CreateAsset(assetIdStr, name, assetPath, false); newAsset.Type = type; newAsset.InvType = invType; @@ -110,10 +147,13 @@ namespace OpenSim.Framework.AssetLoader.Filesystem } catch (XmlException e) { - MainLog.Instance.Error("ASSETS", "Error loading " + filePath + ": " + e.ToString()); + MainLog.Instance.Error("ASSETS", "Error loading {0} : {1}", assetSetPath, e); } } - assets.ForEach(action); + else + { + MainLog.Instance.Error("ASSETS", "Asset set file {0} does not exist!", assetSetPath); + } } } } diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 08b3a9d165..c742cf3cdd 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -318,6 +318,11 @@ namespace OpenSim.Framework temp = "."; return temp; } + + public static string assetsDir() + { + return "assets"; + } public static string configDir() { diff --git a/bin/assets/AssetSets.xml b/bin/assets/AssetSets.xml new file mode 100644 index 0000000000..b827e59b8c --- /dev/null +++ b/bin/assets/AssetSets.xml @@ -0,0 +1,13 @@ + + +
+ +
+ + +
diff --git a/bin/assets/README.txt b/bin/assets/README.txt new file mode 100644 index 0000000000..02cc78f8ad --- /dev/null +++ b/bin/assets/README.txt @@ -0,0 +1,12 @@ +README + +OpenSim comes with a default asset set contained in the OpenSimAssetSet +directory. You can also load up your own asset set to OpenSim on startup by +making a file entry in AssetSets.xml. This file should point towards an XML +file which details the assets in your asset set. The +OpenSimAssetSet/OpenSimAssetSet.xml is a good template for the information +required. + +If you want your assets to show up in the standard inventory library for an +avatar, you will also need to add separate entries to the xml files in the +bin/inventory configuration directory.