clockwerk-opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ |
||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
||
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions are met: |
||
7 | * * Redistributions of source code must retain the above copyright |
||
8 | * notice, this list of conditions and the following disclaimer. |
||
9 | * * Redistributions in binary form must reproduce the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer in the |
||
11 | * documentation and/or other materials provided with the distribution. |
||
12 | * * Neither the name of the OpenSimulator Project nor the |
||
13 | * names of its contributors may be used to endorse or promote products |
||
14 | * derived from this software without specific prior written permission. |
||
15 | * |
||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
26 | */ |
||
27 | |||
28 | using System; |
||
29 | using System.IO; |
||
30 | using System.Net; |
||
31 | using OpenMetaverse; |
||
32 | using OpenSim.Framework.Serialization; |
||
33 | using OpenSim.Region.Framework.Scenes; |
||
34 | |||
35 | namespace OpenSim.Region.CoreModules.World.Archiver |
||
36 | { |
||
37 | /// <summary> |
||
38 | /// Helper methods for archive manipulation |
||
39 | /// </summary> |
||
40 | /// This is a separate class from ArchiveConstants because we need to bring in very OpenSim specific classes. |
||
41 | public static class ArchiveHelpers |
||
42 | { |
||
43 | /// <summary> |
||
44 | /// Create the filename used for objects in OpenSim Archives. |
||
45 | /// </summary> |
||
46 | /// <param name="objectName"></param> |
||
47 | /// <param name="uuid"></param> |
||
48 | /// <param name="pos"></param> |
||
49 | /// <returns></returns> |
||
50 | public static string CreateObjectFilename(SceneObjectGroup sog) |
||
51 | { |
||
52 | return ArchiveConstants.CreateOarObjectFilename(sog.Name, sog.UUID, sog.AbsolutePosition); |
||
53 | } |
||
54 | |||
55 | /// <summary> |
||
56 | /// Create the path used to store an object in an OpenSim Archive. |
||
57 | /// </summary> |
||
58 | /// <param name="objectName"></param> |
||
59 | /// <param name="uuid"></param> |
||
60 | /// <param name="pos"></param> |
||
61 | /// <returns></returns> |
||
62 | public static string CreateObjectPath(SceneObjectGroup sog) |
||
63 | { |
||
64 | return ArchiveConstants.CreateOarObjectPath(sog.Name, sog.UUID, sog.AbsolutePosition); |
||
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 | } |
||
127 | } |
||
128 | } |