Skip to content

Commit

Permalink
Merge pull request #101 from micahmo/release/v2.0.9
Browse files Browse the repository at this point in the history
Release/v2.0.9
  • Loading branch information
micahmo authored Mar 2, 2023
2 parents 684907f + 97d42bd commit 7375aed
Show file tree
Hide file tree
Showing 18 changed files with 286 additions and 24 deletions.
6 changes: 3 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project>
<PropertyGroup>
<!-- Keep in sync with WS4WSetupScript.iss and VersionInfo.xml -->
<AssemblyVersion>2.0.8.0</AssemblyVersion>
<FileVersion>2.0.8.0</FileVersion>
<InformationalVersion>2.0.8.0</InformationalVersion>
<AssemblyVersion>2.0.9.0</AssemblyVersion>
<FileVersion>2.0.9.0</FileVersion>
<InformationalVersion>2.0.9.0</InformationalVersion>
<Authors>Micah Morrison</Authors>
<Product>WS4W</Product>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Installer/WS4WSetupScript.iss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#define MyAppNameOld "WireGuard Server For Windows"
#define MyAppName "Wg Server for Windows"
#define MyAppVersion "2.0.8"
#define MyAppVersion "2.0.9"
#define MyAppPublisher "Micah Morrison"
#define MyAppURL "https://github.com/micahmo/WgServerforWindows"
#define MyAppExeName "WgServerforWindows.exe"
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Below are the tasks that can be performed automatically using this application.

## Before

