Skip to content

Commit

Permalink
Merge pull request #21 from atc-net/feature/RegistrySettings
Browse files Browse the repository at this point in the history
Add support for handling of registry settings
  • Loading branch information
davidkallesen authored Mar 11, 2024
2 parents 21839f0 + e2c59ac commit 47e7cbc
Show file tree
Hide file tree
Showing 21 changed files with 339 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,11 @@ dotnet_diagnostic.IDE0079.severity = none # dotnet_remove_unnecessary_

dotnet_diagnostic.MA0134.severity = none # Observe result of async calls

dotnet_diagnostic.S2629.severity = none # Don't use string interpolation in logging message templates.
dotnet_diagnostic.S3267.severity = none # Loops should be simplified with 'LINQ' expressions
dotnet_diagnostic.S4487.severity = none # Remove this unread private field
dotnet_diagnostic.S6602.severity = none # "Find" method should be used instead of the "FirstOrDefault"
dotnet_diagnostic.S6605.severity = none # Collection-specific "Exists" method should be used instead of the "Any"
dotnet_diagnostic.S6667.severity = none # Logging in a catch clause should pass the caught exception as a parameter.

dotnet_diagnostic.SCS0006.severity = none # Do Not Use Broken Cryptographic Algorithms - Its ok, only using to calculate a file-hash
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<PackageReference Include="Meziantou.Analyzer" Version="2.0.145" PrivateAssets="All" />
<PackageReference Include="SecurityCodeScan.VS2019" Version="5.6.7" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.507" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.20.0.85982" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.21.0.86780" PrivateAssets="All" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public enum HostingFrameworkType
NativeNoSettings,

[Description(".NET Framework 4.8")]
DonNetFramework48,
DotNetFramework48,

[Description(".NET 7")]
DotNet7,
Expand Down
82 changes: 82 additions & 0 deletions src/Atc.Installer.Integration/Helpers/RegistryHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
namespace Atc.Installer.Integration.Helpers;

