diff --git a/EnvyUpdate.sln b/EnvyUpdate.sln
index 6878393..5225e06 100644
--- a/EnvyUpdate.sln
+++ b/EnvyUpdate.sln
@@ -7,10 +7,13 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EnvyUpdate", "EnvyUpdate\En
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug - ignoregpu|Any CPU = Debug - ignoregpu|Any CPU
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {1BF2468D-9579-462D-9153-4836E9C8721F}.Debug - ignoregpu|Any CPU.ActiveCfg = Debug - ignoregpu|Any CPU
+ {1BF2468D-9579-462D-9153-4836E9C8721F}.Debug - ignoregpu|Any CPU.Build.0 = Debug - ignoregpu|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
diff --git a/EnvyUpdate/EnvyUpdate.csproj b/EnvyUpdate/EnvyUpdate.csproj
index ebdeb8b..4baef38 100644
--- a/EnvyUpdate/EnvyUpdate.csproj
+++ b/EnvyUpdate/EnvyUpdate.csproj
@@ -43,6 +43,17 @@
false
+
+ true
+ bin\Debug\
+ DEBUG;TRACE
+ full
+ AnyCPU
+ 7.3
+ prompt
+ MinimumRecommendedRules.ruleset
+ true
+
..\packages\Costura.Fody.4.1.0\lib\net40\Costura.dll
@@ -50,12 +61,16 @@
..\packages\Hardcodet.NotifyIcon.Wpf.1.0.8\lib\net451\Hardcodet.Wpf.TaskbarNotification.dll
+
+ ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll
+
..\packages\Notifications.Wpf.0.1.1\lib\net461\Notifications.Wpf.dll
+
@@ -74,6 +89,7 @@
MSBuild:Compile
Designer
+
InfoWindow.xaml
diff --git a/EnvyUpdate/GlobalVars.cs b/EnvyUpdate/GlobalVars.cs
new file mode 100644
index 0000000..4556a87
--- /dev/null
+++ b/EnvyUpdate/GlobalVars.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EnvyUpdate
+{
+ class GlobalVars
+ {
+ public static string gpuName = null;
+ public static bool mobile = false;
+ }
+}
diff --git a/EnvyUpdate/InfoWindow.xaml b/EnvyUpdate/InfoWindow.xaml
index 86ce504..991bc88 100644
--- a/EnvyUpdate/InfoWindow.xaml
+++ b/EnvyUpdate/InfoWindow.xaml
@@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:EnvyUpdate"
mc:Ignorable="d"
- Title="InfoWindow" Height="224.547" Width="285.714">
+ Title="InfoWindow" Height="238.853" Width="285.714">
@@ -13,7 +13,8 @@
-
+
+
diff --git a/EnvyUpdate/InfoWindow.xaml.cs b/EnvyUpdate/InfoWindow.xaml.cs
index af23f93..47e16c3 100644
--- a/EnvyUpdate/InfoWindow.xaml.cs
+++ b/EnvyUpdate/InfoWindow.xaml.cs
@@ -47,5 +47,9 @@ namespace EnvyUpdate
{
System.Diagnostics.Process.Start("https://github.com/Federerer/Notifications.Wpf/blob/master/LICENSE");
}
+ private void textNewtonsoft_MouseDown(object sender, MouseButtonEventArgs e)
+ {
+ System.Diagnostics.Process.Start("https://github.com/JamesNK/Newtonsoft.Json/blob/master/LICENSE.md");
+ }
}
}
diff --git a/EnvyUpdate/MainWindow.xaml.cs b/EnvyUpdate/MainWindow.xaml.cs
index 1c78927..92c07cd 100644
--- a/EnvyUpdate/MainWindow.xaml.cs
+++ b/EnvyUpdate/MainWindow.xaml.cs
@@ -22,12 +22,25 @@ namespace EnvyUpdate
private readonly string exepath = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "\\";
private readonly string startmenu = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
private readonly string version = "1.4";
+ private string argument = null;
public MainWindow()
{
InitializeComponent();
Title += " " + version;
+ // Try to get command line arguments
+ try
+ {
+ argument = Environment.GetCommandLineArgs()[1];
+ Console.WriteLine("Starting in debug mode.");
+ }
+ catch (IndexOutOfRangeException)
+ {
+ // This is necessary, since .NET throws an exception if you check for a non-existant arg.
+ Console.WriteLine("Starting in release mode.");
+ }
+
// Check if EnvyUpdate is already running
if (Util.IsInstanceOpen("EnvyUpdate"))
{
@@ -50,16 +63,9 @@ namespace EnvyUpdate
}
catch (WebException)
{
- //Silently fail.
+ // Silently fail.
}
}
- /*
- if (Environment.GetCommandLineArgs()[1] == "--ignore-gpu")
- {
- MessageBox.Show("Skipping GPU check!");
- textblockGPU.Text = "Check skipped.";
- }
- */
if (Util.GetLocDriv() != null)
{
localDriv = Util.GetLocDriv();
@@ -67,8 +73,16 @@ namespace EnvyUpdate
}
else
{
- MessageBox.Show("No NVIDIA GPU found. Application will exit.");
- Environment.Exit(255);
+ switch (argument)
+ {
+ case "/ignoregpu":
+ MessageBox.Show("Debug: GPU ignored.");
+ break;
+ default:
+ MessageBox.Show("No NVIDIA GPU found. Application will exit.");
+ Environment.Exit(255);
+ break;
+ }
}
if (File.Exists(appdata + "nvidia-update.txt"))
@@ -129,7 +143,7 @@ namespace EnvyUpdate
pfid = Util.GetData(f.FullName, "ProductType");
osid = Util.GetData(f.FullName, "OperatingSystem");
langid = Util.GetData(f.FullName, "Language");
- gpuURL = "http://www.nvidia.com/Download/processDriver.aspx?psid=" + psid.ToString() + "&pfid=" + pfid.ToString() + "&rpf=1&osid=" + osid.ToString() + "&lid=" + langid.ToString() + "&ctk=0";
+ gpuURL = "http://www.nvidia.com/Download/processDriver.aspx?psid=" + psid.ToString() + "&pfid=" + pfid.ToString() + "&osid=" + osid.ToString() + "&lid=" + langid.ToString();
WebClient c = new WebClient();
gpuURL = c.DownloadString(gpuURL);
string pContent = c.DownloadString(gpuURL);
@@ -178,16 +192,18 @@ namespace EnvyUpdate
osid = Util.GetData(f.FullName, "OperatingSystem");
langid = Util.GetData(f.FullName, "Language");
gpuURL = "http://www.nvidia.com/Download/processDriver.aspx?psid=" + psid.ToString() + "&pfid=" + pfid.ToString() + "&rpf=1&osid=" + osid.ToString() + "&lid=" + langid.ToString() + "&ctk=0";
- WebClient c = new WebClient();
- gpuURL = c.DownloadString(gpuURL);
- string pContent = c.DownloadString(gpuURL);
+ string pContent = null;
+ using (WebClient c = new WebClient())
+ {
+ gpuURL = c.DownloadString(gpuURL);
+ pContent = c.DownloadString(gpuURL);
+ }
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();
if (localDriv != onlineDriv)
{
diff --git a/EnvyUpdate/Util.cs b/EnvyUpdate/Util.cs
index 2edd933..e6f41bc 100644
--- a/EnvyUpdate/Util.cs
+++ b/EnvyUpdate/Util.cs
@@ -6,6 +6,9 @@ using System.Linq;
using System.Management;
using System.Net;
using System.Windows;
+using Newtonsoft.Json;
+using System.Xml;
+using System.Xml.Linq;
namespace EnvyUpdate
{
@@ -79,7 +82,8 @@ namespace EnvyUpdate
///
public static void CreateShortcut(string shortcutName, string shortcutPath, string targetFileLocation, string description)
{
- string shortcutLocation = System.IO.Path.Combine(shortcutPath, shortcutName + ".lnk");
+ // It seems unnecessarily complex to create a simple shortcut using C#. Oh well.
+ string shortcutLocation = Path.Combine(shortcutPath, shortcutName + ".lnk");
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation);
@@ -87,9 +91,15 @@ namespace EnvyUpdate
shortcut.TargetPath = targetFileLocation;
shortcut.Save();
}
-
+ ///
+ /// Checks if application is already running.
+ ///
+ ///
+ ///
public static bool IsInstanceOpen(string name)
{
+ // This basically counts the processes named like the supplied string. If the count is more than 0, it will return true.
+ // Let's hope nobody manages to open this application 2,147,483,647 times, because then the int would overflow and crash EnvyUpdate. But I suppose you've got worse problems than that if you've got 2,147,483,647 instances of any process.
int count = 0;
foreach (Process clsProcess in Process.GetProcesses())
{
@@ -104,21 +114,31 @@ namespace EnvyUpdate
else
return false;
}
-
+ ///
+ /// Shows main window and restores WindowState
+ ///
public static void ShowMain()
{
Application.Current.MainWindow.Show();
Application.Current.MainWindow.WindowState = WindowState.Normal;
}
-
+ ///
+ /// Checks for newest EnvyUpdate version.
+ ///
+ ///
public static string GetNewVer()
{
- string updPath = "https://raw.githubusercontent.com/fyr77/EnvyUpdate/master/res/version.txt";
+ // This will fetch the most recent version's tag on GitHub.
+ string updPath = "https://api.github.com/repos/fyr77/envyupdate/releases/latest";
WebClient wc = new WebClient();
- string webData = wc.DownloadString(updPath).Truncate(3);
+ // Use some user agent to not get 403'd by GitHub.
+ wc.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko");
+ string webData = wc.DownloadString(updPath);
+ dynamic data = JsonConvert.DeserializeObject(webData);
+ string version = data.tag_name;
- return webData;
+ return version;
}
///
@@ -135,7 +155,9 @@ namespace EnvyUpdate
MessageBox.Show("New version of EnvyUpdate found. Application will restart.\nThis will probably take a few seconds.");
- // Replace exe with new one
+ // Replace exe with new one.
+ // This starts a seperate cmd process which will wait a bit, then delete EnvyUpdate and rename the previously downloaded EnvyUpdated.exe to EnvyUpdate.exe
+ // I know this is a bit dumb, but I honestly couldn't think of a different way to solve this properly, since the Application would need to delete itself.
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo
{
@@ -149,5 +171,114 @@ namespace EnvyUpdate
Environment.Exit(2);
}
+ public static int GetIDs(string IDtype)
+ {
+ // TODO: check for 2 occurences of GPU - if yes ask if mobile!!!
+ string xmlcontent = null;
+ int id = -1;
+
+ using (var wc = new WebClient())
+ {
+ switch (IDtype)
+ {
+ case "psid":
+ case "pfid":
+ xmlcontent = wc.DownloadString("https://www.nvidia.com/Download/API/lookupValueSearch.aspx?TypeID=3");
+ break;
+ case "osid":
+ xmlcontent = wc.DownloadString("https://www.nvidia.com/Download/API/lookupValueSearch.aspx?TypeID=4");
+ break;
+ case "langid":
+ xmlcontent = wc.DownloadString("https://www.nvidia.com/Download/API/lookupValueSearch.aspx?TypeID=5");
+ break;
+ default:
+ break;
+ }
+ }
+ XDocument xDoc = XDocument.Parse(xmlcontent);
+
+ if (IDtype == "pfid")
+ {
+ string gpuName = GetGPUName();
+ id = GetValueFromName(xDoc, gpuName);
+ }
+
+ return id;
+ }
+ ///
+ /// Gets Value from Nvidias XML docs by searching for the name. Can be used for OS, Lang and GPU.
+ ///
+ ///
+ ///
+ ///
+ private static int GetValueFromName (XDocument xDoc, string query)
+ {
+ int value = 0;
+
+ var names = xDoc.Descendants("Name");
+ foreach (var name in names)
+ {
+ int i = 0;
+ string sName = name.Value.ToString().ToLower();
+ if (sName == query)
+ {
+ int value1 = 0;
+ int value2 = 0;
+
+ string result = name.Parent.Value;
+ int index = result.IndexOf(sName);
+ string cleanResult = (index < 0)
+ ? result
+ : result.Remove(index, sName.Length);
+
+ if (i == 0)
+ {
+ value1 = int.Parse(cleanResult);
+ }
+ else
+ {
+ value2 = int.Parse(cleanResult);
+ }
+
+ value = value1;
+
+ if (GlobalVars.mobile)
+ {
+ value = value2;
+ }
+
+ i++;
+ }
+ }
+
+ return value;
+ }
+ ///
+ /// Returns GPU name in lower case.
+ ///
+ ///
+ private static string GetGPUName()
+ {
+ string GPUName = null;
+ foreach (ManagementObject obj in new ManagementObjectSearcher("SELECT * FROM Win32_VideoController").Get())
+ {
+ if (obj["Description"].ToString().ToLower().Contains("radeon"))
+ {
+ // If it's an AMD card, use the "Name" field, because they use chip code numbers in "VideoProcessor", which we do not need.
+ // Todo for 3.0: Find a way to ignore mobile Radeon GPUs in Laptops.
+ // For now: Since we only care about Nvidia GPUs, don't break even if an AMD card is found.
+ GPUName = obj["Name"].ToString().ToLower();
+ //break;
+ }
+ if (obj["Description"].ToString().ToLower().Contains("nvidia"))
+ {
+ // If it's an Nvidia GPU, use VideoProcessor so we don't have to truncate the resulting string.
+ GPUName = obj["VideoProcessor"].ToString().ToLower();
+ break;
+ }
+ }
+ // This should NEVER return null outside of debugging mode, since EnvyUpdate should refuse to start without and Nvidia GPU.
+ return GPUName;
+ }
}
}
\ No newline at end of file
diff --git a/EnvyUpdate/packages.config b/EnvyUpdate/packages.config
index 04e210f..d83496a 100644
--- a/EnvyUpdate/packages.config
+++ b/EnvyUpdate/packages.config
@@ -3,5 +3,6 @@
+
\ No newline at end of file
diff --git a/README.md b/README.md
index 74bba5c..f1c89a1 100644
--- a/README.md
+++ b/README.md
@@ -32,4 +32,5 @@ The application is compatible with all Nvidia GPUs that have their drivers avail
* Fody (for embedding DLLs into the main executable): [MIT](https://github.com/Fody/Fody/blob/master/License.txt)
* wpf-notifyicon (for showing an icon in the system tray): [CPOL](https://github.com/hardcodet/wpf-notifyicon/blob/master/LICENSE)
* Notifications.Wpf: [MIT](https://github.com/Federerer/Notifications.Wpf/blob/master/LICENSE)
+* Newtonsoft.Json: [MIT](https://github.com/JamesNK/Newtonsoft.Json/blob/master/LICENSE.md)
* Icon made by Freepik from www.flaticon.com