diff --git a/App.xaml.cs b/App.xaml.cs index c229593..fad04d7 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -18,6 +18,7 @@ namespace HashCalculator.GUI { var core = new TechnologyAssemblerCoreModule(); core.Initialize(); + TracerListener.StartListening(); DispatcherUnhandledException += (s, e) => Program.ErrorBox($"SAGE FastHash 计算器遇上了未处理的错误:{e.Exception}"); } } diff --git a/AssetEntry.cs b/AssetEntry.cs index c708f91..97983bd 100644 --- a/AssetEntry.cs +++ b/AssetEntry.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Threading; using System.Xml.Linq; using TechnologyAssembler.Core.Assets; @@ -34,6 +33,30 @@ namespace HashCalculator.GUI } } + public static AssetEntry? TryParse(XElement element) + { + if (element == null) + { + return null; + } + + if (element.Name.Namespace != ModXml.EalaAsset) + { + TracerListener.WriteLine($"Unknown namespace: {element.Name.Namespace}"); + } + + try + { + return new AssetEntry(element); + } + catch (Exception e) + { + TracerListener.WriteLine($"Failed to parse element: {e}"); + } + + return null; + } + public AssetEntry(XElement element) { if (element == null) diff --git a/Controller.cs b/Controller.cs index ec51f21..37d427c 100644 --- a/Controller.cs +++ b/Controller.cs @@ -1,14 +1,12 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; -using TechnologyAssembler.Core.IO; using TechnologyAssembler.Core.Assets; +using TechnologyAssembler.Core.IO; using TechnologyAssembler.Core.Language.Providers; namespace HashCalculator.GUI @@ -29,11 +27,6 @@ namespace HashCalculator.GUI ViewModel = viewModel; } - public void StartTrace(Action action) - { - TracerListener.StartListening(s => action(() => ViewModel.TraceText += s)); - } - public async Task OnMainInputDecided(InputEntry selected) { try @@ -41,7 +34,7 @@ namespace HashCalculator.GUI _currentBig?.Dispose(); _currentBig = null; ClearEntries(); - ViewModel.TraceText = string.Empty; + ViewModel.ClearTraceText.Execute(null); ViewModel.BigEntryInput.AllManifests = null; ViewModel.IsXml = false; @@ -50,7 +43,7 @@ namespace HashCalculator.GUI case InputEntryType.BinaryFile: ViewModel.StatusText = "请留意一下弹出的窗口("; CopyableBox.ShowDialog("SAGE FastHash 计算器", token => CalculateBinaryHash(selected.Value, token)); - ViewModel.StatusText = ViewModel.SuggestionString(string.Empty); + ViewModel.StatusText = string.Empty; return; case InputEntryType.BigFile: await LoadBig(selected.Value).ConfigureAwait(true); @@ -77,6 +70,11 @@ namespace HashCalculator.GUI } } + public Task RequestOpenFile(string title, params (string Extension, string? Description)[] filters) + { + return ViewModel.RequestOpenFile(title, filters); + } + private static Task CalculateBinaryHash(string filePath, CancellationToken cancel) { return Task.Run(() => @@ -233,7 +231,12 @@ namespace HashCalculator.GUI private async Task LoadXmlInternal(string path, CancellationToken token) { - var modXml = new ModXml(path, token); + if (ModXml.LocateSdkFromRegistry() is not { } sdkRoot) + { + var studio = await RequestOpenFile("选择 Mod Studio", ("EALAModStudio.exe", null)); + sdkRoot = Path.GetDirectoryName(studio); + } + var modXml = new ModXml(path, sdkRoot, token); try { @@ -380,7 +383,8 @@ namespace HashCalculator.GUI private void AddEntry(AssetEntry entry) { _loadedAssets.Add(entry); - ViewModel.AddNewItems(Enumerable.Repeat(entry, 1)); + + ViewModel.AddNewItems(new[] { entry }); } private void AddEntries(IEnumerable entries) diff --git a/HashCalculator.GUI.csproj b/HashCalculator.GUI.csproj index 687f37d..45efdcb 100644 --- a/HashCalculator.GUI.csproj +++ b/HashCalculator.GUI.csproj @@ -3,7 +3,7 @@ true WinExe net5.0-windows - 8.0 + latest enable true AnyCPU;x86 diff --git a/MainWindow.xaml b/MainWindow.xaml index ab1ad39..d9cffb4 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -6,7 +6,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:l="clr-namespace:HashCalculator.GUI" - xmlns:c="clr-namespace:HashCalculator.GUI.Converters" mc:Ignorable="d" Title="SAGE FastHash 哈希计算器" Height="600" @@ -123,11 +122,30 @@ Height="25" Margin="0,5,0,0" > - + > + + + + 红警3吧发帖寻找岚依( - -