Closed RyanWalpole closed 2 years ago
Static download link for latest release: https://github.com/RyanWalpoleEnterprises/Stardew-Valley-Mod-Manager/raw/release-stable/version/StardewModManagerSetup.exe
For use in application to download the latest update.
To implement this chance, we're adding a new setting: Properties.Settings.Default.CheckUpdateOnStartup
which will be TRUE
by default but can be toggled using the new MainPage.TabControl.SettingsTab
private void CheckForUpdatesOnStartup_CheckStateChanged(object sender, EventArgs e)
{
if(CheckForUpdatesOnStartup.Checked == true)
{
Properties.Settings.Default.CheckUpdateOnStartup = "TRUE";
Properties.Settings.Default.Save();
}
if (CheckForUpdatesOnStartup.Checked == false)
{
Properties.Settings.Default.CheckUpdateOnStartup = "FALSE";
Properties.Settings.Default.Save();
}
}
Add a way to toggle this setting on and off. By default this will be set to on, as TRUE
Added a new check to see if the setting is enabled, directing the user to PingNetwork();
instead of Cleanup.Start();
if the user has opted to check for updates on startup.
if(Properties.Settings.Default.CheckUpdateOnStartup == "TRUE")
{
Status.Text = "Contacting Update Server...";
LaunchApplication.Stop();
PingNetwork();
}
else
{
Status.Text = "Launching Mod Manager...";
LaunchApplication.Stop();
Cleanup.Start();
}
Added a new System.Net.NetworkInformation.Ping
operation to see if the GitHub website is online. If the GitHub website returns a IPStatus.Sucess
result, it is assumed that the repository (and update file) will be reachable. If reachable, the application will CheckForUpdate();
- if the user is not connected to a network (offline) or the GitHub website is unreachable, it will continue to launch as normal.
private void PingNetwork()
{
string host = "www.github.com";
Ping p = new Ping();
try
{
PingReply reply = p.Send(host, 7000);
if (reply.Status == IPStatus.Success)
{
CheckForUpdate();
}
else
{
Status.Text = "Launching Mod Manager...";
LaunchApplication.Stop();
Cleanup.Start();
}
}
catch
{
Status.Text = "Launching Mod Manager...";
LaunchApplication.Stop();
Cleanup.Start();
}
}
private void CheckForUpdate()
{
string CurrentUpdateVersion = "https://raw.githubusercontent.com/RyanWalpoleEnterprises/Stardew-Valley-Mod-Manager/main/web/uc.xml";
string LatestRelease = "https://github.com/RyanWalpoleEnterprises/Stardew-Valley-Mod-Manager/releases/latest";
Status.Text = "Checking for updates...";
//MessageBox.Show("Checking for updates...");
//Check for updates
try
{
//View current stable version number
XmlDocument document = new XmlDocument();
document.Load(CurrentUpdateVersion);
string CVER = document.InnerText;
//Compare current stable version against installed version
if (CVER.Contains(Properties.Settings.Default.Version))
{
//No updates available - install version matches stable version
Status.Text = "Launching Mod Manager...";
//MessageBox.Show("No updates found.");
Cleanup.Start();
}
else
{
//Alert to available update
DialogResult dr = MessageBox.Show("There are updates available for Stardew Mod Manager. Would you like to view the latest release?", "Update | Stardew Valley Mod Manager", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
//User clicks yes
if (dr == DialogResult.Yes)
{
try
{
//Process.Start(LatestRelease);
UpdateDownload download = new UpdateDownload();
download.ShowDialog();
Status.Text = "Launching Mod Manager...";
Cleanup.Start();
}
catch
{
Status.Text = "Issue updating. Launching Mod Manager...";
Cleanup.Start();
}
}
else
{
Status.Text = "Launching Mod Manager...";
Cleanup.Start();
}
}
}
catch
{
Status.Text = "Launching Mod Manager...";
Cleanup.Start();
}
}
If an update is available, the application will launch to a new window - UpdateDownload
as a ShowDialog();
event - keeping the splash screen & its progress in suspended state (so that if the user aborts the update, it can continue to run normally)
UpdateDownload is a new window that will replace the previous update method (of launching the release link to the github page and having the user download and update manually) by downloading the executable directly from github and processing it. This will not only be present in the startup update check, but also when updates are checked for manually from the main dashboard.
Is your feature request related to a problem? Please describe. Currently the majority of users are running an outdated version of SDV Mod Manager. An easy way to circumvent this is to take the manual element of updating out of the application and automate it on startup.
Describe the solution you'd like If the user has "Check for updates on startup" checked in the settings, check for updates on startup and prompt to update if there are any available.