From 2c115eda9426e53ffbcd06b494077b5863b17f3d Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Wed, 28 May 2025 13:54:23 +0200 Subject: [PATCH] Slightly improve error message when importing wrongly named atch files. --- .../UI/AdvancedWindow/Meta/AtchMetaDrawer.cs | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Penumbra/UI/AdvancedWindow/Meta/AtchMetaDrawer.cs b/Penumbra/UI/AdvancedWindow/Meta/AtchMetaDrawer.cs index 5bc70fc3..5b6d585a 100644 --- a/Penumbra/UI/AdvancedWindow/Meta/AtchMetaDrawer.cs +++ b/Penumbra/UI/AdvancedWindow/Meta/AtchMetaDrawer.cs @@ -34,6 +34,7 @@ public sealed class AtchMetaDrawer : MetaDrawer, ISer private AtchFile? _currentBaseAtchFile; private AtchPoint? _currentBaseAtchPoint; private readonly AtchPointCombo _combo; + private string _fileImport = string.Empty; public AtchMetaDrawer(ModMetaEditor editor, MetaFileManager metaFiles) : base(editor, metaFiles) @@ -48,6 +49,8 @@ public sealed class AtchMetaDrawer : MetaDrawer, ISer => obj.ToName(); } + private sealed class RaceCodeException(string filePath) : Exception($"Could not identify race code from path {filePath}."); + public void ImportFile(string filePath) { try @@ -57,14 +60,15 @@ public sealed class AtchMetaDrawer : MetaDrawer, ISer var gr = Parser.ParseRaceCode(filePath); if (gr is GenderRace.Unknown) - throw new Exception($"Could not identify race code from path {filePath}."); - var text = File.ReadAllBytes(filePath); - var file = new AtchFile(text); + throw new RaceCodeException(filePath); + + var text = File.ReadAllBytes(filePath); + var file = new AtchFile(text); foreach (var point in file.Points) { foreach (var (entry, index) in point.Entries.WithIndex()) { - var identifier = new AtchIdentifier(point.Type, gr, (ushort) index); + var identifier = new AtchIdentifier(point.Type, gr, (ushort)index); var defaultValue = AtchCache.GetDefault(MetaFiles, identifier); if (defaultValue == null) continue; @@ -76,6 +80,12 @@ public sealed class AtchMetaDrawer : MetaDrawer, ISer } } } + catch (RaceCodeException ex) + { + Penumbra.Messager.AddMessage(new Notification(ex, "The imported .atch file does not contain a race code (cXXXX) in its name.", + "Could not import .atch file:", + NotificationType.Warning)); + } catch (Exception ex) { Penumbra.Messager.AddMessage(new Notification(ex, "Unable to import .atch file.", "Could not import .atch file:", @@ -157,12 +167,12 @@ public sealed class AtchMetaDrawer : MetaDrawer, ISer private void UpdateFile() { - _currentBaseAtchFile = MetaFiles.AtchManager.AtchFileBase[Identifier.GenderRace]; + _currentBaseAtchFile = MetaFiles.AtchManager.AtchFileBase[Identifier.GenderRace]; _currentBaseAtchPoint = _currentBaseAtchFile.GetPoint(Identifier.Type); if (_currentBaseAtchPoint == null) { _currentBaseAtchPoint = _currentBaseAtchFile.Points.First(); - Identifier = Identifier with { Type = _currentBaseAtchPoint.Type }; + Identifier = Identifier with { Type = _currentBaseAtchPoint.Type }; } if (Identifier.EntryIndex >= _currentBaseAtchPoint.Entries.Length)