From 47b2a64cee80682dfdf54a04e31b25defd8b5582 Mon Sep 17 00:00:00 2001 From: rkfg Date: Fri, 4 Mar 2016 00:59:12 +0300 Subject: [PATCH] Store symbols as .gif instead of .jpg, rename already downloaded ones on start, fixes #98. --- .../org/mage/card/arcane/ManaSymbols.java | 35 +++++++++++++++++-- .../card/dl/sources/GathererSymbols.java | 2 +- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Mage.Client/src/main/java/org/mage/card/arcane/ManaSymbols.java b/Mage.Client/src/main/java/org/mage/card/arcane/ManaSymbols.java index 7aa3ef492af..7d133699f0f 100644 --- a/Mage.Client/src/main/java/org/mage/card/arcane/ManaSymbols.java +++ b/Mage.Client/src/main/java/org/mage/card/arcane/ManaSymbols.java @@ -6,6 +6,16 @@ import java.awt.Image; import java.awt.Rectangle; import java.awt.image.BufferedImage; import java.io.File; +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.PathMatcher; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.StandardCopyOption; +import java.nio.file.attribute.BasicFileAttributes; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -36,6 +46,7 @@ public class ManaSymbols { "WP", "UP", "BP", "RP", "GP", "X", "C"}; public static void loadImages() { + renameSymbols(getSymbolsPath() + File.separator + "symbols"); smallSymbolsFound = loadSymbolsImages(15); mediumSymbolsFound = loadSymbolsImages(25); @@ -148,6 +159,24 @@ public class ManaSymbols { return !fileErrors; } + private static void renameSymbols(String path) { + final PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:**/*.jpg"); + try { + Files.walkFileTree(Paths.get(path), new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + if (matcher.matches(file)) { + Path gifPath = file.resolveSibling(file.getFileName().toString().replaceAll("\\.jpg$", ".gif")); + Files.move(file, gifPath, StandardCopyOption.REPLACE_EXISTING); + } + return FileVisitResult.CONTINUE; + } + }); + } catch (IOException e) { + LOGGER.error("Couldn't rename mana symbols!"); + } + } + private static String getSymbolsPath() { return getSymbolsPath(false); } @@ -247,9 +276,9 @@ public class ManaSymbols { symbolFilesFound = mediumSymbolsFound; } if (symbolFilesFound) { - replaced = REPLACE_SYMBOLS_PATTERN.matcher(value).replaceAll("$1$2"); + replaced = REPLACE_SYMBOLS_PATTERN.matcher(value).replaceAll( + "$1$2"); } replaced = replaced.replace("|source|", "{source}"); replaced = replaced.replace("|this|", "{this}"); diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/GathererSymbols.java b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/GathererSymbols.java index bd25bd00594..10bd03ff7a9 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/GathererSymbols.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/GathererSymbols.java @@ -71,7 +71,7 @@ public class GathererSymbols implements Iterable { return computeNext(); } String symbol = sym.replaceAll("/", ""); - File dst = new File(dir, symbol + ".jpg"); + File dst = new File(dir, symbol + ".gif"); switch (symbol) { case "T":