parent
6da7d0cc00
commit
0cbc98f6a7
3 changed files with 63 additions and 17 deletions
|
@ -4,11 +4,14 @@ namespace CreamInstaller
|
|||
{
|
||||
public class CustomMessageException : Exception
|
||||
{
|
||||
public CustomMessageException(string message) => this.message = message;
|
||||
|
||||
private string message;
|
||||
public override string Message => message ?? "CustomMessageException";
|
||||
|
||||
public override string ToString() => Message;
|
||||
|
||||
public CustomMessageException(string message)
|
||||
{
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -41,18 +41,34 @@ namespace CreamInstaller
|
|||
public static bool IsProgramRunningDialog(Form form, ProgramSelection selection)
|
||||
{
|
||||
if (selection.IsProgramRunning)
|
||||
if (new DialogForm(form).Show(ApplicationName, SystemIcons.Error, $"ERROR: {selection.ProgramName} is currently running!" +
|
||||
$"\n\nPlease close the program/game to continue . . . ", "Retry", "Cancel") == DialogResult.OK)
|
||||
{
|
||||
if (new DialogForm(form).Show(ApplicationName, SystemIcons.Error,
|
||||
$"ERROR: {selection.ProgramName} is currently running!" +
|
||||
"\n\nPlease close the program/game to continue . . . ",
|
||||
"Retry", "Cancel") == DialogResult.OK)
|
||||
{
|
||||
return IsProgramRunningDialog(form, selection);
|
||||
else return true;
|
||||
else return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsFilePathLocked(this string filePath)
|
||||
{
|
||||
try { File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None).Close(); }
|
||||
catch (IOException) { return true; }
|
||||
return false;
|
||||
bool Locked = false;
|
||||
try
|
||||
{
|
||||
File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None).Close();
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
Locked = true;
|
||||
}
|
||||
return Locked;
|
||||
}
|
||||
|
||||
public static SelectForm SelectForm;
|
||||
|
@ -71,16 +87,25 @@ namespace CreamInstaller
|
|||
{
|
||||
Canceled = cancel;
|
||||
if (OutputArchive != null || CancellationTokenSource != null || OutputTask != null || OutputFile != null)
|
||||
{
|
||||
InstallForm?.UpdateUser("Cleaning up . . . ", LogColor.Cleanup);
|
||||
}
|
||||
if (OutputArchive != null)
|
||||
{
|
||||
OutputArchive.Dispose();
|
||||
OutputArchive = null;
|
||||
}
|
||||
if (CancellationTokenSource != null) CancellationTokenSource.Cancel();
|
||||
if (CancellationTokenSource != null)
|
||||
{
|
||||
CancellationTokenSource.Cancel();
|
||||
}
|
||||
if (OutputTask != null)
|
||||
{
|
||||
try { OutputTask.Wait(); } catch (AggregateException) { }
|
||||
try
|
||||
{
|
||||
OutputTask.Wait();
|
||||
}
|
||||
catch (AggregateException) { }
|
||||
OutputTask.Dispose();
|
||||
OutputTask = null;
|
||||
}
|
||||
|
@ -91,8 +116,14 @@ namespace CreamInstaller
|
|||
}
|
||||
if (OutputFile != null && File.Exists(OutputFile))
|
||||
{
|
||||
try { File.Delete(OutputFile); }
|
||||
catch { InstallForm?.UpdateUser($"WARNING: Failed to clean up downloaded archive: {OutputFile}", LogColor.Warning); }
|
||||
try
|
||||
{
|
||||
File.Delete(OutputFile);
|
||||
}
|
||||
catch
|
||||
{
|
||||
InstallForm?.UpdateUser($"WARNING: Failed to clean up downloaded archive: {OutputFile}", LogColor.Warning);
|
||||
}
|
||||
OutputFile = null;
|
||||
}
|
||||
if (logout && MegaApiClient != null && MegaApiClient.IsLoggedIn)
|
||||
|
@ -102,6 +133,9 @@ namespace CreamInstaller
|
|||
}
|
||||
}
|
||||
|
||||
private static void OnApplicationExit(object s, EventArgs e) => Cleanup();
|
||||
private static void OnApplicationExit(object s, EventArgs e)
|
||||
{
|
||||
Cleanup();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,14 +19,23 @@ namespace CreamInstaller
|
|||
foreach (string directory in SteamApiDllDirectories)
|
||||
{
|
||||
string file = directory + "\\steam_api64.dll";
|
||||
if (file.IsFilePathLocked()) return true;
|
||||
if (file.IsFilePathLocked())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public ProgramSelection() => Program.ProgramSelections.Add(this);
|
||||
public ProgramSelection()
|
||||
{
|
||||
Program.ProgramSelections.Add(this);
|
||||
}
|
||||
|
||||
public void Toggle(bool Enabled) => this.Enabled = Enabled;
|
||||
public void Toggle(bool Enabled)
|
||||
{
|
||||
this.Enabled = Enabled;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue