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