![BeforeScreenshot](https://user-images.githubusercontent.com/7417301/170070964-b43b88c8-fa87-4123-a7dc-2345046a7baa.png)
![BeforeScreenshot](https://user-images.githubusercontent.com/7417301/219172904-ff6d90d8-79a2-40c9-a038-3a5ad3386089.png)

### WireGuard.exe
This step downloads and runs the latest version of WireGuard for Windows from https://download.wireguard.com/windows-client/wireguard-installer.exe. Once installed, it can be uninstalled directly from WS4W, too.
Expand Down Expand Up @@ -112,9 +112,15 @@ Even with these workarounds, Internet Sharing can become disabled after a reboot

Once the tunnel is installed, the status of the WireGuard interface may be viewed. This is accomplished via the `wg show` command. It will be continually updated as long as `Update Live` is checked.

### Settings

* Set Boot Task Delay

This setting allows configuring a delay for boot tasks. This can be useful for tasks that depend on adapters which are slow to load. Note that tasks must be disabled and re-enabled after changing this value.

## After

![AfterScreenshot](https://user-images.githubusercontent.com/7417301/170075433-e3e27369-30de-4404-a0ca-19d3a57d52f8.png)
![AfterScreenshot](https://user-images.githubusercontent.com/7417301/219172736-083417e2-1952-4e55-8988-06e75b44e33d.png)

## CLI
There is also a CLI bundled in the portable download called `ws4w.exe` which can be invoked from a terminal or called from a script. In addition to messages written to standard out, the CLI will also set the exit code based on the success of executing the given command. In PowerShell, for example, the exit code can be printed with `echo $lastexitcode`.
Expand Down
12 changes: 7 additions & 5 deletions WgServerforWindows/Controls/PrerequisiteItemControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>

<Image Grid.Column="0" Height="40" Margin="5" Source="/Images/checked.png" Visibility="{c:Binding Fulfilled, FalseToVisibility=Collapsed}"/>
<Image Grid.Column="0" Height="40" Margin="5" Source="/Images/cancel.png" Visibility="{c:Binding '!Fulfilled', FalseToVisibility=Collapsed}"/>
<Image Grid.Column="0" Height="40" Margin="5" Source="/Images/info.png" Visibility="{c:Binding IsInformational, FalseToVisibility=Collapsed}"/>
<Grid Grid.Column="0" Visibility="{c:Binding HasIcon, FalseToVisibility=Collapsed}">
<Image Height="40" Margin="5" Source="/Images/checked.png" Visibility="{c:Binding Fulfilled, FalseToVisibility=Collapsed}"/>
<Image Height="40" Margin="5" Source="/Images/cancel.png" Visibility="{c:Binding '!Fulfilled', FalseToVisibility=Collapsed}"/>
<Image Height="40" Margin="5" Source="/Images/info.png" Visibility="{c:Binding IsInformational, FalseToVisibility=Collapsed}"/>
</Grid>

<Grid Grid.Column="1" Margin="5">
<Grid.RowDefinitions>
Expand Down Expand Up @@ -67,7 +69,7 @@
</Grid>

<Grid Grid.Column="2" Visibility="{c:Binding 'HasSubCommands'}">
<xctk:SplitButton Height="28" Padding="5" Margin="5" VerticalAlignment="Center"
<xctk:SplitButton x:Name="SplitButtonNotFulfilled" Height="28" Padding="5" Margin="5" VerticalAlignment="Center"
Content="{Binding ResolveText}"
Command="{Binding Commands.ResolveCommand}"
Visibility="{c:Binding '!Fulfilled', FalseToVisibility=Collapsed}">
Expand Down Expand Up @@ -97,7 +99,7 @@
</ItemsControl>
</xctk:SplitButton.DropDownContent>
</xctk:SplitButton>
<xctk:SplitButton Height="28" Padding="5" Margin="5" VerticalAlignment="Center"
<xctk:SplitButton x:Name="SplitButtonFulfilled" Height="28" Padding="5" Margin="5" VerticalAlignment="Center"
Content="{Binding ConfigureText}"
Command="{Binding Commands.ConfigureCommand}"
Visibility="{c:Binding 'Fulfilled', FalseToVisibility=Collapsed}">
Expand Down
11 changes: 10 additions & 1 deletion WgServerforWindows/Controls/SelectionWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:properties="clr-namespace:WgServerforWindows.Properties"
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
xmlns:models="clr-namespace:WgServerforWindows.Models"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:c="clr-namespace:CalcBinding;assembly=CalcBinding"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=models:SelectionWindowModel}"
Title="{Binding Title}" SizeToContent="WidthAndHeight" MaxWidth="350">
<Grid>
<Grid.ColumnDefinitions>
Expand All @@ -24,14 +28,19 @@
<TextBlock Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="0" Margin="20,10,20,10" Text="{Binding Text}" TextWrapping="Wrap"/>

<ComboBox Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="1" Margin="20,10,20,10" IsEditable="False"
ItemsSource="{Binding Items}" SelectedItem="{Binding SelectedItem}" DisplayMemberPath="DisplayText">
ItemsSource="{Binding Items}" SelectedItem="{Binding SelectedItem}" DisplayMemberPath="DisplayText"
Visibility="{c:Binding IsList, FalseToVisibility=Collapsed}">
<ComboBox.ItemContainerStyle>
<Style>
<Setter Property="Control.ToolTip" Value="{Binding Description}" />
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>

<xctk:DateTimeUpDown Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="1" Margin="20,10,20,10" Format="Custom" FormatString="HH:mm:ss"
Value="{Binding SelectedItem.BackingObject}"
Visibility="{c:Binding IsTimeSpan, FalseToVisibility=Collapsed}"/>

<Button Grid.Column="1" Grid.Row="3" Padding="10,5,10,5" Margin="20,10,10,10" Content="{x:Static properties:Resources.Cancel}" Command="{Binding CancelCommand}">
<b:Interaction.Triggers>
<b:EventTrigger EventName="Click">
Expand Down
2 changes: 1 addition & 1 deletion WgServerforWindows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
xmlns:local="clr-namespace:WgServerforWindows"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type={x:Type models:MainWindowModel}}"
Title="WS4W" Height="650" Width="800"
Title="WS4W" Height="665" Width="800"
Icon="/Images/logo.ico"
Loaded="Window_Loaded">

Expand Down
3 changes: 3 additions & 0 deletions WgServerforWindows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public MainWindow()
var internetSharingPrerequisite = new InternetSharingPrerequisite();
var persistentInternetSharingPrerequisite = new PersistentInternetSharingPrerequisite();
var serverStatusPrerequisite = new ServerStatusPrerequisite();
var bootTaskDelaySubCommand = new BootTaskDelaySubCommand();
var settingsPrerequisite = new SettingsPrerequisite(bootTaskDelaySubCommand);

// -- Set up interdependencies --

Expand Down Expand Up @@ -113,6 +115,7 @@ public MainWindow()
}

mainWindowModel.PrerequisiteItems.Add(serverStatusPrerequisite);
mainWindowModel.PrerequisiteItems.Add(settingsPrerequisite);

// If one of the prereqs changes, check the validity of all of them.
// Do this recursively.
Expand Down
64 changes: 64 additions & 0 deletions WgServerforWindows/Models/BootTaskDelaySubCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using WgServerforWindows.Controls;
using WgServerforWindows.Properties;

namespace WgServerforWindows.Models
{
public class BootTaskDelaySubCommand : PrerequisiteItem
{
#region PrerequisiteItem members

public BootTaskDelaySubCommand() : base
(
title: string.Empty,
successMessage: Resources.BootTaskDelaySuccess,
errorMessage: string.Empty,
resolveText: string.Empty,
configureText: Resources.BootTaskDelayConfigure
)
{
}

public override BooleanTimeCachedProperty Fulfilled { get; } = new BooleanTimeCachedProperty(TimeSpan.FromSeconds(1), () => true);

public override void Resolve()
{
throw new NotImplementedException();
}

public override void Configure()
{
DateTime backingObject = new DateTime(1, 1, 1,
GlobalAppSettings.Instance.BootTaskDelay.Hours,
GlobalAppSettings.Instance.BootTaskDelay.Minutes,
GlobalAppSettings.Instance.BootTaskDelay.Seconds);

var selectionWindowModel = new SelectionWindowModel<DateTime>
{
Title = Resources.BootDelaySelectionTitle,
Text = Resources.BootDelaySelectionText,
SelectedItem = new SelectionItem<DateTime> { BackingObject = backingObject },
IsList = false,
IsTimeSpan = true
};

new SelectionWindow
{
DataContext = selectionWindowModel
}.ShowDialog();

if (selectionWindowModel.DialogResult == true)
{
var timeSpan = new TimeSpan(
selectionWindowModel.SelectedItem.BackingObject.Hour,
selectionWindowModel.SelectedItem.BackingObject.Minute,
selectionWindowModel.SelectedItem.BackingObject.Second);

GlobalAppSettings.Instance.BootTaskDelay = timeSpan;
GlobalAppSettings.Instance.Save();
}
}

#endregion
}
}
66 changes: 66 additions & 0 deletions WgServerforWindows/Models/GlobalAppSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.IO;
using GalaSoft.MvvmLight;
using Jot;
using Jot.Storage;

namespace WgServerforWindows.Models
{
/// <summary>
/// Defines system-wide, application-wide settings which will be persisted across sessions
/// </summary>
internal class GlobalAppSettings : ObservableObject
{
#region Singleton member

/// <summary>
/// Singleton instance
/// </summary>
public static GlobalAppSettings Instance { get; } = new GlobalAppSettings();

#endregion

#region Private constructor

/// <summary>
/// Constructor
/// </summary>
private GlobalAppSettings()
{
// Set up AppSettings tracking
Tracker.Configure<GlobalAppSettings>()
.Property(a => a.BootTaskDelay)
.Track(this);
}

#endregion

#region Public methods

public void Save()
{
Tracker.Persist(this);
}

#endregion

#region Public properties

/// <summary>
/// Boot task delay time
/// </summary>
public TimeSpan BootTaskDelay
{
get => _bootTaskDelay;
set => Set(nameof(BootTaskDelay), ref _bootTaskDelay, value);
}
private TimeSpan _bootTaskDelay;

/// <summary>
/// The public tracker instance located in Public\Documents. Can be used to track things other than the <see cref="Instance"/>.
/// </summary>
public Tracker Tracker { get; } = new Tracker(new JsonFileStore(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments), "WS4W")));

#endregion
}
}
2 changes: 1 addition & 1 deletion WgServerforWindows/Models/NewNetIpAddressTaskSubCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void Resolve(string serverDataPath)
// Create/update a Scheduled Task that sets the NetIPAddress on boot.
TaskDefinition td = TaskService.Instance.NewTask();
td.Actions.Add(new ExecAction(Path.Combine(AppContext.BaseDirectory, "ws4w.exe"), $"{typeof(SetNetIpAddressCommand).GetVerb()} --{typeof(SetNetIpAddressCommand).GetOption(nameof(SetNetIpAddressCommand.ServerDataPath))} {serverDataPath ?? ServerConfigurationPrerequisite.ServerDataPath}"));
td.Triggers.Add(new BootTrigger());
td.Triggers.Add(new BootTrigger { Delay = GlobalAppSettings.Instance.BootTaskDelay });
TaskService.Instance.RootFolder.RegisterTaskDefinition(_netIpAddressTaskUniqueName, td, TaskCreation.CreateOrUpdate, "SYSTEM", null, TaskLogonType.ServiceAccount);

