|
@@ -27,6 +27,7 @@
|
|
|
|
|
|
using OpenMetaverse;
|
|
|
using System;
|
|
|
+using System.Collections.Frozen;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Globalization;
|
|
|
using System.Runtime.CompilerServices;
|
|
@@ -35,16 +36,12 @@ namespace OpenSim.Framework
|
|
|
{
|
|
|
public static class SLUtil
|
|
|
{
|
|
|
-// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
+ //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
/// <summary>
|
|
|
/// Asset types used only in OpenSim.
|
|
|
/// To avoid clashing with the code numbers used in Second Life, use only negative numbers here.
|
|
|
/// </summary>
|
|
|
- public enum OpenSimAssetType : sbyte
|
|
|
- {
|
|
|
- Material = -2
|
|
|
- }
|
|
|
|
|
|
#region SL / file extension / content-type conversions
|
|
|
|
|
@@ -56,81 +53,48 @@ namespace OpenSim.Framework
|
|
|
{
|
|
|
if (Enum.IsDefined(typeof(OpenMetaverse.AssetType), assetType))
|
|
|
return (OpenMetaverse.AssetType)assetType;
|
|
|
- else if (Enum.IsDefined(typeof(OpenSimAssetType), assetType))
|
|
|
- return (OpenSimAssetType)assetType;
|
|
|
else
|
|
|
return OpenMetaverse.AssetType.Unknown;
|
|
|
}
|
|
|
|
|
|
- private class TypeMapping
|
|
|
+ private struct TypeMapping
|
|
|
{
|
|
|
- private sbyte assetType;
|
|
|
- private sbyte inventoryType;
|
|
|
- private string contentType;
|
|
|
- private string contentType2;
|
|
|
- private string extension;
|
|
|
-
|
|
|
- public sbyte AssetTypeCode
|
|
|
- {
|
|
|
- get { return assetType; }
|
|
|
- }
|
|
|
-
|
|
|
- public object AssetType
|
|
|
- {
|
|
|
- get { return AssetTypeFromCode(assetType); }
|
|
|
- }
|
|
|
-
|
|
|
- public sbyte InventoryType
|
|
|
- {
|
|
|
- get { return inventoryType; }
|
|
|
- }
|
|
|
-
|
|
|
- public string ContentType
|
|
|
- {
|
|
|
- get { return contentType; }
|
|
|
- }
|
|
|
-
|
|
|
- public string ContentType2
|
|
|
- {
|
|
|
- get { return contentType2; }
|
|
|
- }
|
|
|
-
|
|
|
- public string Extension
|
|
|
- {
|
|
|
- get { return extension; }
|
|
|
- }
|
|
|
+ public readonly sbyte AssetType;
|
|
|
+ public readonly sbyte InventoryType;
|
|
|
+ public readonly string ContentType;
|
|
|
+ public readonly string ContentType2;
|
|
|
+ public readonly string Extension;
|
|
|
|
|
|
private TypeMapping(sbyte assetType, sbyte inventoryType, string contentType, string contentType2, string extension)
|
|
|
{
|
|
|
- this.assetType = assetType;
|
|
|
- this.inventoryType = inventoryType;
|
|
|
- this.contentType = contentType;
|
|
|
- this.contentType2 = contentType2;
|
|
|
- this.extension = extension;
|
|
|
+ AssetType = assetType;
|
|
|
+ InventoryType = inventoryType;
|
|
|
+ ContentType = contentType;
|
|
|
+ ContentType2 = contentType2;
|
|
|
+ Extension = extension;
|
|
|
}
|
|
|
|
|
|
public TypeMapping(AssetType assetType, sbyte inventoryType, string contentType, string contentType2, string extension)
|
|
|
- : this((sbyte)assetType, inventoryType, contentType, contentType2, extension)
|
|
|
{
|
|
|
+ AssetType = (sbyte)assetType;
|
|
|
+ InventoryType = inventoryType;
|
|
|
+ ContentType = contentType;
|
|
|
+ ContentType2 = contentType2;
|
|
|
+ Extension = extension;
|
|
|
}
|
|
|
|
|
|
public TypeMapping(AssetType assetType, InventoryType inventoryType, string contentType, string contentType2, string extension)
|
|
|
- : this((sbyte)assetType, (sbyte)inventoryType, contentType, contentType2, extension)
|
|
|
+ : this(assetType, (sbyte)inventoryType, contentType, contentType2, extension)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
public TypeMapping(AssetType assetType, InventoryType inventoryType, string contentType, string extension)
|
|
|
- : this((sbyte)assetType, (sbyte)inventoryType, contentType, null, extension)
|
|
|
+ : this(assetType, (sbyte)inventoryType, contentType, null, extension)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
public TypeMapping(AssetType assetType, FolderType inventoryType, string contentType, string extension)
|
|
|
- : this((sbyte)assetType, (sbyte)inventoryType, contentType, null, extension)
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- public TypeMapping(OpenSimAssetType assetType, InventoryType inventoryType, string contentType, string extension)
|
|
|
- : this((sbyte)assetType, (sbyte)inventoryType, contentType, null, extension)
|
|
|
+ : this(assetType, (sbyte)inventoryType, contentType, null, extension)
|
|
|
{
|
|
|
}
|
|
|
}
|
|
@@ -141,7 +105,7 @@ namespace OpenSim.Framework
|
|
|
/// AssetType "AssetType.Texture" -> Content-Type "image-xj2c"
|
|
|
/// Content-Type "image/x-j2c" -> InventoryType "InventoryType.Texture"
|
|
|
/// </summary>
|
|
|
- private static TypeMapping[] MAPPINGS = new TypeMapping[] {
|
|
|
+ private static TypeMapping[] MAPPINGS = [
|
|
|
new TypeMapping(AssetType.Unknown, InventoryType.Unknown, "application/octet-stream", "bin"),
|
|
|
new TypeMapping(AssetType.Texture, InventoryType.Texture, "image/x-j2c", "image/jp2", "j2c"),
|
|
|
new TypeMapping(AssetType.Texture, InventoryType.Snapshot, "image/x-j2c", "image/jp2", "j2c"),
|
|
@@ -184,15 +148,15 @@ namespace OpenSim.Framework
|
|
|
new TypeMapping(AssetType.Folder, InventoryType.Folder, "application/vnd.ll.folder", "folder"),
|
|
|
|
|
|
// OpenSim specific
|
|
|
- new TypeMapping(OpenSimAssetType.Material, InventoryType.Unknown, "application/llsd+xml", "material")
|
|
|
- };
|
|
|
-
|
|
|
- private static Dictionary<sbyte, string> asset2Content;
|
|
|
- private static Dictionary<sbyte, string> asset2Extension;
|
|
|
- private static Dictionary<sbyte, string> inventory2Content;
|
|
|
- private static Dictionary<string, sbyte> content2Asset;
|
|
|
- private static Dictionary<string, sbyte> content2Inventory;
|
|
|
- private static Dictionary<string, AssetType> name2Asset = new Dictionary<string, AssetType>()
|
|
|
+ new TypeMapping(AssetType.OSMaterial, InventoryType.Unknown, "application/llsd+xml", "material")
|
|
|
+ ];
|
|
|
+
|
|
|
+ private static readonly FrozenDictionary<sbyte, string> asset2Content;
|
|
|
+ private static readonly FrozenDictionary<sbyte, string> asset2Extension;
|
|
|
+ private static readonly FrozenDictionary<sbyte, string> inventory2Content;
|
|
|
+ private static readonly FrozenDictionary<string, sbyte> content2Asset;
|
|
|
+ private static readonly FrozenDictionary<string, sbyte> content2Inventory;
|
|
|
+ private static readonly FrozenDictionary<string, AssetType> name2Asset = new Dictionary<string, AssetType>()
|
|
|
{
|
|
|
{"texture", AssetType.Texture },
|
|
|
{"sound", AssetType.Sound},
|
|
@@ -216,8 +180,9 @@ namespace OpenSim.Framework
|
|
|
{"mesh", AssetType.Mesh},
|
|
|
{"settings", AssetType.Settings},
|
|
|
{"material", AssetType.Material}
|
|
|
- };
|
|
|
- private static Dictionary<string, FolderType> name2Inventory = new Dictionary<string, FolderType>()
|
|
|
+ }.ToFrozenDictionary();
|
|
|
+
|
|
|
+ private static readonly FrozenDictionary<string, FolderType> name2Inventory = new Dictionary<string, FolderType>()
|
|
|
{
|
|
|
{"texture", FolderType.Texture},
|
|
|
{"sound", FolderType.Sound},
|
|
@@ -243,34 +208,39 @@ namespace OpenSim.Framework
|
|
|
{"settings", FolderType.Settings},
|
|
|
{"material", FolderType.Material},
|
|
|
{"suitcase", FolderType.Suitcase}
|
|
|
- };
|
|
|
+ }.ToFrozenDictionary();
|
|
|
|
|
|
static SLUtil()
|
|
|
{
|
|
|
- asset2Content = new Dictionary<sbyte, string>();
|
|
|
- asset2Extension = new Dictionary<sbyte, string>();
|
|
|
- inventory2Content = new Dictionary<sbyte, string>();
|
|
|
- content2Asset = new Dictionary<string, sbyte>();
|
|
|
- content2Inventory = new Dictionary<string, sbyte>();
|
|
|
+ Dictionary<sbyte, string> asset2Contentd = [];
|
|
|
+ Dictionary<sbyte, string> asset2Extensiond = [];
|
|
|
+ Dictionary<sbyte, string> inventory2Contentd = [];
|
|
|
+ Dictionary<string, sbyte> content2Assetd = [];
|
|
|
+ Dictionary<string, sbyte> content2Inventoryd = [];
|
|
|
|
|
|
foreach (TypeMapping mapping in MAPPINGS)
|
|
|
{
|
|
|
- sbyte assetType = mapping.AssetTypeCode;
|
|
|
- asset2Content.TryAdd(assetType, mapping.ContentType);
|
|
|
- asset2Extension.TryAdd(assetType, mapping.Extension);
|
|
|
+ sbyte assetType = mapping.AssetType;
|
|
|
+ asset2Contentd.TryAdd(assetType, mapping.ContentType);
|
|
|
+ asset2Extensiond.TryAdd(assetType, mapping.Extension);
|
|
|
|
|
|
- inventory2Content.TryAdd(mapping.InventoryType, mapping.ContentType);
|
|
|
+ inventory2Contentd.TryAdd(mapping.InventoryType, mapping.ContentType);
|
|
|
|
|
|
- content2Asset.TryAdd(mapping.ContentType, assetType);
|
|
|
+ content2Assetd.TryAdd(mapping.ContentType, assetType);
|
|
|
|
|
|
- content2Inventory.TryAdd(mapping.ContentType, mapping.InventoryType);
|
|
|
+ content2Inventoryd.TryAdd(mapping.ContentType, mapping.InventoryType);
|
|
|
|
|
|
if (mapping.ContentType2 != null)
|
|
|
{
|
|
|
- content2Asset.TryAdd(mapping.ContentType2, assetType);
|
|
|
- content2Inventory.TryAdd(mapping.ContentType2, mapping.InventoryType);
|
|
|
+ content2Assetd.TryAdd(mapping.ContentType2, assetType);
|
|
|
+ content2Inventoryd.TryAdd(mapping.ContentType2, mapping.InventoryType);
|
|
|
}
|
|
|
}
|
|
|
+ asset2Content = asset2Contentd.ToFrozenDictionary();
|
|
|
+ asset2Extension = asset2Extensiond.ToFrozenDictionary();
|
|
|
+ inventory2Content = inventory2Contentd.ToFrozenDictionary();
|
|
|
+ content2Asset = content2Assetd.ToFrozenDictionary();
|
|
|
+ content2Inventory = content2Inventoryd.ToFrozenDictionary();
|
|
|
}
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|