GUI: Load metadata file

This commit is contained in:
Katy Coe
2020-02-07 03:52:08 +01:00
parent 8683da1a22
commit f4a1a21e9e
4 changed files with 63 additions and 15 deletions

View File

@@ -1,7 +1,6 @@
<Application x:Class="App"
<Application x:Class="Il2CppInspectorGUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Il2CppInspector.GUI"
StartupUri="MainWindow.xaml">
<Application.Resources>

View File

@@ -2,16 +2,34 @@
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using Il2CppInspector;
namespace Il2CppInspector.GUI
namespace Il2CppInspectorGUI
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
public Metadata CurrentMetadata { get; private set; }
public Exception LastException { get; private set; }
// Attempt to load an IL2CPP metadata file
public Task<bool> LoadMetadataAsync(string metadataFile) =>
Task.Run(() => {
try {
CurrentMetadata = new Metadata(new MemoryStream(File.ReadAllBytes(metadataFile)));
return true;
}
catch (Exception ex) {
LastException = ex;
return false;
}
});
}
}

View File

@@ -1,9 +1,9 @@
<Window x:Class="Il2CppInspector.GUI.MainWindow"
<Window x:Class="Il2CppInspectorGUI.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Il2CppInspector.GUI"
xmlns:local="clr-namespace:Il2CppInspectorGUI"
mc:Ignorable="d"
Title="Il2CppInspector" Height="450" Width="800" Background="White">
<Window.Resources>
@@ -70,13 +70,26 @@
<Grid>
<!-- Main content -->
<Grid>
<TextBlock>Content of window</TextBlock>
<!-- Information about the loaded metadata and binary -->
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height ="Auto" />
<RowDefinition Height ="Auto" />
<RowDefinition Height ="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25*"></ColumnDefinition>
<ColumnDefinition Width="25*"></ColumnDefinition>
<ColumnDefinition Width="25*"></ColumnDefinition>
<ColumnDefinition Width="25*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Content="IL2CPP Metadata version"></Label>
<Label Name="lblMetadataVersion" Grid.Row="0" Grid.Column="1" Content="{Binding Path=Version}"></Label>
</Grid>
</Grid>
<!-- Light boxes -->
<Grid Name="areaLoadMetadata">
<Rectangle Name="rectModalLightBoxBackground" Fill="Black" Opacity="0.4"></Rectangle>
<Button Name="btnSelectMetadataFile" Style="{StaticResource LightBoxButton}" Click="BtnSelectMetadataFile_OnClick">Select an IL2CPP metadata file</Button>
</Grid>
<Rectangle Name="rectModalLightBoxBackground" Fill="Black" Opacity="0.4"></Rectangle>
<Button Name="btnSelectMetadataFile" Style="{StaticResource LightBoxButton}" Click="BtnSelectMetadataFile_OnClick">Select an IL2CPP metadata file</Button>
</Grid>
</Window>

View File

@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
@@ -13,8 +15,9 @@ using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;
using Il2CppInspector;
namespace Il2CppInspector.GUI
namespace Il2CppInspectorGUI
{
/// <summary>
/// Interaction logic for MainWindow.xaml
@@ -28,11 +31,26 @@ namespace Il2CppInspector.GUI
/// <summary>
/// Select global metadata file
/// </summary>
private void BtnSelectMetadataFile_OnClick(object sender, RoutedEventArgs e) {
var openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "IL2CPP global metadata file|global-metadata.dat|All files (*.*)|*.*";
private async void BtnSelectMetadataFile_OnClick(object sender, RoutedEventArgs e) {
var app = (App) Application.Current;
var openFileDialog = new OpenFileDialog {
Filter = "IL2CPP global metadata file|global-metadata.dat|All files (*.*)|*.*",
CheckFileExists = true
};
btnSelectMetadataFile.Visibility = Visibility.Hidden;
if (openFileDialog.ShowDialog() == true) {
// openFileDialog.FileName
// Load the metadata file
if (await app.LoadMetadataAsync(openFileDialog.FileName)) {
// Metadata loaded successfully
lblMetadataVersion.DataContext = app.CurrentMetadata;
}
else {
MessageBox.Show(this, app.LastException.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
btnSelectMetadataFile.Visibility = Visibility.Visible;
}
}
}
}