Skip to content

Commit a877966

Browse files
authored
Added software updater
1 parent 6969547 commit a877966

File tree

5 files changed

+110
-11
lines changed

5 files changed

+110
-11
lines changed

Sonic '06 Mod Manager/About.Designer.cs

Lines changed: 24 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sonic '06 Mod Manager/About.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,16 @@ private void LinkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
7878
{
7979
Process.Start("https://twitter.com/sharu6262");
8080
}
81+
82+
private void Button2_Click(object sender, EventArgs e)
83+
{
84+
if (ModManager.serverStatus == "offline") MessageBox.Show("Unable to establish a connection to SEGA Carnival.", "Server Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
85+
else if (ModManager.serverStatus == "down") MessageBox.Show("The update servers are currently undergoing maintenance. Apologies for the inconvenience.", "Server Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
86+
else
87+
{
88+
ModManager.updateState = "user";
89+
ModManager.CheckForUpdates(ModManager.versionNumber, "https://segacarnival.com/hyper/updates/sonic-06-mod-manager/latest-master.exe", "https://segacarnival.com/hyper/updates/sonic-06-mod-manager/latest_master.txt");
90+
}
91+
}
8192
}
8293
}

Sonic '06 Mod Manager/ModManager.cs

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ namespace Sonic_06_Mod_Manager
4040
{
4141
public partial class ModManager : Form
4242
{
43-
public static string versionNumber = "Version 1.03";
44-
public static string installState = "";
43+
public static string versionNumber = "Version 1.04";
44+
public static string updateState;
45+
public static string serverStatus;
46+
public static string installState;
4547
public static bool isCreatorDisposed;
4648
public static string username;
4749
public static string password;
@@ -72,8 +74,61 @@ public ModManager()
7274

7375
public string applicationData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
7476

77+
public static void CheckForUpdates(string currentVersion, string newVersionDownloadLink, string versionInfoLink)
78+
{
79+
try
80+
{
81+
var latestVersion = new Tools.TimedWebClient { Timeout = 100000 }.DownloadString(versionInfoLink);
82+
var changeLogs = new Tools.TimedWebClient { Timeout = 100000 }.DownloadString("https://segacarnival.com/hyper/updates/sonic-06-mod-manager/changelogs.txt");
83+
if (latestVersion.Contains("Version"))
84+
{
85+
if (latestVersion != currentVersion)
86+
{
87+
DialogResult confirmUpdate = MessageBox.Show("Sonic '06 Mod Manager - " + latestVersion + " is now available!\n\nChangelogs:\n" + changeLogs + "\n\nDo you wish to download it?", "New update available!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
88+
switch (confirmUpdate)
89+
{
90+
case DialogResult.Yes:
91+
try
92+
{
93+
if (File.Exists(Application.ExecutablePath))
94+
{
95+
var clientApplication = new WebClient();
96+
clientApplication.DownloadFileAsync(new Uri(newVersionDownloadLink), Application.ExecutablePath + ".pak");
97+
clientApplication.DownloadFileCompleted += (s, e) =>
98+
{
99+
File.Replace(Application.ExecutablePath + ".pak", Application.ExecutablePath, Application.ExecutablePath + ".bak");
100+
Process.Start(Application.ExecutablePath);
101+
Application.Exit();
102+
};
103+
}
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);
109+
}
110+
break;
111+
}
112+
}
113+
else if (updateState == "user") MessageBox.Show("There are currently no updates available.", "Sonic '06 Mod Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
114+
}
115+
else
116+
{
117+
serverStatus = "down";
118+
}
119+
}
120+
catch
121+
{
122+
serverStatus = "offline";
123+
}
124+
125+
updateState = null;
126+
}
127+
75128
private void ModManager_Load(object sender, EventArgs e)
76129
{
130+
CheckForUpdates(versionNumber, "https://segacarnival.com/hyper/updates/sonic-06-mod-manager/latest-master.exe", "https://segacarnival.com/hyper/updates/sonic-06-mod-manager/latest_master.txt");
131+
77132
if (!Directory.Exists($"{applicationData}\\Sonic_06_Mod_Manager\\Tools\\arctool")) Directory.CreateDirectory($"{applicationData}\\Sonic_06_Mod_Manager\\Tools\\arctool");
78133
if (!File.Exists($"{applicationData}\\Sonic_06_Mod_Manager\\Tools\\arctool\\arctool.php")) File.WriteAllBytes($"{applicationData}\\Sonic_06_Mod_Manager\\Tools\\arctool\\arctool.php", Properties.Resources.arctoolphp);
79134
if (!File.Exists($"{applicationData}\\Sonic_06_Mod_Manager\\Tools\\arctool\\unarc.php")) File.WriteAllBytes($"{applicationData}\\Sonic_06_Mod_Manager\\Tools\\arctool\\unarc.php", Properties.Resources.unarcphp);

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.3.0")]
36+
[assembly: AssemblyFileVersion("1.0.4.0")]

Sonic '06 Mod Manager/Tools.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,4 +343,21 @@ public static void Dispose()
343343
}
344344
}
345345
}
346+
347+
public class TimedWebClient : WebClient
348+
{
349+
public int Timeout { get; set; }
350+
351+
public TimedWebClient()
352+
{
353+
Timeout = 100000;
354+
}
355+
356+
protected override WebRequest GetWebRequest(Uri address)
357+
{
358+
var objWebRequest = base.GetWebRequest(address);
359+
objWebRequest.Timeout = Timeout;
360+
return objWebRequest;
361+
}
362+
}
346363
}

0 commit comments

Comments
 (0)