From f4a1a21e9ee116b15fb93f49c47164e66561210e Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Fri, 7 Feb 2020 03:52:08 +0100 Subject: [PATCH] GUI: Load metadata file --- Il2CppInspector.GUI/App.xaml | 3 +-- Il2CppInspector.GUI/App.xaml.cs | 20 +++++++++++++++++- Il2CppInspector.GUI/MainWindow.xaml | 27 ++++++++++++++++++------- Il2CppInspector.GUI/MainWindow.xaml.cs | 28 +++++++++++++++++++++----- 4 files changed, 63 insertions(+), 15 deletions(-) diff --git a/Il2CppInspector.GUI/App.xaml b/Il2CppInspector.GUI/App.xaml index 51e3da0..378a7a7 100644 --- a/Il2CppInspector.GUI/App.xaml +++ b/Il2CppInspector.GUI/App.xaml @@ -1,7 +1,6 @@ - diff --git a/Il2CppInspector.GUI/App.xaml.cs b/Il2CppInspector.GUI/App.xaml.cs index f297865..1a3e7d2 100644 --- a/Il2CppInspector.GUI/App.xaml.cs +++ b/Il2CppInspector.GUI/App.xaml.cs @@ -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 { /// /// Interaction logic for App.xaml /// 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 LoadMetadataAsync(string metadataFile) => + Task.Run(() => { + try { + CurrentMetadata = new Metadata(new MemoryStream(File.ReadAllBytes(metadataFile))); + return true; + } + catch (Exception ex) { + LastException = ex; + return false; + } + }); } } diff --git a/Il2CppInspector.GUI/MainWindow.xaml b/Il2CppInspector.GUI/MainWindow.xaml index 7ae10a0..a711b86 100644 --- a/Il2CppInspector.GUI/MainWindow.xaml +++ b/Il2CppInspector.GUI/MainWindow.xaml @@ -1,9 +1,9 @@ - @@ -70,13 +70,26 @@ - Content of window + + + + + + + + + + + + + + + + - - - - + + diff --git a/Il2CppInspector.GUI/MainWindow.xaml.cs b/Il2CppInspector.GUI/MainWindow.xaml.cs index b2eebc3..bd8686c 100644 --- a/Il2CppInspector.GUI/MainWindow.xaml.cs +++ b/Il2CppInspector.GUI/MainWindow.xaml.cs @@ -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 { /// /// Interaction logic for MainWindow.xaml @@ -28,11 +31,26 @@ namespace Il2CppInspector.GUI /// /// Select global metadata file /// - 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; + } } } }