diff options
author | John Hurliman | 2009-11-05 13:10:58 -0800 |
---|---|---|
committer | John Hurliman | 2009-11-05 13:10:58 -0800 |
commit | afef1ac191d32e9c1514c294b17e404b1d4ae217 (patch) | |
tree | c390ef81c9c30922c2e95e32844832919884fd9c /OpenSim/Framework | |
parent | Applying #4332, optional packet statistics logging (diff) | |
download | opensim-SC_OLD-afef1ac191d32e9c1514c294b17e404b1d4ae217.zip opensim-SC_OLD-afef1ac191d32e9c1514c294b17e404b1d4ae217.tar.gz opensim-SC_OLD-afef1ac191d32e9c1514c294b17e404b1d4ae217.tar.bz2 opensim-SC_OLD-afef1ac191d32e9c1514c294b17e404b1d4ae217.tar.xz |
Changing the AssetBase constructors to avoid initializing assets with an unknown asset type, and log an error if it ever does happen
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r-- | OpenSim/Framework/AssetBase.cs | 42 | ||||
-rw-r--r-- | OpenSim/Framework/AssetLandmark.cs | 4 | ||||
-rw-r--r-- | OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs | 21 | ||||
-rw-r--r-- | OpenSim/Framework/Capabilities/Caps.cs | 5 | ||||
-rw-r--r-- | OpenSim/Framework/Tests/AssetBaseTest.cs | 3 |
5 files changed, 50 insertions, 25 deletions
diff --git a/OpenSim/Framework/AssetBase.cs b/OpenSim/Framework/AssetBase.cs index 9679ff2..eed9703 100644 --- a/OpenSim/Framework/AssetBase.cs +++ b/OpenSim/Framework/AssetBase.cs | |||
@@ -27,6 +27,8 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Xml.Serialization; | 29 | using System.Xml.Serialization; |
30 | using System.Reflection; | ||
31 | using log4net; | ||
30 | using OpenMetaverse; | 32 | using OpenMetaverse; |
31 | 33 | ||
32 | namespace OpenSim.Framework | 34 | namespace OpenSim.Framework |
@@ -37,6 +39,8 @@ namespace OpenSim.Framework | |||
37 | [Serializable] | 39 | [Serializable] |
38 | public class AssetBase | 40 | public class AssetBase |
39 | { | 41 | { |
42 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
43 | |||
40 | /// <summary> | 44 | /// <summary> |
41 | /// Data of the Asset | 45 | /// Data of the Asset |
42 | /// </summary> | 46 | /// </summary> |
@@ -47,16 +51,34 @@ namespace OpenSim.Framework | |||
47 | /// </summary> | 51 | /// </summary> |
48 | private AssetMetadata m_metadata; | 52 | private AssetMetadata m_metadata; |
49 | 53 | ||
50 | public AssetBase() | 54 | public AssetBase(UUID assetID, string name, sbyte assetType) |
51 | { | 55 | { |
56 | if (assetType == (sbyte)AssetType.Unknown) | ||
57 | { | ||
58 | System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(true); | ||
59 | m_log.ErrorFormat("[ASSETBASE]: Creating asset '{0}' ({1}) with an unknown asset type\n{2}", | ||
60 | name, assetID, trace.ToString()); | ||
61 | } | ||
62 | |||
52 | m_metadata = new AssetMetadata(); | 63 | m_metadata = new AssetMetadata(); |
64 | m_metadata.FullID = assetID; | ||
65 | m_metadata.Name = name; | ||
66 | m_metadata.Type = assetType; | ||
53 | } | 67 | } |
54 | 68 | ||
55 | public AssetBase(UUID assetId, string name) | 69 | public AssetBase(string assetID, string name, sbyte assetType) |
56 | { | 70 | { |
71 | if (assetType == (sbyte)AssetType.Unknown) | ||
72 | { | ||
73 | System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(true); | ||
74 | m_log.ErrorFormat("[ASSETBASE]: Creating asset '{0}' ({1}) with an unknown asset type\n{2}", | ||
75 | name, assetID, trace.ToString()); | ||
76 | } | ||
77 | |||
57 | m_metadata = new AssetMetadata(); | 78 | m_metadata = new AssetMetadata(); |
58 | m_metadata.FullID = assetId; | 79 | m_metadata.ID = assetID; |
59 | m_metadata.Name = name; | 80 | m_metadata.Name = name; |
81 | m_metadata.Type = assetType; | ||
60 | } | 82 | } |
61 | 83 | ||
62 | public bool ContainsReferences | 84 | public bool ContainsReferences |
@@ -193,11 +215,11 @@ namespace OpenSim.Framework | |||
193 | private string m_name = String.Empty; | 215 | private string m_name = String.Empty; |
194 | private string m_description = String.Empty; | 216 | private string m_description = String.Empty; |
195 | private DateTime m_creation_date; | 217 | private DateTime m_creation_date; |
196 | private sbyte m_type; | 218 | private sbyte m_type = (sbyte)AssetType.Unknown; |
197 | private string m_content_type; | 219 | private string m_content_type; |
198 | private byte[] m_sha1; | 220 | private byte[] m_sha1; |
199 | private bool m_local = false; | 221 | private bool m_local; |
200 | private bool m_temporary = false; | 222 | private bool m_temporary; |
201 | //private Dictionary<string, Uri> m_methods = new Dictionary<string, Uri>(); | 223 | //private Dictionary<string, Uri> m_methods = new Dictionary<string, Uri>(); |
202 | //private OSDMap m_extra_data; | 224 | //private OSDMap m_extra_data; |
203 | 225 | ||
@@ -211,7 +233,13 @@ namespace OpenSim.Framework | |||
211 | { | 233 | { |
212 | //get { return m_fullid.ToString(); } | 234 | //get { return m_fullid.ToString(); } |
213 | //set { m_fullid = new UUID(value); } | 235 | //set { m_fullid = new UUID(value); } |
214 | get { return m_id; } | 236 | get |
237 | { | ||
238 | if (String.IsNullOrEmpty(m_id)) | ||
239 | m_id = m_fullid.ToString(); | ||
240 | |||
241 | return m_id; | ||
242 | } | ||
215 | set | 243 | set |
216 | { | 244 | { |
217 | UUID uuid = UUID.Zero; | 245 | UUID uuid = UUID.Zero; |
diff --git a/OpenSim/Framework/AssetLandmark.cs b/OpenSim/Framework/AssetLandmark.cs index fd7a2cd..058b442 100644 --- a/OpenSim/Framework/AssetLandmark.cs +++ b/OpenSim/Framework/AssetLandmark.cs | |||
@@ -38,11 +38,9 @@ namespace OpenSim.Framework | |||
38 | public int Version; | 38 | public int Version; |
39 | 39 | ||
40 | public AssetLandmark(AssetBase a) | 40 | public AssetLandmark(AssetBase a) |
41 | : base(a.FullID, a.Name, a.Type) | ||
41 | { | 42 | { |
42 | Data = a.Data; | 43 | Data = a.Data; |
43 | FullID = a.FullID; | ||
44 | Type = a.Type; | ||
45 | Name = a.Name; | ||
46 | Description = a.Description; | 44 | Description = a.Description; |
47 | InternData(); | 45 | InternData(); |
48 | } | 46 | } |
diff --git a/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs b/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs index a394b1a..9497a2e 100644 --- a/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs +++ b/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs | |||
@@ -43,18 +43,15 @@ namespace OpenSim.Framework.AssetLoader.Filesystem | |||
43 | { | 43 | { |
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
45 | 45 | ||
46 | protected static AssetBase CreateAsset(string assetIdStr, string name, string path, bool isImage) | 46 | protected static AssetBase CreateAsset(string assetIdStr, string name, string path, sbyte type) |
47 | { | 47 | { |
48 | AssetBase asset = new AssetBase( | 48 | AssetBase asset = new AssetBase(new UUID(assetIdStr), name, type); |
49 | new UUID(assetIdStr), | ||
50 | name | ||
51 | ); | ||
52 | 49 | ||
53 | if (!String.IsNullOrEmpty(path)) | 50 | if (!String.IsNullOrEmpty(path)) |
54 | { | 51 | { |
55 | //m_log.InfoFormat("[ASSETS]: Loading: [{0}][{1}]", name, path); | 52 | //m_log.InfoFormat("[ASSETS]: Loading: [{0}][{1}]", name, path); |
56 | 53 | ||
57 | LoadAsset(asset, isImage, path); | 54 | LoadAsset(asset, path); |
58 | } | 55 | } |
59 | else | 56 | else |
60 | { | 57 | { |
@@ -64,8 +61,14 @@ namespace OpenSim.Framework.AssetLoader.Filesystem | |||
64 | return asset; | 61 | return asset; |
65 | } | 62 | } |
66 | 63 | ||
67 | protected static void LoadAsset(AssetBase info, bool image, string path) | 64 | protected static void LoadAsset(AssetBase info, string path) |
68 | { | 65 | { |
66 | bool image = | ||
67 | (info.Type == (sbyte)AssetType.Texture || | ||
68 | info.Type == (sbyte)AssetType.TextureTGA || | ||
69 | info.Type == (sbyte)AssetType.ImageJPEG || | ||
70 | info.Type == (sbyte)AssetType.ImageTGA); | ||
71 | |||
69 | FileInfo fInfo = new FileInfo(path); | 72 | FileInfo fInfo = new FileInfo(path); |
70 | long numBytes = fInfo.Length; | 73 | long numBytes = fInfo.Length; |
71 | if (fInfo.Exists) | 74 | if (fInfo.Exists) |
@@ -138,10 +141,10 @@ namespace OpenSim.Framework.AssetLoader.Filesystem | |||
138 | { | 141 | { |
139 | string assetIdStr = source.Configs[i].GetString("assetID", UUID.Random().ToString()); | 142 | string assetIdStr = source.Configs[i].GetString("assetID", UUID.Random().ToString()); |
140 | string name = source.Configs[i].GetString("name", String.Empty); | 143 | string name = source.Configs[i].GetString("name", String.Empty); |
141 | sbyte type = (sbyte) source.Configs[i].GetInt("assetType", 0); | 144 | sbyte type = (sbyte)source.Configs[i].GetInt("assetType", 0); |
142 | string assetPath = Path.Combine(dir, source.Configs[i].GetString("fileName", String.Empty)); | 145 | string assetPath = Path.Combine(dir, source.Configs[i].GetString("fileName", String.Empty)); |
143 | 146 | ||
144 | AssetBase newAsset = CreateAsset(assetIdStr, name, assetPath, false); | 147 | AssetBase newAsset = CreateAsset(assetIdStr, name, assetPath, type); |
145 | 148 | ||
146 | newAsset.Type = type; | 149 | newAsset.Type = type; |
147 | assets.Add(newAsset); | 150 | assets.Add(newAsset); |
diff --git a/OpenSim/Framework/Capabilities/Caps.cs b/OpenSim/Framework/Capabilities/Caps.cs index ccfe800..72231ca 100644 --- a/OpenSim/Framework/Capabilities/Caps.cs +++ b/OpenSim/Framework/Capabilities/Caps.cs | |||
@@ -888,10 +888,7 @@ namespace OpenSim.Framework.Capabilities | |||
888 | } | 888 | } |
889 | 889 | ||
890 | AssetBase asset; | 890 | AssetBase asset; |
891 | asset = new AssetBase(); | 891 | asset = new AssetBase(assetID, assetName, assType); |
892 | asset.FullID = assetID; | ||
893 | asset.Type = assType; | ||
894 | asset.Name = assetName; | ||
895 | asset.Data = data; | 892 | asset.Data = data; |
896 | if (AddNewAsset != null) | 893 | if (AddNewAsset != null) |
897 | AddNewAsset(asset); | 894 | AddNewAsset(asset); |
diff --git a/OpenSim/Framework/Tests/AssetBaseTest.cs b/OpenSim/Framework/Tests/AssetBaseTest.cs index 3dc6b4e..18a3e01 100644 --- a/OpenSim/Framework/Tests/AssetBaseTest.cs +++ b/OpenSim/Framework/Tests/AssetBaseTest.cs | |||
@@ -67,8 +67,7 @@ namespace OpenSim.Framework.Tests | |||
67 | 67 | ||
68 | private void CheckContainsReferences(AssetType assetType, bool expected) | 68 | private void CheckContainsReferences(AssetType assetType, bool expected) |
69 | { | 69 | { |
70 | AssetBase asset = new AssetBase(); | 70 | AssetBase asset = new AssetBase(UUID.Zero, String.Empty, (sbyte)assetType); |
71 | asset.Type = (sbyte)assetType; | ||
72 | bool actual = asset.ContainsReferences; | 71 | bool actual = asset.ContainsReferences; |
73 | Assert.AreEqual(expected, actual, "Expected "+assetType+".ContainsReferences to be "+expected+" but was "+actual+"."); | 72 | Assert.AreEqual(expected, actual, "Expected "+assetType+".ContainsReferences to be "+expected+" but was "+actual+"."); |
74 | } | 73 | } |