make inspector version a server api, split up output subtypes and tweak some option names

This commit is contained in:
LukeFZ
2025-07-29 23:46:14 +02:00
parent 6583787d8f
commit 832b0020eb
13 changed files with 57 additions and 56 deletions

View File

@@ -2,7 +2,7 @@ using Microsoft.AspNetCore.SignalR;
namespace Il2CppInspector.Redux.FrontendCore; namespace Il2CppInspector.Redux.FrontendCore;
internal class Il2CppHub : Hub public class Il2CppHub : Hub
{ {
private const string ContextKey = "context"; private const string ContextKey = "context";
@@ -51,4 +51,8 @@ internal class Il2CppHub : Hub
{ {
await State.ExportIl2CppFiles(Client, outputDirectory); await State.ExportIl2CppFiles(Client, outputDirectory);
} }
public async Task<string> GetInspectorVersion()
{
return await UiContext.GetInspectorVersion();
}
} }

View File

@@ -0,0 +1,10 @@
namespace Il2CppInspector.Redux.FrontendCore.Outputs;
public enum CSharpLayout
{
SingleFile,
Namespace,
Assembly,
Class,
Tree
}

View File

@@ -7,28 +7,13 @@ public class CSharpStubOutput : IOutputFormatProvider
{ {
public static string Id => "cs"; public static string Id => "cs";
private enum CSharpLayout
{
SingleFile,
Namespace,
Assembly,
Class,
Tree
}
private enum TypeSortingMode
{
Alphabetical,
TypeDefinitionIndex
}
private class Settings(Dictionary<string, string> settings) private class Settings(Dictionary<string, string> settings)
{ {
public readonly CSharpLayout Layout = settings.GetAsEnumOrDefault("layout", CSharpLayout.SingleFile); public readonly CSharpLayout Layout = settings.GetAsEnumOrDefault("layout", CSharpLayout.SingleFile);
public readonly bool FlattenHierarchy = settings.GetAsBooleanOrDefault("flatten", false); public readonly bool FlattenHierarchy = settings.GetAsBooleanOrDefault("flattenhierarchy", false);
public readonly TypeSortingMode SortingMode = settings.GetAsEnumOrDefault("sorting", TypeSortingMode.Alphabetical); public readonly TypeSortingMode SortingMode = settings.GetAsEnumOrDefault("sortingmode", TypeSortingMode.Alphabetical);
public readonly bool SuppressMetadata = settings.GetAsBooleanOrDefault("suppressmetadata", false); public readonly bool SuppressMetadata = settings.GetAsBooleanOrDefault("suppressmetadata", false);
public readonly bool MustCompile = settings.GetAsBooleanOrDefault("compilable", false); public readonly bool MustCompile = settings.GetAsBooleanOrDefault("mustcompile", false);
public readonly bool SeperateAssemblyAttributes = settings.GetAsBooleanOrDefault("seperateassemblyattributes", true); public readonly bool SeperateAssemblyAttributes = settings.GetAsBooleanOrDefault("seperateassemblyattributes", true);
} }

View File

@@ -9,14 +9,6 @@ public class DisassemblerMetadataOutput : IOutputFormatProvider
{ {
public static string Id => "disassemblermetadata"; public static string Id => "disassemblermetadata";
private enum DisassemblerType
{
IDA,
Ghidra,
BinaryNinja,
None
}
private class Settings(Dictionary<string, string> dict) private class Settings(Dictionary<string, string> dict)
{ {
public readonly DisassemblerType Disassembler = dict.GetAsEnumOrDefault("disassembler", DisassemblerType.IDA); public readonly DisassemblerType Disassembler = dict.GetAsEnumOrDefault("disassembler", DisassemblerType.IDA);

View File

@@ -0,0 +1,9 @@
namespace Il2CppInspector.Redux.FrontendCore.Outputs;
public enum DisassemblerType
{
IDA,
Ghidra,
BinaryNinja,
None
}

View File

@@ -0,0 +1,7 @@
namespace Il2CppInspector.Redux.FrontendCore.Outputs;
public enum TypeSortingMode
{
Alphabetical,
TypeDefinitionIndex
}

View File

@@ -10,7 +10,7 @@ public class VsSolutionOutput : IOutputFormatProvider
private class Settings(Dictionary<string, string> settings) private class Settings(Dictionary<string, string> settings)
{ {
public readonly string UnityPath = settings.GetValueOrDefault("unitypath", ""); public readonly string UnityPath = settings.GetValueOrDefault("unitypath", "");
public readonly string UnityAssembliesPath = settings.GetValueOrDefault("assembliespath", ""); public readonly string UnityAssembliesPath = settings.GetValueOrDefault("unityassembliespath", "");
} }
public async Task Export(AppModel model, UiClient client, string outputPath, Dictionary<string, string> settingsDict) public async Task Export(AppModel model, UiClient client, string outputPath, Dictionary<string, string> settingsDict)

View File

@@ -41,7 +41,4 @@ public class UiClient(ISingleClientProxy client)
public async Task OnImportCompleted(CancellationToken cancellationToken = default) public async Task OnImportCompleted(CancellationToken cancellationToken = default)
=> await client.SendAsync(nameof(OnImportCompleted), cancellationToken); => await client.SendAsync(nameof(OnImportCompleted), cancellationToken);
public async Task SetInspectorVersion(string version, CancellationToken cancellationToken = default)
=> await client.SendAsync(nameof(SetInspectorVersion), version, cancellationToken);
} }

View File

@@ -47,10 +47,8 @@ public class UiContext
try try
{ {
var file = FileFormatStream.Load(stream, _loadOptions, client.EventHandler); var file = FileFormatStream.Load(stream, _loadOptions, client.EventHandler)
?? throw new InvalidOperationException("Failed to determine binary file format.");
if (file == null)
throw new InvalidOperationException("Failed to determine binary file format.");
if (file.NumImages == 0) if (file.NumImages == 0)
throw new InvalidOperationException("Failed to find any binary images in the file"); throw new InvalidOperationException("Failed to find any binary images in the file");
@@ -122,7 +120,6 @@ public class UiContext
public async Task Initialize(UiClient client, CancellationToken cancellationToken = default) public async Task Initialize(UiClient client, CancellationToken cancellationToken = default)
{ {
await client.ShowSuccessToast("SignalR initialized!", cancellationToken); await client.ShowSuccessToast("SignalR initialized!", cancellationToken);
await client.SetInspectorVersion(typeof(UiContext).Assembly.GetAssemblyVersion() ?? "<unknown>", cancellationToken);
} }
public async Task LoadInputFiles(UiClient client, List<string> inputFiles, public async Task LoadInputFiles(UiClient client, List<string> inputFiles,
@@ -200,16 +197,16 @@ public class UiContext
{ {
var model = _appModels[0]; var model = _appModels[0];
foreach (var queuedExport in _queuedExports) foreach (var (formatId, outputDirectory, settings) in _queuedExports)
{ {
try try
{ {
var outputFormat = OutputFormatRegistry.GetOutputFormat(queuedExport.FormatId); var outputFormat = OutputFormatRegistry.GetOutputFormat(formatId);
await outputFormat.Export(model, client, queuedExport.OutputDirectory, queuedExport.Settings); await outputFormat.Export(model, client, outputDirectory, settings);
} }
catch (Exception ex) catch (Exception ex)
{ {
await client.ShowErrorToast($"Export for format {queuedExport.FormatId} failed: {ex}", await client.ShowErrorToast($"Export for format {formatId} failed: {ex}",
cancellationToken); cancellationToken);
} }
} }
@@ -246,4 +243,9 @@ public class UiContext
}, cancellationToken); }, cancellationToken);
} }
} }
public static Task<string> GetInspectorVersion()
{
return Task.FromResult(typeof(UiContext).Assembly.GetAssemblyVersion() ?? "<unknown>");
}
} }

