diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Serialization/ArchiveConstants.cs | 208 |
1 files changed, 208 insertions, 0 deletions
diff --git a/OpenSim/Framework/Serialization/ArchiveConstants.cs b/OpenSim/Framework/Serialization/ArchiveConstants.cs new file mode 100644 index 0000000..ab3c285 --- /dev/null +++ b/OpenSim/Framework/Serialization/ArchiveConstants.cs | |||
@@ -0,0 +1,208 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSimAssetType = OpenSim.Framework.SLUtil.OpenSimAssetType; | ||
33 | |||
34 | namespace OpenSim.Framework.Serialization | ||
35 | { | ||
36 | /// <summary> | ||
37 | /// Constants for the archiving module | ||
38 | /// </summary> | ||
39 | public class ArchiveConstants | ||
40 | { | ||
41 | /// <value> | ||
42 | /// The location of the archive control file | ||
43 | /// </value> | ||
44 | public const string CONTROL_FILE_PATH = "archive.xml"; | ||
45 | |||
46 | /// <value> | ||
47 | /// Path for the assets held in an archive | ||
48 | /// </value> | ||
49 | public const string ASSETS_PATH = "assets/"; | ||
50 | |||
51 | /// <value> | ||
52 | /// Path for the inventory data | ||
53 | /// </value> | ||
54 | public const string INVENTORY_PATH = "inventory/"; | ||
55 | |||
56 | /// <value> | ||
57 | /// Path for regions in a multi-region archive | ||
58 | /// </value> | ||
59 | public const string REGIONS_PATH = "regions/"; | ||
60 | |||
61 | /// <value> | ||
62 | /// Path for the prims file | ||
63 | /// </value> | ||
64 | public const string OBJECTS_PATH = "objects/"; | ||
65 | |||
66 | /// <value> | ||
67 | /// Path for terrains. Technically these may be assets, but I think it's quite nice to split them out. | ||
68 | /// </value> | ||
69 | public const string TERRAINS_PATH = "terrains/"; | ||
70 | |||
71 | /// <value> | ||
72 | /// Path for region settings. | ||
73 | /// </value> | ||
74 | public const string SETTINGS_PATH = "settings/"; | ||
75 | |||
76 | /// <value> | ||
77 | /// Path for region settings. | ||
78 | /// </value> | ||
79 | public const string LANDDATA_PATH = "landdata/"; | ||
80 | |||
81 | /// <value> | ||
82 | /// Path for user profiles | ||
83 | /// </value> | ||
84 | public const string USERS_PATH = "userprofiles/"; | ||
85 | |||
86 | /// <value> | ||
87 | /// The character the separates the uuid from extension information in an archived asset filename | ||
88 | /// </value> | ||
89 | public const string ASSET_EXTENSION_SEPARATOR = "_"; | ||
90 | |||
91 | /// <value> | ||
92 | /// Used to separate components in an inventory node name | ||
93 | /// </value> | ||
94 | public const string INVENTORY_NODE_NAME_COMPONENT_SEPARATOR = "__"; | ||
95 | |||
96 | /// <summary> | ||
97 | /// Template used for creating filenames in OpenSim Archives. | ||
98 | /// </summary> | ||
99 | public const string OAR_OBJECT_FILENAME_TEMPLATE = "{0}_{1:000}-{2:000}-{3:000}__{4}.xml"; | ||
100 | |||
101 | /// <value> | ||
102 | /// Extensions used for asset types in the archive | ||
103 | /// </value> | ||
104 | public static readonly IDictionary<sbyte, string> ASSET_TYPE_TO_EXTENSION = new Dictionary<sbyte, string>(); | ||
105 | public static readonly IDictionary<string, sbyte> EXTENSION_TO_ASSET_TYPE = new Dictionary<string, sbyte>(); | ||
106 | |||
107 | static ArchiveConstants() | ||
108 | { | ||
109 | ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Animation] = ASSET_EXTENSION_SEPARATOR + "animation.bvh"; | ||
110 | ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Bodypart] = ASSET_EXTENSION_SEPARATOR + "bodypart.txt"; | ||
111 | ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.CallingCard] = ASSET_EXTENSION_SEPARATOR + "callingcard.txt"; | ||
112 | ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Clothing] = ASSET_EXTENSION_SEPARATOR + "clothing.txt"; | ||
113 | ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Folder] = ASSET_EXTENSION_SEPARATOR + "folder.txt"; // Not sure if we'll ever see this | ||
114 | ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Gesture] = ASSET_EXTENSION_SEPARATOR + "gesture.txt"; | ||
115 | ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.ImageJPEG] = ASSET_EXTENSION_SEPARATOR + "image.jpg"; | ||
116 | ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.ImageTGA] = ASSET_EXTENSION_SEPARATOR + "image.tga"; | ||
117 | ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Landmark] = ASSET_EXTENSION_SEPARATOR + "landmark.txt"; | ||
118 | ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.LSLBytecode] = ASSET_EXTENSION_SEPARATOR + "bytecode.lso"; | ||
119 | ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.LSLText] = ASSET_EXTENSION_SEPARATOR + "script.lsl"; | ||
120 | ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Mesh] = ASSET_EXTENSION_SEPARATOR + "mesh.llmesh"; | ||
121 | ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Notecard] = ASSET_EXTENSION_SEPARATOR + "notecard.txt"; | ||
122 | ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Object] = ASSET_EXTENSION_SEPARATOR + "object.xml"; | ||
123 | ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Simstate] = ASSET_EXTENSION_SEPARATOR + "simstate.bin"; // Not sure if we'll ever see this | ||
124 | ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Sound] = ASSET_EXTENSION_SEPARATOR + "sound.ogg"; | ||
125 | ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.SoundWAV] = ASSET_EXTENSION_SEPARATOR + "sound.wav"; | ||
126 | ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Texture] = ASSET_EXTENSION_SEPARATOR + "texture.jp2"; | ||
127 | ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.TextureTGA] = ASSET_EXTENSION_SEPARATOR + "texture.tga"; | ||
128 | ASSET_TYPE_TO_EXTENSION[(sbyte)OpenSimAssetType.Material] = ASSET_EXTENSION_SEPARATOR + "material.xml"; // Not sure if we'll ever see this | ||
129 | |||
130 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "animation.bvh"] = (sbyte)AssetType.Animation; | ||
131 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "bodypart.txt"] = (sbyte)AssetType.Bodypart; | ||
132 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "callingcard.txt"] = (sbyte)AssetType.CallingCard; | ||
133 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "clothing.txt"] = (sbyte)AssetType.Clothing; | ||
134 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "folder.txt"] = (sbyte)AssetType.Folder; | ||
135 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "gesture.txt"] = (sbyte)AssetType.Gesture; | ||
136 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "image.jpg"] = (sbyte)AssetType.ImageJPEG; | ||
137 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "image.tga"] = (sbyte)AssetType.ImageTGA; | ||
138 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "landmark.txt"] = (sbyte)AssetType.Landmark; | ||
139 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "bytecode.lso"] = (sbyte)AssetType.LSLBytecode; | ||
140 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "script.lsl"] = (sbyte)AssetType.LSLText; | ||
141 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "mesh.llmesh"] = (sbyte)AssetType.Mesh; | ||
142 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "notecard.txt"] = (sbyte)AssetType.Notecard; | ||
143 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "object.xml"] = (sbyte)AssetType.Object; | ||
144 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "simstate.bin"] = (sbyte)AssetType.Simstate; | ||
145 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "sound.ogg"] = (sbyte)AssetType.Sound; | ||
146 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "sound.wav"] = (sbyte)AssetType.SoundWAV; | ||
147 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.jp2"] = (sbyte)AssetType.Texture; | ||
148 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.tga"] = (sbyte)AssetType.TextureTGA; | ||
149 | EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "material.xml"] = (sbyte)OpenSimAssetType.Material; | ||
150 | } | ||
151 | |||
152 | public static string CreateOarLandDataPath(LandData ld) | ||
153 | { | ||
154 | return string.Format("{0}{1}.xml", ArchiveConstants.LANDDATA_PATH, ld.GlobalID); | ||
155 | } | ||
156 | |||
157 | /// <summary> | ||
158 | /// Create the filename used to store an object in an OpenSim Archive. | ||
159 | /// </summary> | ||
160 | /// <param name="objectName"></param> | ||
161 | /// <param name="uuid"></param> | ||
162 | /// <param name="pos"></param> | ||
163 | /// <returns></returns> | ||
164 | public static string CreateOarObjectFilename(string objectName, UUID uuid, Vector3 pos) | ||
165 | { | ||
166 | return string.Format( | ||
167 | OAR_OBJECT_FILENAME_TEMPLATE, objectName, | ||
168 | Math.Round(pos.X), Math.Round(pos.Y), Math.Round(pos.Z), | ||
169 | uuid); | ||
170 | } | ||
171 | |||
172 | /// <summary> | ||
173 | /// Create the path used to store an object in an OpenSim Archives. | ||
174 | /// </summary> | ||
175 | /// <param name="objectName"></param> | ||
176 | /// <param name="uuid"></param> | ||
177 | /// <param name="pos"></param> | ||
178 | /// <returns></returns> | ||
179 | public static string CreateOarObjectPath(string objectName, UUID uuid, Vector3 pos) | ||
180 | { | ||
181 | return OBJECTS_PATH + CreateOarObjectFilename(objectName, uuid, pos); | ||
182 | } | ||
183 | |||
184 | /// <summary> | ||
185 | /// Extract a plain path from an IAR path | ||
186 | /// </summary> | ||
187 | /// <param name="iarPath"></param> | ||
188 | /// <returns></returns> | ||
189 | public static string ExtractPlainPathFromIarPath(string iarPath) | ||
190 | { | ||
191 | List<string> plainDirs = new List<string>(); | ||
192 | |||
193 | string[] iarDirs = iarPath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); | ||
194 | |||
195 | foreach (string iarDir in iarDirs) | ||
196 | { | ||
197 | if (!iarDir.Contains(ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR)) | ||
198 | plainDirs.Add(iarDir); | ||
199 | |||
200 | int i = iarDir.LastIndexOf(ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR); | ||
201 | |||
202 | plainDirs.Add(iarDir.Remove(i)); | ||
203 | } | ||
204 | |||
205 | return string.Join("/", plainDirs.ToArray()); | ||
206 | } | ||
207 | } | ||
208 | } | ||