Refresh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public override void Resolve()
// Create/update a Scheduled Task that disables/enables internet sharing on boot.
TaskDefinition td = TaskService.Instance.NewTask();
td.Actions.Add(new ExecAction(Path.Combine(AppContext.BaseDirectory, "ws4w.exe"), typeof(RestartInternetSharingCommand).GetVerb()));
td.Triggers.Add(new BootTrigger());
td.Triggers.Add(new BootTrigger { Delay = GlobalAppSettings.Instance.BootTaskDelay });
TaskService.Instance.RootFolder.RegisterTaskDefinition(RestartInternetSharingTaskUniqueName, td, TaskCreation.CreateOrUpdate, "SYSTEM", null, TaskLogonType.ServiceAccount);

Refresh();
Expand Down
8 changes: 7 additions & 1 deletion WgServerforWindows/Models/PrerequisiteItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows;
using System.Windows.Controls;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Xceed.Wpf.AvalonDock.Controls;

namespace WgServerforWindows.Models
{
Expand Down Expand Up @@ -102,6 +104,8 @@ public string ConfigureText

public virtual BooleanTimeCachedProperty IsInformational { get; } = new BooleanTimeCachedProperty(TimeSpan.Zero, () => false);

public virtual BooleanTimeCachedProperty HasIcon { get; } = new BooleanTimeCachedProperty(TimeSpan.Zero, () => true);

public bool CanResolve => CanResolveFunc?.Invoke() ?? true;

public Func<bool> CanResolveFunc { get; set; }
Expand All @@ -124,6 +128,8 @@ public string ConfigureText

public int SelectedChildIndex { get; set; }

public Control Control => Application.Current?.Windows.OfType<MainWindow>().FirstOrDefault()?.FindVisualChildren<Control>().FirstOrDefault(b => b.DataContext == this);

#endregion

#region Public methods
Expand Down
2 changes: 1 addition & 1 deletion WgServerforWindows/Models/PrivateNetworkTaskSubCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override void Resolve()
// Create/update a Scheduled Task that sets the Private network category on boot.
TaskDefinition td = TaskService.Instance.NewTask();
td.Actions.Add(new ExecAction(Path.Combine(AppContext.BaseDirectory, "ws4w.exe"), typeof(PrivateNetworkCommand).GetVerb()));
td.Triggers.Add(new BootTrigger());
td.Triggers.Add(new BootTrigger { Delay = GlobalAppSettings.Instance.BootTaskDelay });
TaskService.Instance.RootFolder.RegisterTaskDefinition(_privateNetworkTaskUniqueName, td, TaskCreation.CreateOrUpdate, "SYSTEM", null, TaskLogonType.ServiceAccount);

Refresh();
Expand Down
4 changes: 4 additions & 0 deletions WgServerforWindows/Models/SelectionWindowModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public SelectionItem<T> SelectedItem
}
private SelectionItem<T> _selectedItem;