[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "OK.")]
[SupportedOSPlatform("Windows")]
public static class RegistryHelper
{
public static (bool IsSucceeded, string? ErrorMessage) CreateSubKeyInLocalMachine(
string key)
{
ArgumentException.ThrowIfNullOrEmpty(key);

try
{
using var registryKey = Registry.LocalMachine.CreateSubKey(key);
if (registryKey is null)
{
return (false, $"Registry-LocalMachine-CreateSubKey: {key}");
}
}
catch (Exception ex)
{
return (false, $"Registry-LocalMachine-CreateSubKey: {key} - {ex.Message}");
}

return (true, null);
}

public static (bool IsSucceeded, string? ErrorMessage) DeleteSubKeyTreeInLocalMachine(
string key)
{
ArgumentException.ThrowIfNullOrEmpty(key);

try
{
Registry.LocalMachine.DeleteSubKeyTree(key, throwOnMissingSubKey: false);
}
catch (Exception ex)
{
return (false, $"Registry-LocalMachine-DeleteSubKeyTree: {key} - {ex.Message}");
}

return (true, null);
}

public static (bool IsSucceeded, string? ErrorMessage) CreateSubKeyInCurrentUser(
string key)
{
ArgumentException.ThrowIfNullOrEmpty(key);

try
{
using var registryKey = Registry.CurrentUser.CreateSubKey(key);
if (registryKey is null)
{
return (false, $"Registry-CurrentUser-CreateSubKey: {key}");
}
}
catch (Exception ex)
{
return (false, $"Registry-CurrentUser-CreateSubKey: {key} - {ex.Message}");
}

return (true, null);
}

public static (bool IsSucceeded, string? ErrorMessage) DeleteSubKeyTreeInCurrentUser(
string key)
{
ArgumentException.ThrowIfNullOrEmpty(key);

try
{
Registry.CurrentUser.DeleteSubKeyTree(key, throwOnMissingSubKey: false);
}
catch (Exception ex)
{
return (false, $"Registry-CurrentUser-DeleteSubKeyTree: {key} - {ex.Message}");
}

return (true, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class ApplicationOption

public IList<FolderPermissionOption> FolderPermissions { get; set; } = new List<FolderPermissionOption>();

public IList<RegistrySettingOption> RegistrySettings { get; set; } = new List<RegistrySettingOption>();

public IList<FirewallRuleOption> FirewallRules { get; set; } = new List<FirewallRuleOption>();

public IList<ConfigurationSettingsFileOption> ConfigurationSettingsFiles { get; set; } = new List<ConfigurationSettingsFileOption>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Atc.Installer.Integration.InstallationConfigurations;

public class RegistrySettingOption
{
public string Key { get; set; } = string.Empty;

public InsertRemoveType Action { get; set; }

public override string ToString()
=> $"{nameof(Key)}: {Key}, {nameof(Action)}: {Action}";
}
8 changes: 4 additions & 4 deletions src/Atc.Installer.Wpf.App/Atc.Installer.Wpf.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Atc.Wpf" Version="2.0.424" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.424" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.424" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.424" />
<PackageReference Include="Atc.Wpf" Version="2.0.468" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.468" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.468" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.468" />
<PackageReference Include="ClosedXML" Version="0.104.0-preview2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
Expand Down
9 changes: 9 additions & 0 deletions src/Atc.Installer.Wpf.App/Helpers/ConfigurationFileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ private static void MapCustomSettingsToTemplateSettings(
}
}

foreach (var customRegistrySetting in customApplication.RegistrySettings)
{
if (templateApplication.RegistrySettings.FirstOrDefault(x => x.Key == customRegistrySetting.Key) is
null)
{
templateApplication.RegistrySettings.Add(customRegistrySetting);
}
}

foreach (var customFirewallRule in customApplication.FirewallRules)
{
if (templateApplication.FirewallRules.FirstOrDefault(x => x.Name == customFirewallRule.Name) is null)
Expand Down
3 changes: 2 additions & 1 deletion src/Atc.Installer.Wpf.App/MainWindowViewModel_Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ InstallationFile is not null &&
x.DefaultApplicationSettings.IsDirty ||
x.ApplicationSettings.IsDirty ||
x.FolderPermissions.IsDirty ||
x.RegistrySettings.IsDirty ||
x.FirewallRules.IsDirty ||
x.ConfigurationSettingsFiles.IsDirty));

Expand Down Expand Up @@ -258,7 +259,7 @@ private async Task ReportingToExcelCommandHandler()
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal),
Title = "Select a file",
Filter = "Excel Files|*.xlsx",
FileName = ProjectName,
FileName = ProjectName ?? "NoName",
};

