mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
Improve resilience for Quest Loading
This commit is contained in:
@@ -28,6 +28,7 @@ import java.awt.event.KeyEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -230,7 +231,11 @@ public enum FControl implements KeyEventDispatcher {
|
||||
final String questname = FModel.getQuestPreferences().getPref(QPref.CURRENT_QUEST);
|
||||
final File data = new File(dirQuests.getPath(), questname);
|
||||
if (data.exists()) {
|
||||
try {
|
||||
FModel.getQuest().load(QuestDataIO.loadData(data));
|
||||
} catch(IOException ex) {
|
||||
System.out.println(String.format("Error loading quest data (%s).. skipping for now..", questname));
|
||||
}
|
||||
}
|
||||
|
||||
// Handles resizing in null layouts of layers in JLayeredPane as well as saving window layout
|
||||
|
||||
@@ -20,6 +20,7 @@ import forge.toolbox.FOptionPane;
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@@ -167,6 +168,7 @@ public enum CSubmenuQuestData implements ICDoc {
|
||||
final VSubmenuQuestData view = VSubmenuQuestData.SINGLETON_INSTANCE;
|
||||
final File dirQuests = new File(ForgeConstants.QUEST_SAVE_DIR);
|
||||
final QuestController qc = FModel.getQuest();
|
||||
ArrayList<String> restorableQuests = new ArrayList<>();
|
||||
|
||||
// Iterate over files and load quest data for each.
|
||||
final FilenameFilter takeDatFiles = new FilenameFilter() {
|
||||
@@ -178,7 +180,13 @@ public enum CSubmenuQuestData implements ICDoc {
|
||||
final File[] arrFiles = dirQuests.listFiles(takeDatFiles);
|
||||
arrQuests.clear();
|
||||
for (final File f : arrFiles) {
|
||||
try {
|
||||
System.out.println(String.format("About to load quest (%s)... ", f.getName()));
|
||||
arrQuests.put(f.getName(), QuestDataIO.loadData(f));
|
||||
} catch(IOException ex) {
|
||||
System.out.println(String.format("Error loading quest data (%s).. skipping for now..", f.getName()));
|
||||
restorableQuests.add(f.getName());
|
||||
}
|
||||
}
|
||||
|
||||
// Populate list with available quest data.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package forge.screens.quest;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import forge.FThreads;
|
||||
import forge.Forge;
|
||||
@@ -190,7 +191,14 @@ public class QuestMenu extends FPopupMenu implements IVQuestStats {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void run() {
|
||||
try {
|
||||
FModel.getQuest().load(QuestDataIO.loadData(data));
|
||||
} catch (IOException e) {
|
||||
System.err.println(String.format("Failed to load quest '%s'", questname));
|
||||
// Failed to load last quest, don't continue with quest loading stuff
|
||||
return;
|
||||
}
|
||||
|
||||
((DeckController<Deck>)EditorType.Quest.getController()).setRootFolder(FModel.getQuest().getMyDecks());
|
||||
((DeckController<DeckGroup>)EditorType.QuestDraft.getController()).setRootFolder(FModel.getQuest().getDraftDecks());
|
||||
if (reason == LaunchReason.StartQuestMode) {
|
||||
|
||||
@@ -98,8 +98,7 @@ public class QuestDataIO {
|
||||
*   {@link java.io.File}
|
||||
* @return {@link forge.quest.data.QuestData}
|
||||
*/
|
||||
public static QuestData loadData(final File xmlSaveFile) {
|
||||
try {
|
||||
public static QuestData loadData(final File xmlSaveFile) throws IOException {
|
||||
QuestData data;
|
||||
|
||||
final GZIPInputStream zin = new GZIPInputStream(new FileInputStream(xmlSaveFile));
|
||||
@@ -117,25 +116,24 @@ public class QuestDataIO {
|
||||
zin.close();
|
||||
|
||||
String bigXML = xml.toString();
|
||||
try {
|
||||
data = (QuestData) QuestDataIO.getSerializer(true).fromXML(bigXML);
|
||||
} catch(Exception ex) {
|
||||
// Attempt to auto restore?
|
||||
throw new IOException(ex);
|
||||
}
|
||||
|
||||
if (data.getVersionNumber() != QuestData.CURRENT_VERSION_NUMBER) {
|
||||
try {
|
||||
QuestDataIO.updateSaveFile(data, bigXML, xmlSaveFile.getName().replace(".dat", ""));
|
||||
}
|
||||
catch (final Exception e) {
|
||||
//BugReporter.reportException(e);
|
||||
throw new RuntimeException(e);
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
catch (final Exception ex) {
|
||||
//BugReporter.reportException(ex, "Error loading Quest Data");
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> void setFinalField(final Class<T> clasz, final String fieldName, final T instance,
|
||||
final Object newValue) throws IllegalAccessException, NoSuchFieldException {
|
||||
|
||||
Reference in New Issue
Block a user