1.0 baby!
* add self-updater * fix error-exits * some cleanup Let's call this a stable release.
This commit is contained in:
parent
44f9c1c91e
commit
75762bd44f
4 changed files with 58 additions and 5 deletions
|
@ -19,22 +19,36 @@ namespace EnvyUpdate
|
|||
readonly string startup = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
|
||||
string gpuURL = null;
|
||||
readonly string exeloc = System.Reflection.Assembly.GetEntryAssembly().Location;
|
||||
readonly string exepath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "\\";
|
||||
readonly string exepath = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "\\";
|
||||
readonly string startmenu = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
|
||||
readonly string version = "1.0";
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
Title += " " + version;
|
||||
if (Util.IsInstanceOpen("EnvyUpdate"))
|
||||
{
|
||||
MessageBox.Show("Application is already running.");
|
||||
Application.Current.Shutdown(1);
|
||||
Environment.Exit(1);
|
||||
}
|
||||
if (!Directory.Exists(appdata))
|
||||
{
|
||||
Directory.CreateDirectory(appdata);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (Util.GetNewVer() != version && exepath == appdata)
|
||||
{
|
||||
Util.UpdateApp();
|
||||
}
|
||||
}
|
||||
catch (WebException)
|
||||
{
|
||||
//Silently fail.
|
||||
}
|
||||
|
||||
if (Util.GetLocDriv() != null)
|
||||
{
|
||||
localDriv = Util.GetLocDriv();
|
||||
|
@ -43,7 +57,7 @@ namespace EnvyUpdate
|
|||
else
|
||||
{
|
||||
MessageBox.Show("No NVIDIA GPU found. Application will exit.");
|
||||
Application.Current.Shutdown(255);
|
||||
Environment.Exit(255);
|
||||
}
|
||||
if (File.Exists(appdata + "nvidia-update.txt"))
|
||||
{
|
||||
|
@ -116,7 +130,7 @@ namespace EnvyUpdate
|
|||
{
|
||||
textblockOnline.Foreground = Brushes.Red;
|
||||
buttonDL.Visibility = Visibility.Visible;
|
||||
Notify.ShowUpdatePopup();
|
||||
Notify.ShowDrivUpdatePopup();
|
||||
}
|
||||
else
|
||||
textblockOnline.Foreground = Brushes.Green;
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace EnvyUpdate
|
|||
{
|
||||
class Notify
|
||||
{
|
||||
public static void ShowUpdatePopup()
|
||||
public static void ShowDrivUpdatePopup()
|
||||
{
|
||||
var notificationManager = new NotificationManager();
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ using System.IO;
|
|||
using IWshRuntimeLibrary;
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using System.Net;
|
||||
|
||||
namespace EnvyUpdate
|
||||
{
|
||||
|
@ -105,5 +106,42 @@ namespace EnvyUpdate
|
|||
Application.Current.MainWindow.Show();
|
||||
Application.Current.MainWindow.WindowState = WindowState.Normal;
|
||||
}
|
||||
public static string GetNewVer()
|
||||
{
|
||||
string updPath = "https://raw.githubusercontent.com/fyr77/EnvyUpdate/master/res/version.txt";
|
||||
|
||||
System.Net.WebClient wc = new System.Net.WebClient();
|
||||
string webData = wc.DownloadString(updPath);
|
||||
|
||||
return webData;
|
||||
}
|
||||
/// <summary>
|
||||
/// Updates the application by downloading the new version from Github and replacing the old file using a seperate CMD instance.
|
||||
/// </summary>
|
||||
public static void UpdateApp()
|
||||
{
|
||||
string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\envyupdate\\";
|
||||
|
||||
using (var client = new WebClient())
|
||||
{
|
||||
client.DownloadFile("https://github.com/fyr77/EnvyUpdate/releases/latest/download/EnvyUpdate.exe", appdata + "EnvyUpdated.exe");
|
||||
}
|
||||
|
||||
MessageBox.Show("New version of EnvyUpdate found. Application will restart.\nThis will probably take a few seconds.");
|
||||
|
||||
// Replace exe with new one
|
||||
Process process = new Process();
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo
|
||||
{
|
||||
WindowStyle = ProcessWindowStyle.Hidden,
|
||||
WorkingDirectory = appdata,
|
||||
FileName = "cmd.exe",
|
||||
Arguments = "/C timeout 5 && del EnvyUpdate.exe && ren EnvyUpdated.exe EnvyUpdate.exe && EnvyUpdate.exe"
|
||||
};
|
||||
process.StartInfo = startInfo;
|
||||
process.Start();
|
||||
|
||||
Environment.Exit(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
1
res/version.txt
Normal file
1
res/version.txt
Normal file
|
@ -0,0 +1 @@
|
|||
1.0
|
Reference in a new issue