View File

@@ -6,14 +6,11 @@
$effect(() => { $effect(() => {
if (signalRState.api === undefined) return; if (signalRState.api === undefined) return;
const unregisterSetInspectorVersion = if (inspectorVersion === undefined) {
signalRState.api.client.onSetInspectorVersion(async (version) => { signalRState.api.server.getInspectorVersion().then((version) => {
inspectorVersion = version; inspectorVersion = version;
}); });
}
return () => {
unregisterSetInspectorVersion();
};
}); });
</script> </script>

View File

@@ -45,12 +45,6 @@ export class SignalRClientApi {
return this.registerHandler("OnImportCompleted", handler); return this.registerHandler("OnImportCompleted", handler);
} }
onSetInspectorVersion(
handler: (version: string) => Promise<void>,
): () => void {
return this.registerHandler("SetInspectorVersion", handler);
}
private registerHandler( private registerHandler(
name: string, name: string,
handler: (...args: any[]) => Promise<void>, handler: (...args: any[]) => Promise<void>,

View File

@@ -41,4 +41,8 @@ export class SignalRServerApi {
async exportIl2CppFiles(targetDirectory: string) { async exportIl2CppFiles(targetDirectory: string) {
return await this.connection.send("ExportIl2CppFiles", targetDirectory); return await this.connection.send("ExportIl2CppFiles", targetDirectory);
} }
async getInspectorVersion(): Promise<string> {
return await this.connection.invoke<string>("GetInspectorVersion");
}
} }

View File

@@ -43,7 +43,7 @@ let mockFormatSettings: {
{ {
type: "option", type: "option",
name: { name: {
id: "flatten", id: "flattenhierarchy",
label: "Don't nest folders (flatten hierarchy)", label: "Don't nest folders (flatten hierarchy)",
}, },
default: false, default: false,
@@ -55,7 +55,7 @@ let mockFormatSettings: {
{ {
type: "combobox", type: "combobox",
name: { name: {
id: "sorting", id: "sortingmode",
label: "Type sorting", label: "Type sorting",
}, },
default: "alphabetical", default: "alphabetical",
@@ -85,7 +85,7 @@ let mockFormatSettings: {
{ {
type: "option", type: "option",
name: { name: {
id: "compilable", id: "mustcompile",
label: "Attempt to generate output that compiles", label: "Attempt to generate output that compiles",
}, },
default: false, default: false,
@@ -117,7 +117,7 @@ let mockFormatSettings: {
{ {
type: "filepath", type: "filepath",
name: { name: {
id: "assembliespath", id: "unityassembliespath",
label: "Unity script assemblies path", label: "Unity script assemblies path",
}, },
directoryPath: true, directoryPath: true,