diff --git a/res/defaults/gauntlet/LOCKED_DotP Preconstructed.dat b/res/defaults/gauntlet/LOCKED_DotP Preconstructed.dat index e07cc44ff0e..3b869fdb410 100644 Binary files a/res/defaults/gauntlet/LOCKED_DotP Preconstructed.dat and b/res/defaults/gauntlet/LOCKED_DotP Preconstructed.dat differ diff --git a/res/defaults/gauntlet/LOCKED_Swimming With Sharks.dat b/res/defaults/gauntlet/LOCKED_Swimming With Sharks.dat index 4e6941bbe82..43ce343ef5f 100644 Binary files a/res/defaults/gauntlet/LOCKED_Swimming With Sharks.dat and b/res/defaults/gauntlet/LOCKED_Swimming With Sharks.dat differ diff --git a/src/main/java/forge/ImageCache.java b/src/main/java/forge/ImageCache.java index 61a6e3b7ee8..1902b86697e 100644 --- a/src/main/java/forge/ImageCache.java +++ b/src/main/java/forge/ImageCache.java @@ -22,6 +22,8 @@ import java.util.concurrent.ExecutionException; import javax.swing.ImageIcon; +import org.apache.commons.lang3.StringUtils; + import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader.InvalidCacheLoadException; import com.google.common.cache.LoadingCache; @@ -93,8 +95,8 @@ public class ImageCache { } private static BufferedImage scaleImage(String key, final int width, final int height) { - if ((3 > width && -1 != width) || (3 > height && -1 != height)) { - // picture too small; return a blank + if (StringUtils.isEmpty(key) || (3 > width && -1 != width) || (3 > height && -1 != height)) { + // picture too small or key not defined; return a blank return null; } diff --git a/src/main/java/forge/deck/Deck.java b/src/main/java/forge/deck/Deck.java index 7e0746ac57d..7d73c5b87e6 100644 --- a/src/main/java/forge/deck/Deck.java +++ b/src/main/java/forge/deck/Deck.java @@ -53,19 +53,11 @@ import forge.util.FileUtil; * The set of MTG legal cards that become player's library when the game starts. * Any other data is not part of a deck and should be stored elsewhere. Current * fields allowed for deck metadata are Name, Title, Description and Deck Type. - * - * @author Forge - * @version $Id$ */ +@SuppressWarnings("serial") public class Deck extends DeckBase implements Iterable> { - /** - * - */ - private static final long serialVersionUID = -7478025567887481994L; - private final Map parts = new EnumMap(DeckSection.class); - - private final Set tags = new TreeSet(String.CASE_INSENSITIVE_ORDER); + private final Set tags = new TreeSet(String.CASE_INSENSITIVE_ORDER); // gameType is from Constant.GameType, like GameType.Regular /** diff --git a/src/main/java/forge/deck/DeckSection.java b/src/main/java/forge/deck/DeckSection.java index b0716ab6647..8e3772a7549 100644 --- a/src/main/java/forge/deck/DeckSection.java +++ b/src/main/java/forge/deck/DeckSection.java @@ -1,11 +1,6 @@ package forge.deck; -/** - * TODO: Write javadoc for this type. - * - */ public enum DeckSection { - Avatar(1), Commander(1), Main(60), @@ -24,12 +19,14 @@ public enum DeckSection { if (value == null) { return null; } + final String valToCompate = value.trim(); for (final DeckSection v : DeckSection.values()) { if (v.name().compareToIgnoreCase(valToCompate) == 0) { return v; } } + return null; } } diff --git a/src/main/java/forge/gauntlet/GauntletData.java b/src/main/java/forge/gauntlet/GauntletData.java index caf75666af0..b7d4f282887 100644 --- a/src/main/java/forge/gauntlet/GauntletData.java +++ b/src/main/java/forge/gauntlet/GauntletData.java @@ -1,12 +1,13 @@ package forge.gauntlet; -import java.io.File; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; +import com.thoughtworks.xstream.annotations.XStreamOmitField; + import forge.deck.Deck; @@ -16,8 +17,10 @@ import forge.deck.Deck; *

(S at beginning of class name denotes a static factory.) */ public final class GauntletData { + @XStreamOmitField + private String name; // set based on the the filename on load + private int completed; - private File activeFile; private String timestamp; private List eventRecords = new ArrayList(); private List eventNames = new ArrayList(); @@ -31,17 +34,14 @@ public final class GauntletData { //========== Mutator / accessor methods - /** @param file0 {@link java.io.File} */ - public void setActiveFile(final File file0) { - this.activeFile = file0; + public void setName(String name0) { + name = name0; } - /** @return {@link java.io.File} */ - public File getActiveFile() { - return this.activeFile; + public String getName() { + return name; } - /** */ public void stamp() { final DateFormat dateFormat = new SimpleDateFormat("dd-mm-yy, H:m"); this.timestamp = dateFormat.format(new Date()).toString(); @@ -61,64 +61,52 @@ public final class GauntletData { GauntletIO.saveGauntlet(this); } - /** @return {@link java.lang.String} */ public String getTimestamp() { return this.timestamp; } - /** @param i0 int */ public void setCompleted(final int i0) { this.completed = i0; } - /** @return int */ public int getCompleted() { return this.completed; } - /** @param d0 {@link forge.deck.Deck} */ public void setUserDeck(final Deck d0) { this.userDeck = d0; } - /** @return d0 {@link forge.deck.Deck} */ public Deck getUserDeck() { return this.userDeck; } - /** @return List */ public List getDeckNames() { final List names = new ArrayList(); for (final Deck d : decks) { names.add(d.getName()); } return names; } - /** @param records0 List */ public void setEventRecords(final List records0) { this.eventRecords = records0; } - /** @return List */ public List getEventRecords() { return this.eventRecords; } - /** @param names0 List */ public void setEventNames(final List names0) { this.eventNames = names0; } - /** @return List */ public List getEventNames() { return this.eventNames; } - /** @param decks0 List */ public void setDecks(final List decks0) { this.decks = decks0; } - /** @return List */ public List getDecks() { return this.decks; } diff --git a/src/main/java/forge/gauntlet/GauntletIO.java b/src/main/java/forge/gauntlet/GauntletIO.java index 83503ffad1e..540f729514d 100644 --- a/src/main/java/forge/gauntlet/GauntletIO.java +++ b/src/main/java/forge/gauntlet/GauntletIO.java @@ -27,25 +27,16 @@ import forge.item.CardPrinted; import forge.properties.NewConstants; import forge.util.IgnoringXStream; -/** */ public class GauntletIO { /** Prompt in text field for new (unsaved) built gauntlets. */ public static final String TXF_PROMPT = "[New Gauntlet]"; + /** suffix for all gauntlet data files */ + public static final String SUFFIX_DATA = ".dat"; /** Prefix for quick gauntlet save files. */ public static final String PREFIX_QUICK = "Quick_"; - /** Regex for quick gauntlet save files. */ - public static final String REGEX_QUICK = "^" + GauntletIO.PREFIX_QUICK + "[0-9]+\\.dat$"; /** Regex for locked gauntlet save files. */ - public static final String REGEX_LOCKED = "^LOCKED_.+\\.dat$"; - /** Regex for Subversion files. */ - public static final String SVN_IGNORE = "^\\.svn$"; + public static final String PREFIX_LOCKED = "LOCKED_"; - /** - * Gets the serializer. - * - * @param isIgnoring the is ignoring - * @return the serializer - */ protected static XStream getSerializer(final boolean isIgnoring) { final XStream xStream = isIgnoring ? new IgnoringXStream() : new XStream(); xStream.registerConverter(new DeckSectionToXml()); @@ -53,42 +44,43 @@ public class GauntletIO { return xStream; } + public static File getGauntletFile(String name) { + return new File(NewConstants.GAUNTLET_DIR.userPrefLoc, name + SUFFIX_DATA); + } - /** @return File[] */ + public static File getGauntletFile(GauntletData gd) { + return getGauntletFile(gd.getName()); + } + public static File[] getGauntletFilesUnlocked() { final FilenameFilter filter = new FilenameFilter() { @Override public boolean accept(File dir, String name) { - return (!name.matches(GauntletIO.REGEX_LOCKED) - && !name.matches(GauntletIO.SVN_IGNORE)); + return (name.endsWith(SUFFIX_DATA)); } }; - File folder = new File(NewConstants.GAUNTLET_DIR.defaultLoc); + File folder = new File(NewConstants.GAUNTLET_DIR.userPrefLoc); return folder.listFiles(filter); } - /** @return File[] */ public static File[] getGauntletFilesQuick() { final FilenameFilter filter = new FilenameFilter() { @Override public boolean accept(File dir, String name) { - return (name.matches(GauntletIO.REGEX_QUICK) - && !name.matches(GauntletIO.SVN_IGNORE)); + return (name.startsWith(PREFIX_QUICK) && name.endsWith(SUFFIX_DATA)); } }; - File folder = new File(NewConstants.GAUNTLET_DIR.defaultLoc); + File folder = new File(NewConstants.GAUNTLET_DIR.userPrefLoc); return folder.listFiles(filter); } - /** @return File[] */ public static File[] getGauntletFilesLocked() { final FilenameFilter filter = new FilenameFilter() { @Override public boolean accept(File dir, String name) { - return (name.matches(GauntletIO.REGEX_LOCKED) - && !name.matches(GauntletIO.SVN_IGNORE)); + return (name.startsWith(PREFIX_LOCKED) && name.endsWith(SUFFIX_DATA)); } }; @@ -96,50 +88,29 @@ public class GauntletIO { return folder.listFiles(filter); } - /** - *

- * loadData. - *

- * - * @param xmlSaveFile - *   {@link java.io.File} - * @return {@link forge.gauntlet.GauntletData} - */ public static GauntletData loadGauntlet(final File xmlSaveFile) { + GZIPInputStream zin = null; try { - GauntletData data = null; + zin = new GZIPInputStream(new FileInputStream(xmlSaveFile)); + InputStreamReader reader = new InputStreamReader(zin); - final GZIPInputStream zin = new GZIPInputStream(new FileInputStream(xmlSaveFile)); - - final StringBuilder xml = new StringBuilder(); - final char[] buf = new char[1024]; - final InputStreamReader reader = new InputStreamReader(zin); - while (reader.ready()) { - final int len = reader.read(buf); - if (len == -1) { - break; - } // when end of stream was reached - xml.append(buf, 0, len); - } - - zin.close(); - data = (GauntletData) GauntletIO.getSerializer(true).fromXML(xml.toString()); + GauntletData data = (GauntletData)GauntletIO.getSerializer(true).fromXML(reader); + String filename = xmlSaveFile.getName(); + data.setName(filename.substring(0, filename.length() - SUFFIX_DATA.length())); + return data; } catch (final Exception ex) { BugReporter.reportException(ex, "Error loading Gauntlet Data"); throw new RuntimeException(ex); + } finally { + if (null != zin) { + try { zin.close(); } + catch (IOException e) { System.out.println("error closing gauntlet data reader: " + e); } + } } } - /** - *

- * saveData. - *

- * - * @param gd0 - * a {@link forge.gauntlet.GauntletData} object. - */ public static void saveGauntlet(final GauntletData gd0) { try { final XStream xStream = GauntletIO.getSerializer(false); @@ -151,7 +122,7 @@ public class GauntletIO { } private static void savePacked(final XStream xStream0, final GauntletData gd0) throws IOException { - final BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(gd0.getActiveFile())); + final BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(getGauntletFile(gd0))); final GZIPOutputStream zout = new GZIPOutputStream(bout); xStream0.toXML(gd0, zout); zout.flush(); @@ -159,7 +130,6 @@ public class GauntletIO { } private static class DeckSectionToXml implements Converter { - @SuppressWarnings("rawtypes") @Override public boolean canConvert(final Class clasz) { @@ -171,7 +141,6 @@ public class GauntletIO { for (final Entry e : (CardPool) source) { this.writeCardPrinted(e.getKey(), e.getValue(), writer); } - } @Override @@ -190,10 +159,10 @@ public class GauntletIO { } reader.moveUp(); } + return result; } - /** */ private void writeCardPrinted(final CardPrinted cref, final Integer count, final HierarchicalStreamWriter writer) { writer.startNode("card"); writer.addAttribute("c", cref.getName()); diff --git a/src/main/java/forge/gui/DialogMigrateProfile.java b/src/main/java/forge/gui/DialogMigrateProfile.java index be55fd6e737..93d8da9e653 100644 --- a/src/main/java/forge/gui/DialogMigrateProfile.java +++ b/src/main/java/forge/gui/DialogMigrateProfile.java @@ -832,21 +832,21 @@ public class DialogMigrateProfile { opLogBuf.append(destFile.getAbsolutePath()).append("\n"); if (!destFile.exists()) { - _copyFile(srcFile, destFile); + _copyFile(srcFile, destFile, _move); } else { if (_overwrite) { opLogBuf.append(" Destination file exists; overwriting\n"); - _copyFile(srcFile, destFile); + _copyFile(srcFile, destFile, _move); } else { opLogBuf.append(" Destination file exists; skipping copy\n"); } ++numExisting; } - if (_move) { - opLogBuf.append(" Removing source file after successful copy\n"); + // source file may have been deleted already if _copyFile was called srcFile.delete(); + opLogBuf.append(" Removed source file after successful copy\n"); } ++numSucceeded; @@ -896,10 +896,17 @@ public class DialogMigrateProfile { } } - // actual file copy routine. uses java.nio classes for ultra-fast copying - private static void _copyFile(File srcFile, File destFile) throws IOException { + // when copying is required, uses java nio classes for ultra-fast I/O + private static void _copyFile(File srcFile, File destFile, boolean deleteSrcAfter) throws IOException { destFile.getParentFile().mkdirs(); + // if this is a move, try a simple rename first + if (deleteSrcAfter) { + if (srcFile.renameTo(destFile)) { + return; + } + } + if (!destFile.exists()) { destFile.createNewFile(); } @@ -914,5 +921,9 @@ public class DialogMigrateProfile { if (src != null) { src.close(); } if (dest != null) { dest.close(); } } + + if (deleteSrcAfter) { + srcFile.delete(); + } } } diff --git a/src/main/java/forge/gui/home/gauntlet/CSubmenuGauntletBuild.java b/src/main/java/forge/gui/home/gauntlet/CSubmenuGauntletBuild.java index 366b72056af..b891ad006c2 100644 --- a/src/main/java/forge/gui/home/gauntlet/CSubmenuGauntletBuild.java +++ b/src/main/java/forge/gui/home/gauntlet/CSubmenuGauntletBuild.java @@ -42,13 +42,11 @@ import forge.util.storage.IStorage; @SuppressWarnings("serial") public enum CSubmenuGauntletBuild implements ICDoc { - /** */ SINGLETON_INSTANCE; private final VSubmenuGauntletBuild view = VSubmenuGauntletBuild.SINGLETON_INSTANCE; private final List workingDecks = new ArrayList(); - private File previousDirectory = null; - private File openStartDir = new File(NewConstants.GAUNTLET_DIR.defaultLoc); + private File openStartDir = new File(NewConstants.GAUNTLET_DIR.userPrefLoc); private final FileFilter filterDAT = new FileFilter() { @Override @@ -57,12 +55,8 @@ public enum CSubmenuGauntletBuild implements ICDoc { return true; } - if (!f.getName().matches(GauntletIO.REGEX_LOCKED) - && !f.getName().matches(GauntletIO.REGEX_QUICK)) { - return true; - } - - return false; + String filename = f.getName(); + return (!filename.startsWith(GauntletIO.PREFIX_QUICK) && filename.endsWith(GauntletIO.SUFFIX_DATA)); } @Override @@ -318,7 +312,7 @@ public enum CSubmenuGauntletBuild implements ICDoc { return false; } - final File f = new File(NewConstants.GAUNTLET_DIR.defaultLoc + name + ".dat"); + final File f = new File(NewConstants.GAUNTLET_DIR.userPrefLoc + name + ".dat"); // Confirm if overwrite if (f.exists()) { final int m = JOptionPane.showConfirmDialog(null, @@ -350,7 +344,7 @@ public enum CSubmenuGauntletBuild implements ICDoc { gd.setEventNames(names); gd.setDecks(workingDecks); - gd.setActiveFile(f); + gd.setName(name); gd.reset(); view.getLblSave().setVisible(false); @@ -359,17 +353,14 @@ public enum CSubmenuGauntletBuild implements ICDoc { } private boolean openGauntlet() { - /** */ final File file; - final JFileChooser open = new JFileChooser(previousDirectory); + final JFileChooser open = new JFileChooser(openStartDir); open.setDialogTitle("Import Deck"); open.addChoosableFileFilter(this.filterDAT); - open.setCurrentDirectory(openStartDir); final int returnVal = open.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { file = open.getSelectedFile(); - previousDirectory = file.getParentFile(); } else { return false; diff --git a/src/main/java/forge/gui/home/gauntlet/CSubmenuGauntletContests.java b/src/main/java/forge/gui/home/gauntlet/CSubmenuGauntletContests.java index 3874210f6d2..65cc04ca230 100644 --- a/src/main/java/forge/gui/home/gauntlet/CSubmenuGauntletContests.java +++ b/src/main/java/forge/gui/home/gauntlet/CSubmenuGauntletContests.java @@ -140,11 +140,8 @@ public enum CSubmenuGauntletContests implements ICDoc { private void updateData() { final File[] files = GauntletIO.getGauntletFilesLocked(); final List data = new ArrayList(); - for (final File f : files) { - if (f.getName().matches(GauntletIO.REGEX_LOCKED)) { - data.add(GauntletIO.loadGauntlet(f)); - } + data.add(GauntletIO.loadGauntlet(f)); } view.getGauntletLister().setGauntlets(data); diff --git a/src/main/java/forge/gui/home/gauntlet/CSubmenuGauntletLoad.java b/src/main/java/forge/gui/home/gauntlet/CSubmenuGauntletLoad.java index ea3f040680f..79b7f06f1a0 100644 --- a/src/main/java/forge/gui/home/gauntlet/CSubmenuGauntletLoad.java +++ b/src/main/java/forge/gui/home/gauntlet/CSubmenuGauntletLoad.java @@ -31,12 +31,9 @@ import forge.model.FModel; *

(C at beginning of class name denotes a control class.) * */ - public enum CSubmenuGauntletLoad implements ICDoc { - /** */ SINGLETON_INSTANCE; - private final ActionListener actStartGame = new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { startGame(); } }; @@ -47,6 +44,11 @@ public enum CSubmenuGauntletLoad implements ICDoc { */ @Override public void update() { + updateData(); + enableStartButton(); + + view.getGauntletLister().setSelectedIndex(0); + SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JButton btnStart = view.getBtnStart(); @@ -67,10 +69,6 @@ public enum CSubmenuGauntletLoad implements ICDoc { public void initialize() { view.getBtnStart().addActionListener(actStartGame); - updateData(); - enableStartButton(); - - view.getGauntletLister().setSelectedIndex(0); view.getGauntletLister().setCmdDelete(new Command() { @Override public void execute() { enableStartButton(); } }); view.getGauntletLister().setCmdSelect(new Command() { @Override @@ -89,7 +87,7 @@ public enum CSubmenuGauntletLoad implements ICDoc { } private void enableStartButton() { - if (view.getGauntletLister().getSelectedGauntlet() == null) { + if (view.getGauntletLister().getSelectedGauntletFile() == null) { view.getBtnStart().setEnabled(false); } else { @@ -99,8 +97,7 @@ public enum CSubmenuGauntletLoad implements ICDoc { private void startGame() { FModel.SINGLETON_INSTANCE.setGauntletData( - GauntletIO.loadGauntlet(VSubmenuGauntletQuick.SINGLETON_INSTANCE - .getGauntletLister().getSelectedGauntlet().getActiveFile())); + GauntletIO.loadGauntlet(VSubmenuGauntletQuick.SINGLETON_INSTANCE.getGauntletLister().getSelectedGauntletFile())); // Start game SwingUtilities.invokeLater(new Runnable() { diff --git a/src/main/java/forge/gui/home/gauntlet/CSubmenuGauntletQuick.java b/src/main/java/forge/gui/home/gauntlet/CSubmenuGauntletQuick.java index c52785ee761..3a080fbdd9f 100644 --- a/src/main/java/forge/gui/home/gauntlet/CSubmenuGauntletQuick.java +++ b/src/main/java/forge/gui/home/gauntlet/CSubmenuGauntletQuick.java @@ -7,7 +7,9 @@ import java.awt.event.MouseEvent; import java.io.File; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashSet; import java.util.List; +import java.util.Set; import javax.swing.JList; import javax.swing.ListSelectionModel; @@ -32,7 +34,6 @@ import forge.gauntlet.GauntletIO; import forge.gui.SOverlayUtils; import forge.gui.framework.ICDoc; import forge.model.FModel; -import forge.properties.NewConstants; import forge.quest.QuestController; import forge.quest.QuestEvent; import forge.util.storage.IStorage; @@ -206,7 +207,6 @@ public enum CSubmenuGauntletQuick implements ICDoc { view.getLstDecks().setSelectedIndices(new int[]{0, 1}); } - /** */ private void startGame() { // Start game overlay SwingUtilities.invokeLater(new Runnable() { @@ -219,13 +219,12 @@ public enum CSubmenuGauntletQuick implements ICDoc { // Find appropriate filename for new save, create and set new save file. final File[] arrFiles = GauntletIO.getGauntletFilesQuick(); - final List lstNames = new ArrayList(); - for (File f : arrFiles) { lstNames.add(f.getName()); } + final Set setNames = new HashSet(); + for (File f : arrFiles) { setNames.add(f.getName()); } int num = 1; - while (lstNames.contains(GauntletIO.PREFIX_QUICK + num + ".dat")) { num++; } - FModel.SINGLETON_INSTANCE.getGauntletData().setActiveFile(new File( - NewConstants.GAUNTLET_DIR.defaultLoc + GauntletIO.PREFIX_QUICK + num + ".dat")); + while (setNames.contains(GauntletIO.PREFIX_QUICK + num + GauntletIO.SUFFIX_DATA)) { num++; } + FModel.SINGLETON_INSTANCE.getGauntletData().setName(GauntletIO.PREFIX_QUICK + num); // Pull user deck final Deck userDeck; diff --git a/src/main/java/forge/gui/home/gauntlet/ContestGauntletLister.java b/src/main/java/forge/gui/home/gauntlet/ContestGauntletLister.java index a9e16420a15..d161f5c1a21 100644 --- a/src/main/java/forge/gui/home/gauntlet/ContestGauntletLister.java +++ b/src/main/java/forge/gui/home/gauntlet/ContestGauntletLister.java @@ -17,6 +17,7 @@ import javax.swing.border.MatteBorder; import net.miginfocom.swing.MigLayout; import forge.Command; import forge.gauntlet.GauntletData; +import forge.gauntlet.GauntletIO; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FSkin; @@ -52,7 +53,7 @@ public class ContestGauntletLister extends JPanel { Collections.sort(sorted, new Comparator() { @Override public int compare(final GauntletData x, final GauntletData y) { - return x.getActiveFile().getName().compareTo(y.getActiveFile().getName()); + return x.getName().compareTo(y.getName()); } }); @@ -78,8 +79,8 @@ public class ContestGauntletLister extends JPanel { String name; String progress; for (GauntletData gd : sorted) { - name = gd.getActiveFile().getName(); - name = name.substring(7, name.length() - 4); + name = gd.getName(); + name = name.substring(GauntletIO.PREFIX_LOCKED.length()); progress = String.valueOf(Math.round( ((double) gd.getCompleted() / (double) gd.getDecks().size()) * 100)) + " %"; diff --git a/src/main/java/forge/gui/home/gauntlet/QuickGauntletLister.java b/src/main/java/forge/gui/home/gauntlet/QuickGauntletLister.java index 7a51a3b0f1e..71d0f6c8d93 100644 --- a/src/main/java/forge/gui/home/gauntlet/QuickGauntletLister.java +++ b/src/main/java/forge/gui/home/gauntlet/QuickGauntletLister.java @@ -5,6 +5,7 @@ package forge.gui.home.gauntlet; import java.awt.Color; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -20,6 +21,7 @@ import javax.swing.border.MatteBorder; import net.miginfocom.swing.MigLayout; import forge.Command; import forge.gauntlet.GauntletData; +import forge.gauntlet.GauntletIO; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FSkin; @@ -60,7 +62,7 @@ public class QuickGauntletLister extends JPanel { Collections.sort(sorted, new Comparator() { @Override public int compare(final GauntletData x, final GauntletData y) { - return x.getActiveFile().getName().compareTo(y.getActiveFile().getName()); + return x.getName().compareTo(y.getName()); } }); @@ -85,8 +87,7 @@ public class QuickGauntletLister extends JPanel { RowPanel row; String name; for (GauntletData gd : sorted) { - name = gd.getActiveFile().getName(); - name = name.substring(0, name.length() - 4); + name = gd.getName(); row = new RowPanel(gd); row.setToolTipText(name); @@ -113,12 +114,12 @@ public class QuickGauntletLister extends JPanel { } /** @return {@link forge.deck.Deck} */ - public GauntletData getSelectedGauntlet() { + public File getSelectedGauntletFile() { if (previousSelect == null) { return null; } else { - return previousSelect.getGauntletData(); + return GauntletIO.getGauntletFile(previousSelect.getGauntletData()); } } @@ -221,7 +222,7 @@ public class QuickGauntletLister extends JPanel { */ public boolean setSelectedIndex(int i0) { if (i0 >= rows.length) { return false; } - selectHandler(rows[i0]); + selectHandler(rows[Math.max(0, i0)]); return true; } @@ -263,7 +264,7 @@ public class QuickGauntletLister extends JPanel { final GauntletData gd = r0.getGauntletData(); final int n = JOptionPane.showConfirmDialog(null, - "Are you sure you want to delete \"" + gd.getActiveFile().getName() + "Are you sure you want to delete \"" + gd.getName() + "\" ?", "Delete Gauntlet", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.NO_OPTION) { @@ -271,7 +272,7 @@ public class QuickGauntletLister extends JPanel { } - gd.getActiveFile().delete(); + GauntletIO.getGauntletFile(gd).delete(); if (cmdRowDelete != null) { cmdRowDelete.execute(); } this.setSelectedIndex(0); diff --git a/src/main/java/forge/gui/home/quest/CSubmenuQuestData.java b/src/main/java/forge/gui/home/quest/CSubmenuQuestData.java index 7f4c1300720..476d106cb0b 100644 --- a/src/main/java/forge/gui/home/quest/CSubmenuQuestData.java +++ b/src/main/java/forge/gui/home/quest/CSubmenuQuestData.java @@ -102,18 +102,7 @@ public enum CSubmenuQuestData implements ICDoc { final File dirQuests = new File(NewConstants.QUEST_SAVE_DIR); final QuestController qc = Singletons.getModel().getQuest(); - // Temporary transition code between v1.2.2 and v1.2.3. - // Can be safely deleted after release of 1.2.3. - if (!dirQuests.exists()) { - dirQuests.mkdirs(); - } - File olddata = new File("res/quest/questData.dat"); - File newpath = new File(dirQuests.getPath() + "/questData.dat"); - - if (olddata.exists()) { olddata.renameTo(newpath); } - // end block which can be deleted - - // Iterate over files and load quest datas for each. + // Iterate over files and load quest data for each. FilenameFilter takeDatFiles = new FilenameFilter() { @Override public boolean accept(final File dir, final String name) { @@ -126,7 +115,7 @@ public enum CSubmenuQuestData implements ICDoc { arrQuests.put(f.getName(), QuestDataIO.loadData(f)); } - // Populate list with available quest datas. + // Populate list with available quest data. view.getLstQuests().setQuests(new ArrayList(arrQuests.values())); // If there are quests available, force select. diff --git a/src/main/java/forge/gui/match/GauntletWinLose.java b/src/main/java/forge/gui/match/GauntletWinLose.java index 2412cd44f42..4ae1d268042 100644 --- a/src/main/java/forge/gui/match/GauntletWinLose.java +++ b/src/main/java/forge/gui/match/GauntletWinLose.java @@ -102,8 +102,8 @@ public class GauntletWinLose extends ControlWinLose { this.getView().getBtnQuit().setText("OK"); // Remove save file if it's a quickie, or just reset it. - if (gd.getActiveFile().getName().matches(GauntletIO.REGEX_QUICK)) { - gd.getActiveFile().delete(); + if (gd.getName().startsWith(GauntletIO.PREFIX_QUICK)) { + GauntletIO.getGauntletFile(gd).delete(); } else { gd.reset(); @@ -131,8 +131,8 @@ public class GauntletWinLose extends ControlWinLose { this.getView().getBtnContinue().setVisible(false); // Remove save file if it's a quickie, or just reset it. - if (gd.getActiveFile().getName().matches(GauntletIO.REGEX_QUICK)) { - gd.getActiveFile().delete(); + if (gd.getName().startsWith(GauntletIO.PREFIX_QUICK)) { + GauntletIO.getGauntletFile(gd).delete(); } else { gd.reset(); diff --git a/src/main/java/forge/quest/io/QuestDataIO.java b/src/main/java/forge/quest/io/QuestDataIO.java index 7705b0cb90f..16ff1cdd8e3 100644 --- a/src/main/java/forge/quest/io/QuestDataIO.java +++ b/src/main/java/forge/quest/io/QuestDataIO.java @@ -534,10 +534,9 @@ public class QuestDataIO { } reader.moveUp(); } - return result; + return result; } - } private static class ItemPoolToXml implements Converter {