Skip to content
Open
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
5 changes: 5 additions & 0 deletions Stardrop/Models/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public class Settings
public bool IgnoreHiddenFolders { get; set; } = true;
public bool EnableProfileSpecificModConfigs { get; set; }
public bool ShouldWriteToModConfigs { get; set; }
/// <summary>
/// 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.
/// </summary>
public int ArchiveRetentionDays { get; set; }
public bool EnableModsOnAdd { get; set; }
/// <summary>
/// Whether to always ask before deleting a previous version of a mod when updating the mod.
Expand Down
6 changes: 4 additions & 2 deletions Stardrop/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
7 changes: 4 additions & 3 deletions Stardrop/Utilities/External/NexusClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,9 @@ public async Task<NexusDownloadResult> 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
{
Expand All @@ -483,7 +484,7 @@ public async Task<NexusDownloadResult> 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();
Expand Down
3 changes: 3 additions & 0 deletions Stardrop/ViewModels/SettingsWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; } }
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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");
Expand Down
17 changes: 10 additions & 7 deletions Stardrop/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -2271,8 +2274,8 @@ internal async Task<NXMLinkResult> 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);
}
Expand Down
4 changes: 4 additions & 0 deletions Stardrop/Views/SettingsWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@
<CheckBox Name="alwaysAskToDelete" IsChecked="{Binding AlwaysAskToDelete}" Content="{i18n:Translate ui.settings_window.buttons.always_ask_to_delete}" ToolTip.Tip="{Binding ToolTip_AlwaysAskToDelete}" VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="{DynamicResource ThemeForegroundBrush}" />
<CheckBox Name="automaticallySaveProfileChanges" IsChecked="{Binding ShouldAutomaticallySaveProfileChanges}" Content="{i18n:Translate ui.settings_window.buttons.automatically_save_profile_changes}" ToolTip.Tip="{Binding ToolTip_ShouldAutomaticallySaveProfileChanges}" VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="{DynamicResource ThemeForegroundBrush}" />
<CheckBox Name="showModThumbnails" IsChecked="{Binding ShowModThumbnails}" Content="{i18n:Translate ui.settings_window.buttons.show_mod_thumbnails}" ToolTip.Tip="{Binding ToolTip_ShowModThumbnails}" VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="{DynamicResource ThemeForegroundBrush}" />
<StackPanel Orientation="Horizontal" Margin="0 5 0 5" ToolTip.Tip="{Binding ToolTip_ArchiveRetentionDays}">
<TextBlock Text="{i18n:Translate ui.settings_window.labels.archive_retention_days}" VerticalAlignment="Center" Foreground="{DynamicResource ThemeForegroundBrush}" />
<NumericUpDown Name="archiveRetentionDays" Value="{Binding ArchiveRetentionDays}" Minimum="0" Maximum="365" Increment="1" FormatString="0" Margin="10 0 0 0" Width="120" Background="{DynamicResource ThemeBackgroundBrush}" Foreground="{DynamicResource ThemeForegroundBrush}" BorderBrush="{DynamicResource HighlightBrush}" />
</StackPanel>
<CheckBox Name="collectionsSkipSMAPIUpdateCheck" IsChecked="{Binding CollectionsSkipSMAPIUpdateCheck}" Content="{i18n:Translate ui.settings_window.buttons.collections_skip_smapi_update_check}" ToolTip.Tip="{Binding ToolTip_CollectionsSkipSMAPIUpdateCheck}" VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="{DynamicResource ThemeForegroundBrush}" />
<CheckBox Name="alwaysAskForCollectionInstallTarget" IsChecked="{Binding AlwaysAskForCollectionInstallTarget}" Content="{i18n:Translate ui.settings_window.buttons.always_ask_for_collection_install_target}" ToolTip.Tip="{Binding ToolTip_AlwaysAskForCollectionInstallTarget}" VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="{DynamicResource ThemeForegroundBrush}" />
</StackPanel>
Expand Down
2 changes: 2 additions & 0 deletions Stardrop/i18n/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:",

Expand Down Expand Up @@ -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.'",
Expand Down