diff options
author | Justin Clarke Casey | 2007-12-29 19:01:55 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2007-12-29 19:01:55 +0000 |
commit | 1b1649791fbfdd57173c16f0bf2353898ceb8852 (patch) | |
tree | 3d9062f9241cb13783044b44d0b1d59acc84126c /OpenSim/Framework/AssetLoader/Filesystem | |
parent | Set svn:eol-style. (diff) | |
download | opensim-SC_OLD-1b1649791fbfdd57173c16f0bf2353898ceb8852.zip opensim-SC_OLD-1b1649791fbfdd57173c16f0bf2353898ceb8852.tar.gz opensim-SC_OLD-1b1649791fbfdd57173c16f0bf2353898ceb8852.tar.bz2 opensim-SC_OLD-1b1649791fbfdd57173c16f0bf2353898ceb8852.tar.xz |
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.
Diffstat (limited to 'OpenSim/Framework/AssetLoader/Filesystem')
-rw-r--r-- | OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs | 78 |
1 files changed, 59 insertions, 19 deletions
diff --git a/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs b/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs index bffced8..46e6ae1 100644 --- a/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs +++ b/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs | |||
@@ -44,18 +44,18 @@ namespace OpenSim.Framework.AssetLoader.Filesystem | |||
44 | { | 44 | { |
45 | public class AssetLoaderFileSystem : IAssetLoader | 45 | public class AssetLoaderFileSystem : IAssetLoader |
46 | { | 46 | { |
47 | protected AssetBase CreateAsset(string assetIdStr, string name, string filename, bool isImage) | 47 | protected AssetBase CreateAsset(string assetIdStr, string name, string path, bool isImage) |
48 | { | 48 | { |
49 | AssetBase asset = new AssetBase( | 49 | AssetBase asset = new AssetBase( |
50 | new LLUUID(assetIdStr), | 50 | new LLUUID(assetIdStr), |
51 | name | 51 | name |
52 | ); | 52 | ); |
53 | 53 | ||
54 | if (!String.IsNullOrEmpty(filename)) | 54 | if (!String.IsNullOrEmpty(path)) |
55 | { | 55 | { |
56 | MainLog.Instance.Verbose("ASSETS", "Loading: [{0}][{1}]", name, filename); | 56 | MainLog.Instance.Verbose("ASSETS", "Loading: [{0}][{1}]", name, path); |
57 | 57 | ||
58 | LoadAsset(asset, isImage, filename); | 58 | LoadAsset(asset, isImage, path); |
59 | } | 59 | } |
60 | else | 60 | else |
61 | { | 61 | { |
@@ -65,13 +65,11 @@ namespace OpenSim.Framework.AssetLoader.Filesystem | |||
65 | return asset; | 65 | return asset; |
66 | } | 66 | } |
67 | 67 | ||
68 | protected void LoadAsset(AssetBase info, bool image, string filename) | 68 | protected void LoadAsset(AssetBase info, bool image, string path) |
69 | { | 69 | { |
70 | string dataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "assets/OpenSimAssetSet"); //+ folder; | 70 | FileInfo fInfo = new FileInfo(path); |
71 | string fileName = Path.Combine(dataPath, filename); | ||
72 | FileInfo fInfo = new FileInfo(fileName); | ||
73 | long numBytes = fInfo.Length; | 71 | long numBytes = fInfo.Length; |
74 | FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); | 72 | FileStream fStream = new FileStream(path, FileMode.Open, FileAccess.Read); |
75 | byte[] idata = new byte[numBytes]; | 73 | byte[] idata = new byte[numBytes]; |
76 | BinaryReader br = new BinaryReader(fStream); | 74 | BinaryReader br = new BinaryReader(fStream); |
77 | idata = br.ReadBytes((int) numBytes); | 75 | idata = br.ReadBytes((int) numBytes); |
@@ -83,25 +81,64 @@ namespace OpenSim.Framework.AssetLoader.Filesystem | |||
83 | 81 | ||
84 | public void ForEachXmlAsset(Action<AssetBase> action) | 82 | public void ForEachXmlAsset(Action<AssetBase> action) |
85 | { | 83 | { |
86 | List<AssetBase> assets = new List<AssetBase>(); | 84 | List<AssetBase> assets = new List<AssetBase>(); |
87 | // System.Console.WriteLine("trying loading asset into database"); | 85 | string assetSetsPath = Path.Combine(Util.assetsDir(), "AssetSets.xml"); |
88 | string filePath = Path.Combine(Util.configDir(), "assets/OpenSimAssetSet/OpenSimAssetSet.xml"); | 86 | |
89 | if (File.Exists(filePath)) | 87 | if (File.Exists(assetSetsPath)) |
90 | { | 88 | { |
89 | string assetSetPath = "ERROR"; | ||
90 | |||
91 | try | 91 | try |
92 | { | 92 | { |
93 | XmlConfigSource source = new XmlConfigSource(filePath); | 93 | XmlConfigSource source = new XmlConfigSource(assetSetsPath); |
94 | |||
95 | for (int i = 0; i < source.Configs.Count; i++) | ||
96 | { | ||
97 | assetSetPath = source.Configs[i].GetString("file", ""); | ||
98 | |||
99 | LoadXmlAssetSet(Path.Combine(Util.assetsDir(), assetSetPath), assets); | ||
100 | } | ||
101 | } | ||
102 | catch (XmlException e) | ||
103 | { | ||
104 | MainLog.Instance.Error("ASSETS", "Error loading {0} : {1}", assetSetPath, e); | ||
105 | } | ||
106 | } | ||
107 | else | ||
108 | { | ||
109 | MainLog.Instance.Error( | ||
110 | "ASSETS", | ||
111 | "Asset set control file assets/AssetSets.xml does not exist! No assets loaded."); | ||
112 | } | ||
113 | |||
114 | assets.ForEach(action); | ||
115 | } | ||
116 | |||
117 | /// <summary> | ||
118 | /// Use the asset set information at path to load assets | ||
119 | /// </summary> | ||
120 | /// <param name="path"></param> | ||
121 | /// <param name="assets"></param> | ||
122 | protected void LoadXmlAssetSet(string assetSetPath, List<AssetBase> assets) | ||
123 | { | ||
124 | MainLog.Instance.Verbose("ASSETS", "Loading asset set {0}", assetSetPath); | ||
125 | |||
126 | if (File.Exists(assetSetPath)) | ||
127 | { | ||
128 | try | ||
129 | { | ||
130 | XmlConfigSource source = new XmlConfigSource(assetSetPath); | ||
131 | String dir = Path.GetDirectoryName(assetSetPath); | ||
94 | 132 | ||
95 | for (int i = 0; i < source.Configs.Count; i++) | 133 | for (int i = 0; i < source.Configs.Count; i++) |
96 | { | 134 | { |
97 | // System.Console.WriteLine("loading asset into database"); | ||
98 | string assetIdStr = source.Configs[i].GetString("assetID", LLUUID.Random().ToString()); | 135 | string assetIdStr = source.Configs[i].GetString("assetID", LLUUID.Random().ToString()); |
99 | string name = source.Configs[i].GetString("name", ""); | 136 | string name = source.Configs[i].GetString("name", ""); |
100 | sbyte type = (sbyte) source.Configs[i].GetInt("assetType", 0); | 137 | sbyte type = (sbyte) source.Configs[i].GetInt("assetType", 0); |
101 | sbyte invType = (sbyte) source.Configs[i].GetInt("inventoryType", 0); | 138 | sbyte invType = (sbyte) source.Configs[i].GetInt("inventoryType", 0); |
102 | string fileName = source.Configs[i].GetString("fileName", ""); | 139 | string assetPath = Path.Combine(dir, source.Configs[i].GetString("fileName", "")); |
103 | 140 | ||
104 | AssetBase newAsset = CreateAsset(assetIdStr, name, fileName, false); | 141 | AssetBase newAsset = CreateAsset(assetIdStr, name, assetPath, false); |
105 | 142 | ||
106 | newAsset.Type = type; | 143 | newAsset.Type = type; |
107 | newAsset.InvType = invType; | 144 | newAsset.InvType = invType; |
@@ -110,10 +147,13 @@ namespace OpenSim.Framework.AssetLoader.Filesystem | |||
110 | } | 147 | } |
111 | catch (XmlException e) | 148 | catch (XmlException e) |
112 | { | 149 | { |
113 | MainLog.Instance.Error("ASSETS", "Error loading " + filePath + ": " + e.ToString()); | 150 | MainLog.Instance.Error("ASSETS", "Error loading {0} : {1}", assetSetPath, e); |
114 | } | 151 | } |
115 | } | 152 | } |
116 | assets.ForEach(action); | 153 | else |
154 | { | ||
155 | MainLog.Instance.Error("ASSETS", "Asset set file {0} does not exist!", assetSetPath); | ||
156 | } | ||
117 | } | 157 | } |
118 | } | 158 | } |
119 | } | 159 | } |