Slightly improve error message when importing wrongly named atch files.

This commit is contained in:
Ottermandias 2025-05-28 13:54:23 +02:00
parent ebe45c6a47
commit 2c115eda94

View file

@ -34,6 +34,7 @@ public sealed class AtchMetaDrawer : MetaDrawer<AtchIdentifier, AtchEntry>, ISer
private AtchFile? _currentBaseAtchFile; private AtchFile? _currentBaseAtchFile;
private AtchPoint? _currentBaseAtchPoint; private AtchPoint? _currentBaseAtchPoint;
private readonly AtchPointCombo _combo; private readonly AtchPointCombo _combo;
private string _fileImport = string.Empty;
public AtchMetaDrawer(ModMetaEditor editor, MetaFileManager metaFiles) public AtchMetaDrawer(ModMetaEditor editor, MetaFileManager metaFiles)
: base(editor, metaFiles) : base(editor, metaFiles)
@ -48,6 +49,8 @@ public sealed class AtchMetaDrawer : MetaDrawer<AtchIdentifier, AtchEntry>, ISer
=> obj.ToName(); => obj.ToName();
} }
private sealed class RaceCodeException(string filePath) : Exception($"Could not identify race code from path {filePath}.");
public void ImportFile(string filePath) public void ImportFile(string filePath)
{ {
try try
@ -57,14 +60,15 @@ public sealed class AtchMetaDrawer : MetaDrawer<AtchIdentifier, AtchEntry>, ISer
var gr = Parser.ParseRaceCode(filePath); var gr = Parser.ParseRaceCode(filePath);
if (gr is GenderRace.Unknown) if (gr is GenderRace.Unknown)
throw new Exception($"Could not identify race code from path {filePath}."); throw new RaceCodeException(filePath);
var text = File.ReadAllBytes(filePath);
var file = new AtchFile(text); var text = File.ReadAllBytes(filePath);
var file = new AtchFile(text);
foreach (var point in file.Points) foreach (var point in file.Points)
{ {
foreach (var (entry, index) in point.Entries.WithIndex()) 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); var defaultValue = AtchCache.GetDefault(MetaFiles, identifier);
if (defaultValue == null) if (defaultValue == null)
continue; continue;
@ -76,6 +80,12 @@ public sealed class AtchMetaDrawer : MetaDrawer<AtchIdentifier, AtchEntry>, 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) catch (Exception ex)
{ {
Penumbra.Messager.AddMessage(new Notification(ex, "Unable to import .atch file.", "Could not import .atch file:", 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<AtchIdentifier, AtchEntry>, ISer
private void UpdateFile() private void UpdateFile()
{ {
_currentBaseAtchFile = MetaFiles.AtchManager.AtchFileBase[Identifier.GenderRace]; _currentBaseAtchFile = MetaFiles.AtchManager.AtchFileBase[Identifier.GenderRace];
_currentBaseAtchPoint = _currentBaseAtchFile.GetPoint(Identifier.Type); _currentBaseAtchPoint = _currentBaseAtchFile.GetPoint(Identifier.Type);
if (_currentBaseAtchPoint == null) if (_currentBaseAtchPoint == null)
{ {
_currentBaseAtchPoint = _currentBaseAtchFile.Points.First(); _currentBaseAtchPoint = _currentBaseAtchFile.Points.First();
Identifier = Identifier with { Type = _currentBaseAtchPoint.Type }; Identifier = Identifier with { Type = _currentBaseAtchPoint.Type };
} }
if (Identifier.EntryIndex >= _currentBaseAtchPoint.Entries.Length) if (Identifier.EntryIndex >= _currentBaseAtchPoint.Entries.Length)