Example #1
0
  /**
   * 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);
  }
  @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 "";
    }
  }
Example #3
0
 /**
  * Rebuilds the "newcards.log" file so that it contains all the new playable cards which have been
  * added since the imported and current versions.
  */
 private void updateNewCardsLog() {
   setProgressNote(UiString.get(_S2));
   setProgress(0);
   final File scriptsDirectory = this.importDataPath.resolve("scripts").toFile();
   final File[] scriptFiles = MagicFileSystem.getSortedScriptFiles(scriptsDirectory);
   final List<String> cards = new ArrayList<>();
   final int countMax = scriptFiles.length;
   int count = 0;
   for (final File file : scriptFiles) {
     final Properties content = FileIO.toProp(file);
     cards.add(content.getProperty("name"));
     count++;
     setProgress((int) ((count / (double) countMax) * 100));
   }
   CardDefinitions.updateNewCardsLog(cards);
   setProgressNote(OK_STRING);
 }