public void TestInplaceReplace() { FreeMount.Init(); var resPath = Path.Combine(Environment.CurrentDirectory, @"..\..\Res"); //var path = Path.Combine(resPath, "dx_ふかみ_駅員服.psb"); var path = Path.Combine(resPath, "dx_ふかみ_駅員服.lz4.psb"); var jsonPath = Path.Combine(resPath, "dx_ふかみ_駅員服.json"); PsbCompiler.InplaceReplaceToFile(path, jsonPath); }
//private static PsbPixelFormat _pixelFormat = PsbPixelFormat.None; static void Main(string[] args) { Console.WriteLine("FreeMote PSB Compiler"); Console.WriteLine("by Ulysses, [email protected]"); FreeMount.Init(); Console.WriteLine($"{FreeMount.PluginsCount} Plugins Loaded."); InMemoryLoading = true; Console.WriteLine(); var app = new CommandLineApplication(); app.OptionsComparison = StringComparison.OrdinalIgnoreCase; //help app.HelpOption(); app.ExtendedHelpText = PrintHelp(); //options var optVer = app.Option <ushort>("-v|--ver <VER>", "Set PSB version [2,4]. Default=3", CommandOptionType.SingleValue); var optKey = app.Option <uint>("-k|--key <KEY>", "Set PSB key (uint, dec)", CommandOptionType.SingleValue); var optSpec = app.Option <PsbSpec>("-p|--spec <SPEC>", "Set PSB platform (krkr/common/win/ems)", CommandOptionType.SingleValue); var optNoRename = app.Option("-no-rename", "Prevent output file renaming, may overwrite your original PSB files", CommandOptionType.NoValue); var optNoShell = app.Option("-no-shell", "Prevent shell packing (compression)", CommandOptionType.NoValue); var optDouble = app.Option("-double|--json-double", "(Json) Use double numbers only (no float)", CommandOptionType.NoValue, true); //var optOutputPath = // app.Option<string>("-o|--output", "(TODO:)Set output directory or file name.", CommandOptionType.SingleValue); //TODO: If set dir, ok; if set filename, only works for the first //args var argPath = app.Argument("Files", "File paths", multipleValues: true); //command: link app.Command("link", linkCmd => { //help linkCmd.Description = "Link textures into an external texture PSB"; linkCmd.HelpOption(); linkCmd.ExtendedHelpText = @" Example: PsBuild link -o Order sample.psb tex000.png tex001.bmp "; //options var optOrder = linkCmd.Option <PsbLinkOrderBy>("-o|--order <ORDER>", "Set texture link order (Name/Order/Convention). Default=Name", CommandOptionType.SingleValue); //args var argPsbPath = linkCmd.Argument("PSB", "PSB Path").IsRequired().Accepts(v => v.ExistingFile()); var argTexPaths = linkCmd.Argument("Textures", "Texture Paths", true).IsRequired(); linkCmd.OnExecute(() => { var order = optOrder.HasValue() ? optOrder.ParsedValue : PsbLinkOrderBy.Name; var psbPath = argPsbPath.Value; var texPaths = argTexPaths.Values; Link(psbPath, texPaths, order); }); }); //command: port app.Command("port", portCmd => { //help portCmd.Description = "Re-compile a PSB to another platform"; portCmd.HelpOption(); portCmd.ExtendedHelpText = @" Example: PsBuild port -p win sample.psb "; //options var optPortSpec = portCmd.Option <PsbSpec>("-p|--spec <SPEC>", "Target PSB platform (krkr/common/win/ems)", CommandOptionType.SingleValue).IsRequired(); //args var argPsbPath = portCmd.Argument("PSB", "PSB Path", multipleValues: true).IsRequired(); portCmd.OnExecute(() => { var portSpec = optPortSpec.ParsedValue; var psbPaths = argPsbPath.Values; foreach (var s in psbPaths) { if (File.Exists(s)) { Port(s, portSpec); } } }); }); //info-psb app.Command("info-psb", archiveCmd => { //help archiveCmd.Description = "Pack files to info.psb.m & body.bin (FreeMote.Plugins required)"; archiveCmd.HelpOption(); archiveCmd.ExtendedHelpText = @" Example: PsBuild info-psb sample_info.psb.m.json (Key specified in resx.json) PsBuild info-psb -k 1234567890ab -l 131 sample_info.psb.m.json (Must keep every filename correct) Hint: Always keep file names correct. A file name in source folder must match a name kept in .m.json If there are both `.m` and `.m.json` in the source folder, `.json` will be used (unless using `--packed`). If you don't have enough RAM to keep the whole output, use `-1by1` and wait patiently. "; //options //var optMdfSeed = archiveCmd.Option("-s|--seed <SEED>", // "Set complete seed (Key+FileName)", // CommandOptionType.SingleValue); var optIntersect = archiveCmd.Option("-i|--intersect", "Only pack files which existed in info.psb.m", CommandOptionType.NoValue); var optPacked = archiveCmd.Option("-p|--packed", "Prefer using PSB files rather than json files in source folder", CommandOptionType.NoValue); var optMdfKey = archiveCmd.Option("-k|--key <KEY>", "Set key (get file name from input path)", CommandOptionType.SingleValue); var optMdfKeyLen = archiveCmd.Option <int>("-l|--length <LEN>", "Set key length. Default=131", CommandOptionType.SingleValue); var optInfoOom = archiveCmd.Option("-1by1|--enumerate", "Disable parallel processing (can be slow but save a lot memory)", CommandOptionType.NoValue); var optInfoRaw = archiveCmd.Option("-raw|--raw", "Keep all sources raw (don't compile jsons or pack MDF shell)", CommandOptionType.NoValue); //args var argPsbPaths = archiveCmd.Argument("PSB", "Archive Info PSB .json paths", true); archiveCmd.OnExecute(() => { bool intersect = optIntersect.HasValue(); bool preferPacked = optPacked.HasValue(); bool enableParallel = FastMode; bool keepRaw = false; if (optInfoOom.HasValue()) { enableParallel = false; } if (optInfoRaw.HasValue()) { keepRaw = true; } string key = optMdfKey.HasValue() ? optMdfKey.Value() : null; //string seed = optMdfSeed.HasValue() ? optMdfSeed.Value() : null; int keyLen = optMdfKeyLen.HasValue() ? optMdfKeyLen.ParsedValue : 131; Stopwatch sw = Stopwatch.StartNew(); foreach (var s in argPsbPaths.Values) { PackArchive(s, key, intersect, preferPacked, enableParallel, keyLen, keepRaw); } sw.Stop(); Console.WriteLine($"Process time: {sw.Elapsed:g}"); }); }); //command: replace app.Command("replace", replaceCmd => { //help replaceCmd.Description = "In-place Replace the images in PSB"; replaceCmd.HelpOption(); replaceCmd.ExtendedHelpText = @" Example: PsBuild replace sample.psb sample.json Hint: Only works with textures not compressed (RGBA8, RGBA4444) pure PSBs. "; var argPsbPath = replaceCmd.Argument("PSB", "PSB path", false); var argJsonPath = replaceCmd.Argument("Json", "PSB Json path", false); replaceCmd.OnExecute(() => { if (!File.Exists(argPsbPath.Value) || !File.Exists(argJsonPath.Value)) { Console.WriteLine("File not exists."); return; } var output = PsbCompiler.InplaceReplaceToFile(argPsbPath.Value, argJsonPath.Value); Console.WriteLine($"In-place Replace Output: {output}"); }); }); app.OnExecute(() => { if (optDouble.HasValue()) { JsonUseDoubleOnly = true; } ushort?ver = optVer.HasValue() ? optVer.ParsedValue : (ushort?)null; uint?key = optKey.HasValue() ? optKey.ParsedValue : (uint?)null; PsbSpec?spec = optSpec.HasValue() ? optSpec.ParsedValue : (PsbSpec?)null; var canRename = !optNoRename.HasValue(); var canPack = !optNoShell.HasValue(); foreach (var file in argPath.Values) { Compile(file, ver, key, spec, canRename, canPack); } }); if (args.Length == 0) { app.ShowHelp(); return; } app.Execute(args); Console.WriteLine("Done."); }