Skip to content

Commit e6dc969

Browse files
authored
Check for multiple instances before updating
1 parent 090f15f commit e6dc969

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

Sonic '06 Mod Manager/ModManager.cs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace Sonic_06_Mod_Manager
4040
{
4141
public partial class ModManager : Form
4242
{
43-
public static string versionNumber = "Version 1.04";
43+
public static string versionNumber = "Version 1.05";
4444
public static string updateState;
4545
public static string serverStatus;
4646
public static string installState;
@@ -88,24 +88,29 @@ public static void CheckForUpdates(string currentVersion, string newVersionDownl
8888
switch (confirmUpdate)
8989
{
9090
case DialogResult.Yes:
91-
try
91+
var exists = System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)).Count() > 1;
92+
if (exists) { MessageBox.Show("Please close any other instances of Sonic '06 Mod Manager and try again.", "Stupid Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
93+
else
9294
{
93-
if (File.Exists(Application.ExecutablePath))
95+
try
9496
{
95-
var clientApplication = new WebClient();
96-
clientApplication.DownloadFileAsync(new Uri(newVersionDownloadLink), Application.ExecutablePath + ".pak");
97-
clientApplication.DownloadFileCompleted += (s, e) =>
97+
if (File.Exists(Application.ExecutablePath))
9898
{
99-
File.Replace(Application.ExecutablePath + ".pak", Application.ExecutablePath, Application.ExecutablePath + ".bak");
100-
Process.Start(Application.ExecutablePath);
101-
Application.Exit();
102-
};
99+
var clientApplication = new WebClient();
100+
clientApplication.DownloadFileAsync(new Uri(newVersionDownloadLink), Application.ExecutablePath + ".pak");
101+
clientApplication.DownloadFileCompleted += (s, e) =>
102+
{
103+
File.Replace(Application.ExecutablePath + ".pak", Application.ExecutablePath, Application.ExecutablePath + ".bak");
104+
Process.Start(Application.ExecutablePath);
105+
Application.Exit();
106+
};
107+
}
108+
else { MessageBox.Show("Sonic '06 Mod Manager doesn't exist... What?!", "Stupid Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
109+
}
110+
catch
111+
{
112+
MessageBox.Show("An error occurred when updating Sonic '06 Mod Manager.", "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
103113
}
104-
else { MessageBox.Show("Sonic '06 Mod Manager doesn't exist... What?!", "Stupid Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
105-
}
106-
catch
107-
{
108-
MessageBox.Show("An error occurred when updating Sonic '06 Mod Manager.", "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
109114
}
110115
break;
111116
}

Sonic '06 Mod Manager/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
3535
[assembly: AssemblyVersion("1.0.0.0")]
36-
[assembly: AssemblyFileVersion("1.0.4.0")]
36+
[assembly: AssemblyFileVersion("1.0.5.0")]

0 commit comments

Comments
 (0)