29 using System.Diagnostics;
30 using System.Collections.Generic;
33 using System.Threading;
34 using System.Reflection;
35 using OpenSim.Framework;
36 using OpenSim.Framework.Console;
37 using OpenSim.Server.Base;
38 using OpenSim.Services.Base;
39 using OpenSim.Services.Interfaces;
44 namespace OpenSim.Server.Handlers.BakedTextures
48 private static readonly ILog m_log =
50 MethodBase.GetCurrentMethod().DeclaringType);
54 private System.Text.UTF8Encoding utf8encoding =
55 new System.Text.UTF8Encoding();
57 public XBakes(IConfigSource config) : base(config)
59 MainConsole.Instance.Commands.AddCommand(
"fs",
false,
60 "delete bakes",
"delete bakes <ID>",
61 "Delete agent's baked textures from server",
64 IConfig assetConfig = config.Configs[
"BakedTextureService"];
65 if (assetConfig == null)
67 throw new Exception(
"No BakedTextureService configuration");
70 m_FSBase = assetConfig.GetString(
"BaseDirectory", String.Empty);
71 if (m_FSBase == String.Empty)
73 m_log.ErrorFormat(
"[BAKES]: BaseDirectory not specified");
74 throw new Exception(
"Configuration error");
77 m_log.Info(
"[BAKES]: XBakes service enabled");
80 public string Get(
string id)
82 string file = HashToFile(
id);
83 string diskFile = Path.Combine(m_FSBase, file);
85 if (
File.Exists(diskFile))
89 byte[] content = File.ReadAllBytes(diskFile);
91 return utf8encoding.GetString(content);
100 public void Store(
string id,
string sdata)
102 string file = HashToFile(
id);
103 string diskFile = Path.Combine(m_FSBase, file);
105 Directory.CreateDirectory(Path.GetDirectoryName(diskFile));
107 File.Delete(diskFile);
109 byte[] data = utf8encoding.GetBytes(sdata);
111 using (FileStream fs = File.Create(diskFile))
112 fs.Write(data, 0, data.Length);
115 private void HandleDeleteBakes(
string module,
string[] args)
119 MainConsole.Instance.Output(
"Syntax: delete bakes <ID>");
123 string file = HashToFile(args[2]);
124 string diskFile = Path.Combine(m_FSBase, file);
126 if (
File.Exists(diskFile))
128 File.Delete(diskFile);
129 MainConsole.Instance.Output(
"Bakes deleted");
132 MainConsole.Instance.Output(
"Bakes not found");
137 return Path.Combine(hash.Substring(0, 2),
138 Path.Combine(hash.Substring(2, 2),
139 Path.Combine(hash.Substring(4, 2),
140 hash.Substring(6, 4))));
145 return Path.Combine(HashToPath(hash), hash);
XBakes(IConfigSource config)
void Store(string id, string sdata)
string HashToFile(string hash)
string HashToPath(string hash)
Interactive OpenSim region server