delete old files before downloaing, fix download task
This commit is contained in:
parent
174e21d03f
commit
90ceffdfca
@ -69,12 +69,16 @@ public static class DownloadCacheHelper
|
||||
/// <param name="targetLink">The url to download the file from</param>
|
||||
/// <param name="progress">A provider for progress updates</param>
|
||||
/// <returns>A <see cref="FileInfo"/> object of the cached file</returns>
|
||||
/// <remarks>If the file exists, it is deleted before downloading</remarks>
|
||||
public static async Task<FileInfo?> DownloadFileAsync(string outputFileName, string targetLink, IProgress<double> progress)
|
||||
{
|
||||
var outputFile = new FileInfo(Path.Join(CachePath, outputFileName));
|
||||
|
||||
try
|
||||
{
|
||||
if (outputFile.Exists)
|
||||
outputFile.Delete();
|
||||
|
||||
// Use the provided extension method
|
||||
using (var file = new FileStream(outputFile.FullName, FileMode.Create, FileAccess.Write, FileShare.None))
|
||||
await _httpClient.DownloadDataAsync(targetLink, file, progress);
|
||||
@ -102,12 +106,16 @@ public static class DownloadCacheHelper
|
||||
/// <param name="outputFileName">The file name to save the file as</param>
|
||||
/// <param name="downloadStream">The stream the download the file from</param>
|
||||
/// <returns>A <see cref="FileInfo"/> object of the cached file</returns>
|
||||
/// <remarks>If the file exists, it is deleted before downloading</remarks>
|
||||
public static async Task<FileInfo?> DownloadFileAsync(string outputFileName, Stream downloadStream)
|
||||
{
|
||||
var outputFile = new FileInfo(Path.Join(CachePath, outputFileName));
|
||||
|
||||
try
|
||||
{
|
||||
if (outputFile.Exists)
|
||||
outputFile.Delete();
|
||||
|
||||
using var patcherFileStream = outputFile.Open(FileMode.Create);
|
||||
{
|
||||
await downloadStream.CopyToAsync(patcherFileStream);
|
||||
|
@ -1,5 +1,4 @@
|
||||
using CG.Web.MegaApiClient;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json;
|
||||
using SPTInstaller.Interfaces;
|
||||
using SPTInstaller.Models;
|
||||
using System.Collections.Generic;
|
||||
@ -7,7 +6,6 @@ using System.Threading.Tasks;
|
||||
using SPTInstaller.Helpers;
|
||||
using SPTInstaller.Models.Mirrors;
|
||||
using SPTInstaller.Models.Mirrors.Downloaders;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Serilog;
|
||||
|
||||
namespace SPTInstaller.Installer_Tasks;
|
||||
@ -39,9 +37,10 @@ public class DownloadTask : InstallerTaskBase
|
||||
if (mirrorsList == null)
|
||||
return Result.FromError("Failed to deserialize mirrors list");
|
||||
|
||||
|
||||
foreach (var mirror in mirrorsList)
|
||||
{
|
||||
_expectedPatcherHash = mirror.Hash;
|
||||
|
||||
switch (mirror.Link)
|
||||
{
|
||||
case string l when l.StartsWith("https://mega"):
|
||||
@ -58,7 +57,7 @@ public class DownloadTask : InstallerTaskBase
|
||||
|
||||
private async Task<IResult> DownloadPatcherFromMirrors(IProgress<double> progress)
|
||||
{
|
||||
SetStatus("Downloading Patcher", "Checking cache ...", progressStyle: ProgressStyle.Indeterminate);
|
||||
SetStatus("Downloading Patcher", "Verifying cached patcher ...", progressStyle: ProgressStyle.Indeterminate);
|
||||
|
||||
if (DownloadCacheHelper.CheckCache("patcher.zip", _expectedPatcherHash, out var cacheFile))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user