-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move downloads out of Temp and clean up after cancel and complete.
- Loading branch information
Showing
12 changed files
with
174 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/Networking/NexusMods.Networking.Downloaders/DownloadSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using JetBrains.Annotations; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NexusMods.Abstractions.Settings; | ||
using NexusMods.Paths; | ||
|
||
namespace NexusMods.Networking.Downloaders; | ||
|
||
/// <summary> | ||
/// Settings for downloads. | ||
/// </summary> | ||
[PublicAPI] | ||
public class DownloadSettings : ISettings | ||
{ | ||
|
||
/// <summary> | ||
/// Base directory where files generated during ongoing download operations are located. | ||
/// </summary> | ||
/// <remarks> | ||
/// Should not be placed in Temp or similar directories, | ||
/// as download files may need to persist across application and system restarts. | ||
/// </remarks> | ||
public ConfigurablePath OngoingDownloadLocation { get; set; } | ||
|
||
|
||
/// <inheritdoc/> | ||
public static ISettingsBuilder Configure(ISettingsBuilder settingsBuilder) | ||
{ | ||
return settingsBuilder | ||
.ConfigureDefault(CreateDefault) | ||
.ConfigureStorageBackend<DownloadSettings>(builder => builder.UseJson()); | ||
} | ||
|
||
/// <summary> | ||
/// Create default value. | ||
/// </summary> | ||
public static DownloadSettings CreateDefault(IServiceProvider serviceProvider) | ||
{ | ||
var os = serviceProvider.GetRequiredService<IFileSystem>().OS; | ||
|
||
return new DownloadSettings | ||
{ | ||
OngoingDownloadLocation = GetStandardDownloadPath(os), | ||
}; | ||
} | ||
|
||
private static ConfigurablePath GetStandardDownloadPath(IOSInformation os) | ||
{ | ||
var basePath = os.MatchPlatform( | ||
onWindows: () => KnownPath.LocalApplicationDataDirectory, | ||
onLinux: () => KnownPath.XDG_DATA_HOME, | ||
onOSX: () => KnownPath.LocalApplicationDataDirectory | ||
); | ||
// NOTE: OSX ".App" is apparently special, using _ instead of . to prevent weirdness | ||
var baseDirectoryName = os.IsOSX ? "NexusMods_App/" : "NexusMods.App/"; | ||
var downloadsSubPath = baseDirectoryName + "Downloads/Ongoing"; | ||
|
||
return new ConfigurablePath(basePath, downloadsSubPath); | ||
} | ||
|
||
/// <summary> | ||
/// Absolute path to the standard downloads' folder. | ||
/// </summary> | ||
public static AbsolutePath GetStandardDownloadsFolder(IFileSystem fs) | ||
{ | ||
return GetStandardDownloadPath(fs.OS).ToPath(fs); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.