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