Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 private void ProcessTOCs()
 {
     foreach (var disc in convertInfo.DiscInfos)
     {
         var t       = new FileInfo(disc.SourceIso);
         var isosize = (uint)t.Length;
         if (!string.IsNullOrEmpty(disc.SourceToc))
         {
             if (File.Exists(disc.SourceToc))
             {
                 var cue = CueFileReader.Read(disc.SourceToc);
                 disc.TocData = cue.GetTOCData(isosize);
             }
             else
             {
                 Notify?.Invoke(PopstationEventEnum.Warning, $"{disc.SourceToc} not found, using default");
                 var cue = CueFileExtensions.GetDummyCueFile();
                 disc.TocData = cue.GetTOCData(isosize);
             }
         }
         else
         {
             Notify?.Invoke(PopstationEventEnum.Warning, $"TOC not specified, using default");
             var cue = CueFileExtensions.GetDummyCueFile();
             disc.TocData = cue.GetTOCData(isosize);
         }
     }
 }
Ejemplo n.º 3
0
        private void Scan(object obj)
        {
            if (_model.IsScanning)
            {
                var result = MessageBox.Show(Window, "Abort scanning?", "Batch", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);
                if (result == MessageBoxResult.Yes)
                {
                    Cancel();
                }
                return;
            }

            if (string.IsNullOrEmpty(_model.Settings.InputPath))
            {
                MessageBox.Show(Window, "No input path specified", "Batch", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (!Directory.Exists(_model.Settings.InputPath))
            {
                MessageBox.Show(Window, "Invalid directory or directory not found", "Batch", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            var patterns = new List <string>();

            if (_model.ConvertImageToPbp || _model.GenerateResourceFolders)
            {
                if (_model.Settings.IsM3uChecked)
                {
                    patterns.Add("*.m3u");
                }
                if (_model.Settings.IsBinChecked)
                {
                    patterns.Add("*.cue");
                    patterns.Add("*.bin");
                }
                if (_model.Settings.IsImgChecked)
                {
                    patterns.Add("*.img");
                }
                if (_model.Settings.IsIsoChecked)
                {
                    patterns.Add("*.iso");
                }
                if (_model.Settings.Is7zChecked)
                {
                    patterns.Add("*.7z");
                }
                if (_model.Settings.IsZipChecked)
                {
                    patterns.Add("*.zip");
                }
                if (_model.Settings.IsRarChecked)
                {
                    patterns.Add("*.rar");
                }
            }


            if (_model.ConvertPbpToImage || _model.ExtractResources || _model.GenerateResourceFolders)
            {
                patterns.Add("*.pbp");
            }



            Task.Run(() =>
            {
                _dispatcher.Invoke(() =>
                {
                    _model.IsScanning = true;
                    _model.BatchEntries.Clear();
                });

                var ignoreFileSet = new HashSet <string>();

                string GetAbsolutePath(string currentDirectory, string file)
                {
                    if (Path.IsPathFullyQualified(file))
                    {
                        return(file);
                    }
                    return(Path.Combine(currentDirectory, file));
                }


                string GetFullPath(string file)
                {
                    return(Path.Combine(_model.Settings.InputPath, file));
                }

                foreach (var pattern in patterns)
                {
                    if (_token.IsCancellationRequested)
                    {
                        break;
                    }

                    var searchOption = SearchOption.TopDirectoryOnly;

                    if (_model.Settings.RecurseFolders)
                    {
                        searchOption = SearchOption.AllDirectories;
                    }

                    var files = Directory.EnumerateFiles(_model.Settings.InputPath, pattern, searchOption);

                    foreach (var file in files.Select(GetFullPath))
                    {
                        var currentPath = Path.GetDirectoryName(file);

                        if (_token.IsCancellationRequested)
                        {
                            break;
                        }

                        switch (pattern)
                        {
                        case "*.m3u":
                            {
                                var playlist = M3uFileReader.Read(file);
                                foreach (var fileEntry in playlist.FileEntries)
                                {
                                    ignoreFileSet.Add(GetAbsolutePath(currentPath, fileEntry));
                                }

                                break;
                            }

                        case "*.cue":
                            {
                                var cueFiles = CueFileReader.Read(file);
                                foreach (var fileEntry in cueFiles.FileEntries)
                                {
                                    ignoreFileSet.Add(GetAbsolutePath(currentPath, fileEntry.FileName));
                                }

                                break;
                            }
                        }

                        var relativePath = Path.GetRelativePath(_model.Settings.InputPath, file);

                        if (!ignoreFileSet.Contains(file))
                        {
                            _dispatcher.Invoke(() =>
                            {
                                _model.BatchEntries.Add(new BatchEntryModel()
                                {
                                    RelativePath = relativePath,
                                    MaxProgress  = 100,
                                    Progress     = 0,
                                    Status       = "Ready"
                                });
                            });
                        }
                    }
                }

                _dispatcher.Invoke(() =>
                {
                    _model.IsScanning = false;
                });

                if (_token.IsCancellationRequested)
                {
                    _dispatcher.Invoke(() =>
                    {
                        MessageBox.Show(Window, "Scan aborted!", "Batch", MessageBoxButton.OK, MessageBoxImage.Warning);
                    });
                }

                _dispatcher.Invoke(() =>
                {
                    MessageBox.Show(Window, $"Scan found {_model.BatchEntries.Count} entries", "Batch", MessageBoxButton.OK, MessageBoxImage.Information);
                });
            });
        }
Ejemplo n.º 4
0
        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);
        }