From 257a9ad3989ee5422295eb1be407930725bbc64c Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 21 Apr 2024 13:44:35 +0100 Subject: [PATCH] libomv now knows old opensim material asset type + dotnet8 usless changes --- OpenSim/Framework/SLUtil.cs | 134 +++++++----------- .../Serialization/ArchiveConstants.cs | 5 +- .../Servers/HttpServer/OSHttpRequest.cs | 2 +- .../CoreModules/World/Wind/WindModule.cs | 2 +- .../Region/Framework/Scenes/UuidGatherer.cs | 5 +- .../Materials/MaterialsModule.cs | 3 +- 6 files changed, 59 insertions(+), 92 deletions(-) diff --git a/OpenSim/Framework/SLUtil.cs b/OpenSim/Framework/SLUtil.cs index a36790fd4f..d824bbdf2f 100644 --- a/OpenSim/Framework/SLUtil.cs +++ b/OpenSim/Framework/SLUtil.cs @@ -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); /// /// Asset types used only in OpenSim. /// To avoid clashing with the code numbers used in Second Life, use only negative numbers here. /// - 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" /// - 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") - }; + new TypeMapping(AssetType.OSMaterial, InventoryType.Unknown, "application/llsd+xml", "material") + ]; - private static Dictionary asset2Content; - private static Dictionary asset2Extension; - private static Dictionary inventory2Content; - private static Dictionary content2Asset; - private static Dictionary content2Inventory; - private static Dictionary name2Asset = new Dictionary() + private static readonly FrozenDictionary asset2Content; + private static readonly FrozenDictionary asset2Extension; + private static readonly FrozenDictionary inventory2Content; + private static readonly FrozenDictionary content2Asset; + private static readonly FrozenDictionary content2Inventory; + private static readonly FrozenDictionary name2Asset = new Dictionary() { {"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 name2Inventory = new Dictionary() + }.ToFrozenDictionary(); + + private static readonly FrozenDictionary name2Inventory = new Dictionary() { {"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(); - asset2Extension = new Dictionary(); - inventory2Content = new Dictionary(); - content2Asset = new Dictionary(); - content2Inventory = new Dictionary(); + Dictionary asset2Contentd = []; + Dictionary asset2Extensiond = []; + Dictionary inventory2Contentd = []; + Dictionary content2Assetd = []; + Dictionary 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)] diff --git a/OpenSim/Framework/Serialization/ArchiveConstants.cs b/OpenSim/Framework/Serialization/ArchiveConstants.cs index 63d8bd14fb..245bc0bf28 100644 --- a/OpenSim/Framework/Serialization/ArchiveConstants.cs +++ b/OpenSim/Framework/Serialization/ArchiveConstants.cs @@ -29,7 +29,6 @@ using System; using System.Collections.Generic; using System.Text; using OpenMetaverse; -using OpenSimAssetType = OpenSim.Framework.SLUtil.OpenSimAssetType; namespace OpenSim.Framework.Serialization { @@ -125,7 +124,7 @@ namespace OpenSim.Framework.Serialization ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.SoundWAV] = ASSET_EXTENSION_SEPARATOR + "sound.wav"; ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Texture] = ASSET_EXTENSION_SEPARATOR + "texture.jp2"; ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.TextureTGA] = ASSET_EXTENSION_SEPARATOR + "texture.tga"; - ASSET_TYPE_TO_EXTENSION[(sbyte)OpenSimAssetType.Material] = ASSET_EXTENSION_SEPARATOR + "material.xml"; + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.OSMaterial] = ASSET_EXTENSION_SEPARATOR + "material.xml"; ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Settings] = ASSET_EXTENSION_SEPARATOR + "settings.bin"; ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Material] = ASSET_EXTENSION_SEPARATOR + "prmat.dat"; @@ -148,7 +147,7 @@ namespace OpenSim.Framework.Serialization EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "sound.wav"] = (sbyte)AssetType.SoundWAV; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.jp2"] = (sbyte)AssetType.Texture; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.tga"] = (sbyte)AssetType.TextureTGA; - EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "material.xml"] = (sbyte)OpenSimAssetType.Material; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "material.xml"] = (sbyte)AssetType.OSMaterial; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "settings.bin"] = (sbyte)AssetType.Settings; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "prmat.dat"] = (sbyte)AssetType.Material; } diff --git a/OpenSim/Framework/Servers/HttpServer/OSHttpRequest.cs b/OpenSim/Framework/Servers/HttpServer/OSHttpRequest.cs index de54dd5e03..7510e04469 100644 --- a/OpenSim/Framework/Servers/HttpServer/OSHttpRequest.cs +++ b/OpenSim/Framework/Servers/HttpServer/OSHttpRequest.cs @@ -263,7 +263,7 @@ namespace OpenSim.Framework.Servers.HttpServer NameValueCollection q = m_request.QueryString; _queryAsDictionay = new Dictionary(); m_queryFlags = new HashSet(); - for(int i = 0; i