diff options
Diffstat (limited to 'OpenSim/Framework/SLUtil.cs')
-rw-r--r-- | OpenSim/Framework/SLUtil.cs | 320 |
1 files changed, 320 insertions, 0 deletions
diff --git a/OpenSim/Framework/SLUtil.cs b/OpenSim/Framework/SLUtil.cs new file mode 100644 index 0000000..2fc5bdf --- /dev/null +++ b/OpenSim/Framework/SLUtil.cs | |||
@@ -0,0 +1,320 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Reflection; | ||
4 | using log4net; | ||
5 | using OpenMetaverse; | ||
6 | |||
7 | namespace OpenSim.Framework | ||
8 | { | ||
9 | public static class SLUtil | ||
10 | { | ||
11 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
12 | |||
13 | #region SL / file extension / content-type conversions | ||
14 | |||
15 | public static string SLAssetTypeToContentType(int assetType) | ||
16 | { | ||
17 | switch ((AssetType)assetType) | ||
18 | { | ||
19 | case AssetType.Texture: | ||
20 | return "image/x-j2c"; | ||
21 | case AssetType.Sound: | ||
22 | return "application/ogg"; | ||
23 | case AssetType.CallingCard: | ||
24 | return "application/vnd.ll.callingcard"; | ||
25 | case AssetType.Landmark: | ||
26 | return "application/vnd.ll.landmark"; | ||
27 | case AssetType.Clothing: | ||
28 | return "application/vnd.ll.clothing"; | ||
29 | case AssetType.Object: | ||
30 | return "application/vnd.ll.primitive"; | ||
31 | case AssetType.Notecard: | ||
32 | return "application/vnd.ll.notecard"; | ||
33 | case AssetType.Folder: | ||
34 | return "application/vnd.ll.folder"; | ||
35 | case AssetType.RootFolder: | ||
36 | return "application/vnd.ll.rootfolder"; | ||
37 | case AssetType.LSLText: | ||
38 | return "application/vnd.ll.lsltext"; | ||
39 | case AssetType.LSLBytecode: | ||
40 | return "application/vnd.ll.lslbyte"; | ||
41 | case AssetType.TextureTGA: | ||
42 | case AssetType.ImageTGA: | ||
43 | return "image/tga"; | ||
44 | case AssetType.Bodypart: | ||
45 | return "application/vnd.ll.bodypart"; | ||
46 | case AssetType.TrashFolder: | ||
47 | return "application/vnd.ll.trashfolder"; | ||
48 | case AssetType.SnapshotFolder: | ||
49 | return "application/vnd.ll.snapshotfolder"; | ||
50 | case AssetType.LostAndFoundFolder: | ||
51 | return "application/vnd.ll.lostandfoundfolder"; | ||
52 | case AssetType.SoundWAV: | ||
53 | return "audio/x-wav"; | ||
54 | case AssetType.ImageJPEG: | ||
55 | return "image/jpeg"; | ||
56 | case AssetType.Animation: | ||
57 | return "application/vnd.ll.animation"; | ||
58 | case AssetType.Gesture: | ||
59 | return "application/vnd.ll.gesture"; | ||
60 | case AssetType.Simstate: | ||
61 | return "application/x-metaverse-simstate"; | ||
62 | case AssetType.FavoriteFolder: | ||
63 | return "application/vnd.ll.favoritefolder"; | ||
64 | case AssetType.Link: | ||
65 | return "application/vnd.ll.link"; | ||
66 | case AssetType.LinkFolder: | ||
67 | return "application/vnd.ll.linkfolder"; | ||
68 | case AssetType.CurrentOutfitFolder: | ||
69 | return "application/vnd.ll.currentoutfitfolder"; | ||
70 | case AssetType.OutfitFolder: | ||
71 | return "application/vnd.ll.outfitfolder"; | ||
72 | case AssetType.MyOutfitsFolder: | ||
73 | return "application/vnd.ll.myoutfitsfolder"; | ||
74 | case AssetType.InboxFolder: | ||
75 | return "application/vnd.ll.inboxfolder"; | ||
76 | case AssetType.Unknown: | ||
77 | default: | ||
78 | return "application/octet-stream"; | ||
79 | } | ||
80 | } | ||
81 | |||
82 | public static sbyte ContentTypeToSLAssetType(string contentType) | ||
83 | { | ||
84 | switch (contentType) | ||
85 | { | ||
86 | case "image/x-j2c": | ||
87 | case "image/jp2": | ||
88 | return (sbyte)AssetType.Texture; | ||
89 | case "application/ogg": | ||
90 | return (sbyte)AssetType.Sound; | ||
91 | case "application/vnd.ll.callingcard": | ||
92 | case "application/x-metaverse-callingcard": | ||
93 | return (sbyte)AssetType.CallingCard; | ||
94 | case "application/vnd.ll.landmark": | ||
95 | case "application/x-metaverse-landmark": | ||
96 | return (sbyte)AssetType.Landmark; | ||
97 | case "application/vnd.ll.clothing": | ||
98 | case "application/x-metaverse-clothing": | ||
99 | return (sbyte)AssetType.Clothing; | ||
100 | case "application/vnd.ll.primitive": | ||
101 | case "application/x-metaverse-primitive": | ||
102 | return (sbyte)AssetType.Object; | ||
103 | case "application/vnd.ll.notecard": | ||
104 | case "application/x-metaverse-notecard": | ||
105 | return (sbyte)AssetType.Notecard; | ||
106 | case "application/vnd.ll.folder": | ||
107 | return (sbyte)AssetType.Folder; | ||
108 | case "application/vnd.ll.rootfolder": | ||
109 | return (sbyte)AssetType.RootFolder; | ||
110 | case "application/vnd.ll.lsltext": | ||
111 | case "application/x-metaverse-lsl": | ||
112 | return (sbyte)AssetType.LSLText; | ||
113 | case "application/vnd.ll.lslbyte": | ||
114 | case "application/x-metaverse-lso": | ||
115 | return (sbyte)AssetType.LSLBytecode; | ||
116 | case "image/tga": | ||
117 | // Note that AssetType.TextureTGA will be converted to AssetType.ImageTGA | ||
118 | return (sbyte)AssetType.ImageTGA; | ||
119 | case "application/vnd.ll.bodypart": | ||
120 | case "application/x-metaverse-bodypart": | ||
121 | return (sbyte)AssetType.Bodypart; | ||
122 | case "application/vnd.ll.trashfolder": | ||
123 | return (sbyte)AssetType.TrashFolder; | ||
124 | case "application/vnd.ll.snapshotfolder": | ||
125 | return (sbyte)AssetType.SnapshotFolder; | ||
126 | case "application/vnd.ll.lostandfoundfolder": | ||
127 | return (sbyte)AssetType.LostAndFoundFolder; | ||
128 | case "audio/x-wav": | ||
129 | return (sbyte)AssetType.SoundWAV; | ||
130 | case "image/jpeg": | ||
131 | return (sbyte)AssetType.ImageJPEG; | ||
132 | case "application/vnd.ll.animation": | ||
133 | case "application/x-metaverse-animation": | ||
134 | return (sbyte)AssetType.Animation; | ||
135 | case "application/vnd.ll.gesture": | ||
136 | case "application/x-metaverse-gesture": | ||
137 | return (sbyte)AssetType.Gesture; | ||
138 | case "application/x-metaverse-simstate": | ||
139 | return (sbyte)AssetType.Simstate; | ||
140 | case "application/vnd.ll.favoritefolder": | ||
141 | return (sbyte)AssetType.FavoriteFolder; | ||
142 | case "application/vnd.ll.link": | ||
143 | return (sbyte)AssetType.Link; | ||
144 | case "application/vnd.ll.linkfolder": | ||
145 | return (sbyte)AssetType.LinkFolder; | ||
146 | case "application/vnd.ll.currentoutfitfolder": | ||
147 | return (sbyte)AssetType.CurrentOutfitFolder; | ||
148 | case "application/vnd.ll.outfitfolder": | ||
149 | return (sbyte)AssetType.OutfitFolder; | ||
150 | case "application/vnd.ll.myoutfitsfolder": | ||
151 | return (sbyte)AssetType.MyOutfitsFolder; | ||
152 | case "application/vnd.ll.inboxfolder": | ||
153 | return (sbyte)AssetType.InboxFolder; | ||
154 | case "application/octet-stream": | ||
155 | default: | ||
156 | return (sbyte)AssetType.Unknown; | ||
157 | } | ||
158 | } | ||
159 | |||
160 | public static sbyte ContentTypeToSLInvType(string contentType) | ||
161 | { | ||
162 | switch (contentType) | ||
163 | { | ||
164 | case "image/x-j2c": | ||
165 | case "image/jp2": | ||
166 | case "image/tga": | ||
167 | case "image/jpeg": | ||
168 | return (sbyte)InventoryType.Texture; | ||
169 | case "application/ogg": | ||
170 | case "audio/x-wav": | ||
171 | return (sbyte)InventoryType.Sound; | ||
172 | case "application/vnd.ll.callingcard": | ||
173 | case "application/x-metaverse-callingcard": | ||
174 | return (sbyte)InventoryType.CallingCard; | ||
175 | case "application/vnd.ll.landmark": | ||
176 | case "application/x-metaverse-landmark": | ||
177 | return (sbyte)InventoryType.Landmark; | ||
178 | case "application/vnd.ll.clothing": | ||
179 | case "application/x-metaverse-clothing": | ||
180 | case "application/vnd.ll.bodypart": | ||
181 | case "application/x-metaverse-bodypart": | ||
182 | return (sbyte)InventoryType.Wearable; | ||
183 | case "application/vnd.ll.primitive": | ||
184 | case "application/x-metaverse-primitive": | ||
185 | return (sbyte)InventoryType.Object; | ||
186 | case "application/vnd.ll.notecard": | ||
187 | case "application/x-metaverse-notecard": | ||
188 | return (sbyte)InventoryType.Notecard; | ||
189 | case "application/vnd.ll.folder": | ||
190 | return (sbyte)InventoryType.Folder; | ||
191 | case "application/vnd.ll.rootfolder": | ||
192 | return (sbyte)InventoryType.RootCategory; | ||
193 | case "application/vnd.ll.lsltext": | ||
194 | case "application/x-metaverse-lsl": | ||
195 | case "application/vnd.ll.lslbyte": | ||
196 | case "application/x-metaverse-lso": | ||
197 | return (sbyte)InventoryType.LSL; | ||
198 | case "application/vnd.ll.trashfolder": | ||
199 | case "application/vnd.ll.snapshotfolder": | ||
200 | case "application/vnd.ll.lostandfoundfolder": | ||
201 | return (sbyte)InventoryType.Folder; | ||
202 | case "application/vnd.ll.animation": | ||
203 | case "application/x-metaverse-animation": | ||
204 | return (sbyte)InventoryType.Animation; | ||
205 | case "application/vnd.ll.gesture": | ||
206 | case "application/x-metaverse-gesture": | ||
207 | return (sbyte)InventoryType.Gesture; | ||
208 | case "application/x-metaverse-simstate": | ||
209 | return (sbyte)InventoryType.Snapshot; | ||
210 | case "application/octet-stream": | ||
211 | default: | ||
212 | return (sbyte)InventoryType.Unknown; | ||
213 | } | ||
214 | } | ||
215 | |||
216 | #endregion SL / file extension / content-type conversions | ||
217 | |||
218 | /// <summary> | ||
219 | /// Parse a notecard in Linden format to a string of ordinary text. | ||
220 | /// </summary> | ||
221 | /// <param name="rawInput"></param> | ||
222 | /// <returns></returns> | ||
223 | public static string ParseNotecardToString(string rawInput) | ||
224 | { | ||
225 | string[] output = ParseNotecardToList(rawInput).ToArray(); | ||
226 | |||
227 | // foreach (string line in output) | ||
228 | // m_log.DebugFormat("[PARSE NOTECARD]: ParseNotecardToString got line {0}", line); | ||
229 | |||
230 | return string.Join("\n", output); | ||
231 | } | ||
232 | |||
233 | /// <summary> | ||
234 | /// Parse a notecard in Linden format to a list of ordinary lines. | ||
235 | /// </summary> | ||
236 | /// <param name="rawInput"></param> | ||
237 | /// <returns></returns> | ||
238 | public static List<string> ParseNotecardToList(string rawInput) | ||
239 | { | ||
240 | string[] input = rawInput.Replace("\r", "").Split('\n'); | ||
241 | int idx = 0; | ||
242 | int level = 0; | ||
243 | List<string> output = new List<string>(); | ||
244 | string[] words; | ||
245 | |||
246 | while (idx < input.Length) | ||
247 | { | ||
248 | if (input[idx] == "{") | ||
249 | { | ||
250 | level++; | ||
251 | idx++; | ||
252 | continue; | ||
253 | } | ||
254 | |||
255 | if (input[idx]== "}") | ||
256 | { | ||
257 | level--; | ||
258 | idx++; | ||
259 | continue; | ||
260 | } | ||
261 | |||
262 | switch (level) | ||
263 | { | ||
264 | case 0: | ||
265 | words = input[idx].Split(' '); // Linden text ver | ||
266 | // Notecards are created *really* empty. Treat that as "no text" (just like after saving an empty notecard) | ||
267 | if (words.Length < 3) | ||
268 | return output; | ||
269 | |||
270 | int version = int.Parse(words[3]); | ||
271 | if (version != 2) | ||
272 | return output; | ||
273 | break; | ||
274 | case 1: | ||
275 | words = input[idx].Split(' '); | ||
276 | if (words[0] == "LLEmbeddedItems") | ||
277 | break; | ||
278 | if (words[0] == "Text") | ||
279 | { | ||
280 | int len = int.Parse(words[2]); | ||
281 | idx++; | ||
282 | |||
283 | int count = -1; | ||
284 | |||
285 | while (count < len) | ||
286 | { | ||
287 | // int l = input[idx].Length; | ||
288 | string ln = input[idx]; | ||
289 | |||
290 | int need = len-count-1; | ||
291 | if (ln.Length > need) | ||
292 | ln = ln.Substring(0, need); | ||
293 | |||
294 | // m_log.DebugFormat("[PARSE NOTECARD]: Adding line {0}", ln); | ||
295 | output.Add(ln); | ||
296 | count += ln.Length + 1; | ||
297 | idx++; | ||
298 | } | ||
299 | |||
300 | return output; | ||
301 | } | ||
302 | break; | ||
303 | case 2: | ||
304 | words = input[idx].Split(' '); // count | ||
305 | if (words[0] == "count") | ||
306 | { | ||
307 | int c = int.Parse(words[1]); | ||
308 | if (c > 0) | ||
309 | return output; | ||
310 | break; | ||
311 | } | ||
312 | break; | ||
313 | } | ||
314 | idx++; | ||
315 | } | ||
316 | |||
317 | return output; | ||
318 | } | ||
319 | } | ||
320 | } \ No newline at end of file | ||