C++: Generate output in a folder

This commit is contained in:
Katy Coe
2020-07-18 19:18:08 +02:00
parent e74663a2ba
commit 632d1d2d9b
4 changed files with 20 additions and 15 deletions

View File

@@ -32,8 +32,8 @@ namespace Il2CppInspector.CLI
[Option('p', "py-out", Required = false, HelpText = "IDA Python script output file", Default = "ida.py")] [Option('p', "py-out", Required = false, HelpText = "IDA Python script output file", Default = "ida.py")]
public string PythonOutFile { get; set; } public string PythonOutFile { get; set; }
[Option('h', "cpp-out", Required = false, HelpText = "C++ header output file", Default = "il2cpp-types.h")] [Option('h', "cpp-out", Required = false, HelpText = "C++ scaffolding output path", Default = "cpp")]
public string CppOutFile { get; set; } 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", [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 [] { Default = new [] {
@@ -263,7 +263,7 @@ namespace Il2CppInspector.CLI
// C++ output // C++ output
using (new Benchmark("Generate C++ code")) { using (new Benchmark("Generate C++ code")) {
new CppScaffolding(appModel).WriteCppToFile(options.CppOutFile); new CppScaffolding(appModel).Write(options.CppOutPath);
} }
} }

View File

@@ -22,8 +22,15 @@ namespace Il2CppInspector.Outputs
public CppScaffolding(AppModel model) => this.model = model; public CppScaffolding(AppModel model) => this.model = model;
public void WriteCppToFile(string outputFile) { public void Write(string outputPath) {
using var fs = new FileStream(outputFile, FileMode.Create); // 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); writer = new StreamWriter(fs, Encoding.UTF8);
writeLine("// Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty"); writeLine("// Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty");

View File

@@ -419,17 +419,15 @@ namespace Il2CppInspectorGUI
// C++ scaffolding // C++ scaffolding
case { rdoOutputCpp: var r } when r.IsChecked == true: case { rdoOutputCpp: var r } when r.IsChecked == true:
var cppSaveFileDialog = new SaveFileDialog { var cppSaveFolderDialog = new VistaFolderBrowserDialog {
Filter = "C++ header file (*.h)|*.h|All files (*.*)|*.*", Description = "Select save location",
FileName = "il2cpp-types.h", UseDescriptionForTitle = true
CheckFileExists = false,
OverwritePrompt = true
}; };
if (cppSaveFileDialog.ShowDialog() == false) if (cppSaveFolderDialog.ShowDialog() == false)
return; return;
var cppOutFile = cppSaveFileDialog.FileName; var cppOutPath = cppSaveFolderDialog.SelectedPath;
areaBusyIndicator.Visibility = Visibility.Visible; areaBusyIndicator.Visibility = Visibility.Visible;
var selectedCppUnityVersion = ((UnityHeader)cboCppUnityVersion.SelectedItem)?.MinVersion; var selectedCppUnityVersion = ((UnityHeader)cboCppUnityVersion.SelectedItem)?.MinVersion;
@@ -439,7 +437,7 @@ namespace Il2CppInspectorGUI
model.Build(selectedCppUnityVersion, cppCompiler); model.Build(selectedCppUnityVersion, cppCompiler);
OnStatusUpdate(this, "Generating C++ scaffolding"); OnStatusUpdate(this, "Generating C++ scaffolding");
new CppScaffolding(model).WriteCppToFile(cppOutFile); new CppScaffolding(model).Write(cppOutPath);
}); });
break; break;
} }

View File

@@ -57,7 +57,7 @@ namespace Il2CppInspector
.WriteScriptToFile(testPath + $@"\test-ida-result{nameSuffix}.py"); .WriteScriptToFile(testPath + $@"\test-ida-result{nameSuffix}.py");
new CppScaffolding(appModel) new CppScaffolding(appModel)
.WriteCppToFile(testPath + $@"\test-result{nameSuffix}.h"); .Write(testPath + $@"\test-cpp-result{nameSuffix}");
} }
// Compare test results with expected results // Compare test results with expected results
@@ -65,7 +65,7 @@ namespace Il2CppInspector
var suffix = (i > 0 ? "-" + i : ""); var suffix = (i > 0 ? "-" + i : "");
compareFiles(testPath, suffix + ".cs", $"test-result{suffix}.cs"); 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"); compareFiles(testPath, suffix + ".py", $"test-ida-result{suffix}.py");
} }
} }