internal async void RW_CrawlingComplete() { crawlingComplete = true; Dispatcher.Invoke(() => { DownloadMissing.IsEnabled = false; ScanRailworks.IsEnabled = false; TotalProgress.Value = 100; TotalProgress.IsIndeterminate = true; }); HashSet <string> globalDeps = new HashSet <string>(); try { for (int i = 0; i < RW.Routes.Count; i++) { RW.Routes[i].AllDependencies = RW.Routes[i].Dependencies.Union(RW.Routes[i].ScenarioDeps).ToArray(); globalDeps.UnionWith(RW.Routes[i].AllDependencies); } HashSet <string> existing = await RW.GetMissing(globalDeps); globalDeps.ExceptWith(existing); HashSet <string> downloadable = await PM.GetDownloadableDependencies(globalDeps, existing, this); HashSet <string> paid = await PM.GetPaidDependencies(globalDeps); RW.Routes.Sort(delegate(RouteInfo x, RouteInfo y) { return(x.AllDependencies.Length.CompareTo(y.AllDependencies.Length)); }); // BUG: NullReferenceException int maxThreads = Math.Min(Environment.ProcessorCount, RW.Routes.Count); Parallel.For(0, maxThreads, workerId => { int max = RW.Routes.Count * (workerId + 1) / maxThreads; for (int i = RW.Routes.Count * workerId / maxThreads; i < max; i++) { List <Dependency> deps = new List <Dependency>(); int _i = ((i & 1) != 0) ? (i - 1) / 2 : (RW.Routes.Count - 1) - i / 2; for (int j = 0; j < RW.Routes[_i].AllDependencies.Length; j++) { string dep = RW.Routes[_i].AllDependencies[j]; if (dep != string.Empty) { bool isRoute = RW.Routes[_i].Dependencies.Contains(dep); bool isScenario = RW.Routes[_i].ScenarioDeps.Contains(dep); DependencyState state = DependencyState.Unknown; if (existing.Contains(dep)) { state = DependencyState.Downloaded; } else if (downloadable.Contains(dep)) { state = DependencyState.Available; } else if (paid.Contains(dep)) { state = DependencyState.Paid; } else { state = DependencyState.Unavailable; } deps.Add(new Dependency(dep, state, isScenario, isRoute)); } } RW.Routes[_i].AllDependencies = null; RW.Routes[_i].ParsedDependencies = new DependenciesList(deps); RW.Routes[_i].Redraw(); } }); loadingComplete = true; Dispatcher.Invoke(() => { TotalProgress.IsIndeterminate = false; if (downloadable.Count + PM.PkgsToDownload.Count > 0) { DownloadMissing.IsEnabled = true; } ScanRailworks.IsEnabled = true; ScanRailworks.Content = "Rescan assets..."; }); } catch (Exception e) { if (e.GetType() != typeof(ThreadInterruptedException) && e.GetType() != typeof(ThreadAbortException)) { Trace.Assert(false, e.ToString()); } } new Task(() => { PM.RunQueueWatcher(); }).Start(); }
internal void RW_CrawlingComplete() { crawlingComplete = true; PM.StopMSMQ = true; Dispatcher.Invoke(() => { DownloadMissing.IsEnabled = false; ScanRailworks.IsEnabled = false; TotalProgress.Value = 100; TotalProgress.IsIndeterminate = true; }); try { for (int i = 0; i < RW.Routes.Count; i++) { RW.Routes[i].AllDependencies = RW.Routes[i].Dependencies.Union(RW.Routes[i].ScenarioDeps).ToArray(); RW.AllRequiredDeps.UnionWith(RW.Routes[i].AllDependencies); } RW.Routes.Sort(delegate(RouteInfo x, RouteInfo y) { return(x.AllDependencies.Length.CompareTo(y.AllDependencies.Length)); }); // BUG: NullReferenceException RW.getAllInstalledDepsEvent.WaitOne(); RW.AllMissingDeps = RW.AllRequiredDeps.Except(RW.AllInstalledDeps); PM.GetPackagesToDownload(RW.AllMissingDeps); dlcReportFinishedHandler.WaitOne(); int maxThreads = Math.Min(Environment.ProcessorCount, RW.Routes.Count); Parallel.For(0, maxThreads, workerId => { int max = RW.Routes.Count * (workerId + 1) / maxThreads; for (int i = RW.Routes.Count * workerId / maxThreads; i < max; i++) { List <Dependency> deps = new List <Dependency>(); int _i = ((i & 1) != 0) ? (i - 1) / 2 : (RW.Routes.Count - 1) - i / 2; for (int j = 0; j < RW.Routes[_i].AllDependencies.Length; j++) { string dep = RW.Routes[_i].AllDependencies[j]; if (dep != string.Empty) { bool isRoute = RW.Routes[_i].Dependencies.Contains(dep); bool isScenario = RW.Routes[_i].ScenarioDeps.Contains(dep); int?pkgId = null; DependencyState state = DependencyState.Unknown; if (RW.AllInstalledDeps.Contains(dep)) { state = DependencyState.Downloaded; if (PM.DownloadableDeps.Contains(dep)) { pkgId = PM.DownloadableDepsPackages[dep]; } else if (PM.DownloadablePaidDeps.Contains(dep)) { pkgId = PM.DownloadablePaidDepsPackages[dep]; } //pkgId = PM.CachedPackages.FirstOrDefault(x => x.FilesContained.Contains(dep))?.PackageId; } else if (PM.DownloadableDeps.Contains(dep)) { state = DependencyState.Available; pkgId = PM.DownloadableDepsPackages[dep]; } else if (PM.DownloadablePaidDeps.Contains(dep)) { state = DependencyState.Paid; pkgId = PM.DownloadablePaidDepsPackages[dep]; } else { state = DependencyState.Unavailable; } deps.Add(new Dependency(dep, state, isScenario, isRoute, pkgId)); } } RW.Routes[_i].AllDependencies = null; RW.Routes[_i].ParsedDependencies = new DependenciesList(deps); RW.Routes[_i].Redraw(); } }); loadingComplete = true; Dispatcher.Invoke(() => { TotalProgress.IsIndeterminate = false; PM.StopMSMQ = false; ScanRailworks.IsEnabled = true; ScanRailworks.Content = Localization.Strings.MainRescan; }); } catch (Exception e) { if (e.GetType() != typeof(ThreadInterruptedException) && e.GetType() != typeof(ThreadAbortException)) { Trace.Assert(false, e.ToString()); } } new Task(async() => { await PM.ResolveConflicts(); PM.CheckUpdates(); Dispatcher.Invoke(() => { if (PM.PkgsToDownload.Count > 0) { DownloadMissing.IsEnabled = true; } }); PM.RunQueueWatcher(); }).Start(); }