diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs | 191 |
1 files changed, 90 insertions, 101 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs index fe26429..3080c71 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs | |||
@@ -74,7 +74,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
74 | private string FilePrefix; | 74 | private string FilePrefix; |
75 | private string ScriptEnginesPath = "ScriptEngines"; | 75 | private string ScriptEnginesPath = "ScriptEngines"; |
76 | // mapping between LSL and C# line/column numbers | 76 | // mapping between LSL and C# line/column numbers |
77 | private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> m_positionMap; | ||
78 | private ICodeConverter LSL_Converter; | 77 | private ICodeConverter LSL_Converter; |
79 | 78 | ||
80 | private List<string> m_warnings = new List<string>(); | 79 | private List<string> m_warnings = new List<string>(); |
@@ -91,6 +90,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
91 | private static UInt64 scriptCompileCounter = 0; // And a counter | 90 | private static UInt64 scriptCompileCounter = 0; // And a counter |
92 | 91 | ||
93 | public IScriptEngine m_scriptEngine; | 92 | public IScriptEngine m_scriptEngine; |
93 | private Dictionary<string, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>> m_lineMaps = | ||
94 | new Dictionary<string, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>>(); | ||
95 | |||
94 | public Compiler(IScriptEngine scriptEngine) | 96 | public Compiler(IScriptEngine scriptEngine) |
95 | { | 97 | { |
96 | m_scriptEngine = scriptEngine; | 98 | m_scriptEngine = scriptEngine; |
@@ -172,8 +174,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
172 | else | 174 | else |
173 | { | 175 | { |
174 | #if DEBUG | 176 | #if DEBUG |
175 | // m_log.Debug("[Compiler]: " + | 177 | // m_log.Debug("[Compiler]: " + |
176 | // "Config OK. Default language \"" + defaultCompileLanguage + "\" specified in \"DefaultCompileLanguage\" is recognized as a valid language."); | 178 | // "Config OK. Default language \"" + defaultCompileLanguage + "\" specified in \"DefaultCompileLanguage\" is recognized as a valid language."); |
177 | #endif | 179 | #endif |
178 | // LANGUAGE IS IN ALLOW-LIST | 180 | // LANGUAGE IS IN ALLOW-LIST |
179 | DefaultCompileLanguage = LanguageMapping[defaultCompileLanguage]; | 181 | DefaultCompileLanguage = LanguageMapping[defaultCompileLanguage]; |
@@ -212,12 +214,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
212 | catch (Exception ex) | 214 | catch (Exception ex) |
213 | { | 215 | { |
214 | m_log.Error("[Compiler]: Exception trying to create ScriptEngine directory \"" + Path.Combine(ScriptEnginesPath, | 216 | m_log.Error("[Compiler]: Exception trying to create ScriptEngine directory \"" + Path.Combine(ScriptEnginesPath, |
215 | m_scriptEngine.World.RegionInfo.RegionID.ToString())+ "\": " + ex.ToString()); | 217 | m_scriptEngine.World.RegionInfo.RegionID.ToString()) + "\": " + ex.ToString()); |
216 | } | 218 | } |
217 | } | 219 | } |
218 | 220 | ||
219 | foreach (string file in Directory.GetFiles(Path.Combine(ScriptEnginesPath, | 221 | foreach (string file in Directory.GetFiles(Path.Combine(ScriptEnginesPath, |
220 | m_scriptEngine.World.RegionInfo.RegionID.ToString()),FilePrefix + "_compiled*")) | 222 | m_scriptEngine.World.RegionInfo.RegionID.ToString()), FilePrefix + "_compiled*")) |
221 | { | 223 | { |
222 | try | 224 | try |
223 | { | 225 | { |
@@ -271,16 +273,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
271 | /// </summary> | 273 | /// </summary> |
272 | /// <param name="Script">LSL script</param> | 274 | /// <param name="Script">LSL script</param> |
273 | /// <returns>Filename to .dll assembly</returns> | 275 | /// <returns>Filename to .dll assembly</returns> |
274 | public object PerformScriptCompile(string Script, string asset, UUID ownerUUID) | 276 | public void PerformScriptCompile(string Script, string asset, UUID ownerUUID, |
277 | out string assembly, out Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap) | ||
275 | { | 278 | { |
276 | m_positionMap = null; | 279 | linemap = null; |
277 | m_warnings.Clear(); | 280 | m_warnings.Clear(); |
278 | 281 | ||
279 | string OutFile = Path.Combine(ScriptEnginesPath, Path.Combine( | 282 | assembly = Path.Combine(ScriptEnginesPath, Path.Combine( |
280 | m_scriptEngine.World.RegionInfo.RegionID.ToString(), | 283 | m_scriptEngine.World.RegionInfo.RegionID.ToString(), |
281 | FilePrefix + "_compiled_" + asset + ".dll")); | 284 | FilePrefix + "_compiled_" + asset + ".dll")); |
282 | // string OutFile = Path.Combine(ScriptEnginesPath, | ||
283 | // FilePrefix + "_compiled_" + asset + ".dll"); | ||
284 | 285 | ||
285 | if (!Directory.Exists(ScriptEnginesPath)) | 286 | if (!Directory.Exists(ScriptEnginesPath)) |
286 | { | 287 | { |
@@ -305,60 +306,63 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
305 | } | 306 | } |
306 | } | 307 | } |
307 | 308 | ||
308 | if (Script == String.Empty) | 309 | // Don't recompile if we already have it |
310 | // Performing 3 file exists tests for every script can still be slow | ||
311 | if (File.Exists(assembly) && File.Exists(assembly + ".text") && File.Exists(assembly + ".map")) | ||
309 | { | 312 | { |
310 | if (File.Exists(OutFile)) | 313 | // If we have already read this linemap file, then it will be in our dictionary. |
311 | return OutFile; | 314 | // Don't build another copy of the dictionary (saves memory) and certainly |
312 | 315 | // don't keep reading the same file from disk multiple times. | |
313 | throw new Exception("Cannot find script assembly and no script text present"); | 316 | if (!m_lineMaps.ContainsKey(assembly)) |
317 | m_lineMaps[assembly] = ReadMapFile(assembly + ".map"); | ||
318 | linemap = m_lineMaps[assembly]; | ||
319 | return; | ||
314 | } | 320 | } |
315 | 321 | ||
316 | // Don't recompile if we already have it | 322 | if (Script == String.Empty) |
317 | // | ||
318 | if (File.Exists(OutFile) && File.Exists(OutFile+".text") && File.Exists(OutFile+".map")) | ||
319 | { | 323 | { |
320 | ReadMapFile(OutFile+".map"); | 324 | throw new Exception("Cannot find script assembly and no script text present"); |
321 | return OutFile; | ||
322 | } | 325 | } |
323 | 326 | ||
324 | enumCompileType l = DefaultCompileLanguage; | 327 | enumCompileType language = DefaultCompileLanguage; |
325 | 328 | ||
326 | if (Script.StartsWith("//c#", true, CultureInfo.InvariantCulture)) | 329 | if (Script.StartsWith("//c#", true, CultureInfo.InvariantCulture)) |
327 | l = enumCompileType.cs; | 330 | language = enumCompileType.cs; |
328 | if (Script.StartsWith("//vb", true, CultureInfo.InvariantCulture)) | 331 | if (Script.StartsWith("//vb", true, CultureInfo.InvariantCulture)) |
329 | { | 332 | { |
330 | l = enumCompileType.vb; | 333 | language = enumCompileType.vb; |
331 | // We need to remove //vb, it won't compile with that | 334 | // We need to remove //vb, it won't compile with that |
332 | 335 | ||
333 | Script = Script.Substring(4, Script.Length - 4); | 336 | Script = Script.Substring(4, Script.Length - 4); |
334 | } | 337 | } |
335 | if (Script.StartsWith("//lsl", true, CultureInfo.InvariantCulture)) | 338 | if (Script.StartsWith("//lsl", true, CultureInfo.InvariantCulture)) |
336 | l = enumCompileType.lsl; | 339 | language = enumCompileType.lsl; |
337 | 340 | ||
338 | if (Script.StartsWith("//js", true, CultureInfo.InvariantCulture)) | 341 | if (Script.StartsWith("//js", true, CultureInfo.InvariantCulture)) |
339 | l = enumCompileType.js; | 342 | language = enumCompileType.js; |
340 | 343 | ||
341 | if (Script.StartsWith("//yp", true, CultureInfo.InvariantCulture)) | 344 | if (Script.StartsWith("//yp", true, CultureInfo.InvariantCulture)) |
342 | l = enumCompileType.yp; | 345 | language = enumCompileType.yp; |
343 | 346 | ||
344 | if (!AllowedCompilers.ContainsKey(l.ToString())) | 347 | if (!AllowedCompilers.ContainsKey(language.ToString())) |
345 | { | 348 | { |
346 | // Not allowed to compile to this language! | 349 | // Not allowed to compile to this language! |
347 | string errtext = String.Empty; | 350 | string errtext = String.Empty; |
348 | errtext += "The compiler for language \"" + l.ToString() + "\" is not in list of allowed compilers. Script will not be executed!"; | 351 | errtext += "The compiler for language \"" + language.ToString() + "\" is not in list of allowed compilers. Script will not be executed!"; |
349 | throw new Exception(errtext); | 352 | throw new Exception(errtext); |
350 | } | 353 | } |
351 | 354 | ||
352 | if (m_scriptEngine.World.Permissions.CanCompileScript(ownerUUID, (int)l) == false) { | 355 | if (m_scriptEngine.World.Permissions.CanCompileScript(ownerUUID, (int)language) == false) |
356 | { | ||
353 | // Not allowed to compile to this language! | 357 | // Not allowed to compile to this language! |
354 | string errtext = String.Empty; | 358 | string errtext = String.Empty; |
355 | errtext += ownerUUID + " is not in list of allowed users for this scripting language. Script will not be executed!"; | 359 | errtext += ownerUUID + " is not in list of allowed users for this scripting language. Script will not be executed!"; |
356 | throw new Exception(errtext); | 360 | throw new Exception(errtext); |
357 | } | 361 | } |
358 | 362 | ||
359 | string compileScript = Script; | 363 | string compileScript = Script; |
360 | 364 | ||
361 | if (l == enumCompileType.lsl) | 365 | if (language == enumCompileType.lsl) |
362 | { | 366 | { |
363 | // Its LSL, convert it to C# | 367 | // Its LSL, convert it to C# |
364 | LSL_Converter = (ICodeConverter)new CSCodeGenerator(); | 368 | LSL_Converter = (ICodeConverter)new CSCodeGenerator(); |
@@ -370,16 +374,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
370 | AddWarning(warning); | 374 | AddWarning(warning); |
371 | } | 375 | } |
372 | 376 | ||
373 | m_positionMap = ((CSCodeGenerator) LSL_Converter).PositionMap; | 377 | linemap = ((CSCodeGenerator)LSL_Converter).PositionMap; |
378 | // Write the linemap to a file and save it in our dictionary for next time. | ||
379 | m_lineMaps[assembly] = linemap; | ||
380 | WriteMapFile(assembly + ".map", linemap); | ||
374 | } | 381 | } |
375 | 382 | ||
376 | if (l == enumCompileType.yp) | 383 | if (language == enumCompileType.yp) |
377 | { | 384 | { |
378 | // Its YP, convert it to C# | 385 | // Its YP, convert it to C# |
379 | compileScript = YP_Converter.Convert(Script); | 386 | compileScript = YP_Converter.Convert(Script); |
380 | } | 387 | } |
381 | 388 | ||
382 | switch (l) | 389 | switch (language) |
383 | { | 390 | { |
384 | case enumCompileType.cs: | 391 | case enumCompileType.cs: |
385 | case enumCompileType.lsl: | 392 | case enumCompileType.lsl: |
@@ -396,7 +403,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
396 | break; | 403 | break; |
397 | } | 404 | } |
398 | 405 | ||
399 | return CompileFromDotNetText(compileScript, l, asset); | 406 | assembly = CompileFromDotNetText(compileScript, language, asset, assembly); |
407 | return; | ||
400 | } | 408 | } |
401 | 409 | ||
402 | public string[] GetWarnings() | 410 | public string[] GetWarnings() |
@@ -468,22 +476,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
468 | /// </summary> | 476 | /// </summary> |
469 | /// <param name="Script">CS script</param> | 477 | /// <param name="Script">CS script</param> |
470 | /// <returns>Filename to .dll assembly</returns> | 478 | /// <returns>Filename to .dll assembly</returns> |
471 | internal string CompileFromDotNetText(string Script, enumCompileType lang, string asset) | 479 | internal string CompileFromDotNetText(string Script, enumCompileType lang, string asset, string assembly) |
472 | { | 480 | { |
473 | string ext = "." + lang.ToString(); | 481 | string ext = "." + lang.ToString(); |
474 | 482 | ||
475 | // Output assembly name | 483 | // Output assembly name |
476 | scriptCompileCounter++; | 484 | scriptCompileCounter++; |
477 | string OutFile = Path.Combine(ScriptEnginesPath, Path.Combine( | ||
478 | m_scriptEngine.World.RegionInfo.RegionID.ToString(), | ||
479 | FilePrefix + "_compiled_" + asset + ".dll")); | ||
480 | try | 485 | try |
481 | { | 486 | { |
482 | File.Delete(OutFile); | 487 | File.Delete(assembly); |
483 | } | 488 | } |
484 | catch (Exception e) // NOTLEGIT - Should be just FileIOException | 489 | catch (Exception e) // NOTLEGIT - Should be just FileIOException |
485 | { | 490 | { |
486 | throw new Exception("Unable to delete old existing "+ | 491 | throw new Exception("Unable to delete old existing " + |
487 | "script-file before writing new. Compile aborted: " + | 492 | "script-file before writing new. Compile aborted: " + |
488 | e.ToString()); | 493 | e.ToString()); |
489 | } | 494 | } |
@@ -492,7 +497,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
492 | if (WriteScriptSourceToDebugFile) | 497 | if (WriteScriptSourceToDebugFile) |
493 | { | 498 | { |
494 | string srcFileName = FilePrefix + "_source_" + | 499 | string srcFileName = FilePrefix + "_source_" + |
495 | Path.GetFileNameWithoutExtension(OutFile) + ext; | 500 | Path.GetFileNameWithoutExtension(assembly) + ext; |
496 | try | 501 | try |
497 | { | 502 | { |
498 | File.WriteAllText(Path.Combine(Path.Combine( | 503 | File.WriteAllText(Path.Combine(Path.Combine( |
@@ -502,7 +507,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
502 | } | 507 | } |
503 | catch (Exception ex) //NOTLEGIT - Should be just FileIOException | 508 | catch (Exception ex) //NOTLEGIT - Should be just FileIOException |
504 | { | 509 | { |
505 | m_log.Error("[Compiler]: Exception while "+ | 510 | m_log.Error("[Compiler]: Exception while " + |
506 | "trying to write script source to file \"" + | 511 | "trying to write script source to file \"" + |
507 | srcFileName + "\": " + ex.ToString()); | 512 | srcFileName + "\": " + ex.ToString()); |
508 | } | 513 | } |
@@ -528,7 +533,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
528 | } | 533 | } |
529 | 534 | ||
530 | parameters.GenerateExecutable = false; | 535 | parameters.GenerateExecutable = false; |
531 | parameters.OutputAssembly = OutFile; | 536 | parameters.OutputAssembly = assembly; |
532 | parameters.IncludeDebugInformation = CompileWithDebugInformation; | 537 | parameters.IncludeDebugInformation = CompileWithDebugInformation; |
533 | //parameters.WarningLevel = 1; // Should be 4? | 538 | //parameters.WarningLevel = 1; // Should be 4? |
534 | parameters.TreatWarningsAsErrors = false; | 539 | parameters.TreatWarningsAsErrors = false; |
@@ -543,7 +548,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
543 | case enumCompileType.cs: | 548 | case enumCompileType.cs: |
544 | case enumCompileType.lsl: | 549 | case enumCompileType.lsl: |
545 | bool complete = false; | 550 | bool complete = false; |
546 | bool retried = false; | 551 | bool retried = false; |
547 | do | 552 | do |
548 | { | 553 | { |
549 | lock (CScodeProvider) | 554 | lock (CScodeProvider) |
@@ -584,7 +589,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
584 | parameters, Script); | 589 | parameters, Script); |
585 | break; | 590 | break; |
586 | default: | 591 | default: |
587 | throw new Exception("Compiler is not able to recongnize "+ | 592 | throw new Exception("Compiler is not able to recongnize " + |
588 | "language type \"" + lang.ToString() + "\""); | 593 | "language type \"" + lang.ToString() + "\""); |
589 | } | 594 | } |
590 | 595 | ||
@@ -609,7 +614,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
609 | 614 | ||
610 | if (severity == "Error") | 615 | if (severity == "Error") |
611 | { | 616 | { |
612 | lslPos = FindErrorPosition(CompErr.Line, CompErr.Column); | 617 | lslPos = FindErrorPosition(CompErr.Line, CompErr.Column, m_lineMaps[assembly]); |
613 | string text = CompErr.ErrorText; | 618 | string text = CompErr.ErrorText; |
614 | 619 | ||
615 | // Use LSL type names | 620 | // Use LSL type names |
@@ -635,14 +640,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
635 | // the compile may not be immediately apparent. Wait a | 640 | // the compile may not be immediately apparent. Wait a |
636 | // reasonable amount of time before giving up on it. | 641 | // reasonable amount of time before giving up on it. |
637 | 642 | ||
638 | if (!File.Exists(OutFile)) | 643 | if (!File.Exists(assembly)) |
639 | { | 644 | { |
640 | for (int i=0; i<20 && !File.Exists(OutFile); i++) | 645 | for (int i = 0; i < 20 && !File.Exists(assembly); i++) |
641 | { | 646 | { |
642 | System.Threading.Thread.Sleep(250); | 647 | System.Threading.Thread.Sleep(250); |
643 | } | 648 | } |
644 | // One final chance... | 649 | // One final chance... |
645 | if (!File.Exists(OutFile)) | 650 | if (!File.Exists(assembly)) |
646 | { | 651 | { |
647 | errtext = String.Empty; | 652 | errtext = String.Empty; |
648 | errtext += "No compile error. But not able to locate compiled file."; | 653 | errtext += "No compile error. But not able to locate compiled file."; |
@@ -650,15 +655,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
650 | } | 655 | } |
651 | } | 656 | } |
652 | 657 | ||
653 | // m_log.DebugFormat("[Compiler] Compiled new assembly "+ | 658 | // m_log.DebugFormat("[Compiler] Compiled new assembly "+ |
654 | // "for {0}", asset); | 659 | // "for {0}", asset); |
655 | 660 | ||
656 | // Because windows likes to perform exclusive locks, we simply | 661 | // Because windows likes to perform exclusive locks, we simply |
657 | // write out a textual representation of the file here | 662 | // write out a textual representation of the file here |
658 | // | 663 | // |
659 | // Read the binary file into a buffer | 664 | // Read the binary file into a buffer |
660 | // | 665 | // |
661 | FileInfo fi = new FileInfo(OutFile); | 666 | FileInfo fi = new FileInfo(assembly); |
662 | 667 | ||
663 | if (fi == null) | 668 | if (fi == null) |
664 | { | 669 | { |
@@ -671,7 +676,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
671 | 676 | ||
672 | try | 677 | try |
673 | { | 678 | { |
674 | FileStream fs = File.Open(OutFile, FileMode.Open, FileAccess.Read); | 679 | FileStream fs = File.Open(assembly, FileMode.Open, FileAccess.Read); |
675 | fs.Read(data, 0, data.Length); | 680 | fs.Read(data, 0, data.Length); |
676 | fs.Close(); | 681 | fs.Close(); |
677 | } | 682 | } |
@@ -690,40 +695,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
690 | 695 | ||
691 | Byte[] buf = enc.GetBytes(filetext); | 696 | Byte[] buf = enc.GetBytes(filetext); |
692 | 697 | ||
693 | FileStream sfs = File.Create(OutFile+".text"); | 698 | FileStream sfs = File.Create(assembly + ".text"); |
694 | sfs.Write(buf, 0, buf.Length); | 699 | sfs.Write(buf, 0, buf.Length); |
695 | sfs.Close(); | 700 | sfs.Close(); |
696 | 701 | ||
697 | string posmap = String.Empty; | 702 | return assembly; |
698 | if (m_positionMap != null) | ||
699 | { | ||
700 | foreach (KeyValuePair<KeyValuePair<int, int>, KeyValuePair<int, int>> kvp in m_positionMap) | ||
701 | { | ||
702 | KeyValuePair<int, int> k = kvp.Key; | ||
703 | KeyValuePair<int, int> v = kvp.Value; | ||
704 | posmap += String.Format("{0},{1},{2},{3}\n", | ||
705 | k.Key, k.Value, v.Key, v.Value); | ||
706 | } | ||
707 | } | ||
708 | |||
709 | buf = enc.GetBytes(posmap); | ||
710 | |||
711 | FileStream mfs = File.Create(OutFile+".map"); | ||
712 | mfs.Write(buf, 0, buf.Length); | ||
713 | mfs.Close(); | ||
714 | |||
715 | return OutFile; | ||
716 | } | ||
717 | |||
718 | public KeyValuePair<int, int> FindErrorPosition(int line, int col) | ||
719 | { | ||
720 | return FindErrorPosition(line, col, m_positionMap); | ||
721 | } | 703 | } |
722 | 704 | ||
723 | private class kvpSorter : IComparer<KeyValuePair<int,int>> | 705 | private class kvpSorter : IComparer<KeyValuePair<int, int>> |
724 | { | 706 | { |
725 | public int Compare(KeyValuePair<int,int> a, | 707 | public int Compare(KeyValuePair<int, int> a, |
726 | KeyValuePair<int,int> b) | 708 | KeyValuePair<int, int> b) |
727 | { | 709 | { |
728 | return a.Key.CompareTo(b.Key); | 710 | return a.Key.CompareTo(b.Key); |
729 | } | 711 | } |
@@ -742,8 +724,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
742 | out ret)) | 724 | out ret)) |
743 | return ret; | 725 | return ret; |
744 | 726 | ||
745 | List<KeyValuePair<int,int>> sorted = | 727 | List<KeyValuePair<int, int>> sorted = |
746 | new List<KeyValuePair<int,int>>(positionMap.Keys); | 728 | new List<KeyValuePair<int, int>>(positionMap.Keys); |
747 | 729 | ||
748 | sorted.Sort(new kvpSorter()); | 730 | sorted.Sort(new kvpSorter()); |
749 | 731 | ||
@@ -791,32 +773,37 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
791 | return message; | 773 | return message; |
792 | } | 774 | } |
793 | 775 | ||
794 | public Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> LineMap() | 776 | |
777 | private static void WriteMapFile(string filename, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap) | ||
795 | { | 778 | { |
796 | if (m_positionMap == null) | 779 | string mapstring = String.Empty; |
797 | return null; | 780 | foreach (KeyValuePair<KeyValuePair<int, int>, KeyValuePair<int, int>> kvp in linemap) |
798 | 781 | { | |
799 | Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> ret = | 782 | KeyValuePair<int, int> k = kvp.Key; |
800 | new Dictionary<KeyValuePair<int,int>, KeyValuePair<int, int>>(); | 783 | KeyValuePair<int, int> v = kvp.Value; |
801 | 784 | mapstring += String.Format("{0},{1},{2},{3}\n", k.Key, k.Value, v.Key, v.Value); | |
802 | foreach (KeyValuePair<int, int> kvp in m_positionMap.Keys) | 785 | } |
803 | ret.Add(kvp, m_positionMap[kvp]); | 786 | |
804 | 787 | System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); | |
805 | return ret; | 788 | Byte[] mapbytes = enc.GetBytes(mapstring); |
789 | FileStream mfs = File.Create(filename); | ||
790 | mfs.Write(mapbytes, 0, mapbytes.Length); | ||
791 | mfs.Close(); | ||
806 | } | 792 | } |
807 | 793 | ||
808 | private void ReadMapFile(string filename) | 794 | |
795 | private static Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> ReadMapFile(string filename) | ||
809 | { | 796 | { |
797 | Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap; | ||
810 | try | 798 | try |
811 | { | 799 | { |
812 | StreamReader r = File.OpenText(filename); | 800 | StreamReader r = File.OpenText(filename); |
801 | linemap = new Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>(); | ||
813 | 802 | ||
814 | m_positionMap = new Dictionary<KeyValuePair<int,int>, KeyValuePair<int, int>>(); | ||
815 | |||
816 | string line; | 803 | string line; |
817 | while ((line = r.ReadLine()) != null) | 804 | while ((line = r.ReadLine()) != null) |
818 | { | 805 | { |
819 | String[] parts = line.Split(new Char[] {','}); | 806 | String[] parts = line.Split(new Char[] { ',' }); |
820 | int kk = System.Convert.ToInt32(parts[0]); | 807 | int kk = System.Convert.ToInt32(parts[0]); |
821 | int kv = System.Convert.ToInt32(parts[1]); | 808 | int kv = System.Convert.ToInt32(parts[1]); |
822 | int vk = System.Convert.ToInt32(parts[2]); | 809 | int vk = System.Convert.ToInt32(parts[2]); |
@@ -825,12 +812,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
825 | KeyValuePair<int, int> k = new KeyValuePair<int, int>(kk, kv); | 812 | KeyValuePair<int, int> k = new KeyValuePair<int, int>(kk, kv); |
826 | KeyValuePair<int, int> v = new KeyValuePair<int, int>(vk, vv); | 813 | KeyValuePair<int, int> v = new KeyValuePair<int, int>(vk, vv); |
827 | 814 | ||
828 | m_positionMap[k] = v; | 815 | linemap[k] = v; |
829 | } | 816 | } |
830 | } | 817 | } |
831 | catch | 818 | catch |
832 | { | 819 | { |
820 | linemap = new Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>(); | ||
833 | } | 821 | } |
822 | return linemap; | ||
834 | } | 823 | } |
835 | } | 824 | } |
836 | } | 825 | } |