/// <summary> /// Initializes the NXMWorker pipe listener. /// </summary> private void InitializeDownloadHandle() { if (NoMissingMods) { return; } var nexusProtocol = new NexusProtocol(); // Start capturing piped messages from the NXMWorker, handle any progress reports. nexusProtocol.StartRecievingProtocolValues(new Progress <CaptureProtocolValuesProgress>(async x => { var matchingMods = MissingMods.Where(y => y.NexusModId == x.ModId); if (!matchingMods.Any()) { return; } var matchingMod = matchingMods.First(); if (matchingMod != null) { WindowNotificationControls.MoveToFront(); // Start downloading the mod file. await NexusMod.DownloadModFile(matchingMod, x.FileId, new Progress <DownloadModFileProgress>(downloadProgress => { MissingMods[MissingMods.IndexOf(matchingMod)].CurrentDownloadPercentage = downloadProgress.CurrentDownloadPercentage; if (downloadProgress.IsDownloadComplete) { Modpack.UpdateModArchivePaths(matchingMod, downloadProgress.DownloadLocation); MissingMods.Remove(matchingMod); NoMissingMods = MissingMods.Count == 0; } })); } })); }
private async void FindAndValidateModFile(Mod currentMod) { var fileBrowser = new OpenFileDialog() { Title = $"Find {currentMod.ModName} | {currentMod.FileName}", InitialDirectory = "Downloads", Filter = "Mod Archive (*.zip;*.7zip;*.7z;*.rar;*.gzip)|*.zip;*.7zip;*.7z;*.rar;*.gzip", }; if (fileBrowser.ShowDialog() != DialogResult.OK) { return; } var archivePath = fileBrowser.FileName; var validationResult = false; MissingMods.Where(x => x == currentMod).First().IsIndeterminateProcess = true; await Task.Factory.StartNew(() => { validationResult = Validation.IsMatchingModArchive(currentMod, archivePath).Result; }); if (validationResult) { MissingMods.Where(x => x == currentMod).First().IsIndeterminateProcess = false; MissingMods.Remove(currentMod); NoMissingMods = MissingMods.Count == 0; } else { MissingMods.Where(x => x == currentMod).First().IsIndeterminateProcess = false; } // Show in UI }