diff options
Merge branch 'careminster' into tests
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs | 190 |
1 files changed, 39 insertions, 151 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs index 3cec77f..5a06bdb 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs | |||
@@ -309,26 +309,15 @@ namespace OpenSim.Region.Framework.Scenes | |||
309 | 309 | ||
310 | public string GetStateSnapshot() | 310 | public string GetStateSnapshot() |
311 | { | 311 | { |
312 | //m_log.Debug(" >>> GetStateSnapshot <<<"); | ||
313 | |||
314 | List<string> assemblies = new List<string>(); | ||
315 | Dictionary<UUID, string> states = new Dictionary<UUID, string>(); | 312 | Dictionary<UUID, string> states = new Dictionary<UUID, string>(); |
316 | 313 | ||
317 | foreach (SceneObjectPart part in m_parts.Values) | 314 | foreach (SceneObjectPart part in m_parts.Values) |
318 | { | 315 | { |
319 | foreach (string a in part.Inventory.GetScriptAssemblies()) | ||
320 | { | ||
321 | if (a != "" && !assemblies.Contains(a)) | ||
322 | assemblies.Add(a); | ||
323 | } | ||
324 | |||
325 | foreach (KeyValuePair<UUID, string> s in part.Inventory.GetScriptStates()) | 316 | foreach (KeyValuePair<UUID, string> s in part.Inventory.GetScriptStates()) |
326 | { | ||
327 | states[s.Key] = s.Value; | 317 | states[s.Key] = s.Value; |
328 | } | ||
329 | } | 318 | } |
330 | 319 | ||
331 | if (states.Count < 1 || assemblies.Count < 1) | 320 | if (states.Count < 1) |
332 | return ""; | 321 | return ""; |
333 | 322 | ||
334 | XmlDocument xmldoc = new XmlDocument(); | 323 | XmlDocument xmldoc = new XmlDocument(); |
@@ -342,104 +331,49 @@ namespace OpenSim.Region.Framework.Scenes | |||
342 | 331 | ||
343 | xmldoc.AppendChild(rootElement); | 332 | xmldoc.AppendChild(rootElement); |
344 | 333 | ||
345 | XmlElement wrapper = xmldoc.CreateElement("", "Assemblies", | ||
346 | ""); | ||
347 | 334 | ||
348 | rootElement.AppendChild(wrapper); | 335 | XmlElement wrapper = xmldoc.CreateElement("", "ScriptStates", |
349 | |||
350 | foreach (string assembly in assemblies) | ||
351 | { | ||
352 | string fn = Path.GetFileName(assembly); | ||
353 | if (fn == String.Empty) | ||
354 | continue; | ||
355 | |||
356 | String filedata = String.Empty; | ||
357 | |||
358 | if (File.Exists(assembly+".text")) | ||
359 | { | ||
360 | FileInfo tfi = new FileInfo(assembly+".text"); | ||
361 | |||
362 | if (tfi == null) | ||
363 | continue; | ||
364 | |||
365 | Byte[] tdata = new Byte[tfi.Length]; | ||
366 | |||
367 | try | ||
368 | { | ||
369 | FileStream tfs = File.Open(assembly+".text", FileMode.Open, FileAccess.Read); | ||
370 | tfs.Read(tdata, 0, tdata.Length); | ||
371 | tfs.Close(); | ||
372 | } | ||
373 | catch (Exception e) | ||
374 | { | ||
375 | m_log.DebugFormat("[SOG]: Unable to open script textfile {0}, reason: {1}", assembly+".text", e.Message); | ||
376 | } | ||
377 | |||
378 | filedata = new System.Text.ASCIIEncoding().GetString(tdata); | ||
379 | } | ||
380 | else | ||
381 | { | ||
382 | FileInfo fi = new FileInfo(assembly); | ||
383 | |||
384 | if (fi == null) | ||
385 | continue; | ||
386 | |||
387 | Byte[] data = new Byte[fi.Length]; | ||
388 | |||
389 | try | ||
390 | { | ||
391 | FileStream fs = File.Open(assembly, FileMode.Open, FileAccess.Read); | ||
392 | fs.Read(data, 0, data.Length); | ||
393 | fs.Close(); | ||
394 | } | ||
395 | catch (Exception e) | ||
396 | { | ||
397 | m_log.DebugFormat("[SOG]: Unable to open script assembly {0}, reason: {1}", assembly, e.Message); | ||
398 | } | ||
399 | |||
400 | filedata = System.Convert.ToBase64String(data); | ||
401 | } | ||
402 | XmlElement assemblyData = xmldoc.CreateElement("", "Assembly", ""); | ||
403 | XmlAttribute assemblyName = xmldoc.CreateAttribute("", "Filename", ""); | ||
404 | assemblyName.Value = fn; | ||
405 | assemblyData.Attributes.Append(assemblyName); | ||
406 | |||
407 | assemblyData.InnerText = filedata; | ||
408 | |||
409 | wrapper.AppendChild(assemblyData); | ||
410 | } | ||
411 | |||
412 | wrapper = xmldoc.CreateElement("", "ScriptStates", | ||
413 | ""); | 336 | ""); |
414 | 337 | ||
415 | rootElement.AppendChild(wrapper); | 338 | rootElement.AppendChild(wrapper); |
416 | 339 | ||
417 | foreach (KeyValuePair<UUID, string> state in states) | 340 | foreach (KeyValuePair<UUID, string> state in states) |
418 | { | 341 | { |
419 | XmlElement stateData = xmldoc.CreateElement("", "State", ""); | ||
420 | |||
421 | XmlAttribute stateID = xmldoc.CreateAttribute("", "UUID", ""); | ||
422 | stateID.Value = state.Key.ToString(); | ||
423 | stateData.Attributes.Append(stateID); | ||
424 | |||
425 | XmlDocument sdoc = new XmlDocument(); | 342 | XmlDocument sdoc = new XmlDocument(); |
426 | sdoc.LoadXml(state.Value); | 343 | sdoc.LoadXml(state.Value); |
427 | XmlNodeList rootL = sdoc.GetElementsByTagName("ScriptState"); | 344 | XmlNodeList rootL = sdoc.GetElementsByTagName("State"); |
428 | XmlNode rootNode = rootL[0]; | 345 | XmlNode rootNode = rootL[0]; |
429 | 346 | ||
430 | XmlNode newNode = xmldoc.ImportNode(rootNode, true); | 347 | XmlNode newNode = xmldoc.ImportNode(rootNode, true); |
431 | stateData.AppendChild(newNode); | 348 | wrapper.AppendChild(newNode); |
432 | wrapper.AppendChild(stateData); | ||
433 | } | 349 | } |
434 | 350 | ||
435 | return xmldoc.InnerXml; | 351 | return xmldoc.InnerXml; |
436 | } | 352 | } |
437 | 353 | ||
438 | public void SetState(string objXMLData, UUID RegionID) | 354 | public void SetState(string objXMLData, IScene ins) |
439 | { | 355 | { |
356 | if (!(ins is Scene)) | ||
357 | return; | ||
358 | |||
359 | Scene s = (Scene)ins; | ||
360 | |||
440 | if (objXMLData == String.Empty) | 361 | if (objXMLData == String.Empty) |
441 | return; | 362 | return; |
442 | 363 | ||
364 | IScriptModule scriptModule = null; | ||
365 | |||
366 | foreach (IScriptModule sm in s.RequestModuleInterfaces<IScriptModule>()) | ||
367 | { | ||
368 | if (sm.ScriptEngineName == s.DefaultScriptEngine) | ||
369 | scriptModule = sm; | ||
370 | else if (scriptModule == null) | ||
371 | scriptModule = sm; | ||
372 | } | ||
373 | |||
374 | if (scriptModule == null) | ||
375 | return; | ||
376 | |||
443 | XmlDocument doc = new XmlDocument(); | 377 | XmlDocument doc = new XmlDocument(); |
444 | try | 378 | try |
445 | { | 379 | { |
@@ -457,69 +391,23 @@ namespace OpenSim.Region.Framework.Scenes | |||
457 | } | 391 | } |
458 | 392 | ||
459 | XmlNodeList rootL = doc.GetElementsByTagName("ScriptData"); | 393 | XmlNodeList rootL = doc.GetElementsByTagName("ScriptData"); |
460 | if (rootL.Count == 1) | 394 | if (rootL.Count != 1) |
395 | return; | ||
396 | |||
397 | XmlElement rootE = (XmlElement)rootL[0]; | ||
398 | |||
399 | XmlNodeList dataL = rootE.GetElementsByTagName("ScriptStates"); | ||
400 | if (dataL.Count != 1) | ||
401 | return; | ||
402 | |||
403 | XmlElement dataE = (XmlElement)dataL[0]; | ||
404 | |||
405 | foreach (XmlNode n in dataE.ChildNodes) | ||
461 | { | 406 | { |
462 | XmlNode rootNode = rootL[0]; | 407 | XmlElement stateE = (XmlElement)n; |
463 | if (rootNode != null) | 408 | UUID itemID = new UUID(stateE.GetAttribute("UUID")); |
464 | { | 409 | |
465 | XmlNodeList partL = rootNode.ChildNodes; | 410 | scriptModule.SetXMLState(itemID, n.OuterXml); |
466 | |||
467 | foreach (XmlNode part in partL) | ||
468 | { | ||
469 | XmlNodeList nodeL = part.ChildNodes; | ||
470 | |||
471 | switch (part.Name) | ||
472 | { | ||
473 | case "Assemblies": | ||
474 | foreach (XmlNode asm in nodeL) | ||
475 | { | ||
476 | string fn = asm.Attributes.GetNamedItem("Filename").Value; | ||
477 | |||
478 | Byte[] filedata = Convert.FromBase64String(asm.InnerText); | ||
479 | string path = Path.Combine("ScriptEngines", RegionID.ToString()); | ||
480 | path = Path.Combine(path, fn); | ||
481 | |||
482 | if (!File.Exists(path)) | ||
483 | { | ||
484 | FileStream fs = File.Create(path); | ||
485 | fs.Write(filedata, 0, filedata.Length); | ||
486 | fs.Close(); | ||
487 | |||
488 | Byte[] textbytes = new System.Text.ASCIIEncoding().GetBytes(asm.InnerText); | ||
489 | fs = File.Create(path+".text"); | ||
490 | fs.Write(textbytes, 0, textbytes.Length); | ||
491 | fs.Close(); | ||
492 | } | ||
493 | } | ||
494 | break; | ||
495 | case "ScriptStates": | ||
496 | foreach (XmlNode st in nodeL) | ||
497 | { | ||
498 | string id = st.Attributes.GetNamedItem("UUID").Value; | ||
499 | UUID uuid = new UUID(id); | ||
500 | XmlNode state = st.ChildNodes[0]; | ||
501 | |||
502 | XmlDocument sdoc = new XmlDocument(); | ||
503 | XmlNode sxmlnode = sdoc.CreateNode( | ||
504 | XmlNodeType.XmlDeclaration, | ||
505 | "", ""); | ||
506 | sdoc.AppendChild(sxmlnode); | ||
507 | |||
508 | XmlNode newnode = sdoc.ImportNode(state, true); | ||
509 | sdoc.AppendChild(newnode); | ||
510 | |||
511 | string spath = Path.Combine("ScriptEngines", RegionID.ToString()); | ||
512 | spath = Path.Combine(spath, uuid.ToString()); | ||
513 | FileStream sfs = File.Create(spath + ".state"); | ||
514 | System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); | ||
515 | Byte[] buf = enc.GetBytes(sdoc.InnerXml); | ||
516 | sfs.Write(buf, 0, buf.Length); | ||
517 | sfs.Close(); | ||
518 | } | ||
519 | break; | ||
520 | } | ||
521 | } | ||
522 | } | ||
523 | } | 411 | } |
524 | } | 412 | } |
525 | } | 413 | } |