aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Framework/Communications/Cache/FileAssetClient.cs56
-rw-r--r--OpenSim/Region/Application/OpenSimBase.cs4
2 files changed, 60 insertions, 0 deletions
diff --git a/OpenSim/Framework/Communications/Cache/FileAssetClient.cs b/OpenSim/Framework/Communications/Cache/FileAssetClient.cs
new file mode 100644
index 0000000..fcab349
--- /dev/null
+++ b/OpenSim/Framework/Communications/Cache/FileAssetClient.cs
@@ -0,0 +1,56 @@
1using System.IO;
2using System.Xml.Serialization;
3
4namespace OpenSim.Framework.Communications.Cache
5{
6 public class FileAssetClient : AssetServerBase
7 {
8 private readonly string m_dir;
9 private readonly XmlSerializer m_xs = new XmlSerializer(typeof(AssetBase));
10
11 public FileAssetClient(string dir)
12 {
13 if(!Directory.Exists(dir))
14 {
15 Directory.CreateDirectory(dir);
16 }
17 m_dir = dir;
18 }
19 public override void StoreAsset(AssetBase asset)
20 {
21 string cdir = m_dir + Path.DirectorySeparatorChar + asset.FullID.Data[0]
22 + Path.DirectorySeparatorChar + asset.FullID.Data[1];
23
24 if (!Directory.Exists(m_dir + Path.DirectorySeparatorChar + asset.FullID.Data[0]))
25 Directory.CreateDirectory(m_dir + Path.DirectorySeparatorChar + asset.FullID.Data[0]);
26
27 if (!Directory.Exists(cdir))
28 Directory.CreateDirectory(cdir);
29
30 FileStream x = new FileStream(cdir + Path.DirectorySeparatorChar + asset.FullID + ".xml", FileMode.Create);
31 m_xs.Serialize(x, asset);
32
33 x.Flush();
34 x.Close();
35 }
36
37 public override void UpdateAsset(AssetBase asset)
38 {
39 StoreAsset(asset);
40 }
41
42 protected override AssetBase GetAsset(AssetRequest req)
43 {
44 string cdir = m_dir + Path.DirectorySeparatorChar + req.AssetID.Data[0]
45 + Path.DirectorySeparatorChar + req.AssetID.Data[1];
46 if (File.Exists(cdir + Path.DirectorySeparatorChar + req.AssetID + ".xml"))
47 {
48 FileStream x = File.OpenRead(cdir + Path.DirectorySeparatorChar + req.AssetID + ".xml");
49 AssetBase ret = (AssetBase) m_xs.Deserialize(x);
50 x.Close();
51 return ret;
52 }
53 return null;
54 }
55 }
56}
diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs
index 78064da..ce4fdfe 100644
--- a/OpenSim/Region/Application/OpenSimBase.cs
+++ b/OpenSim/Region/Application/OpenSimBase.cs
@@ -421,6 +421,10 @@ namespace OpenSim
421 { 421 {
422 assetServer = new GridAssetClient(m_networkServersInfo.AssetURL); 422 assetServer = new GridAssetClient(m_networkServersInfo.AssetURL);
423 } 423 }
424 else if (m_assetStorage == "file")
425 {
426 assetServer = new FileAssetClient(m_networkServersInfo.AssetURL);
427 }
424 else 428 else
425 { 429 {
426 SQLAssetServer sqlAssetServer = new SQLAssetServer(m_standaloneAssetPlugin, m_standaloneAssetSource); 430 SQLAssetServer sqlAssetServer = new SQLAssetServer(m_standaloneAssetPlugin, m_standaloneAssetSource);