-
Notifications
You must be signed in to change notification settings - Fork 737
Add toggle to enable/disable insecure settings #3723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Martí Climent (marticliment)
merged 12 commits into
main
from
Add-secure-settings-toggle
Jun 13, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
38f323f
Update .deepsource.toml
marticliment d94b167
Add [yet untested] code skeleton for secure settings
marticliment 1894ab8
Add working example toggle with UAC prompt
marticliment 64767d4
little fix
marticliment 550c1ce
Add new "Dangerous settings" settings section, add more things to Sec…
marticliment c0fff6a
Add new secure settings to the Admin UI
marticliment f1877bd
Update Administrator.xaml.cs
marticliment 6b04997
remove test entry
marticliment e5a27ff
Block CLI parameters if they have not been enabled from Secure Settings
marticliment ff417b2
Merge branch 'main' into Add-secure-settings-toggle
marticliment e944374
Update Administrator.xaml
marticliment 6ce86ea
Merge branch 'Add-secure-settings-toggle' of https://github.com/marti…
marticliment File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,107 @@ | ||
| using System.Diagnostics; | ||
| using UniGetUI.Core.Data; | ||
| using UniGetUI.Core.Tools; | ||
|
|
||
| namespace UniGetUI.Core.SettingsEngine.SecureSettings; | ||
|
|
||
| public static class SecureSettings | ||
| { | ||
| private static readonly Dictionary<string, bool> _cache = new(); | ||
|
|
||
| public static class Args | ||
| { | ||
| public const string ENABLE_FOR_USER = "--enable-secure-setting-for-user"; | ||
| public const string DISABLE_FOR_USER = "--disable-secure-setting-for-user"; | ||
| } | ||
|
|
||
| public static bool Get(string setting) | ||
| { | ||
| string purifiedSetting = CoreTools.MakeValidFileName(setting); | ||
| if (_cache.TryGetValue(purifiedSetting, out var value)) | ||
| { | ||
| return value; | ||
| } | ||
|
|
||
| string purifiedUser = CoreTools.MakeValidFileName(Environment.UserName); | ||
|
|
||
| var appData = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); | ||
| var settingsLocation = Path.Join(appData, "UniGetUI\\SecureSettings", purifiedUser); | ||
| var settingFile = Path.Join(settingsLocation, purifiedSetting); | ||
|
|
||
| if (!Directory.Exists(settingsLocation)) | ||
| { | ||
| _cache[purifiedSetting] = false; | ||
| return false; | ||
| } | ||
|
|
||
| bool exists = File.Exists(settingFile); | ||
| _cache[purifiedSetting] = exists; | ||
| return exists; | ||
| } | ||
|
|
||
| public static async Task<bool> TrySet(string setting, bool enabled) | ||
| { | ||
| string purifiedSetting = CoreTools.MakeValidFileName(setting); | ||
| _cache.Remove(purifiedSetting); | ||
|
|
||
| string purifiedUser = CoreTools.MakeValidFileName(Environment.UserName); | ||
|
|
||
| using Process p = new Process(); | ||
| p.StartInfo = new() | ||
| { | ||
| UseShellExecute = true, | ||
| CreateNoWindow = true, | ||
| FileName = CoreData.UniGetUIExecutableFile, | ||
| Verb = "runas", | ||
| ArgumentList = | ||
| { | ||
| enabled? Args.ENABLE_FOR_USER: Args.DISABLE_FOR_USER, | ||
| purifiedUser, | ||
| purifiedSetting | ||
| } | ||
| }; | ||
|
|
||
| p.Start(); | ||
| await p.WaitForExitAsync(); | ||
| return p.ExitCode is 0; | ||
| } | ||
|
|
||
| public static int ApplyForUser(string username, string setting, bool enable) | ||
| { | ||
| try | ||
| { | ||
| string purifiedSetting = CoreTools.MakeValidFileName(setting); | ||
| _cache.Remove(purifiedSetting); | ||
|
|
||
| string purifiedUser = CoreTools.MakeValidFileName(username); | ||
|
|
||
| var appData = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); | ||
| var settingsLocation = Path.Join(appData, "UniGetUI\\SecureSettings", purifiedUser); | ||
| var settingFile = Path.Join(settingsLocation, purifiedSetting); | ||
|
|
||
| if (!Directory.Exists(settingsLocation)) | ||
| { | ||
| Directory.CreateDirectory(settingsLocation); | ||
| } | ||
|
|
||
| if (enable) | ||
| { | ||
| File.WriteAllText(settingFile, ""); | ||
| } | ||
| else | ||
| { | ||
| if (File.Exists(settingFile)) | ||
| { | ||
| File.Delete(settingFile); | ||
| } | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Console.WriteLine(ex); | ||
| return -1; | ||
| } | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/UniGetUI.Core.SecureSettings/UniGetUI.Core.SecureSettings.csproj
This file contains hidden or 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,9 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <ItemGroup> | ||
| <ProjectReference Include="..\UniGetUI.Core.Tools\UniGetUI.Core.Tools.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="..\SharedAssemblyInfo.cs" Link="SharedAssemblyInfo.cs" /> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assignment 'options.CustomParameters = [];' may cause issues if CustomParameters is not of an array type; consider using an appropriate collection initializer (e.g., new List()) to match its declared type.