mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 10:18:01 +00:00
Old-format decks will load without exceptions
This commit is contained in:
@@ -23,7 +23,7 @@ public class DeckSerializer {
|
|||||||
FileUtil.writeFile(f, serializeDeck(d));
|
FileUtil.writeFile(f, serializeDeck(d));
|
||||||
}
|
}
|
||||||
|
|
||||||
static DeckFileHeader readDeckMetadata(final Map<String, List<String>> map, final boolean canThrow) {
|
static DeckFileHeader readDeckMetadata(final Map<String, List<String>> map) {
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -33,9 +33,6 @@ public class DeckSerializer {
|
|||||||
}
|
}
|
||||||
final List<String> general = map.get("general");
|
final List<String> general = map.get("general");
|
||||||
if (general != null) {
|
if (general != null) {
|
||||||
if (canThrow) {
|
|
||||||
throw new OldDeckFileFormatException();
|
|
||||||
}
|
|
||||||
final FileSectionManual fs = new FileSectionManual();
|
final FileSectionManual fs = new FileSectionManual();
|
||||||
fs.put(DeckFileHeader.NAME, StringUtils.join(map.get(""), " "));
|
fs.put(DeckFileHeader.NAME, StringUtils.join(map.get(""), " "));
|
||||||
fs.put(DeckFileHeader.DECK_TYPE, StringUtils.join(general, " "));
|
fs.put(DeckFileHeader.DECK_TYPE, StringUtils.join(general, " "));
|
||||||
@@ -66,19 +63,15 @@ public class DeckSerializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Deck fromFile(final File deckFile) {
|
public static Deck fromFile(final File deckFile) {
|
||||||
return fromSections(FileSection.parseSections(FileUtil.readFile(deckFile)), false);
|
return fromSections(FileSection.parseSections(FileUtil.readFile(deckFile)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Deck fromSections(final Map<String, List<String>> sections) {
|
public static Deck fromSections(final Map<String, List<String>> sections) {
|
||||||
return fromSections(sections, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Deck fromSections(final Map<String, List<String>> sections, final boolean canThrowExtendedErrors) {
|
|
||||||
if (sections == null || sections.isEmpty()) {
|
if (sections == null || sections.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final DeckFileHeader dh = readDeckMetadata(sections, canThrowExtendedErrors);
|
final DeckFileHeader dh = readDeckMetadata(sections);
|
||||||
if (dh == null) {
|
if (dh == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ public class DeckStorage extends StorageReaderFolder<Deck> implements IItemSeria
|
|||||||
@Override
|
@Override
|
||||||
protected Deck read(final File file) {
|
protected Deck read(final File file) {
|
||||||
final Map<String, List<String>> sections = FileSection.parseSections(FileUtil.readFile(file));
|
final Map<String, List<String>> sections = FileSection.parseSections(FileUtil.readFile(file));
|
||||||
Deck result = DeckSerializer.fromSections(sections, true);
|
Deck result = DeckSerializer.fromSections(sections);
|
||||||
|
|
||||||
if (moveWronglyNamedDecks) {
|
if (moveWronglyNamedDecks) {
|
||||||
adjustFileLocation(file, result);
|
adjustFileLocation(file, result);
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ public class OldDeckParser {
|
|||||||
|
|
||||||
final List<String> fileLines = FileUtil.readFile(f);
|
final List<String> fileLines = FileUtil.readFile(f);
|
||||||
final Map<String, List<String>> sections = FileSection.parseSections(fileLines);
|
final Map<String, List<String>> sections = FileSection.parseSections(fileLines);
|
||||||
final DeckFileHeader dh = DeckSerializer.readDeckMetadata(sections, false);
|
final DeckFileHeader dh = DeckSerializer.readDeckMetadata(sections);
|
||||||
String name = dh.getName();
|
String name = dh.getName();
|
||||||
|
|
||||||
if (dh.isCustomPool()) {
|
if (dh.isCustomPool()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user