diff --git a/README.md b/README.md index 269b850..5b1f61b 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,19 @@ A program to build Syati Modules. (Command line tool) ```bat -SyatiModuleBuildTool.exe +SyatiModuleBuildTool.exe ``` + +**Mandatory Arguments:** - Replace `` with one of the following: `USA`, `PAL`, `JPN`, `KOR`, `TWN`. Choose the one that matches your game disc. - Replace `` with the complete path to your Syati folder. If your path has spaces in it, surround it with Quotation Marks " - Replace `` with the complete path to the folder that you put the modules into. If your path has spaces in it, surround it with Quotation Marks " -- Replace `` with the complete path of the folder that you would like the resulting CustomCode.bin to be saved to. If your path has spaces in it, surround it with Quotation Marks " +- Replace `` with the complete path of the folder that you would like the resulting CustomCode.bin to be saved to. If your path has spaces in it, surround it with Quotation Marks " +- Replace `` with the complete path of the folder that you would like the disc files of the modules to be copied to. If your path has spaces in it, surround it with Quotation Marks ". + +**Optional Arguments:** +- If you would like to copy disc files, add `-d ` to the end of the command, and replace `` with the folder you would like to copy the disc files to. If your path has spaces in it, surround it with Quotation Marks ". (Ensure there is a space between the last path and this argument) - If you would like to use **UniBuild**, add `-u` to the end of the command. (Ensure there is a space between the last path and the `-u`) > *Note: UniBuild is an alternative method of compiling modules which may result in smaller output binaries. If you have less than 10 modules, you do not need UniBuild.* -After running the command, you will be given a **CustomCode.bin** and a **CustomCode.map**. +After running the command, you will be given a **CustomCode.bin**, a **CustomCode.map**, and if specified, the disc files of all your modules. diff --git a/SyatiModuleBuildTool/DiscUtility.cs b/SyatiModuleBuildTool/DiscUtility.cs index 4f6b48d..a3e9c1f 100644 --- a/SyatiModuleBuildTool/DiscUtility.cs +++ b/SyatiModuleBuildTool/DiscUtility.cs @@ -1,6 +1,38 @@ namespace SyatiModuleBuildTool; -public static class DiscUtility -{ - // Todo lol +public static class DiscUtility { + public static void CopyAllFiles(List modules, string output) { + foreach (ModuleInfo module in modules) + CopyFiles(module, output); + } + + public static void CopyFiles(ModuleInfo module, string output) { + var discFolder = Path.Combine(module.FolderPath, "disc"); + + if (!Directory.Exists(discFolder)) + return; + + Console.WriteLine($"Copying files from {discFolder}"); + + var discPaths = Directory.GetFiles(discFolder, "*", SearchOption.AllDirectories); + + foreach (var sourcePath in discPaths) { + var relativePath = Path.GetRelativePath(discFolder, sourcePath); + var targetPath = Path.Combine(output, relativePath); + + try { + if (Path.Exists(targetPath)) + Console.WriteLine($"{sourcePath} will replace {targetPath}"); + + var targetDirectory = Path.GetDirectoryName(targetPath); + if (targetDirectory is not null) + Directory.CreateDirectory(targetDirectory); + + File.Copy(sourcePath, targetPath, true); + } + catch (Exception e) { + Console.WriteLine($"Error while copying \"{discFolder}\": {e.Message}"); + } + } + } } diff --git a/SyatiModuleBuildTool/Program.cs b/SyatiModuleBuildTool/Program.cs index 5688c89..065e4cd 100644 --- a/SyatiModuleBuildTool/Program.cs +++ b/SyatiModuleBuildTool/Program.cs @@ -155,7 +155,7 @@ void TryLoadModule(string ModulePath) $"-D{args[0]}" ]; Console.WriteLine(); - if (args.Any(o => o.Equals("-u"))) + if (args.Any(s => s.Equals("-u"))) ModuleUtility.CompileAllUnibuild(Modules, Flags, IncludePaths, SyatiFolderPath, args[3], ref AllObjectOutputs); else ModuleUtility.CompileAllModules(Modules, Flags, IncludePaths, SyatiFolderPath, ref AllObjectOutputs); @@ -185,17 +185,40 @@ void TryLoadModule(string ModulePath) throw new InvalidOperationException("Linker Failure"); } + if (GetOptionalArgument(ref args, "-d", out var path) && path is not null) { + Console.WriteLine(); + Console.WriteLine("Copying disc..."); + + DiscUtility.CopyAllFiles(Modules, path); + } + + Console.WriteLine(); Console.WriteLine("Complete!"); } + static bool GetOptionalArgument(ref string[] args, string flag, out string? str) { + for (int i = 4; i < args.Length; i++) { + if (args[i] == flag) { + if (i + 1 < args.Length) + str = args[i + 1]; + else + str = null; + + return true; + } + } + str = null; + return false; + } static void Help() { Console.WriteLine( """ - SyatiModuleBuildTool.exe + SyatiModuleBuildTool.exe Extra options: - -u Enable UniBuild. UniBuild can shrink the final .bin file size at the potential cost of debuggability. Should only be used when you have a lot of modules. (10+) + -d Copy module disc files. To use this option, replace with the path you want to copy the disc files to. + -u Enable UniBuild. UniBuild can shrink the final .bin file size at the potential cost of debuggability. Should only be used when you have a lot of modules. (10+) """); } static void Error(Exception ex)