29 using System.Collections.Generic;
31 using System.Reflection;
40 namespace OpenSim.Framework.AssetLoader.Filesystem
44 private static readonly UUID LIBRARY_OWNER_ID =
new UUID(
"11111111-1111-0000-0000-000100bba000");
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49 AssetBase asset =
new AssetBase(
new UUID(assetIdStr), name, type, LIBRARY_OWNER_ID.ToString());
51 if (!String.IsNullOrEmpty(path))
55 LoadAsset(asset, path);
59 m_log.InfoFormat(
"[ASSETS]: Instantiated: [{0}]", name);
73 FileInfo fInfo =
new FileInfo(path);
74 long numBytes = fInfo.Length;
77 FileStream fStream =
new FileStream(path, FileMode.Open, FileAccess.Read);
78 byte[] idata =
new byte[numBytes];
79 BinaryReader br =
new BinaryReader(fStream);
80 idata = br.ReadBytes((int)numBytes);
88 m_log.ErrorFormat(
"[ASSETS]: file: [{0}] not found !", path);
94 List<AssetBase> assets =
new List<AssetBase>();
95 if (
File.Exists(assetSetFilename))
97 string assetSetPath =
"ERROR";
98 string assetRootPath =
"";
101 XmlConfigSource source =
new XmlConfigSource(assetSetFilename);
102 assetRootPath = Path.GetFullPath(source.SavePath);
103 assetRootPath = Path.GetDirectoryName(assetRootPath);
105 for (
int i = 0; i < source.Configs.Count; i++)
107 assetSetPath = source.Configs[i].GetString(
"file", String.Empty);
109 LoadXmlAssetSet(Path.Combine(assetRootPath, assetSetPath), assets);
112 catch (XmlException e)
114 m_log.ErrorFormat(
"[ASSETS]: Error loading {0} : {1}", assetSetPath, e);
119 m_log.ErrorFormat(
"[ASSETS]: Asset set control file {0} does not exist! No assets loaded.", assetSetFilename);
122 assets.ForEach(action);
134 if (
File.Exists(assetSetPath))
138 XmlConfigSource source =
new XmlConfigSource(assetSetPath);
139 String dir = Path.GetDirectoryName(assetSetPath);
141 for (
int i = 0; i < source.Configs.Count; i++)
143 string assetIdStr = source.Configs[i].GetString(
"assetID", UUID.Random().ToString());
144 string name = source.Configs[i].GetString(
"name", String.Empty);
145 sbyte type = (sbyte)source.Configs[i].GetInt(
"assetType", 0);
146 string assetPath = Path.Combine(dir, source.Configs[i].GetString(
"fileName", String.Empty));
148 AssetBase newAsset = CreateAsset(assetIdStr, name, assetPath, type);
150 newAsset.Type = type;
151 assets.Add(newAsset);
154 catch (XmlException e)
156 m_log.ErrorFormat(
"[ASSETS]: Error loading {0} : {1}", assetSetPath, e);
161 m_log.ErrorFormat(
"[ASSETS]: Asset set file {0} does not exist!", assetSetPath);
void ForEachDefaultXmlAsset(string assetSetFilename, Action< AssetBase > action)
static void LoadXmlAssetSet(string assetSetPath, List< AssetBase > assets)
Use the asset set information at path to load assets
Asset class. All Assets are reference by this class or a class derived from this class ...
static AssetBase CreateAsset(string assetIdStr, string name, string path, sbyte type)
static void LoadAsset(AssetBase info, string path)
Interactive OpenSim region server