/// <summary> /// Reads or builds and reads Remote Client & Reference Client & Installed Client File List /// </summary> /// <returns>awaitable Task</returns> public Task Setup() { return(Task.Run(() => { RemoteClient.Setup().Wait(); ExistingClient.Setup().Wait(); InstalledClient.Setup().Wait(); Install().Wait(); OnCompleted?.Invoke(); })); }
/// <summary> /// Verify files of the installed client. Undo's every change the user performed, such as edits and restores deleted files. /// </summary> /// <returns>awaitable task</returns> public Task VerifyClient(bool deleteRedundantFiles = false) { return(Task.Run(() => { var fileList = Path.Combine(InstalledClient.Path, "FileList.ini"); if (File.Exists(fileList)) { File.Delete(fileList); } InstalledClient.Setup().Wait(); InstalledClient.WriteList(); fileList = Path.Combine(ExistingClient.Path, "FileList.ini"); if (File.Exists(fileList)) { File.Delete(fileList); } ExistingClient.Setup().Wait(); ExistingClient.WriteList(); Install().Wait(); foreach (var checksum in RemoteClient.Checksums) { InstalledClient.Checksums.TryRemove(checksum.Key, out string ignored); } if (deleteRedundantFiles) { OnFileChange?.Invoke($"Removing {InstalledClient.Checksums.Count} Orphaned Files"); foreach (var checksum in InstalledClient.Checksums) { var path = Path.Combine(InstalledClient.Path, checksum.Key); if (File.Exists(path)) { File.Delete(path); } } InstalledClient.Checksums.Clear(); foreach (var checksum in RemoteClient.Checksums) { InstalledClient.Checksums.AddOrUpdate(checksum.Key, checksum.Value); } InstalledClient.WriteList(); } OnCompleted?.Invoke(); })); }
private Task DownloadFiles() { return(Task.Run(() => { var resetevent = new AutoResetEvent(true); var counter = 0; var fileCount = DownloadQueue.Count; while (DownloadQueue.Count > 0) { var file = DownloadQueue.Dequeue(); counter++; if (!Directory.Exists(Path.GetDirectoryName(Path.Combine(InstalledClient.Path, file)))) { Directory.CreateDirectory(Path.GetDirectoryName(Path.Combine(InstalledClient.Path, file))); } OnFileChange?.Invoke($"Downloading {counter}/{fileCount} - {((double) counter/fileCount*100.0).ToString("F")}%"); using (var client = new WebClient()) { client.DownloadProgressChanged += (sender, args) => OnDownloadProgressChange?.Invoke(args.ProgressPercentage); var counter1 = counter; client.DownloadFileCompleted += (sender, args) => { var checksum = Checksum.GetFor(Path.Combine(InstalledClient.Path, file)); InstalledClient.Checksums.AddOrUpdate(file, checksum); OnTotalProgressChange?.Invoke((double)counter1 / fileCount * 100.0); resetevent.Set(); }; client.DownloadFileAsync(new Uri("http://alumni.votc.xyz/Downloads/Conquer/SelectiveDeploy/Client/" + file), Path.Combine(InstalledClient.Path, file)); resetevent.WaitOne(); } } OnFileChange?.Invoke("Finished Downloading Files!"); OnTotalProgressChange?.Invoke(100); OnDownloadProgressChange?.Invoke(100); InstalledClient.WriteList(); OnCompleted?.Invoke(); })); }