add DCH compat, better debug

This commit is contained in:
fyr77 2020-09-06 11:03:04 +02:00
parent 58631d5d8a
commit a42641fdce
12 changed files with 157 additions and 54 deletions

49
EnvyUpdate/Debug.cs Normal file
View file

@ -0,0 +1,49 @@
using System;
using System.Linq;
namespace EnvyUpdate
{
class Debug
{
readonly static string debugFilePath = GlobalVars.exepath + "debug.txt";
public static int LoadFakeIDs(string idType)
{
/*
* Usage:
* Create debug.txt file.
* Fill in variables:
* Line 1: psid
* Line 2: pfid
* Line 3: osid
* Line 4: dtcid
* Line 5: Local driver version
*
* Supply /debug flag to exe.
*/
string line = null;
switch (idType)
{
case "psid":
line = File.ReadLines(debugFilePath).Take(1).First();
break;
case "pfid":
line = File.ReadLines(debugFilePath).Skip(1).Take(1).First();
break;
case "osid":
line = File.ReadLines(debugFilePath).Skip(2).Take(1).First();
break;
case "dtcid":
line = File.ReadLines(debugFilePath).Skip(3).Take(1).First();
break;
default:
break;
}
return int.Parse(line);
}
public static string LocalDriv()
{
return File.ReadLines(debugFilePath).Skip(4).Take(1).First();
}
}
}

View file

@ -95,6 +95,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Debug.cs" />
<Compile Include="GlobalVars.cs" />
<Compile Include="InfoWindow.xaml.cs">
<DependentUpon>InfoWindow.xaml</DependentUpon>

View file

@ -9,7 +9,7 @@ namespace EnvyUpdate
public static readonly string exeloc = System.Reflection.Assembly.GetEntryAssembly().Location;
public static readonly string exepath = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "\\";
public static readonly string startmenu = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
public static readonly float version = 2.3F;
public static readonly float version = 2.4F;
public static readonly string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\envyupdate\\";
public static readonly string startup = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
public static readonly string desktopOverride = exepath + "desktop.envy";

View file

