Exemplo n.º 1
0
        private void SetResources(ProcessOptions processOptions, ConvertOptions options, GameEntry entry)
        {
            var appPath     = ApplicationInfo.AppPath;
            var defaultPath = Path.Combine(appPath, "Resources");


            if (string.IsNullOrEmpty(processOptions.ResourceFoldersPath))
            {
                processOptions.ResourceFoldersPath = options.OriginalPath;
            }

            Resource GetResourceOrDefault(ResourceType type, string ext)
            {
                var filename = Popstation.GetResourceFilename(processOptions.CustomResourceFormat, options.OriginalFilename, entry.GameID, entry.SaveFolderName, entry.GameName, entry.SaveDescription, entry.Format, type, ext);

                var resourcePath = Path.Combine(processOptions.ResourceFoldersPath, filename);

                if (!File.Exists(resourcePath) || !processOptions.ImportResources)
                {
                    resourcePath = Path.Combine(defaultPath, $"{type}.{ext}");
                }

                return(new Resource(type, resourcePath));
            }

            options.Icon0 = GetResourceOrDefault(ResourceType.ICON0, "png");
            options.Icon1 = GetResourceOrDefault(ResourceType.ICON1, "pmf");
            options.Pic0  = GetResourceOrDefault(ResourceType.PIC0, "png");
            options.Pic1  = GetResourceOrDefault(ResourceType.PIC1, "png");
            options.Snd0  = GetResourceOrDefault(ResourceType.SND0, "at3");
        }
Exemplo n.º 2
0
        public bool RepackPBP(
            string originalFile,
            string srcPbp,
            ProcessOptions processOptions,
            CancellationToken cancellationToken)
        {
            var appPath = ApplicationInfo.AppPath;
            var gameId  = GetPBPGameId(srcPbp);
            var game    = GetGameEntry(gameId, srcPbp, false);


            var options = new ConvertOptions()
            {
                DiscInfos = new List <DiscInfo>()
                {
                    new DiscInfo()
                    {
                        GameID     = game.ScannerID,
                        GameTitle  = game.SaveDescription,
                        GameName   = game.GameName,
                        Region     = game.Format,
                        MainGameID = game.SaveFolderName,
                        SourceIso  = srcPbp,
                    }
                },
                OriginalFilename  = Path.GetFileNameWithoutExtension(originalFile),
                OriginalPath      = Path.GetDirectoryName(originalFile),
                OutputPath        = processOptions.OutputPath,
                MainGameTitle     = game.GameName,
                MainGameRegion    = game.Format,
                MainGameID        = game.SaveFolderName,
                SaveTitle         = game.SaveDescription,
                SaveID            = game.SaveFolderName,
                BasePbp           = Path.Combine(appPath, "Resources", "BASE.PBP"),
                CompressionLevel  = processOptions.CompressionLevel,
                CheckIfFileExists = processOptions.CheckIfFileExists,
                SkipIfFileExists  = processOptions.SkipIfFileExists,
                FileNameFormat    = processOptions.FileNameFormat,
            };

            if (processOptions.GenerateResourceFolders)
            {
                GenerateResourceFolders(processOptions, options, game);
                return(true);
            }

            SetResources(processOptions, options, game);

            _notifier.Notify(PopstationEventEnum.Info, $"Using Title '{game.GameName}'");

            var popstation = new Popstation
            {
                ActionIfFileExists = _eventHandler.ActionIfFileExists,
                Notify             = _notifier.Notify,
                TempFiles          = tempFiles
            };

            return(popstation.Repack(options, cancellationToken));
        }
Exemplo n.º 3
0
        public bool Repack(ConvertOptions options, CancellationToken cancellationToken)
        {
            using (var stream = new FileStream(options.DiscInfos[0].SourceIso, FileMode.Open, FileAccess.Read))
            {
                var path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                try
                {
                    //ExtractResources(stream, (type, extension) => GetResourcePath(options, gameInfo, type, extension));

                    var writer = new PbpRewriter(options);

                    var directory = options.OutputPath;
                    var ext       = ".pbp";

                    var title  = options.MainGameTitle;
                    var code   = options.MainGameID;
                    var region = options.MainGameRegion;

                    var outputFilename = GetFilename(options.FileNameFormat,
                                                     options.OriginalFilename,
                                                     code,
                                                     code,
                                                     title,
                                                     title,
                                                     region
                                                     );

                    var outputPath = Path.Combine(directory, $"{outputFilename}{ext}");

                    if (!Directory.Exists(directory))
                    {
                        Directory.CreateDirectory(directory);
                    }

                    using (var outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write, FileShare.Write))
                    {
                        writer.Write(outputStream, cancellationToken);
                    }
                }
                finally
                {
                    Directory.Delete(path, true);
                }

                return(cancellationToken.IsCancellationRequested);
            }
        }
