-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from ewrogers/auto-update
Auto update
- Loading branch information
Showing
48 changed files
with
1,618 additions
and
397 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8.1" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Application x:Class="SleepHunter.Updater.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:SleepHunter.Updater"> | ||
<Application.Resources> | ||
<ResourceDictionary> | ||
<!-- Import the Obsidian UI style from SleepHunter --> | ||
<ResourceDictionary.MergedDictionaries> | ||
<ResourceDictionary Source="/SleepHunter;component/Obsidian.xaml"/> | ||
</ResourceDictionary.MergedDictionaries> | ||
</ResourceDictionary> | ||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Windows; | ||
|
||
namespace SleepHunter.Updater | ||
{ | ||
public partial class App : Application | ||
{ | ||
protected override void OnStartup(StartupEventArgs e) | ||
{ | ||
// Invalid number of arguments, exit | ||
// Usage: Updater.exe <zip file> <install path> | ||
if (e.Args.Length != 2) | ||
{ | ||
Shutdown(); | ||
return; | ||
} | ||
|
||
var updateFilePath = e.Args[0]; | ||
var installationPath = e.Args[1]; | ||
var executableFile = Path.Combine(installationPath, "SleepHunter.exe"); | ||
|
||
base.OnStartup(e); | ||
|
||
var mainWindow = new MainWindow(); | ||
mainWindow.Show(); | ||
|
||
// Check that the update file exists, show error if missing | ||
if (!File.Exists(updateFilePath)) | ||
{ | ||
mainWindow.SetStatusText("Unable to Update"); | ||
mainWindow.SetErrorMessage("Missing update file.\nYou can try again within SleepHunter, or install it manually."); | ||
return; | ||
} | ||
|
||
// Terminate any existing SleepHunter instances | ||
try | ||
{ | ||
mainWindow.SetStatusText("Preparing..."); | ||
|
||
foreach (var process in Process.GetProcessesByName("SleepHunter")) | ||
process.Kill(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
mainWindow.SetStatusText("Unable to Update"); | ||
mainWindow.SetErrorMessage(ex.Message); | ||
return; | ||
} | ||
|
||
// Try to update, and display an error if something goes wrong | ||
try | ||
{ | ||
mainWindow.PerformAppUpdate(updateFilePath, installationPath); | ||
} | ||
catch (Exception ex) | ||
{ | ||
mainWindow.SetStatusText("Unable to Update"); | ||
mainWindow.SetErrorMessage(ex.Message); | ||
return; | ||
} | ||
|
||
// Check that the executable exists, show error if missing | ||
if (!File.Exists(executableFile)) | ||
{ | ||
mainWindow.SetStatusText("Unable to Restart"); | ||
mainWindow.SetErrorMessage("Missing SleepHunter executable in installation folder.\nYou may need to apply the update manually."); | ||
return; | ||
} | ||
|
||
// Restart SleepHunter | ||
mainWindow.SetStatusText("Restarting SleepHunter..."); | ||
Process.Start(executableFile); | ||
|
||
Shutdown(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<Window x:Class="SleepHunter.Updater.MainWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:local="clr-namespace:SleepHunter.Updater" | ||
mc:Ignorable="d" | ||
Title="SleepHunter Updater" | ||
Width="560" Height="380" | ||
WindowStartupLocation="CenterScreen" | ||
ResizeMode="NoResize" | ||
Style="{StaticResource ObsidianWindow}" | ||
Loaded="Window_Loaded" | ||
Closing="Window_Closing"> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="*"/> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="Auto"/> | ||
</Grid.RowDefinitions> | ||
|
||
<StackPanel Orientation="Vertical" Margin="16"> | ||
<!-- Status Text --> | ||
<TextBlock Name="statusText" | ||
Text="Extracting files..." | ||
TextAlignment="Left" | ||
Margin="0,8" | ||
Style="{StaticResource ObsidianText}"/> | ||
|
||
<Grid> | ||
<!-- Progress Bar --> | ||
<ProgressBar x:Name="progressBar" | ||
Style="{StaticResource ObsidianProgressBar}" | ||
Minimum="0" | ||
Maximum="100" | ||
Height="32" | ||
Value="50" | ||
Margin="0,4"> | ||
</ProgressBar> | ||
|
||
|
||
<!-- Progress Percentage Text --> | ||
<TextBlock Name="progressPercentText" | ||
Text="50%" | ||
TextAlignment="Center" | ||
Margin="0" | ||
FontSize="16" | ||
FontWeight="Normal" | ||
Style="{StaticResource ObsidianText}"/> | ||
</Grid> | ||
|
||
<Grid> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*"/> | ||
<ColumnDefinition Width="*"/> | ||
</Grid.ColumnDefinitions> | ||
|
||
<!-- Progress File Text --> | ||
<TextBlock Name="progressFileText" | ||
Text="SleepHunter.exe" | ||
TextAlignment="Left" | ||
Margin="4,2" | ||
FontSize="14" | ||
Foreground="{StaticResource ObsidianInactive}" | ||
Style="{StaticResource ObsidianText}"/> | ||
|
||
<!-- Progress Count Text --> | ||
<TextBlock Name="progressCountText" | ||
Grid.Column="1" | ||
Text="1 of 6 files" | ||
TextAlignment="Right" | ||
Margin="4,2" | ||
FontSize="14" | ||
Foreground="{StaticResource ObsidianInactive}" | ||
Style="{StaticResource ObsidianText}"/> | ||
|
||
</Grid> | ||
</StackPanel> | ||
|
||
<Separator Grid.Row="1" Style="{StaticResource ObsidianSeparator}"/> | ||
|
||
<StackPanel Grid.Row="2" Orientation="Horizontal" Margin="8,4"> | ||
<!-- Error Icon --> | ||
<Path Name="warningIcon" | ||
StrokeThickness="4" | ||
Stroke="{DynamicResource ObsidianBackground}" | ||
Data="M 0,2 h 64 l -32,-62 z m 32,-32 v 12 m 0,2 v 4" | ||
Margin="32,64,32,0" | ||
HorizontalAlignment="Center" | ||
VerticalAlignment="Center"/> | ||
|
||
<!-- Error Message Text --> | ||
<TextBlock Name="errorMessageText" | ||
Text="The quick brown fox jumps over the lazy dog." | ||
VerticalAlignment="Center" | ||
TextAlignment="Center" | ||
FontSize="16" | ||
TextWrapping="WrapWithOverflow" | ||
MaxWidth="380" | ||
Foreground="{StaticResource ObsidianActive}" | ||
Style="{StaticResource ObsidianText}"/> | ||
</StackPanel> | ||
|
||
<Separator Grid.Row="3" Style="{StaticResource ObsidianSeparator}"/> | ||
|
||
<TextBlock Grid.Row="4" Grid.ColumnSpan="2" | ||
Text="SleepHunter will be re-launched after the update is completed." | ||
TextAlignment="Center" | ||
Margin="8,4" | ||
FontSize="14" | ||
Foreground="{StaticResource ObsidianInactive}" | ||
Style="{StaticResource ObsidianText}"/> | ||
|
||
<TextBlock Name="versionText" | ||
Grid.Row="5" | ||
Text="Updater - v0.0.0" | ||
HorizontalAlignment="Center" | ||
VerticalAlignment="Top" | ||
Margin="8" | ||
Foreground="{StaticResource ObsidianDisabled}" | ||
FontSize="14" | ||
Style="{StaticResource ObsidianText}"/> | ||
</Grid> | ||
</Window> |
Oops, something went wrong.