mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
Fixed too large temp files creation for svg icons on startup
This commit is contained in:
parent
8b8392f42c
commit
09f5af154e
4 changed files with 46 additions and 22 deletions
|
@ -325,6 +325,7 @@ public class DeckGeneratorDialog {
|
|||
// Generated deck has a nice unique name which corresponds to the timestamp at which it was created.
|
||||
String deckName = "Generated-Deck-" + dateFormat.format(new Date());
|
||||
File tmp = new File(tempDir + File.separator + deckName + ".dck");
|
||||
tmp.getParentFile().mkdirs();
|
||||
tmp.createNewFile();
|
||||
deck.setName(deckName);
|
||||
Sets.saveDeck(tmp.getAbsolutePath(), deck.getDeckCardLists());
|
||||
|
|
|
@ -57,6 +57,7 @@ public final class SaveObjectUtil {
|
|||
String time = now(DATE_PATTERN);
|
||||
File f = new File("income" + File.separator + name + '_' + time + ".save");
|
||||
if (!f.exists()) {
|
||||
f.getParentFile().mkdirs();
|
||||
f.createNewFile();
|
||||
}
|
||||
oos = new ObjectOutputStream(new FileOutputStream(f));
|
||||
|
|
|
@ -56,6 +56,8 @@ import org.apache.batik.util.SVGConstants;
|
|||
import org.apache.log4j.Logger;
|
||||
import org.mage.plugins.card.utils.CardImageUtils;
|
||||
|
||||
import static org.mage.plugins.card.utils.CardImageUtils.getImagesDir;
|
||||
|
||||
public final class ManaSymbols {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(ManaSymbols.class);
|
||||
|
@ -93,6 +95,41 @@ public final class ManaSymbols {
|
|||
|
||||
private static final JLabel labelRender = new JLabel(); // render mana text
|
||||
|
||||
private static String getSvgPathToCss() {
|
||||
return getImagesDir() + File.separator + "temp" + File.separator + "batic-svg-settings.css";
|
||||
}
|
||||
private static void prepareSvg(Boolean forceToCreateCss) {
|
||||
File f = new File(getSvgPathToCss());
|
||||
|
||||
if (forceToCreateCss || !f.exists()) {
|
||||
|
||||
// Rendering hints can't be set programatically, so
|
||||
// we override defaults with a temporary stylesheet.
|
||||
// These defaults emphasize quality and precision, and
|
||||
// are more similar to the defaults of other SVG viewers.
|
||||
// SVG documents can still override these defaults.
|
||||
String css = "svg {"
|
||||
+ "shape-rendering: geometricPrecision;"
|
||||
+ "text-rendering: geometricPrecision;"
|
||||
+ "color-rendering: optimizeQuality;"
|
||||
+ "image-rendering: optimizeQuality;"
|
||||
+ "}";
|
||||
|
||||
FileWriter w = null;
|
||||
try {
|
||||
f.getParentFile().mkdirs();
|
||||
f.createNewFile();
|
||||
w = new FileWriter(f);
|
||||
w.write(css);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error("Can't create css file for svg", e);
|
||||
}
|
||||
finally {
|
||||
StreamUtils.closeQuietly(w);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadImages() {
|
||||
// TODO: delete files rename jpg->gif (it was for backward compatibility for one of the old version?)
|
||||
renameSymbols(getResourceSymbolsPath(ResourceSymbolSize.SMALL));
|
||||
|
@ -101,6 +138,9 @@ public final class ManaSymbols {
|
|||
//renameSymbols(getSymbolsPath(ResourceSymbolSize.SVG)); // not need
|
||||
// TODO: remove medium sets files to "medium" folder like symbols above?
|
||||
|
||||
// prepare svg settings
|
||||
prepareSvg(true);
|
||||
|
||||
// preload symbol images
|
||||
loadSymbolImages(15);
|
||||
loadSymbolImages(25);
|
||||
|
@ -243,26 +283,9 @@ public final class ManaSymbols {
|
|||
|
||||
final BufferedImage[] imagePointer = new BufferedImage[1];
|
||||
|
||||
// Rendering hints can't be set programatically, so
|
||||
// we override defaults with a temporary stylesheet.
|
||||
// These defaults emphasize quality and precision, and
|
||||
// are more similar to the defaults of other SVG viewers.
|
||||
// SVG documents can still override these defaults.
|
||||
String css = "svg {"
|
||||
+ "shape-rendering: geometricPrecision;"
|
||||
+ "text-rendering: geometricPrecision;"
|
||||
+ "color-rendering: optimizeQuality;"
|
||||
+ "image-rendering: optimizeQuality;"
|
||||
+ "}";
|
||||
|
||||
File cssFile = File.createTempFile("batik-default-override-", ".css");
|
||||
FileWriter w = null;
|
||||
try {
|
||||
w = new FileWriter(cssFile);
|
||||
w.write(css);
|
||||
} finally {
|
||||
StreamUtils.closeQuietly(w);
|
||||
}
|
||||
// css settings for svg
|
||||
prepareSvg(false);
|
||||
File cssFile = new File(getSvgPathToCss());
|
||||
|
||||
TranscodingHints transcoderHints = new TranscodingHints();
|
||||
|
||||
|
@ -311,8 +334,6 @@ public final class ManaSymbols {
|
|||
t.transcode(input, null);
|
||||
} catch (Exception e) {
|
||||
throw new IOException("Couldn't convert svg file: " + svgFile + " , reason: " + e.getMessage());
|
||||
} finally {
|
||||
cssFile.delete();
|
||||
}
|
||||
|
||||
BufferedImage originImage = imagePointer[0];
|
||||
|
|
|
@ -41,6 +41,7 @@ public class CounterPluginImpl implements CounterPlugin {
|
|||
File data = new File(PLUGIN_DATA_FOLDER_PATH + File.separator + DATA_STORAGE_FILE);
|
||||
if (!data.exists()) {
|
||||
try {
|
||||
data.getParentFile().mkdirs();
|
||||
data.createNewFile();
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
|
|
Loading…
Reference in a new issue