Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ These parameters are accepted by the app executables in addition to the automati
| `--no-corrupt-dialog` | Shows the verbose crash report instead of the simplified dialog. | Troubleshooting flag. |
| `--enable-secure-setting <key>` / `--disable-secure-setting <key>` | Toggles one secure setting for the current user. | May require elevation. |
| `--enable-secure-setting-for-user <user> <key>` / `--disable-secure-setting-for-user <user> <key>` | Toggles one secure setting for a specified user. | May require elevation. |
| `--delete-shortcuts <path> [<path>...]` | Deletes desktop or Start Menu shortcuts, then quits. | Used by UniGetUI to remove shortcuts the current user is not allowed to delete; refuses any path that is not a `.lnk` or `.url` under a desktop or Start Menu folder. |
| `<bundle-file>` | Loads a valid bundle file into the Package Bundles page. | Supported extensions include `.ubundle`, `.json`, `.yaml`, and `.xml`. |

## Other environment variables
Expand Down
31 changes: 31 additions & 0 deletions src/Shared/SharedPreUiCommandDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ internal static class SharedPreUiCommandDispatcher
internal const string SetSettingValueArgument = "--set-setting-value";
internal const string EnableSecureSettingArgument = "--enable-secure-setting";
internal const string DisableSecureSettingArgument = "--disable-secure-setting";
internal const string DeleteShortcutsArgument = ShortcutFileRemover.CliArgument;
internal const string MigrateWingetUIToUniGetUIArgument = "--migrate-wingetui-to-unigetui";
internal const string UninstallWingetUIArgument = "--uninstall-wingetui";
internal const string UninstallUniGetUIArgument = "--uninstall-unigetui";
Expand Down Expand Up @@ -120,6 +121,11 @@ public static string[] IgnoreArgumentsInjectedIntoProtocolLaunch(string[] args)
return DisableSecureSettingForUser(args, exitCodes);
}

if (args.Contains(DeleteShortcutsArgument))
{
return DeleteShortcuts(args, exitCodes);
}

if (args.Contains(MigrateWingetUIToUniGetUIArgument))
{
return MigrateWingetUIToUniGetUI();
Expand Down Expand Up @@ -326,6 +332,31 @@ public static int DisableSecureSettingForUser(IReadOnlyList<string> args, Shared
}
}

public static int DeleteShortcuts(
IReadOnlyList<string> args,
SharedPreUiCommandExitCodes exitCodes
)
{
int basePos = FindArgumentIndex(args, DeleteShortcutsArgument);
if (basePos < 0 || basePos + 1 >= args.Count)
{
return exitCodes.InvalidParameter;
}

string[] shortcutPaths = [.. args.Skip(basePos + 1)];

try
{
return ShortcutFileRemover.DeleteAsElevatedInstance(shortcutPaths) is 0
? exitCodes.Success
: exitCodes.Failed;
}
catch (Exception ex)
{
return ex.HResult;
}
}

public static int MigrateWingetUIToUniGetUI()
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ private void ResetAll()

public void SaveChanges()
{
List<string> desktopShortcutsToDelete = [];
List<string> startMenuShortcutsToDelete = [];

if (ShowDesktopTab)
CoreSettings.Set(CoreSettings.K.RemoveAllDesktopShortcuts, AutoDelete);

Expand All @@ -293,7 +296,7 @@ public void SaveChanges()
DesktopShortcutsDatabase.RemoveFromUnknownShortcuts(entry.Path);

if (entry.IsDeletable && File.Exists(entry.Path))
DesktopShortcutsDatabase.DeleteFromDisk(entry.Path);
desktopShortcutsToDelete.Add(entry.Path);
}

CaptureUnsavedStartMenuVerdicts();
Expand All @@ -311,7 +314,7 @@ public void SaveChanges()
continue;

if (File.Exists(path))
StartMenuShortcutsDatabase.DeleteFromDisk(path);
startMenuShortcutsToDelete.Add(path);
}

_unsavedStartMenuVerdicts.Clear();
Expand All @@ -329,8 +332,20 @@ public void SaveChanges()
);

if (File.Exists(shortcut))
StartMenuShortcutsDatabase.DeleteFromDisk(shortcut);
startMenuShortcutsToDelete.Add(shortcut);
}
}

if (desktopShortcutsToDelete.Count > 0)
DesktopShortcutsDatabase.DeleteFromDisk(desktopShortcutsToDelete);

if (startMenuShortcutsToDelete.Count > 0)
StartMenuShortcutsDatabase.DeleteFromDisk(startMenuShortcutsToDelete);

foreach (var rule in StartMenuRules)
{
if (rule.FolderIsInvalid)
continue;

StartMenuShortcutsDatabase.SetRule(rule.PackageId, rule.Folder);
StartMenuShortcutsDatabase.RebaseRelocations(rule.PackageId);
Expand Down
Loading
Loading