diff --git a/.gitattributes b/.gitattributes index 06285a26f6f..bee9d3aed3e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -13904,7 +13904,6 @@ src/main/java/forge/gui/ForgeAction.java svneol=native#text/plain src/main/java/forge/gui/GuiChoose.java -text src/main/java/forge/gui/GuiDialog.java -text src/main/java/forge/gui/GuiDisplayUtil.java svneol=native#text/plain -src/main/java/forge/gui/GuiImportPicture.java svneol=native#text/plain src/main/java/forge/gui/GuiProgressBarWindow.java svneol=native#text/plain src/main/java/forge/gui/GuiUtils.java svneol=native#text/plain src/main/java/forge/gui/InputProxy.java svneol=native#text/plain @@ -14176,9 +14175,7 @@ src/main/java/forge/util/Aggregates.java -text src/main/java/forge/util/Base64Coder.java svneol=native#text/plain src/main/java/forge/util/BinaryUtil.java -text src/main/java/forge/util/ComparableOp.java -text -src/main/java/forge/util/CopyFiles.java svneol=native#text/plain src/main/java/forge/util/Expressions.java -text -src/main/java/forge/util/FileFinder.java svneol=native#text/plain src/main/java/forge/util/FileSection.java -text src/main/java/forge/util/FileSectionManual.java -text src/main/java/forge/util/FileUtil.java svneol=native#text/plain diff --git a/src/main/java/forge/gui/DialogMigrateProfile.java b/src/main/java/forge/gui/DialogMigrateProfile.java new file mode 100644 index 00000000000..8c6b8bef8fb --- /dev/null +++ b/src/main/java/forge/gui/DialogMigrateProfile.java @@ -0,0 +1,366 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (c) 2013 Forge Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package forge.gui; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.channels.FileChannel; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.swing.JPanel; +import javax.swing.JProgressBar; +import javax.swing.JScrollPane; +import javax.swing.ScrollPaneConstants; +import javax.swing.SwingUtilities; +import javax.swing.SwingWorker; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import net.miginfocom.swing.MigLayout; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Pair; + +import forge.gui.toolbox.FButton; +import forge.gui.toolbox.FCheckBox; +import forge.gui.toolbox.FLabel; +import forge.gui.toolbox.FOverlay; +import forge.gui.toolbox.FPanel; +import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FTextArea; +import forge.gui.toolbox.FTextField; +import forge.properties.NewConstants; + +public class DialogMigrateProfile { + private final Runnable _onImportDone; + private final FButton _btnStart; + private final JPanel _selectionPanel; + private volatile boolean _cancel; + + public DialogMigrateProfile(String srcDir, boolean showMigrationBlurb, final Runnable onImportDone) { + FPanel p = new FPanel(new MigLayout("insets dialog, gap 0, center, wrap")); + p.setOpaque(false); + p.setBackgroundTexture(FSkin.getIcon(FSkin.Backgrounds.BG_TEXTURE)); + + // header + p.add(new FLabel.Builder().text("Migrate profile data (in progress: not yet functional)").fontSize(15).build(), "center"); + + if (showMigrationBlurb) { + FPanel blurbPanel = new FPanel(new MigLayout("insets dialog, gap 10, center, wrap")); + blurbPanel.setOpaque(false); + blurbPanel.add(new FLabel.Builder().text("What's this?").build(), "growx"); + blurbPanel.add(new FLabel.Builder().text( + "Over the last several years, people have had to jump through a lot of hoops to" + + " update to the most recent version. We hope to reduce this workload to a point where a new" + + " user will find that it is fairly painless to update. In order to make this happen, Forge" + + " has changed where it stores your data so that it is outside of the program installation directory." + + " This way, when you upgrade, you will no longer need to import your data every time to get things" + + " working. There are other benefits to having user data separate from program data, too, and it" + + " lays the groundwork for some cool new features.").build()); + blurbPanel.add(new FLabel.Builder().text("So where's my data going?").build(), "growx"); + blurbPanel.add(new FLabel.Builder().text( + "Forge will now store your data in the same place as other applications on your system." + + " Specifically, your personal data, like decks, quest progress, and program preferences will be" + + " stored in " + NewConstants.USER_DIR + " and all downloaded content, such as card pictures," + + " skins, and quest world prices will be under " + NewConstants.CACHE_DIR + ". If, for whatever" + + " reason, you need to set different paths, cancel out of this dialog, exit Forge, and find the " + + NewConstants.PROFILE_TEMPLATE_FILE + " file in the program installation directory. Copy or rename" + + " it to " + NewConstants.PROFILE_FILE + " and edit the paths inside it. Then restart Forge and use" + + " this dialog to move your data to the paths that you set. Keep in mind that if you install a future" + + " version of Forge into a different directory, you'll need to copy this file over so Forge will know" + + " where to find your data.").build()); + blurbPanel.add(new FLabel.Builder().text( + "Remember, your data won't be available until you complete this step!").build(), "growx"); + p.add(blurbPanel, "gap 10 10 20 20"); + } + + // import source widgets + JPanel importSourcePanel = new JPanel(new MigLayout("insets 0, gap 5")); + importSourcePanel.setOpaque(false); + importSourcePanel.add(new FLabel.Builder().text("Import from:").build()); + boolean emptySrcDir = StringUtils.isEmpty(srcDir); + FTextField txfSrc = new FTextField.Builder().readonly(!emptySrcDir).build(); + importSourcePanel.add(txfSrc, "gap 5, pushx"); + if (!emptySrcDir) { + File srcDirFile = new File(srcDir); + txfSrc.setText(srcDirFile.getAbsolutePath()); + } + importSourcePanel.add(new FLabel.ButtonBuilder().text("Choose directory...").enabled(emptySrcDir).build(), "h pref+8!, w pref+12!"); + p.add(importSourcePanel, "growx"); + + // prepare import selection panel + _selectionPanel = new JPanel(); + _selectionPanel.setOpaque(false); + p.add(_selectionPanel, "growx"); + + // action button widgets + final Runnable cleanup = new Runnable() { + @Override public void run() { SOverlayUtils.hideOverlay(); } + }; + _btnStart = new FButton("Start import"); + _btnStart.setEnabled(false); + + final FButton btnCancel = new FButton("Cancel"); + btnCancel.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { _cancel = true; cleanup.run(); } + }); + + _onImportDone = new Runnable() { + @Override public void run() { + cleanup.run(); + if (null != onImportDone) { + onImportDone.run(); + } + } + }; + + JPanel southPanel = new JPanel(new MigLayout("gap 20, ax center")); + southPanel.setOpaque(false); + southPanel.add(_btnStart, "center, w 40%, h pref+12!"); + southPanel.add(btnCancel, "center, w 40%, h pref+12!"); + + p.add(southPanel, "dock south"); + + JPanel overlay = FOverlay.SINGLETON_INSTANCE.getPanel(); + overlay.setLayout(new MigLayout("insets 0, gap 0, wrap, ax center, ay center")); + overlay.add(p, "w 700!"); + SOverlayUtils.showOverlay(); + + // focus cancel button + SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { btnCancel.requestFocusInWindow(); } + }); + + _AnalyzerUpdater analyzer = new _AnalyzerUpdater(!emptySrcDir); + analyzer.execute(); + } + + private enum OpType { + CONSTRUCTED_DECK, + UNKNOWN_DECK, + GAUNTLET_DATA, + QUEST_DATA, + PREFERENCE_FILE + } + + private class _AnalyzerUpdater extends SwingWorker { + private final Map>>> _selections = + new HashMap>>>(); + + private final FCheckBox _moveCheckbox; + private final FTextArea _operationLog; + private final JProgressBar _progressBar; + + public _AnalyzerUpdater(boolean forced) { + _selectionPanel.removeAll(); + _selectionPanel.setLayout(new MigLayout("insets 0, gap 5, wrap")); + + ChangeListener changeListener = new ChangeListener() { + @Override public void stateChanged(ChangeEvent arg0) { _updateUI(); } + }; + + // add known deck checkboxes + JPanel knownDeckPanel = new JPanel(new MigLayout("insets 0, gap 5, wrap")); + knownDeckPanel.setOpaque(false); + knownDeckPanel.add(new FLabel.Builder().text("Decks").build()); + FCheckBox constructed = new FCheckBox(); + constructed.setName("Constructed decks"); + constructed.addChangeListener(changeListener); + _selections.put(OpType.CONSTRUCTED_DECK, Pair.of(constructed, new HashSet>())); + + // add unknown deck combobox + + // add other data elements (gauntlets, quest data) + + // add move/copy checkbox + _moveCheckbox = new FCheckBox("move files"); + _moveCheckbox.setSelected(true); + _moveCheckbox.setEnabled(!forced); + _moveCheckbox.addChangeListener(changeListener); + _selectionPanel.add(_moveCheckbox); + + // add operation summary textfield + _operationLog = new FTextArea(); + _operationLog.setFocusable(true); + JScrollPane scroller = new JScrollPane(_operationLog); + scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); + _selectionPanel.add(scroller, "w 100%!, h 10%!"); + + // add progress bar + _progressBar = new JProgressBar(); + _progressBar.setIndeterminate(true); + _progressBar.setString("Analyzing source directory..."); + _progressBar.setStringPainted(true); + _selectionPanel.add(_progressBar, "w 100%!"); + } + + private void _updateUI() { + // set operation summary + StringBuilder log = new StringBuilder(); + int totalOps = 0; + for (Pair>> selection : _selections.values()) { + FCheckBox cb = selection.getLeft(); + Set> ops = selection.getRight(); + + if (cb.isSelected()) { + totalOps += ops.size(); + } + + // update checkbox text with new totals + cb.setText(String.format("%s (%d)", cb.getName(), ops.size())); + } + log.append(_moveCheckbox.isSelected() ? "Moving" : "Copying"); + log.append(" ").append(totalOps).append(" files\n\n"); + for (Pair>> selection : _selections.values()) { + if (selection.getLeft().isSelected()) { + for (Pair op : selection.getRight()) { + log.append(String.format("%s -> %s\n", + op.getLeft().getAbsolutePath(), op.getRight().getAbsolutePath())); + } + } + } + _operationLog.setText(log.toString()); + } + + private void _disableAll() { + _moveCheckbox.setEnabled(false); + } + + @Override + protected Void doInBackground() throws Exception { + // TODO: analysis + // ensure we ignore data that is already in the destination directory + return null; + } + + @Override + protected void done() { + if (_cancel) { return; } + _btnStart.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent arg0) { + _btnStart.removeActionListener(this); + _btnStart.setEnabled(false); + + _disableAll(); + + _Importer importer = new _Importer(_selections, _operationLog, _progressBar, _moveCheckbox.isSelected()); + importer.execute(); + } + }); + _btnStart.setEnabled(true); + } + } + + private class _Importer extends SwingWorker { + private final List> _operations; + private final FTextArea _operationLog; + private final JProgressBar _progressBar; + private final boolean _move; + + public _Importer(Map>>> selections, + FTextArea operationLog, JProgressBar progressBar, boolean move) { + _operationLog = operationLog; + _progressBar = progressBar; + _move = move; + + int totalOps = 0; + for (Pair>> selection : selections.values()) { + if (selection.getLeft().isSelected()) { + totalOps += selection.getRight().size(); + } + } + _operations = new ArrayList>(totalOps); + for (Pair>> selection : selections.values()) { + if (selection.getLeft().isSelected()) { + _operations.addAll(selection.getRight()); + } + } + } + + @Override + protected Void doInBackground() throws Exception { + _operationLog.setText(""); + + // determine total number of operations and set progress bar bounds + _progressBar.setString(_move ? "Moving files" : "Copying files"); + _progressBar.setMinimum(0); + _progressBar.setMaximum(_operations.size()); + _progressBar.setIndeterminate(false); + + // assumes all destination directories have been created + int numOps = 0; + for (Pair op : _operations) { + _progressBar.setValue(++numOps); + + File srcFile = op.getLeft(); + File destFile = op.getRight(); + + try { + _copyFile(srcFile, destFile); + + if (_move) { + srcFile.delete(); + } + + // this operation is thread safe + _operationLog.append(String.format("%s %s -> %s\n", + _move ? "Moved" : "Copied", + srcFile.getAbsolutePath(), destFile.getAbsolutePath())); + } catch (IOException e) { + _operationLog.append(String.format("Failed to %s %s -> %s (%s)\n", + _move ? "move" : "copy", + srcFile.getAbsolutePath(), destFile.getAbsolutePath(), + e.getMessage())); + } + } + + return null; + } + + @Override + protected void done() { + _onImportDone.run(); + } + + private void _copyFile(File srcFile, File destFile) throws IOException { + if(!destFile.exists()) { + destFile.createNewFile(); + } + + FileChannel src = null; + FileChannel dest = null; + try { + src = new FileInputStream(srcFile).getChannel(); + dest = new FileOutputStream(destFile).getChannel(); + dest.transferFrom(src, 0, src.size()); + } finally { + if (src != null) { src.close(); } + if (dest != null) { dest.close(); } + } + } + } +} diff --git a/src/main/java/forge/gui/GuiImportPicture.java b/src/main/java/forge/gui/GuiImportPicture.java deleted file mode 100644 index 79963a55e09..00000000000 --- a/src/main/java/forge/gui/GuiImportPicture.java +++ /dev/null @@ -1,352 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui; - -import java.awt.Color; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.Rectangle; -import java.awt.event.MouseEvent; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JDialog; -import javax.swing.JFileChooser; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JProgressBar; -import javax.swing.event.MouseInputAdapter; - -import forge.properties.NewConstants; -import forge.util.CopyFiles; -import forge.util.FileFinder; - -@SuppressWarnings("serial") -public class GuiImportPicture extends JDialog { - private JPanel jContentPane = null; - private JLabel jLabel = null; - private JLabel jLabel1 = null; - private JLabel jLabelSource = null; - private JButton jButtonSource = null; - private JPanel jPanel = null; - private JCheckBox jCheckBox = null; - private JButton jButtonStart = null; - - private JLabel jLabelHDDFree = null; - private JLabel jLabelNeedSpace = null; - - private JLabel jLabelTotalFiles = null; - private List listFiles; - private ArrayList fileCopyList; - private long freeSpaceM; - private int filesForCopy; - private String oldText; - private JProgressBar jProgressBar = null; - - public GuiImportPicture(final JFrame owner) { - super(owner, "Import Pictures", true); - - setSize(400, 295); - setResizable(false); - setLocationRelativeTo(null); - setContentPane(getJContentPane()); - } - - private JPanel getJContentPane() { - this.jLabelTotalFiles = new JLabel(); - this.jLabelTotalFiles.setBounds(new Rectangle(15, 180, 248, 16)); - this.jLabelTotalFiles.setText("Total files for copying: Unknown."); - this.jLabelNeedSpace = new JLabel(); - this.jLabelNeedSpace.setBounds(new Rectangle(15, 150, 177, 16)); - this.jLabelNeedSpace.setText("HDD Need Space: Unknown."); - this.jLabelHDDFree = new JLabel(); - this.jLabelHDDFree.setBounds(new Rectangle(15, 119, 177, 16)); - - final File file = new File(NewConstants.CACHE_CARD_PICS_DIR); - - final long freeSpace = file.getFreeSpace(); - this.freeSpaceM = freeSpace / 1024 / 1024; - - // MiB here is not a typo; it is the unit for megabytes calculated - // by powers of 1024 instead of 1000. - this.jLabelHDDFree.setText("HDD Free Space: " + this.freeSpaceM + " MiB"); - - this.jLabelSource = new JLabel(); - this.jLabelSource.setBounds(new Rectangle(63, 45, 267, 17)); - this.jLabelSource.setBorder(BorderFactory.createLineBorder(Color.black, 1)); - this.jLabelSource.setText(""); - this.jLabel1 = new JLabel(); - this.jLabel1.setBounds(new Rectangle(16, 45, 48, 17)); - this.jLabel1.setText("Source:"); - this.jLabel = new JLabel(); - this.jLabel.setBounds(new Rectangle(15, 15, 360, 19)); - this.jLabel.setText("Please select source directory:"); - this.jContentPane = new JPanel(); - this.jContentPane.setLayout(null); - this.jContentPane.add(this.jLabel, null); - this.jContentPane.add(this.jLabel1, null); - this.jContentPane.add(this.jLabelSource, null); - this.jContentPane.add(this.getJButtonSource(), null); - this.jContentPane.add(this.getJPanel(), null); - this.jContentPane.add(this.getJButtonStart(), null); - this.jContentPane.add(this.jLabelHDDFree, null); - this.jContentPane.add(this.jLabelNeedSpace, null); - this.jContentPane.add(this.jLabelTotalFiles, null); - this.jContentPane.add(this.getJProgressBar(), null); - return this.jContentPane; - } - - private JButton getJButtonSource() { - if (this.jButtonSource == null) { - this.jButtonSource = new JButton(); - this.jButtonSource.setBounds(new Rectangle(329, 45, 47, 17)); - this.jButtonSource.setText("..."); - this.jButtonSource.addMouseListener(new java.awt.event.MouseAdapter() { - @Override - public void mouseClicked(final java.awt.event.MouseEvent e) { - JFileChooser chooser; - String choosertitle; - choosertitle = "Select source directory."; - chooser = new JFileChooser(); - chooser.setCurrentDirectory(new java.io.File(".")); - chooser.setDialogTitle(choosertitle); - chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - - chooser.setAcceptAllFileFilterUsed(false); - GuiImportPicture.this.oldText = GuiImportPicture.this.jLabelSource.getText(); - GuiImportPicture.this.jLabelSource.setText("Please wait..."); - if (chooser.showOpenDialog(GuiImportPicture.this) == JFileChooser.APPROVE_OPTION) { - final FileFinder ff = new FileFinder(); - try { - GuiImportPicture.this.listFiles = ff.findFiles(chooser.getSelectedFile().toString(), - ".+\\.jpg"); - } catch (final Exception e2) { - e2.printStackTrace(); - } - GuiImportPicture.this.jLabelSource.setText(chooser.getSelectedFile().toString()); - if (GuiImportPicture.this.jCheckBox.isSelected()) { - GuiImportPicture.this.filesForCopy = ff.getFilesNumber(); - GuiImportPicture.this.jLabelTotalFiles.setText("Total files for copying: " - + GuiImportPicture.this.filesForCopy); - GuiImportPicture.this.jLabelNeedSpace.setText("HDD Need Space: " - + (ff.getDirectorySize() / 1024 / 1024) + " MB"); - GuiImportPicture.this.jProgressBar.setValue(0); - if ((GuiImportPicture.this.freeSpaceM > (ff.getDirectorySize() / 1024 / 1024)) - && (GuiImportPicture.this.filesForCopy > 0)) { - GuiImportPicture.this.jButtonStart.setEnabled(true); - } - - } else { - String fName; - int start; - long filesToCopySize; - GuiImportPicture.this.filesForCopy = 0; - filesToCopySize = 0; - GuiImportPicture.this.fileCopyList = new ArrayList(); - - for (int i = 0; i < GuiImportPicture.this.listFiles.size(); i++) { - - fName = GuiImportPicture.this.listFiles.get(i).getName(); - start = fName.indexOf("full"); - fName = fName.substring(0, start - 1) + fName.substring(start + 4, fName.length() - 4); - //fName = GuiDisplayUtil.cleanString(fName) + ".jpg"; - final File file = new File(NewConstants.CACHE_CARD_PICS_DIR, fName); - if (!file.exists()) { - GuiImportPicture.this.filesForCopy = GuiImportPicture.this.filesForCopy + 1; - filesToCopySize = filesToCopySize + GuiImportPicture.this.listFiles.get(i).length(); - GuiImportPicture.this.fileCopyList.add(GuiImportPicture.this.listFiles.get(i)); - } - } - GuiImportPicture.this.jLabelTotalFiles.setText("Total files for copying: " - + GuiImportPicture.this.filesForCopy); - GuiImportPicture.this.jLabelNeedSpace.setText("HDD Need Space: " - + (filesToCopySize / 1024 / 1024) + " MB"); - GuiImportPicture.this.jProgressBar.setValue(0); - if ((GuiImportPicture.this.freeSpaceM > (filesToCopySize / 1024 / 1024)) - && (GuiImportPicture.this.filesForCopy > 0)) { - GuiImportPicture.this.jButtonStart.setEnabled(true); - } - } - - } else { - if (GuiImportPicture.this.oldText.equals("")) { - GuiImportPicture.this.jLabelSource.setText(""); - } else { - GuiImportPicture.this.jLabelSource.setText(GuiImportPicture.this.oldText); - } - - } - } - }); - } - return this.jButtonSource; - } - - private JPanel getJPanel() { - if (this.jPanel == null) { - final GridBagConstraints gridBagConstraints = new GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridwidth = 2; - gridBagConstraints.insets = new Insets(0, 0, 0, 120); - gridBagConstraints.gridy = 0; - this.jPanel = new JPanel(); - this.jPanel.setLayout(new GridBagLayout()); - this.jPanel.setBounds(new Rectangle(15, 74, 362, 31)); - this.jPanel.setBorder(BorderFactory.createLineBorder(Color.black, 1)); - this.jPanel.add(this.getJCheckBox(), gridBagConstraints); - } - return this.jPanel; - } - - private JCheckBox getJCheckBox() { - if (this.jCheckBox == null) { - this.jCheckBox = new JCheckBox(); - this.jCheckBox.setSelected(false); - this.jCheckBox.setText("Overwriting picture in resource folder"); - this.jCheckBox.addMouseListener(new java.awt.event.MouseAdapter() { - @Override - public void mouseClicked(final java.awt.event.MouseEvent e) { - GuiImportPicture.this.jButtonStart.setEnabled(false); - if (GuiImportPicture.this.jLabelSource.getText().equals("")) { - final FileFinder ff = new FileFinder(); - try { - GuiImportPicture.this.listFiles = ff.findFiles(GuiImportPicture.this.jLabelSource.getText() - .toString(), ".+\\.jpg"); - } catch (final Exception e2) { - e2.printStackTrace(); - } - if (GuiImportPicture.this.jCheckBox.isSelected()) { - GuiImportPicture.this.filesForCopy = ff.getFilesNumber(); - GuiImportPicture.this.jLabelTotalFiles.setText("Total files for copying: " - + GuiImportPicture.this.filesForCopy); - GuiImportPicture.this.jLabelNeedSpace.setText("HDD Need Space: " - + (ff.getDirectorySize() / 1024 / 1024) + " MB"); - GuiImportPicture.this.jProgressBar.setValue(0); - if ((GuiImportPicture.this.freeSpaceM > (ff.getDirectorySize() / 1024 / 1024)) - && (GuiImportPicture.this.filesForCopy > 0)) { - GuiImportPicture.this.jButtonStart.setEnabled(true); - } - } else { - - String fName; - int start; - long filesToCopySize; - GuiImportPicture.this.filesForCopy = 0; - filesToCopySize = 0; - GuiImportPicture.this.fileCopyList = new ArrayList(); - - for (int i = 0; i < GuiImportPicture.this.listFiles.size(); i++) { - - fName = GuiImportPicture.this.listFiles.get(i).getName(); - start = fName.indexOf("full"); - fName = fName.substring(0, start - 1) + fName.substring(start + 4, fName.length() - 4); - //fName = GuiDisplayUtil.cleanString(fName) + ".jpg"; - final File file = new File(NewConstants.CACHE_CARD_PICS_DIR, fName); - if (!file.exists()) { - GuiImportPicture.this.filesForCopy = GuiImportPicture.this.filesForCopy + 1; - filesToCopySize = filesToCopySize + GuiImportPicture.this.listFiles.get(i).length(); - GuiImportPicture.this.fileCopyList.add(GuiImportPicture.this.listFiles.get(i)); - } - } - GuiImportPicture.this.jLabelTotalFiles.setText("Total files for copying: " - + GuiImportPicture.this.filesForCopy); - GuiImportPicture.this.jLabelNeedSpace.setText("HDD Need Space: " - + (filesToCopySize / 1024 / 1024) + " MB"); - GuiImportPicture.this.jProgressBar.setValue(0); - if ((GuiImportPicture.this.freeSpaceM > (filesToCopySize / 1024 / 1024)) - && (GuiImportPicture.this.filesForCopy > 0)) { - GuiImportPicture.this.jButtonStart.setEnabled(true); - } - } - } - } - }); - } - return this.jCheckBox; - } - - private JButton getJButtonStart() { - if (this.jButtonStart == null) { - this.jButtonStart = new JButton(); - this.jButtonStart.setEnabled(false); - this.jButtonStart.setBounds(new Rectangle(136, 239, 123, 17)); - this.jButtonStart.setText("Import"); - // jButtonStart.addMouseListener(new CustomListener()); - this.jButtonStart.addMouseListener(new MouseInputAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - - if (GuiImportPicture.this.jButtonStart.isEnabled()) { - GuiImportPicture.this.jLabelTotalFiles.setText("Please wait while all files are copying."); - if (GuiImportPicture.this.jCheckBox.isSelected()) { - GuiImportPicture.this.jButtonStart.setEnabled(false); - GuiImportPicture.this.jCheckBox.setEnabled(false); - GuiImportPicture.this.jButtonSource.setEnabled(false); - final CopyFiles cFiles = new CopyFiles(GuiImportPicture.this.listFiles, - GuiImportPicture.this.jLabelTotalFiles, GuiImportPicture.this.jProgressBar, - GuiImportPicture.this.jCheckBox, GuiImportPicture.this.jButtonSource); - cFiles.addPropertyChangeListener(new PropertyChangeListener() { - @Override - public void propertyChange(final PropertyChangeEvent evt) { - if ("progress".equals(evt.getPropertyName())) { - GuiImportPicture.this.jProgressBar.setValue((Integer) evt.getNewValue()); - } - } - }); - cFiles.execute(); - } else { - GuiImportPicture.this.jButtonStart.setEnabled(false); - GuiImportPicture.this.jCheckBox.setEnabled(false); - GuiImportPicture.this.jButtonSource.setEnabled(false); - final CopyFiles cFiles = new CopyFiles(GuiImportPicture.this.fileCopyList, - GuiImportPicture.this.jLabelTotalFiles, GuiImportPicture.this.jProgressBar, - GuiImportPicture.this.jCheckBox, GuiImportPicture.this.jButtonSource); - cFiles.addPropertyChangeListener(new PropertyChangeListener() { - @Override - public void propertyChange(final PropertyChangeEvent evt) { - if ("progress".equals(evt.getPropertyName())) { - GuiImportPicture.this.jProgressBar.setValue((Integer) evt.getNewValue()); - } - } - }); - } - } - } - }); - } - return this.jButtonStart; - } - - private JProgressBar getJProgressBar() { - if (this.jProgressBar == null) { - this.jProgressBar = new JProgressBar(); - this.jProgressBar.setBounds(new Rectangle(15, 210, 363, 18)); - this.jProgressBar.setMinimum(0); - this.jProgressBar.setMaximum(100); - } - return this.jProgressBar; - } -} diff --git a/src/main/java/forge/gui/deckeditor/views/VCurrentDeck.java b/src/main/java/forge/gui/deckeditor/views/VCurrentDeck.java index d540c2c3773..1b0dd77d4ec 100644 --- a/src/main/java/forge/gui/deckeditor/views/VCurrentDeck.java +++ b/src/main/java/forge/gui/deckeditor/views/VCurrentDeck.java @@ -76,7 +76,7 @@ public enum VCurrentDeck implements IVDoc, ITableContainer { private final JLabel btnPrintProxies = new FLabel.Builder() .fontSize(14) - .tooltip("Print Proxies") + .tooltip("Print to HTML file") .iconInBackground(true) .iconAlignX(SwingConstants.CENTER) .icon(FSkin.getIcon(FSkin.InterfaceIcons.ICO_PRINT)) diff --git a/src/main/java/forge/gui/home/settings/CSubmenuDownloaders.java b/src/main/java/forge/gui/home/settings/CSubmenuDownloaders.java index 3fe1e13c559..8ae553929f4 100644 --- a/src/main/java/forge/gui/home/settings/CSubmenuDownloaders.java +++ b/src/main/java/forge/gui/home/settings/CSubmenuDownloaders.java @@ -4,7 +4,7 @@ import javax.swing.SwingUtilities; import forge.Command; import forge.error.BugReporter; -import forge.gui.GuiImportPicture; +import forge.gui.DialogMigrateProfile; import forge.gui.download.GuiDownloadPicturesLQ; import forge.gui.download.GuiDownloadPrices; import forge.gui.download.GuiDownloadQuestImages; @@ -33,19 +33,10 @@ public enum CSubmenuDownloaders implements ICDoc { public void execute() { new GuiDownloadPrices(); } }; private final Command cmdHowToPlay = new Command() { @Override public void execute() { VSubmenuDownloaders.SINGLETON_INSTANCE.showHowToPlay(); } }; - - private final Command cmdImportPictures = new Command() { - @Override - public void execute() { - final GuiImportPicture ip = new GuiImportPicture(null); - ip.setVisible(true); - } - }; - + private final Command cmdImportPictures = new Command() { @Override + public void execute() { new DialogMigrateProfile(null, false, null); } }; private final Command cmdReportBug = new Command() { @Override - public void execute() { - BugReporter.reportBug(null); - } + public void execute() { BugReporter.reportBug(null); } }; /* (non-Javadoc) diff --git a/src/main/java/forge/gui/home/settings/VSubmenuDownloaders.java b/src/main/java/forge/gui/home/settings/VSubmenuDownloaders.java index 4bc82a813fd..9a6c54cbfb2 100644 --- a/src/main/java/forge/gui/home/settings/VSubmenuDownloaders.java +++ b/src/main/java/forge/gui/home/settings/VSubmenuDownloaders.java @@ -141,7 +141,7 @@ public enum VSubmenuDownloaders implements IVSubmenu { public void actionPerformed(final ActionEvent arg0) { SOverlayUtils.hideOverlay(); } }); p.add(c, "w 500!"); - p.add(btnClose, "w 200!, h pref+12, center, gaptop 30"); + p.add(btnClose, "w 200!, h pref+12!, center, gaptop 30"); overlay.add(p, "gap 0 0 10% 10%"); SOverlayUtils.showOverlay(); diff --git a/src/main/java/forge/gui/toolbox/FLabel.java b/src/main/java/forge/gui/toolbox/FLabel.java index a7b1a2e86a3..969b78f8d79 100644 --- a/src/main/java/forge/gui/toolbox/FLabel.java +++ b/src/main/java/forge/gui/toolbox/FLabel.java @@ -73,6 +73,7 @@ public class FLabel extends JLabel implements ILocalRepaint { private boolean bldIconScaleAuto = true; protected boolean bldReactOnMouseDown = false; private boolean bldUseSkinColors = true; + private boolean bldEnabled = true; protected String bldText, bldToolTip; private ImageIcon bldIcon; @@ -141,6 +142,10 @@ public class FLabel extends JLabel implements ILocalRepaint { * @return {@link forge.gui.toolbox.Builder} */ public Builder fontStyle(final int i0) { this.bldFontStyle = i0; return this; } + /**@param b0   boolean + * @return {@link forge.gui.toolbox.Builder} */ + public Builder enabled(final boolean b0) { this.bldEnabled = b0; return this; } + /**@param b0   boolean * @return {@link forge.gui.toolbox.Builder} */ public Builder iconScaleAuto(final boolean b0) { this.bldIconScaleAuto = b0; return this; } @@ -193,6 +198,7 @@ public class FLabel extends JLabel implements ILocalRepaint { this.iconAlignX = b0.bldIconAlignX; this.iconInsets = b0.bldIconInsets; + this.setEnabled(b0.bldEnabled); this.setFontStyle(b0.bldFontStyle); this.setFontSize(b0.bldFontSize); this.setUnhoveredAlpha(b0.bldUnhoveredAlpha); diff --git a/src/main/java/forge/model/FModel.java b/src/main/java/forge/model/FModel.java index 8ab5ce81c23..3bcdce5a172 100644 --- a/src/main/java/forge/model/FModel.java +++ b/src/main/java/forge/model/FModel.java @@ -100,7 +100,7 @@ public enum FModel { * if we could not find or write to the log file. */ private FModel() { - // Fire up log file and exception handling + // install our error reporter ExceptionHandler.registerErrorHandling(); // create profile dirs if they don't already exist @@ -115,6 +115,7 @@ public enum FModel { } } + // initialize log file final File logFile = new File(NewConstants.LOG_FILE); final boolean deleteSucceeded = logFile.delete(); diff --git a/src/main/java/forge/properties/ForgeProfileProperties.java b/src/main/java/forge/properties/ForgeProfileProperties.java index 5f2954c1c3d..5f00222fdb2 100644 --- a/src/main/java/forge/properties/ForgeProfileProperties.java +++ b/src/main/java/forge/properties/ForgeProfileProperties.java @@ -59,13 +59,17 @@ public class ForgeProfileProperties { private static String _getDir(Properties props, String propertyKey, String defaultVal) { String retDir = props.getProperty(propertyKey, defaultVal).trim(); if (retDir.isEmpty()) { - // use default if dir is "defined" as an empty or whitespace string in the properties file - return defaultVal; + // use default if dir is "defined" as an empty string in the properties file + retDir = defaultVal; } - if (retDir.endsWith("/") || retDir.endsWith(File.pathSeparator)) { + + // canonicalize + retDir = new File(retDir).getAbsolutePath(); + + if (retDir.endsWith(File.pathSeparator)) { return retDir; } - return retDir + "/"; + return retDir + File.pathSeparator; } // returns a pair diff --git a/src/main/java/forge/properties/NewConstants.java b/src/main/java/forge/properties/NewConstants.java index af19082418c..fefb60b85c5 100644 --- a/src/main/java/forge/properties/NewConstants.java +++ b/src/main/java/forge/properties/NewConstants.java @@ -47,21 +47,21 @@ public final class NewConstants { public static final String DEFAULT_CHALLENGES_DIR = _QUEST_DIR + "challenges"; // data tree roots - private static final String _USER_DIR; - private static final String _CACHE_DIR; - public static final String CACHE_CARD_PICS_DIR; + public static final String USER_DIR; + public static final String CACHE_DIR; + public static final String CACHE_CARD_PICS_DIR; static { ForgeProfileProperties profileProps = new ForgeProfileProperties(PROFILE_FILE); - _USER_DIR = profileProps.userDir; - _CACHE_DIR = profileProps.cacheDir; + USER_DIR = profileProps.userDir; + CACHE_DIR = profileProps.cacheDir; CACHE_CARD_PICS_DIR = profileProps.cardPicsDir; } // data that is only in the profile dirs - private static final String _USER_QUEST_DIR = _USER_DIR + "quest/"; - private static final String _USER_PREFS_DIR = _USER_DIR + "preferences/"; - public static final String LOG_FILE = _USER_DIR + "forge.log"; - public static final String DECK_BASE_DIR = _USER_DIR + "decks/"; + private static final String _USER_QUEST_DIR = USER_DIR + "quest/"; + private static final String _USER_PREFS_DIR = USER_DIR + "preferences/"; + public static final String LOG_FILE = USER_DIR + "forge.log"; + public static final String DECK_BASE_DIR = USER_DIR + "decks/"; public static final String DECK_CONSTRUCTED_DIR = DECK_BASE_DIR + "constructed/"; public static final String DECK_DRAFT_DIR = DECK_BASE_DIR + "draft/"; public static final String DECK_SEALED_DIR = DECK_BASE_DIR + "sealed/"; @@ -80,8 +80,8 @@ public final class NewConstants { public static final FileLocation EDITOR_LAYOUT_FILE = new FileLocation(_DEFAULTS_DIR, _USER_PREFS_DIR, "editor.xml"); // data that is only in the cached dir - private static final String _DB_DIR = _CACHE_DIR + "db/"; - private static final String _PICS_DIR = _CACHE_DIR + "pics/"; + private static final String _DB_DIR = CACHE_DIR + "db/"; + private static final String _PICS_DIR = CACHE_DIR + "pics/"; public static final String CACHE_TOKEN_PICS_DIR = _PICS_DIR + "tokens/"; public static final String CACHE_ICON_PICS_DIR = _PICS_DIR + "icons/"; public static final String CACHE_BOOSTER_PICS_DIR = _PICS_DIR + "boosters/"; @@ -92,6 +92,9 @@ public final class NewConstants { public static final String CACHE_MORPH_IMAGE_FILE = "morph"; public static final String[] PROFILE_DIRS = { + USER_DIR, + CACHE_DIR, + CACHE_CARD_PICS_DIR, _USER_PREFS_DIR, _DB_DIR, DECK_CONSTRUCTED_DIR, @@ -100,7 +103,6 @@ public final class NewConstants { DECK_SCHEME_DIR, DECK_PLANE_DIR, QUEST_SAVE_DIR, - CACHE_CARD_PICS_DIR, CACHE_TOKEN_PICS_DIR, CACHE_ICON_PICS_DIR, CACHE_BOOSTER_PICS_DIR, diff --git a/src/main/java/forge/util/CopyFiles.java b/src/main/java/forge/util/CopyFiles.java deleted file mode 100644 index 75a2dcd904a..00000000000 --- a/src/main/java/forge/util/CopyFiles.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.util; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.List; - -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JProgressBar; -import javax.swing.SwingWorker; - -import forge.properties.NewConstants; - -/** - *

