aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs119
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetServer.cs3
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetServerBase.cs102
-rw-r--r--OpenSim/Framework/IAssetLoader.cs37
-rw-r--r--OpenSim/Framework/IAssetServer.cs6
5 files changed, 162 insertions, 105 deletions
diff --git a/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs b/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs
new file mode 100644
index 0000000..6968956
--- /dev/null
+++ b/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs
@@ -0,0 +1,119 @@
1/*
2* Copyright (c) Contributors, http://opensimulator.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28
29using System;
30using System.Collections.Generic;
31using System.IO;
32using System.Xml;
33
34using libsecondlife;
35using Nini.Config;
36
37using OpenSim.Framework;
38using OpenSim.Framework.Console;
39
40/// <summary>
41/// Loads assets from the filesystem location. Not yet a plugin, though it should be.
42/// </summary>
43namespace OpenSim.Framework.AssetLoader.Filesystem
44{
45 public class AssetLoaderFileSystem : IAssetLoader
46 {
47 protected AssetBase CreateAsset(string assetIdStr, string name, string filename, bool isImage)
48 {
49 AssetBase asset = new AssetBase(
50 new LLUUID(assetIdStr),
51 name
52 );
53
54 if (!String.IsNullOrEmpty(filename))
55 {
56 MainLog.Instance.Verbose("ASSETS", "Loading: [{0}][{1}]", name, filename);
57
58 LoadAsset(asset, isImage, filename);
59 }
60 else
61 {
62 MainLog.Instance.Verbose("ASSETS", "Instantiated: [{0}]", name);
63 }
64
65 return asset;
66 }
67
68 protected void LoadAsset(AssetBase info, bool image, string filename)
69 {
70 string dataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "assets"); //+ folder;
71 string fileName = Path.Combine(dataPath, filename);
72 FileInfo fInfo = new FileInfo(fileName);
73 long numBytes = fInfo.Length;
74 FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
75 byte[] idata = new byte[numBytes];
76 BinaryReader br = new BinaryReader(fStream);
77 idata = br.ReadBytes((int) numBytes);
78 br.Close();
79 fStream.Close();
80 info.Data = idata;
81 //info.loaded=true;
82 }
83
84 public void ForEachXmlAsset(Action<AssetBase> action)
85 {
86 List<AssetBase> assets = new List<AssetBase>();
87 // System.Console.WriteLine("trying loading asset into database");
88 string filePath = Path.Combine(Util.configDir(), "OpenSimAssetSet.xml");
89 if (File.Exists(filePath))
90 {
91 try
92 {
93 XmlConfigSource source = new XmlConfigSource(filePath);
94
95 for (int i = 0; i < source.Configs.Count; i++)
96 {
97 // System.Console.WriteLine("loading asset into database");
98 string assetIdStr = source.Configs[i].GetString("assetID", LLUUID.Random().ToString());
99 string name = source.Configs[i].GetString("name", "");
100 sbyte type = (sbyte) source.Configs[i].GetInt("assetType", 0);
101 sbyte invType = (sbyte) source.Configs[i].GetInt("inventoryType", 0);
102 string fileName = source.Configs[i].GetString("fileName", "");
103
104 AssetBase newAsset = CreateAsset(assetIdStr, name, fileName, false);
105
106 newAsset.Type = type;
107 newAsset.InvType = invType;
108 assets.Add(newAsset);
109 }
110 }
111 catch (XmlException e)
112 {
113 MainLog.Instance.Error("ASSETS", "Error loading " + filePath + ": " + e.ToString());
114 }
115 }
116 assets.ForEach(action);
117 }
118 }
119}
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
diff --git a/OpenSim/Framework/IAssetLoader.cs b/OpenSim/Framework/IAssetLoader.cs
new file mode 100644
index 0000000..6bcaa24
--- /dev/null
+++ b/OpenSim/Framework/IAssetLoader.cs
@@ -0,0 +1,37 @@
1/*
2* Copyright (c) Contributors, http://opensimulator.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28
29using System;
30
31namespace OpenSim.Framework
32{
33 public interface IAssetLoader
34 {
35 void ForEachXmlAsset(Action<AssetBase> action);
36 }
37}
diff --git a/OpenSim/Framework/IAssetServer.cs b/OpenSim/Framework/IAssetServer.cs
index afd3687..df36623 100644
--- a/OpenSim/Framework/IAssetServer.cs
+++ b/OpenSim/Framework/IAssetServer.cs
@@ -41,12 +41,6 @@ namespace OpenSim.Framework
41 void UpdateAsset(AssetBase asset); 41 void UpdateAsset(AssetBase asset);
42 void StoreAndCommitAsset(AssetBase asset); 42 void StoreAndCommitAsset(AssetBase asset);
43 void Close(); 43 void Close();
44 void LoadAsset(AssetBase info, bool image, string filename);
45 List<AssetBase> GetDefaultAssets();
46 AssetBase CreateImageAsset(string assetIdStr, string name, string filename);
47 void ForEachDefaultAsset(Action<AssetBase> action);
48 AssetBase CreateAsset(string assetIdStr, string name, string filename, bool isImage);
49 void ForEachXmlAsset(Action<AssetBase> action);
50 } 44 }
51 45
52 // could change to delegate? 46 // could change to delegate?