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: 3 additions & 2 deletions Stardrop/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
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
18 changes: 3 additions & 15 deletions Stardrop/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 to be deleted later

_viewModel.EvaluateRequirements();
_viewModel.UpdateEndorsements();
Expand Down Expand Up @@ -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 to be deleted later

_viewModel.EvaluateRequirements();
_viewModel.UpdateEndorsements();
Expand Down Expand Up @@ -2271,11 +2263,7 @@ 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))
{
File.Delete(downloadedFilePath);
}
// The downloaded archive is kept in the Nexus folder to be deleted later

_viewModel.EvaluateRequirements();
_viewModel.UpdateEndorsements();
Expand Down