- Fixed a file locked exception
This commit is contained in:
pointfeev 2023-03-02 13:40:16 -05:00
parent 39e5ba06ad
commit c8c3354379
4 changed files with 23 additions and 29 deletions

View file

@ -4,7 +4,7 @@
<TargetFramework>net7.0-windows</TargetFramework> <TargetFramework>net7.0-windows</TargetFramework>
<UseWindowsForms>True</UseWindowsForms> <UseWindowsForms>True</UseWindowsForms>
<ApplicationIcon>Resources\ini.ico</ApplicationIcon> <ApplicationIcon>Resources\ini.ico</ApplicationIcon>
<Version>4.7.0.1</Version> <Version>4.7.0.2</Version>
<Copyright>2021, pointfeev (https://github.com/pointfeev)</Copyright> <Copyright>2021, pointfeev (https://github.com/pointfeev)</Copyright>
<Company>CreamInstaller</Company> <Company>CreamInstaller</Company>
<Product>Automatic DLC Unlocker Installer &amp; Configuration Generator</Product> <Product>Automatic DLC Unlocker Installer &amp; Configuration Generator</Product>

View file

@ -64,35 +64,31 @@ internal sealed class ProgramSelection
if (Platform is Platform.Steam or Platform.Paradox) 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); 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() if (api32.FileLocked() || api32_o.FileLocked() || api64.FileLocked() || api64_o.FileLocked() || config.FileLocked())
|| config.IsFilePathLocked())
return true; return true;
directory.GetSmokeApiComponents(out api32, out api32_o, out api64, out api64_o, out string old_config, out config, out string old_log, 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); out string log, out string cache);
if (api32.IsFilePathLocked() || api32_o.IsFilePathLocked() || api64.IsFilePathLocked() || api64_o.IsFilePathLocked() if (api32.FileLocked() || api32_o.FileLocked() || api64.FileLocked() || api64_o.FileLocked() || old_config.FileLocked()
|| old_config.IsFilePathLocked() || config.IsFilePathLocked() || old_log.IsFilePathLocked() || log.IsFilePathLocked() || config.FileLocked() || old_log.FileLocked() || log.FileLocked() || cache.FileLocked())
|| cache.IsFilePathLocked())
return true; return true;
} }
if (Platform is Platform.Epic or Platform.Paradox) 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, directory.GetScreamApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out string config,
out string log); out string log);
if (api32.IsFilePathLocked() || api32_o.IsFilePathLocked() || api64.IsFilePathLocked() || api64_o.IsFilePathLocked() if (api32.FileLocked() || api32_o.FileLocked() || api64.FileLocked() || api64_o.FileLocked() || config.FileLocked() || log.FileLocked())
|| config.IsFilePathLocked() || log.IsFilePathLocked())
return true; return true;
} }
if (Platform is Platform.Ubisoft) if (Platform is Platform.Ubisoft)
{ {
directory.GetUplayR1Components(out string api32, out string api32_o, out string api64, out string api64_o, out string config, directory.GetUplayR1Components(out string api32, out string api32_o, out string api64, out string api64_o, out string config,
out string log); out string log);
if (api32.IsFilePathLocked() || api32_o.IsFilePathLocked() || api64.IsFilePathLocked() || api64_o.IsFilePathLocked() if (api32.FileLocked() || api32_o.FileLocked() || api64.FileLocked() || api64_o.FileLocked() || config.FileLocked() || log.FileLocked())
|| config.IsFilePathLocked() || log.IsFilePathLocked())
return true; return true;
directory.GetUplayR2Components(out string old_api32, out string old_api64, out api32, out api32_o, out api64, out api64_o, out config, directory.GetUplayR2Components(out string old_api32, out string old_api64, out api32, out api32_o, out api64, out api64_o, out config,
out log); out log);
if (old_api32.IsFilePathLocked() || old_api64.IsFilePathLocked() || api32.IsFilePathLocked() || api32_o.IsFilePathLocked() if (old_api32.FileLocked() || old_api64.FileLocked() || api32.FileLocked() || api32_o.FileLocked() || api64.FileLocked()
|| api64.IsFilePathLocked() || api64_o.IsFilePathLocked() || config.IsFilePathLocked() || log.IsFilePathLocked()) || api64_o.FileLocked() || config.FileLocked() || log.FileLocked())
return true; return true;
} }
} }

View file

@ -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)] [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode), DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
private static extern bool GetBinaryType(string lpApplicationName, out BinaryType lpBinaryType); private static extern bool GetBinaryType(string lpApplicationName, out BinaryType lpBinaryType);

View file

@ -11,6 +11,21 @@ namespace CreamInstaller.Utility;
internal static class SafeIO 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) internal static bool DirectoryExists(this string directoryPath, bool crucial = false, Form form = null)
{ {
while (!Program.Canceled) while (!Program.Canceled)