Ejemplo n.º 1
0
        private static async Task <IEnumerable <string> > DoExtract(IEnumerable <FileEntry> files, IProgress <ProgressRecord> progress, CancellationToken ct)
        {
            progress.Report(new ProgressRecord("Determining reading order", 0, 0));
            var toProcess = BuildWorklist(files);

            var overallResults = new HashSet <string>();

            if (ct.IsCancellationRequested)
            {
                return(overallResults);
            }

            int total = toProcess.Count;
            int done  = 0;

            foreach (var(bundleName, fileList) in toProcess)
            {
                if (ct.IsCancellationRequested)
                {
                    return(overallResults);
                }

                progress.Report(new ProgressRecord($"Scanning bundles for names", total, done));
                done++;

                string bundle_path = Path.Combine(Utils.CurrentWindow.AssetsDir, bundleName + ".bundle");
                if (!File.Exists(bundle_path))
                {
                    Console.WriteLine("Bundle: {0}, does not exist!", bundle_path);
                    continue;
                }

                var pendingResults = new List <Task <IEnumerable <string> > >();

                using var fs = new FileStream(bundle_path, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true);

                foreach (var(file, packageEntry) in fileList)
                {
                    if (packageEntry.Length != 0)
                    {
                        pendingResults.Add(AnalyzeFileInPackage(file, packageEntry, fs, ct));
                    }
                    else
                    {
                        pendingResults.Add(Task.FromResult(Enumerable.Empty <string>()));
                    }
                }
                var results = await Task.WhenAll(pendingResults);

                overallResults.UnionWith(results.SelectMany(i => i));
            }
            return(overallResults);
        }