-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from atc-net/feature/RegistrySettings
Add support for handling of registry settings
- Loading branch information
Showing
21 changed files
with
339 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/Atc.Installer.Integration/InstallationConfigurations/RegistrySettingOption.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.