diff options
author | Justin Clark-Casey (justincc) | 2010-05-28 19:21:00 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2010-05-28 19:21:00 +0100 |
commit | d72435693bf950dde2f3f20e9b5d41c91af60456 (patch) | |
tree | efdf0fd474345128513080a1f566afa532ea53f7 /OpenSim/Region | |
parent | Adjust Scene.DeleteAllSceneObjects() to not delete objects attached to avatars. (diff) | |
download | opensim-SC_OLD-d72435693bf950dde2f3f20e9b5d41c91af60456.zip opensim-SC_OLD-d72435693bf950dde2f3f20e9b5d41c91af60456.tar.gz opensim-SC_OLD-d72435693bf950dde2f3f20e9b5d41c91af60456.tar.bz2 opensim-SC_OLD-d72435693bf950dde2f3f20e9b5d41c91af60456.tar.xz |
refactor: move GetStream and URI methods from ArchiveReadRequest -> ArchiveHelpers
Diffstat (limited to '')
3 files changed, 65 insertions, 64 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs index cfe3caa..8f3f65b 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs | |||
@@ -37,7 +37,6 @@ using OpenSim.Framework; | |||
37 | using OpenSim.Framework.Serialization; | 37 | using OpenSim.Framework.Serialization; |
38 | using OpenSim.Framework.Serialization.External; | 38 | using OpenSim.Framework.Serialization.External; |
39 | using OpenSim.Framework.Communications; | 39 | using OpenSim.Framework.Communications; |
40 | |||
41 | using OpenSim.Framework.Communications.Osp; | 40 | using OpenSim.Framework.Communications.Osp; |
42 | using OpenSim.Region.CoreModules.World.Archiver; | 41 | using OpenSim.Region.CoreModules.World.Archiver; |
43 | using OpenSim.Region.Framework.Scenes; | 42 | using OpenSim.Region.Framework.Scenes; |
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 | ||
28 | using System; | ||
29 | using System.IO; | ||
30 | using System.Net; | ||
28 | using OpenMetaverse; | 31 | using OpenMetaverse; |
29 | using OpenSim.Framework.Serialization; | 32 | using OpenSim.Framework.Serialization; |
30 | using OpenSim.Region.Framework.Scenes; | 33 | using 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 f97ae5f..bc653ce 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 | { |
@@ -471,68 +471,6 @@ namespace OpenSim.Region.CoreModules.World.Archiver | |||
471 | } | 471 | } |
472 | 472 | ||
473 | /// <summary> | 473 | /// <summary> |
474 | /// Resolve path to a working FileStream | ||
475 | /// </summary> | ||
476 | /// <param name="path"></param> | ||
477 | /// <returns></returns> | ||
478 | private Stream GetStream(string path) | ||
479 | { | ||
480 | if (File.Exists(path)) | ||
481 | { | ||
482 | return new FileStream(path, FileMode.Open, FileAccess.Read); | ||
483 | } | ||
484 | else | ||
485 | { | ||
486 | try | ||
487 | { | ||
488 | Uri uri = new Uri(path); | ||
489 | if (uri.Scheme == "file") | ||
490 | { | ||
491 | return new FileStream(uri.AbsolutePath, FileMode.Open, FileAccess.Read); | ||
492 | } | ||
493 | else | ||
494 | { | ||
495 | if (uri.Scheme != "http") | ||
496 | throw new Exception(String.Format("Unsupported URI scheme ({0})", path)); | ||
497 | |||
498 | // OK, now we know we have an HTTP URI to work with | ||
499 | |||
500 | return URIFetch(uri); | ||
501 | } | ||
502 | } | ||
503 | catch (UriFormatException) | ||
504 | { | ||
505 | // In many cases the user will put in a plain old filename that cannot be found so assume that | ||
506 | // this is the problem rather than confusing the issue with a UriFormatException | ||
507 | throw new Exception(String.Format("Cannot find file {0}", path)); | ||
508 | } | ||
509 | } | ||
510 | } | ||
511 | |||
512 | private static Stream URIFetch(Uri uri) | ||
513 | { | ||
514 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); | ||
515 | |||
516 | // request.Credentials = credentials; | ||
517 | |||
518 | request.ContentLength = 0; | ||
519 | request.KeepAlive = false; | ||
520 | |||
521 | WebResponse response = request.GetResponse(); | ||
522 | Stream file = response.GetResponseStream(); | ||
523 | |||
524 | // justincc: gonna ignore the content type for now and just try anything | ||
525 | //if (response.ContentType != "application/x-oar") | ||
526 | // throw new Exception(String.Format("{0} does not identify an OAR file", uri.ToString())); | ||
527 | |||
528 | if (response.ContentLength == 0) | ||
529 | throw new Exception(String.Format("{0} returned an empty file", uri.ToString())); | ||
530 | |||
531 | // return new BufferedStream(file, (int) response.ContentLength); | ||
532 | return new BufferedStream(file, 1000000); | ||
533 | } | ||
534 | |||
535 | /// <summary> | ||
536 | /// Load oar control file | 474 | /// Load oar control file |
537 | /// </summary> | 475 | /// </summary> |
538 | /// <param name="path"></param> | 476 | /// <param name="path"></param> |