From 8765f6ec4520e88a854eaaff8a68ab59c5fd7880 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 13 Oct 2016 02:06:11 +0200 Subject: [PATCH] * Some fixes to symbol download for sets. --- .../org/mage/plugins/card/dl/Downloader.java | 4 + .../plugins/card/dl/sources/GathererSets.java | 177 ++++++++++-------- 2 files changed, 106 insertions(+), 75 deletions(-) diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/dl/Downloader.java b/Mage.Client/src/main/java/org/mage/plugins/card/dl/Downloader.java index ca5160a71d..92759be7ec 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/dl/Downloader.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/dl/Downloader.java @@ -153,6 +153,10 @@ public class Downloader extends AbstractLaternaBean implements Disposable { } finally { try { os.close(); + if (!dst.isValid()) { + dst.delete(); + logger.warn("Resource not found " + job.getName() + " from " + job.getSource().toString()); + } } catch (IOException ex) { logger.warn("While closing", ex); } diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/GathererSets.java b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/GathererSets.java index 6976992128..35df357243 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/GathererSets.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/GathererSets.java @@ -2,8 +2,12 @@ package org.mage.plugins.card.dl.sources; import java.io.File; import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; import java.util.HashMap; import java.util.Iterator; +import mage.cards.ExpansionSet; +import mage.cards.Sets; import org.mage.plugins.card.dl.DownloadJob; import static org.mage.plugins.card.dl.DownloadJob.fromURL; import static org.mage.plugins.card.dl.DownloadJob.toFile; @@ -14,90 +18,97 @@ public class GathererSets implements Iterable { private static final File DEFAULT_OUT_DIR = new File("plugins" + File.separator + "images" + SETS_PATH); private static File outDir = DEFAULT_OUT_DIR; - private static final String[] symbols = {"10E", "9ED", "8ED", "7ED", "6ED", "5ED", "4ED", "3ED", "2ED", "LEB", "LEA", - "HOP", - "ARN", "ATQ", "LEG", "DRK", "FEM", "HML", - "ICE", "ALL", "CSP", - "MIR", "VIS", "WTH", - "TMP", "STH", "EXO", - "USG", "ULG", "UDS", - "MMQ", "NMS", "PCY", - "INV", "PLS", "APC", - "ODY", "TOR", "JUD", - "ONS", "LGN", "SCG", - "MRD", "DST", "5DN", - "CHK", "BOK", "SOK", - "RAV", "GPT", "DIS", - "TSP", "TSB", "PLC", "FUT", - "LRW", "MOR", - "SHM", "EVE", - "MED", "ME2", "ME3", "ME4", - "POR", "PO2", "PTK", - "ARC", - "W16"}; + private static final String[] symbols = {"10E", "9ED", "8ED", "7ED", "6ED", "5ED", "4ED", "3ED", "2ED", "LEB", "LEA", + "HOP", + "ARN", "ATQ", "LEG", "DRK", "FEM", "HML", + "ICE", "ALL", "CSP", + "MIR", "VIS", "WTH", + "TMP", "STH", "EXO", + "USG", "ULG", "UDS", + "MMQ", "NEM", "PCY", + "INV", "PLS", "APC", + "ODY", "TOR", "JUD", + "ONS", "LGN", "SCG", + "MRD", "DST", "5DN", + "CHK", "BOK", "SOK", + "RAV", "GPT", "DIS", + "TSP", "TSB", "PLC", "FUT", + "LRW", "MOR", + "SHM", "EVE", + "MED", "ME2", "ME3", "ME4", + "POR", "PO2", "PTK", + "ARC", "DD3EVG", + "W16"}; private static final String[] withMythics = {"M10", "M11", "M12", "M13", "M14", "M15", "ORI", - "ANB", - "DDF", "DDG", "DDH", "DDI", "DDJ", "DDK", "DDL", "DDM", "DDN", - "DD3", "DD3B", "DDO", "DDP", "DDQ", "DDR", "DDS", - "FVD", "FVE", "FVL", "FVR", - "V12", "V13", "V14", "V15", "V16", - "ALA", "CON", "ARB", - "ZEN", "WWK", "ROE", - "SOM", "MBS", "NPH", - "CMD", "C13", "C14", "C15", "C16", "CMA", - "PC2", "PCA", - "ISD", "DKA", "AVR", - "RTR", "GTC", "DGM", - "MMA", "MM2", "EMA", "MM3", - "THS", "BNG", "JOU", - "CNS", "CN2", - "VMA", "TPR", - "KTK", "FRF", "DTK", - "BFZ", "EXP", "OGW", - "SOI", "EMN", - "KLD", "MPS", "AER", - "AKH", "HOU" - }; + "ANB", + "DDF", "DDG", "DDH", "DDI", "DDJ", "DDK", "DDL", "DDM", "DDN", + "DD3DVD", "DD3GLV", "DD3JVC", "DDO", "DDP", "DDQ", "DDR", "DDS", + "ALA", "CON", "ARB", + "ZEN", "WWK", "ROE", + "SOM", "MBS", "NPH", + "CMD", "C13", "C14", "C15", "C16", "CMA", + "PC2", "PCA", + "ISD", "DKA", "AVR", + "RTR", "GTC", "DGM", + "MMA", "MM2", "EMA", "MM3", + "THS", "BNG", "JOU", + "CNS", "CN2", + "VMA", "TPR", + "KTK", "FRF", "DTK", + "BFZ", "OGW", + "SOI", "EMN", + "KLD", "MPS", "AER", + "AKH", "HOU" + }; + + private static final String[] onlyMythics = { + "DRB", "V09", "V12", "V12", "V13", "V14", "V15", "V16", "EXP" + }; + private static final HashMap symbolsReplacements = new HashMap<>(); static { + symbolsReplacements.put("2ED", "2U"); + symbolsReplacements.put("3ED", "3E"); + symbolsReplacements.put("4ED", "4E"); + symbolsReplacements.put("5ED", "5E"); + symbolsReplacements.put("6ED", "6E"); + symbolsReplacements.put("7ED", "7E"); + symbolsReplacements.put("ALL", "AL"); + symbolsReplacements.put("APC", "AP"); symbolsReplacements.put("ARN", "AN"); symbolsReplacements.put("ATQ", "AQ"); - symbolsReplacements.put("LEG", "LE"); + symbolsReplacements.put("CMA", "CM1"); + symbolsReplacements.put("DD3DVD", "DD3_DVD"); + symbolsReplacements.put("DD3EVG", "DD3_EVG"); + symbolsReplacements.put("DD3GLV", "DD3_GLV"); + symbolsReplacements.put("DD3JVC", "DD3_JVC"); symbolsReplacements.put("DRK", "DK"); + symbolsReplacements.put("EXO", "EX"); symbolsReplacements.put("FEM", "FE"); symbolsReplacements.put("HML", "HM"); symbolsReplacements.put("ICE", "IA"); - symbolsReplacements.put("ALL", "AL"); - symbolsReplacements.put("APC", "AP"); - symbolsReplacements.put("TMP", "TE"); symbolsReplacements.put("INV", "IN"); + symbolsReplacements.put("LEA", "1E"); + symbolsReplacements.put("LEB", "2E"); + symbolsReplacements.put("LEG", "LE"); + symbolsReplacements.put("MIR", "MI"); + symbolsReplacements.put("MMQ", "MM"); + symbolsReplacements.put("NEM", "NE"); + symbolsReplacements.put("ODY", "OD"); + symbolsReplacements.put("PCY", "PR"); symbolsReplacements.put("PLS", "PS"); - symbolsReplacements.put("WTH", "WL"); + symbolsReplacements.put("POR", "PO"); + symbolsReplacements.put("PO2", "P2"); + symbolsReplacements.put("PTK", "PK"); + symbolsReplacements.put("STH", "ST"); + symbolsReplacements.put("TMP", "TE"); + symbolsReplacements.put("UDS", "CG"); symbolsReplacements.put("ULG", "GU"); symbolsReplacements.put("USG", "UZ"); - symbolsReplacements.put("UDS", "CG"); - symbolsReplacements.put("ODY", "OD"); - symbolsReplacements.put("MMQ", "MM"); - symbolsReplacements.put("NMS", "NE"); - symbolsReplacements.put("PCY", "PR"); - symbolsReplacements.put("STH", "ST"); - symbolsReplacements.put("EXO", "EX"); symbolsReplacements.put("VIS", "VI"); - symbolsReplacements.put("MIR", "MI"); - symbolsReplacements.put("7ED", "7E"); - symbolsReplacements.put("6ED", "6E"); - symbolsReplacements.put("5ED", "5E"); - symbolsReplacements.put("4ED", "4E"); - symbolsReplacements.put("3ED", "3E"); - symbolsReplacements.put("2ED", "2U"); - symbolsReplacements.put("LEB", "2E"); - symbolsReplacements.put("LEA", "1E"); - symbolsReplacements.put("DD3A", "DD3"); - symbolsReplacements.put("DD3B", "DD3"); - symbolsReplacements.put("DD3C", "DD3"); - symbolsReplacements.put("DD3D", "DD3"); + symbolsReplacements.put("WTH", "WL"); } public GathererSets(String path) { @@ -110,17 +121,33 @@ public class GathererSets implements Iterable { @Override public Iterator iterator() { + Calendar c = Calendar.getInstance(); + c.setTime(new Date()); + c.add(Calendar.DATE, -14); + Date compareDate = c.getTime(); ArrayList jobs = new ArrayList<>(); for (String symbol : symbols) { - jobs.add(generateDownloadJob(symbol, "C")); - jobs.add(generateDownloadJob(symbol, "U")); - jobs.add(generateDownloadJob(symbol, "R")); + ExpansionSet exp = Sets.findSet(symbol); + if (exp != null && exp.getReleaseDate().before(compareDate)) { + jobs.add(generateDownloadJob(symbol, "C")); + jobs.add(generateDownloadJob(symbol, "U")); + jobs.add(generateDownloadJob(symbol, "R")); + } } for (String symbol : withMythics) { - jobs.add(generateDownloadJob(symbol, "C")); - jobs.add(generateDownloadJob(symbol, "U")); - jobs.add(generateDownloadJob(symbol, "R")); - jobs.add(generateDownloadJob(symbol, "M")); + ExpansionSet exp = Sets.findSet(symbol); + if (exp != null && exp.getReleaseDate().before(compareDate)) { + jobs.add(generateDownloadJob(symbol, "C")); + jobs.add(generateDownloadJob(symbol, "U")); + jobs.add(generateDownloadJob(symbol, "R")); + jobs.add(generateDownloadJob(symbol, "M")); + } + } + for (String symbol : onlyMythics) { + ExpansionSet exp = Sets.findSet(symbol); + if (exp != null && exp.getReleaseDate().before(compareDate)) { + jobs.add(generateDownloadJob(symbol, "M")); + } } return jobs.iterator(); }