From fa3975b4e8e7a3383eb7a2d7de0700fc0c837897 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 15 Oct 2022 21:10:15 +0100 Subject: [PATCH] more useless changes on some oar/iar files --- .../World/Archiver/ArchiveReadRequest.cs | 289 +++++++++--------- .../World/Archiver/AssetsDearchiver.cs | 23 +- 2 files changed, 151 insertions(+), 161 deletions(-) diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs index 568907b076..dc703274e7 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs @@ -131,12 +131,12 @@ namespace OpenSim.Region.CoreModules.World.Archiver /// /// original oar region size. not using Constants.RegionSize /// - protected Vector3 m_incomingRegionSize = new Vector3(256f, 256f, float.MaxValue); + protected Vector3 m_incomingRegionSize = new(256f, 256f, float.MaxValue); /// /// Center around which to apply the rotation relative to the original oar position /// - protected Vector3 m_rotationCenter = new Vector3(128f, 128f, 0f); + protected Vector3 m_rotationCenter = new(128f, 128f, 0f); /// /// Corner 1 of a bounding cuboid which specifies which objects we load from the oar @@ -146,7 +146,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver /// /// Size of a bounding cuboid which specifies which objects we load from the oar /// - protected Vector3 m_boundingSize = new Vector3(Constants.MaximumRegionSize, Constants.MaximumRegionSize, float.MaxValue); + protected Vector3 m_boundingSize = new(Constants.MaximumRegionSize, Constants.MaximumRegionSize, float.MaxValue); protected bool m_noObjects = false; protected bool m_boundingBox = false; @@ -155,17 +155,14 @@ namespace OpenSim.Region.CoreModules.World.Archiver /// /// Used to cache lookups for valid uuids. /// - private IDictionary m_validUserUuids = new Dictionary(); + private readonly Dictionary m_validUserUuids = new(); private IUserManagement m_UserMan; private IUserManagement UserManager { get { - if (m_UserMan == null) - { - m_UserMan = m_rootScene.RequestModuleInterface(); - } + m_UserMan ??= m_rootScene.RequestModuleInterface(); return m_UserMan; } } @@ -173,11 +170,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver /// /// Used to cache lookups for valid groups. /// - private IDictionary m_validGroupUuids = new Dictionary(); + private readonly Dictionary m_validGroupUuids = new(); - private IGroupsModule m_groupsModule; + private readonly IGroupsModule m_groupsModule; - private IAssetService m_assetService = null; + private readonly IAssetService m_assetService = null; private UUID m_defaultUser; @@ -294,10 +291,10 @@ namespace OpenSim.Region.CoreModules.World.Archiver private void loadNeededAssets(assetfileInfo[] assetsFiles, int count, ref int successfulAssetRestores, ref int failedAssetRestores, ref int skipedAssetRestores) { - List ids = new List(count); - List uuids = new List(count); - List types = new List(count); - List datas = new List(count); + List ids = new(count); + List uuids = new(count); + List types = new(count); + List datas = new(count); for (int i = 0; i < count; ++i) { @@ -307,7 +304,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver assetsFiles[i].path = null; assetsFiles[i].data = null; - string filename = assetPath.Substring(ArchiveConstants.ASSETS_PATH.Length); + string filename = assetPath[ArchiveConstants.ASSETS_PATH.Length..]; int indx = filename.LastIndexOf(ArchiveConstants.ASSET_EXTENSION_SEPARATOR); if (indx < 0) { @@ -317,7 +314,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver failedAssetRestores++; continue; } - string extension = filename.Substring(indx); + string extension = filename[indx..]; if (ArchiveConstants.EXTENSION_TO_ASSET_TYPE.ContainsKey(extension)) { string id = filename.Remove(indx); @@ -336,7 +333,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver bool[] exits = m_assetService.AssetsExist(ids.ToArray()); ids.Clear(); - if (exits == null) + if (exits is null) { m_log.Error("[ARCHIVER]: asset service AssetsExists failed"); failedAssetRestores += uuids.Count; @@ -388,19 +385,18 @@ namespace OpenSim.Region.CoreModules.World.Archiver // We dearchive all the scenes at once, because the files in the TAR archive might be mixed. // Therefore, we have to keep track of the dearchive context of all the scenes. - Dictionary sceneContexts = new Dictionary(); + Dictionary sceneContexts = new(); string fullPath = "NONE"; TarArchiveReader archive = null; byte[] data; - TarArchiveReader.TarEntryType entryType; assetfileInfo[] assetsFiles = new assetfileInfo[32]; int assetsFilesCount = 0; try { FindAndLoadControlFile(out archive, out dearchivedScenes); - while ((data = archive.ReadEntry(out fullPath, out entryType)) != null) + while ((data = archive.ReadEntry(out fullPath, out TarArchiveReader.TarEntryType entryType)) is not null) { //m_log.DebugFormat( // "[ARCHIVER]: Successfully read {0} ({1} bytes)", filePath, data.Length); @@ -410,13 +406,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver // Find the scene that this file belongs to - Scene scene; - string filePath; - if (!dearchivedScenes.GetRegionFromPath(fullPath, out scene, out filePath)) + if (!dearchivedScenes.GetRegionFromPath(fullPath, out Scene scene, out string filePath)) continue; // this file belongs to a region that we're not loading DearchiveContext sceneContext = null; - if (scene != null) + if (scene is not null) { if (!sceneContexts.TryGetValue(scene.RegionInfo.RegionID, out sceneContext)) { @@ -427,36 +421,43 @@ namespace OpenSim.Region.CoreModules.World.Archiver // Process the file - if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH) && !m_noObjects) + if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH)) { - sceneContext.SerialisedSceneObjects.Add(Encoding.UTF8.GetString(data)); + if(!m_noObjects) + sceneContext.SerialisedSceneObjects.Add(Encoding.UTF8.GetString(data)); } - else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH) && !m_skipAssets) + else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH)) { - assetfileInfo asf = new assetfileInfo + if(!m_skipAssets) { - path = filePath, - data = data - }; + assetfileInfo asf = new() + { + path = filePath, + data = data + }; - assetsFiles[assetsFilesCount++] = asf; - if (assetsFilesCount == 32) - { - loadNeededAssets(assetsFiles, assetsFilesCount, ref successfulAssetRestores, ref failedAssetRestores, ref skippedAssetRestores); - assetsFilesCount = 0; + assetsFiles[assetsFilesCount++] = asf; + if (assetsFilesCount == 32) + { + loadNeededAssets(assetsFiles, assetsFilesCount, ref successfulAssetRestores, ref failedAssetRestores, ref skippedAssetRestores); + assetsFilesCount = 0; + } } } - else if (filePath.StartsWith(ArchiveConstants.TERRAINS_PATH) && (!m_merge || m_mergeTerrain)) + else if (filePath.StartsWith(ArchiveConstants.TERRAINS_PATH)) { - LoadTerrain(scene, filePath, data); + if(!m_merge || m_mergeTerrain) + LoadTerrain(scene, filePath, data); } - else if (!m_merge && filePath.StartsWith(ArchiveConstants.SETTINGS_PATH)) + else if (filePath.StartsWith(ArchiveConstants.SETTINGS_PATH)) { - LoadRegionSettings(scene, filePath, data, dearchivedScenes); + if(!m_merge) + LoadRegionSettings(scene, filePath, data, dearchivedScenes); } - else if (filePath.StartsWith(ArchiveConstants.LANDDATA_PATH) && (!m_merge || m_mergeParcels)) + else if (filePath.StartsWith(ArchiveConstants.LANDDATA_PATH)) { - sceneContext.SerialisedParcels.Add(Encoding.UTF8.GetString(data)); + if(!m_merge || m_mergeParcels) + sceneContext.SerialisedParcels.Add(Encoding.UTF8.GetString(data)); } else if (filePath == ArchiveConstants.CONTROL_FILE_PATH) { @@ -471,33 +472,32 @@ namespace OpenSim.Region.CoreModules.World.Archiver } catch (Exception e) { - m_log.Error( - String.Format("[ARCHIVER]: Aborting load with error in archive file {0} ", fullPath), e); - m_errorMessage += e.ToString(); + m_log.Error($"[ARCHIVER]: Aborting load with error in archive file {fullPath}: {e.Message}"); + m_errorMessage += e.Message; m_rootScene.EventManager.TriggerOarFileLoaded(m_requestId, new List(), m_errorMessage); return; } finally { - if (archive != null) + if (archive is not null) archive.Close(); } if (!m_skipAssets) { - m_log.InfoFormat("[ARCHIVER]: Restored {0} assets", successfulAssetRestores + skippedAssetRestores); - m_log.InfoFormat("[ARCHIVER]: Skipped {0} asset uploads", skippedAssetRestores); + m_log.Info($"[ARCHIVER]: Restored {successfulAssetRestores + skippedAssetRestores} assets"); + m_log.Info($"[ARCHIVER]: Skipped {skippedAssetRestores} asset uploads"); if (failedAssetRestores > 0) { - m_log.ErrorFormat("[ARCHIVER]: Failed to load {0} assets", failedAssetRestores); - m_errorMessage += String.Format("Failed to load {0} assets", failedAssetRestores); + m_log.Error($"[ARCHIVER]: Failed to load {failedAssetRestores} assets"); + m_errorMessage += $"Failed to load {failedAssetRestores} assets"; } } foreach (DearchiveContext sceneContext in sceneContexts.Values) { - m_log.InfoFormat("[ARCHIVER]: Loading region {0}", sceneContext.Scene.RegionInfo.RegionName); + m_log.Info($"[ARCHIVER]: Loading region {sceneContext.Scene.RegionInfo.RegionName}"); if (!m_merge) { @@ -513,13 +513,13 @@ namespace OpenSim.Region.CoreModules.World.Archiver // Inform any interested parties that the region has changed. We waited until now so that all // of the region's objects will be loaded when we send this notification. IEstateModule estateModule = sceneContext.Scene.RequestModuleInterface(); - if (estateModule != null) + if (estateModule is not null) estateModule.TriggerRegionInfoChange(); } catch (Exception e) { - m_log.Error("[ARCHIVER]: Error loading parcels or objects ", e); - m_errorMessage += e.ToString(); + m_log.Error($"[ARCHIVER]: Error loading parcels or objects :{e.Message}"); + m_errorMessage += e.Message; m_rootScene.EventManager.TriggerOarFileLoaded(m_requestId, new List(), m_errorMessage); return; } @@ -544,7 +544,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver sceneContext.SceneObjects.Clear(); } m_log.Info("[ARCHIVER]: Start scripts done"); - }, null, string.Format("ReadArchiveStartScripts (request {0})", m_requestId)); + }, null, $"ReadArchiveStartScripts (request {m_requestId})"); } m_log.InfoFormat("[ARCHIVER]: Successfully loaded archive"); @@ -567,12 +567,10 @@ namespace OpenSim.Region.CoreModules.World.Archiver archive = new TarArchiveReader(m_loadStream); dearchivedScenes = new DearchiveScenesInfo(); - string filePath; byte[] data; - TarArchiveReader.TarEntryType entryType; bool firstFile = true; - while ((data = archive.ReadEntry(out filePath, out entryType)) != null) + while ((data = archive.ReadEntry(out string filePath, out TarArchiveReader.TarEntryType entryType)) is not null) { if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType) continue; @@ -582,7 +580,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver LoadControlFile(filePath, data, dearchivedScenes); // Find which scenes are available in the simulator - ArchiveScenesGroup simulatorScenes = new ArchiveScenesGroup(); + ArchiveScenesGroup simulatorScenes = new(); SceneManager.Instance.ForEachScene(delegate(Scene scene2) { simulatorScenes.AddScene(scene2); @@ -598,7 +596,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver { m_loadStream.Seek(0, SeekOrigin.Begin); } - else if (m_loadPath != null) + else if (m_loadPath is not null) { archive.Close(); archive = null; @@ -629,10 +627,10 @@ namespace OpenSim.Region.CoreModules.World.Archiver protected void LoadObjects(Scene scene, List serialisedSceneObjects, List sceneObjects) { // Reload serialized prims - m_log.InfoFormat("[ARCHIVER]: Loading {0} scene objects. Please wait.", serialisedSceneObjects.Count); + m_log.Info($"[ARCHIVER]: Loading {serialisedSceneObjects.Count} scene objects. Please wait."); // Convert rotation to radians - double rotation = Math.PI * m_rotation / 180f; + double rotation = MathF.PI * m_rotation / 180f; OpenMetaverse.Quaternion rot = OpenMetaverse.Quaternion.CreateFromAxisAngle(0, 0, 1, (float)rotation); @@ -640,7 +638,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver IRegionSerialiserModule serialiser = scene.RequestModuleInterface(); int sceneObjectsLoadedCount = 0; - Vector3 boundingExtent = new Vector3(m_boundingOrigin.X + m_boundingSize.X, m_boundingOrigin.Y + m_boundingSize.Y, m_boundingOrigin.Z + m_boundingSize.Z); + Vector3 boundingExtent = new(m_boundingOrigin.X + m_boundingSize.X, m_boundingOrigin.Y + m_boundingSize.Y, m_boundingOrigin.Z + m_boundingSize.Z); int mergeskip = 0; foreach (string serialisedSceneObject in serialisedSceneObjects) @@ -660,7 +658,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver Vector3 pos = sceneObject.AbsolutePosition; if (m_debug) - m_log.DebugFormat("[ARCHIVER]: Loading object from OAR with original scene position {0}.", pos.ToString()); + m_log.Debug($"[ARCHIVER]: Loading object from OAR with original scene position {pos}"); // Happily this does not do much to the object since it hasn't been added to the scene yet if (!sceneObject.IsAttachment) @@ -669,8 +667,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver { //fix the rotation center to the middle of the incoming region now as it's otherwise hopelessly confusing on varRegions //as it only works with objects and terrain (using old Merge method) and not parcels - m_rotationCenter.X = m_incomingRegionSize.X / 2; - m_rotationCenter.Y = m_incomingRegionSize.Y / 2; + m_rotationCenter.X = m_incomingRegionSize.X * 0.5f; + m_rotationCenter.Y = m_incomingRegionSize.Y * 0.5f; // Rotate the object sceneObject.RootPart.RotationOffset = rot * sceneObject.GroupRotation; @@ -680,7 +678,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver offset *= rot; // Restore the object position back to relative to the region pos = m_rotationCenter + offset; - if (m_debug) m_log.DebugFormat("[ARCHIVER]: After rotation, object from OAR is at scene position {0}.", pos.ToString()); + if (m_debug) m_log.Debug($"[ARCHIVER]: After rotation, object from OAR is at scene position {pos}"); } if (m_boundingBox) { @@ -688,7 +686,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver || pos.Y < m_boundingOrigin.Y || pos.Y >= boundingExtent.Y || pos.Z < m_boundingOrigin.Z || pos.Z >= boundingExtent.Z) { - if (m_debug) m_log.DebugFormat("[ARCHIVER]: Skipping object from OAR in scene because it's position {0} is outside of bounding cube.", pos.ToString()); + if (m_debug) m_log.Debug($"[ARCHIVER]: Skipping object from OAR in scene because it's position {pos} is outside of bounding cube."); continue; } //adjust object position to be relative to <0,0> so we can apply the displacement @@ -702,15 +700,15 @@ namespace OpenSim.Region.CoreModules.World.Archiver || pos.Y < 0 || pos.Y >= scene.RegionInfo.RegionSizeY || pos.Z < Constants.MinSimulationHeight || pos.Z > Constants.MaxSimulationHeight) { - if (m_debug) m_log.DebugFormat("[ARCHIVER]: Skipping object from OAR After displacement clip {0}.", pos.ToString()); + if (m_debug) m_log.Debug($"[ARCHIVER]: Skipping object from OAR After displacement clip {pos}"); continue; } - if (m_debug) m_log.DebugFormat("[ARCHIVER]: After displacement, object from OAR is at scene position {0}.", pos.ToString()); + if (m_debug) m_log.Debug($"[ARCHIVER]: After displacement, object from OAR is at scene position {pos}"); } sceneObject.AbsolutePosition = pos; } if (m_debug) - m_log.DebugFormat("[ARCHIVER]: Placing object from OAR in scene at position {0}. ", pos.ToString()); + m_log.Debug($"[ARCHIVER]: Placing object from OAR in scene at position {pos}. "); bool isTelehub = (sceneObject.UUID.Equals(oldTelehubUUID)) && (!oldTelehubUUID.IsZero()); @@ -739,22 +737,22 @@ namespace OpenSim.Region.CoreModules.World.Archiver } } - m_log.InfoFormat("[ARCHIVER]: Loaded {0} scene objects to the scene", sceneObjectsLoadedCount); + m_log.Info($"[ARCHIVER]: Loaded {sceneObjectsLoadedCount} scene objects to the scene"); int ignoredObjects = serialisedSceneObjects.Count - sceneObjectsLoadedCount - mergeskip; if(mergeskip > 0) { if(m_mergeReplaceObjects) - m_log.InfoFormat("[ARCHIVER]: Replaced {0} scene objects", mergeskip); + m_log.Info($"[ARCHIVER]: Replaced {mergeskip} scene objects"); else - m_log.InfoFormat("[ARCHIVER]: Skipped {0} scene objects that already existed in the scene", mergeskip); + m_log.Info($"[ARCHIVER]: Skipped {mergeskip} scene objects that already existed in the scene"); } if (ignoredObjects > 0) - m_log.WarnFormat("[ARCHIVER]: Ignored {0} possible out of bounds", ignoredObjects); + m_log.Warn($"[ARCHIVER]: Ignored {ignoredObjects} possible out of bounds"); if (!oldTelehubUUID.IsZero()) { - m_log.WarnFormat("[ARCHIVER]: Telehub object not found: {0}", oldTelehubUUID); + m_log.Warn($"[ARCHIVER]: Telehub object not found: {oldTelehubUUID}"); scene.RegionInfo.RegionSettings.TelehubObject = UUID.Zero; scene.RegionInfo.RegionSettings.ClearSpawnPoints(); } @@ -775,7 +773,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver if (!ResolveUserUuid(scene, part.CreatorID)) part.CreatorID = m_defaultUser; } - if (UserManager != null) + if (UserManager is not null) UserManager.AddCreatorUser(part.CreatorID, part.CreatorData); if (!(ResolveUserUuid(scene, part.OwnerID) || ResolveGroupUuid(part.OwnerID))) @@ -796,11 +794,6 @@ namespace OpenSim.Region.CoreModules.World.Archiver // being no copy/no mod for everyone lock (part.TaskInventory) { -/* avination code disabled for opensim - // And zap any troublesome sit target information - part.SitTargetOrientation = new Quaternion(0, 0, 0, 1); - part.SitTargetPosition = new Vector3(0, 0, 0); -*/ // Fix ownership/creator of inventory items // Not doing so results in inventory items // being no copy/no mod for everyone @@ -820,14 +813,13 @@ namespace OpenSim.Region.CoreModules.World.Archiver kvp.Value.CreatorID = m_defaultUser; } - if (UserManager != null) + if (UserManager is not null) UserManager.AddCreatorUser(kvp.Value.CreatorID, kvp.Value.CreatorData); if (!ResolveGroupUuid(kvp.Value.GroupID)) kvp.Value.GroupID = UUID.Zero; } part.TaskInventory.LockItemsForRead(false); - } } } @@ -846,15 +838,14 @@ namespace OpenSim.Region.CoreModules.World.Archiver } // Reload serialized parcels - m_log.InfoFormat("[ARCHIVER]: Loading {0} parcels. Please wait.", serialisedParcels.Count); - List landData = new List(); - ILandObject landObject = scene.RequestModuleInterface(); + m_log.Info($"[ARCHIVER]: Loading {serialisedParcels.Count} parcels. Please wait."); + List landData = new(); + ILandObject landObject; List parcels; - Vector3 parcelDisp = new Vector3(m_displacement.X, m_displacement.Y, 0f); - Vector2 displacement = new Vector2(m_displacement.X, m_displacement.Y); - Vector2 boundingOrigin = new Vector2(m_boundingOrigin.X, m_boundingOrigin.Y); - Vector2 boundingSize = new Vector2(m_boundingSize.X, m_boundingSize.Y); - Vector2 regionSize = new Vector2(scene.RegionInfo.RegionSizeX, scene.RegionInfo.RegionSizeY); + Vector2 displacement = new(m_displacement.X, m_displacement.Y); + Vector2 boundingOrigin = new(m_boundingOrigin.X, m_boundingOrigin.Y); + Vector2 boundingSize = new(m_boundingSize.X, m_boundingSize.Y); + Vector2 regionSize = new(scene.RegionInfo.RegionSizeX, scene.RegionInfo.RegionSizeY); // Gather any existing parcels before we add any more. Later as we add parcels we can check if the new parcel // data overlays any of the old data, and we can modify and remove (if empty) the old parcel so that there's no conflict @@ -866,31 +857,30 @@ namespace OpenSim.Region.CoreModules.World.Archiver { LandData parcel = LandDataSerializer.Deserialize(serialisedParcel); bool overrideRegionSize = true; //use the src land parcel data size not the dst region size - bool isEmptyNow; // create a new LandObject that we can use to manipulate the incoming source parcel data // this is ok, but just beware that some of the LandObject functions (that we haven't used here) still // assume we're always using the destination region size - LandData ld = new LandData(); - landObject = new LandObject(ld, scene); - landObject.LandData = parcel; + LandData ld = new(); + landObject = new LandObject(ld, scene) + { + LandData = parcel + }; bool[,] srcLandBitmap = landObject.ConvertBytesToLandBitmap(overrideRegionSize); if (landObject.IsLandBitmapEmpty(srcLandBitmap)) { - m_log.InfoFormat("[ARCHIVER]: Skipping source parcel {0} with GlobalID: {1} LocalID: {2} that has no claimed land.", - parcel.Name, parcel.GlobalID, parcel.LocalID); + m_log.Info($"[ARCHIVER]: Skipping source parcel {parcel.Name} with GlobalID: {parcel.GlobalID} LocalID: {parcel.LocalID} that has no claimed land."); continue; } //m_log.DebugFormat("[ARCHIVER]: Showing claimed land for source parcel: {0} with GlobalID: {1} LocalID: {2}.", // parcel.Name, parcel.GlobalID, parcel.LocalID); //landObject.DebugLandBitmap(srcLandBitmap); - bool[,] dstLandBitmap = landObject.RemapLandBitmap(srcLandBitmap, displacement, m_rotation, boundingOrigin, boundingSize, regionSize, out isEmptyNow); + bool[,] dstLandBitmap = landObject.RemapLandBitmap(srcLandBitmap, displacement, m_rotation, boundingOrigin, boundingSize, regionSize, out bool isEmptyNow); if (isEmptyNow) { - m_log.WarnFormat("[ARCHIVER]: Not adding destination parcel {0} with GlobalID: {1} LocalID: {2} because, after applying rotation, bounding and displacement, it has no claimed land.", - parcel.Name, parcel.GlobalID, parcel.LocalID); + m_log.Warn($"[ARCHIVER]: Not adding destination parcel {parcel.Name} with GlobalID: {parcel.GlobalID} LocalID: {parcel.LocalID} because, after applying rotation, bounding and displacement, it has no claimed land."); continue; } //m_log.DebugFormat("[ARCHIVER]: Showing claimed land for destination parcel: {0} with GlobalID: {1} LocalID: {2} after applying rotation, bounding and displacement.", @@ -909,7 +899,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver //and if so modify or lose the existing parcels for (int i = 0; i < parcels.Count; i++) { - if (parcels[i] != null) + if (parcels[i] is not null) { bool[,] modLandBitmap = parcels[i].ConvertBytesToLandBitmap(overrideRegionSize); modLandBitmap = parcels[i].RemoveFromLandBitmap(modLandBitmap, dstLandBitmap, out isEmptyNow); @@ -950,7 +940,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver parcel.OwnerID = m_rootScene.RegionInfo.EstateSettings.EstateOwner; } - List accessList = new List(); + List accessList = new(); foreach (LandAccessEntry entry in parcel.ParcelAccessList) { if (ResolveUserUuid(scene, entry.AgentID)) @@ -959,13 +949,13 @@ namespace OpenSim.Region.CoreModules.World.Archiver } parcel.ParcelAccessList = accessList; - if (m_debug) m_log.DebugFormat("[ARCHIVER]: Adding parcel {0}, local id {1}, owner {2}, group {3}, isGroupOwned {4}, area {5}", - parcel.Name, parcel.LocalID, parcel.OwnerID, parcel.GroupID, parcel.IsGroupOwned, parcel.Area); + if (m_debug) + m_log.Debug($"[ARCHIVER]: Adding parcel {parcel.Name}, local id {parcel.LocalID}, owner {parcel.OwnerID}, group {parcel.GroupID}, isGroupOwned {parcel.IsGroupOwned}, area {parcel.Area}"); landData.Add(parcel); } - m_log.InfoFormat("[ARCHIVER]: Clearing {0} parcels.", parcels.Count); + m_log.Info($"[ARCHIVER]: Clearing {parcels.Count} parcels."); bool setupDefaultParcel = (landData.Count == 0); scene.LandChannel.Clear(setupDefaultParcel); @@ -974,17 +964,17 @@ namespace OpenSim.Region.CoreModules.World.Archiver int j = 0; for (int i = 0; i < parcels.Count; i++) //if merging then we need to also add back in any existing parcels { - if (parcels[i] != null) + if (parcels[i] is not null) { landData.Add(parcels[i].LandData); j++; } } - m_log.InfoFormat("[ARCHIVER]: Keeping {0} old parcels.", j); + m_log.Info($"[ARCHIVER]: Keeping {j} old parcels."); } scene.EventManager.TriggerIncomingLandDataFromStorage(landData); - m_log.InfoFormat("[ARCHIVER]: Added {0} total parcels.", landData.Count); + m_log.Info($"[ARCHIVER]: Added {landData.Count} total parcels."); } /// @@ -1002,7 +992,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver // Note: we call GetUserAccount() inside the lock because this UserID is likely // to occur many times, and we only want to query the users service once. UserAccount account = scene.UserAccountService.GetUserAccount(scene.RegionInfo.ScopeID, uuid); - m_validUserUuids.Add(uuid, account != null); + m_validUserUuids.Add(uuid, account is not null); } return m_validUserUuids[uuid]; @@ -1021,7 +1011,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver if (!m_validGroupUuids.ContainsKey(uuid)) { bool exists; - if (m_groupsModule == null) + if (m_groupsModule is null) { exists = false; } @@ -1029,7 +1019,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver { // Note: we call GetGroupRecord() inside the lock because this GroupID is likely // to occur many times, and we only want to query the groups service once. - exists = (m_groupsModule.GetGroupRecord(uuid) != null); + exists = (m_groupsModule.GetGroupRecord(uuid) is not null); } m_validGroupUuids.Add(uuid, exists); } @@ -1042,7 +1032,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver { if (assetType == (sbyte)AssetType.Unknown) { - m_log.WarnFormat("[ARCHIVER]: Importing {0} byte asset {1} with unknown type", data.Length, assetID.ToString()); + m_log.Warn($"[ARCHIVER]: Importing {data.Length} byte asset {assetID} with unknown type"); } else if (assetType == (sbyte)AssetType.Object) { @@ -1053,13 +1043,15 @@ namespace OpenSim.Region.CoreModules.World.Archiver return true; }); - if (data == null) + if (data is null) return false; } //m_log.DebugFormat("[ARCHIVER]: Importing asset {0}, type {1}", uuid, assetType); - AssetBase asset = new AssetBase(assetID, string.Empty, assetType, UUID.Zero.ToString()); - asset.Data = data; + AssetBase asset = new(assetID, string.Empty, assetType, UUID.Zero.ToString()) + { + Data = data + }; m_assetService.Store(asset); return true; // not right @@ -1078,21 +1070,20 @@ namespace OpenSim.Region.CoreModules.World.Archiver private bool LoadRegionSettings(Scene scene, string settingsPath, byte[] data, DearchiveScenesInfo dearchivedScenes) { RegionSettings loadedRegionSettings; - ViewerEnvironment regionEnv = null; + ViewerEnvironment regionEnv; try { loadedRegionSettings = RegionSettingsSerializer.Deserialize(data, out regionEnv, scene.RegionInfo.EstateSettings); } catch (Exception e) { - m_log.ErrorFormat( - "[ARCHIVER]: Could not parse region settings file {0}. Ignoring. Exception was {1}", - settingsPath, e); + m_log.Error( + $"[ARCHIVER]: Could not parse region settings file {settingsPath}: {e.Message}"); return false; } IEnvironmentModule mEnv = scene.RequestModuleInterface(); - if(mEnv != null) + if(mEnv is not null) { mEnv.StoreOnRegion(regionEnv); mEnv.WindlightRefresh(0); @@ -1144,7 +1135,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver scene.EstateDataServiceSafe?.StoreEstateSettings(scene.RegionInfo.EstateSettings); IEstateModule estateModule = scene.RequestModuleInterface(); - if (estateModule != null) + if (estateModule is not null) estateModule.sendRegionHandshakeToAll(); return true; @@ -1162,21 +1153,20 @@ namespace OpenSim.Region.CoreModules.World.Archiver private bool LoadTerrain(Scene scene, string terrainPath, byte[] data) { ITerrainModule terrainModule = scene.RequestModuleInterface(); - using (MemoryStream ms = new MemoryStream(data)) + using MemoryStream ms = new(data); + + if (!m_displacement.IsZero() || m_rotation != 0f || m_boundingBox) { - if (!m_displacement.IsZero() || m_rotation != 0f || m_boundingBox) - { - Vector2 boundingOrigin = new Vector2(m_boundingOrigin.X, m_boundingOrigin.Y); - Vector2 boundingSize = new Vector2(m_boundingSize.X, m_boundingSize.Y); - terrainModule.LoadFromStream(terrainPath, m_displacement, m_rotation, boundingOrigin, boundingSize, ms); ; - } - else - { - terrainModule.LoadFromStream(terrainPath, ms); - } + Vector2 boundingOrigin = new(m_boundingOrigin.X, m_boundingOrigin.Y); + Vector2 boundingSize = new(m_boundingSize.X, m_boundingSize.Y); + terrainModule.LoadFromStream(terrainPath, m_displacement, m_rotation, boundingOrigin, boundingSize, ms); ; + } + else + { + terrainModule.LoadFromStream(terrainPath, ms); } - m_log.DebugFormat("[ARCHIVER]: Restored terrain {0}", terrainPath); + m_log.Debug($"[ARCHIVER]: Restored terrain {terrainPath}"); return true; } @@ -1189,10 +1179,12 @@ namespace OpenSim.Region.CoreModules.World.Archiver /// public DearchiveScenesInfo LoadControlFile(string path, byte[] data, DearchiveScenesInfo dearchivedScenes) { - XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); - XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None); - XmlTextReader xtr = new XmlTextReader(Encoding.ASCII.GetString(data), XmlNodeType.Document, context); - xtr.DtdProcessing = DtdProcessing.Ignore; + XmlNamespaceManager nsmgr = new(new NameTable()); + XmlParserContext context = new(null, nsmgr, null, XmlSpace.None); + XmlTextReader xtr = new(Encoding.ASCII.GetString(data), XmlNodeType.Document, context) + { + DtdProcessing = DtdProcessing.Ignore + }; // Loaded metadata will be empty if no information exists in the archive dearchivedScenes.LoadedCreationDateTime = 0; @@ -1213,17 +1205,14 @@ namespace OpenSim.Region.CoreModules.World.Archiver if (majorVersion > MAX_MAJOR_VERSION) { throw new Exception( - string.Format( - "The OAR you are trying to load has major version number of {0} but this version of OpenSim can only load OARs with major version number {1} and below", - majorVersion, MAX_MAJOR_VERSION)); + $"The OAR you are trying to load has major version number of {majorVersion} but this version can only load OARs with major version number {MAX_MAJOR_VERSION} and below"); } - m_log.InfoFormat("[ARCHIVER]: Loading OAR with version {0}", version); + m_log.InfoFormat($"[ARCHIVER]: Loading OAR with version {version}"); } else if (xtr.Name.ToString() == "datetime") { - int value; - if (Int32.TryParse(xtr.ReadElementContentAsString(), out value)) + if (Int32.TryParse(xtr.ReadElementContentAsString(), out int value)) dearchivedScenes.LoadedCreationDateTime = value; } else if (xtr.Name.ToString() == "row") @@ -1248,15 +1237,13 @@ namespace OpenSim.Region.CoreModules.World.Archiver } else if (xtr.Name.ToString() == "size_in_meters") { - Vector3 value; - string size = "<" + xtr.ReadElementContentAsString() + ",0>"; - if (Vector3.TryParse(size, out value)) + string size = $"<{xtr.ReadElementContentAsString()},0>"; + if (Vector3.TryParse(size, out Vector3 value)) { m_incomingRegionSize = value; if(multiRegion) dearchivedScenes.SetRegionSize(m_incomingRegionSize); - m_log.DebugFormat("[ARCHIVER]: Found region_size info {0}", - m_incomingRegionSize.ToString()); + m_log.Debug($"[ARCHIVER]: Found region_size info {m_incomingRegionSize}"); } } } @@ -1274,7 +1261,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver } ControlFileLoaded = true; - if(xtr != null) + if(xtr is not null) xtr.Close(); return dearchivedScenes; diff --git a/OpenSim/Region/CoreModules/World/Archiver/AssetsDearchiver.cs b/OpenSim/Region/CoreModules/World/Archiver/AssetsDearchiver.cs index 7bc83ac3b6..3207a1a717 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/AssetsDearchiver.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/AssetsDearchiver.cs @@ -29,7 +29,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Reflection; -using System.Text; using System.Xml; using log4net; using OpenMetaverse; @@ -49,7 +48,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver /// /// Store for asset data we received before we get the metadata /// - protected Dictionary m_assetDataAwaitingMetadata = new Dictionary(); + protected Dictionary m_assetDataAwaitingMetadata = new(); /// /// Asset metadata. Is null if asset metadata isn't yet available. @@ -91,9 +90,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver { m_metadata = new Dictionary(); - StringReader sr = new StringReader(xml); - XmlTextReader reader = new XmlTextReader(sr); - reader.DtdProcessing = DtdProcessing.Ignore; + StringReader sr = new(xml); + XmlTextReader reader = new(sr) + { + DtdProcessing = DtdProcessing.Ignore + }; reader.ReadStartElement("assets"); reader.Read(); @@ -102,7 +103,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver { reader.Read(); - AssetMetadata metadata = new AssetMetadata(); + AssetMetadata metadata = new(); string filename = reader.ReadElementString("filename"); m_log.Debug($"[DEARCHIVER]: Reading node {filename}"); @@ -143,7 +144,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver protected void ResolveAssetData(string assetPath, byte[] data) { // Right now we're nastily obtaining the UUID from the filename - string filename = assetPath.Remove(0, ArchiveConstants.ASSETS_PATH.Length); + string filename = assetPath[ArchiveConstants.ASSETS_PATH.Length..]; if (m_metadata.ContainsKey(filename)) { @@ -155,9 +156,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver m_log.Debug($"[ARCHIVER]: Importing asset {filename}"); - AssetBase asset = new AssetBase(new UUID(filename), metadata.Name, metadata.AssetType, UUID.ZeroString); - asset.Description = metadata.Description; - asset.Data = data; + AssetBase asset = new(new UUID(filename), metadata.Name, metadata.AssetType, UUID.ZeroString) + { + Description = metadata.Description, + Data = data + }; m_cache.Store(asset); }