diff --git a/src/UniGetUI.Core.IconStore/UniGetUI.Core.IconEngine.csproj b/src/UniGetUI.Core.IconStore/UniGetUI.Core.IconEngine.csproj
index 60da03e101..29fd21b362 100644
--- a/src/UniGetUI.Core.IconStore/UniGetUI.Core.IconEngine.csproj
+++ b/src/UniGetUI.Core.IconStore/UniGetUI.Core.IconEngine.csproj
@@ -24,6 +24,6 @@
-
+
diff --git a/src/UniGetUI.Core.LanguageEngine/UniGetUI.Core.LanguageEngine.csproj b/src/UniGetUI.Core.LanguageEngine/UniGetUI.Core.LanguageEngine.csproj
index a191fa73eb..625d9d0186 100644
--- a/src/UniGetUI.Core.LanguageEngine/UniGetUI.Core.LanguageEngine.csproj
+++ b/src/UniGetUI.Core.LanguageEngine/UniGetUI.Core.LanguageEngine.csproj
@@ -12,7 +12,7 @@
-
+
diff --git a/src/UniGetUI.PackageEngine.Operations/PackageOperations.cs b/src/UniGetUI.PackageEngine.Operations/PackageOperations.cs
index 4777b2fd17..120e48f054 100644
--- a/src/UniGetUI.PackageEngine.Operations/PackageOperations.cs
+++ b/src/UniGetUI.PackageEngine.Operations/PackageOperations.cs
@@ -157,7 +157,7 @@ protected override Task HandleSuccess()
if (Settings.Get("AskToDeleteNewDesktopShortcuts"))
{
- DesktopShortcutsDatabase.TryRemoveNewShortcuts(DesktopShortcutsBeforeStart);
+ DesktopShortcutsDatabase.HandleNewShortcuts(DesktopShortcutsBeforeStart);
}
return Task.CompletedTask;
}
@@ -177,7 +177,7 @@ protected override void Initialize()
if (Settings.Get("AskToDeleteNewDesktopShortcuts"))
{
- DesktopShortcutsBeforeStart = DesktopShortcutsDatabase.GetShortcuts();
+ DesktopShortcutsBeforeStart = DesktopShortcutsDatabase.GetShortcutsOnDisk();
}
}
}
@@ -209,7 +209,7 @@ protected override async Task HandleSuccess()
if (Settings.Get("AskToDeleteNewDesktopShortcuts"))
{
- DesktopShortcutsDatabase.TryRemoveNewShortcuts(DesktopShortcutsBeforeStart);
+ DesktopShortcutsDatabase.HandleNewShortcuts(DesktopShortcutsBeforeStart);
}
if (await Package.HasUpdatesIgnoredAsync() && await Package.GetIgnoredUpdatesVersionAsync() != "*")
@@ -231,7 +231,7 @@ protected override void Initialize()
if (Settings.Get("AskToDeleteNewDesktopShortcuts"))
{
- DesktopShortcutsBeforeStart = DesktopShortcutsDatabase.GetShortcuts();
+ DesktopShortcutsBeforeStart = DesktopShortcutsDatabase.GetShortcutsOnDisk();
}
}
}
diff --git a/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Classes/DesktopShortcutsDatabase.cs b/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Classes/DesktopShortcutsDatabase.cs
index ea04da8d0e..42fbc90e03 100644
--- a/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Classes/DesktopShortcutsDatabase.cs
+++ b/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Classes/DesktopShortcutsDatabase.cs
@@ -8,8 +8,8 @@ public static class DesktopShortcutsDatabase
public enum Status
{
Maintain, // The user has explicitly requested this shortcut not be deleted
- Delete, // The user has allowed the shortcut to be deleted
Unknown, // The user has not said whether they want this shortcut to be deleted
+ Delete, // The user has allowed the shortcut to be deleted
}
private static readonly List UnknownShortcuts = [];
@@ -28,10 +28,13 @@ public static void ResetDatabase()
/// Adds a desktop shortcut to the deletable desktop shortcuts database
///
/// The path of the shortcut to delete
- /// Whether or not to mark this entry as deletable in the database. Defaults to true
- public static void AddToDatabase(string shortcutPath, bool deletable = true)
+ /// The status to set
+ public static void AddToDatabase(string shortcutPath, Status shortcutStatus)
{
- Settings.SetDictionaryItem("DeletableDesktopShortcuts", shortcutPath, deletable);
+ if (shortcutStatus is Status.Unknown)
+ Settings.RemoveDictionaryKey("DeletableDesktopShortcuts", shortcutPath);
+ else
+ Settings.SetDictionaryItem("DeletableDesktopShortcuts", shortcutPath, shortcutStatus is Status.Delete);
}
///
@@ -54,28 +57,6 @@ public static bool Remove(string shortcutPath)
return false;
}
- ///
- /// Attempts to reset the configuration of a given shortcut path from the database.
- /// This will make it so the user is asked about it the next time it is discovered.
- /// Different from `Remove` as Remove simply marks it as non-deletable, whereas this removes the configuration entirely.
- ///
- /// The path of the shortcut to delete
- /// True if the shortcut was completely removed, false if it was not there from the beginning
- public static bool ResetShortcut(string shortcutPath)
- {
- // Remove the entry if present
- if (Settings.DictionaryContainsKey("DeletableDesktopShortcuts", shortcutPath))
- {
- // Remove the entry and propagate changes to disk
- Settings.RemoveDictionaryKey("DeletableDesktopShortcuts", shortcutPath);
- return true;
- }
-
- // Do nothing if the entry was not there
- Logger.Warn($"Attempted to reset a deletable desktop shortcut {{shortcutPath={shortcutPath}}} that was not found there");
- return false;
- }
-
///
/// Attempts to delete the given shortcut path off the disk
///
@@ -103,7 +84,7 @@ public static bool DeleteFromDisk(string shortcutPath)
/// until a choice is given to the user and they explicitly request that it be deleted.
///
/// The path of the shortcut to be deleted
- /// True if the package is ignored, false otherwhise
+ /// The status of a shortcut
public static Status GetStatus(string shortcutPath)
{
// Check if the package is ignored
@@ -120,7 +101,7 @@ public static Status GetStatus(string shortcutPath)
/// Get a list of shortcuts (.lnk files only) currently on the user's desktop
///
/// A list of desktop shortcut paths
- public static List GetShortcuts()
+ public static List GetShortcutsOnDisk()
{
List shortcuts = [];
string UserDesktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
@@ -130,6 +111,23 @@ public static List GetShortcuts()
return shortcuts;
}
+ ///
+ /// Gets all the shortcuts exist on disk or/and on the database
+ ///
+ ///
+ public static List GetAllShortcuts()
+ {
+ var shortcuts = GetShortcutsOnDisk();
+
+ foreach (var item in Settings.GetDictionary("DeletableDesktopShortcuts"))
+ {
+ if (!shortcuts.Contains(item.Key))
+ shortcuts.Add(item.Key);
+ }
+
+ return shortcuts;
+ }
+
///
/// Remove a shortcut from the list of shortcuts whose deletion verdicts are unknown (as in, the user needs to be asked about deleting them when their operations finish)
///
@@ -150,29 +148,52 @@ public static List GetUnknownShortcuts()
}
///
- /// Will attempt to remove new desktop shortcuts, if applicable.
+ /// Will handle the removal, if applicable, of any shortcut that is not present on the given PreviousShortCutList.
///
- ///
- public static void TryRemoveNewShortcuts(IReadOnlyList PreviousShortCutList)
+ /// The shortcuts that already existed
+ public static void HandleNewShortcuts(IReadOnlyList PreviousShortCutList)
{
- HashSet ShortcutSet = PreviousShortCutList.ToHashSet();
- List CurrentShortcutList = DesktopShortcutsDatabase.GetShortcuts();
- foreach (string shortcut in CurrentShortcutList)
+ bool DeleteUnknownShortcuts = Settings.Get("RemoveAllDesktopShortcuts");
+ HashSet PreviousShortcuts = [.. PreviousShortCutList];
+ List CurrentShortcuts = GetShortcutsOnDisk();
+
+ foreach (string shortcut in CurrentShortcuts)
{
- if (ShortcutSet.Contains(shortcut)) continue;
- switch (DesktopShortcutsDatabase.GetStatus(shortcut))
+ var status = GetStatus(shortcut);
+ if (status is Status.Maintain)
+ {
+ // Don't delete this shortcut, it has been set to be kept
+ }
+ else if (status is Status.Delete)
+ {
+ // If a shortcut is set to be deleted, delete it,
+ // even when it was not created during an UniGetUI operation
+ DeleteFromDisk(shortcut);
+ }
+ else if (status is Status.Unknown)
{
- case Status.Delete:
- DesktopShortcutsDatabase.DeleteFromDisk(shortcut);
- break;
- case Status.Maintain:
- Logger.Debug("Refraining from deleting new shortcut " + shortcut + ": user disabled its deletion");
- break;
- case Status.Unknown:
- if (UnknownShortcuts.Contains(shortcut)) continue;
- Logger.Info("Marking the shortcut " + shortcut + " to be asked to be deleted");
- UnknownShortcuts.Add(shortcut);
- break;
+ if (DeleteUnknownShortcuts)
+ {
+ // If a shortcut has not been detected yet, and it
+ // existed before an operation started, then do nothing.
+ if(PreviousShortcuts.Contains(shortcut))
+ continue;
+
+ // If the shortcut was created during an operation
+ // and autodelete is enabled, delete that icon
+ Logger.Warn($"New shortcut {shortcut} will be set for deletion (this shortcut was never seen before)");
+ AddToDatabase(shortcut, Status.Delete);
+ DeleteFromDisk(shortcut);
+ }
+ else
+ {
+ // Mark the shortcut as unknown and prompt the user.
+ if (!UnknownShortcuts.Contains(shortcut))
+ {
+ Logger.Info($"Marking the shortcut {shortcut} to be asked to be deleted");
+ UnknownShortcuts.Add(shortcut);
+ }
+ }
}
}
}
diff --git a/src/UniGetUI/Pages/DialogPages/DesktopShortcuts.xaml b/src/UniGetUI/Pages/DialogPages/DesktopShortcuts.xaml
index f0010776d0..d6e5afbe20 100644
--- a/src/UniGetUI/Pages/DialogPages/DesktopShortcuts.xaml
+++ b/src/UniGetUI/Pages/DialogPages/DesktopShortcuts.xaml
@@ -7,8 +7,7 @@
xmlns:local="using:UniGetUI.Interface"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:widgets="using:UniGetUI.Interface.Widgets"
- Width="900"
- MaxWidth="1100"
+ MaxWidth="950"
mc:Ignorable="d">
@@ -30,7 +29,7 @@
VerticalAlignment="Bottom"
Orientation="Vertical"
Spacing="4">
-