From d866451d9bc3e269718db7bfed3565e53b1c6d7c Mon Sep 17 00:00:00 2001 From: Mozi <29089388+pzhlkj6612@users.noreply.github.com> Date: Wed, 8 Jan 2025 01:49:12 +0000 Subject: [PATCH 1/2] Fix incorrect hash calculation for files in nested directories (#628) * Fix path to additional files in inner directories for hash calc Example path: Game Options\AI\No Change.ini * workaround for net48: substring --- DXMainClient/Online/FileHashCalculator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DXMainClient/Online/FileHashCalculator.cs b/DXMainClient/Online/FileHashCalculator.cs index 94a39bef8..fe9596cbe 100644 --- a/DXMainClient/Online/FileHashCalculator.cs +++ b/DXMainClient/Online/FileHashCalculator.cs @@ -151,7 +151,7 @@ public void CalculateHashes() { if (path.Exists) { - foreach (string filename in path.EnumerateFiles("*", SearchOption.AllDirectories).Select(s => s.Name)) + foreach (string filename in path.EnumerateFiles("*", SearchOption.AllDirectories).Select(s => s.FullName.Substring(path.FullName.Length))) { string fileRelativePath = SafePath.CombineFilePath(path.Name, filename); string fileFullPath = SafePath.CombineFilePath(path.FullName, filename); From bae385595f48c525f1f44baf24044f337dc6cae2 Mon Sep 17 00:00:00 2001 From: SadPencil Date: Wed, 8 Jan 2025 09:54:29 +0800 Subject: [PATCH 2/2] Disable showing map preview for maps without texture files (#629) * Disable showing map preview for maps without texture files * Enforce coding style * Update GameInformationPanel.cs * Fix noMapPreview get disposed * Update GameInformationPanel.cs --- .../DXGUI/Multiplayer/GameInformationPanel.cs | 43 +++++++++++++------ DXMainClient/Domain/Multiplayer/Map.cs | 3 ++ 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/DXMainClient/DXGUI/Multiplayer/GameInformationPanel.cs b/DXMainClient/DXGUI/Multiplayer/GameInformationPanel.cs index 895e1a18c..e8be3c255 100644 --- a/DXMainClient/DXGUI/Multiplayer/GameInformationPanel.cs +++ b/DXMainClient/DXGUI/Multiplayer/GameInformationPanel.cs @@ -1,13 +1,16 @@ -using Rampastring.XNAUI.XNAControls; -using Rampastring.XNAUI; -using Microsoft.Xna.Framework; -using DTAClient.Domain.Multiplayer; +using System; +using System.Diagnostics; + +using ClientCore; using ClientCore.Extensions; + +using DTAClient.Domain.Multiplayer; + +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using Rampastring.Tools; -using System.Net.NetworkInformation; -using System; -using ClientCore; + +using Rampastring.XNAUI; +using Rampastring.XNAUI.XNAControls; namespace DTAClient.DXGUI.Multiplayer { @@ -39,7 +42,9 @@ public GameInformationPanel(WindowManager windowManager, MapLoader mapLoader) private XNALabel[] lblPlayerNames; private GenericHostedGame game = null; - private Texture2D mapTexture; + + private bool disposeTextures = false; + private Texture2D mapTexture = null; private Texture2D noMapPreviewTexture = null; private const int leftColumnPositionX = 10; @@ -65,7 +70,7 @@ public override void Initialize() lblGameInformation.FontIndex = 1; lblGameInformation.Text = "GAME INFORMATION".L10N("Client:Main:GameInfo"); - if(AssetLoader.AssetExists("noMapPreview.png")) + if (AssetLoader.AssetExists("noMapPreview.png")) noMapPreviewTexture = AssetLoader.LoadTexture("noMapPreview.png"); rightColumnPositionX = Width / 2 - columnMargin; @@ -189,9 +194,17 @@ public void SetInfo(GenericHostedGame game) if (mapLoader != null) { - mapTexture = mapLoader.GameModeMaps.Find(m => m.Map.Name == game.Map)?.Map.LoadPreviewTexture(); + mapTexture = mapLoader.GameModeMaps.Find(m => m.Map.Name == game.Map && m.Map.IsPreviewTextureCached())?.Map?.LoadPreviewTexture(); if (mapTexture == null && noMapPreviewTexture != null) + { + Debug.Assert(!noMapPreviewTexture.IsDisposed, "noMapPreviewTexture should not be disposed."); mapTexture = noMapPreviewTexture; + disposeTextures = false; + } + else + { + disposeTextures = true; + } } } @@ -208,8 +221,12 @@ public void ClearInfo() foreach (XNALabel label in lblPlayerNames) label.Visible = false; - mapTexture?.Dispose(); - mapTexture = null; + if (mapTexture != null && disposeTextures) + { + Debug.Assert(!mapTexture.IsDisposed, "mapTexture should not be disposed."); + mapTexture.Dispose(); + mapTexture = null; + } } public override void Draw(GameTime gameTime) diff --git a/DXMainClient/Domain/Multiplayer/Map.cs b/DXMainClient/Domain/Multiplayer/Map.cs index 1393dae6f..7e1b4cffd 100644 --- a/DXMainClient/Domain/Multiplayer/Map.cs +++ b/DXMainClient/Domain/Multiplayer/Map.cs @@ -680,6 +680,9 @@ private void ParseSpawnIniOptions(IniFile forcedOptionsIni, string spawnIniOptio } } + public bool IsPreviewTextureCached() => + SafePath.GetFile(ProgramConstants.GamePath, PreviewPath).Exists; + /// /// Loads and returns the map preview texture. ///