@ -6,19 +6,19 @@
xmlns:local="clr-namespace:EnvyUpdate"
xmlns:p="clr-namespace:EnvyUpdate.Properties"
mc:Ignorable="d"
Title="" Height="274" Width="286" ResizeMode="NoResize" WindowStyle="ToolWindow" SizeToContent="WidthAndHeight">
Title="" Height="290" Width="286" ResizeMode="NoResize" WindowStyle="ToolWindow" SizeToContent="WidthAndHeight">
<Grid>
<Button Content="{x:Static p:Resources.ui_info_website}" Margin="10,10,10,0" VerticalAlignment="Top" Height="20" Click="ButtonWeb_Click"/>
<Label Content="Licenses:" HorizontalAlignment="Left" Margin="10,60,0,0" VerticalAlignment="Top" FontWeight="Bold"/>
<TextBlock x:Name="textEnvyUpdate" Margin="10,91,10,0" TextWrapping="Wrap" Height="18" VerticalAlignment="Top" MouseEnter="text_MouseEnter" MouseLeave="text_MouseLeave" MouseDown="textEnvyUpdate_MouseDown"><Run Text="EnvyUpdate"/><Run Text=": MIT"/></TextBlock>
<TextBlock x:Name="textFody" Margin="10,109,10,0" TextWrapping="Wrap" Text="Fody: MIT" Height="18" VerticalAlignment="Top" MouseEnter="text_MouseEnter" MouseLeave="text_MouseLeave" MouseDown="textFody_MouseDown"/>
<TextBlock x:Name="textNotifyIcon" Margin="10,145,10,0" TextWrapping="Wrap" Text="wpf-notifyicon: CPOL" Height="18" VerticalAlignment="Top" MouseEnter="text_MouseEnter" MouseLeave="text_MouseLeave" MouseDown="textNotifyIcon_MouseDown"/>
<TextBlock x:Name="textNotifications" Margin="10,163,10,0" TextWrapping="Wrap" Text="Notifications.Wpf: MIT" Height="18" VerticalAlignment="Top" MouseEnter="text_MouseEnter" MouseLeave="text_MouseLeave" MouseDown="textNotifications_MouseDown"/>
<TextBlock Margin="10,217,10,0" TextWrapping="Wrap" Text="Icon made by Freepik from www.flaticon.com" Height="18" VerticalAlignment="Top"/>
<TextBlock x:Name="textNewtonsoft" Margin="10,181,10,0" TextWrapping="Wrap" Height="18" VerticalAlignment="Top" MouseEnter="text_MouseEnter" MouseLeave="text_MouseLeave" MouseDown="textNewtonsoft_MouseDown"><Run Text="Newtonsoft.Json"/><Run Text=": MIT"/></TextBlock>
<TextBlock x:Name="textCostura" Margin="10,127,10,0" TextWrapping="Wrap" Text="Costura.Fody: MIT" Height="18" VerticalAlignment="Top" MouseEnter="text_MouseEnter" MouseLeave="text_MouseLeave" MouseDown="textCostura_MouseDown"/>
<Label Content="Licenses:" HorizontalAlignment="Left" Margin="10,73,0,0" VerticalAlignment="Top" FontWeight="Bold"/>
<TextBlock x:Name="textEnvyUpdate" Margin="10,104,10,0" TextWrapping="Wrap" Height="18" VerticalAlignment="Top" MouseEnter="text_MouseEnter" MouseLeave="text_MouseLeave" MouseDown="textEnvyUpdate_MouseDown"><Run Text="EnvyUpdate"/><Run Text=": MIT"/></TextBlock>
<TextBlock x:Name="textFody" Margin="10,122,10,0" TextWrapping="Wrap" Text="Fody: MIT" Height="18" VerticalAlignment="Top" MouseEnter="text_MouseEnter" MouseLeave="text_MouseLeave" MouseDown="textFody_MouseDown"/>
<TextBlock x:Name="textNotifyIcon" Margin="10,158,10,0" TextWrapping="Wrap" Text="wpf-notifyicon: CPOL" Height="18" VerticalAlignment="Top" MouseEnter="text_MouseEnter" MouseLeave="text_MouseLeave" MouseDown="textNotifyIcon_MouseDown"/>
<TextBlock x:Name="textNotifications" Margin="10,176,10,0" TextWrapping="Wrap" Text="Notifications.Wpf: MIT" Height="18" VerticalAlignment="Top" MouseEnter="text_MouseEnter" MouseLeave="text_MouseLeave" MouseDown="textNotifications_MouseDown"/>
<TextBlock Margin="10,230,10,0" TextWrapping="Wrap" Text="Icon made by Freepik from www.flaticon.com" Height="18" VerticalAlignment="Top"/>
<TextBlock x:Name="textNewtonsoft" Margin="10,194,10,0" TextWrapping="Wrap" Height="18" VerticalAlignment="Top" MouseEnter="text_MouseEnter" MouseLeave="text_MouseLeave" MouseDown="textNewtonsoft_MouseDown"><Run Text="Newtonsoft.Json"/><Run Text=": MIT"/></TextBlock>
<TextBlock x:Name="textCostura" Margin="10,140,10,0" TextWrapping="Wrap" Text="Costura.Fody: MIT" Height="18" VerticalAlignment="Top" MouseEnter="text_MouseEnter" MouseLeave="text_MouseLeave" MouseDown="textCostura_MouseDown"/>
<CheckBox x:Name="chkMobile" Content="{x:Static p:Resources.ui_info_mobile}" Margin="10,40,10,0" VerticalAlignment="Top" Checked="chkMobile_Checked" Unchecked="chkMobile_Unchecked"/>
<TextBlock x:Name="textResourceEmbedder" Margin="10,199,10,0" TextWrapping="Wrap" Height="18" VerticalAlignment="Top" MouseEnter="text_MouseEnter" MouseLeave="text_MouseLeave" MouseDown="textResourceEmbedder_MouseDown"><Run Text="Resource Embedder"/><Run Text=": MIT"/></TextBlock>
<TextBlock x:Name="textResourceEmbedder" Margin="10,212,10,0" TextWrapping="Wrap" Height="18" VerticalAlignment="Top" MouseEnter="text_MouseEnter" MouseLeave="text_MouseLeave" MouseDown="textResourceEmbedder_MouseDown"><Run Text="Resource Embedder"/><Run Text=": MIT"/></TextBlock>
<CheckBox x:Name="chkDCH" Content="{x:Static p:Resources.ui_info_dch}" Margin="10,60,10,0" VerticalAlignment="Top" IsEnabled="False"/>
</Grid>
</Window>

View file

@ -19,11 +19,12 @@ namespace EnvyUpdate
if (GlobalVars.isMobile)
chkMobile.IsChecked = true;
if (Util.IsMobile())
defaultIsMobile = true;
defaultIsMobile = Util.IsMobile();
if (defaultIsMobile != GlobalVars.isMobile)
isOverride = true;
chkDCH.IsChecked = Util.IsDCH();
}
private void ButtonWeb_Click(object sender, RoutedEventArgs e)

View file

@ -7,7 +7,7 @@
xmlns:p="clr-namespace:EnvyUpdate.Properties"
xmlns:tb="http://www.hardcodet.net/taskbar"
mc:Ignorable="d"
Title="EnvyUpdate" Height="159" Width="290.5" Icon="icon.ico" StateChanged="Window_StateChanged" Closing="Window_Closing" ResizeMode="CanMinimize">
Title="EnvyUpdate" Height="160" Width="290" Icon="icon.ico" StateChanged="Window_StateChanged" Closing="Window_Closing" ResizeMode="CanMinimize">
<Grid Margin="0,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="17*"/>

View file

