Changing the AssetBase constructors to avoid initializing assets with an unknown asset type, and log an error if it ever does happen

This commit is contained in:
John Hurliman
2009-11-05 13:10:58 -08:00
parent e6d7303b29
commit afef1ac191
31 changed files with 105 additions and 122 deletions

View File

@@ -27,6 +27,8 @@
using System;
using System.Xml.Serialization;
using System.Reflection;
using log4net;
using OpenMetaverse;
namespace OpenSim.Framework
@@ -37,6 +39,8 @@ namespace OpenSim.Framework
[Serializable]
public class AssetBase
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// Data of the Asset
/// </summary>
@@ -47,16 +51,34 @@ namespace OpenSim.Framework
/// </summary>
private AssetMetadata m_metadata;
public AssetBase()
public AssetBase(UUID assetID, string name, sbyte assetType)
{
if (assetType == (sbyte)AssetType.Unknown)
{
System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(true);
m_log.ErrorFormat("[ASSETBASE]: Creating asset '{0}' ({1}) with an unknown asset type\n{2}",
name, assetID, trace.ToString());
}
m_metadata = new AssetMetadata();
m_metadata.FullID = assetID;
m_metadata.Name = name;
m_metadata.Type = assetType;
}
public AssetBase(UUID assetId, string name)
public AssetBase(string assetID, string name, sbyte assetType)
{
if (assetType == (sbyte)AssetType.Unknown)
{
System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(true);
m_log.ErrorFormat("[ASSETBASE]: Creating asset '{0}' ({1}) with an unknown asset type\n{2}",
name, assetID, trace.ToString());
}
m_metadata = new AssetMetadata();
m_metadata.FullID = assetId;
m_metadata.ID = assetID;
m_metadata.Name = name;
m_metadata.Type = assetType;
}
public bool ContainsReferences
@@ -193,11 +215,11 @@ namespace OpenSim.Framework
private string m_name = String.Empty;
private string m_description = String.Empty;
private DateTime m_creation_date;
private sbyte m_type;
private sbyte m_type = (sbyte)AssetType.Unknown;
private string m_content_type;
private byte[] m_sha1;
private bool m_local = false;
private bool m_temporary = false;
private bool m_local;
private bool m_temporary;
//private Dictionary<string, Uri> m_methods = new Dictionary<string, Uri>();
//private OSDMap m_extra_data;
@@ -211,7 +233,13 @@ namespace OpenSim.Framework
{
//get { return m_fullid.ToString(); }
//set { m_fullid = new UUID(value); }
get { return m_id; }
get
{
if (String.IsNullOrEmpty(m_id))
m_id = m_fullid.ToString();
return m_id;
}
set
{
UUID uuid = UUID.Zero;

View File

@@ -38,11 +38,9 @@ namespace OpenSim.Framework
public int Version;
public AssetLandmark(AssetBase a)
: base(a.FullID, a.Name, a.Type)
{
Data = a.Data;
FullID = a.FullID;
Type = a.Type;
Name = a.Name;
Description = a.Description;
InternData();
}

View File

@@ -43,18 +43,15 @@ namespace OpenSim.Framework.AssetLoader.Filesystem
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
protected static AssetBase CreateAsset(string assetIdStr, string name, string path, bool isImage)
protected static AssetBase CreateAsset(string assetIdStr, string name, string path, sbyte type)
{
AssetBase asset = new AssetBase(
new UUID(assetIdStr),
name
);
AssetBase asset = new AssetBase(new UUID(assetIdStr), name, type);
if (!String.IsNullOrEmpty(path))
{
//m_log.InfoFormat("[ASSETS]: Loading: [{0}][{1}]", name, path);
LoadAsset(asset, isImage, path);
LoadAsset(asset, path);
}
else
{
@@ -64,8 +61,14 @@ namespace OpenSim.Framework.AssetLoader.Filesystem
return asset;
}
protected static void LoadAsset(AssetBase info, bool image, string path)
protected static void LoadAsset(AssetBase info, string path)
{
bool image =
(info.Type == (sbyte)AssetType.Texture ||
info.Type == (sbyte)AssetType.TextureTGA ||
info.Type == (sbyte)AssetType.ImageJPEG ||
info.Type == (sbyte)AssetType.ImageTGA);
FileInfo fInfo = new FileInfo(path);
long numBytes = fInfo.Length;
if (fInfo.Exists)
@@ -138,10 +141,10 @@ namespace OpenSim.Framework.AssetLoader.Filesystem
{
string assetIdStr = source.Configs[i].GetString("assetID", UUID.Random().ToString());
string name = source.Configs[i].GetString("name", String.Empty);
sbyte type = (sbyte) source.Configs[i].GetInt("assetType", 0);
sbyte type = (sbyte)source.Configs[i].GetInt("assetType", 0);
string assetPath = Path.Combine(dir, source.Configs[i].GetString("fileName", String.Empty));
AssetBase newAsset = CreateAsset(assetIdStr, name, assetPath, false);
AssetBase newAsset = CreateAsset(assetIdStr, name, assetPath, type);
newAsset.Type = type;
assets.Add(newAsset);

View File

@@ -888,10 +888,7 @@ namespace OpenSim.Framework.Capabilities
}
AssetBase asset;
asset = new AssetBase();
asset.FullID = assetID;
asset.Type = assType;
asset.Name = assetName;
asset = new AssetBase(assetID, assetName, assType);
asset.Data = data;
if (AddNewAsset != null)
AddNewAsset(asset);

View File

@@ -67,8 +67,7 @@ namespace OpenSim.Framework.Tests
private void CheckContainsReferences(AssetType assetType, bool expected)
{
AssetBase asset = new AssetBase();
asset.Type = (sbyte)assetType;
AssetBase asset = new AssetBase(UUID.Zero, String.Empty, (sbyte)assetType);
bool actual = asset.ContainsReferences;
Assert.AreEqual(expected, actual, "Expected "+assetType+".ContainsReferences to be "+expected+" but was "+actual+".");
}