From 4ae10034bd929c6451633c6fc5172c44e9280fa4 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Fri, 28 Dec 2007 22:13:43 +0000 Subject: Factor out common asset loading from AssetServerBase and Grid/AssetServer/Main --- .../Framework/Communications/Cache/AssetServer.cs | 3 +- .../Communications/Cache/AssetServerBase.cs | 102 +-------------------- 2 files changed, 6 insertions(+), 99 deletions(-) (limited to 'OpenSim/Framework/Communications/Cache') diff --git a/OpenSim/Framework/Communications/Cache/AssetServer.cs b/OpenSim/Framework/Communications/Cache/AssetServer.cs index 692ee1e..575e80a 100644 --- a/OpenSim/Framework/Communications/Cache/AssetServer.cs +++ b/OpenSim/Framework/Communications/Cache/AssetServer.cs @@ -122,8 +122,7 @@ namespace OpenSim.Framework.Communications.Cache { MainLog.Instance.Verbose("LOCAL ASSET SERVER", "Setting up asset database"); - ForEachDefaultAsset(StoreAsset); - ForEachXmlAsset(StoreAsset); + base.LoadDefaultAssets(); } } diff --git a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs index 1b2c836..2153fbf 100644 --- a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs +++ b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs @@ -28,12 +28,10 @@ using System; using System.Collections.Generic; -using System.IO; using System.Threading; -using System.Xml; using libsecondlife; -using Nini.Config; using OpenSim.Framework.Console; +using OpenSim.Framework.AssetLoader.Filesystem; namespace OpenSim.Framework.Communications.Cache { @@ -45,6 +43,9 @@ namespace OpenSim.Framework.Communications.Cache protected IAssetProvider m_assetProviderPlugin; protected object syncLock = new object(); + // Temporarily hardcoded - should be a plugin + protected IAssetLoader assetLoader = new AssetLoaderFileSystem(); + protected abstract void StoreAsset(AssetBase asset); protected abstract void CommitAssets(); @@ -85,8 +86,7 @@ namespace OpenSim.Framework.Communications.Cache { MainLog.Instance.Verbose("ASSETSERVER", "Setting up asset database"); - ForEachDefaultAsset(StoreAsset); - ForEachXmlAsset(StoreAsset); + assetLoader.ForEachXmlAsset(StoreAsset); CommitAssets(); } @@ -119,25 +119,6 @@ namespace OpenSim.Framework.Communications.Cache } } - public void LoadAsset(AssetBase info, bool image, string filename) - { - //should request Asset from storage manager - //but for now read from file - - string dataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "assets"); //+ folder; - string fileName = Path.Combine(dataPath, filename); - FileInfo fInfo = new FileInfo(fileName); - long numBytes = fInfo.Length; - FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); - byte[] idata = new byte[numBytes]; - BinaryReader br = new BinaryReader(fStream); - idata = br.ReadBytes((int) numBytes); - br.Close(); - fStream.Close(); - info.Data = idata; - //info.loaded=true; - } - public void SetReceiver(IAssetReceiver receiver) { _receiver = receiver; @@ -179,78 +160,5 @@ namespace OpenSim.Framework.Communications.Cache public void SetServerInfo(string ServerUrl, string ServerKey) { } - - public virtual List GetDefaultAssets() - { - List assets = new List(); - return assets; - } - - public AssetBase CreateImageAsset(string assetIdStr, string name, string filename) - { - return CreateAsset(assetIdStr, name, filename, true); - } - - public void ForEachDefaultAsset(Action action) - { - List assets = GetDefaultAssets(); - assets.ForEach(action); - } - - public AssetBase CreateAsset(string assetIdStr, string name, string filename, bool isImage) - { - AssetBase asset = new AssetBase( - new LLUUID(assetIdStr), - name - ); - - if (!String.IsNullOrEmpty(filename)) - { - MainLog.Instance.Verbose("ASSETS", "Loading: [{0}][{1}]", name, filename); - - LoadAsset(asset, isImage, filename); - } - else - { - MainLog.Instance.Verbose("ASSETS", "Instantiated: [{0}]", name); - } - - return asset; - } - - public void ForEachXmlAsset(Action action) - { - List assets = new List(); - // System.Console.WriteLine("trying loading asset into database"); - string filePath = Path.Combine(Util.configDir(), "OpenSimAssetSet.xml"); - if (File.Exists(filePath)) - { - try - { - XmlConfigSource source = new XmlConfigSource(filePath); - - for (int i = 0; i < source.Configs.Count; i++) - { - // System.Console.WriteLine("loading asset into database"); - string assetIdStr = source.Configs[i].GetString("assetID", LLUUID.Random().ToString()); - string name = source.Configs[i].GetString("name", ""); - sbyte type = (sbyte) source.Configs[i].GetInt("assetType", 0); - sbyte invType = (sbyte) source.Configs[i].GetInt("inventoryType", 0); - string fileName = source.Configs[i].GetString("fileName", ""); - - AssetBase newAsset = CreateAsset(assetIdStr, name, fileName, false); - - newAsset.Type = type; - newAsset.InvType = invType; - assets.Add(newAsset); - } - } - catch (XmlException e) - { - MainLog.Instance.Error("ASSETS", "Error loading " + filePath + ": " + e.ToString()); - } - } - assets.ForEach(action); - } } } \ No newline at end of file -- cgit v1.1