public static async Task DoDownloadAndInstallProcDump(IProgress <int> progress = null, CancellationToken ct = default(CancellationToken)) { //Download File progress?.Report(5); const string downloadLink = @"https://download.sysinternals.com/files/Procdump.zip"; var tempFileName = Path.GetTempFileName(); try { var downloadFileAsync = new SimpleFileDownloader(downloadLink, tempFileName); if (progress != null) { downloadFileAsync.ProgressChanged += (sender, args) => { progress.Report(Convert.ToInt32(Math.Floor(70 * (downloadFileAsync.DownloadProgress / 100)))); } } ; await downloadFileAsync.DownloadAsync(ct); } catch (AggregateException) { if (File.Exists(tempFileName)) { File.Delete(tempFileName); } throw; } //Extract File progress?.Report(65); Progress <double> extractProgress = null; if (progress != null) { extractProgress = new Progress <double>(); extractProgress.ProgressChanged += (o, ea) => { progress.Report(70 + Convert.ToInt32(Math.Floor(20 * (ea / 100)))); }; } var tempDir = Path.Combine(Path.GetTempPath(), "Celeste_Launcher_ProcDump"); if (Directory.Exists(tempDir)) { Misc.CleanUpFiles(tempDir, "*.*"); } try { await ZipUtils.ExtractZipFile(tempFileName, tempDir); } catch (AggregateException) { Misc.CleanUpFiles(tempDir, "*.*"); throw; } finally { if (File.Exists(tempFileName)) { File.Delete(tempFileName); } } //Move File progress?.Report(90); var destinationDir = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar; try { Misc.MoveFiles(tempDir, destinationDir); } finally { Misc.CleanUpFiles(tempDir, "*.*"); } // progress?.Report(100); }
public static async Task DownloadAndInstallUpdate(bool isSteam = false, IProgress <int> progress = null, CancellationToken ct = default(CancellationToken)) { Misc.CleanUpFiles(Directory.GetCurrentDirectory(), "*.old"); var gitVersion = await GetGitHubVersion().ConfigureAwait(false); progress?.Report(3); if (gitVersion <= Assembly.GetExecutingAssembly().GetName().Version) { return; } ct.ThrowIfCancellationRequested(); const string zipName = "Celeste_Launcher.zip"; var downloadLink = $"{ReleaseZipUrl}{gitVersion}/{zipName}"; //Download File progress?.Report(5); var tempFileName = Path.GetTempFileName(); try { var downloadFileAsync = new SimpleFileDownloader(downloadLink, tempFileName); if (progress != null) { downloadFileAsync.ProgressChanged += (sender, args) => { progress.Report(Convert.ToInt32(Math.Floor(70 * (downloadFileAsync.DownloadProgress / 100)))); } } ; await downloadFileAsync.DownloadAsync(ct); } catch (AggregateException) { if (File.Exists(tempFileName)) { File.Delete(tempFileName); } throw; } //Extract File progress?.Report(65); Progress <double> extractProgress = null; if (progress != null) { extractProgress = new Progress <double>(); extractProgress.ProgressChanged += (o, ea) => { progress.Report(70 + Convert.ToInt32(Math.Floor(20 * (ea / 100)))); }; } var tempDir = Path.Combine(Path.GetTempPath(), $"Celeste_Launcher_v{gitVersion}"); if (Directory.Exists(tempDir)) { Misc.CleanUpFiles(tempDir, "*.*"); } try { await ZipUtils.ExtractZipFile(tempFileName, tempDir, ct, null, extractProgress); } catch (AggregateException) { Misc.CleanUpFiles(tempDir, "*.*"); throw; } finally { if (File.Exists(tempFileName)) { File.Delete(tempFileName); } } //Move File progress?.Report(90); var destinationDir = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar; try { Misc.MoveFiles(tempDir, destinationDir); } finally { Misc.CleanUpFiles(tempDir, "*.*"); } //isSteam Version if (isSteam) { progress?.Report(95); Steam.ConvertToSteam(destinationDir); } //Clean Old File progress?.Report(97); Misc.CleanUpFiles(Directory.GetCurrentDirectory(), "*.old"); // progress?.Report(100); }