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">
<HintPath>..\packages\Hardcodet.NotifyIcon.Wpf.1.0.8\lib\net451\Hardcodet.Wpf.TaskbarNotification.dll</HintPath>
</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.Data" />
<Reference Include="System.Management" />
@ -71,6 +74,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Notify.cs" />
<Compile Include="Util.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
@ -130,12 +134,12 @@
</COMReference>
</ItemGroup>
<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">
<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>
</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\Fody.6.0.5\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.6.0.5\build\Fody.targets'))" />
</Target>
<Import Project="..\packages\Fody.6.0.5\build\Fody.targets" Condition="Exists('..\packages\Fody.6.0.5\build\Fody.targets')" />
</Project>

View file

@ -25,10 +25,10 @@ namespace EnvyUpdate
public MainWindow()
{
InitializeComponent();
if (Util.IsProcessOpen("EnvyUpdate"))
if (Util.IsInstanceOpen("EnvyUpdate"))
{
MessageBox.Show("Application is already running.");
System.Environment.Exit(1);
Application.Current.Shutdown(1);
}
if (!Directory.Exists(appdata))
{
@ -43,7 +43,7 @@ namespace EnvyUpdate
else
{
MessageBox.Show("No NVIDIA GPU found. Application will exit.");
System.Environment.Exit(255);
Application.Current.Shutdown(255);
}
if (File.Exists(appdata + "nvidia-update.txt"))
{
@ -63,11 +63,6 @@ namespace EnvyUpdate
private void Dt_Tick(object sender, EventArgs e)
{
Load();
if (textblockOnline.Foreground == Brushes.Red)
{
Show();
WindowState = WindowState.Normal;
}
}
private void buttonHelp_Click(object sender, RoutedEventArgs e)
@ -121,15 +116,14 @@ namespace EnvyUpdate
{
textblockOnline.Foreground = Brushes.Red;
buttonDL.Visibility = Visibility.Visible;
Notify.ShowUpdatePopup();
}
else
{
textblockOnline.Foreground = Brushes.Green;
if (exepath == appdata)
{
WindowState = WindowState.Minimized;
Hide();
}
if (exepath == appdata)
{
WindowState = WindowState.Minimized;
Hide();
}
}
private void Load(string[] files)
@ -180,8 +174,7 @@ namespace EnvyUpdate
private void TaskbarIcon_TrayLeftMouseDown(object sender, RoutedEventArgs e)
{
Show();
WindowState = WindowState.Normal;
Util.ShowMain();
}
private void Window_StateChanged(object sender, EventArgs e)
@ -234,6 +227,7 @@ namespace EnvyUpdate
{
var window = MessageBox.Show("Exit EnvyUpdate?", "", MessageBoxButton.YesNo);
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 IWshRuntimeLibrary;
using System.Diagnostics;
using System.Windows;
namespace EnvyUpdate
{
@ -83,17 +84,26 @@ namespace EnvyUpdate
shortcut.TargetPath = targetFileLocation;
shortcut.Save();
}
public static bool IsProcessOpen(string name)
public static bool IsInstanceOpen(string name)
{
int count = 0;
foreach (Process clsProcess in Process.GetProcesses())
{
if (clsProcess.ProcessName.Contains(name))
{
return true;
count++;
}
}
return false;
if (count > 1)
return true;
else
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"?>
<packages>
<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="Notifications.Wpf" version="0.1.1" targetFramework="net472" />
</packages>