Esempio n. 1
0
        private static void DecompressMod(string objPath, List <string> chunk, ConcurrentDictionary <string, MemoryStream> streams)
        {
            // Create a FileStream with the following arguments to be able to have multiple threads access it
            using (FileStream fileStream = new FileStream(objPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                using (SevenZipExtractor extractor = new SevenZipExtractor(fileStream)) {
                    _decompressTotalFiles += chunk.Count;             // Counts the number of items that need to be loaded for accurate progress bar
                    foreach (var fileName in chunk)
                    {
                        LoadStep.UpdateProgress((float)_decompressTasksCompleted / _decompressTotalFiles);                 // Sets the progress bar
                        // If the extension is not valid, skip the file
                        string extension = Path.GetExtension(fileName);
                        if (!(extension == ".ini" || extension == ".cs" || extension == ".png" || extension == ".dll" || extension == ".obj"))
                        {
                            continue;
                        }

                        // Create a MemoryStream and extract the file
                        MemoryStream stream = new MemoryStream();
                        extractor.ExtractFile(fileName, stream);
                        stream.Position = 0;
                        streams.TryAdd(fileName, stream);

                        // Increments the number of tasks completed for accurate progress display
                        _decompressTasksCompleted++;
                    }
                }
        }
Esempio 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);
     }
 }