aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs')
-rw-r--r--OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs119
1 files changed, 119 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..6968956
--- /dev/null
+++ b/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs
@@ -0,0 +1,119 @@
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 OpenSim 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
29using System;
30using System.Collections.Generic;
31using System.IO;
32using System.Xml;
33
34using libsecondlife;
35using Nini.Config;
36
37using OpenSim.Framework;
38using OpenSim.Framework.Console;
39
40/// <summary>
41/// Loads assets from the filesystem location. Not yet a plugin, though it should be.
42/// </summary>
43namespace OpenSim.Framework.AssetLoader.Filesystem
44{
45 public class AssetLoaderFileSystem : IAssetLoader
46 {
47 protected AssetBase CreateAsset(string assetIdStr, string name, string filename, bool isImage)
48 {
49 AssetBase asset = new AssetBase(
50 new LLUUID(assetIdStr),
51 name
52 );
53
54 if (!String.IsNullOrEmpty(filename))
55 {
56 MainLog.Instance.Verbose("ASSETS", "Loading: [{0}][{1}]", name, filename);
57
58 LoadAsset(asset, isImage, filename);
59 }
60 else
61 {
62 MainLog.Instance.Verbose("ASSETS", "Instantiated: [{0}]", name);
63 }
64
65 return asset;
66 }
67
68 protected void LoadAsset(AssetBase info, bool image, string filename)
69 {
70 string dataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "assets"); //+ folder;
71 string fileName = Path.Combine(dataPath, filename);
72 FileInfo fInfo = new FileInfo(fileName);
73 long numBytes = fInfo.Length;
74 FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
75 byte[] idata = new byte[numBytes];
76 BinaryReader br = new BinaryReader(fStream);
77 idata = br.ReadBytes((int) numBytes);
78 br.Close();
79 fStream.Close();
80 info.Data = idata;
81 //info.loaded=true;
82 }
83
84 public void ForEachXmlAsset(Action<AssetBase> action)
85 {
86 List<AssetBase> assets = new List<AssetBase>();
87 // System.Console.WriteLine("trying loading asset into database");
88 string filePath = Path.Combine(Util.configDir(), "OpenSimAssetSet.xml");
89 if (File.Exists(filePath))
90 {
91 try
92 {
93 XmlConfigSource source = new XmlConfigSource(filePath);
94
95 for (int i = 0; i < source.Configs.Count; i++)
96 {
97 // System.Console.WriteLine("loading asset into database");
98 string assetIdStr = source.Configs[i].GetString("assetID", LLUUID.Random().ToString());
99 string name = source.Configs[i].GetString("name", "");
100 sbyte type = (sbyte) source.Configs[i].GetInt("assetType", 0);
101 sbyte invType = (sbyte) source.Configs[i].GetInt("inventoryType", 0);
102 string fileName = source.Configs[i].GetString("fileName", "");
103
104 AssetBase newAsset = CreateAsset(assetIdStr, name, fileName, false);
105
106 newAsset.Type = type;
107 newAsset.InvType = invType;
108 assets.Add(newAsset);
109 }
110 }
111 catch (XmlException e)
112 {
113 MainLog.Instance.Error("ASSETS", "Error loading " + filePath + ": " + e.ToString());
114 }
115 }
116 assets.ForEach(action);
117 }
118 }
119}