diff --git a/CreamInstaller/CreamInstaller.csproj b/CreamInstaller/CreamInstaller.csproj index d35351c..a287fbe 100644 --- a/CreamInstaller/CreamInstaller.csproj +++ b/CreamInstaller/CreamInstaller.csproj @@ -4,7 +4,7 @@ net7.0-windows True Resources\ini.ico - 4.7.0.1 + 4.7.0.2 2021, pointfeev (https://github.com/pointfeev) CreamInstaller Automatic DLC Unlocker Installer & Configuration Generator diff --git a/CreamInstaller/ProgramSelection.cs b/CreamInstaller/ProgramSelection.cs index 942b0ce..4e0b0bc 100644 --- a/CreamInstaller/ProgramSelection.cs +++ b/CreamInstaller/ProgramSelection.cs @@ -64,35 +64,31 @@ internal sealed class ProgramSelection if (Platform is Platform.Steam or Platform.Paradox) { directory.GetCreamApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out string config); - if (api32.IsFilePathLocked() || api32_o.IsFilePathLocked() || api64.IsFilePathLocked() || api64_o.IsFilePathLocked() - || config.IsFilePathLocked()) + if (api32.FileLocked() || api32_o.FileLocked() || api64.FileLocked() || api64_o.FileLocked() || config.FileLocked()) return true; directory.GetSmokeApiComponents(out api32, out api32_o, out api64, out api64_o, out string old_config, out config, out string old_log, out string log, out string cache); - if (api32.IsFilePathLocked() || api32_o.IsFilePathLocked() || api64.IsFilePathLocked() || api64_o.IsFilePathLocked() - || old_config.IsFilePathLocked() || config.IsFilePathLocked() || old_log.IsFilePathLocked() || log.IsFilePathLocked() - || cache.IsFilePathLocked()) + if (api32.FileLocked() || api32_o.FileLocked() || api64.FileLocked() || api64_o.FileLocked() || old_config.FileLocked() + || config.FileLocked() || old_log.FileLocked() || log.FileLocked() || cache.FileLocked()) return true; } if (Platform is Platform.Epic or Platform.Paradox) { directory.GetScreamApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out string config, out string log); - if (api32.IsFilePathLocked() || api32_o.IsFilePathLocked() || api64.IsFilePathLocked() || api64_o.IsFilePathLocked() - || config.IsFilePathLocked() || log.IsFilePathLocked()) + if (api32.FileLocked() || api32_o.FileLocked() || api64.FileLocked() || api64_o.FileLocked() || config.FileLocked() || log.FileLocked()) return true; } if (Platform is Platform.Ubisoft) { directory.GetUplayR1Components(out string api32, out string api32_o, out string api64, out string api64_o, out string config, out string log); - if (api32.IsFilePathLocked() || api32_o.IsFilePathLocked() || api64.IsFilePathLocked() || api64_o.IsFilePathLocked() - || config.IsFilePathLocked() || log.IsFilePathLocked()) + if (api32.FileLocked() || api32_o.FileLocked() || api64.FileLocked() || api64_o.FileLocked() || config.FileLocked() || log.FileLocked()) return true; directory.GetUplayR2Components(out string old_api32, out string old_api64, out api32, out api32_o, out api64, out api64_o, out config, out log); - if (old_api32.IsFilePathLocked() || old_api64.IsFilePathLocked() || api32.IsFilePathLocked() || api32_o.IsFilePathLocked() - || api64.IsFilePathLocked() || api64_o.IsFilePathLocked() || config.IsFilePathLocked() || log.IsFilePathLocked()) + if (old_api32.FileLocked() || old_api64.FileLocked() || api32.FileLocked() || api32_o.FileLocked() || api64.FileLocked() + || api64_o.FileLocked() || config.FileLocked() || log.FileLocked()) return true; } } diff --git a/CreamInstaller/Resources/Resources.cs b/CreamInstaller/Resources/Resources.cs index 4090607..c9ba088 100644 --- a/CreamInstaller/Resources/Resources.cs +++ b/CreamInstaller/Resources/Resources.cs @@ -474,23 +474,6 @@ internal static class Resources } } - internal static bool IsFilePathLocked(this string filePath) - { - try - { - File.Open(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None).Close(); - } - catch (FileNotFoundException) - { - return false; - } - catch (IOException) - { - return true; - } - return false; - } - [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode), DefaultDllImportSearchPaths(DllImportSearchPath.System32)] private static extern bool GetBinaryType(string lpApplicationName, out BinaryType lpBinaryType); diff --git a/CreamInstaller/Utility/SafeIO.cs b/CreamInstaller/Utility/SafeIO.cs index 070017a..8fa811b 100644 --- a/CreamInstaller/Utility/SafeIO.cs +++ b/CreamInstaller/Utility/SafeIO.cs @@ -11,6 +11,21 @@ namespace CreamInstaller.Utility; internal static class SafeIO { + internal static bool FileLocked(this string filePath) + { + if (!FileExists(filePath)) + return false; + try + { + File.Open(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None).Close(); + } + catch + { + return true; + } + return false; + } + internal static bool DirectoryExists(this string directoryPath, bool crucial = false, Form form = null) { while (!Program.Canceled)