diff --git a/Stardrop/Models/Settings.cs b/Stardrop/Models/Settings.cs
index 7c16085..0908951 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 b02fffe..55ffc20 100644
--- a/Stardrop/Program.cs
+++ b/Stardrop/Program.cs
@@ -147,9 +147,11 @@ 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 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())
+ 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/Utilities/External/NexusClient.cs b/Stardrop/Utilities/External/NexusClient.cs
index beffcd3..bc6e1f9 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/ViewModels/SettingsWindowViewModel.cs b/Stardrop/ViewModels/SettingsWindowViewModel.cs
index 961b9f7..dae6b0b 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 e3d9d97..9fac90b 100644
--- a/Stardrop/Views/MainWindow.axaml.cs
+++ b/Stardrop/Views/MainWindow.axaml.cs
@@ -1161,8 +1161,8 @@ 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))
+ // 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);
}
@@ -2089,10 +2089,13 @@ 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)))
+ // Delete the downloaded archived mods, unless they are being kept for other tools to collect
+ if (Program.settings.ArchiveRetentionDays <= 0)
{
- File.Delete(filePath);
+ foreach (var filePath in updateFilePaths.Where(p => File.Exists(p)))
+ {
+ File.Delete(filePath);
+ }
}
_viewModel.EvaluateRequirements();
@@ -2271,8 +2274,8 @@ 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))
+ // 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);
}
diff --git a/Stardrop/Views/SettingsWindow.axaml b/Stardrop/Views/SettingsWindow.axaml
index c71921e..e17a005 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 a9c4ff4..4bd58f5 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.'",