aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/Cache/FileAssetClient.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Communications/Cache/FileAssetClient.cs')
-rw-r--r--OpenSim/Framework/Communications/Cache/FileAssetClient.cs121
1 files changed, 0 insertions, 121 deletions
diff --git a/OpenSim/Framework/Communications/Cache/FileAssetClient.cs b/OpenSim/Framework/Communications/Cache/FileAssetClient.cs
deleted file mode 100644
index 8d03f56..0000000
--- a/OpenSim/Framework/Communications/Cache/FileAssetClient.cs
+++ /dev/null
@@ -1,121 +0,0 @@
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 OpenSimulator 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
28using System.IO;
29using System.Reflection;
30using log4net;
31using System.Xml.Serialization;
32
33namespace OpenSim.Framework.Communications.Cache
34{
35 public class FileAssetClient : AssetServerBase
36 {
37
38 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
39
40 #region IPlugin
41
42 public override string Name
43 {
44 get { return "File"; }
45 }
46
47 public override string Version
48 {
49 get { return "1.0"; }
50 }
51
52 public override void Initialise(ConfigSettings p_set, string p_url)
53 {
54 m_log.Debug("[FILEASSET] Plugin configured initialisation");
55 Initialise(p_url);
56 }
57
58 #endregion
59
60 private string m_dir;
61 private readonly XmlSerializer m_xs = new XmlSerializer(typeof(AssetBase));
62
63 public FileAssetClient() {}
64
65 public FileAssetClient(string p_url)
66 {
67 m_log.Debug("[FILEASSET] Direct constructor");
68 Initialise(p_url);
69 }
70
71 public void Initialise(string dir)
72 {
73 if (!Directory.Exists(dir))
74 {
75 Directory.CreateDirectory(dir);
76 }
77 m_dir = dir;
78 }
79
80 public override void StoreAsset(AssetBase asset)
81 {
82 byte[] idBytes = asset.FullID.Guid.ToByteArray();
83
84 string cdir = m_dir + Path.DirectorySeparatorChar + idBytes[0]
85 + Path.DirectorySeparatorChar + idBytes[1];
86
87 if (!Directory.Exists(m_dir + Path.DirectorySeparatorChar + idBytes[0]))
88 Directory.CreateDirectory(m_dir + Path.DirectorySeparatorChar + idBytes[0]);
89
90 if (!Directory.Exists(cdir))
91 Directory.CreateDirectory(cdir);
92
93 FileStream x = new FileStream(cdir + Path.DirectorySeparatorChar + asset.FullID + ".xml", FileMode.Create);
94 m_xs.Serialize(x, asset);
95
96 x.Flush();
97 x.Close();
98 }
99
100 public override void UpdateAsset(AssetBase asset)
101 {
102 StoreAsset(asset);
103 }
104
105 protected override AssetBase GetAsset(AssetRequest req)
106 {
107 byte[] idBytes = req.AssetID.Guid.ToByteArray();
108
109 string cdir = m_dir + Path.DirectorySeparatorChar + idBytes[0]
110 + Path.DirectorySeparatorChar + idBytes[1];
111 if (File.Exists(cdir + Path.DirectorySeparatorChar + req.AssetID + ".xml"))
112 {
113 FileStream x = File.OpenRead(cdir + Path.DirectorySeparatorChar + req.AssetID + ".xml");
114 AssetBase ret = (AssetBase) m_xs.Deserialize(x);
115 x.Close();
116 return ret;
117 }
118 return null;
119 }
120 }
121}