|
@@ -1,6 +1,7 @@
|
|
using System.IO;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Text;
|
|
using System.Xml;
|
|
using System.Xml;
|
|
|
|
+using PixiEditor.Exceptions;
|
|
|
|
|
|
namespace PixiEditor.Models.Commands.Templates.Parsers;
|
|
namespace PixiEditor.Models.Commands.Templates.Parsers;
|
|
|
|
|
|
@@ -30,12 +31,12 @@ public class AsepriteKeysParser : KeysParser
|
|
{
|
|
{
|
|
if (!File.Exists(path))
|
|
if (!File.Exists(path))
|
|
{
|
|
{
|
|
- throw new FileNotFoundException("File not found", path);
|
|
|
|
|
|
+ throw new MissingFileException("File not found", path);
|
|
}
|
|
}
|
|
|
|
|
|
if (Path.GetExtension(path) != ".aseprite-keys")
|
|
if (Path.GetExtension(path) != ".aseprite-keys")
|
|
{
|
|
{
|
|
- throw new ArgumentException("File is not aseprite-keys file", nameof(path));
|
|
|
|
|
|
+ throw new InvalidFileFormatException("File is not aseprite-keys file", path);
|
|
}
|
|
}
|
|
|
|
|
|
return LoadAndParse(path, applyDefaults);
|
|
return LoadAndParse(path, applyDefaults);
|
|
@@ -44,15 +45,33 @@ public class AsepriteKeysParser : KeysParser
|
|
private ShortcutsTemplate LoadAndParse(string path, bool applyDefaults)
|
|
private ShortcutsTemplate LoadAndParse(string path, bool applyDefaults)
|
|
{
|
|
{
|
|
XmlDocument doc = new XmlDocument();
|
|
XmlDocument doc = new XmlDocument();
|
|
- doc.Load(path);
|
|
|
|
|
|
+
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ doc.Load(path);
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e) when (e is DirectoryNotFoundException or FileNotFoundException or PathTooLongException)
|
|
|
|
+ {
|
|
|
|
+ throw new MissingFileException("File not found", e);
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e)
|
|
|
|
+ {
|
|
|
|
+ throw new RecoverableException("Error while reading the file", e);
|
|
|
|
+ }
|
|
|
|
|
|
List<KeyDefinition> keyDefinitions = new List<KeyDefinition>(); // DefaultShortcut is actually mapped shortcut.
|
|
List<KeyDefinition> keyDefinitions = new List<KeyDefinition>(); // DefaultShortcut is actually mapped shortcut.
|
|
|
|
|
|
LoadCommands(doc, keyDefinitions, applyDefaults);
|
|
LoadCommands(doc, keyDefinitions, applyDefaults);
|
|
LoadTools(doc, keyDefinitions, applyDefaults);
|
|
LoadTools(doc, keyDefinitions, applyDefaults);
|
|
-
|
|
|
|
- ShortcutsTemplate template = ShortcutsTemplate.FromKeyDefinitions(keyDefinitions);
|
|
|
|
- return template;
|
|
|
|
|
|
+
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ return ShortcutsTemplate.FromKeyDefinitions(keyDefinitions);
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e)
|
|
|
|
+ {
|
|
|
|
+ throw new InvalidFileFormatException("The file contains an invalid shortcut", e);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
private void LoadCommands(XmlDocument document, List<KeyDefinition> keyDefinitions, bool applyDefaults)
|
|
private void LoadCommands(XmlDocument document, List<KeyDefinition> keyDefinitions, bool applyDefaults)
|