aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorMW2008-03-12 15:45:56 +0000
committerMW2008-03-12 15:45:56 +0000
commit2fea38a5f2d0ee71eef998ec6f7bf4351f188bd7 (patch)
treed8db0ada39919743707cfedcdc6dc8c4dfa605bf /OpenSim
parent* Switched Noise 'Flood Area' brush to use Perlin rather than random noise. (diff)
downloadopensim-SC-2fea38a5f2d0ee71eef998ec6f7bf4351f188bd7.zip
opensim-SC-2fea38a5f2d0ee71eef998ec6f7bf4351f188bd7.tar.gz
opensim-SC-2fea38a5f2d0ee71eef998ec6f7bf4351f188bd7.tar.bz2
opensim-SC-2fea38a5f2d0ee71eef998ec6f7bf4351f188bd7.tar.xz
Applied patch from mantis #610, fixed invalid filenames with dump_assets_to_file set to true. thanks tyre.
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Communications/Capabilities/Caps.cs2
-rw-r--r--OpenSim/Framework/Util.cs81
2 files changed, 56 insertions, 27 deletions
diff --git a/OpenSim/Framework/Communications/Capabilities/Caps.cs b/OpenSim/Framework/Communications/Capabilities/Caps.cs
index 8f41d62..5df6a06 100644
--- a/OpenSim/Framework/Communications/Capabilities/Caps.cs
+++ b/OpenSim/Framework/Communications/Capabilities/Caps.cs
@@ -553,7 +553,7 @@ namespace OpenSim.Region.Capabilities
553 { 553 {
554 Directory.CreateDirectory(assetPath); 554 Directory.CreateDirectory(assetPath);
555 } 555 }
556 FileStream fs = File.Create(Path.Combine(assetPath, filename)); 556 FileStream fs = File.Create(Path.Combine(assetPath, Util.safeFileName(filename)));
557 BinaryWriter bw = new BinaryWriter(fs); 557 BinaryWriter bw = new BinaryWriter(fs);
558 bw.Write(data); 558 bw.Write(data);
559 bw.Close(); 559 bw.Close();
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 8ba6643..847436f 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -37,8 +37,8 @@ using System.Text;
37using libsecondlife; 37using libsecondlife;
38using Nini.Config; 38using Nini.Config;
39 39
40using System.Runtime.Serialization; 40using System.Runtime.Serialization;
41using System.Runtime.Serialization.Formatters.Binary; 41using System.Runtime.Serialization.Formatters.Binary;
42namespace OpenSim.Framework 42namespace OpenSim.Framework
43{ 43{
44 public class Util 44 public class Util
@@ -48,7 +48,13 @@ namespace OpenSim.Framework
48 private static object XferLock = new object(); 48 private static object XferLock = new object();
49 private static Dictionary<LLUUID, string> capsURLS = new Dictionary<LLUUID, string>(); 49 private static Dictionary<LLUUID, string> capsURLS = new Dictionary<LLUUID, string>();
50 50
51 #region Vector Equasions 51 // Get a list of invalid path characters (OS dependent)
52 private static string regexInvalidPathChars = "[" + new String(Path.GetInvalidPathChars()) + "]";
53 // Get a list of invalid file characters (OS dependent)
54 private static string regexInvalidFileChars = "[" + new String(Path.GetInvalidFileNameChars()) + "]";
55
56
57 #region Vector Equasions
52 /// <summary> 58 /// <summary>
53 /// Get the distance between two 3d vectors 59 /// Get the distance between two 3d vectors
54 /// </summary> 60 /// </summary>
@@ -60,7 +66,7 @@ namespace OpenSim.Framework
60 float dx = a.X - b.X; 66 float dx = a.X - b.X;
61 float dy = a.Y - b.Y; 67 float dy = a.Y - b.Y;
62 float dz = a.Z - b.Z; 68 float dz = a.Z - b.Z;
63 return Math.Sqrt(dx*dx + dy*dy + dz*dz); 69 return Math.Sqrt(dx * dx + dy * dy + dz * dz);
64 } 70 }
65 71
66 /// <summary> 72 /// <summary>
@@ -68,7 +74,8 @@ namespace OpenSim.Framework
68 /// </summary> 74 /// </summary>
69 /// <param name="a">A 3d vector</param> 75 /// <param name="a">A 3d vector</param>
70 /// <returns>The magnitude of the vector</returns> 76 /// <returns>The magnitude of the vector</returns>
71 public static double GetMagnitude(LLVector3 a) { 77 public static double GetMagnitude(LLVector3 a)
78 {
72 return Math.Sqrt((a.X * a.X) + (a.Y * a.Y) + (a.Z * a.Z)); 79 return Math.Sqrt((a.X * a.X) + (a.Y * a.Y) + (a.Z * a.Z));
73 } 80 }
74 81
@@ -91,16 +98,16 @@ namespace OpenSim.Framework
91 /// Returns if a vector is a zero vector (has all zero components) 98 /// Returns if a vector is a zero vector (has all zero components)
92 /// </summary> 99 /// </summary>
93 /// <returns></returns> 100 /// <returns></returns>
94 public static bool IsZeroVector( LLVector3 v ) 101 public static bool IsZeroVector(LLVector3 v)
95 { 102 {
96 if( v.X == 0 && v.Y == 0 && v.Z == 0) 103 if (v.X == 0 && v.Y == 0 && v.Z == 0)
97 { 104 {
98 return true; 105 return true;
99 } 106 }
100 107
101 return false; 108 return false;
102 } 109 }
103 # endregion 110 # endregion
104 111
105 public static ulong UIntsToLong(uint X, uint Y) 112 public static ulong UIntsToLong(uint X, uint Y)
106 { 113 {
@@ -299,7 +306,7 @@ namespace OpenSim.Framework
299 for (int j = 0; j < 16 && (i + j) < bytes.Length; j++) 306 for (int j = 0; j < 16 && (i + j) < bytes.Length; j++)
300 { 307 {
301 if (bytes[i + j] >= 0x20 && bytes[i + j] < 0x7E) 308 if (bytes[i + j] >= 0x20 && bytes[i + j] < 0x7E)
302 output.Append((char) bytes[i + j]); 309 output.Append((char)bytes[i + j]);
303 else 310 else
304 output.Append("."); 311 output.Append(".");
305 } 312 }
@@ -358,6 +365,28 @@ namespace OpenSim.Framework
358 return null; 365 return null;
359 } 366 }
360 367
368 /// <summary>
369 /// Removes all invalid path chars (OS dependent)
370 /// </summary>
371 /// <param name="path">path</param>
372 /// <returns>safe path</returns>
373 public static string safePath(string path)
374 {
375 return System.Text.RegularExpressions.Regex.Replace(path, @regexInvalidPathChars, string.Empty);
376 }
377
378 /// <summary>
379 /// Removes all invalid filename chars (OS dependent)
380 /// </summary>
381 /// <param name="path">filename</param>
382 /// <returns>safe filename</returns>
383 public static string safeFileName(string filename)
384 {
385 return System.Text.RegularExpressions.Regex.Replace(filename, @regexInvalidFileChars, string.Empty); ;
386 }
387
388
389
361 // 390 //
362 // directory locations 391 // directory locations
363 // 392 //
@@ -365,12 +394,12 @@ namespace OpenSim.Framework
365 public static string homeDir() 394 public static string homeDir()
366 { 395 {
367 string temp; 396 string temp;
368// string personal=(Environment.GetFolderPath(Environment.SpecialFolder.Personal)); 397 // string personal=(Environment.GetFolderPath(Environment.SpecialFolder.Personal));
369// temp = Path.Combine(personal,".OpenSim"); 398 // temp = Path.Combine(personal,".OpenSim");
370 temp = "."; 399 temp = ".";
371 return temp; 400 return temp;
372 } 401 }
373 402
374 public static string assetsDir() 403 public static string assetsDir()
375 { 404 {
376 return Path.Combine(configDir(), "assets"); 405 return Path.Combine(configDir(), "assets");
@@ -439,10 +468,10 @@ namespace OpenSim.Framework
439 468
440 public static void AddDataRowToConfig(IConfigSource config, DataRow row) 469 public static void AddDataRowToConfig(IConfigSource config, DataRow row)
441 { 470 {
442 config.Configs.Add((string) row[0]); 471 config.Configs.Add((string)row[0]);
443 for (int i = 0; i < row.Table.Columns.Count; i++) 472 for (int i = 0; i < row.Table.Columns.Count; i++)
444 { 473 {
445 config.Configs[(string) row[0]].Set(row.Table.Columns[i].ColumnName, row[i]); 474 config.Configs[(string)row[0]].Set(row.Table.Columns[i].ColumnName, row[i]);
446 } 475 }
447 } 476 }
448 477
@@ -468,25 +497,25 @@ namespace OpenSim.Framework
468 497
469 public static string CleanString(string input) 498 public static string CleanString(string input)
470 { 499 {
471 if(input.Length == 0) 500 if (input.Length == 0)
472 return input; 501 return input;
473 502
474 int clip=input.Length; 503 int clip = input.Length;
475 504
476 // Test for ++ string terminator 505 // Test for ++ string terminator
477 int pos=input.IndexOf("\0"); 506 int pos = input.IndexOf("\0");
478 if(pos != -1 && pos < clip) 507 if (pos != -1 && pos < clip)
479 clip=pos; 508 clip = pos;
480 509
481 // Test for CR 510 // Test for CR
482 pos=input.IndexOf("\r"); 511 pos = input.IndexOf("\r");
483 if(pos != -1 && pos < clip) 512 if (pos != -1 && pos < clip)
484 clip=pos; 513 clip = pos;
485 514
486 // Test for LF 515 // Test for LF
487 pos=input.IndexOf("\n"); 516 pos = input.IndexOf("\n");
488 if(pos != -1 && pos < clip) 517 if (pos != -1 && pos < clip)
489 clip=pos; 518 clip = pos;
490 519
491 // Truncate string before first end-of-line character found 520 // Truncate string before first end-of-line character found
492 return input.Substring(0, clip); 521 return input.Substring(0, clip);