Skip to content

Commit

Permalink
Added software updater
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperbx authored Jun 27, 2019
1 parent 6969547 commit a877966
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 11 deletions.
32 changes: 24 additions & 8 deletions Sonic '06 Mod Manager/About.Designer.cs

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

11 changes: 11 additions & 0 deletions Sonic '06 Mod Manager/About.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,16 @@ private void LinkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
{
Process.Start("https://twitter.com/sharu6262");
}

private void Button2_Click(object sender, EventArgs e)
{
if (ModManager.serverStatus == "offline") MessageBox.Show("Unable to establish a connection to SEGA Carnival.", "Server Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
else if (ModManager.serverStatus == "down") MessageBox.Show("The update servers are currently undergoing maintenance. Apologies for the inconvenience.", "Server Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
{
ModManager.updateState = "user";
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");
}
}
}
}
59 changes: 57 additions & 2 deletions Sonic '06 Mod Manager/ModManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ namespace Sonic_06_Mod_Manager
{
public partial class ModManager : Form
{
public static string versionNumber = "Version 1.03";
public static string installState = "";
public static string versionNumber = "Version 1.04";
public static string updateState;
public static string serverStatus;
public static string installState;
public static bool isCreatorDisposed;
public static string username;
public static string password;
Expand Down Expand Up @@ -72,8 +74,61 @@ public ModManager()

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

public static void CheckForUpdates(string currentVersion, string newVersionDownloadLink, string versionInfoLink)
{
try
{
var latestVersion = new Tools.TimedWebClient { Timeout = 100000 }.DownloadString(versionInfoLink);
var changeLogs = new Tools.TimedWebClient { Timeout = 100000 }.DownloadString("https://segacarnival.com/hyper/updates/sonic-06-mod-manager/changelogs.txt");
if (latestVersion.Contains("Version"))
{
if (latestVersion != currentVersion)
{
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);
switch (confirmUpdate)
{
case DialogResult.Yes:
try
{
if (File.Exists(Application.ExecutablePath))
{
var clientApplication = new WebClient();
clientApplication.DownloadFileAsync(new Uri(newVersionDownloadLink), Application.ExecutablePath + ".pak");
clientApplication.DownloadFileCompleted += (s, e) =>
{
File.Replace(Application.ExecutablePath + ".pak", Application.ExecutablePath, Application.ExecutablePath + ".bak");
Process.Start(Application.ExecutablePath);
Application.Exit();
};
}
else { MessageBox.Show("Sonic '06 Mod Manager doesn't exist... What?!", "Stupid Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
}
catch
{
MessageBox.Show("An error occurred when updating Sonic '06 Mod Manager.", "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
break;
}
}
else if (updateState == "user") MessageBox.Show("There are currently no updates available.", "Sonic '06 Mod Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
serverStatus = "down";
}
}
catch
{
serverStatus = "offline";
}

updateState = null;
}

private void ModManager_Load(object sender, EventArgs e)
{
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");

if (!Directory.Exists($"{applicationData}\\Sonic_06_Mod_Manager\\Tools\\arctool")) Directory.CreateDirectory($"{applicationData}\\Sonic_06_Mod_Manager\\Tools\\arctool");
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);
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);
Expand Down
2 changes: 1 addition & 1 deletion Sonic '06 Mod Manager/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyFileVersion("1.0.4.0")]
17 changes: 17 additions & 0 deletions Sonic '06 Mod Manager/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,21 @@ public static void Dispose()
}
}
}

public class TimedWebClient : WebClient
{
public int Timeout { get; set; }

public TimedWebClient()
{
Timeout = 100000;
}

protected override WebRequest GetWebRequest(Uri address)
{
var objWebRequest = base.GetWebRequest(address);
objWebRequest.Timeout = Timeout;
return objWebRequest;
}
}
}

0 comments on commit a877966

Please sign in to comment.