Exemplo n.º 4
0
        public bool Convert(ConvertOptions convertInfo, CancellationToken cancellationToken)
        {
            PbpWriter writer;

            if (convertInfo.DiscInfos.Count == 1)
            {
                writer = new SingleDiscPbpWriter(convertInfo);
            }
            else
            {
                writer = new MultiDiscPbpWriter(convertInfo);
            }

            writer.Notify             = Notify;
            writer.ActionIfFileExists = ActionIfFileExists;
            writer.TempFiles          = TempFiles;

            var directory = convertInfo.OutputPath;
            var ext       = ".pbp";

            var title  = convertInfo.MainGameTitle;
            var code   = convertInfo.MainGameID;
            var region = convertInfo.MainGameRegion;

            var outputFilename = GetFilename(convertInfo.FileNameFormat,
                                             convertInfo.OriginalFilename,
                                             code,
                                             code,
                                             title,
                                             title,
                                             region
                                             );

            var outputPath = Path.Combine(directory, $"{outputFilename}{ext}");

            var finalDirectory = Directory.GetParent(outputPath);

            if (finalDirectory != null && !finalDirectory.Exists)
            {
                finalDirectory.Create();
            }

            using (var outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write, FileShare.Write))
            {
                writer.Write(outputStream, cancellationToken);
            }

            return(cancellationToken.IsCancellationRequested);
        }
Exemplo n.º 5
0
        private void GenerateResourceFolders(ProcessOptions processOptions, ConvertOptions options, GameEntry entry)
        {
            var path = Popstation.GetResourceFilename(processOptions.CustomResourceFormat, options.OriginalFilename, entry.GameID, entry.SaveFolderName, entry.GameName, entry.SaveDescription, entry.Format, ResourceType.ICON0, "png");

            path = Path.GetDirectoryName(path);

            path = Path.Combine(options.OriginalPath, path);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            using (File.Create(Path.Combine(path, entry.GameName)))
            {
            }
        }
Exemplo n.º 6
0
        private bool ConvertIsos(
            string originalFile,
            string[] srcIsos,
            string[] srcTocs,
            ProcessOptions processOptions,
            CancellationToken cancellationToken)
        {
            var appPath = ApplicationInfo.AppPath;
            var srcIso  = srcIsos[0];
            var gameId  = GameDB.FindGameId(srcIso);
            var game    = GetGameEntry(gameId, srcIso, false);

            var options = new ConvertOptions()
            {
                OriginalPath      = Path.GetDirectoryName(originalFile),
                OriginalFilename  = Path.GetFileNameWithoutExtension(originalFile),
                OutputPath        = processOptions.OutputPath,
                DiscInfos         = new List <DiscInfo>(),
                MainGameTitle     = game.SaveDescription,
                MainGameID        = game.SaveFolderName,
                MainGameRegion    = game.Format,
                SaveTitle         = game.SaveDescription,
                SaveID            = game.SaveFolderName,
                BasePbp           = Path.Combine(appPath, "Resources", "BASE.PBP"),
                CompressionLevel  = processOptions.CompressionLevel,
                CheckIfFileExists = processOptions.CheckIfFileExists,
                SkipIfFileExists  = processOptions.SkipIfFileExists,
                FileNameFormat    = processOptions.FileNameFormat,
            };

            if (processOptions.GenerateResourceFolders)
            {
                GenerateResourceFolders(processOptions, options, game);
                return(true);
            }
            SetResources(processOptions, options, game);

            for (var i = 0; i < srcIsos.Length; i++)
            {
                gameId = GameDB.FindGameId(srcIso);
                game   = GetGameEntry(gameId, srcIsos[i]);

                options.DiscInfos.Add(new DiscInfo()
                {
                    GameID     = game.ScannerID,
                    GameTitle  = game.SaveDescription,
                    GameName   = game.GameName,
                    Region     = game.Format,
                    MainGameID = game.SaveFolderName,
                    SourceIso  = srcIsos[i],
                    SourceToc  = i < srcTocs.Length ? srcTocs[i] : "",
                });
            }

            _notifier?.Notify(PopstationEventEnum.Info, $"Using Title '{game.SaveDescription}'");

            var popstation = new Popstation
            {
                ActionIfFileExists = _eventHandler.ActionIfFileExists,
                Notify             = _notifier.Notify,
                TempFiles          = tempFiles
            };

            return(popstation.Convert(options, cancellationToken));
        }