- * CopyFiles class. - *

- * - * @author Forge - * @version $Id$ - */ -public class CopyFiles extends SwingWorker { - - private final List fileList; - - /** The j lb. */ - private final JLabel jLabel; - - /** The j b. */ - private final JProgressBar jProgressBar; - - /** The j check. */ - private final JCheckBox jCheck; - - /** The j source. */ - private final JButton jSource; - - /** The count. */ - private int count; - - /** - *

- * Constructor for CopyFiles. - *

- * - * @param fileList - * a {@link java.util.List} object. - * @param jLabelTotalFiles - * a {@link javax.swing.JLabel} object. - * @param jProgressBar - * a {@link javax.swing.JProgressBar} object. - * @param jCheckBox - * a {@link javax.swing.JCheckBox} object. - * @param jButtonSource - * a {@link javax.swing.JButton} object. - */ - public CopyFiles(final List fileList, final JLabel jLabelTotalFiles, final JProgressBar jProgressBar, - final JCheckBox jCheckBox, final JButton jButtonSource) { - this.fileList = fileList; - this.jLabel = jLabelTotalFiles; - this.jProgressBar = jProgressBar; - this.jCheck = jCheckBox; - this.jSource = jButtonSource; - } - - /** {@inheritDoc} */ - @Override - protected final Void doInBackground() { - for (int i = 0; i < this.fileList.size(); i++) { - this.publish(); - String cName, name, source; - name = this.fileList.get(i).getName(); - source = this.fileList.get(i).getAbsolutePath(); - cName = name.substring(0, name.length() - 8); - //cName = GuiDisplayUtil.cleanString(cName) + ".jpg"; - final File sourceFile = new File(source); - final File reciever = new File(NewConstants.CACHE_CARD_PICS_DIR, cName); - reciever.delete(); - - try { - reciever.createNewFile(); - final FileOutputStream fos = new FileOutputStream(reciever); - final FileInputStream fis = new FileInputStream(sourceFile); - final byte[] buff = new byte[32 * 1024]; - int length; - while (fis.available() > 0) { - length = fis.read(buff); - if (length > 0) { - fos.write(buff, 0, length); - } - } - fos.flush(); - fis.close(); - fos.close(); - this.count = ((i * 100) / this.fileList.size()) + 1; - this.setProgress(this.count); - - } catch (final IOException e1) { - e1.printStackTrace(); - } - - } - return null; - - } - - /** {@inheritDoc} */ - @Override - protected final void done() { - this.jLabel.setText("All files were copied successfully."); - this.jProgressBar.setIndeterminate(false); - this.jCheck.setEnabled(true); - this.jSource.setEnabled(true); - - } - -} diff --git a/src/main/java/forge/util/FileFinder.java b/src/main/java/forge/util/FileFinder.java deleted file mode 100644 index 6f28e372bce..00000000000 --- a/src/main/java/forge/util/FileFinder.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.util; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - *

- * FileFinder class. - *

- * - * @author Forge - * @version $Id$ - */ -public class FileFinder { - - private Pattern p = null; - private Matcher m = null; - private long totalLength = 0; - private int filesNumber = 0; - private long directoriesNumber = 0; - /** Constant FILES=0. */ - private static final int FILES = 0; - /** Constant DIRECTORIES=1. */ - private static final int DIRECTORIES = 1; - private ArrayList fileNames; - private ArrayList fName; - - /** - *

- * Constructor for FileFinder. - *

- */ - public FileFinder() { - } - - /** - *

- * findFiles. - *

- * - * @param startPath - * a {@link java.lang.String} object. - * @param mask - * a {@link java.lang.String} object. - * @return a {@link java.util.List} object. - * @throws Exception - * the exception - */ - public final List findFiles(final String startPath, final String mask) throws Exception { - this.fileNames = new ArrayList(); - this.fName = new ArrayList(); - return this.findWithFull(startPath, mask, FileFinder.FILES); - } - - /** - *

- * getDirectorySize. - *

- * - * @return a long. - */ - public final long getDirectorySize() { - return this.totalLength; - } - - /** - *

- * Getter for the field filesNumber. - *

- * - * @return a int. - */ - public final int getFilesNumber() { - return this.filesNumber; - } - - /** - *

- * Getter for the field directoriesNumber. - *

- * - * @return a long. - */ - public final long getDirectoriesNumber() { - return this.directoriesNumber; - } - - /** - *

- * accept. - *

- * - * @param name - * a {@link java.lang.String} object. - * @return a boolean. - */ - private boolean accept(final String name) { - - if (this.p == null) { - return true; - } - - this.m = this.p.matcher(name); - - return this.m.matches(); - } - - /** - *

- * findWithFull. - *

- * - * @param startPath - * a {@link java.lang.String} object. - * @param mask - * a {@link java.lang.String} object. - * @param objectType - * a int. - * @return a {@link java.util.List} object. - * @throws java.lang.Exception - * if any. - */ - private List findWithFull(final String startPath, final String mask, final int objectType) throws Exception { - - if ((startPath == null) || (mask == null)) { - throw new Exception("Error"); - } - final File topDirectory = new File(startPath); - if (!topDirectory.exists()) { - throw new Exception("Error"); - } - - if (!mask.equals("")) { - this.p = Pattern.compile(mask, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); - } - this.filesNumber = 0; - this.directoriesNumber = 0; - this.totalLength = 0; - final ArrayList res = new ArrayList(100); - - this.searchWithFull(topDirectory, res, objectType); - this.p = null; - return res; - } - - /** - *

- * searchWithFull. - *

- * - * @param topDirectory - * a {@link java.io.File} object. - * @param res - * a {@link java.util.List} object. - * @param objectType - * a int. - */ - private void searchWithFull(final File topDirectory, final List res, final int objectType) { - - final File[] list = topDirectory.listFiles(); - - for (final File element : list) { - - if (element.isDirectory()) { - - if ((objectType != FileFinder.FILES) && this.accept(element.getName())) { - - this.directoriesNumber++; - res.add(element); - } - - this.searchWithFull(element, res, objectType); - } else { - - if ((objectType != FileFinder.DIRECTORIES) && this.accept(element.getName())) { - if (element.getName().contains("full")) { - if (this.fileNames.size() == 0) { - this.fileNames.add(element.getName()); - this.filesNumber++; - this.totalLength += element.length(); - res.add(element); - } - this.fName.add(element.getName()); - if (this.fileNames.size() >= 1) { - if (Collections.indexOfSubList(this.fileNames, this.fName) == -1) { - this.fileNames.add(element.getName()); - this.filesNumber++; - this.totalLength += element.length(); - res.add(element); - } - this.fName.remove(0); - } - } - } - } - } - } - -} diff --git a/src/main/java/forge/view/FView.java b/src/main/java/forge/view/FView.java index 5869b9bb78b..89ac8085ba1 100644 --- a/src/main/java/forge/view/FView.java +++ b/src/main/java/forge/view/FView.java @@ -5,8 +5,11 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.Frame; import java.awt.Graphics; +import java.io.File; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import javax.swing.JFrame; import javax.swing.JLayeredPane; @@ -16,8 +19,12 @@ import javax.swing.border.EmptyBorder; import javax.swing.border.LineBorder; import net.miginfocom.swing.MigLayout; + +import com.google.common.collect.Lists; + import forge.Singletons; import forge.control.FControl; +import forge.gui.DialogMigrateProfile; import forge.gui.deckeditor.VDeckEditorUI; import forge.gui.framework.DragCell; import forge.gui.framework.EDocID; @@ -29,6 +36,7 @@ import forge.gui.toolbox.FOverlay; import forge.gui.toolbox.FPanel; import forge.gui.toolbox.FSkin; import forge.model.BuildInfo; +import forge.properties.NewConstants; /** */ public enum FView { @@ -108,7 +116,6 @@ public enum FView { // All is ready to go - fire up home screen and discard splash frame. Singletons.getControl().changeState(FControl.Screens.HOME_SCREEN); - //CMainMenu.SINGLETON_INSTANCE.selectPrevious(); FView.this.frmSplash.dispose(); FView.this.frmSplash = null; @@ -116,6 +123,35 @@ public enum FView { // Allow OS to set location. Hopefully this doesn't cause issues frmDocument.setLocationByPlatform(true); frmDocument.setVisible(true); + + // remove this once our userbase has been migrated to the profile layout + { + // get profile directories -- if one of them is actually under the res directory, don't + // try to migrate it + Set profileDirs = new HashSet(); + for (String dname : NewConstants.PROFILE_DIRS) { + profileDirs.add(new File(dname)); + } + + // check quickly whether we have any data to migrate + boolean hasData = false; + for (String resDir : Lists.newArrayList("decks", "gauntlet", "pics", "pics_product", "preferences", "quest/data")) { + File f = new File("res", resDir); + if (f.exists() && !profileDirs.contains(f)) { + System.out.println("pre-profile data found: " + f.getAbsolutePath()); + hasData = true; + break; + } + } + + if (hasData) { + new DialogMigrateProfile("res", true, new Runnable() { + @Override public void run() { + // TODO: reload appropriate data structures + } + }); + } + } } /** @return {@link forge.view.SplashFrame} */