public bool IsList { get; set; } = true;

public bool IsTimeSpan { get; set; }

public bool? DialogResult { get; private set; }

public ICommand CancelCommand => _cancelCommand ??= new RelayCommand(() =>
Expand Down
44 changes: 44 additions & 0 deletions WgServerforWindows/Models/SettingsPrerequisite.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using WgServerforWindows.Controls;
using WgServerforWindows.Properties;

namespace WgServerforWindows.Models
{
public class SettingsPrerequisite : PrerequisiteItem
{
#region PrerequisiteItem members

public SettingsPrerequisite(BootTaskDelaySubCommand bootTaskDelaySubCommand) : base
(
title: string.Empty,
successMessage: string.Empty,
errorMessage: string.Empty,
resolveText: string.Empty,
configureText: Resources.SettingsConfigure
)
{
SubCommands.Add(bootTaskDelaySubCommand);
}

public override BooleanTimeCachedProperty Fulfilled { get; } = new BooleanTimeCachedProperty(TimeSpan.FromSeconds(1), () => true);

public override BooleanTimeCachedProperty HasIcon { get; } = new BooleanTimeCachedProperty(TimeSpan.Zero, () => false);

public override void Resolve()
{
throw new NotImplementedException();
}

public override void Configure()
{
if (Control is PrerequisiteItemControl prerequisiteItemControl)
{
prerequisiteItemControl.SplitButtonFulfilled.IsOpen = true;
}
}

public override BooleanTimeCachedProperty IsInformational { get; } = new BooleanTimeCachedProperty(TimeSpan.Zero, () => true);

#endregion
}
}
Loading

0 comments on commit 7375aed

Please sign in to comment.