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.
afrisby
Justin Clarke Casey 2007-12-29 19:01:55 +00:00
parent 1efc7d8279
commit 1b1649791f
4 changed files with 89 additions and 19 deletions

View File

@ -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<AssetBase> action)
{
List<AssetBase> assets = new List<AssetBase>();
// System.Console.WriteLine("trying loading asset into database");
string filePath = Path.Combine(Util.configDir(), "assets/OpenSimAssetSet/OpenSimAssetSet.xml");
if (File.Exists(filePath))
List<AssetBase> assets = new List<AssetBase>();
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);
}
/// <summary>
/// Use the asset set information at path to load assets
/// </summary>
/// <param name="path"></param>
/// <param name="assets"></param>
protected void LoadXmlAssetSet(string assetSetPath, List<AssetBase> 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);
}
}
}
}

View File

@ -318,6 +318,11 @@ namespace OpenSim.Framework
temp = ".";
return temp;
}
public static string assetsDir()
{
return "assets";
}
public static string configDir()
{

13
bin/assets/AssetSets.xml Normal file
View File

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

12
bin/assets/README.txt Normal file
View File

@ -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.