aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/World/Archiver
diff options
context:
space:
mode:
authorMelanie2010-05-28 21:56:42 +0100
committerMelanie2010-05-28 21:56:42 +0100
commit542e6b8af4c9b8aa2ba753dbaed5032fb5293024 (patch)
tree4acfe25e2388f35da48f7eaf3b312d85f149625f /OpenSim/Region/CoreModules/World/Archiver
parentMerge branch 'careminster-presence-refactor' of www.3dhosting.de:/var/git/car... (diff)
parentget TestSaveIarV0_1() uncommented but not running as a test yet since I didn'... (diff)
downloadopensim-SC-542e6b8af4c9b8aa2ba753dbaed5032fb5293024.zip
opensim-SC-542e6b8af4c9b8aa2ba753dbaed5032fb5293024.tar.gz
opensim-SC-542e6b8af4c9b8aa2ba753dbaed5032fb5293024.tar.bz2
opensim-SC-542e6b8af4c9b8aa2ba753dbaed5032fb5293024.tar.xz
Merge branch 'master' into careminster-presence-refactor
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Archiver')
-rw-r--r--OpenSim/Region/CoreModules/World/Archiver/ArchiveHelpers.cs64
-rw-r--r--OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs64
2 files changed, 65 insertions, 63 deletions
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveHelpers.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveHelpers.cs
index 880bd7c..ddc3dd7 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveHelpers.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveHelpers.cs
@@ -25,6 +25,9 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System;
29using System.IO;
30using System.Net;
28using OpenMetaverse; 31using OpenMetaverse;
29using OpenSim.Framework.Serialization; 32using OpenSim.Framework.Serialization;
30using OpenSim.Region.Framework.Scenes; 33using OpenSim.Region.Framework.Scenes;
@@ -60,5 +63,66 @@ namespace OpenSim.Region.CoreModules.World.Archiver
60 { 63 {
61 return ArchiveConstants.CreateOarObjectPath(sog.Name, sog.UUID, sog.AbsolutePosition); 64 return ArchiveConstants.CreateOarObjectPath(sog.Name, sog.UUID, sog.AbsolutePosition);
62 } 65 }
66
67 /// <summary>
68 /// Resolve path to a working FileStream
69 /// </summary>
70 /// <param name="path"></param>
71 /// <returns></returns>
72 public static Stream GetStream(string path)
73 {
74 if (File.Exists(path))
75 {
76 return new FileStream(path, FileMode.Open, FileAccess.Read);
77 }
78 else
79 {
80 try
81 {
82 Uri uri = new Uri(path);
83 if (uri.Scheme == "file")
84 {
85 return new FileStream(uri.AbsolutePath, FileMode.Open, FileAccess.Read);
86 }
87 else
88 {
89 if (uri.Scheme != "http")
90 throw new Exception(String.Format("Unsupported URI scheme ({0})", path));
91
92 // OK, now we know we have an HTTP URI to work with
93 return URIFetch(uri);
94 }
95 }
96 catch (UriFormatException)
97 {
98 // In many cases the user will put in a plain old filename that cannot be found so assume that
99 // this is the problem rather than confusing the issue with a UriFormatException
100 throw new Exception(String.Format("Cannot find file {0}", path));
101 }
102 }
103 }
104
105 public static Stream URIFetch(Uri uri)
106 {
107 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
108
109 // request.Credentials = credentials;
110
111 request.ContentLength = 0;
112 request.KeepAlive = false;
113
114 WebResponse response = request.GetResponse();
115 Stream file = response.GetResponseStream();
116
117 // justincc: gonna ignore the content type for now and just try anything
118 //if (response.ContentType != "application/x-oar")
119 // throw new Exception(String.Format("{0} does not identify an OAR file", uri.ToString()));
120
121 if (response.ContentLength == 0)
122 throw new Exception(String.Format("{0} returned an empty file", uri.ToString()));
123
124 // return new BufferedStream(file, (int) response.ContentLength);
125 return new BufferedStream(file, 1000000);
126 }
63 } 127 }
64} \ No newline at end of file 128} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
index 9c8193a..57b7672 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
@@ -78,7 +78,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
78 78
79 try 79 try
80 { 80 {
81 m_loadStream = new GZipStream(GetStream(loadPath), CompressionMode.Decompress); 81 m_loadStream = new GZipStream(ArchiveHelpers.GetStream(loadPath), CompressionMode.Decompress);
82 } 82 }
83 catch (EntryPointNotFoundException e) 83 catch (EntryPointNotFoundException e)
84 { 84 {
@@ -473,68 +473,6 @@ namespace OpenSim.Region.CoreModules.World.Archiver
473 } 473 }
474 474
475 /// <summary> 475 /// <summary>
476 /// Resolve path to a working FileStream
477 /// </summary>
478 /// <param name="path"></param>
479 /// <returns></returns>
480 private Stream GetStream(string path)
481 {
482 if (File.Exists(path))
483 {
484 return new FileStream(path, FileMode.Open, FileAccess.Read);
485 }
486 else
487 {
488 try
489 {
490 Uri uri = new Uri(path);
491 if (uri.Scheme == "file")
492 {
493 return new FileStream(uri.AbsolutePath, FileMode.Open, FileAccess.Read);
494 }
495 else
496 {
497 if (uri.Scheme != "http")
498 throw new Exception(String.Format("Unsupported URI scheme ({0})", path));
499
500 // OK, now we know we have an HTTP URI to work with
501
502 return URIFetch(uri);
503 }
504 }
505 catch (UriFormatException)
506 {
507 // In many cases the user will put in a plain old filename that cannot be found so assume that
508 // this is the problem rather than confusing the issue with a UriFormatException
509 throw new Exception(String.Format("Cannot find file {0}", path));
510 }
511 }
512 }
513
514 private static Stream URIFetch(Uri uri)
515 {
516 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
517
518 // request.Credentials = credentials;
519
520 request.ContentLength = 0;
521 request.KeepAlive = false;
522
523 WebResponse response = request.GetResponse();
524 Stream file = response.GetResponseStream();
525
526 // justincc: gonna ignore the content type for now and just try anything
527 //if (response.ContentType != "application/x-oar")
528 // throw new Exception(String.Format("{0} does not identify an OAR file", uri.ToString()));
529
530 if (response.ContentLength == 0)
531 throw new Exception(String.Format("{0} returned an empty file", uri.ToString()));
532
533 // return new BufferedStream(file, (int) response.ContentLength);
534 return new BufferedStream(file, 1000000);
535 }
536
537 /// <summary>
538 /// Load oar control file 476 /// Load oar control file
539 /// </summary> 477 /// </summary>
540 /// <param name="path"></param> 478 /// <param name="path"></param>