private GameEntry GetGameEntry(string gameId, string path, bool showMessages = true) { GameEntry game; var dummyTitle = Path.GetFileNameWithoutExtension(path); if (gameId != null) { game = _gameDb.GetEntryByScannerID(gameId); if (game == null) { if (showMessages) { _notifier?.Notify(PopstationEventEnum.Warning, $"Did not find a Game with ID {gameId} Using title {dummyTitle}"); } game = GetDummyGame(gameId, dummyTitle); } if (showMessages) { _notifier?.Notify(PopstationEventEnum.Info, $"Found {gameId} \"{game.GameName}\""); } } else { if (showMessages) { _notifier?.Notify(PopstationEventEnum.Warning, "Did not find a Game ID! Using SLUS-00000"); } game = GetDummyGame("SLUS-00000", dummyTitle); } return(game); }
public void LoadPbp() { if (IsBusy) { MessageBox.Show(Window, "An operation is in progress. Please wait for the current operation to complete.", "PSXPackager", MessageBoxButton.OK, MessageBoxImage.Information); return; } var openFileDialog = new Ookii.Dialogs.Wpf.VistaOpenFileDialog(); openFileDialog.Filter = "PBP Files|*.pbp|All files|*.*"; var result = openFileDialog.ShowDialog(); if (!result.GetValueOrDefault(false)) { return; } var path = openFileDialog.FileName; try { using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { var pbpReader = new PbpReader(stream); var discs = pbpReader.Discs.Select((d, i) => { var game = _gameDb.GetEntryByScannerID(d.DiscID); var disc = new Disc() { Index = i, Title = game.GameName, Size = d.IsoSize, GameID = d.DiscID, IsRemoveEnabled = true, IsLoadEnabled = true, IsSaveAsEnabled = true, IsEmpty = false, SourceUrl = $"//pbp/disc{i}/{path}" }; disc.RemoveCommand = new RelayCommand((o) => Remove(disc)); return(disc); }).ToList(); var dummyDiscs = DummyDisc(discs.Count, 5 - discs.Count); Model.Discs = discs.Concat(dummyDiscs).ToList(); void LoadResource(ResourceType type, ResourceModel model) { if (pbpReader.TryGetResourceStream(type, stream, out var resourceStream)) { model.Icon = GetBitmapImage(resourceStream); model.IsLoadEnabled = true; model.IsSaveAsEnabled = true; model.IsRemoveEnabled = true; model.SourceUrl = $"//pbp/{type.ToString().ToLower()}/{path}"; } } LoadResource(ResourceType.ICON0, Model.Icon0); LoadResource(ResourceType.ICON1, Model.Icon1); LoadResource(ResourceType.PIC0, Model.Pic0); LoadResource(ResourceType.PIC1, Model.Pic1); Model.IsNew = false; } } catch (Exception e) { MessageBox.Show(Window, e.Message, "PSXPackager", MessageBoxButton.OK, MessageBoxImage.Warning); } }