@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
@ -85,16 +86,15 @@ namespace EnvyUpdate
}
else
{
switch (argument)
if (argument == "/debug")
{
case "/ignoregpu":
MessageBox.Show("Debug: GPU ignored.");
isDebug = true;
break;
default:
MessageBox.Show(Properties.Resources.no_compatible_gpu);
Environment.Exit(255);
break;
MessageBox.Show("Debug mode!");
isDebug = true;
}
else
{
MessageBox.Show(Properties.Resources.no_compatible_gpu);
Environment.Exit(255);
}
}
@ -119,38 +119,50 @@ namespace EnvyUpdate
private void Load()
{
int psid;
int pfid;
int osid;
int psid = 0;
int pfid = 0;
int osid = 0;
int dtcid = 0;
//int langid;
// This little bool check is necessary for debug mode on systems without an Nvidia GPU.
if (!isDebug)
{
psid = Util.GetIDs("pfid");
pfid = Util.GetIDs("psid");
psid = Util.GetIDs("psid");
pfid = Util.GetIDs("pfid");
osid = Util.GetIDs("osid");
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);
var pattern = @"\d{3}\.\d{2}&nbsp";
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 (float.Parse(localDriv) < float.Parse(onlineDriv))
{
textblockOnline.Foreground = Brushes.Red;
buttonDL.Visibility = Visibility.Visible;
Notify.ShowDrivUpdatePopup();
}
else
textblockOnline.Foreground = Brushes.Green;
dtcid = Util.GetDTCID();
}
else
{
psid = Debug.LoadFakeIDs("psid");
pfid = Debug.LoadFakeIDs("pfid");
osid = Debug.LoadFakeIDs("osid");
dtcid = Debug.LoadFakeIDs("dtcid");
localDriv = Debug.LocalDriv();
textblockGPU.Text = localDriv;
}
gpuURL = "http://www.nvidia.com/Download/processDriver.aspx?psid=" + psid.ToString() + "&pfid=" + pfid.ToString() + "&osid=" + osid.ToString() + "&dtcid=" + dtcid.ToString(); // + "&lid=" + langid.ToString();
WebClient c = new WebClient();
gpuURL = c.DownloadString(gpuURL);
string pContent = c.DownloadString(gpuURL);
var pattern = @"\d{3}\.\d{2}&nbsp";
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 (float.Parse(localDriv) < float.Parse(onlineDriv))
{
textblockOnline.Foreground = Brushes.Red;
buttonDL.Visibility = Visibility.Visible;
Notify.ShowDrivUpdatePopup();
}
else
textblockOnline.Foreground = Brushes.Green;
if (GlobalVars.exepath == GlobalVars.appdata)
{
@ -161,7 +173,7 @@ namespace EnvyUpdate
private void buttonDL_Click(object sender, RoutedEventArgs e)
{
System.Diagnostics.Process.Start(gpuURL);
Process.Start(gpuURL);
}
private void TaskbarIcon_TrayLeftMouseDown(object sender, RoutedEventArgs e)

View file

@ -51,5 +51,5 @@ using System.Windows;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.3")]
[assembly: AssemblyFileVersion("2.3")]
[assembly: AssemblyVersion("2.4")]
[assembly: AssemblyFileVersion("2.4")]

View file

@ -132,6 +132,15 @@ namespace EnvyUpdate.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to DCH driver.
/// </summary>
public static string ui_info_dch {
get {
return ResourceManager.GetString("ui_info_dch", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Mobile GPU (Laptop, etc)?.
/// </summary>

View file

@ -141,6 +141,9 @@
<data name="ui_autostart" xml:space="preserve">
<value>Autostart</value>
</data>
<data name="ui_info_dch" xml:space="preserve">
<value>DCH Treiber</value>
</data>
<data name="ui_info_mobile" xml:space="preserve">
<value>Mobile Grafikkarte (Laptop, etc)?</value>
</data>

View file

@ -141,6 +141,9 @@
<data name="ui_autostart" xml:space="preserve">
<value>Autostart</value>
</data>
<data name="ui_info_dch" xml:space="preserve">
<value>DCH driver</value>
</data>
<data name="ui_info_mobile" xml:space="preserve">
<value>Mobile GPU (Laptop, etc)?</value>
</data>

View file

@ -357,6 +357,10 @@ namespace EnvyUpdate
// This should NEVER return null outside of debugging mode, since EnvyUpdate should refuse to start without and Nvidia GPU.
return GPUName;
}
/// <summary>
/// Checks for Battery and assumes a mobile GPU if present.
/// </summary>
/// <returns></returns>
public static bool IsMobile()
{
bool result = false;
@ -372,10 +376,31 @@ namespace EnvyUpdate
return result;
}
/// <summary>
/// Checks Windows registry for Nvidia DCH Key. If it is present, returns true.
/// </summary>
/// <returns></returns>
public static bool IsDCH()
{
RegistryKey nvlddmkm = Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\services\nvlddmkm", true);
return nvlddmkm.GetValueNames().Contains("DCHUVen");
try
{
RegistryKey nvlddmkm = Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\services\nvlddmkm", true);
return nvlddmkm.GetValueNames().Contains("DCHUVen");
}
catch (NullReferenceException)
{
// Assume no DCH driver is installed if key is not found.
return false;
}
}
public static int GetDTCID()
{
int dtcid = 0;
if (IsDCH())
{
dtcid = 1;
}
return dtcid;
}
}
}