From ec3a99cad065c42c3767440a15e3487a0d28a7f2 Mon Sep 17 00:00:00 2001 From: VTXG Date: Fri, 17 Jan 2025 20:59:12 +0000 Subject: [PATCH 1/7] Added DiscUtil --- SyatiModuleBuildTool/DiscUtility.cs | 32 ++++++++++++++++++++++++++--- SyatiModuleBuildTool/Program.cs | 12 +++++++++-- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/SyatiModuleBuildTool/DiscUtility.cs b/SyatiModuleBuildTool/DiscUtility.cs index 4f6b48d..a8bd847 100644 --- a/SyatiModuleBuildTool/DiscUtility.cs +++ b/SyatiModuleBuildTool/DiscUtility.cs @@ -1,6 +1,32 @@ 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 sourceDiscFolder = Path.Combine(module.FolderPath, "disc"); + + if (!Directory.Exists(sourceDiscFolder)) { + return; + } + + Console.WriteLine($"Copying files from {sourceDiscFolder}"); + + foreach (var sourcePath in Directory.EnumerateFiles(sourceDiscFolder, "*", SearchOption.AllDirectories)) { + var relativePath = Path.GetRelativePath(sourceDiscFolder, sourcePath); + var targetPath = Path.Combine(output, relativePath); + + try { + Directory.CreateDirectory(Path.GetDirectoryName(targetPath)!); + File.Copy(sourcePath, targetPath, true); + } + catch (Exception e) { + Console.WriteLine($"Error while copying \"{sourceDiscFolder}\": {e.Message}"); + } + } + } } diff --git a/SyatiModuleBuildTool/Program.cs b/SyatiModuleBuildTool/Program.cs index 5688c89..b1ba750 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.Last().Equals("-u")) ModuleUtility.CompileAllUnibuild(Modules, Flags, IncludePaths, SyatiFolderPath, args[3], ref AllObjectOutputs); else ModuleUtility.CompileAllModules(Modules, Flags, IncludePaths, SyatiFolderPath, ref AllObjectOutputs); @@ -185,6 +185,14 @@ void TryLoadModule(string ModulePath) throw new InvalidOperationException("Linker Failure"); } + if (args.Length > 4 && args[4] != "-u") { // Make sure the argument in the position of Path_To_Disc_Output_Folder isn't the unibuild flag + Console.WriteLine(); + Console.WriteLine("Copying disc..."); + + DiscUtility.CopyAllFiles(Modules, args[4]); + } + + Console.WriteLine(); Console.WriteLine("Complete!"); } @@ -192,7 +200,7 @@ 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+) From 71092197b1d837b0d14d0b24c01c12d644d14637 Mon Sep 17 00:00:00 2001 From: VTXG Date: Fri, 17 Jan 2025 21:03:39 +0000 Subject: [PATCH 2/7] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 269b850..23e2a22 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,13 @@ A program to build Syati Modules. (Command line tool) ```bat -SyatiModuleBuildTool.exe +SyatiModuleBuildTool.exe ``` - 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 " - 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.* From 582afa86cd0eb47c7f5f70b36189d7f6929bfc90 Mon Sep 17 00:00:00 2001 From: VTXG Date: Sat, 18 Jan 2025 23:25:52 +0000 Subject: [PATCH 3/7] Made disc file copying an optional argument (-d ) --- README.md | 11 ++++++++--- SyatiModuleBuildTool/Program.cs | 33 +++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 23e2a22..5b1f61b 100644 --- a/README.md +++ b/README.md @@ -3,14 +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 disc files of the modules to be copied 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/Program.cs b/SyatiModuleBuildTool/Program.cs index b1ba750..fb3a796 100644 --- a/SyatiModuleBuildTool/Program.cs +++ b/SyatiModuleBuildTool/Program.cs @@ -155,7 +155,7 @@ void TryLoadModule(string ModulePath) $"-D{args[0]}" ]; Console.WriteLine(); - if (args.Last().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,37 @@ void TryLoadModule(string ModulePath) throw new InvalidOperationException("Linker Failure"); } - if (args.Length > 4 && args[4] != "-u") { // Make sure the argument in the position of Path_To_Disc_Output_Folder isn't the unibuild flag - Console.WriteLine(); - Console.WriteLine("Copying disc..."); + // if (args.Length > 4 && args[4] != "-u") { // Make sure the argument in the position of Path_To_Disc_Output_Folder isn't the unibuild flag + if (GetOptionalArgument(ref args, "-d", out var path)) { + if (path is not null) { + Console.WriteLine(); + Console.WriteLine("Copying disc..."); - DiscUtility.CopyAllFiles(Modules, args[4]); + DiscUtility.CopyAllFiles(Modules, path); + } + else { + Console.WriteLine("A path to copy disc files to was not provided, skipped copying."); + } } Console.WriteLine(); Console.WriteLine("Complete!"); } + static bool GetOptionalArgument(ref string[] args, string flag, out string? str) { + for (int i = 0; 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( @@ -203,7 +223,8 @@ static void Help() 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) From 00d1ad4647d4680e6ff4b2a44c943b4305311de2 Mon Sep 17 00:00:00 2001 From: VTXG Date: Sun, 19 Jan 2025 00:03:44 +0000 Subject: [PATCH 4/7] Remove commented code --- SyatiModuleBuildTool/Program.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/SyatiModuleBuildTool/Program.cs b/SyatiModuleBuildTool/Program.cs index fb3a796..4a8b165 100644 --- a/SyatiModuleBuildTool/Program.cs +++ b/SyatiModuleBuildTool/Program.cs @@ -185,7 +185,6 @@ void TryLoadModule(string ModulePath) throw new InvalidOperationException("Linker Failure"); } - // if (args.Length > 4 && args[4] != "-u") { // Make sure the argument in the position of Path_To_Disc_Output_Folder isn't the unibuild flag if (GetOptionalArgument(ref args, "-d", out var path)) { if (path is not null) { Console.WriteLine(); From cec16c61e7a87829e330202c32e9add8c097380f Mon Sep 17 00:00:00 2001 From: VTXG Date: Sun, 19 Jan 2025 00:47:50 +0000 Subject: [PATCH 5/7] Make review changes --- SyatiModuleBuildTool/DiscUtility.cs | 15 +++++++++------ SyatiModuleBuildTool/Program.cs | 17 ++++++----------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/SyatiModuleBuildTool/DiscUtility.cs b/SyatiModuleBuildTool/DiscUtility.cs index a8bd847..bd3baf2 100644 --- a/SyatiModuleBuildTool/DiscUtility.cs +++ b/SyatiModuleBuildTool/DiscUtility.cs @@ -2,26 +2,29 @@ public static class DiscUtility { public static void CopyAllFiles(List modules, string output) { - foreach (ModuleInfo module in modules) { + foreach (ModuleInfo module in modules) CopyFiles(module, output); - } } public static void CopyFiles(ModuleInfo module, string output) { var sourceDiscFolder = Path.Combine(module.FolderPath, "disc"); - if (!Directory.Exists(sourceDiscFolder)) { + if (!Directory.Exists(sourceDiscFolder)) return; - } Console.WriteLine($"Copying files from {sourceDiscFolder}"); - foreach (var sourcePath in Directory.EnumerateFiles(sourceDiscFolder, "*", SearchOption.AllDirectories)) { + var discPaths = Directory.GetFiles(sourceDiscFolder, "*", SearchOption.AllDirectories); + + foreach (var sourcePath in discPaths) { var relativePath = Path.GetRelativePath(sourceDiscFolder, sourcePath); var targetPath = Path.Combine(output, relativePath); try { - Directory.CreateDirectory(Path.GetDirectoryName(targetPath)!); + var targetDirectory = Path.GetDirectoryName(targetPath); + if (targetDirectory is not null) + Directory.CreateDirectory(targetDirectory); + File.Copy(sourcePath, targetPath, true); } catch (Exception e) { diff --git a/SyatiModuleBuildTool/Program.cs b/SyatiModuleBuildTool/Program.cs index 4a8b165..065e4cd 100644 --- a/SyatiModuleBuildTool/Program.cs +++ b/SyatiModuleBuildTool/Program.cs @@ -185,23 +185,18 @@ void TryLoadModule(string ModulePath) throw new InvalidOperationException("Linker Failure"); } - if (GetOptionalArgument(ref args, "-d", out var path)) { - if (path is not null) { - Console.WriteLine(); - Console.WriteLine("Copying disc..."); + if (GetOptionalArgument(ref args, "-d", out var path) && path is not null) { + Console.WriteLine(); + Console.WriteLine("Copying disc..."); - DiscUtility.CopyAllFiles(Modules, path); - } - else { - Console.WriteLine("A path to copy disc files to was not provided, skipped copying."); - } + DiscUtility.CopyAllFiles(Modules, path); } Console.WriteLine(); Console.WriteLine("Complete!"); } static bool GetOptionalArgument(ref string[] args, string flag, out string? str) { - for (int i = 0; i < args.Length; i++) { + for (int i = 4; i < args.Length; i++) { if (args[i] == flag) { if (i + 1 < args.Length) str = args[i + 1]; @@ -219,7 +214,7 @@ static void Help() { Console.WriteLine( """ - SyatiModuleBuildTool.exe + SyatiModuleBuildTool.exe Extra options: -d Copy module disc files. To use this option, replace with the path you want to copy the disc files to. From c14a5f3f51503699282fdfc340435375c9a1de95 Mon Sep 17 00:00:00 2001 From: VTXG Date: Sun, 19 Jan 2025 18:08:12 +0000 Subject: [PATCH 6/7] Add warning when overwriting file --- SyatiModuleBuildTool/DiscUtility.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/SyatiModuleBuildTool/DiscUtility.cs b/SyatiModuleBuildTool/DiscUtility.cs index bd3baf2..4aea32c 100644 --- a/SyatiModuleBuildTool/DiscUtility.cs +++ b/SyatiModuleBuildTool/DiscUtility.cs @@ -7,20 +7,23 @@ public static void CopyAllFiles(List modules, string output) { } public static void CopyFiles(ModuleInfo module, string output) { - var sourceDiscFolder = Path.Combine(module.FolderPath, "disc"); + var discFolder = Path.Combine(module.FolderPath, "disc"); - if (!Directory.Exists(sourceDiscFolder)) + if (!Directory.Exists(discFolder)) return; - Console.WriteLine($"Copying files from {sourceDiscFolder}"); + Console.WriteLine($"Copying files from {discFolder}"); - var discPaths = Directory.GetFiles(sourceDiscFolder, "*", SearchOption.AllDirectories); + var discPaths = Directory.GetFiles(discFolder, "*", SearchOption.AllDirectories); foreach (var sourcePath in discPaths) { - var relativePath = Path.GetRelativePath(sourceDiscFolder, sourcePath); + var relativePath = Path.GetRelativePath(discFolder, sourcePath); var targetPath = Path.Combine(output, relativePath); try { + if (Path.Exists(targetPath)) + Console.WriteLine($" - File will replace {targetPath}"); + var targetDirectory = Path.GetDirectoryName(targetPath); if (targetDirectory is not null) Directory.CreateDirectory(targetDirectory); @@ -28,7 +31,7 @@ public static void CopyFiles(ModuleInfo module, string output) { File.Copy(sourcePath, targetPath, true); } catch (Exception e) { - Console.WriteLine($"Error while copying \"{sourceDiscFolder}\": {e.Message}"); + Console.WriteLine($"Error while copying {discFolder}: {e.Message}"); } } } From 8ee1c0c8b741d1bffcc510d97662cd158f0109dc Mon Sep 17 00:00:00 2001 From: VTXG Date: Mon, 20 Jan 2025 18:44:48 +0000 Subject: [PATCH 7/7] Make review changes --- SyatiModuleBuildTool/DiscUtility.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SyatiModuleBuildTool/DiscUtility.cs b/SyatiModuleBuildTool/DiscUtility.cs index 4aea32c..a3e9c1f 100644 --- a/SyatiModuleBuildTool/DiscUtility.cs +++ b/SyatiModuleBuildTool/DiscUtility.cs @@ -22,7 +22,7 @@ public static void CopyFiles(ModuleInfo module, string output) { try { if (Path.Exists(targetPath)) - Console.WriteLine($" - File will replace {targetPath}"); + Console.WriteLine($"{sourcePath} will replace {targetPath}"); var targetDirectory = Path.GetDirectoryName(targetPath); if (targetDirectory is not null) @@ -31,7 +31,7 @@ public static void CopyFiles(ModuleInfo module, string output) { File.Copy(sourcePath, targetPath, true); } catch (Exception e) { - Console.WriteLine($"Error while copying {discFolder}: {e.Message}"); + Console.WriteLine($"Error while copying \"{discFolder}\": {e.Message}"); } } }