public async Task <HashSet <string> > GetDownloadableDependencies(HashSet <string> globalDependencies, HashSet <string> existing, MainWindow mw) { InstalledPackages = SqLiteAdapter.LoadInstalledPackages(); HashSet <string> allDownloadableDeps = await WebWrapper.QueryArray("listFiles"); HashSet <string> conflictDeps = existing.Intersect(allDownloadableDeps).Except(InstalledPackages.SelectMany(x => x.FilesContained)).ToHashSet(); HashSet <int> conflictPackages = new HashSet <int>(); int maxThreads = Math.Min(Environment.ProcessorCount, conflictDeps.Count); Parallel.For(0, maxThreads, workerId => { Task.Run(async() => { int max = conflictDeps.Count * (workerId + 1) / maxThreads; for (int i = conflictDeps.Count * workerId / maxThreads; i < max; i++) { List <int> packages = await FindFile(conflictDeps.ElementAt(i), false); Trace.Assert(packages.Count > 0, $"FindFile for {conflictDeps.ElementAt(i)} returned no packages!"); if (packages.Count > 0) { int id = packages.First(); lock (conflictPackages) { if (conflictPackages.Contains(id)) { continue; } conflictPackages.Add(id); } } } }).Wait(); }); bool rewriteAll = false; bool keepAll = false; for (int i = 0; i < conflictPackages.Count; i++) { int id = conflictPackages.ElementAt(i); if (Settings.Default.IgnoredPackages?.Contains(id) == true) { continue; } Package p = CachedPackages.FirstOrDefault(x => x.PackageId == id); bool rewrite = false; if (!rewriteAll && !keepAll) { Task <ContentDialogResult> t = null; mw.Dispatcher.Invoke(() => { MainWindow.ContentDialog = new ConflictPackageDialog(p.DisplayName); t = MainWindow.ContentDialog.ShowAsync(); }); ContentDialogResult result = await t; ConflictPackageDialog dlg = (ConflictPackageDialog)MainWindow.ContentDialog; rewrite = dlg.RewriteLocal; rewriteAll = dlg.RewriteAll; keepAll = dlg.KeepAll; } if (rewrite || rewriteAll) { PkgsToDownload.Add(id); HashSet <int> depsPkgs = new HashSet <int>(); await GetDependencies(new HashSet <int>() { id }, depsPkgs); PkgsToDownload.UnionWith(depsPkgs); } else { if (Settings.Default.IgnoredPackages == null) { Settings.Default.IgnoredPackages = new List <int>(); } Settings.Default.IgnoredPackages.Add(id); Settings.Default.Save(); } } CheckUpdates(); DownloadableDeps = allDownloadableDeps.Intersect(globalDependencies).ToHashSet(); return(DownloadableDeps); }
public async Task ResolveConflicts() { HashSet <string> conflictDeps = MainWindow.RW.AllInstalledDeps.Intersect(DownloadableDeps).Except(InstalledPackages.SelectMany(x => x.FilesContained)).ToHashSet(); HashSet <int> conflictPackages = new HashSet <int>(); while (conflictDeps.Count > 0) { Package pkg = CachedPackages.First(x => x.FilesContained.Contains(conflictDeps.First())); conflictPackages.Add(pkg.PackageId); conflictDeps.ExceptWith(pkg.FilesContained); } //HashSet<int> conflictPackages = conflictPkgs.Select(x => x.PackageId).ToHashSet(); bool rewriteAll = false; bool keepAll = false; for (int i = 0; i < conflictPackages.Count; i++) { int id = conflictPackages.ElementAt(i); if (Settings.Default.IgnoredPackages?.Contains(id) == true) { continue; } Package p = CachedPackages.FirstOrDefault(x => x.PackageId == id); bool rewrite = false; if (!rewriteAll && !keepAll) { Task <ContentDialogResult> t = null; MainWindow.Dispatcher.Invoke(() => { MainWindow.ContentDialog = new ConflictPackageDialog(p.DisplayName); t = MainWindow.ContentDialog.ShowAsync(); }); ContentDialogResult result = await t; ConflictPackageDialog dlg = (ConflictPackageDialog)MainWindow.ContentDialog; rewrite = dlg.RewriteLocal; rewriteAll = dlg.RewriteAll; keepAll = dlg.KeepAll; } if (rewrite || rewriteAll) { PkgsToDownload.Add(id); HashSet <int> depsPkgs = new HashSet <int>(); await GetDependencies(new HashSet <int>() { id }, depsPkgs); PkgsToDownload.UnionWith(depsPkgs); } else { if (Settings.Default.IgnoredPackages == null) { Settings.Default.IgnoredPackages = new List <int>(); } Settings.Default.IgnoredPackages.Add(id); Settings.Default.Save(); } } }