diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs | 165 | ||||
-rw-r--r-- | OpenSim/Framework/AssetLoader/Filesystem/Properties/AssemblyInfo.cs | 33 |
2 files changed, 198 insertions, 0 deletions
diff --git a/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs b/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs new file mode 100644 index 0000000..097ad7d --- /dev/null +++ b/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs | |||
@@ -0,0 +1,165 @@ | |||
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.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Xml; | ||
33 | using log4net; | ||
34 | using Nini.Config; | ||
35 | using OpenMetaverse; | ||
36 | |||
37 | /// <summary> | ||
38 | /// Loads assets from the filesystem location. Not yet a plugin, though it should be. | ||
39 | /// </summary> | ||
40 | namespace OpenSim.Framework.AssetLoader.Filesystem | ||
41 | { | ||
42 | public class AssetLoaderFileSystem : IAssetLoader | ||
43 | { | ||
44 | private static readonly UUID LIBRARY_OWNER_ID = new UUID("11111111-1111-0000-0000-000100bba000"); | ||
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | protected static AssetBase CreateAsset(string assetIdStr, string name, string path, sbyte type) | ||
48 | { | ||
49 | AssetBase asset = new AssetBase(new UUID(assetIdStr), name, type, LIBRARY_OWNER_ID.ToString()); | ||
50 | |||
51 | if (!String.IsNullOrEmpty(path)) | ||
52 | { | ||
53 | //m_log.InfoFormat("[ASSETS]: Loading: [{0}][{1}]", name, path); | ||
54 | |||
55 | LoadAsset(asset, path); | ||
56 | } | ||
57 | else | ||
58 | { | ||
59 | m_log.InfoFormat("[ASSETS]: Instantiated: [{0}]", name); | ||
60 | } | ||
61 | |||
62 | return asset; | ||
63 | } | ||
64 | |||
65 | protected static void LoadAsset(AssetBase info, string path) | ||
66 | { | ||
67 | // bool image = | ||
68 | // (info.Type == (sbyte)AssetType.Texture || | ||
69 | // info.Type == (sbyte)AssetType.TextureTGA || | ||
70 | // info.Type == (sbyte)AssetType.ImageJPEG || | ||
71 | // info.Type == (sbyte)AssetType.ImageTGA); | ||
72 | |||
73 | FileInfo fInfo = new FileInfo(path); | ||
74 | long numBytes = fInfo.Length; | ||
75 | if (fInfo.Exists) | ||
76 | { | ||
77 | FileStream fStream = new FileStream(path, FileMode.Open, FileAccess.Read); | ||
78 | byte[] idata = new byte[numBytes]; | ||
79 | BinaryReader br = new BinaryReader(fStream); | ||
80 | idata = br.ReadBytes((int)numBytes); | ||
81 | br.Close(); | ||
82 | fStream.Close(); | ||
83 | info.Data = idata; | ||
84 | //info.loaded=true; | ||
85 | } | ||
86 | else | ||
87 | { | ||
88 | m_log.ErrorFormat("[ASSETS]: file: [{0}] not found !", path); | ||
89 | } | ||
90 | } | ||
91 | |||
92 | public void ForEachDefaultXmlAsset(string assetSetFilename, Action<AssetBase> action) | ||
93 | { | ||
94 | List<AssetBase> assets = new List<AssetBase>(); | ||
95 | if (File.Exists(assetSetFilename)) | ||
96 | { | ||
97 | string assetSetPath = "ERROR"; | ||
98 | string assetRootPath = ""; | ||
99 | try | ||
100 | { | ||
101 | XmlConfigSource source = new XmlConfigSource(assetSetFilename); | ||
102 | assetRootPath = Path.GetFullPath(source.SavePath); | ||
103 | assetRootPath = Path.GetDirectoryName(assetRootPath); | ||
104 | |||
105 | for (int i = 0; i < source.Configs.Count; i++) | ||
106 | { | ||
107 | assetSetPath = source.Configs[i].GetString("file", String.Empty); | ||
108 | |||
109 | LoadXmlAssetSet(Path.Combine(assetRootPath, assetSetPath), assets); | ||
110 | } | ||
111 | } | ||
112 | catch (XmlException e) | ||
113 | { | ||
114 | m_log.ErrorFormat("[ASSETS]: Error loading {0} : {1}", assetSetPath, e); | ||
115 | } | ||
116 | } | ||
117 | else | ||
118 | { | ||
119 | m_log.ErrorFormat("[ASSETS]: Asset set control file {0} does not exist! No assets loaded.", assetSetFilename); | ||
120 | } | ||
121 | |||
122 | assets.ForEach(action); | ||
123 | } | ||
124 | |||
125 | /// <summary> | ||
126 | /// Use the asset set information at path to load assets | ||
127 | /// </summary> | ||
128 | /// <param name="assetSetPath"></param> | ||
129 | /// <param name="assets"></param> | ||
130 | protected static void LoadXmlAssetSet(string assetSetPath, List<AssetBase> assets) | ||
131 | { | ||
132 | //m_log.InfoFormat("[ASSETS]: Loading asset set {0}", assetSetPath); | ||
133 | |||
134 | if (File.Exists(assetSetPath)) | ||
135 | { | ||
136 | try | ||
137 | { | ||
138 | XmlConfigSource source = new XmlConfigSource(assetSetPath); | ||
139 | String dir = Path.GetDirectoryName(assetSetPath); | ||
140 | |||
141 | for (int i = 0; i < source.Configs.Count; i++) | ||
142 | { | ||
143 | string assetIdStr = source.Configs[i].GetString("assetID", UUID.Random().ToString()); | ||
144 | string name = source.Configs[i].GetString("name", String.Empty); | ||
145 | sbyte type = (sbyte)source.Configs[i].GetInt("assetType", 0); | ||
146 | string assetPath = Path.Combine(dir, source.Configs[i].GetString("fileName", String.Empty)); | ||
147 | |||
148 | AssetBase newAsset = CreateAsset(assetIdStr, name, assetPath, type); | ||
149 | |||
150 | newAsset.Type = type; | ||
151 | assets.Add(newAsset); | ||
152 | } | ||
153 | } | ||
154 | catch (XmlException e) | ||
155 | { | ||
156 | m_log.ErrorFormat("[ASSETS]: Error loading {0} : {1}", assetSetPath, e); | ||
157 | } | ||
158 | } | ||
159 | else | ||
160 | { | ||
161 | m_log.ErrorFormat("[ASSETS]: Asset set file {0} does not exist!", assetSetPath); | ||
162 | } | ||
163 | } | ||
164 | } | ||
165 | } | ||
diff --git a/OpenSim/Framework/AssetLoader/Filesystem/Properties/AssemblyInfo.cs b/OpenSim/Framework/AssetLoader/Filesystem/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..cd182d6 --- /dev/null +++ b/OpenSim/Framework/AssetLoader/Filesystem/Properties/AssemblyInfo.cs | |||
@@ -0,0 +1,33 @@ | |||
1 | using System.Reflection; | ||
2 | using System.Runtime.CompilerServices; | ||
3 | using System.Runtime.InteropServices; | ||
4 | |||
5 | // General Information about an assembly is controlled through the following | ||
6 | // set of attributes. Change these attribute values to modify the information | ||
7 | // associated with an assembly. | ||
8 | [assembly: AssemblyTitle("OpenSim.Framework.AssetLoader.Filesystem")] | ||
9 | [assembly: AssemblyDescription("")] | ||
10 | [assembly: AssemblyConfiguration("")] | ||
11 | [assembly: AssemblyCompany("http://opensimulator.org")] | ||
12 | [assembly: AssemblyProduct("OpenSim")] | ||
13 | [assembly: AssemblyCopyright("OpenSimulator developers")] | ||
14 | [assembly: AssemblyTrademark("")] | ||
15 | [assembly: AssemblyCulture("")] | ||
16 | |||
17 | // Setting ComVisible to false makes the types in this assembly not visible | ||
18 | // to COM components. If you need to access a type in this assembly from | ||
19 | // COM, set the ComVisible attribute to true on that type. | ||
20 | [assembly: ComVisible(false)] | ||
21 | |||
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
23 | [assembly: Guid("8cb9cf69-4771-4d3a-a2ba-bac7230de326")] | ||
24 | |||
25 | // Version information for an assembly consists of the following four values: | ||
26 | // | ||
27 | // Major Version | ||
28 | // Minor Version | ||
29 | // Build Number | ||
30 | // Revision | ||
31 | // | ||
32 | [assembly: AssemblyVersion("0.8.2.*")] | ||
33 | |||