Ejemplo n.º 1
0
        private static int _decompressTotalFiles;         // Total number of items that need to be decompressed

        internal static void DecompressMod(string objPath, ConcurrentDictionary <string, MemoryStream> streams)
        {
            LoadStep.UpdateSubProgressText("Decompressing");

            SevenZipExtractor extractor = new SevenZipExtractor(objPath);

            List <string> fileNames  = extractor.ArchiveFileNames.ToList();
            double        numThreads = Math.Min((double)ModContent.GetInstance <LoadConfig>().NumThreads, fileNames.Count);

            List <Task> tasks = new List <Task>();

            // Split the files into numThreads chunks
            var chunks    = new List <List <string> >();
            int chunkSize = (int)Math.Round(fileNames.Count / numThreads, MidpointRounding.AwayFromZero);

            for (int i = 0; i < fileNames.Count; i += chunkSize)
            {
                chunks.Add(fileNames.GetRange(i, Math.Min(chunkSize, fileNames.Count - i)));
            }

            // Create tasks and decompress the chunks
            foreach (var chunk in chunks)
            {
                tasks.Add(Task.Run(() => DecompressMod(objPath, chunk, streams)));
            }

            // Wait for all tasks to finish
            Task.WaitAll(tasks.ToArray());

            extractor.Dispose();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// This is the second method that's called, and it calls <see cref="HandleFile"/> for every file that was added to <see cref="files"/> by <see cref="AddFiles"/><br/>
 /// Normally, there's no reason for you to call or override this method.
 /// </summary>
 public virtual void IterateFiles(int totalFiles)
 {
     foreach (string file in files)
     {
         LoadStep.UpdateSubProgressText(file);
         HandleFile(file);
         LoadStep.TaskCompletedCount++;
         LoadStep.UpdateProgress((float)LoadStep.TaskCompletedCount / totalFiles);
     }
 }