Skip to content

Commit

Permalink
Add missing policies check
Browse files Browse the repository at this point in the history
  • Loading branch information
riverar committed Nov 12, 2024
1 parent 7cea2fe commit 44a5b1e
Show file tree
Hide file tree
Showing 4 changed files with 223 additions and 106 deletions.
104 changes: 96 additions & 8 deletions EarTrumpet/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,43 @@
using EarTrumpet.UI.Helpers;
using EarTrumpet.UI.ViewModels;
using EarTrumpet.UI.Views;
using Microsoft.Win32;
using Windows.Win32;

namespace EarTrumpet;

public sealed partial class App : IDisposable
{
public static bool IsShuttingDown { get; private set; }
public static bool HasIdentity { get; private set; }
public static bool HasDevIdentity { get; private set; }
public static string PackageName { get; private set; }
public static Version PackageVersion { get; private set; }
public static bool IsShuttingDown
{
get; private set;
}
public static bool HasIdentity
{
get; private set;
}
public static bool HasDevIdentity
{
get; private set;
}
public static string PackageName
{
get; private set;
}
public static Version PackageVersion
{
get; private set;
}
public static TimeSpan Duration => s_appTimer.Elapsed;

public FlyoutWindow FlyoutWindow { get; private set; }
public DeviceCollectionViewModel CollectionViewModel { get; private set; }
public FlyoutWindow FlyoutWindow
{
get; private set;
}
public DeviceCollectionViewModel CollectionViewModel
{
get; private set;
}

private static readonly Stopwatch s_appTimer = Stopwatch.StartNew();
private FlyoutViewModel _flyoutViewModel;
Expand All @@ -40,7 +62,10 @@ public sealed partial class App : IDisposable
private WindowHolder _settingsWindow;
private ErrorReporter _errorReporter;

public static AppSettings Settings { get; private set; }
public static AppSettings Settings
{
get; private set;
}

private void OnAppStartup(object sender, StartupEventArgs e)
{
Expand All @@ -61,6 +86,7 @@ private void OnAppStartup(object sender, StartupEventArgs e)

try
{
NotifyOnMissingStartupPolicies();
ContinueStartup();
}
catch (Exception ex) when (IsCriticalFontLoadFailure(ex))
Expand Down Expand Up @@ -196,6 +222,68 @@ private static void OnCriticalFontLoadFailure()
new AutoResetEvent(false).WaitOne();
}

private static bool IsAnyStartupPolicyMissing()
{
Trace.WriteLine($"App IsAnyStartupPolicyMissing");

try
{
var registryPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System";
using var key = Registry.LocalMachine.OpenSubKey(registryPath);
if (key == null)
{
return true;
}

var dwords = new[] {
"EnableFullTrustStartupTasks",
"EnableUwpStartupTasks",
"SupportFullTrustStartupTasks",
"SupportUwpStartupTasks"
};

foreach (var dword in dwords)
{
// Warning: RegistryKey.GetValue returns int for DWORDs

var value = key.GetValue(dword);
if (value == null || value.GetType() != typeof(int))
{
Trace.WriteLine($"Missing or invalid: {dword}");
return true;
}
}
}
catch (Exception ex)
{
Trace.WriteLine($"Exception: {ex}");
}

return false;
}

private static void NotifyOnMissingStartupPolicies()
{
if (!IsAnyStartupPolicyMissing())
{
return;
}

new Thread(() =>
{
if (MessageBox.Show(
EarTrumpet.Properties.Resources.MissingPoliciesHelpText,
EarTrumpet.Properties.Resources.MissingPoliciesDialogHeaderText,
MessageBoxButton.OKCancel,
MessageBoxImage.Warning,
MessageBoxResult.OK) == MessageBoxResult.OK)
{
Trace.WriteLine($"App NotifyOnMissingStartupPolicies OK");
ProcessHelper.StartNoThrow("https://eartrumpet.app/jmp/fixstartup");
}
}).Start();
}

private List<ContextMenuItem> GetTrayContextMenuItems()
{
var ret = new List<ContextMenuItem>(CollectionViewModel.AllDevices.OrderBy(x => x.DisplayName).Select(dev => new ContextMenuItem
Expand Down
193 changes: 97 additions & 96 deletions EarTrumpet/EarTrumpet.csproj
Original file line number Diff line number Diff line change
@@ -1,103 +1,104 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<OutputType>WinExe</OutputType>
<WarningsAsErrors>true</WarningsAsErrors>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ApplicationIcon>Assets\Icon-Light.ico</ApplicationIcon>
<ApplicationManifest>App.manifest</ApplicationManifest>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWindowsForms>true</UseWindowsForms>
<UseWPF>true</UseWPF>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<Configurations>Debug;Release;VSDebug</Configurations>
<Platforms>x86;x64;ARM64</Platforms>
<GenerateSatelliteAssembliesForCore>true</GenerateSatelliteAssembliesForCore>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<OutputPath>..\Build\$(Configuration)\$(Platform)\</OutputPath>
<DefineConstants>TRACE;$(Platform.ToUpper());$(Configuration.ToUpper())</DefineConstants>
<PropertyGroup>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<OutputType>WinExe</OutputType>
<WarningsAsErrors>true</WarningsAsErrors>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ApplicationIcon>Assets\Icon-Light.ico</ApplicationIcon>
<ApplicationManifest>App.manifest</ApplicationManifest>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWindowsForms>true</UseWindowsForms>
<UseWPF>true</UseWPF>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<Configurations>Debug;Release;VSDebug</Configurations>
<Platforms>x86;x64;ARM64</Platforms>
<GenerateSatelliteAssembliesForCore>true</GenerateSatelliteAssembliesForCore>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<OutputPath>..\Build\$(Configuration)\$(Platform)\</OutputPath>
<DefineConstants>TRACE;$(Platform.ToUpper());$(Configuration.ToUpper())</DefineConstants>
<RuntimeIdentifier>win-$(Platform.ToLower())</RuntimeIdentifier>
<SupportedOSPlatformVersion>10.0.19041.0</SupportedOSPlatformVersion>
<AnalysisLevel>latest</AnalysisLevel>
<SupportedOSPlatformVersion>10.0.19041.0</SupportedOSPlatformVersion>
<AnalysisLevel>latest</AnalysisLevel>
<SelfContained>true</SelfContained>
<UseRidGraph>true</UseRidGraph>
<PublishProfile>Properties\PublishProfiles\$(Platform).pubxml</PublishProfile>
</PropertyGroup>
<PropertyGroup Condition=" $(Configuration.EndsWith('Debug')) ">
<SelfContained>true</SelfContained>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='VSDebug|x86'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='VSDebug|x64'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='VSDebug|ARM64'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<AppDesigner Include="Properties\" />
</ItemGroup>
<ItemGroup>
<Resource Include="Assets\Icon-Light.ico" />
<Resource Include="Assets\Logo-Dark.png" />
<Resource Include="Assets\Logo-Light.png" />
<Resource Include="Assets\Icon-Dark.ico" />
<Resource Include="Assets\Welcome.gif" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Bugsnag" Version="3.1.0" />
<PackageReference Include="GitVersion.MsBuild" Version="5.12.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Windows.SDK.Win32Metadata" Version="62.0.23-preview" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.ComponentModel.Composition" Version="8.0.0" />
<PackageReference Include="System.Composition.AttributedModel" Version="8.0.0" />
<PackageReference Include="System.Composition.Runtime" Version="8.0.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='VSDebug|x86'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='VSDebug|x64'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='VSDebug|ARM64'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<Resource Include="Assets\Icon-Light.ico" />
<Resource Include="Assets\Logo-Dark.png" />
<Resource Include="Assets\Logo-Light.png" />
<Resource Include="Assets\Icon-Dark.ico" />
<Resource Include="Assets\Welcome.gif" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Bugsnag" Version="3.1.0" />
<PackageReference Include="GitVersion.MsBuild" Version="5.12.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Windows.SDK.Win32Metadata" Version="62.0.23-preview" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.ComponentModel.Composition" Version="8.0.0" />
<PackageReference Include="System.Composition.AttributedModel" Version="8.0.0" />
<PackageReference Include="System.Composition.Runtime" Version="8.0.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="XamlAnimatedGif" Version="2.3.0" />
</ItemGroup>
<ItemGroup>
<Page Remove="UI\Controls\SearchBox.xaml" />
</ItemGroup>
<ItemGroup>
<None Update="App.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="BeforeBuild" DependsOnTargets="GetVersion">
<PropertyGroup Condition=" '$(Channel)'=='Store' ">
<ChannelVersion>$(GitVersion_MajorMinorPatch).0</ChannelVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(ChannelVersion)'=='' ">
<ChannelVersion>$(GitVersion_MajorMinorPatch).$(GitVersion_CommitsSinceVersionSource)</ChannelVersion>
</PropertyGroup>
<Message Text="GitVersion_InformationalVersion: $(GitVersion_InformationalVersion)" />
<Exec Command="powershell -executionpolicy Bypass -noprofile &quot;&amp; '$(ProjectDir)prebuild.ps1'&quot; $(ChannelVersion)" />
</Target>
</ItemGroup>
<ItemGroup>
<None Update="App.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Page Remove="UI\Controls\SearchBox.xaml" />
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<Target Name="BeforeBuild" DependsOnTargets="GetVersion">
<PropertyGroup Condition=" '$(Channel)'=='Store' ">
<ChannelVersion>$(GitVersion_MajorMinorPatch).0</ChannelVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(ChannelVersion)'=='' ">
<ChannelVersion>$(GitVersion_MajorMinorPatch).$(GitVersion_CommitsSinceVersionSource)</ChannelVersion>
</PropertyGroup>
<Message Text="GitVersion_InformationalVersion: $(GitVersion_InformationalVersion)" />
<Exec Command="powershell -executionpolicy Bypass -noprofile &quot;&amp; '$(ProjectDir)prebuild.ps1'&quot; $(ChannelVersion)" />
</Target>
</Project>
24 changes: 22 additions & 2 deletions EarTrumpet/Properties/Resources.Designer.cs

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

Loading

0 comments on commit 44a5b1e

Please sign in to comment.