/** * Copy card images only if imported version stores them in the "Magarena\cards" and * "Magarena\tokens" directories. */ private void importCardData() { setProgressNote(UiString.get(_S10)); boolean isMissingFiles = false; if (GeneralConfig.getInstance().isCustomCardImagesPath() == false) { final File[] oldDirs = { new File(importDataPath.toFile(), MagicFileSystem.CARD_IMAGE_FOLDER), new File(importDataPath.toFile(), MagicFileSystem.TOKEN_IMAGE_FOLDER) }; final List<MagicCardDefinition> cards = CardDefinitions.getAllCards(); final double totalFiles = cards.size(); int loopCount = 0; for (final MagicCardDefinition card : cards) { // check if file is in previous version for (final File oldDir : oldDirs) { final File newFile = MagicFileSystem.getCardImageFile(card); final File oldFile = new File(oldDir, newFile.getName()); if (oldFile.exists()) { try { FileUtils.copyFile(oldFile, newFile); break; } catch (IOException ex) { System.err.println("Unable to copy " + oldFile); } } else { isMissingFiles = true; } } loopCount++; setProgress((int) ((loopCount / totalFiles) * 100)); if (isCancelled()) { setProgressNote(String.format("%s\n", UiString.get(_S11))); return; } } // refresh magic.ui.CachedImagesProvider.getInstance().clearCache(); } GeneralConfig.getInstance().setIsMissingFiles(isMissingFiles); setProgressNote(OK_STRING); }
public static String getKeywordsFileContent() { final String content = getResourceFileContent( String.format( "/magic/data/keywords/%s.txt", GeneralConfig.getInstance().getTranslation())); return content.isEmpty() ? getResourceFileContent("/magic/data/keywords/English.txt") : content; }
/** Merges "general.cfg" file. If setting already exists then imported value takes precedence. */ private void importPreferences() throws IOException { setProgressNote(UiString.get(_S5)); final String CONFIG_FILENAME = "general.cfg"; // Create new config file with default settings. final File thisConfigFile = MagicFileSystem.getDataPath().resolve(CONFIG_FILENAME).toFile(); if (thisConfigFile.exists()) { thisConfigFile.delete(); } GeneralConfig.getInstance().save(); final Properties thisProperties = FileIO.toProp(thisConfigFile); final Properties theirProperties = FileIO.toProp(importDataPath.resolve(CONFIG_FILENAME).toFile()); // list of latest config settings. final List<String> thisSettings = new ArrayList<>(thisProperties.stringPropertyNames()); // not interested in importing these settings. thisSettings.removeAll( Arrays.asList("left", "fullScreen", "top", "height", "width", "translation")); // import settings... for (String setting : thisSettings) { if (theirProperties.containsKey(setting)) { thisProperties.setProperty(setting, theirProperties.getProperty(setting)); } } // save updated preferences and reload. FileIO.toFile(thisConfigFile, thisProperties, "General configuration"); GeneralConfig.getInstance().load(); setProgressNote(OK_STRING); }
@Override protected String getAlertCaption() { assert !SwingUtilities.isEventDispatchThread(); if (!hasChecked || isVisible()) { isMissingImages = CardDefinitions.isMissingImages(); GeneralConfig.getInstance().setIsMissingFiles(isMissingImages); hasChecked = true; } if (isMissingImages) { return UiString.get(_S1); } else { return ""; } }