if (saveFileDialog.ShowDialog() != true ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc.Wpf" Version="2.0.424" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.424" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.424" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.424" />
<PackageReference Include="Atc.Wpf" Version="2.0.468" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.468" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.468" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.468" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc.Wpf" Version="2.0.424" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.424" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.424" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.424" />
<PackageReference Include="Atc.Wpf" Version="2.0.468" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.468" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.468" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.468" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ private void CheckPrerequisitesForHostingFramework()
{
switch (HostingFramework)
{
case HostingFrameworkType.DonNetFramework48:
case HostingFrameworkType.DotNetFramework48:
if (iisInstallerService.IsMicrosoftDotNetFramework48())
{
AddToInstallationPrerequisites("IsMicrosoftDotNetFramework48", LogCategoryType.Information, "Microsoft .NET Framework 4.8 is installed");
Expand Down Expand Up @@ -976,6 +976,8 @@ private async Task ServiceDeployWebsitePostProcessing(

EnsureFolderPermissions();

EnsureRegistrySettings();

EnsureFirewallRules();

if (HostingFramework == HostingFrameworkType.NodeJs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc.Wpf" Version="2.0.424" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.424" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.424" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.424" />
<PackageReference Include="Atc.Wpf" Version="2.0.468" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.468" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.468" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.468" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc.Wpf" Version="2.0.424" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.424" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.424" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.424" />
<PackageReference Include="Atc.Wpf" Version="2.0.468" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.468" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.468" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.468" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,10 @@ private void CheckPrerequisitesForHostingFramework()
case HostingFrameworkType.DotNet8:
AddToInstallationPrerequisites("IsMicrosoftDotNet8", LogCategoryType.Warning, "Microsoft .NET 8 is not installed");
break;
case HostingFrameworkType.DonNetFramework48 when waInstallerService.IsMicrosoftDotNetFramework48():
case HostingFrameworkType.DotNetFramework48 when waInstallerService.IsMicrosoftDotNetFramework48():
AddToInstallationPrerequisites("IsMicrosoftDotNetFramework48", LogCategoryType.Information, "Microsoft .NET Framework 4.8 is installed");
break;
case HostingFrameworkType.DonNetFramework48:
case HostingFrameworkType.DotNetFramework48:
AddToInstallationPrerequisites("IsMicrosoftDotNetFramework48", LogCategoryType.Warning, "Microsoft .NET Framework 4.8 is not installed");
break;
case HostingFrameworkType.Native:
Expand Down Expand Up @@ -796,6 +796,8 @@ private async Task ServiceDeployWindowServicePostProcessing(

EnsureFolderPermissions();

EnsureRegistrySettings();

EnsureFirewallRules();

if (TryGetStringFromApplicationSettings("WebProtocol", out _))
Expand Down Expand Up @@ -886,6 +888,8 @@ private Task<bool> ServiceDeployWindowApplicationCreate(

EnsureFolderPermissions();

EnsureRegistrySettings();

EnsureFirewallRules();

InstallationState = ComponentInstallationState.Installed;
Expand Down Expand Up @@ -921,6 +925,8 @@ private bool ServiceDeployWindowApplicationUpdate(

EnsureFolderPermissions();

EnsureRegistrySettings();

EnsureFirewallRules();

InstallationState = ComponentInstallationState.Installed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.433" />
<PackageReference Include="Atc.Wpf" Version="2.0.424" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.424" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.424" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.424" />
<PackageReference Include="Atc.Wpf" Version="2.0.468" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.468" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.468" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.468" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public ComponentProviderViewModel()
DefaultApplicationSettings = new ApplicationSettingsViewModel(isDefaultApplicationSettings: true, RefComponentProviders);
ApplicationSettings = new ApplicationSettingsViewModel(isDefaultApplicationSettings: false, RefComponentProviders);
FolderPermissions = new FolderPermissionsViewModel();
RegistrySettings = new RegistrySettingsViewModel();
FirewallRules = new FirewallRulesViewModel();
ConfigurationSettingsFiles = new ConfigurationSettingsFilesViewModel();
}
Expand Down Expand Up @@ -80,6 +81,9 @@ public ComponentProviderViewModel(
FolderPermissions = new FolderPermissionsViewModel();
FolderPermissions.Populate(this, applicationOption.FolderPermissions);

RegistrySettings = new RegistrySettingsViewModel();
RegistrySettings.Populate(this, applicationOption.RegistrySettings);

FirewallRules = new FirewallRulesViewModel();
FirewallRules.Populate(this, applicationOption.FirewallRules);

Expand Down Expand Up @@ -155,6 +159,8 @@ public bool ShowOnlyBaseSettings

public FolderPermissionsViewModel FolderPermissions { get; }

public RegistrySettingsViewModel RegistrySettings { get; }

public FirewallRulesViewModel FirewallRules { get; }

public ConfigurationSettingsFilesViewModel ConfigurationSettingsFiles { get; }
Expand Down
Loading

0 comments on commit 47e7cbc

Please sign in to comment.