diff --git a/src/Helpers.cs b/src/Helpers.cs index 1d98288..2d57fef 100644 --- a/src/Helpers.cs +++ b/src/Helpers.cs @@ -135,5 +135,19 @@ public static double GetDouble(string value) return result; } + + public static bool IsFileLocked(string filePath) + { + try + { + using FileStream inputStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.None); + inputStream.Close(); + } + catch (Exception) + { + return true; + } + return false; + } } } diff --git a/src/LegendaryDownloadManager.xaml.cs b/src/LegendaryDownloadManager.xaml.cs index 1bc68a1..26810d6 100644 --- a/src/LegendaryDownloadManager.xaml.cs +++ b/src/LegendaryDownloadManager.xaml.cs @@ -216,7 +216,8 @@ public void EnqueueMultipleJobs(List downloadManag public static async Task WaitUntilLegendaryCloses() { - if (File.Exists(Path.Combine(LegendaryLauncher.ConfigPath, "installed.json.lock"))) + var installedLockPath = Path.Combine(LegendaryLauncher.ConfigPath, "installed.json.lock"); + if (File.Exists(installedLockPath) && Helpers.IsFileLocked(installedLockPath)) { await Task.Delay(1000); await WaitUntilLegendaryCloses();