From d4ddafd0b020bd70c1d111017acd13a36f522329 Mon Sep 17 00:00:00 2001 From: Frank Nielson Date: Fri, 16 Oct 2026 21:32:40 -0600 Subject: [PATCH 1/3] Keep downloaded mod archives so other tools can collect them Archives downloaded from Nexus Mods are no longer deleted after installing. They stay in the Nexus folder for mods like ModSyncCheck to move out, and Stardrop deletes any still there once they are a week old. A download whose name is already taken by a kept archive overwrites it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WZe5qavYftiucj2HUFfcDC --- Stardrop/Program.cs | 5 +++-- Stardrop/Utilities/External/NexusClient.cs | 7 ++++--- Stardrop/Views/MainWindow.axaml.cs | 18 +++--------------- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/Stardrop/Program.cs b/Stardrop/Program.cs index b02fffe9..f2d0b5ac 100644 --- a/Stardrop/Program.cs +++ b/Stardrop/Program.cs @@ -147,9 +147,10 @@ public static void Main(string[] args) settings.NexusDetails = new NexusUser(); } - // Delete any files underneath the Nexus folder + // Delete the downloaded archives underneath the Nexus folder once they are a week old. They are kept + // after installing so that mods like ModSyncCheck can collect them, which moves them out of the folder var nexusDirectory = new DirectoryInfo(Pathing.GetNexusPath()); - foreach (FileInfo file in nexusDirectory.GetFiles()) + foreach (FileInfo file in nexusDirectory.GetFiles().Where(f => f.LastWriteTime < DateTime.Now.AddDays(-7))) { file.Delete(); } diff --git a/Stardrop/Utilities/External/NexusClient.cs b/Stardrop/Utilities/External/NexusClient.cs index beffcd3c..bc6e1f91 100644 --- a/Stardrop/Utilities/External/NexusClient.cs +++ b/Stardrop/Utilities/External/NexusClient.cs @@ -470,8 +470,9 @@ public async Task DownloadFileAndGetPath(string uri, string // usable as a filename is on the way into the path rather than at any one of them var filePath = Path.Combine(Pathing.GetNexusPath(), Pathing.GetSafePathSegment(fileName)); - // FileMode.CreateNew throws on a name that is already taken, which would otherwise send a download that - // never started down the cleanup path below and delete whatever already held the name + // Archives are kept after installing, so an archive from an earlier download can already hold the name. + // It is overwritten via FileMode.Create, and only once the response has succeeded, so a download that + // never started leaves the earlier archive alone bool hasCreatedFile = false; try { @@ -483,7 +484,7 @@ public async Task DownloadFileAndGetPath(string uri, string return new(DownloadResultKind.Failed, null); } - using var fileStream = new FileStream(filePath, FileMode.CreateNew); + using var fileStream = new FileStream(filePath, FileMode.Create); hasCreatedFile = true; using var downloadStream = await response.Content.ReadAsStreamAsync(); diff --git a/Stardrop/Views/MainWindow.axaml.cs b/Stardrop/Views/MainWindow.axaml.cs index e3d9d97f..5f5a306c 100644 --- a/Stardrop/Views/MainWindow.axaml.cs +++ b/Stardrop/Views/MainWindow.axaml.cs @@ -1161,11 +1161,7 @@ private async void InstallButton_Click(object? sender, Avalonia.Interactivity.Ro await CheckForModUpdates(addedMods, useCache: true, skipCacheCheck: true); await GetCachedModUpdates(_viewModel.Mods.ToList(), skipCacheCheck: true); - // Delete the downloaded archived mod - if (File.Exists(downloadedFilePath)) - { - File.Delete(downloadedFilePath); - } + // The downloaded archive is kept in the Nexus folder rather than deleted _viewModel.EvaluateRequirements(); _viewModel.UpdateEndorsements(); @@ -2089,11 +2085,7 @@ private async Task HandleBulkModInstall(bool enabledModsOnly = false) await CheckForModUpdates(addedMods, useCache: true, skipCacheCheck: true); await GetCachedModUpdates(_viewModel.Mods.ToList(), skipCacheCheck: true); - // Delete the downloaded archived mods - foreach (var filePath in updateFilePaths.Where(p => File.Exists(p))) - { - File.Delete(filePath); - } + // The downloaded archives are kept in the Nexus folder rather than deleted _viewModel.EvaluateRequirements(); _viewModel.UpdateEndorsements(); @@ -2271,11 +2263,7 @@ internal async Task ProcessNXMLink(NXM nxmLink) await CheckForModUpdates(addedMods, useCache: true, skipCacheCheck: true); await GetCachedModUpdates(_viewModel.Mods.ToList(), skipCacheCheck: true); - // Delete the downloaded archived mod - if (File.Exists(downloadedFilePath)) - { - File.Delete(downloadedFilePath); - } + // The downloaded archive is kept in the Nexus folder rather than deleted _viewModel.EvaluateRequirements(); _viewModel.UpdateEndorsements(); From a510c115b1478604d9a1fdc5b490dca75098617c Mon Sep 17 00:00:00 2001 From: Frank Nielson Date: Fri, 16 Oct 2026 22:34:13 -0600 Subject: [PATCH 2/3] Reword the comments on kept archives Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WZe5qavYftiucj2HUFfcDC --- Stardrop/Views/MainWindow.axaml.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Stardrop/Views/MainWindow.axaml.cs b/Stardrop/Views/MainWindow.axaml.cs index 5f5a306c..eda3fef1 100644 --- a/Stardrop/Views/MainWindow.axaml.cs +++ b/Stardrop/Views/MainWindow.axaml.cs @@ -1161,7 +1161,7 @@ private async void InstallButton_Click(object? sender, Avalonia.Interactivity.Ro await CheckForModUpdates(addedMods, useCache: true, skipCacheCheck: true); await GetCachedModUpdates(_viewModel.Mods.ToList(), skipCacheCheck: true); - // The downloaded archive is kept in the Nexus folder rather than deleted + // The downloaded archive is kept in the Nexus folder to be deleted later _viewModel.EvaluateRequirements(); _viewModel.UpdateEndorsements(); @@ -2085,7 +2085,7 @@ private async Task HandleBulkModInstall(bool enabledModsOnly = false) await CheckForModUpdates(addedMods, useCache: true, skipCacheCheck: true); await GetCachedModUpdates(_viewModel.Mods.ToList(), skipCacheCheck: true); - // The downloaded archives are kept in the Nexus folder rather than deleted + // The downloaded archives are kept in the Nexus folder to be deleted later _viewModel.EvaluateRequirements(); _viewModel.UpdateEndorsements(); @@ -2263,7 +2263,7 @@ internal async Task ProcessNXMLink(NXM nxmLink) await CheckForModUpdates(addedMods, useCache: true, skipCacheCheck: true); await GetCachedModUpdates(_viewModel.Mods.ToList(), skipCacheCheck: true); - // The downloaded archive is kept in the Nexus folder rather than deleted + // The downloaded archive is kept in the Nexus folder to be deleted later _viewModel.EvaluateRequirements(); _viewModel.UpdateEndorsements(); From 812c2a4de65e0b9918ad00c70adf8102d42ca4ac Mon Sep 17 00:00:00 2001 From: Frank Nielson Date: Fri, 13 Nov 2026 15:44:09 -0700 Subject: [PATCH 3/3] Make keeping downloaded archives an opt-in setting Add an "ArchiveRetentionDays" setting, shown in the settings window under Miscellaneous. It defaults to 0, which keeps the previous behavior: an archive is deleted as soon as it is installed, and the Nexus folder is emptied on startup. A value above 0 keeps archives for that many days, and startup only deletes archives older than that. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01WmGx3mbnmBQtiBLQ3BPH7b --- Stardrop/Models/Settings.cs | 5 +++++ Stardrop/Program.cs | 7 ++++--- .../ViewModels/SettingsWindowViewModel.cs | 3 +++ Stardrop/Views/MainWindow.axaml.cs | 21 ++++++++++++++++--- Stardrop/Views/SettingsWindow.axaml | 4 ++++ Stardrop/i18n/default.json | 2 ++ 6 files changed, 36 insertions(+), 6 deletions(-) diff --git a/Stardrop/Models/Settings.cs b/Stardrop/Models/Settings.cs index 7c16085c..09089514 100644 --- a/Stardrop/Models/Settings.cs +++ b/Stardrop/Models/Settings.cs @@ -25,6 +25,11 @@ public class Settings public bool IgnoreHiddenFolders { get; set; } = true; public bool EnableProfileSpecificModConfigs { get; set; } public bool ShouldWriteToModConfigs { get; set; } + /// + /// How many days a downloaded mod archive is kept in the Nexus folder after it is installed, so that other + /// tools can collect it. 0 deletes the archive once it is installed, and any left over at startup. + /// + public int ArchiveRetentionDays { get; set; } public bool EnableModsOnAdd { get; set; } /// /// Whether to always ask before deleting a previous version of a mod when updating the mod. diff --git a/Stardrop/Program.cs b/Stardrop/Program.cs index f2d0b5ac..55ffc20c 100644 --- a/Stardrop/Program.cs +++ b/Stardrop/Program.cs @@ -147,10 +147,11 @@ public static void Main(string[] args) settings.NexusDetails = new NexusUser(); } - // Delete the downloaded archives underneath the Nexus folder once they are a week old. They are kept - // after installing so that mods like ModSyncCheck can collect them, which moves them out of the folder + // Delete the downloaded archives underneath the Nexus folder, once they are older than the retention + // period. With the default of 0 days every archive goes, as they are deleted right after installing var nexusDirectory = new DirectoryInfo(Pathing.GetNexusPath()); - foreach (FileInfo file in nexusDirectory.GetFiles().Where(f => f.LastWriteTime < DateTime.Now.AddDays(-7))) + var archiveCutoff = DateTime.Now.AddDays(-Math.Max(0, settings.ArchiveRetentionDays)); + foreach (FileInfo file in nexusDirectory.GetFiles().Where(f => settings.ArchiveRetentionDays <= 0 || f.LastWriteTime < archiveCutoff)) { file.Delete(); } diff --git a/Stardrop/ViewModels/SettingsWindowViewModel.cs b/Stardrop/ViewModels/SettingsWindowViewModel.cs index 961b9f79..dae6b0ba 100644 --- a/Stardrop/ViewModels/SettingsWindowViewModel.cs +++ b/Stardrop/ViewModels/SettingsWindowViewModel.cs @@ -16,6 +16,7 @@ public class SettingsWindowViewModel : ViewModelBase public bool IgnoreHiddenFolders { get { return Program.settings.IgnoreHiddenFolders; } set { Program.settings.IgnoreHiddenFolders = value; } } public bool IsAskingBeforeAcceptingNXM { get { return Program.settings.IsAskingBeforeAcceptingNXM; } set { Program.settings.IsAskingBeforeAcceptingNXM = value; } } public bool EnableProfileSpecificModConfigs { get { return Program.settings.EnableProfileSpecificModConfigs; } set { Program.settings.EnableProfileSpecificModConfigs = value; } } + public double ArchiveRetentionDays { get { return Program.settings.ArchiveRetentionDays; } set { Program.settings.ArchiveRetentionDays = (int)Math.Max(0, Math.Round(value)); } } public bool EnableModsOnAdd { get { return Program.settings.EnableModsOnAdd; } set { Program.settings.EnableModsOnAdd = value; } } public bool AlwaysAskToDelete { get { return Program.settings.AlwaysAskToDelete; } set { Program.settings.AlwaysAskToDelete = value; } } public bool AlwaysAskForCollectionInstallTarget { get { return Program.settings.AlwaysAskForCollectionInstallTarget; } set { Program.settings.AlwaysAskForCollectionInstallTarget = value; } } @@ -43,6 +44,7 @@ public class SettingsWindowViewModel : ViewModelBase public string ToolTip_CollectionsSkipSMAPIUpdateCheck { get; set; } public string ToolTip_EnableProfileSpecificModConfigs { get; set; } public string ToolTip_EnableModsOnAdd { get; set; } + public string ToolTip_ArchiveRetentionDays { get; set; } public string ToolTip_ShouldAutomaticallySaveProfileChanges { get; set; } public string ToolTip_ShowModThumbnails { get; set; } public string ToolTip_Save { get; set; } @@ -72,6 +74,7 @@ public SettingsWindowViewModel() ToolTip_AlwaysAskForCollectionInstallTarget = Program.translation.Get("ui.settings_window.tooltips.always_ask_for_collection_install_target"); ToolTip_CollectionsSkipSMAPIUpdateCheck = Program.translation.Get("ui.settings_window.tooltips.collections_skip_smapi_update_check"); ToolTip_EnableProfileSpecificModConfigs = Program.translation.Get("ui.settings_window.tooltips.enable_profile_specific_configs"); + ToolTip_ArchiveRetentionDays = Program.translation.Get("ui.settings_window.tooltips.archive_retention_days"); ToolTip_EnableModsOnAdd = Program.translation.Get("ui.settings_window.tooltips.enable_mods_on_add"); ToolTip_ShouldAutomaticallySaveProfileChanges = Program.translation.Get("ui.settings_window.tooltips.automatically_save_profile_changes"); ToolTip_ShowModThumbnails = Program.translation.Get("ui.settings_window.tooltips.show_mod_thumbnails"); diff --git a/Stardrop/Views/MainWindow.axaml.cs b/Stardrop/Views/MainWindow.axaml.cs index eda3fef1..9fac90bd 100644 --- a/Stardrop/Views/MainWindow.axaml.cs +++ b/Stardrop/Views/MainWindow.axaml.cs @@ -1161,7 +1161,11 @@ private async void InstallButton_Click(object? sender, Avalonia.Interactivity.Ro await CheckForModUpdates(addedMods, useCache: true, skipCacheCheck: true); await GetCachedModUpdates(_viewModel.Mods.ToList(), skipCacheCheck: true); - // The downloaded archive is kept in the Nexus folder to be deleted later + // Delete the downloaded archived mod, unless it is being kept for other tools to collect + if (Program.settings.ArchiveRetentionDays <= 0 && File.Exists(downloadedFilePath)) + { + File.Delete(downloadedFilePath); + } _viewModel.EvaluateRequirements(); _viewModel.UpdateEndorsements(); @@ -2085,7 +2089,14 @@ private async Task HandleBulkModInstall(bool enabledModsOnly = false) await CheckForModUpdates(addedMods, useCache: true, skipCacheCheck: true); await GetCachedModUpdates(_viewModel.Mods.ToList(), skipCacheCheck: true); - // The downloaded archives are kept in the Nexus folder to be deleted later + // Delete the downloaded archived mods, unless they are being kept for other tools to collect + if (Program.settings.ArchiveRetentionDays <= 0) + { + foreach (var filePath in updateFilePaths.Where(p => File.Exists(p))) + { + File.Delete(filePath); + } + } _viewModel.EvaluateRequirements(); _viewModel.UpdateEndorsements(); @@ -2263,7 +2274,11 @@ internal async Task ProcessNXMLink(NXM nxmLink) await CheckForModUpdates(addedMods, useCache: true, skipCacheCheck: true); await GetCachedModUpdates(_viewModel.Mods.ToList(), skipCacheCheck: true); - // The downloaded archive is kept in the Nexus folder to be deleted later + // Delete the downloaded archived mod, unless it is being kept for other tools to collect + if (Program.settings.ArchiveRetentionDays <= 0 && File.Exists(downloadedFilePath)) + { + File.Delete(downloadedFilePath); + } _viewModel.EvaluateRequirements(); _viewModel.UpdateEndorsements(); diff --git a/Stardrop/Views/SettingsWindow.axaml b/Stardrop/Views/SettingsWindow.axaml index c71921e7..e17a005c 100644 --- a/Stardrop/Views/SettingsWindow.axaml +++ b/Stardrop/Views/SettingsWindow.axaml @@ -239,6 +239,10 @@ + + + + diff --git a/Stardrop/i18n/default.json b/Stardrop/i18n/default.json index a9c4ff43..4bd58f5e 100644 --- a/Stardrop/i18n/default.json +++ b/Stardrop/i18n/default.json @@ -137,6 +137,7 @@ "ui.settings_window.labels.languages": "Languages", "ui.settings_window.labels.grouping": "Mod Grouping", "ui.settings_window.labels.miscellaneous": "Miscellaneous", + "ui.settings_window.labels.archive_retention_days": "Keep Downloaded Mod Archives (Days)", "ui.settings_window.labels.nexus": "Nexus Mods", "ui.settings_window.labels.preferred_server": "Preferred Server:", @@ -191,6 +192,7 @@ "ui.settings_window.tooltips.enable_mods_on_add": "If checked, Stardrop will automatically enable newly added or updated mods", "ui.settings_window.tooltips.collections_skip_smapi_update_check": "Tells SMAPI to ignore collection mods out of the update check, so its console does not report updates that the collection is meant to handle.", "ui.settings_window.tooltips.always_ask_to_delete": "If checked, Stardrop will always ask whether to delete mod files when updating the mod", + "ui.settings_window.tooltips.archive_retention_days": "How many days to keep a downloaded mod archive after it is installed, so other tools (such as ModSyncCheck) can collect it.\n\nIf 0, the archive is deleted once the mod is installed.", "ui.settings_window.tooltips.always_ask_for_collection_install_target": "If checked, Stardrop will ask whether a mod added while using a collection profile should be added to that collection.\n\nIf unchecked, it is added to the collection without asking.", "ui.settings_window.tooltips.automatically_save_profile_changes": "If checked, Stardrop will automatically save changes made to the profile", "ui.settings_window.tooltips.show_mod_thumbnails": "If checked, displays the mod's thumbnail from Nexus Mods (where applicable).\n\nRequires a Stardrop API key from Nexus Mods.'",