Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
properly close threads upon exit.
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikx committed Jul 30, 2020
1 parent 3e5dece commit 264a79e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 25 deletions.
10 changes: 10 additions & 0 deletions Metro Skin Installer/Metro Skin Installer/InstallActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
using System.Threading;
using System.Web.Script.Serialization;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.ComponentModel;

namespace Metro_Skin_Installer
{
class InstallActions
{

public static bool workerRequestCancel = false;

public const string SkinFolder = "\\"+"MetroSkin";
public static void UpdateCheck()
{
Expand Down Expand Up @@ -172,6 +177,11 @@ public static void TempExtractPatch()
{
ZipProgressChanged?.Invoke(e.EntriesExtracted * 100 / e.EntriesTotal);
}
if (workerRequestCancel)
{
e.Cancel = true;
}
};
patchZip.ExtractAll(Path.GetTempPath(), ExtractExistingFileAction.OverwriteSilently);
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 45 additions & 24 deletions Metro Skin Installer/Metro Skin Installer/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public MainForm()
{
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;
FormClosing += formClosingHandler;
Thread UpdateCheck = new Thread(InstallActions.UpdateCheck);
UpdateCheck.Start();
if(SteamSkinPath == null)
Expand All @@ -30,6 +31,16 @@ public MainForm()
}
}


private void formClosingHandler (object sender, CancelEventArgs e)
{
InstallActions.workerRequestCancel = true;
if (DownloadPatchWorker.IsBusy)
{
DownloadPatchWorker.CancelAsync();
}
while (DownloadPatchWorker.IsBusy || DownloadWorker.IsBusy) { Application.DoEvents(); };
}
public static bool hasPermission(string dir)
{
try
Expand Down Expand Up @@ -111,42 +122,47 @@ private void InstallExtras()
}

}

private void DownloadPatch_DoWork(object sender, DoWorkEventArgs e) //When select extras window is activated
{
DownloadPatch();
if (DownloadPatchWorker.CancellationPending) { InstallActions.Cleanup(); return; }
progressBar1.Value = 100;
InstallActions.ZipProgressChanged += (f) => { progressBar1.Value = f; };
InstallActions.TempExtractPatch();
InstallActions.ZipProgressChanged -= (f) => { progressBar1.Value = f; };
if (InstallActions.err_ARCHIVE)
if (!DownloadPatchWorker.CancellationPending)
{
page1.Visible = true;
page2patched.Visible = false;
return;
}

extrasListBox.DataSource = InstallActions.DetectExtras();
if (File.Exists(SteamSkinPath + InstallActions.SkinFolder + "\\extras.txt"))
{
string[] savedExtras = File.ReadAllLines(SteamSkinPath + InstallActions.SkinFolder + "\\extras.txt");
for (int i = 0; i < extrasListBox.Items.Count; i++)
if (InstallActions.err_ARCHIVE)
{
if (savedExtras.Contains(extrasListBox.Items[i]))
extrasListBox.SetItemChecked(i, true);
page1.Visible = true;
page2patched.Visible = false;
return;
}
if (savedExtras.Length > 0)
saveExtrasCheckBox.Checked = true;
}
progressBar1.Visible = false;
extrasLoadingText.Visible = false;
saveExtrasCheckBox.Invoke((MethodInvoker)(() => { saveExtrasCheckBox.Visible = true; }));
PatchInstallButton.Enabled = true;
PatchInstallButton.ForeColor = Color.White;
PatchInstallButton.Image = Properties.Resources.right_arrow;

extrasListBox.DataSource = InstallActions.DetectExtras();
if (File.Exists(SteamSkinPath + InstallActions.SkinFolder + "\\extras.txt"))
{
string[] savedExtras = File.ReadAllLines(SteamSkinPath + InstallActions.SkinFolder + "\\extras.txt");
for (int i = 0; i < extrasListBox.Items.Count; i++)
{
if (savedExtras.Contains(extrasListBox.Items[i]))
extrasListBox.SetItemChecked(i, true);
}
if (savedExtras.Length > 0)
saveExtrasCheckBox.Checked = true;
}
progressBar1.Visible = false;
extrasLoadingText.Visible = false;
saveExtrasCheckBox.Invoke((MethodInvoker)(() => { saveExtrasCheckBox.Visible = true; }));
PatchInstallButton.Enabled = true;
PatchInstallButton.ForeColor = Color.White;
PatchInstallButton.Image = Properties.Resources.right_arrow;
} else { InstallActions.Cleanup(); }

}
private void ExitButton_Click(object sender, EventArgs e)
{
InstallActions.Cleanup();
Application.Exit();
}
#region dragabbletitlebar
Expand Down Expand Up @@ -228,6 +244,7 @@ private void PatchInstallButton_Click(object sender, EventArgs e)
InstallerArguments.Add(isPatch);
InstallerPage.Visible = true;
page2patched.Visible = false;
ExitButton.Enabled = false;
DownloadWorker.RunWorkerAsync(InstallerArguments);
}
#endregion
Expand All @@ -248,8 +265,12 @@ private void DownloadPatch()
};

PatchDownloader.DownloadFileAsync(uri, TempDir + "\\installer.zip");
while (PatchDownloader.IsBusy)
while (PatchDownloader.IsBusy )
{
if (DownloadPatchWorker.CancellationPending)
{
PatchDownloader.CancelAsync();
}
Thread.Sleep(500);
}
}
Expand Down

0 comments on commit 264a79e

Please sign in to comment.