From 632d1d2d9b1fd52a359b8fe01a5f3840a153286a Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Sat, 18 Jul 2020 19:18:08 +0200 Subject: [PATCH] C++: Generate output in a folder --- Il2CppInspector.CLI/Program.cs | 6 +++--- Il2CppInspector.Common/Outputs/CppScaffolding.cs | 11 +++++++++-- Il2CppInspector.GUI/MainWindow.xaml.cs | 14 ++++++-------- Il2CppTests/TestRunner.cs | 4 ++-- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/Il2CppInspector.CLI/Program.cs b/Il2CppInspector.CLI/Program.cs index 83fcc8b..2892f98 100644 --- a/Il2CppInspector.CLI/Program.cs +++ b/Il2CppInspector.CLI/Program.cs @@ -32,8 +32,8 @@ namespace Il2CppInspector.CLI [Option('p', "py-out", Required = false, HelpText = "IDA Python script output file", Default = "ida.py")] public string PythonOutFile { get; set; } - [Option('h', "cpp-out", Required = false, HelpText = "C++ header output file", Default = "il2cpp-types.h")] - public string CppOutFile { get; set; } + [Option('h', "cpp-out", Required = false, HelpText = "C++ scaffolding output path", Default = "cpp")] + public string CppOutPath { get; set; } [Option('e', "exclude-namespaces", Required = false, Separator = ',', HelpText = "Comma-separated list of namespaces to suppress in C# output, or 'none' to include all namespaces", Default = new [] { @@ -263,7 +263,7 @@ namespace Il2CppInspector.CLI // C++ output using (new Benchmark("Generate C++ code")) { - new CppScaffolding(appModel).WriteCppToFile(options.CppOutFile); + new CppScaffolding(appModel).Write(options.CppOutPath); } } diff --git a/Il2CppInspector.Common/Outputs/CppScaffolding.cs b/Il2CppInspector.Common/Outputs/CppScaffolding.cs index 59844f4..bdf668b 100644 --- a/Il2CppInspector.Common/Outputs/CppScaffolding.cs +++ b/Il2CppInspector.Common/Outputs/CppScaffolding.cs @@ -22,8 +22,15 @@ namespace Il2CppInspector.Outputs public CppScaffolding(AppModel model) => this.model = model; - public void WriteCppToFile(string outputFile) { - using var fs = new FileStream(outputFile, FileMode.Create); + public void Write(string outputPath) { + // Ensure output directory exists and is not a file + // A System.IOException will be thrown if it's a file' + Directory.CreateDirectory(outputPath); + + // Write il2cpp-types.h + var typeHeaderFile = Path.Combine(outputPath, "il2cpp-types.h"); + + using var fs = new FileStream(typeHeaderFile, FileMode.Create); writer = new StreamWriter(fs, Encoding.UTF8); writeLine("// Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty"); diff --git a/Il2CppInspector.GUI/MainWindow.xaml.cs b/Il2CppInspector.GUI/MainWindow.xaml.cs index d7224f9..6c3d5fa 100644 --- a/Il2CppInspector.GUI/MainWindow.xaml.cs +++ b/Il2CppInspector.GUI/MainWindow.xaml.cs @@ -419,17 +419,15 @@ namespace Il2CppInspectorGUI // C++ scaffolding case { rdoOutputCpp: var r } when r.IsChecked == true: - var cppSaveFileDialog = new SaveFileDialog { - Filter = "C++ header file (*.h)|*.h|All files (*.*)|*.*", - FileName = "il2cpp-types.h", - CheckFileExists = false, - OverwritePrompt = true + var cppSaveFolderDialog = new VistaFolderBrowserDialog { + Description = "Select save location", + UseDescriptionForTitle = true }; - if (cppSaveFileDialog.ShowDialog() == false) + if (cppSaveFolderDialog.ShowDialog() == false) return; - var cppOutFile = cppSaveFileDialog.FileName; + var cppOutPath = cppSaveFolderDialog.SelectedPath; areaBusyIndicator.Visibility = Visibility.Visible; var selectedCppUnityVersion = ((UnityHeader)cboCppUnityVersion.SelectedItem)?.MinVersion; @@ -439,7 +437,7 @@ namespace Il2CppInspectorGUI model.Build(selectedCppUnityVersion, cppCompiler); OnStatusUpdate(this, "Generating C++ scaffolding"); - new CppScaffolding(model).WriteCppToFile(cppOutFile); + new CppScaffolding(model).Write(cppOutPath); }); break; } diff --git a/Il2CppTests/TestRunner.cs b/Il2CppTests/TestRunner.cs index 7be427f..8511053 100644 --- a/Il2CppTests/TestRunner.cs +++ b/Il2CppTests/TestRunner.cs @@ -57,7 +57,7 @@ namespace Il2CppInspector .WriteScriptToFile(testPath + $@"\test-ida-result{nameSuffix}.py"); new CppScaffolding(appModel) - .WriteCppToFile(testPath + $@"\test-result{nameSuffix}.h"); + .Write(testPath + $@"\test-cpp-result{nameSuffix}"); } // Compare test results with expected results @@ -65,7 +65,7 @@ namespace Il2CppInspector var suffix = (i > 0 ? "-" + i : ""); compareFiles(testPath, suffix + ".cs", $"test-result{suffix}.cs"); - compareFiles(testPath, suffix + ".h", $"test-result{suffix}.h"); + compareFiles(testPath, suffix + ".h", $@"test-cpp-result{suffix}\il2cpp-types.h"); compareFiles(testPath, suffix + ".py", $"test-ida-result{suffix}.py"); } }