void bw_MinifyArchiveWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker bw = (BackgroundWorker)sender; RAFArchive archive = (RAFArchive)e.Argument; Console.WriteLine("Minifying Archive: " + archive.GetID()); //Create temporary dat file Console.WriteLine("-> Creating temporary file"); string tempDatFilePath = archive.RAFFilePath + ".dat.temp"; FileStream datFs = File.Create(tempDatFilePath); Console.WriteLine("-> Begin Writing New Entries"); List <RAFFileListEntry> entries = archive.GetDirectoryFile().GetFileList().GetFileEntries(); for (int i = 0; i < entries.Count; i++) { //Report progress to main thread if ((i % 100) == 0) { bw.ReportProgress((int)(i * 100 / entries.Count), entries[i].FileName); } byte[] rawContent = entries[i].GetRawContent(); datFs.Write(rawContent, 0, rawContent.Length); } Console.WriteLine(" ->Done"); Console.WriteLine("-> Delete old Archive File... (Closing File Stream)"); archive.GetDataFileContentStream().Close(); //First we close the old .dat file stream, so we can replace the unowned file Console.WriteLine(" Stream Closed... Now deleting old DAT file"); File.Delete(archive.RAFFilePath + ".dat"); Console.WriteLine(" Move Replacement DAT File..."); File.Move(tempDatFilePath, archive.RAFFilePath + ".dat"); Console.WriteLine("-> Generate new Archive Directory File (*.raf)."); archive.SaveDirectoryFile(); Console.WriteLine("-> Done"); }
void bw_AnalyzeArchiveWorker_DoWork(object sender, DoWorkEventArgs e) { Console.WriteLine("Analyzing - doing work"); BackgroundWorker bw = (BackgroundWorker)sender; RAFArchive[] archives = (RAFArchive[])e.Argument; TimeSpan updateInterval = new TimeSpan(0, 0, 0, 0, 100); DateTime lastUpdate = DateTime.Now - updateInterval; long bytesWasted = 0; Console.WriteLine("Enter for. Archives count: " + archives.Length); for (int i = 0; i < archives.Length; i++) { RAFArchive archive = archives[i]; long archiveBytesUsed = 0; //We add to this each time, then find out how many bytes could have been saved. List <RAFFileListEntry> entries = archive.GetDirectoryFile().GetFileList().GetFileEntries(); Console.WriteLine("Analyzing Archive: " + archive.GetID() + "; " + entries.Count + " entries"); for (int j = 0; j < entries.Count; j++) { //Console.WriteLine(" " + j); //Report progress to main thread if (j % 100 == 0) { bw.ReportProgress(0, new long[] { j, i, bytesWasted }); lastUpdate = DateTime.Now; } //Console.WriteLine(" !"); archiveBytesUsed += entries[j].FileSize; } bytesWasted += new FileInfo(archive.RAFFilePath + ".dat").Length - archiveBytesUsed; Console.WriteLine("Current Bytes Wasted: " + bytesWasted); } }