diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Archiver/ArchiveHelpers.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Archiver/ArchiveHelpers.cs | 64 |
1 files changed, 64 insertions, 0 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 | ||
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 |