* Cleanup logs from load svg/gif errors (show total errors instead each symbol)

This commit is contained in:
Oleg Agafonov 2018-08-26 01:15:11 +04:00
parent d5c8d68fa1
commit 3f16a83fd3

View file

@ -37,6 +37,7 @@ import java.util.regex.Pattern;
import java.util.stream.IntStream; import java.util.stream.IntStream;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.swing.*; import javax.swing.*;
import mage.cards.repository.ExpansionRepository; import mage.cards.repository.ExpansionRepository;
import mage.client.MageFrame; import mage.client.MageFrame;
import mage.client.constants.Constants; import mage.client.constants.Constants;
@ -81,6 +82,7 @@ public final class ManaSymbols {
withoutSymbols.add("MPRP"); withoutSymbols.add("MPRP");
} }
private static final Map<String, Dimension> setImagesExist = new HashMap<>(); private static final Map<String, Dimension> setImagesExist = new HashMap<>();
private static final Pattern REPLACE_SYMBOLS_PATTERN = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}"); private static final Pattern REPLACE_SYMBOLS_PATTERN = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}");
@ -98,6 +100,7 @@ public final class ManaSymbols {
private static String getSvgPathToCss() { private static String getSvgPathToCss() {
return getImagesDir() + File.separator + "temp" + File.separator + "batic-svg-settings.css"; return getImagesDir() + File.separator + "temp" + File.separator + "batic-svg-settings.css";
} }
private static void prepareSvg(Boolean forceToCreateCss) { private static void prepareSvg(Boolean forceToCreateCss) {
File f = new File(getSvgPathToCss()); File f = new File(getSvgPathToCss());
@ -123,14 +126,15 @@ public final class ManaSymbols {
w.write(css); w.write(css);
} catch (Throwable e) { } catch (Throwable e) {
LOGGER.error("Can't create css file for svg", e); LOGGER.error("Can't create css file for svg", e);
} } finally {
finally {
StreamUtils.closeQuietly(w); StreamUtils.closeQuietly(w);
} }
} }
} }
public static void loadImages() { public static void loadImages() {
LOGGER.info("Loading symbols...");
// TODO: delete files rename jpg->gif (it was for backward compatibility for one of the old version?) // TODO: delete files rename jpg->gif (it was for backward compatibility for one of the old version?)
renameSymbols(getResourceSymbolsPath(ResourceSymbolSize.SMALL)); renameSymbols(getResourceSymbolsPath(ResourceSymbolSize.SMALL));
renameSymbols(getResourceSymbolsPath(ResourceSymbolSize.MEDIUM)); renameSymbols(getResourceSymbolsPath(ResourceSymbolSize.MEDIUM));
@ -298,7 +302,7 @@ public final class ManaSymbols {
shadowY = 2 * Math.round(1f / 16f * resizeToHeight); shadowY = 2 * Math.round(1f / 16f * resizeToHeight);
resizeToWidth = resizeToWidth - shadowX; resizeToWidth = resizeToWidth - shadowX;
resizeToHeight = resizeToHeight - shadowY; resizeToHeight = resizeToHeight - shadowY;
}; }
if (resizeToWidth > 0) { if (resizeToWidth > 0) {
transcoderHints.put(ImageTranscoder.KEY_WIDTH, (float) resizeToWidth); //your image width transcoderHints.put(ImageTranscoder.KEY_WIDTH, (float) resizeToWidth); //your image width
@ -453,7 +457,8 @@ public final class ManaSymbols {
// priority: SVG -> GIF // priority: SVG -> GIF
// gif remain for backward compatibility // gif remain for backward compatibility
//boolean fileErrors = false; int[] iconErrors = new int[2]; // 0 - svg, 1 - gif
AtomicBoolean fileErrors = new AtomicBoolean(false); AtomicBoolean fileErrors = new AtomicBoolean(false);
Map<String, BufferedImage> sizedSymbols = new ConcurrentHashMap<>(); Map<String, BufferedImage> sizedSymbols = new ConcurrentHashMap<>();
IntStream.range(0, symbols.length).parallel().forEach(i -> { IntStream.range(0, symbols.length).parallel().forEach(i -> {
@ -469,7 +474,8 @@ public final class ManaSymbols {
// gif // gif
if (image == null) { if (image == null) {
//LOGGER.info("SVG symbol can't be load: " + file.getPath());
iconErrors[0] += 1; // svg fail
file = getSymbolFileNameAsGIF(symbol, size); file = getSymbolFileNameAsGIF(symbol, size);
if (file.exists()) { if (file.exists()) {
@ -481,11 +487,27 @@ public final class ManaSymbols {
if (image != null) { if (image != null) {
sizedSymbols.put(symbol, image); sizedSymbols.put(symbol, image);
} else { } else {
iconErrors[1] += 1; // gif fail
fileErrors.set(true); fileErrors.set(true);
LOGGER.warn("SVG or GIF symbol can't be load: " + symbol);
} }
}); });
// total errors
String errorInfo = "";
if (iconErrors[0] > 0) {
errorInfo += "SVG fails - " + iconErrors[0];
}
if (iconErrors[1] > 0) {
if (!errorInfo.isEmpty()) {
errorInfo += ", ";
}
errorInfo += "GIF fails - " + iconErrors[1];
}
if (!errorInfo.isEmpty()) {
LOGGER.warn("Symbols can't be load for size " + size + ": " + errorInfo);
}
manaImages.put(size, sizedSymbols); manaImages.put(size, sizedSymbols);
return !fileErrors.get(); return !fileErrors.get();
} }