private (string, string) ProcessCue(string file, string tempPath) { var filePath = Path.GetDirectoryName(file); var cueFiles = CueFileReader.Read(file); string srcToc = null; if (cueFiles.FileEntries.Count() > 1) { _notifier?.Notify(PopstationEventEnum.Info, $"Merging .bins..."); var mergedBin = MergeBins(file, cueFiles, tempPath); var cueFile = Path.Combine(tempPath, Path.GetFileNameWithoutExtension(mergedBin.Path) + ".cue"); CueFileWriter.Write(mergedBin.CueFile, cueFile); srcToc = cueFile; file = mergedBin.Path; tempFiles.Add(mergedBin.Path); tempFiles.Add(cueFile); } else { srcToc = file; file = Path.Combine(filePath, cueFiles.FileEntries.First().FileName); } return(file, srcToc); }
private void ExtractISO(PbpDiscEntry disc, string path, ExtractOptions extractInfo, CancellationToken cancellationToken) { try { disc.ProgressEvent += ProgressEvent; if (!ContinueIfFileExists(extractInfo, path)) { return; } Notify?.Invoke(PopstationEventEnum.Info, $"Writing {path}..."); Notify?.Invoke(PopstationEventEnum.GetIsoSize, disc.IsoSize); Notify?.Invoke(PopstationEventEnum.ExtractStart, disc.Index); var cueFilename = Path.GetFileNameWithoutExtension(path) + ".cue"; var dirPath = Path.GetDirectoryName(path); var cuePath = Path.Combine(dirPath, cueFilename); TempFiles.Add(path); TempFiles.Add(cuePath); using (var isoStream = new FileStream(path, FileMode.Create, FileAccess.Write)) { disc.CopyTo(isoStream, cancellationToken); } if (cancellationToken.IsCancellationRequested) { return; } TempFiles.Remove(path); if (!extractInfo.CreateCuesheet) { return; } var cueFile = TOCtoCUE(disc.TOC, Path.GetFileName(path)); CueFileWriter.Write(cueFile, cuePath); TempFiles.Remove(cuePath); Notify?.Invoke(PopstationEventEnum.ExtractComplete, null); } finally { disc.ProgressEvent -= ProgressEvent; } }
private void ConvertMultiToSingleBin_OnClick(object sender, RoutedEventArgs e) { var openFileDialog = new Ookii.Dialogs.Wpf.VistaOpenFileDialog(); openFileDialog.Filter = "Supported files|*.bin;*.cue|All files|*.*"; openFileDialog.Multiselect = true; var openResult = openFileDialog.ShowDialog(); if (!openResult.GetValueOrDefault(false)) { return; } var saveFileDialog = new Ookii.Dialogs.Wpf.VistaSaveFileDialog(); saveFileDialog.Filter = "Supported files|*.bin;"; saveFileDialog.DefaultExt = ".bin"; saveFileDialog.AddExtension = true; var saveResult = saveFileDialog.ShowDialog(); if (!saveResult.GetValueOrDefault(false)) { return; } bool generatedCue = false; string tempFile = ""; var trackRegex = new Regex("Track (\\d+)"); if (openFileDialog.FileNames.Length > 1) { if (!openFileDialog.FileNames.All(f => { var match = trackRegex.Match(f); return(Path.GetExtension(f).ToLower() == ".bin" && match.Success && int.TryParse(match.Groups[1].Value, out var dummy)); })) { MessageBox.Show(Window, "Please multi-select only .bins ending in (Track #)", "PSXPackager", MessageBoxButton.OK, MessageBoxImage.Information); return; } var cueFile = new CueFile(); var index = 1; foreach (var fileName in openFileDialog.FileNames.OrderBy(f => int.Parse(trackRegex.Match(f).Groups[1].Value))) { cueFile.FileEntries.Add(new CueFileEntry() { FileName = fileName, FileType = "BINARY", Tracks = index == 1 ? new List <CueTrack>() { new CueTrack() { DataType = CueTrackType.Data, Number = index, Indexes = new List <CueIndex>() { new CueIndex() { Number = 1, Position = new IndexPosition(0, 0, 0) } } } } : new List <CueTrack>() { new CueTrack() { DataType = CueTrackType.Audio, Number = index, Indexes = new List <CueIndex>() { new CueIndex() { Number = 0, Position = new IndexPosition(0, 0, 0) }, new CueIndex() { Number = 1, Position = new IndexPosition(0, 2, 0) } } } } }); index++; } tempFile = Path.GetTempFileName() + ".cue"; CueFileWriter.Write(cueFile, tempFile); generatedCue = true; } else if (Path.GetExtension(openFileDialog.FileName).ToLower() == ".cue") { tempFile = openFileDialog.FileName; } else { MessageBox.Show(Window, "Please select the CUE file, or if you do not have a CUE file, multi-select all the .bins ending in (Track #)", "PSXPackager", MessageBoxButton.OK, MessageBoxImage.Information); } var folder = Path.GetDirectoryName(Path.GetFullPath(saveFileDialog.FileName)); var filename = Path.GetFileName(saveFileDialog.FileName); var processing = new Popstation.Processing(null, null, null); var(binfile, cuefile) = processing.ProcessCue(tempFile, Path.GetTempPath()); var cueFileName = Path.GetFileNameWithoutExtension(filename) + ".cue"; var outputPath = Path.Combine(folder, saveFileDialog.FileName); if (File.Exists(outputPath)) { File.Delete(outputPath); } File.Move(binfile, outputPath); if (generatedCue) { var updatedCueFile = CueFileReader.Read(cuefile); var fileEntry = updatedCueFile.FileEntries.First(); fileEntry.FileName = filename; CueFileWriter.Write(updatedCueFile, Path.Combine(folder, cueFileName)); } MessageBox.Show(Window, $"Merged .bins to {outputPath}", "PSXPackager", MessageBoxButton.OK, MessageBoxImage.Information); }