From d6e55fa17f5383b3b4a9d58c81698ae2522db3df Mon Sep 17 00:00:00 2001 From: Kemal Setya Adhi Date: Thu, 26 Dec 2024 00:41:07 +0700 Subject: [PATCH] [HSR] Fix DirectoryNotFoundException on RemoveHashMarkFile --- .../Classes/RepairManagement/StarRail/Check.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/CollapseLauncher/Classes/RepairManagement/StarRail/Check.cs b/CollapseLauncher/Classes/RepairManagement/StarRail/Check.cs index 46fc093ac..7276d2fce 100644 --- a/CollapseLauncher/Classes/RepairManagement/StarRail/Check.cs +++ b/CollapseLauncher/Classes/RepairManagement/StarRail/Check.cs @@ -1,4 +1,5 @@ -using Hi3Helper; +using CollapseLauncher.Helper; +using Hi3Helper; using Hi3Helper.Data; using Hi3Helper.SentryHelper; using Hi3Helper.Shared.ClassStruct; @@ -389,10 +390,18 @@ private static void RemoveHashMarkFile(string filePath, out string basePath, out basePath = Path.GetDirectoryName(filePath); baseName = Path.GetFileNameWithoutExtension(filePath); + // Get directory base info. If it doesn't exist, return + DirectoryInfo basePathDirInfo = new DirectoryInfo(basePath); + if (!basePathDirInfo.Exists) + { + return; + } + // Enumerate any possible existing hash path and delete it - foreach (string existingPath in Directory.EnumerateFiles(basePath!, $"{baseName}_*.hash")) + foreach (FileInfo existingPath in basePathDirInfo.EnumerateFiles($"{baseName}_*.hash") + .EnumerateNoReadOnly()) { - File.Delete(existingPath); + existingPath.Delete(); } } #endregion