aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/Cache
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Communications/Cache')
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetServer.cs3
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetServerBase.cs102
2 files changed, 6 insertions, 99 deletions
diff --git a/OpenSim/Framework/Communications/Cache/AssetServer.cs b/OpenSim/Framework/Communications/Cache/AssetServer.cs
index 692ee1e..575e80a 100644
--- a/OpenSim/Framework/Communications/Cache/AssetServer.cs
+++ b/OpenSim/Framework/Communications/Cache/AssetServer.cs
@@ -122,8 +122,7 @@ namespace OpenSim.Framework.Communications.Cache
122 { 122 {
123 MainLog.Instance.Verbose("LOCAL ASSET SERVER", "Setting up asset database"); 123 MainLog.Instance.Verbose("LOCAL ASSET SERVER", "Setting up asset database");
124 124
125 ForEachDefaultAsset(StoreAsset); 125 base.LoadDefaultAssets();
126 ForEachXmlAsset(StoreAsset);
127 } 126 }
128 } 127 }
129 128
diff --git a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs
index 1b2c836..2153fbf 100644
--- a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs
+++ b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs
@@ -28,12 +28,10 @@
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.IO;
32using System.Threading; 31using System.Threading;
33using System.Xml;
34using libsecondlife; 32using libsecondlife;
35using Nini.Config;
36using OpenSim.Framework.Console; 33using OpenSim.Framework.Console;
34using OpenSim.Framework.AssetLoader.Filesystem;
37 35
38namespace OpenSim.Framework.Communications.Cache 36namespace OpenSim.Framework.Communications.Cache
39{ 37{
@@ -45,6 +43,9 @@ namespace OpenSim.Framework.Communications.Cache
45 protected IAssetProvider m_assetProviderPlugin; 43 protected IAssetProvider m_assetProviderPlugin;
46 protected object syncLock = new object(); 44 protected object syncLock = new object();
47 45
46 // Temporarily hardcoded - should be a plugin
47 protected IAssetLoader assetLoader = new AssetLoaderFileSystem();
48
48 protected abstract void StoreAsset(AssetBase asset); 49 protected abstract void StoreAsset(AssetBase asset);
49 protected abstract void CommitAssets(); 50 protected abstract void CommitAssets();
50 51
@@ -85,8 +86,7 @@ namespace OpenSim.Framework.Communications.Cache
85 { 86 {
86 MainLog.Instance.Verbose("ASSETSERVER", "Setting up asset database"); 87 MainLog.Instance.Verbose("ASSETSERVER", "Setting up asset database");
87 88
88 ForEachDefaultAsset(StoreAsset); 89 assetLoader.ForEachXmlAsset(StoreAsset);
89 ForEachXmlAsset(StoreAsset);
90 90
91 CommitAssets(); 91 CommitAssets();
92 } 92 }
@@ -119,25 +119,6 @@ namespace OpenSim.Framework.Communications.Cache
119 } 119 }
120 } 120 }
121 121
122 public void LoadAsset(AssetBase info, bool image, string filename)
123 {
124 //should request Asset from storage manager
125 //but for now read from file
126
127 string dataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "assets"); //+ folder;
128 string fileName = Path.Combine(dataPath, filename);
129 FileInfo fInfo = new FileInfo(fileName);
130 long numBytes = fInfo.Length;
131 FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
132 byte[] idata = new byte[numBytes];
133 BinaryReader br = new BinaryReader(fStream);
134 idata = br.ReadBytes((int) numBytes);
135 br.Close();
136 fStream.Close();
137 info.Data = idata;
138 //info.loaded=true;
139 }
140
141 public void SetReceiver(IAssetReceiver receiver) 122 public void SetReceiver(IAssetReceiver receiver)
142 { 123 {
143 _receiver = receiver; 124 _receiver = receiver;
@@ -179,78 +160,5 @@ namespace OpenSim.Framework.Communications.Cache
179 public void SetServerInfo(string ServerUrl, string ServerKey) 160 public void SetServerInfo(string ServerUrl, string ServerKey)
180 { 161 {
181 } 162 }
182
183 public virtual List<AssetBase> GetDefaultAssets()
184 {
185 List<AssetBase> assets = new List<AssetBase>();
186 return assets;
187 }
188
189 public AssetBase CreateImageAsset(string assetIdStr, string name, string filename)
190 {
191 return CreateAsset(assetIdStr, name, filename, true);
192 }
193
194 public void ForEachDefaultAsset(Action<AssetBase> action)
195 {
196 List<AssetBase> assets = GetDefaultAssets();
197 assets.ForEach(action);
198 }
199
200 public AssetBase CreateAsset(string assetIdStr, string name, string filename, bool isImage)
201 {
202 AssetBase asset = new AssetBase(
203 new LLUUID(assetIdStr),
204 name
205 );
206
207 if (!String.IsNullOrEmpty(filename))
208 {
209 MainLog.Instance.Verbose("ASSETS", "Loading: [{0}][{1}]", name, filename);
210
211 LoadAsset(asset, isImage, filename);
212 }
213 else
214 {
215 MainLog.Instance.Verbose("ASSETS", "Instantiated: [{0}]", name);
216 }
217
218 return asset;
219 }
220
221 public void ForEachXmlAsset(Action<AssetBase> action)
222 {
223 List<AssetBase> assets = new List<AssetBase>();
224 // System.Console.WriteLine("trying loading asset into database");
225 string filePath = Path.Combine(Util.configDir(), "OpenSimAssetSet.xml");
226 if (File.Exists(filePath))
227 {
228 try
229 {
230 XmlConfigSource source = new XmlConfigSource(filePath);
231
232 for (int i = 0; i < source.Configs.Count; i++)
233 {
234 // System.Console.WriteLine("loading asset into database");
235 string assetIdStr = source.Configs[i].GetString("assetID", LLUUID.Random().ToString());
236 string name = source.Configs[i].GetString("name", "");
237 sbyte type = (sbyte) source.Configs[i].GetInt("assetType", 0);
238 sbyte invType = (sbyte) source.Configs[i].GetInt("inventoryType", 0);
239 string fileName = source.Configs[i].GetString("fileName", "");
240
241 AssetBase newAsset = CreateAsset(assetIdStr, name, fileName, false);
242
243 newAsset.Type = type;
244 newAsset.InvType = invType;
245 assets.Add(newAsset);
246 }
247 }
248 catch (XmlException e)
249 {
250 MainLog.Instance.Error("ASSETS", "Error loading " + filePath + ": " + e.ToString());
251 }
252 }
253 assets.ForEach(action);
254 }
255 } 163 }
256} \ No newline at end of file 164} \ No newline at end of file