public void Explode(string dir, bool decompGZ, ExplodeProgressCallback epc) { explodeEvents[(int)ExplodeEvents.NotRunning].Reset(); Directory.CreateDirectory(decompGZ ? Path.Combine(dir, VolFile.DecompDir) : dir); outstandingRequests.Capacity = embeddedFiles.Count; int minNumThread, minNumCompThread; // we can handle more threads since we're mainly IO bound ThreadPool.GetMinThreads(out minNumThread, out minNumCompThread); ThreadPool.SetMinThreads(minNumThread * 2, minNumCompThread); foreach (EmbeddedFileInfo efi in embeddedFiles) { if (efi.fileAddress == 0) { string dirName = Path.Combine(dir, efi.name); if (decompGZ) { dirName += Path.DirectorySeparatorChar + VolFile.DecompDir; } DirectoryInfo di = Directory.CreateDirectory(dirName); DateTime dirDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(efi.dateTime); di.LastAccessTime = di.LastWriteTime = di.CreationTime = dirDate; //Directory.SetCreationTime(dirName, dirDate); //Directory.SetLastWriteTime(dirName, dirDate); //Directory.SetLastAccessTime(dirName, dirDate); } else if (!explodeEvents[(int)ExplodeEvents.Stop].WaitOne(0)) { ExtractSingleFile(efi, dir, decompGZ, false, epc); } else { break; } } ThreadPool.SetMinThreads(minNumThread, minNumCompThread); explodeEvents[(int)ExplodeEvents.NotRunning].Set(); }
public WorkUnit( string dir, EmbeddedFileInfo efiParam, VolFile volFile, bool decompGZ, ManualResetEvent compEvent, ExplodeProgressCallback epc ) { efi = efiParam; destFile = new FileStream( Path.Combine(dir, efi.name), FileMode.Create, FileAccess.ReadWrite, FileShare.None, 8192, false ); fileVolAddress = volFile.volMappingAddrAsNum + efi.fileAddress; shouldDecompAfter = (decompGZ && efi.name.EndsWith(".gz")); finishedHandle = compEvent; callback = epc; }
private void ExtractSingleFile(EmbeddedFileInfo efi, string dir, bool decompGZ, bool waitForCompletion, ExplodeProgressCallback epc) { ManualResetEvent finEvent = new ManualResetEvent(false); if (!waitForCompletion) { outstandingRequests.Add(finEvent); } WorkUnit unit = new WorkUnit(dir, efi, this, decompGZ, finEvent, epc); if (!ThreadPool.QueueUserWorkItem(new WaitCallback(ExtractCallback), unit)) { throw new ThreadInterruptedException("No Threadpool Threads"); } if (waitForCompletion) { finEvent.WaitOne(); finEvent.Close(); } }