private void ExtractResources(Stream stream, Func <ResourceType, string, string> getResourcePath)
        {
            Stream resourceStream;

            var pbpStreamReader = new PbpReader(stream);

            if (pbpStreamReader.TryGetResourceStream(ResourceType.ICON0, stream, out resourceStream))
            {
                ExtractResource(resourceStream, getResourcePath(ResourceType.ICON0, ".png"));
            }

            if (pbpStreamReader.TryGetResourceStream(ResourceType.ICON1, stream, out resourceStream))
            {
                ExtractResource(resourceStream, getResourcePath(ResourceType.ICON1, ".pmf"));
            }

            if (pbpStreamReader.TryGetResourceStream(ResourceType.PIC0, stream, out resourceStream))
            {
                ExtractResource(resourceStream, getResourcePath(ResourceType.PIC0, ".png"));
            }

            if (pbpStreamReader.TryGetResourceStream(ResourceType.PIC1, stream, out resourceStream))
            {
                ExtractResource(resourceStream, getResourcePath(ResourceType.PIC1, ".png"));
            }

            if (pbpStreamReader.TryGetResourceStream(ResourceType.SND0, stream, out resourceStream))
            {
                ExtractResource(resourceStream, getResourcePath(ResourceType.SND0, ".at3"));
            }
        }
Esempio n. 2
0
        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);
            }
        }