Code cleanup

This commit is contained in:
pointfeev 2021-08-07 18:24:13 -05:00
parent bfaf295339
commit 730d96a473
5 changed files with 112 additions and 66 deletions

View file

@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.IO.Compression;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
namespace CreamInstaller
{
@ -34,7 +34,10 @@ namespace CreamInstaller
if (log && !logTextBox.IsDisposed)
{
if (logTextBox.Text.Length > 0)
{
logTextBox.AppendText(Environment.NewLine, color);
}
logTextBox.AppendText(userInfoLabel.Text, color);
}
}
@ -102,7 +105,9 @@ namespace CreamInstaller
UpdateProgress(100);
if (!Program.IsProgramRunningDialog(this, selection))
{
throw new OperationCanceledException();
}
UpdateProgress(0);
UpdateUser("Installing CreamAPI files for " + selection.ProgramName + " . . . ", LogColor.Operation);
@ -159,9 +164,11 @@ namespace CreamInstaller
string file = keyValuePair.Key;
string backup = keyValuePair.Value;
if (!string.IsNullOrEmpty(backup))
{
File.Delete(backup);
}
}
}
UpdateProgress(100);
}
@ -170,12 +177,16 @@ namespace CreamInstaller
foreach (ProgramSelection selection in Program.ProgramSelections.ToList())
{
if (Program.Canceled)
{
break;
}
Program.Cleanup(cancel: false, logout: false);
if (!Program.IsProgramRunningDialog(this, selection))
{
throw new OperationCanceledException();
}
try
{
@ -202,7 +213,7 @@ namespace CreamInstaller
}
}
private int ProgramCount = Program.ProgramSelections.Count;
private readonly int ProgramCount = Program.ProgramSelections.Count;
private async void Start()
{

View file

@ -1,12 +1,12 @@
using System;
using CG.Web.MegaApiClient;
using Onova;
using Onova.Models;
using Onova.Services;
using System;
using System.Drawing;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using CG.Web.MegaApiClient;
using Onova;
using Onova.Models;
using Onova.Services;
namespace CreamInstaller
{
@ -60,8 +60,10 @@ namespace CreamInstaller
cancellationTokenSource.Dispose();
cancellationTokenSource = null;
if (checkForUpdatesResult.CanUpdate)
{
latestVersion = checkForUpdatesResult.LastVersion;
}
}
catch { }
}

View file

@ -24,10 +24,9 @@ namespace CreamInstaller
public static string BackupFileExtension = ".creaminstaller.backup";
[STAThread]
static void Main()
private static void Main()
{
bool createdNew = true;
Mutex mutex = new Mutex(true, "CreamInstaller", out createdNew);
Mutex mutex = new Mutex(true, "CreamInstaller", out bool createdNew);
if (createdNew)
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
@ -47,8 +46,10 @@ namespace CreamInstaller
$"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;

View file

@ -18,8 +18,10 @@ namespace CreamInstaller
{
string file = directory + "\\steam_api64.dll";
if (file.IsFilePathLocked())
{
return true;
}
}
return false;
}
}
@ -32,13 +34,17 @@ namespace CreamInstaller
public void Add()
{
if (!Program.ProgramSelections.Contains(this))
{
Program.ProgramSelections.Add(this);
}
}
public void Remove()
{
if (Program.ProgramSelections.Contains(this))
{
Program.ProgramSelections.Remove(this);
}
}
}
}

View file

@ -1,14 +1,14 @@
using System;
using System.Windows.Forms;
using CG.Web.MegaApiClient;
using System.Collections.Generic;
using System.IO;
using Microsoft.Win32;
using CG.Web.MegaApiClient;
using Gameloop.Vdf;
using Gameloop.Vdf.Linq;
using System.Threading.Tasks;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CreamInstaller
{
@ -59,16 +59,25 @@ namespace CreamInstaller
private List<string> GetSteamApiDllDirectoriesFromGameDirectory(string gameDirectory, List<string> steamApiDllDirectories = null)
{
if (steamApiDllDirectories is null)
{
steamApiDllDirectories = new();
}
string file = gameDirectory + "\\steam_api64.dll";
if (File.Exists(file))
{
steamApiDllDirectories.Add(gameDirectory);
}
foreach (string _directory in Directory.GetDirectories(gameDirectory))
{
GetSteamApiDllDirectoriesFromGameDirectory(_directory, steamApiDllDirectories);
}
if (!steamApiDllDirectories.Any())
{
return null;
}
return steamApiDllDirectories;
}
@ -93,7 +102,7 @@ namespace CreamInstaller
return null;
}
private List<CheckBox> checkBoxes = new();
private readonly List<CheckBox> checkBoxes = new();
private void GetCreamApiApplicablePrograms(IProgress<int> progress)
{
int maxProgress = 0;
@ -120,8 +129,10 @@ namespace CreamInstaller
rootDirectory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string launcherDirectory = rootDirectory + "\\Programs\\Paradox Interactive";
if (Directory.Exists(launcherDirectory))
{
directories = GetSteamApiDllDirectoriesFromGameDirectory(launcherDirectory);
}
}
else
{
rootDirectory = null;
@ -202,7 +213,7 @@ namespace CreamInstaller
}
else
{
int p = (int)((float)((float)_progress / (float)maxProgress) * 100);
int p = (int)((float)(_progress / (float)maxProgress) * 100);
label2.Text = "Finding CreamAPI-applicable programs on your computer . . . " + p + "% (" + _progress + "/" + maxProgress + ")";
progressBar1.Value = p;
}
@ -218,7 +229,9 @@ namespace CreamInstaller
{
allCheckBox.Enabled = true;
foreach (CheckBox checkBox in checkBoxes)
{
checkBox.Enabled = true;
}
acceptButton.Enabled = true;
}
@ -236,8 +249,10 @@ namespace CreamInstaller
foreach (ProgramSelection selection in Program.ProgramSelections)
{
if (!Program.IsProgramRunningDialog(this, selection))
{
return;
}
}
Hide();
InstallForm installForm = new InstallForm(this);
@ -254,7 +269,10 @@ namespace CreamInstaller
Location = new Point(X, Y);
Show();
}
else Close();
else
{
Close();
}
}
}
@ -267,10 +285,18 @@ namespace CreamInstaller
{
bool shouldCheck = false;
foreach (CheckBox checkBox in checkBoxes)
{
if (!checkBox.Checked)
{
shouldCheck = true;
}
}
foreach (CheckBox checkBox in checkBoxes)
{
checkBox.Checked = shouldCheck;
}
allCheckBox.Checked = shouldCheck;
}
}