bool Dump(CueBin cueBin, string directoryTo, CueBinPrefs prefs) { ProgressReport pr = new ProgressReport(); Thread workThread = new Thread(() => { cueBin.Dump(directoryTo, prefs, pr); }); ProgressDialog pd = new ProgressDialog(pr); pd.Show(this); this.Enabled = false; workThread.Start(); for (; ; ) { Application.DoEvents(); Thread.Sleep(10); if (workThread.ThreadState != ThreadState.Running) break; pd.Update(); } this.Enabled = true; pd.Dispose(); return !pr.CancelSignal; }
public void Dump(string directory, CueBinPrefs prefs, ProgressReport progress) { byte[] subcodeTemp = new byte[96]; progress.TaskCount = 2; progress.Message = "Generating Cue"; progress.ProgressEstimate = 1; progress.ProgressCurrent = 0; progress.InfoPresent = true; string cuePath = Path.Combine(directory, baseName + ".cue"); if (prefs.DumpToBitbucket) { } else File.WriteAllText(cuePath, cue); progress.Message = "Writing bin(s)"; progress.TaskCurrent = 1; progress.ProgressEstimate = bins.Sum(bfd => bfd.abas.Count); progress.ProgressCurrent = 0; if(!prefs.ReallyDumpBin) return; foreach (var bfd in bins) { int sectorSize = bfd.SectorSize; byte[] temp = new byte[2352]; byte[] empty = new byte[2352]; string trackBinFile = bfd.name; string trackBinPath = Path.Combine(directory, trackBinFile); string subQPath = Path.ChangeExtension(trackBinPath, ".sub.q"); Stream fsSubQ = null; Stream fs; if(prefs.DumpToBitbucket) fs = Stream.Null; else fs = new FileStream(trackBinPath, FileMode.Create, FileAccess.Write, FileShare.None); try { if (prefs.DumpSubchannelQ) if (prefs.DumpToBitbucket) fsSubQ = Stream.Null; else fsSubQ = new FileStream(subQPath, FileMode.Create, FileAccess.Write, FileShare.None); for (int i = 0; i < bfd.abas.Count; i++) { if (progress.CancelSignal) return; progress.ProgressCurrent++; int aba = bfd.abas[i]; if (bfd.aba_zeros[i]) { fs.Write(empty, 0, sectorSize); } else { if (sectorSize == 2352) disc.ReadABA_2352(aba, temp, 0); else if (sectorSize == 2048) disc.ReadABA_2048(aba, temp, 0); else throw new InvalidOperationException(); fs.Write(temp, 0, sectorSize); //write subQ if necessary if (fsSubQ != null) { disc.Sectors[aba].SubcodeSector.ReadSubcodeDeinterleaved(subcodeTemp, 0); fsSubQ.Write(subcodeTemp, 12, 12); } } } } finally { fs.Dispose(); if (fsSubQ != null) fsSubQ.Dispose(); } } }
//NOT SUPPORTED RIGHT NOW //public string CreateRedumpReport() //{ // if (disc.TOC.Sessions[0].Tracks.Count != bins.Count) // throw new InvalidOperationException("Cannot generate redump report on CueBin lacking OneBinPerTrack property"); // StringBuilder sb = new StringBuilder(); // for (int i = 0; i < disc.TOC.Sessions[0].Tracks.Count; i++) // { // var track = disc.TOC.Sessions[0].Tracks[i]; // var bfd = bins[i]; // //dump the track // byte[] dump = new byte[track.length_aba * 2352]; // //TODO ????????? post-ABA unknown // //for (int aba = 0; aba < track.length_aba; aba++) // // disc.ReadLBA_2352(bfd.lbas[lba],dump,lba*2352); // string crc32 = string.Format("{0:X8}", CRC32.Calculate(dump)); // string md5 = Util.Hash_MD5(dump, 0, dump.Length); // string sha1 = Util.Hash_SHA1(dump, 0, dump.Length); // int pregap = track.Indexes[1].lba - track.Indexes[0].lba; // Timestamp pregap_ts = new Timestamp(pregap); // Timestamp len_ts = new Timestamp(track.length_lba); // sb.AppendFormat("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\n", // i, // Cue.RedumpTypeStringForTrackType(track.TrackType), // pregap_ts.Value, // len_ts.Value, // track.length_lba, // track.length_lba*Cue.BINSectorSizeForTrackType(track.TrackType), // crc32, // md5, // sha1 // ); // } // return sb.ToString(); //} public void Dump(string directory, CueBinPrefs prefs) { ProgressReport pr = new ProgressReport(); Dump(directory, prefs, pr); }
public void Dump(string directory, CueBinPrefs prefs, ProgressReport progress) { byte[] subcodeTemp = new byte[96]; progress.TaskCount = 2; progress.Message = "Generating Cue"; progress.ProgressEstimate = 1; progress.ProgressCurrent = 0; progress.InfoPresent = true; string cuePath = Path.Combine(directory, baseName + ".cue"); if (prefs.DumpToBitbucket) { } else { File.WriteAllText(cuePath, cue); } progress.Message = "Writing bin(s)"; progress.TaskCurrent = 1; progress.ProgressEstimate = bins.Sum(bfd => bfd.abas.Count); progress.ProgressCurrent = 0; if (!prefs.ReallyDumpBin) { return; } foreach (var bfd in bins) { int sectorSize = bfd.SectorSize; byte[] temp = new byte[2352]; byte[] empty = new byte[2352]; string trackBinFile = bfd.name; string trackBinPath = Path.Combine(directory, trackBinFile); string subQPath = Path.ChangeExtension(trackBinPath, ".sub.q"); Stream fsSubQ = null; Stream fs; if (prefs.DumpToBitbucket) { fs = Stream.Null; } else { fs = new FileStream(trackBinPath, FileMode.Create, FileAccess.Write, FileShare.None); } try { if (prefs.DumpSubchannelQ) { if (prefs.DumpToBitbucket) { fsSubQ = Stream.Null; } else { fsSubQ = new FileStream(subQPath, FileMode.Create, FileAccess.Write, FileShare.None); } } for (int i = 0; i < bfd.abas.Count; i++) { if (progress.CancelSignal) { return; } progress.ProgressCurrent++; int aba = bfd.abas[i]; if (bfd.aba_zeros[i]) { fs.Write(empty, 0, sectorSize); } else { if (sectorSize == 2352) { disc.ReadABA_2352(aba, temp, 0); } else if (sectorSize == 2048) { disc.ReadABA_2048(aba, temp, 0); } else { throw new InvalidOperationException(); } fs.Write(temp, 0, sectorSize); //write subQ if necessary if (fsSubQ != null) { disc.Sectors[aba].SubcodeSector.ReadSubcodeDeinterleaved(subcodeTemp, 0); fsSubQ.Write(subcodeTemp, 12, 12); } } } } finally { fs.Dispose(); if (fsSubQ != null) { fsSubQ.Dispose(); } } } }
//NOT SUPPORTED RIGHT NOW //public string CreateRedumpReport() //{ // if (disc.TOC.Sessions[0].Tracks.Count != bins.Count) // throw new InvalidOperationException("Cannot generate redump report on CueBin lacking OneBinPerTrack property"); // StringBuilder sb = new StringBuilder(); // for (int i = 0; i < disc.TOC.Sessions[0].Tracks.Count; i++) // { // var track = disc.TOC.Sessions[0].Tracks[i]; // var bfd = bins[i]; // //dump the track // byte[] dump = new byte[track.length_aba * 2352]; // //TODO ????????? post-ABA unknown // //for (int aba = 0; aba < track.length_aba; aba++) // // disc.ReadLBA_2352(bfd.lbas[lba],dump,lba*2352); // string crc32 = string.Format("{0:X8}", CRC32.Calculate(dump)); // string md5 = Util.Hash_MD5(dump, 0, dump.Length); // string sha1 = Util.Hash_SHA1(dump, 0, dump.Length); // int pregap = track.Indexes[1].lba - track.Indexes[0].lba; // Timestamp pregap_ts = new Timestamp(pregap); // Timestamp len_ts = new Timestamp(track.length_lba); // sb.AppendFormat("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\n", // i, // Cue.RedumpTypeStringForTrackType(track.TrackType), // pregap_ts.Value, // len_ts.Value, // track.length_lba, // track.length_lba*Cue.BINSectorSizeForTrackType(track.TrackType), // crc32, // md5, // sha1 // ); // } // return sb.ToString(); //} public void Dump(string directory, CueBinPrefs prefs) { ProgressReport pr = new ProgressReport(); Dump(directory, prefs, pr); }
public ProgressDialog(ProgressReport pr) { InitializeComponent(); this.pr = pr; }