|
@@ -85,37 +85,34 @@ internal class Importer : ObservableObject
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- var doc = PixiParser.Deserialize(path).ToDocument();
|
|
|
+ using var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
|
|
|
+ var pixiDocument = PixiParser.DeserializeUsingCompatible(fileStream);
|
|
|
+
|
|
|
+ var document = pixiDocument switch
|
|
|
+ {
|
|
|
+ Document v5 => v5.ToDocument(),
|
|
|
+ DeprecatedDocument v4 => v4.ToDocument()
|
|
|
+ };
|
|
|
|
|
|
if (associatePath)
|
|
|
{
|
|
|
- doc.FullFilePath = path;
|
|
|
+ document.FullFilePath = path;
|
|
|
}
|
|
|
|
|
|
- return doc;
|
|
|
+ return document;
|
|
|
}
|
|
|
catch (DirectoryNotFoundException)
|
|
|
{
|
|
|
//TODO: Handle
|
|
|
throw new RecoverableException();
|
|
|
}
|
|
|
- catch (InvalidFileException)
|
|
|
+ catch (InvalidFileException e)
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- var doc = DeprecatedPixiParser.Deserialize(path).ToDocument();
|
|
|
-
|
|
|
- if (associatePath)
|
|
|
- {
|
|
|
- doc.FullFilePath = path;
|
|
|
- }
|
|
|
-
|
|
|
- return doc;
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- throw new CorruptedFileException("FAILED_TO_OPEN_FILE", e);
|
|
|
- }
|
|
|
+ throw new CorruptedFileException("FAILED_TO_OPEN_FILE", e);
|
|
|
+ }
|
|
|
+ catch (OldFileFormatException e)
|
|
|
+ {
|
|
|
+ throw new CorruptedFileException("FAILED_TO_OPEN_FILE", e);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -123,22 +120,31 @@ internal class Importer : ObservableObject
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- var doc = PixiParser.Deserialize(file).ToDocument();
|
|
|
- doc.FullFilePath = originalFilePath;
|
|
|
- return doc;
|
|
|
- }
|
|
|
- catch (InvalidFileException)
|
|
|
- {
|
|
|
- try
|
|
|
+ if (!PixiParser.TryGetCompatibleVersion(file, out var parser))
|
|
|
{
|
|
|
- var doc = DeprecatedPixiParser.Deserialize(file).ToDocument();
|
|
|
- doc.FullFilePath = originalFilePath;
|
|
|
- return doc;
|
|
|
+ // TODO: Handle
|
|
|
+ throw new RecoverableException();
|
|
|
}
|
|
|
- catch (InvalidFileException e)
|
|
|
+
|
|
|
+ var pixiDocument = parser.Deserialize(file);
|
|
|
+
|
|
|
+ var document = pixiDocument switch
|
|
|
{
|
|
|
- throw new CorruptedFileException("FAILED_TO_OPEN_FILE", e);
|
|
|
- }
|
|
|
+ Document v5 => v5.ToDocument(),
|
|
|
+ DeprecatedDocument v4 => v4.ToDocument()
|
|
|
+ };
|
|
|
+
|
|
|
+ document.FullFilePath = originalFilePath;
|
|
|
+
|
|
|
+ return document;
|
|
|
+ }
|
|
|
+ catch (InvalidFileException e)
|
|
|
+ {
|
|
|
+ throw new CorruptedFileException("FAILED_TO_OPEN_FILE", e);
|
|
|
+ }
|
|
|
+ catch (OldFileFormatException e)
|
|
|
+ {
|
|
|
+ throw new CorruptedFileException("FAILED_TO_OPEN_FILE", e);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -148,8 +154,13 @@ internal class Importer : ObservableObject
|
|
|
{
|
|
|
throw new InvalidFileTypeException(new LocalizedString("FILE_EXTENSION_NOT_SUPPORTED", Path.GetExtension(path)));
|
|
|
}
|
|
|
+
|
|
|
+ if (Path.GetExtension(path) != ".pixi")
|
|
|
+ return Surface.Load(path);
|
|
|
+
|
|
|
+ using var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
|
|
|
|
|
|
- return Path.GetExtension(path) != ".pixi" ? Surface.Load(path) : PixiParser.Deserialize(path).ToDocument().PreviewSurface;
|
|
|
+ return Surface.Load(PixiParser.ReadPreview(fileStream));
|
|
|
}
|
|
|
|
|
|
public static bool IsSupportedFile(string path)
|