inching towards 1.0

* update Fody
* fix instance detection
* add notification support
This commit is contained in:
Jakob 2019-12-29 21:41:57 +01:00
parent 1b16cb65ea
commit 44f9c1c91e
6 changed files with 52 additions and 28 deletions

View file

@ -50,6 +50,9 @@
<Reference Include="Hardcodet.Wpf.TaskbarNotification, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Hardcodet.Wpf.TaskbarNotification, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Hardcodet.NotifyIcon.Wpf.1.0.8\lib\net451\Hardcodet.Wpf.TaskbarNotification.dll</HintPath> <HintPath>..\packages\Hardcodet.NotifyIcon.Wpf.1.0.8\lib\net451\Hardcodet.Wpf.TaskbarNotification.dll</HintPath>
</Reference> </Reference>
<Reference Include="Notifications.Wpf, Version=0.1.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Notifications.Wpf.0.1.1\lib\net461\Notifications.Wpf.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Management" /> <Reference Include="System.Management" />
@ -71,6 +74,7 @@
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</ApplicationDefinition> </ApplicationDefinition>
<Compile Include="Notify.cs" />
<Compile Include="Util.cs" /> <Compile Include="Util.cs" />
<Page Include="MainWindow.xaml"> <Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
@ -130,12 +134,12 @@
</COMReference> </COMReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Fody.6.0.4\build\Fody.targets" Condition="Exists('..\packages\Fody.6.0.4\build\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup> <PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup> </PropertyGroup>
<Error Condition="!Exists('..\packages\Fody.6.0.4\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.6.0.4\build\Fody.targets'))" />
<Error Condition="!Exists('..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props'))" /> <Error Condition="!Exists('..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props'))" />
<Error Condition="!Exists('..\packages\Fody.6.0.5\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.6.0.5\build\Fody.targets'))" />
</Target> </Target>
<Import Project="..\packages\Fody.6.0.5\build\Fody.targets" Condition="Exists('..\packages\Fody.6.0.5\build\Fody.targets')" />
</Project> </Project>

View file

@ -25,10 +25,10 @@ namespace EnvyUpdate
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
if (Util.IsProcessOpen("EnvyUpdate")) if (Util.IsInstanceOpen("EnvyUpdate"))
{ {
MessageBox.Show("Application is already running."); MessageBox.Show("Application is already running.");
System.Environment.Exit(1); Application.Current.Shutdown(1);
} }
if (!Directory.Exists(appdata)) if (!Directory.Exists(appdata))
{ {
@ -43,7 +43,7 @@ namespace EnvyUpdate
else else
{ {
MessageBox.Show("No NVIDIA GPU found. Application will exit."); MessageBox.Show("No NVIDIA GPU found. Application will exit.");
System.Environment.Exit(255); Application.Current.Shutdown(255);
} }
if (File.Exists(appdata + "nvidia-update.txt")) if (File.Exists(appdata + "nvidia-update.txt"))
{ {
@ -63,11 +63,6 @@ namespace EnvyUpdate
private void Dt_Tick(object sender, EventArgs e) private void Dt_Tick(object sender, EventArgs e)
{ {
Load(); Load();
if (textblockOnline.Foreground == Brushes.Red)
{
Show();
WindowState = WindowState.Normal;
}
} }
private void buttonHelp_Click(object sender, RoutedEventArgs e) private void buttonHelp_Click(object sender, RoutedEventArgs e)
@ -121,9 +116,9 @@ namespace EnvyUpdate
{ {
textblockOnline.Foreground = Brushes.Red; textblockOnline.Foreground = Brushes.Red;
buttonDL.Visibility = Visibility.Visible; buttonDL.Visibility = Visibility.Visible;
Notify.ShowUpdatePopup();
} }
else else
{
textblockOnline.Foreground = Brushes.Green; textblockOnline.Foreground = Brushes.Green;
if (exepath == appdata) if (exepath == appdata)
{ {
@ -131,7 +126,6 @@ namespace EnvyUpdate
Hide(); Hide();
} }
} }
}
private void Load(string[] files) private void Load(string[] files)
{ {
FileInfo f = new FileInfo(files[0]); FileInfo f = new FileInfo(files[0]);
@ -180,8 +174,7 @@ namespace EnvyUpdate
private void TaskbarIcon_TrayLeftMouseDown(object sender, RoutedEventArgs e) private void TaskbarIcon_TrayLeftMouseDown(object sender, RoutedEventArgs e)
{ {
Show(); Util.ShowMain();
WindowState = WindowState.Normal;
} }
private void Window_StateChanged(object sender, EventArgs e) private void Window_StateChanged(object sender, EventArgs e)
@ -234,6 +227,7 @@ namespace EnvyUpdate
{ {
var window = MessageBox.Show("Exit EnvyUpdate?", "", MessageBoxButton.YesNo); var window = MessageBox.Show("Exit EnvyUpdate?", "", MessageBoxButton.YesNo);
e.Cancel = (window == MessageBoxResult.No); e.Cancel = (window == MessageBoxResult.No);
Application.Current.Shutdown();
} }
} }
} }

19
EnvyUpdate/Notify.cs Normal file
View file

@ -0,0 +1,19 @@
using Notifications.Wpf;
namespace EnvyUpdate
{
class Notify
{
public static void ShowUpdatePopup()
{
var notificationManager = new NotificationManager();
notificationManager.Show(new NotificationContent
{
Title = "EnvyUpdate",
Message = "A new driver update is available for your graphics card. Click for more info.",
Type = NotificationType.Information
}, onClick: Util.ShowMain);
}
}
}

View file

@ -4,6 +4,7 @@ using System.Management;
using System.IO; using System.IO;
using IWshRuntimeLibrary; using IWshRuntimeLibrary;
using System.Diagnostics; using System.Diagnostics;
using System.Windows;
namespace EnvyUpdate namespace EnvyUpdate
{ {
@ -83,17 +84,26 @@ namespace EnvyUpdate
shortcut.TargetPath = targetFileLocation; shortcut.TargetPath = targetFileLocation;
shortcut.Save(); shortcut.Save();
} }
public static bool IsProcessOpen(string name) public static bool IsInstanceOpen(string name)
{ {
int count = 0;
foreach (Process clsProcess in Process.GetProcesses()) foreach (Process clsProcess in Process.GetProcesses())
{ {
if (clsProcess.ProcessName.Contains(name)) if (clsProcess.ProcessName.Contains(name))
{ {
return true; count++;
} }
} }
if (count > 1)
return true;
else
return false; return false;
} }
public static void ShowMain()
{
Application.Current.MainWindow.Show();
Application.Current.MainWindow.WindowState = WindowState.Normal;
}
} }
} }

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="Costura.Fody" version="4.1.0" targetFramework="net472" /> <package id="Costura.Fody" version="4.1.0" targetFramework="net472" />
<package id="Fody" version="6.0.4" targetFramework="net472" developmentDependency="true" /> <package id="Fody" version="6.0.5" targetFramework="net472" developmentDependency="true" />
<package id="Hardcodet.NotifyIcon.Wpf" version="1.0.8" targetFramework="net472" /> <package id="Hardcodet.NotifyIcon.Wpf" version="1.0.8" targetFramework="net472" />
<package id="Notifications.Wpf" version="0.1.1" targetFramework="net472" />
</packages> </packages>

View file

@ -18,15 +18,11 @@ Simply download the latest release from the [releases page](https://github.com/f
## Compatibility ## Compatibility
The application is compatible with all Nvidia GPUs that have their drivers available on the nvidia.com download page. The application is compatible with all Nvidia GPUs that have their drivers available on the nvidia.com download page and runs on Windows 7 and up.
## Branches
* The main `master` branch requires Windows 10 because of the way it sends notifications.
* The `compat` branch does not use notifications, opening the main window instead. This is compatible with Windows 7 and up.
## Licenses ## Licenses
* This project: [MIT](https://github.com/fyr77/EnvyUpdate/blob/master/LICENSE) * This project: [MIT](https://github.com/fyr77/EnvyUpdate/blob/master/LICENSE)
* Fody (for embedding DLLs into the main executable): [MIT](https://github.com/Fody/Fody/blob/master/License.txt) * 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) * 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)