Skip to content

Commit

Permalink
[Fix] Added back the admin mode check and messages. Previous versions…
Browse files Browse the repository at this point in the history
… displayed a Windows error when run as non-admin.

[Improvement] Updated GitHub actions to allow beta release as well (this commit will allow to test it).
  • Loading branch information
wokhan committed Jan 3, 2021
1 parent 8ed0535 commit b179bc0
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 26 deletions.
109 changes: 109 additions & 0 deletions .github/workflows/beta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Beta

on:
push:
branches:
- master
tags:
- 'v*beta' # Push events to matching v*, i.e. v1.0, v20.15.10
#schedule: # to be enabled to have real nightlies
#- cron: 0 0 * * *

jobs:
publish-nightly:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
- name: Build and publish
run: dotnet publish -c Release
- name: Zip published files
run: compress-archive -path ./bin/net5.0-windows/publish/* -destinationpath ./bin/net5.0-windows/wfn-${{ github.ref }}.zip
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ github.ref }}-beta
release_name: v${{ github.ref }} (beta)
draft: false
prerelease: true
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./bin/net5.0-windows/wfn-${{ github.ref }}.zip
asset_name: wfn-${{ github.ref }}.zip
asset_content_type: application/zip
publish-nightly-x64:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
- name: Build and publish
run: dotnet publish -r win-x64 -c Release --self-contained true
- name: Zip published files
run: compress-archive -path ./bin/net5.0-windows/win-x64/publish/* -destinationpath ./bin/net5.0-windows/wfn-x64-${{ github.ref }}.zip
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ github.ref }}-beta
release_name: v${{ github.ref }} (beta)
draft: false
prerelease: true
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./bin/net5.0-windows/wfn-x64-${{ github.ref }}.zip
asset_name: wfn-x64-standalone-${{ github.ref }}.zip
asset_content_type: application/zip
publish-nightly-x86:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
- name: Build and publish
run: dotnet publish -r win-x86 -c Release --self-contained true
- name: Zip published files
run: compress-archive -path ./bin/net5.0-windows/win-x86/publish -destinationpath ./bin/net5.0-windows/wfn-x86-${{ github.ref }}.zip
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ github.ref }}-beta
release_name: v${{ github.ref }} (beta)
draft: false
prerelease: true
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./bin/net5.0-windows/wfn-x86-${{ github.ref }}.zip
asset_name: wfn-x86-standalone-${{ github.ref }}.zip
asset_content_type: application/zip

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: .NET Core
name: Nightlies

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion Common/Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<NeutralLanguage>en-US</NeutralLanguage>
<Description>Windows Firewall Notifier - Common Library</Description>
<Product>Windows Firewall Notifier</Product>
<Copyright>2011-2020 Wokhan (https://github.com/wokhansoft/WFN)</Copyright>
<Copyright>2011-2021 Wokhan (https://github.com/wokhansoft/WFN)</Copyright>
<Authors>Wokhan Solutions</Authors>
<OutputPath>..\bin\$(ConfigurationName)</OutputPath>
<Nullable>Enable</Nullable>
Expand Down
6 changes: 5 additions & 1 deletion Common/Config/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Common/Config/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<Setting Name="EnableVerboseLogging" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="AlwaysRunAs" Roaming="true" Type="System.Boolean" Scope="Application">
<Setting Name="AlwaysRunAs" Roaming="true" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="EnableDnsResolver" Type="System.Boolean" Scope="User">
Expand Down
6 changes: 2 additions & 4 deletions Common/Processes/ProcessHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,20 @@
using System.Management;
using System.Text.RegularExpressions;
using System.Windows;
using Wokhan.WindowsFirewallNotifier.Common.Net.WFP;
using Wokhan.WindowsFirewallNotifier.Common.Net.IP;
using System.IO;
using Wokhan.WindowsFirewallNotifier.Common.Logging;

namespace Wokhan.WindowsFirewallNotifier.Common.Processes
{
public static partial class ProcessHelper
{
public static void ElevateCurrentProcess()
public static void RunElevated(string process)
{
ProcessStartInfo proc = new ProcessStartInfo
{
UseShellExecute = true,
WorkingDirectory = Environment.CurrentDirectory,
FileName = Path.Combine(Assembly.GetCallingAssembly().Location),
FileName = process,
Verb = "runas"
};

Expand Down
11 changes: 9 additions & 2 deletions Console/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.IO;
using System.Reflection;
using System.Windows;

using Wokhan.WindowsFirewallNotifier.Common.Config;
Expand Down Expand Up @@ -33,7 +35,7 @@ private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionE
MessageBox.Show(((Exception)e.ExceptionObject).Message, Common.Properties.Resources.MSG_DLG_ERR_TITLE, MessageBoxButton.OK, MessageBoxImage.Error);
}

public bool IsElevated { get; } = UAC.CheckProcessElevated();
public bool IsElevated { get; } = UAC.CheckProcessElevated();

private void Application_Startup(object sender, StartupEventArgs e)
{
Expand All @@ -55,7 +57,12 @@ private void Application_Startup(object sender, StartupEventArgs e)

internal void RestartAsAdmin()
{
ProcessHelper.ElevateCurrentProcess();
if (System.Diagnostics.Debugger.IsAttached)
{
MessageBox.Show("WFN is currently being debugged with a non-admin Visual Studio instance.\r\nDebugger will be detached if you want to use admin-only features as it requires launching a new WFN instance.\r\nTo avoid this, please run Visual Studio with admin privileges.", "Non-admin debugger detected", MessageBoxButton.OK, MessageBoxImage.Information);
}

ProcessHelper.RunElevated(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), ProcessNames.WFN.FileName));
Environment.Exit(0);
}
}
Expand Down
6 changes: 3 additions & 3 deletions Console/Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<TargetFramework>net5.0-windows</TargetFramework>
<!-- auto-increment version - see: https://stackoverflow.com/a/60571414 -->
<!-- TODO: add this to other projects as well? -->
<FileVersion>2.1.$([System.DateTime]::UtcNow.Date.Subtract($([System.DateTime]::Parse("2020-01-01"))).TotalDays).$([System.Math]::Floor($([MSBuild]::Divide($([System.DateTime]::UtcNow.TimeOfDay.TotalSeconds), 1.32))))</FileVersion>
<FileVersion>2.5.$([System.DateTime]::UtcNow.Date.Subtract($([System.DateTime]::Parse("2020-01-01"))).TotalDays).$([System.Math]::Floor($([MSBuild]::Divide($([System.DateTime]::UtcNow.TimeOfDay.TotalSeconds), 1.32))))</FileVersion>
<!-- Version impacts location of the user.config location, therefore remove the last part (seconds) -->
<Version>2.1.$([System.DateTime]::UtcNow.Date.Subtract($([System.DateTime]::Parse("2020-01-01"))).TotalDays)</Version>
<Version>2.5.$([System.DateTime]::UtcNow.Date.Subtract($([System.DateTime]::Parse("2020-01-01"))).TotalDays)</Version>
<UseWPF>true</UseWPF>
<AssemblyName>WFN</AssemblyName>
<RootNamespace>Wokhan.WindowsFirewallNotifier.Console</RootNamespace>
Expand All @@ -17,7 +17,7 @@
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>-->
<Description>Windows Firewall Notifier - Console</Description>
<Product>Windows Firewall Notifier</Product>
<Copyright>2011-2020 Wokhan (https://github.com/wokhansoft/WFN)</Copyright>
<Copyright>2011-2021 Wokhan (https://github.com/wokhansoft/WFN)</Copyright>
<Authors>Wokhan Solutions</Authors>
<OutputPath>..\bin\$(ConfigurationName)</OutputPath>
<OutputType>WinExe</OutputType>
Expand Down
6 changes: 3 additions & 3 deletions Console/Properties/app.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
<assemblyIdentity
type="win32"
name="Windows Firewall Notifier Console"
version="2.1.0.0"
version="2.5.0.0"
processorArchitecture="*"
/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<!--<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
</trustInfo>-->
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 -->
Expand Down
5 changes: 4 additions & 1 deletion Console/UI/Controls/AdminPanel.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
<ColumnDefinition />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Content="{Binding Caption,FallbackValue=Message}" />
<StackPanel Orientation="Vertical">
<Label VerticalAlignment="Center" Padding="5,2,5,0" Content="{Binding Caption,FallbackValue=Message}" />
<Label VerticalAlignment="Center" Padding="5,0,2,0" FontStyle="Italic" FontSize="11" Content="You can also head to the options and set WFN to be always started as an admin to avoid this message." />
</StackPanel>
<Button Grid.Column="1" Click="btnRestartAdmin_Click" ext:CustomAdorner.Image="{StaticResource Image_Shield}" Content="Restart as admin" />
</Grid>
</ContentControl>
Expand Down
11 changes: 7 additions & 4 deletions Console/UI/Controls/AdminPanel.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

namespace Wokhan.WindowsFirewallNotifier.Console.UI.Controls
{
/// <summary>
/// Logique d'interaction pour AdminPanel.xaml
/// </summary>
public partial class AdminPanel : UserControl
{
public string Caption { get; set; }
public string Caption
{
get => (string)GetValue(CaptionProperty);
set => SetValue(CaptionProperty, value);
}

public static readonly DependencyProperty CaptionProperty = DependencyProperty.Register(nameof(Caption), typeof(string), typeof(AdminPanel));

public AdminPanel()
{
Expand Down
8 changes: 6 additions & 2 deletions Console/UI/Pages/EventsLog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using Wokhan.UI.Extensions;
using Wokhan.WindowsFirewallNotifier.Common.Config;
using Wokhan.WindowsFirewallNotifier.Common.Helpers;
using Wokhan.WindowsFirewallNotifier.Common.Logging;
using Wokhan.WindowsFirewallNotifier.Common.Processes;
using Wokhan.WindowsFirewallNotifier.Common.Security;
Expand Down Expand Up @@ -54,8 +55,11 @@ public EventsLog()
{
VirtualizedQueryableExtensions.Init(Dispatcher);

Loaded += (s, e) => StartHandlingSecurityLogEvents();
Unloaded += (s, e) => StopHandlingSecurityLogEvents();
if (UAC.CheckProcessElevated())
{
Loaded += (s, e) => StartHandlingSecurityLogEvents();
Unloaded += (s, e) => StopHandlingSecurityLogEvents();
}

eventsLogFilters = new EventsLogFilters(this);

Expand Down
3 changes: 2 additions & 1 deletion Console/UI/Pages/Options.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
<TextBlock Text="Notifier settings" Style="{StaticResource SectionHeader}" />
<StackPanel Margin="10">
<TextBlock Margin="0,0,0,10" TextWrapping="Wrap" Text="The following options only apply if you chose 'Block and prompt' for the outgoing connections in the Firewall settings page, as they target the WFN notification window." />
<CheckBox Padding="3" Content="Start minimized" IsChecked="{Binding StartNotifierMinimized, Source={x:Static settings:Settings.Default}}" />
<CheckBox Padding="3" Content="Always run as an admin" IsChecked="{Binding AlwaysRunAs,Mode=TwoWay}" />
<CheckBox Padding="3" Content="Start minimized" IsChecked="{Binding StartNotifierMinimized,Mode=TwoWay}" />
<CheckBox Padding="3" Content="Use an animated notification" IsChecked="{Binding UseAnimation,Mode=TwoWay}" />
<CheckBox Padding="3" Content="Enable services detection*" ToolTip="Additionally tries to detect the service making a connection in the notifier." IsChecked="{Binding EnableServiceDetection,Mode=TwoWay}" IsEnabled="{Binding IsElevated,Source={x:Static Application.Current}}" />
<Button x:Name="btnTestNotif" Click="btnTestNotif_Click" HorizontalAlignment="Center" ext:CustomAdorner.Image="/Wokhan.WindowsFirewallNotifier.Common;component/Resources/Notifier.ico" Content="Start Notifier now" />
Expand Down
2 changes: 1 addition & 1 deletion Notifier/Notifier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<Description>Windows Firewall Notifier - Notification handler</Description>
<Product>Windows Firewall Notifier</Product>
<Copyright>2011-2020 Wokhan and others (https://github.com/wokhansoft/WFN)</Copyright>
<Copyright>2011-2021 Wokhan and others (https://github.com/wokhansoft/WFN)</Copyright>
<Authors>Wokhan Solutions, Harrwiss</Authors>
<OutputPath>..\bin\$(ConfigurationName)</OutputPath>
<Company>Wokhan Solutions</Company>
Expand Down
3 changes: 2 additions & 1 deletion WindowsFirewallNotifier.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{1DBB954C-E22
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "github-actions", "github-actions", "{573DABCD-1C81-465A-AD08-41F109761D74}"
ProjectSection(SolutionItems) = preProject
.github\workflows\dotnetcore.yml = .github\workflows\dotnetcore.yml
.github\workflows\beta.yml = .github\workflows\beta.yml
.github\workflows\nightly.yml = .github\workflows\nightly.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "legal", "legal", "{28683BDB-380A-4B87-AC28-142192543EEB}"
Expand Down

0 comments on commit b179bc0

Please sign in to comment.