Skip to content

Commit

Permalink
Merge pull request #4 from ewrogers/auto-update
Browse files Browse the repository at this point in the history
Auto update
  • Loading branch information
ewrogers authored Apr 11, 2023
2 parents ef37cf5 + 2ff9ecd commit aea445a
Show file tree
Hide file tree
Showing 48 changed files with 1,618 additions and 397 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,24 @@ All notable changes to this library will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.0.2] - Unreleased
## [4.1.0] - 2023-04-10

### Added

- New `Updates` section in `Settings` window allowing version checking
- New `Auto-Update` window for downloading updates and launching the updater
- New `SleepHunter.Updater` child project for applying auto-updates
- New scanline overlay for displaying modals
- Check for new updates on startup (if enabled)

### Changed

- Accessor key for `About` is now `Alt+B` instead of `Alt+A` (conflicted with `All Macros`)

### Removed

- Dead code for MVVM (use `CommunityToolkit.Mvvm` instead)
- Old `Debug.WriteLine` calls (only used in Debug mode)

## [4.0.1] - 2023-04-09

Expand Down
39 changes: 32 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@

# SleepHunter
<img src="SleepHunter/SleepHunter.ico" width=32 height=32/>
Dark Ages Automation Tool

**Disclaimer: Much of the code here does not follow proper MVVM conventions or project structure.**
<img src="SleepHunter/SleepHunter.png" width=32 height=32/> <img src="SleepHunter.Updater/SleepHunter-Updater.png" width=32 height=32/>
Dark Ages Automation Tool + Updater

<img src="Screenshots/About-1.5.0.PNG"/>

## Requirements

- [Dark Ages](https://www.darkages.com) Client 7.41
- [Dark Ages](https://www.darkages.com) Client 7.41 (current latest)
- [.NET Framework 4.8.1](https://dotnet.microsoft.com/en-us/download/dotnet-framework/net481) (or newer)

## Installation
Expand All @@ -20,6 +18,27 @@ Dark Ages Automation Tool
4. Configure your DA installation path in `Settings->Game Client` (if different)
5. Profit!

## Auto-Update

Starting with version 4.1.0, the long awaited auto-update functionality is now working!
It pulls from the [latest release](https://github.com/ewrogers/SleepHunter4/releases) section.

This means you can update from within the SleepHunter application itself by going to `Settings->Updates`.
If there is a new version available, you can update to it which will download, install, and restart SleepHunter.

**NOTE**: Your user settings **will be preserved**, but all other existing data files will be overwritten.

## Contributing

I am always accepting of pull requests (PRs) against this repository for additional features, bug fixes, and enhancements.
Now that Auto-Update is functional, it should be much easier to distribute these changes to users of the application.

It is recommended that you use [Visual Studio 2022+](https://visualstudio.microsoft.com/vs/0) for developing on Windows.
I am not sure of WPF support within other IDEs.

Unfortunately this repository does not have *any* unit tests, so you will have to test for regressions manually.
Please be mindful of the users of this application, and thoroughly test any functionality for breaking changes.

## What is SleepHunter?

SleepHunter is an automation tool used for improving character skills and abilities in [Dark Ages](https://www.darkages.com).
Expand Down Expand Up @@ -163,7 +182,7 @@ In order to do that, I knew I would need to be able to read more character state
perform more actions like equipping items and having alternate characters assist others.

It became obvious to me that this was untennable from a "scripting" perspective, at least if the layperson was going to be able to use it.
So the user experience was drastically changed. Instead you could simple double-click to add spells and skills to a queue and be on your way.
So the user experience was drastically changed. Instead you could simply double-click to add spells and skills to a queue and be on your way.

The macro engine let you set a variety of parameters but for the most part it was automatic.
It could detect when to switch staves for better cast times, wait for mana regeneration, and even flower other characters for nearly-inifite mana.
Expand All @@ -181,13 +200,19 @@ There was also a slight UI facelift in 2016 as well, mostly toning down font siz
#### Going Forward

While SleepHunter v4 continues to be the current version and fairly stable, there were always things I wanted to improve upon or add.
The infamous "Auto-Update" that never actually functioned is one of many.
The infamous "Auto-Update" that never actually functioned is one of many (now available in v4.1.0+).

A proper user manual hosted as this repositories GitHub Pages would also be useful, and can be linked from the application itself.

I also was never happy that despite using WPF, I ended up building it very WinForms-y in terms of code-behind instead of a proper MVVM data-binding application.
It's probably too much work to refactor for no apparent gain, but for anyone considering writing a WPF application today -- [use MVVM](https://learn.microsoft.com/en-us/dotnet/communitytoolkit/mvvm/).

There's still a few bugs I want to fix as well. I am still humbled by the fact people still use this application over two decades later.
That and I am surprised the game itself is still online, even if only a husk of its former self.

I absolutely accept PRs for this application! If you have a feature or bug fix that you want to implement yourself, have at it.
It should be much easier to coordinate and distribute once Auto-Update is live.

#### Why didn't you go network (packet-based) instead?

This was a constant internal struggle that I had when developing v4.
Expand Down
6 changes: 6 additions & 0 deletions SleepHunter.Updater/App.config
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>
13 changes: 13 additions & 0 deletions SleepHunter.Updater/App.xaml
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>
79 changes: 79 additions & 0 deletions SleepHunter.Updater/App.xaml.cs
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();
}
}
}
128 changes: 128 additions & 0 deletions SleepHunter.Updater/MainWindow.xaml
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>
Loading

0 comments on commit aea445a

Please sign in to comment.