public void FileWork_Complate(object sender, RunWorkerCompletedEventArgs e) { ExtrectFileWorker kWorker = sender as ExtrectFileWorker; if (e.Cancelled == false && e.Error == null) { /* * bool bIsNew; * Mutex kMutex = new Mutex(false, "FileWork_Complate", out bIsNew); * kMutex.WaitOne(); * Console.Write("\r FileExtract: " + kWorker.m_nOwerIndex + " / " + kWorker.m_nTotal + " Done!!"); * kMutex.ReleaseMutex(); * kMutex = null; */ } else { bool bIsNew; Mutex kMutex = new Mutex(false, "FileWork_Complate", out bIsNew); kMutex.WaitOne(); Console.Write("\r Error!!" + e.Error.ToString()); kMutex.ReleaseMutex(); kMutex = null; } { bool bIsNew; Mutex kMutex = new Mutex(false, "FileWork_Complate", out bIsNew); kMutex.WaitOne(); m_nThreadCount--; kMutex.ReleaseMutex(); kMutex = null; } }
public void dataextract_SeperateFile(object sender, DoWorkEventArgs e) { ExtrectFileWorker kFileWorker = sender as ExtrectFileWorker; if (kFileWorker == null) { return; } BNSDat.ExtrectFile(kFileWorker.m_kFileStream, kFileWorker.m_kFile, kFileWorker.m_kFilePath); }
public void ExtractMultiThread(string FileName, Action <int, int, char> processedEvent, bool is64 = false) { if (m_nThreadCount != 0) { Console.Write("\rIt' Processing!!"); return; } long nTick = DateTime.Now.Ticks; m_nThreadCount = 0; FileStream fs = new FileStream(FileName, FileMode.Open); BinaryReader br = new BinaryReader(fs); string file_path; byte[] buffer_packed; byte[] Signature = br.ReadBytes(8); uint Version = br.ReadUInt32(); byte[] Unknown_001 = br.ReadBytes(5); int FileDataSizePacked = is64 ? (int)br.ReadInt64() : br.ReadInt32(); int FileCount = is64 ? (int)br.ReadInt64() : br.ReadInt32(); bool IsCompressed = br.ReadByte() == 1; bool IsEncrypted = br.ReadByte() == 1; byte[] Unknown_002 = br.ReadBytes(62); int FileTableSizePacked = is64 ? (int)br.ReadInt64() : br.ReadInt32(); int FileTableSizeUnpacked = is64 ? (int)br.ReadInt64() : br.ReadInt32(); buffer_packed = br.ReadBytes(FileTableSizePacked); int OffsetGlobal = is64 ? (int)br.ReadInt64() : br.ReadInt32(); OffsetGlobal = (int)br.BaseStream.Position; // don't trust value, read current stream location. byte[] FileTableUnpacked = Unpack(buffer_packed, FileTableSizePacked, FileTableSizePacked, FileTableSizeUnpacked, IsEncrypted, IsCompressed); buffer_packed = null; MemoryStream ms = new MemoryStream(FileTableUnpacked); BinaryReader br2 = new BinaryReader(ms); for (int i = 0; i < FileCount; i++) { BPKG_FTE FileTableEntry = new BPKG_FTE(); FileTableEntry.FilePathLength = is64 ? (int)br2.ReadInt64() : br2.ReadInt32(); FileTableEntry.FilePath = Encoding.Unicode.GetString(br2.ReadBytes(FileTableEntry.FilePathLength * 2)); FileTableEntry.Unknown_001 = br2.ReadByte(); FileTableEntry.IsCompressed = br2.ReadByte() == 1; FileTableEntry.IsEncrypted = br2.ReadByte() == 1; FileTableEntry.Unknown_002 = br2.ReadByte(); FileTableEntry.FileDataSizeUnpacked = is64 ? (int)br2.ReadInt64() : br2.ReadInt32(); FileTableEntry.FileDataSizeSheared = is64 ? (int)br2.ReadInt64() : br2.ReadInt32(); FileTableEntry.FileDataSizeStored = is64 ? (int)br2.ReadInt64() : br2.ReadInt32(); FileTableEntry.FileDataOffset = (is64 ? (int)br2.ReadInt64() : br2.ReadInt32()) + OffsetGlobal; FileTableEntry.Padding = br2.ReadBytes(60); // unlimit thread count /* * while (m_nThreadCount > 10) * { * * } */ { bool bIsNew; Mutex kMutex = new Mutex(false, "FileWork_Complate", out bIsNew); kMutex.WaitOne(); m_nThreadCount++; kMutex.ReleaseMutex(); kMutex = null; } file_path = string.Format("{0}.files\\{1}", FileName, FileTableEntry.FilePath); ExtrectFileWorker kWorker = new ExtrectFileWorker(fs, FileTableEntry, file_path, (i + 1), FileCount); kWorker.WorkerSupportsCancellation = true; kWorker.WorkerReportsProgress = true; kWorker.RunWorkerCompleted += FileWork_Complate; kWorker.RunWorkerAsync(); processedEvent((i + 1), FileCount, '\0'); } Console.Write("\rWaiting Processing..."); int nRotatingCount = 0; int nRotatingIndex = 0; char [] cRotatingArray = { '/', '-', '\\', '|' }; // wait Processing while (m_nThreadCount != 0) { nRotatingIndex = nRotatingCount % 4; processedEvent(m_nThreadCount, nRotatingIndex, cRotatingArray[nRotatingIndex]); nRotatingCount++; Thread.Sleep(100); } processedEvent(m_nThreadCount, nRotatingIndex, cRotatingArray[nRotatingIndex]); br2.Close(); ms.Close(); br2 = null; ms = null; br.Close(); fs.Close(); br = null; fs = null; nTick = DateTime.Now.Ticks - nTick; TimeSpan elapsedSpan = new TimeSpan(nTick); Console.Write("\rComplate time :" + elapsedSpan.TotalMilliseconds + "ms"); }