From 212dd5958e5b0a2d722a576f07c9a40d9f38877e Mon Sep 17 00:00:00 2001 From: Jakob Date: Sat, 9 Nov 2019 19:15:20 +0100 Subject: [PATCH] fix issues #2 and #3 --- EnvyUpdate.sln | 4 ++-- EnvyUpdate/MainWindow.xaml.cs | 45 ++++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/EnvyUpdate.sln b/EnvyUpdate.sln index 5a12df1..6878393 100644 --- a/EnvyUpdate.sln +++ b/EnvyUpdate.sln @@ -11,8 +11,8 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {1BF2468D-9579-462D-9153-4836E9C8721F}.Debug|Any CPU.ActiveCfg = Release|Any CPU - {1BF2468D-9579-462D-9153-4836E9C8721F}.Debug|Any CPU.Build.0 = Release|Any CPU + {1BF2468D-9579-462D-9153-4836E9C8721F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1BF2468D-9579-462D-9153-4836E9C8721F}.Debug|Any CPU.Build.0 = Debug|Any CPU {1BF2468D-9579-462D-9153-4836E9C8721F}.Release|Any CPU.ActiveCfg = Release|Any CPU {1BF2468D-9579-462D-9153-4836E9C8721F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection diff --git a/EnvyUpdate/MainWindow.xaml.cs b/EnvyUpdate/MainWindow.xaml.cs index 832e83a..a8b0313 100644 --- a/EnvyUpdate/MainWindow.xaml.cs +++ b/EnvyUpdate/MainWindow.xaml.cs @@ -20,7 +20,8 @@ namespace EnvyUpdate readonly string startup = Environment.GetFolderPath(Environment.SpecialFolder.Startup); string gpuURL = null; readonly string exeloc = System.Reflection.Assembly.GetEntryAssembly().Location; - bool isAtStartup = false; + readonly string exepath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "\\"; + readonly string startmenu = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu); public MainWindow() { @@ -30,14 +31,6 @@ namespace EnvyUpdate Directory.CreateDirectory(appdata); } - // A bit of a hacky way to know if running the autostarted version or the regular one. - if (System.AppDomain.CurrentDomain.FriendlyName == "EnvyUpdateInstalled.exe") - { - WindowState = WindowState.Minimized; - Hide(); - isAtStartup = true; - } - if (Util.GetLocDriv() != null) { localDriv = Util.GetLocDriv(); @@ -112,10 +105,11 @@ namespace EnvyUpdate WebClient c = new WebClient(); gpuURL = c.DownloadString(gpuURL); string pContent = c.DownloadString(gpuURL); - var pattern = @"\d{3}\.\d{2}"; + var pattern = @"\d{3}\.\d{2} "; Regex rgx = new Regex(pattern); var matches = rgx.Matches(pContent); onlineDriv = Convert.ToString(matches[0]); + onlineDriv = onlineDriv.Remove(onlineDriv.Length - 5); textblockOnline.Text = onlineDriv; c.Dispose(); @@ -123,14 +117,17 @@ namespace EnvyUpdate { textblockOnline.Foreground = Brushes.Red; buttonDL.Visibility = Visibility.Visible; - if (isAtStartup) - { - Show(); - WindowState = WindowState.Normal; - } } else + { textblockOnline.Foreground = Brushes.Green; + //if (System.Reflection.Assembly.GetExecutingAssembly().CodeBase == appdata) + //{ + //WindowState = WindowState.Minimized; + //System.Threading.Thread.Sleep(100); + //Hide(); + //} + } } private void Load(string[] files) { @@ -157,10 +154,11 @@ namespace EnvyUpdate WebClient c = new WebClient(); gpuURL = c.DownloadString(gpuURL); string pContent = c.DownloadString(gpuURL); - var pattern = @"\d{3}\.\d{2}"; + var pattern = @"\d{3}\.\d{2} "; Regex rgx = new Regex(pattern); var matches = rgx.Matches(pContent); onlineDriv = Convert.ToString(matches[0]); + onlineDriv = onlineDriv.Remove(onlineDriv.Length - 5); textblockOnline.Text = onlineDriv; c.Dispose(); @@ -210,14 +208,23 @@ namespace EnvyUpdate private void chkAutostart_Checked(object sender, RoutedEventArgs e) { - File.Copy(exeloc, appdata + "EnvyUpdateInstalled.exe", true); - Util.CreateShortcut("EnvyUpdate", startup, appdata + "EnvyUpdateInstalled.exe", "Nvidia Updater Application."); + if (exepath != appdata) + { + File.Copy(exeloc, appdata + "EnvyUpdate.exe", true); + Util.CreateShortcut("EnvyUpdate", startup, appdata + "EnvyUpdate.exe", "Nvidia Updater Application."); + Util.CreateShortcut("EnvyUpdate", startmenu, appdata + "EnvyUpdate.exe", "Nvidia Updater Application."); + } + else + { + chkAutostart.IsEnabled = false; + } } private void chkAutostart_Unchecked(object sender, RoutedEventArgs e) { - File.Delete(appdata + "EnvyUpdateInstalled.exe"); + File.Delete(appdata + "EnvyUpdate.exe"); File.Delete(startup + "\\EnvyUpdate.lnk"); + File.Delete(startmenu + "\\EnvyUpdate.lnk"); } private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)