From 3a306429697983064dfb6d75894482b0f7eac7b7 Mon Sep 17 00:00:00 2001 From: truongdatnhan Date: Thu, 21 Jul 2022 14:48:52 +0700 Subject: [PATCH 1/3] Update .gitignore --- .gitignore | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 96502955e0..580bdf21a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/logs/** +/logs/** .idea/ *.iml /target @@ -7,6 +7,12 @@ /build/ /dist/ /nbproject/ - +/.settings /out *.onetoc2 + +# Eclipse m2e generated files +# Eclipse Core +.project +# JDT-specific (Eclipse Java Development Tools) +.classpath From d42a57ef7902f98542bf9fd598f6aedc24385ecf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BA=A1t=20Nh=C3=A2n=20Tr=C6=B0=C6=A1ng?= Date: Thu, 21 Jul 2022 15:00:30 +0700 Subject: [PATCH 2/3] Update dependencies ! --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 2d53675e85..a72823045b 100644 --- a/pom.xml +++ b/pom.xml @@ -25,15 +25,15 @@ 1.7.36 - 2.17.1 - 21.1.0 - 4.1.74.Final + 2.18.0 + 22.2.0 + 4.1.79.Final 5.8.2 1.15 1.0 2.11.0 5.0.1 - 8.0.28 + 8.0.29 From a44744c05b10e389cafde72074df9cac5cb2072d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BA=A1t=20Nh=C3=A2n=20Tr=C6=B0=C6=A1ng?= Date: Sat, 30 Jul 2022 16:10:46 +0700 Subject: [PATCH 3/3] Upgrade to Java NIO --- handbook/Use.txt | 2 +- src/main/java/client/Stat.java | 42 +------ .../java/provider/DataProviderFactory.java | 3 +- src/main/java/provider/wz/WZFiles.java | 8 +- .../java/provider/wz/XMLDomMapleData.java | 15 +-- src/main/java/provider/wz/XMLWZFile.java | 68 +++++----- .../java/tools/mapletools/ArrowFetcher.java | 10 +- .../tools/mapletools/BossHpBarFetcher.java | 43 ++++--- .../mapletools/CashCosmeticsChecker.java | 93 +++++++------- .../tools/mapletools/CashDropFetcher.java | 9 +- .../tools/mapletools/CashVegaChecker.java | 10 +- .../tools/mapletools/CodeCouponGenerator.java | 38 +++--- .../java/tools/mapletools/DojoUpdate.java | 99 +++++++++------ .../tools/mapletools/EmptyItemWzChecker.java | 17 +-- .../mapletools/EquipmentOmniLeveller.java | 119 +++++++++--------- .../mapletools/GachaponItemIdRetriever.java | 46 ++++--- .../java/tools/mapletools/IdRetriever.java | 34 ++--- .../tools/mapletools/MapInfoRetriever.java | 12 +- .../java/tools/mapletools/MesoFetcher.java | 58 +++++---- .../java/tools/mapletools/MobBookIndexer.java | 26 ++-- .../java/tools/mapletools/MobBookUpdate.java | 31 +++-- .../tools/mapletools/MonsterStatFetcher.java | 13 ++ .../tools/mapletools/NoItemIdFetcher.java | 13 +- .../tools/mapletools/NoItemNameFetcher.java | 26 ++-- .../mapletools/QuestItemCountFetcher.java | 9 +- .../tools/mapletools/QuestItemFetcher.java | 26 ++-- .../tools/mapletools/QuestMesoFetcher.java | 17 ++- .../tools/mapletools/QuestlineFetcher.java | 17 ++- .../tools/mapletools/ReactorDropFetcher.java | 11 +- .../tools/mapletools/SkillMakerFetcher.java | 17 ++- .../mapletools/SkillMakerReagentIndexer.java | 17 ++- .../mapletools/SkillbookChanceFetcher.java | 9 +- .../mapletools/SkillbookStackUpdate.java | 71 ++++++----- .../java/tools/mapletools/ToolConstants.java | 15 +-- .../tools/mapletools/WorldmapChecker.java | 9 +- 35 files changed, 553 insertions(+), 500 deletions(-) diff --git a/handbook/Use.txt b/handbook/Use.txt index 37f96fee60..3cc5d46e54 100644 --- a/handbook/Use.txt +++ b/handbook/Use.txt @@ -1,4 +1,4 @@ -2000000 - Red Potion - A potion made out of red herbs.\nRecovers 50 HP. +2000000 - Red Potion - A potion made out of red herbs.\nRecovers 50 HP. 2000001 - Orange Potion - A concentrated potion made out of red herbs.\nRecovers 150 HP. 2000002 - White Potion - A highly-concentrated potion made out of red herbs.\nRecovers 300 HP. 2000003 - Blue Potion - A potion made out of blue herbs.\nRecovers 100 MP. diff --git a/src/main/java/client/Stat.java b/src/main/java/client/Stat.java index 940d5b139b..cd0ee18e42 100644 --- a/src/main/java/client/Stat.java +++ b/src/main/java/client/Stat.java @@ -76,44 +76,10 @@ public enum Stat { } public static Stat getByString(String type) { - if (type.equals("SKIN")) { - return SKIN; - } else if (type.equals("FACE")) { - return FACE; - } else if (type.equals("HAIR")) { - return HAIR; - } else if (type.equals("LEVEL")) { - return LEVEL; - } else if (type.equals("JOB")) { - return JOB; - } else if (type.equals("STR")) { - return STR; - } else if (type.equals("DEX")) { - return DEX; - } else if (type.equals("INT")) { - return INT; - } else if (type.equals("LUK")) { - return LUK; - } else if (type.equals("HP")) { - return HP; - } else if (type.equals("MAXHP")) { - return MAXHP; - } else if (type.equals("MP")) { - return MP; - } else if (type.equals("MAXMP")) { - return MAXMP; - } else if (type.equals("AVAILABLEAP")) { - return AVAILABLEAP; - } else if (type.equals("AVAILABLESP")) { - return AVAILABLESP; - } else if (type.equals("EXP")) { - return EXP; - } else if (type.equals("FAME")) { - return FAME; - } else if (type.equals("MESO")) { - return MESO; - } else if (type.equals("PET")) { - return PET; + for (Stat stat : Stat.values()) { + if (stat.name().equals(type)) { + return stat; + } } return null; } diff --git a/src/main/java/provider/DataProviderFactory.java b/src/main/java/provider/DataProviderFactory.java index dc15004cb0..a90751a83d 100644 --- a/src/main/java/provider/DataProviderFactory.java +++ b/src/main/java/provider/DataProviderFactory.java @@ -25,9 +25,10 @@ import provider.wz.WZFiles; import provider.wz.XMLWZFile; import java.io.File; +import java.nio.file.Path; public class DataProviderFactory { - private static DataProvider getWZ(File in) { + private static DataProvider getWZ(Path in) { return new XMLWZFile(in); } diff --git a/src/main/java/provider/wz/WZFiles.java b/src/main/java/provider/wz/WZFiles.java index f563941118..3fe8dae892 100644 --- a/src/main/java/provider/wz/WZFiles.java +++ b/src/main/java/provider/wz/WZFiles.java @@ -1,6 +1,8 @@ package provider.wz; import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; public enum WZFiles { QUEST("Quest"), @@ -25,12 +27,12 @@ public enum WZFiles { this.fileName = name + ".wz"; } - public File getFile() { - return new File(DIRECTORY, fileName); + public Path getFile() { + return Paths.get(DIRECTORY).resolve(fileName); } public String getFilePath() { - return getFile().getPath(); + return getFile().toString(); } private static String getWzDirectory() { diff --git a/src/main/java/provider/wz/XMLDomMapleData.java b/src/main/java/provider/wz/XMLDomMapleData.java index 0962b2734b..4ea8461c37 100644 --- a/src/main/java/provider/wz/XMLDomMapleData.java +++ b/src/main/java/provider/wz/XMLDomMapleData.java @@ -37,15 +37,16 @@ import java.awt.*; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class XMLDomMapleData implements Data { private final Node node; - private File imageDataDir; + private Path imageDataDir; - public XMLDomMapleData(FileInputStream fis, File imageDataDir) { + public XMLDomMapleData(FileInputStream fis, Path imageDataDir) { try { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); @@ -91,7 +92,7 @@ public class XMLDomMapleData implements Data { } XMLDomMapleData ret = new XMLDomMapleData(myNode); - ret.imageDataDir = new File(imageDataDir, getName() + "/" + path).getParentFile(); + ret.imageDataDir = imageDataDir.resolve(getName().trim()).resolve(path).getParent(); return ret; } @@ -103,12 +104,12 @@ public class XMLDomMapleData implements Data { for (int i = 0; i < childNodes.getLength(); i++) { Node childNode = childNodes.item(i); if (childNode.getNodeType() == Node.ELEMENT_NODE) { - XMLDomMapleData child = new XMLDomMapleData(childNode); - child.imageDataDir = new File(imageDataDir, getName()); + XMLDomMapleData child = new XMLDomMapleData(childNode); + child.imageDataDir = imageDataDir.resolve(getName().trim()); ret.add(child); } } - + return ret; } @@ -193,7 +194,7 @@ public class XMLDomMapleData implements Data { return null; } XMLDomMapleData parentData = new XMLDomMapleData(parentNode); - parentData.imageDataDir = imageDataDir.getParentFile(); + parentData.imageDataDir = imageDataDir.getParent(); return parentData; } diff --git a/src/main/java/provider/wz/XMLWZFile.java b/src/main/java/provider/wz/XMLWZFile.java index 6b1f62b129..c9d95c8656 100644 --- a/src/main/java/provider/wz/XMLWZFile.java +++ b/src/main/java/provider/wz/XMLWZFile.java @@ -29,53 +29,59 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; public class XMLWZFile implements DataProvider { - private final File root; + private final Path root; private final WZDirectoryEntry rootForNavigation; - public XMLWZFile(File fileIn) { + public XMLWZFile(Path fileIn) { root = fileIn; - rootForNavigation = new WZDirectoryEntry(fileIn.getName(), 0, 0, null); + rootForNavigation = new WZDirectoryEntry(fileIn.getFileName().toString(), 0, 0, null); fillMapleDataEntitys(root, rootForNavigation); } - private void fillMapleDataEntitys(File lroot, WZDirectoryEntry wzdir) { - for (File file : lroot.listFiles()) { - String fileName = file.getName(); - if (file.isDirectory() && !fileName.endsWith(".img")) { - WZDirectoryEntry newDir = new WZDirectoryEntry(fileName, 0, 0, wzdir); - wzdir.addDirectory(newDir); - fillMapleDataEntitys(file, newDir); - } else if (fileName.endsWith(".xml")) { - wzdir.addFile(new WZFileEntry(fileName.substring(0, fileName.length() - 4), 0, 0, wzdir)); + private void fillMapleDataEntitys(Path lroot, WZDirectoryEntry wzdir) { + + try (DirectoryStream stream = Files.newDirectoryStream(lroot)) { + for (Path path : stream) { + String fileName = path.getFileName().toString(); + if(Files.isDirectory(path) && !fileName.endsWith(".img") ) { + WZDirectoryEntry newDir = new WZDirectoryEntry(fileName, 0, 0, wzdir); + wzdir.addDirectory(newDir); + fillMapleDataEntitys(path, newDir); + } else if (fileName.endsWith(".xml")) { + wzdir.addFile(new WZFileEntry(fileName.substring(0, fileName.length() - 4), 0, 0, wzdir)); + } } - } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } @Override public synchronized Data getData(String path) { - File dataFile = new File(root, path + ".xml"); - File imageDataDir = new File(root, path); - if (!dataFile.exists()) { + Path dataFile = root.resolve(path + ".xml"); + //File(root, path + ".xml"); + Path imageDataDir = root.resolve(path); + //File imageDataDir = new File(root, path); + if (!Files.exists(dataFile)) { return null;//bitches } - FileInputStream fis; - try { - fis = new FileInputStream(dataFile); - } catch (FileNotFoundException e) { - throw new RuntimeException("Datafile " + path + " does not exist in " + root.getAbsolutePath()); - } final XMLDomMapleData domMapleData; - try { - domMapleData = new XMLDomMapleData(fis, imageDataDir.getParentFile()); - } finally { - try { - fis.close(); - } catch (IOException e) { - throw new RuntimeException(e); - } + try(FileInputStream fis = new FileInputStream(dataFile.toString()) ) { + domMapleData = new XMLDomMapleData(fis, imageDataDir.getParent()); + }catch (FileNotFoundException e) { + throw new RuntimeException("Datafile " + path + " does not exist in " + root.toAbsolutePath()); + }catch (IOException e) { + throw new RuntimeException(e); } + + return domMapleData; } @@ -83,4 +89,4 @@ public class XMLWZFile implements DataProvider { public DataDirectoryEntry getRoot() { return rootForNavigation; } -} +} \ No newline at end of file diff --git a/src/main/java/tools/mapletools/ArrowFetcher.java b/src/main/java/tools/mapletools/ArrowFetcher.java index f2d4344e5f..996f8e3bd7 100644 --- a/src/main/java/tools/mapletools/ArrowFetcher.java +++ b/src/main/java/tools/mapletools/ArrowFetcher.java @@ -24,9 +24,12 @@ import tools.Pair; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.time.Duration; +import java.time.Instant; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -171,7 +174,7 @@ public class ArrowFetcher { if (!existingEntries.isEmpty()) { List entryValues = getArrowEntryValues(existingEntries); - printWriter = new PrintWriter(ToolConstants.getOutputFile(OUTPUT_FILE_NAME), StandardCharsets.UTF_8); + printWriter = new PrintWriter(Files.newOutputStream(ToolConstants.getOutputFile(OUTPUT_FILE_NAME))); printSqlHeader(); for (int[] arrowEntry : entryValues) { @@ -211,10 +214,15 @@ public class ArrowFetcher { } public static void main(String[] args) { + Instant instantStarted = Instant.now(); // load mob stats from WZ mobStats = MonsterStatFetcher.getAllMonsterStats(); calcAllMobsArrowRange(); updateMobsArrowRange(); + Instant instantStopped = Instant.now(); + Duration durationBetween = Duration.between(instantStarted, instantStopped); + System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis()); + System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); } } diff --git a/src/main/java/tools/mapletools/BossHpBarFetcher.java b/src/main/java/tools/mapletools/BossHpBarFetcher.java index a08d0cfdcb..51dca74fea 100644 --- a/src/main/java/tools/mapletools/BossHpBarFetcher.java +++ b/src/main/java/tools/mapletools/BossHpBarFetcher.java @@ -4,6 +4,11 @@ import provider.wz.WZFiles; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.time.Duration; +import java.time.Instant; import java.util.ArrayList; import java.util.List; @@ -129,21 +134,21 @@ public class BossHpBarFetcher { } private static void readBossHpBarData() throws IOException { - String line; + - final File mobDirectory = WZFiles.MOB.getFile(); - for (File file : mobDirectory.listFiles()) { - if (file.isFile()) { - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); - - while ((line = bufferedReader.readLine()) != null) { - translateToken(line); - } - - bufferedReader.close(); - fileReader.close(); - } + final Path mobDirectory = WZFiles.MOB.getFile(); + try (DirectoryStream stream = Files.newDirectoryStream(mobDirectory)) { + for (Path path : stream) { + if(Files.isRegularFile(path)) { + try(BufferedReader br = Files.newBufferedReader(path)) { + bufferedReader = br; + String line; + while ((line = bufferedReader.readLine()) != null) { + translateToken(line); + } + } + } + } } } @@ -162,17 +167,16 @@ public class BossHpBarFetcher { private static void reportBossHpBarData() { // This will reference one line at a time - try { + try(final PrintWriter printWriter = new PrintWriter(Files.newOutputStream(ToolConstants.getOutputFile(OUTPUT_FILE_NAME)))) { System.out.println("Reading WZs..."); readBossHpBarData(); System.out.println("Reporting results..."); - final PrintWriter printWriter = new PrintWriter(ToolConstants.getOutputFile(OUTPUT_FILE_NAME), StandardCharsets.UTF_8); + printReportFileHeader(printWriter); printReportFileResults(printWriter); - printWriter.close(); System.out.println("Done!"); } catch (FileNotFoundException ex) { System.out.println("Unable to open mob file."); @@ -184,7 +188,12 @@ public class BossHpBarFetcher { } public static void main(String[] args) { + Instant instantStarted = Instant.now(); reportBossHpBarData(); + Instant instantStopped = Instant.now(); + Duration durationBetween = Duration.between(instantStarted, instantStopped); + System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis()); + System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); } } diff --git a/src/main/java/tools/mapletools/CashCosmeticsChecker.java b/src/main/java/tools/mapletools/CashCosmeticsChecker.java index 696f3218b1..4ba2d5c3d6 100644 --- a/src/main/java/tools/mapletools/CashCosmeticsChecker.java +++ b/src/main/java/tools/mapletools/CashCosmeticsChecker.java @@ -5,6 +5,8 @@ import tools.Pair; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.*; /** @@ -21,8 +23,8 @@ import java.util.*; * Estimated parse time: 1 minute */ public class CashCosmeticsChecker { - private static final String INPUT_DIRECTORY_PATH = ToolConstants.getInputFile("care").getPath(); - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("cash_cosmetics_result.txt"); + private static final String INPUT_DIRECTORY_PATH = ToolConstants.getInputFile("care").toString(); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("cash_cosmetics_result.txt"); private static final boolean IGNORE_CURRENT_SCRIPT_COSMETICS = false; // Toggle to preference private static final int INITIAL_STRING_LENGTH = 50; @@ -613,51 +615,50 @@ public class CashCosmeticsChecker { private static void reportCosmeticResults() throws IOException { System.out.println("Reporting results ..."); - - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); - - printReportFileHeader(); - - if (!missingCosmeticsNpcTypes.isEmpty()) { - printWriter.println("Found " + missingCosmeticsNpcTypes.size() + " entries with missing cosmetic entries."); - - for (Pair, List> mcn : getSortedMapEntries(missingCosmeticsNpcTypes)) { - printWriter.println(" NPC " + mcn.getLeft()); - - Pair, List> genderItemids = getCosmeticReport(mcn.getRight()); - reportNpcCosmetics(genderItemids.getLeft()); - reportNpcCosmetics(genderItemids.getRight()); - printWriter.println(); - } + + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE));) { + printWriter = pw; + printReportFileHeader(); + + if (!missingCosmeticsNpcTypes.isEmpty()) { + printWriter.println("Found " + missingCosmeticsNpcTypes.size() + " entries with missing cosmetic entries."); + + for (Pair, List> mcn : getSortedMapEntries(missingCosmeticsNpcTypes)) { + printWriter.println(" NPC " + mcn.getLeft()); + + Pair, List> genderItemids = getCosmeticReport(mcn.getRight()); + reportNpcCosmetics(genderItemids.getLeft()); + reportNpcCosmetics(genderItemids.getRight()); + printWriter.println(); + } + } + + if (!unusedCosmetics.isEmpty()) { + printWriter.println("Unused cosmetics: " + unusedCosmetics.size()); + + List list = new ArrayList<>(unusedCosmetics); + Collections.sort(list); + + for (Integer i : list) { + printWriter.println(i + " " + cosmeticIdNames.get(i)); + } + + printWriter.println(); + } + + if (!missingCosmeticNames.isEmpty()) { + printWriter.println("Missing cosmetic itemids: " + missingCosmeticNames.size()); + + List listString = new ArrayList<>(missingCosmeticNames); + Collections.sort(listString); + + for (String c : listString) { + printWriter.println(c); + } + + printWriter.println(); + } } - - if (!unusedCosmetics.isEmpty()) { - printWriter.println("Unused cosmetics: " + unusedCosmetics.size()); - - List list = new ArrayList<>(unusedCosmetics); - Collections.sort(list); - - for (Integer i : list) { - printWriter.println(i + " " + cosmeticIdNames.get(i)); - } - - printWriter.println(); - } - - if (!missingCosmeticNames.isEmpty()) { - printWriter.println("Missing cosmetic itemids: " + missingCosmeticNames.size()); - - List listString = new ArrayList<>(missingCosmeticNames); - Collections.sort(listString); - - for (String c : listString) { - printWriter.println(c); - } - - printWriter.println(); - } - - printWriter.close(); } public static void main(String[] args) { diff --git a/src/main/java/tools/mapletools/CashDropFetcher.java b/src/main/java/tools/mapletools/CashDropFetcher.java index 75176c4a81..04504085f7 100644 --- a/src/main/java/tools/mapletools/CashDropFetcher.java +++ b/src/main/java/tools/mapletools/CashDropFetcher.java @@ -5,6 +5,8 @@ import tools.Pair; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -20,7 +22,7 @@ import java.util.*; * Estimated parse time: 2 minutes */ public class CashDropFetcher { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("cash_drop_report.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("cash_drop_report.txt"); private static final Connection con = SimpleDatabaseConnection.getConnection(); private static final int INITIAL_STRING_LENGTH = 50; private static final int ITEM_FILE_NAME_SIZE = 13; @@ -260,7 +262,8 @@ public class CashDropFetcher { } private static void reportNxDropData() { - try { + //NEED FUTURE UPDATE + try { System.out.println("Reading Character.wz ..."); ArrayList files = new ArrayList<>(); listFiles(WZFiles.CHARACTER.getFilePath(), files); @@ -311,7 +314,7 @@ public class CashDropFetcher { System.out.println("Reporting results..."); // report suspects of missing quest drop data, as well as those drop data that may have incorrect questids. - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); + printWriter = new PrintWriter(Files.newOutputStream(OUTPUT_FILE)); printReportFileHeader(); reportNxDropResults(true); diff --git a/src/main/java/tools/mapletools/CashVegaChecker.java b/src/main/java/tools/mapletools/CashVegaChecker.java index 230c0814d7..2c375723ba 100644 --- a/src/main/java/tools/mapletools/CashVegaChecker.java +++ b/src/main/java/tools/mapletools/CashVegaChecker.java @@ -4,6 +4,8 @@ import provider.wz.WZFiles; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.HashSet; import java.util.Set; @@ -16,7 +18,7 @@ import java.util.Set; * Estimated parse time: 10 seconds */ public class CashVegaChecker { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("vega_checker_report.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("vega_checker_report.txt"); private static final int INITIAL_STRING_LENGTH = 1000; private static final Set vegaItems = new HashSet<>(); @@ -154,11 +156,11 @@ public class CashVegaChecker { } private static void reportMissingVegaItems() { - System.out.println("Reporting results ..."); + //NEED FUTURE UPDATE + System.out.println("Reporting results ..."); try { - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); - + printWriter = new PrintWriter(Files.newOutputStream(OUTPUT_FILE)); printReportFileHeader(); for (Integer itemid : vegaItems) { diff --git a/src/main/java/tools/mapletools/CodeCouponGenerator.java b/src/main/java/tools/mapletools/CodeCouponGenerator.java index ddf9b94805..3231172524 100644 --- a/src/main/java/tools/mapletools/CodeCouponGenerator.java +++ b/src/main/java/tools/mapletools/CodeCouponGenerator.java @@ -4,6 +4,8 @@ import tools.Pair; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.*; import java.util.ArrayList; import java.util.HashSet; @@ -22,7 +24,7 @@ import static java.util.concurrent.TimeUnit.HOURS; * Estimated parse time: 2 minutes (for 100 code entries) */ public class CodeCouponGenerator { - private static final File INPUT_FILE = ToolConstants.getInputFile("CouponCodes.img.xml"); + private static final Path INPUT_FILE = ToolConstants.getInputFile("CouponCodes.img.xml"); private static final int INITIAL_STRING_LENGTH = 250; private static final Connection con = SimpleDatabaseConnection.getConnection(); @@ -312,24 +314,19 @@ public class CodeCouponGenerator { ps.close(); } - private static void generateCodeCoupons(File file) throws IOException { - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); + private static void generateCodeCoupons(Path file) throws IOException { + try(BufferedReader br = Files.newBufferedReader(file); con;) { + bufferedReader = br; + resetCouponPackage(); + status = 0; - resetCouponPackage(); - status = 0; + System.out.println("Reading XML coupon information..."); + String line; + while ((line = bufferedReader.readLine()) != null) { + translateToken(line); + } + System.out.println(); - System.out.println("Reading XML coupon information..."); - String line; - while ((line = bufferedReader.readLine()) != null) { - translateToken(line); - } - - bufferedReader.close(); - fileReader.close(); - System.out.println(); - - try { System.out.println("Loading DB coupon codes..."); loadUsedCouponCodes(); System.out.println(); @@ -340,10 +337,9 @@ public class CodeCouponGenerator { commitCodeCouponDescription(ccd); } System.out.println(); - - con.close(); System.out.println("Done."); - } catch (SQLException e) { + + } catch (SQLException e) { e.printStackTrace(); } } @@ -352,7 +348,7 @@ public class CodeCouponGenerator { try { generateCodeCoupons(INPUT_FILE); } catch (IOException ex) { - System.out.println("Error reading file '" + INPUT_FILE.getAbsolutePath() + "'"); + System.out.println("Error reading file '" + INPUT_FILE.toAbsolutePath() + "'"); } } } diff --git a/src/main/java/tools/mapletools/DojoUpdate.java b/src/main/java/tools/mapletools/DojoUpdate.java index dbacb0ac18..9ad06668fa 100644 --- a/src/main/java/tools/mapletools/DojoUpdate.java +++ b/src/main/java/tools/mapletools/DojoUpdate.java @@ -4,6 +4,12 @@ import provider.wz.WZFiles; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.time.Duration; +import java.time.Instant; /** * @author RonanLana @@ -16,8 +22,10 @@ import java.nio.charset.StandardCharsets; * Estimated parse time: 10 seconds */ public class DojoUpdate { - private static final File INPUT_DIRECTORY = new File(WZFiles.MAP.getFile(), "/Map/Map9"); - private static final File OUTPUT_DIRECTORY = ToolConstants.getOutputFile("dojo-maps"); + //private static final Path INPUT_DIRECTORY = WZFiles.MAP.getFile().resolve("/Map/Map9"); + private static final Path INPUT_DIRECTORY = WZFiles.MAP.getFile().resolve("Map").resolve("Map9"); + private static final Path OUTPUT_DIRECTORY = ToolConstants.getOutputFile("dojo-maps"); + private static final Path WORKING_DIRECTORY = Paths.get("").toAbsolutePath(); private static final int DOJO_MIN_MAP_ID = 925_020_100; private static final int DOJO_MAX_MAP_ID = 925_033_804; private static final int INITIAL_STRING_LENGTH = 250; @@ -114,30 +122,25 @@ public class DojoUpdate { return Integer.parseInt(fileName.substring(0, 9)); } - private static void parseDojoData(File file, String curPath) throws IOException { - int mapId = getMapId(file.getName()); + private static void parseDojoData(Path file, String curPath) throws IOException { + int mapId = getMapId(file.getFileName().toString()); isDojoMapid = isDojoMapId(mapId); if (!isDojoMapid) { return; } + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_DIRECTORY.resolve(curPath).resolve(file.getFileName()))); + BufferedReader br = Files.newBufferedReader(file);) { + printWriter = pw; + bufferedReader = br; + status = 0; - printWriter = new PrintWriter(OUTPUT_DIRECTORY.getPath() + "/" + curPath + file.getName(), StandardCharsets.UTF_8); - - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); - - status = 0; - - String line; - while ((line = bufferedReader.readLine()) != null) { - translateToken(line); + String line; + while ((line = bufferedReader.readLine()) != null) { + translateToken(line); + } + + printFileFooter(); } - - bufferedReader.close(); - fileReader.close(); - - printFileFooter(); - printWriter.close(); } private static boolean isDojoMapId(int mapId) { @@ -152,31 +155,49 @@ public class DojoUpdate { } private static void parseDirectoryDojoData(String curPath) { - File folder = new File(OUTPUT_DIRECTORY, curPath); - if (!folder.exists()) { - folder.mkdir(); + Path folder = OUTPUT_DIRECTORY.resolve(curPath); + if (!Files.exists(folder)) { + try { + Files.createDirectory(folder); + } catch (IOException e) { + // TODO Auto-generated catch block + System.out.println("Unable to create folder " + folder.toAbsolutePath() + "."); + e.printStackTrace(); + } } System.out.println("Parsing directory '" + curPath + "'"); - folder = new File(INPUT_DIRECTORY, curPath); - for (File file : folder.listFiles()) { - if (file.isFile()) { - try { - parseDojoData(file, curPath); - } catch (FileNotFoundException ex) { - System.out.println("Unable to open dojo file " + file.getAbsolutePath() + "."); - } catch (IOException ex) { - System.out.println("Error reading dojo file " + file.getAbsolutePath() + "."); - } catch (Exception e) { - e.printStackTrace(); - } - } else { - parseDirectoryDojoData(curPath + file.getName() + "/"); - } - } + folder = INPUT_DIRECTORY.resolve(curPath); + try (DirectoryStream stream = Files.newDirectoryStream(folder)) { + for (Path path : stream) { + if(Files.isRegularFile(path)) { + try { + parseDojoData(path, curPath); + } catch (FileNotFoundException ex) { + System.out.println("Unable to open dojo file " + path.toAbsolutePath() + "."); + } catch (IOException ex) { + System.out.println("Error reading dojo file " + path.toAbsolutePath() + "."); + } catch (Exception e) { + e.printStackTrace(); + } + } else { + parseDirectoryDojoData(curPath + path.getFileName() + "/"); + } + } + } catch (IOException e1) { + System.out.println("Unable to read folder " + folder.toAbsolutePath() + "."); + // TODO Auto-generated catch block + e1.printStackTrace(); + } } public static void main(String[] args) { + Instant instantStarted = Instant.now(); parseDirectoryDojoData(""); + Instant instantStopped = Instant.now(); + Duration durationBetween = Duration.between(instantStarted, instantStopped); + System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis()); + System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); + } } diff --git a/src/main/java/tools/mapletools/EmptyItemWzChecker.java b/src/main/java/tools/mapletools/EmptyItemWzChecker.java index f696d319a1..3ac5c7ddf0 100644 --- a/src/main/java/tools/mapletools/EmptyItemWzChecker.java +++ b/src/main/java/tools/mapletools/EmptyItemWzChecker.java @@ -4,6 +4,8 @@ import provider.wz.WZFiles; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.*; /** @@ -14,8 +16,8 @@ import java.util.*; * And it removes from the String.wz XMLs all entries which misses properties on Item.wz. */ public class EmptyItemWzChecker { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("empty_item_wz_report.txt"); - private static final String OUTPUT_PATH = ToolConstants.OUTPUT_DIRECTORY.getPath(); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("empty_item_wz_report.txt"); + private static final String OUTPUT_PATH = ToolConstants.OUTPUT_DIRECTORY.toString(); private static final int INITIAL_STRING_LENGTH = 50; private static final int ITEM_FILE_NAME_SIZE = 13; @@ -338,12 +340,11 @@ public class EmptyItemWzChecker { private static void reportItemNameDiff(Set emptyItemNames, Set emptyNameItems) throws IOException { System.out.println("Reporting results..."); - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); - - printReportFileHeader(); - printReportFileResults(emptyItemNames, emptyNameItems); - - printWriter.close(); + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + printWriter = pw; + printReportFileHeader(); + printReportFileResults(emptyItemNames, emptyNameItems); + } } private static void locateItemStringWzDiff() throws IOException { diff --git a/src/main/java/tools/mapletools/EquipmentOmniLeveller.java b/src/main/java/tools/mapletools/EquipmentOmniLeveller.java index b10caeb260..6047cdf981 100644 --- a/src/main/java/tools/mapletools/EquipmentOmniLeveller.java +++ b/src/main/java/tools/mapletools/EquipmentOmniLeveller.java @@ -4,6 +4,11 @@ import provider.wz.WZFiles; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.time.Duration; +import java.time.Instant; /** * @author RonanLana @@ -16,14 +21,13 @@ import java.nio.charset.StandardCharsets; * Estimated parse time: 7 minutes */ public class EquipmentOmniLeveller { - private static final File INPUT_DIRECTORY = WZFiles.CHARACTER.getFile(); - private static final File OUTPUT_DIRECTORY = ToolConstants.getOutputFile("equips-with-levels"); + private static final Path INPUT_DIRECTORY = WZFiles.CHARACTER.getFile(); + private static final Path OUTPUT_DIRECTORY = ToolConstants.getOutputFile("equips-with-levels"); private static final int INITIAL_STRING_LENGTH = 250; private static final int FIXED_EXP = 10000; private static final int MAX_EQP_LEVEL = 30; private static PrintWriter printWriter = null; - private static InputStreamReader fileReader = null; private static BufferedReader bufferedReader = null; private static int infoTagState = -1; @@ -353,31 +357,25 @@ public class EquipmentOmniLeveller { return accessInfoTag; } - private static void copyCashItemData(File file, String curPath) throws IOException { - printWriter = new PrintWriter(new File(OUTPUT_DIRECTORY, curPath + file.getName()), StandardCharsets.UTF_8); - - fileReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); - - String line; - while ((line = bufferedReader.readLine()) != null) { - printWriter.println(line); - } - - bufferedReader.close(); - fileReader.close(); - - printWriter.close(); + private static void copyCashItemData(Path file, String curPath) throws IOException { + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_DIRECTORY.resolve(curPath).resolve(file.getFileName()))); + BufferedReader br = Files.newBufferedReader(file);) { + printWriter = pw; + bufferedReader = br; + String line; + while ((line = bufferedReader.readLine()) != null) { + printWriter.println(line); + } + } } - private static void parseEquipData(File file, String curPath) throws IOException { - printWriter = new PrintWriter(new File(OUTPUT_DIRECTORY, curPath + file.getName()), StandardCharsets.UTF_8); - - fileReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); - - try { - status = 0; + private static void parseEquipData(Path file, String curPath) throws IOException { + + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_DIRECTORY.resolve(curPath).resolve(file.getFileName()))); + BufferedReader br = Files.newBufferedReader(file);) { + printWriter = pw; + bufferedReader = br; + status = 0; upgradeable = false; cash = false; @@ -389,20 +387,12 @@ public class EquipmentOmniLeveller { infoTagState = -1; } } - - bufferedReader.close(); - fileReader.close(); - printFileFooter(); - printWriter.close(); - } catch (RuntimeException e) { - bufferedReader.close(); - fileReader.close(); - - printWriter.close(); - + } catch (RuntimeException e) { copyCashItemData(file, curPath); } + + } private static void printFileFooter() { @@ -413,31 +403,48 @@ public class EquipmentOmniLeveller { } private static void parseDirectoryEquipData(String curPath) { - File folder = new File(OUTPUT_DIRECTORY, curPath); - if (!folder.exists()) { - folder.mkdir(); + Path folder = OUTPUT_DIRECTORY.resolve(curPath); + if (!Files.exists(folder)) { + try { + Files.createDirectory(folder); + } catch (IOException e) { + // TODO Auto-generated catch block + System.out.println("Unable to create folder " + folder.toAbsolutePath() + "."); + e.printStackTrace(); + } } System.out.println("Parsing directory '" + curPath + "'"); - folder = new File(INPUT_DIRECTORY, curPath); - for (File file : folder.listFiles()) { - if (file.isFile()) { - try { - parseEquipData(file, curPath); - } catch (FileNotFoundException ex) { - System.out.println("Unable to open equip file " + file.getAbsolutePath() + "."); - } catch (IOException ex) { - System.out.println("Error reading equip file " + file.getAbsolutePath() + "."); - } catch (Exception e) { - e.printStackTrace(); - } - } else { - parseDirectoryEquipData(curPath + file.getName() + "/"); - } - } + folder = INPUT_DIRECTORY.resolve(curPath); + try (DirectoryStream stream = Files.newDirectoryStream(folder)) { + for (Path path : stream) { + if(Files.isRegularFile(path)) { + try { + parseEquipData(path, curPath); + } catch (FileNotFoundException ex) { + System.out.println("Unable to open dojo file " + path.toAbsolutePath() + "."); + } catch (IOException ex) { + System.out.println("Error reading dojo file " + path.toAbsolutePath() + "."); + } catch (Exception e) { + e.printStackTrace(); + } + } else { + parseDirectoryEquipData(curPath + path.getFileName() + "/"); + } + } + } catch (IOException e1) { + System.out.println("Unable to read folder " + folder.toAbsolutePath() + "."); + // TODO Auto-generated catch block + e1.printStackTrace(); + } } public static void main(String[] args) { + Instant instantStarted = Instant.now(); parseDirectoryEquipData(""); + Instant instantStopped = Instant.now(); + Duration durationBetween = Duration.between(instantStarted, instantStopped); + System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis()); + System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); } } diff --git a/src/main/java/tools/mapletools/GachaponItemIdRetriever.java b/src/main/java/tools/mapletools/GachaponItemIdRetriever.java index 0761d804a1..efffff4e74 100644 --- a/src/main/java/tools/mapletools/GachaponItemIdRetriever.java +++ b/src/main/java/tools/mapletools/GachaponItemIdRetriever.java @@ -2,6 +2,8 @@ package tools.mapletools; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -22,8 +24,8 @@ import java.util.regex.Pattern; * Estimated parse time: 1 minute */ public class GachaponItemIdRetriever { - private static final File INPUT_FILE = ToolConstants.getInputFile("gachapon_items.txt"); - private static final File OUTPUT_DIRECTORY = ToolConstants.getOutputFile("gachapons"); + private static final Path INPUT_FILE = ToolConstants.getInputFile("gachapon_items.txt"); + private static final Path OUTPUT_DIRECTORY = ToolConstants.getOutputFile("gachapons"); private static final Connection con = SimpleDatabaseConnection.getConnection(); private static final Pattern pattern = Pattern.compile("(\\d*)%"); private static final int[] scrollsChances = new int[]{10, 15, 30, 60, 65, 70, 100}; @@ -247,12 +249,8 @@ public class GachaponItemIdRetriever { private static void fetchDataOnMapleHandbook() throws SQLException { String line; - - try { - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(INPUT_FILE), StandardCharsets.UTF_8); - BufferedReader bufferedReader = new BufferedReader(fileReader); - - int skip = 0; + try(BufferedReader bufferedReader = Files.newBufferedReader(INPUT_FILE)) { + int skip = 0; boolean lineHeader = false; while ((line = bufferedReader.readLine()) != null) { if (skip > 0) { @@ -276,10 +274,10 @@ public class GachaponItemIdRetriever { if (printWriter != null) { printWriter.close(); } - File outputFile = new File(OUTPUT_DIRECTORY, gachaponName + ".txt"); + Path outputFile = OUTPUT_DIRECTORY.resolve(gachaponName + ".txt"); setupDirectories(outputFile); - printWriter = new PrintWriter(outputFile, StandardCharsets.UTF_8); + printWriter = new PrintWriter(Files.newOutputStream(outputFile)); skip = 2; lineHeader = true; @@ -297,30 +295,30 @@ public class GachaponItemIdRetriever { } } } - - if (printWriter != null) { - printWriter.close(); - } - bufferedReader.close(); - fileReader.close(); } catch (IOException ex) { System.out.println(ex.getMessage()); ex.printStackTrace(); } + + + } - private static void setupDirectories(File file) { - if (!file.getParentFile().exists()) { - file.getParentFile().mkdirs(); - } + private static void setupDirectories(Path file) { + if(!Files.exists(file.getParent())) { + try { + Files.createDirectories(file.getParent()); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } public static void main(String[] args) { - try { - loadHandbookUseNames(); + try(con) { + loadHandbookUseNames(); fetchDataOnMapleHandbook(); - - con.close(); } catch (SQLException e) { System.out.println("Error: invalid SQL syntax"); System.out.println(e.getMessage()); diff --git a/src/main/java/tools/mapletools/IdRetriever.java b/src/main/java/tools/mapletools/IdRetriever.java index 58039bc0dc..a41806e70b 100644 --- a/src/main/java/tools/mapletools/IdRetriever.java +++ b/src/main/java/tools/mapletools/IdRetriever.java @@ -2,10 +2,14 @@ package tools.mapletools; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.time.Duration; +import java.time.Instant; import java.util.ArrayList; /** @@ -26,8 +30,8 @@ import java.util.ArrayList; */ public class IdRetriever { private static final boolean INSTALL_SQLTABLE = true; - private static final File INPUT_FILE = ToolConstants.getInputFile("fetch_ids.txt"); - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("fetched_ids.txt"); + private static final Path INPUT_FILE = ToolConstants.getInputFile("fetch_ids.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("fetched_ids.txt"); private static final Connection con = SimpleDatabaseConnection.getConnection(); private static InputStreamReader fileReader = null; @@ -132,15 +136,11 @@ public class IdRetriever { } private static void fetchDataOnMapleHandbook() throws SQLException { - String line; - - try { - fileReader = new InputStreamReader(new FileInputStream(INPUT_FILE), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); - - PrintWriter printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); - - while ((line = bufferedReader.readLine()) != null) { + try(BufferedReader br = Files.newBufferedReader(INPUT_FILE); + PrintWriter printWriter = new PrintWriter(Files.newOutputStream(OUTPUT_FILE));) { + bufferedReader = br; + String line; + while ((line = bufferedReader.readLine()) != null) { if (line.isEmpty()) { printWriter.println(""); continue; @@ -164,17 +164,13 @@ public class IdRetriever { printWriter.println(str); } - - printWriter.close(); - bufferedReader.close(); - fileReader.close(); - } catch (IOException ex) { + } catch (IOException ex) { System.out.println(ex.getMessage()); } } public static void main(String[] args) { - + Instant instantStarted = Instant.now(); try { if (INSTALL_SQLTABLE) { parseMapleHandbook(); @@ -187,6 +183,10 @@ public class IdRetriever { System.out.println("Error: invalid SQL syntax"); e.printStackTrace(); } + Instant instantStopped = Instant.now(); + Duration durationBetween = Duration.between(instantStarted, instantStopped); + System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis()); + System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); } } diff --git a/src/main/java/tools/mapletools/MapInfoRetriever.java b/src/main/java/tools/mapletools/MapInfoRetriever.java index 6c35a62a06..ade7693d24 100644 --- a/src/main/java/tools/mapletools/MapInfoRetriever.java +++ b/src/main/java/tools/mapletools/MapInfoRetriever.java @@ -5,6 +5,8 @@ import provider.wz.WZFiles; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -16,7 +18,7 @@ import java.util.List; * the "info" node in their WZ node tree. */ public class MapInfoRetriever { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("map_info_report.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("map_info_report.txt"); private static final List missingInfo = new ArrayList<>(); private static BufferedReader bufferedReader = null; @@ -129,18 +131,14 @@ public class MapInfoRetriever { } private static void writeReport() { - try { - PrintWriter printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); - - if (!missingInfo.isEmpty()) { + try(PrintWriter printWriter = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + if (!missingInfo.isEmpty()) { for (Integer i : missingInfo) { printWriter.println(i); } } else { printWriter.println("All map files contain 'info' node."); } - - printWriter.close(); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/tools/mapletools/MesoFetcher.java b/src/main/java/tools/mapletools/MesoFetcher.java index 7f777664c9..c843c4e7f8 100644 --- a/src/main/java/tools/mapletools/MesoFetcher.java +++ b/src/main/java/tools/mapletools/MesoFetcher.java @@ -6,9 +6,13 @@ import tools.Pair; import java.io.File; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.time.Duration; +import java.time.Instant; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -27,7 +31,7 @@ import java.util.Map; */ public class MesoFetcher { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("meso_drop_data.sql"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("meso_drop_data.sql"); private static final boolean PERMIT_MESOS_ON_DOJO_BOSSES = false; private static final int MESO_ID = 0; private static final int MIN_ITEMS = 4; @@ -119,14 +123,12 @@ public class MesoFetcher { private static void generateMissingMobsMesoRange() { System.out.print("Generating missing ranges... "); - Connection con = SimpleDatabaseConnection.getConnection(); - List existingMobs = new ArrayList<>(200); - - try { - // select all mobs which doesn't drop mesos and have a fair amount of items dropping (meaning they are not an event mob) - PreparedStatement ps = con.prepareStatement("SELECT dropperid FROM drop_data WHERE dropperid NOT IN (SELECT DISTINCT dropperid FROM drop_data WHERE itemid = 0) GROUP BY dropperid HAVING count(*) >= " + MIN_ITEMS + ";"); - ResultSet rs = ps.executeQuery(); - + try(Connection con = SimpleDatabaseConnection.getConnection(); + PreparedStatement ps = con.prepareStatement("SELECT dropperid FROM drop_data WHERE dropperid NOT IN (SELECT DISTINCT dropperid FROM drop_data WHERE itemid = 0) GROUP BY dropperid HAVING count(*) >= " + MIN_ITEMS + ";"); + ResultSet rs = ps.executeQuery();) { + + List existingMobs = new ArrayList<>(200); + if (rs.isBeforeFirst()) { while (rs.next()) { int mobid = rs.getInt(1); @@ -137,18 +139,19 @@ public class MesoFetcher { } if (!existingMobs.isEmpty()) { - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); - printSqlHeader(); + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + printWriter = pw; + + printSqlHeader(); - for (int i = 0; i < existingMobs.size() - 1; i++) { - printSqlMobMesoRange(existingMobs.get(i)); + for (int i = 0; i < existingMobs.size() - 1; i++) { + printSqlMobMesoRange(existingMobs.get(i)); + } + + printSqlMobMesoRangeFinal(existingMobs.get(existingMobs.size() - 1)); + + printSqlExceptions(); } - - printSqlMobMesoRangeFinal(existingMobs.get(existingMobs.size() - 1)); - - printSqlExceptions(); - - printWriter.close(); } else { throw new Exception("ALREADY UPDATED"); } @@ -156,13 +159,9 @@ public class MesoFetcher { } else { throw new Exception("ALREADY UPDATED"); } - - rs.close(); - ps.close(); - con.close(); - + System.out.println("done!"); - + } catch (Exception e) { if (e.getMessage() != null && e.getMessage().equals("ALREADY UPDATED")) { System.out.println("done! The DB is already up-to-date, no file generated."); @@ -170,14 +169,21 @@ public class MesoFetcher { e.printStackTrace(); } } + } public static void main(String[] args) { - // load mob stats from WZ + Instant instantStarted = Instant.now(); + // load mob stats from WZ mobStats = MonsterStatFetcher.getAllMonsterStats(); calcAllMobsMesoRange(); generateMissingMobsMesoRange(); + Instant instantStopped = Instant.now(); + Duration durationBetween = Duration.between(instantStarted, instantStopped); + System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis()); + System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); + } } diff --git a/src/main/java/tools/mapletools/MobBookIndexer.java b/src/main/java/tools/mapletools/MobBookIndexer.java index 403b470430..3dbb168588 100644 --- a/src/main/java/tools/mapletools/MobBookIndexer.java +++ b/src/main/java/tools/mapletools/MobBookIndexer.java @@ -4,6 +4,8 @@ import provider.wz.WZFiles; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -16,7 +18,7 @@ import java.sql.SQLException; * puts them on a SQL table with the correspondent mob cardid. */ public class MobBookIndexer { - private static final File INPUT_FILE = new File(WZFiles.STRING.getFile(), "MonsterBook.img.xml"); + private static final Path INPUT_FILE = WZFiles.STRING.getFile().resolve("MonsterBook.img.xml"); private static final Connection con = SimpleDatabaseConnection.getConnection(); private static BufferedReader bufferedReader = null; @@ -123,14 +125,13 @@ public class MobBookIndexer { } private static void indexFromDropData() { - // This will reference one line at a time - String line = null; - - try { - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(INPUT_FILE), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); - - PreparedStatement ps = con.prepareStatement("DROP TABLE IF EXISTS monstercardwz;"); + + try(con; + BufferedReader br = Files.newBufferedReader(INPUT_FILE);) { + bufferedReader = br; + String line = null; + + PreparedStatement ps = con.prepareStatement("DROP TABLE IF EXISTS monstercardwz;"); ps.execute(); ps = con.prepareStatement("CREATE TABLE `monstercardwz` (" @@ -144,12 +145,7 @@ public class MobBookIndexer { while ((line = bufferedReader.readLine()) != null) { translateToken(line); } - - bufferedReader.close(); - fileReader.close(); - - con.close(); - } catch (FileNotFoundException ex) { + } catch (FileNotFoundException ex) { System.out.println("Unable to open file '" + INPUT_FILE + "'"); } catch (IOException ex) { System.out.println("Error reading file '" + INPUT_FILE + "'"); diff --git a/src/main/java/tools/mapletools/MobBookUpdate.java b/src/main/java/tools/mapletools/MobBookUpdate.java index fe5e28743b..efe91373f3 100644 --- a/src/main/java/tools/mapletools/MobBookUpdate.java +++ b/src/main/java/tools/mapletools/MobBookUpdate.java @@ -4,6 +4,8 @@ import provider.wz.WZFiles; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -26,8 +28,8 @@ import java.sql.SQLException; * remove the property 'MonsterBook.img' inside 'string.wz' and choose to import the xml generated with this software. */ public class MobBookUpdate { - private static final File INPUT_FILE = new File(WZFiles.STRING.getFile(), "MonsterBook.img.xml"); - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("MonsterBook_updated.img.xml"); + private static final Path INPUT_FILE = WZFiles.STRING.getFile().resolve("MonsterBook.img.xml"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("MonsterBook_updated.img.xml"); private static final Connection con = SimpleDatabaseConnection.getConnection(); private static PrintWriter printWriter = null; @@ -143,23 +145,17 @@ public class MobBookUpdate { } private static void updateFromDropData() { - // This will reference one line at a time - String line = null; - - try { - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(INPUT_FILE), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); - - while ((line = bufferedReader.readLine()) != null) { + try(con; + PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE)); + BufferedReader br = Files.newBufferedReader(INPUT_FILE);) { + printWriter = pw; + bufferedReader = br; + + String line = null; + + while ((line = bufferedReader.readLine()) != null) { translateToken(line); } - - printWriter.close(); - bufferedReader.close(); - fileReader.close(); - - con.close(); } catch (FileNotFoundException ex) { System.out.println("Unable to open file '" + INPUT_FILE + "'"); } catch (IOException ex) { @@ -170,6 +166,7 @@ public class MobBookUpdate { } catch (Exception e) { e.printStackTrace(); } + } public static void main(String[] args) { diff --git a/src/main/java/tools/mapletools/MonsterStatFetcher.java b/src/main/java/tools/mapletools/MonsterStatFetcher.java index e28d6506d0..db855bfff8 100644 --- a/src/main/java/tools/mapletools/MonsterStatFetcher.java +++ b/src/main/java/tools/mapletools/MonsterStatFetcher.java @@ -11,6 +11,8 @@ import server.life.LifeFactory.selfDestruction; import server.life.MonsterStats; import tools.Pair; +import java.time.Duration; +import java.time.Instant; import java.util.*; public class MonsterStatFetcher { @@ -140,4 +142,15 @@ public class MonsterStatFetcher { } } + public static void main(String[] args) { + Instant instantStarted = Instant.now(); + // load mob stats from WZ + Map mobStats = MonsterStatFetcher.getAllMonsterStats(); + Instant instantStopped = Instant.now(); + Duration durationBetween = Duration.between(instantStarted, instantStopped); + System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis()); + System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); + + } + } diff --git a/src/main/java/tools/mapletools/NoItemIdFetcher.java b/src/main/java/tools/mapletools/NoItemIdFetcher.java index 602d5420c2..d055bb2816 100644 --- a/src/main/java/tools/mapletools/NoItemIdFetcher.java +++ b/src/main/java/tools/mapletools/NoItemIdFetcher.java @@ -4,6 +4,8 @@ import provider.wz.WZFiles; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -20,7 +22,7 @@ import java.util.*; * A file is generated listing all the inexistent ids. */ public class NoItemIdFetcher { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("no_item_id_report.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("no_item_id_report.txt"); private static final Connection con = SimpleDatabaseConnection.getConnection(); private static final Set existingIds = new HashSet<>(); @@ -199,16 +201,13 @@ public class NoItemIdFetcher { } public static void main(String[] args) { - try { - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); - - existingIds.add(0); // meso itemid + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + printWriter = pw; + existingIds.add(0); // meso itemid readEquipDataDirectory(WZFiles.CHARACTER.getFilePath()); readItemDataDirectory(WZFiles.ITEM.getFilePath()); evaluateDropsFromDb(); - - printWriter.close(); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/tools/mapletools/NoItemNameFetcher.java b/src/main/java/tools/mapletools/NoItemNameFetcher.java index 3e7e3989cb..161fccfd7e 100644 --- a/src/main/java/tools/mapletools/NoItemNameFetcher.java +++ b/src/main/java/tools/mapletools/NoItemNameFetcher.java @@ -6,6 +6,8 @@ import provider.wz.WZFiles; import java.io.File; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.*; /** @@ -19,8 +21,8 @@ import java.util.*; * Estimated parse time: 2 minutes */ public class NoItemNameFetcher { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("no_item_name_result.txt"); - private static final File OUTPUT_XML_FILE = ToolConstants.getOutputFile("no_item_name_xml.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("no_item_name_result.txt"); + private static final Path OUTPUT_XML_FILE = ToolConstants.getOutputFile("no_item_name_xml.txt"); private static final Map itemsWzPath = new HashMap<>(); private static final Map equipTypes = new HashMap<>(); @@ -435,20 +437,22 @@ public class NoItemNameFetcher { private static void writeMissingStringWZNames(Map> missingNames) throws Exception { System.out.println("Writing remaining 'String.wz' names..."); + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_XML_FILE))) { + printWriter = pw; + + printOutputFileHeader(); - printWriter = new PrintWriter(OUTPUT_XML_FILE, StandardCharsets.UTF_8); - printOutputFileHeader(); + String[] nodePaths = {"Cash.img", "Consume.img", "Eqp.img", "Etc.img", "Ins.img", "Pet.img"}; + for (int i = 0; i < nodePaths.length; i++) { + writeMissingStringWZNode(nodePaths[i], missingNames.get(nodePaths[i]), i == 2); + } - String[] nodePaths = {"Cash.img", "Consume.img", "Eqp.img", "Etc.img", "Ins.img", "Pet.img"}; - for (int i = 0; i < nodePaths.length; i++) { - writeMissingStringWZNode(nodePaths[i], missingNames.get(nodePaths[i]), i == 2); } - - printWriter.close(); } public static void main(String[] args) { - try { + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + printWriter = pw; curType = ItemType.EQP; readEquipWZData(); @@ -457,10 +461,8 @@ public class NoItemNameFetcher { readStringWZData(); // calculates the diff and effectively holds all items with no name property on the WZ System.out.println("Reporting results..."); - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); printReportFileHeader(); printReportFileResults(); - printWriter.close(); Map> missingNames = filterMissingItemNames(); writeMissingStringWZNames(missingNames); diff --git a/src/main/java/tools/mapletools/QuestItemCountFetcher.java b/src/main/java/tools/mapletools/QuestItemCountFetcher.java index fb0a453a92..c19f0adda5 100644 --- a/src/main/java/tools/mapletools/QuestItemCountFetcher.java +++ b/src/main/java/tools/mapletools/QuestItemCountFetcher.java @@ -5,6 +5,8 @@ import tools.Pair; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.*; /** @@ -17,7 +19,7 @@ import java.util.*; * Running it should generate a report file under "output" folder with the search results. */ public class QuestItemCountFetcher { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("quest_item_count_report.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("quest_item_count_report.txt"); private static final String ACT_NAME = WZFiles.QUEST.getFilePath() + "/Act.img.xml"; private static final String CHECK_NAME = WZFiles.QUEST.getFilePath() + "/Check.img.xml"; private static final int INITIAL_STRING_LENGTH = 50; @@ -241,17 +243,16 @@ public class QuestItemCountFetcher { private static void reportQuestItemCountData() { // This will reference one line at a time - try { + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { System.out.println("Reading WZs..."); readQuestItemCountData(); System.out.println("Reporting results..."); - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); + printWriter = pw; printReportFileHeader(); printReportFileResults(); - printWriter.close(); System.out.println("Done!"); } catch (FileNotFoundException ex) { System.out.println("Unable to open quest file."); diff --git a/src/main/java/tools/mapletools/QuestItemFetcher.java b/src/main/java/tools/mapletools/QuestItemFetcher.java index 3c3f6becca..56b4ef1e97 100644 --- a/src/main/java/tools/mapletools/QuestItemFetcher.java +++ b/src/main/java/tools/mapletools/QuestItemFetcher.java @@ -8,6 +8,8 @@ import tools.Pair; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -25,7 +27,7 @@ import java.util.*; * Estimated parse time: 1 minute */ public class QuestItemFetcher { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("quest_report.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("quest_report.txt"); private static final int INITIAL_STRING_LENGTH = 50; private static final int INITIAL_LENGTH = 200; private static final boolean DISPLAY_EXTRA_INFO = true; // display items with zero quantity over the quest act WZ @@ -409,32 +411,28 @@ public class QuestItemFetcher { private static void reportQuestItemData() { // This will reference one line at a time String line = null; - String fileName = null; + Path file = null; - try { + try{ System.out.println("Reading WZs..."); - fileName = WZFiles.QUEST.getFilePath() + "/Check.img.xml"; - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(fileName), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); + file = WZFiles.QUEST.getFile().resolve("Check.img.xml"); + bufferedReader = Files.newBufferedReader(file); while ((line = bufferedReader.readLine()) != null) { translateCheckToken(line); // fetch expired quests through here as well } bufferedReader.close(); - fileReader.close(); - fileName = WZFiles.QUEST.getFilePath() + "/Act.img.xml"; - fileReader = new InputStreamReader(new FileInputStream(fileName), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); + file = WZFiles.QUEST.getFile().resolve("Act.img.xml"); + bufferedReader = Files.newBufferedReader(file); while ((line = bufferedReader.readLine()) != null) { translateActToken(line); } bufferedReader.close(); - fileReader.close(); System.out.println("Calculating table diffs..."); calculateQuestItemDiff(); @@ -453,7 +451,7 @@ public class QuestItemFetcher { System.out.println("Reporting results..."); // report suspects of missing quest drop data, as well as those drop data that may have incorrect questids. - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); + printWriter = new PrintWriter(Files.newOutputStream(OUTPUT_FILE)); printReportFileHeader(); @@ -508,9 +506,9 @@ public class QuestItemFetcher { printWriter.close(); System.out.println("Done!"); } catch (FileNotFoundException ex) { - System.out.println("Unable to open file '" + fileName + "'"); + System.out.println("Unable to open file '" + file + "'"); } catch (IOException ex) { - System.out.println("Error reading file '" + fileName + "'"); + System.out.println("Error reading file '" + file + "'"); } catch (SQLException e) { System.out.println("Warning: Could not establish connection to database to report quest data."); System.out.println(e.getMessage()); diff --git a/src/main/java/tools/mapletools/QuestMesoFetcher.java b/src/main/java/tools/mapletools/QuestMesoFetcher.java index 4bf1a8da95..5623911a54 100644 --- a/src/main/java/tools/mapletools/QuestMesoFetcher.java +++ b/src/main/java/tools/mapletools/QuestMesoFetcher.java @@ -4,6 +4,8 @@ import provider.wz.WZFiles; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.*; /** @@ -16,7 +18,7 @@ import java.util.*; * Running it should generate a report file under "output" folder with the search results. */ public class QuestMesoFetcher { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("quest_meso_report.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("quest_meso_report.txt"); private static final boolean PRINT_FEES = true; // print missing values as additional info report private static final int INITIAL_STRING_LENGTH = 50; @@ -147,25 +149,21 @@ public class QuestMesoFetcher { private static void readQuestMesoData() throws IOException { String line; - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(WZFiles.QUEST.getFilePath() + "/Act.img.xml"), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); + bufferedReader = Files.newBufferedReader(WZFiles.QUEST.getFile().resolve("Act.img.xml")); while ((line = bufferedReader.readLine()) != null) { translateTokenAct(line); } bufferedReader.close(); - fileReader.close(); - fileReader = new InputStreamReader(new FileInputStream(WZFiles.QUEST.getFilePath() + "/Check.img.xml"), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); + bufferedReader = Files.newBufferedReader(WZFiles.QUEST.getFile().resolve("Check.img.xml")); while ((line = bufferedReader.readLine()) != null) { translateTokenCheck(line); } bufferedReader.close(); - fileReader.close(); } private static void printReportFileHeader() { @@ -232,20 +230,19 @@ public class QuestMesoFetcher { private static void reportQuestMesoData() { // This will reference one line at a time - try { + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { System.out.println("Reading WZs..."); readQuestMesoData(); System.out.println("Reporting results..."); // report missing meso checks on quest completes - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); + printWriter = pw; printReportFileHeader(); printReportFileResults(checkedMesoQuests, appliedMesoQuests, true); printReportFileResults(appliedMesoQuests, checkedMesoQuests, false); - printWriter.close(); System.out.println("Done!"); } catch (FileNotFoundException ex) { System.out.println("Unable to open quest file."); diff --git a/src/main/java/tools/mapletools/QuestlineFetcher.java b/src/main/java/tools/mapletools/QuestlineFetcher.java index cd40f6c83b..0e8188fb10 100644 --- a/src/main/java/tools/mapletools/QuestlineFetcher.java +++ b/src/main/java/tools/mapletools/QuestlineFetcher.java @@ -4,6 +4,10 @@ import provider.wz.WZFiles; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.time.Duration; +import java.time.Instant; import java.util.*; /** @@ -18,7 +22,7 @@ import java.util.*; * Running it should generate a report file under "output" folder with the search results. */ public class QuestlineFetcher { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("questline_report.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("questline_report.txt"); private static final String ACT_NAME = WZFiles.QUEST.getFilePath() + "/Act.img.xml"; private static final String CHECK_NAME = WZFiles.QUEST.getFilePath() + "/Check.img.xml"; private static final int INITIAL_STRING_LENGTH = 50; @@ -289,7 +293,7 @@ public class QuestlineFetcher { private static void reportQuestlineData() { // This will reference one line at a time - try { + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { System.out.println("Reading quest scripts..."); instantiateQuestScriptFiles(ToolConstants.SCRIPTS_PATH + "/quest"); @@ -301,12 +305,11 @@ public class QuestlineFetcher { calculateSkillRelatedMissingQuestScripts(); System.out.println("Reporting results..."); - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); + printWriter = pw; printReportFileHeader(); printReportFileResults(); - printWriter.close(); System.out.println("Done!"); } catch (FileNotFoundException ex) { System.out.println("Unable to open quest file."); @@ -356,7 +359,13 @@ public class QuestlineFetcher { */ public static void main(String[] args) { + Instant instantStarted = Instant.now(); reportQuestlineData(); + Instant instantStopped = Instant.now(); + Duration durationBetween = Duration.between(instantStarted, instantStopped); + System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis()); + System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); + } } diff --git a/src/main/java/tools/mapletools/ReactorDropFetcher.java b/src/main/java/tools/mapletools/ReactorDropFetcher.java index c8c5497c5f..32879069fd 100644 --- a/src/main/java/tools/mapletools/ReactorDropFetcher.java +++ b/src/main/java/tools/mapletools/ReactorDropFetcher.java @@ -3,6 +3,8 @@ package tools.mapletools; import java.io.File; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -16,7 +18,7 @@ import java.util.*; * not yet coded. */ public class ReactorDropFetcher { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("reactor_drop_report.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("reactor_drop_report.txt"); private static final String REACTOR_SCRIPT_PATH = ToolConstants.SCRIPTS_PATH + "/reactor"; private static final Connection con = SimpleDatabaseConnection.getConnection(); @@ -84,19 +86,18 @@ public class ReactorDropFetcher { } private static void reportMissingReactors() { - try { + try(con; + PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { System.out.println("Fetching reactors from DB..."); fetchMissingReactorDrops(); - con.close(); - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); + printWriter = pw; // report suspects of missing quest drop data, as well as those drop data that may have incorrect questids. System.out.println("Reporting results..."); printReportFileHeader(); reportMissingReactorDrops(); - printWriter.close(); System.out.println("Done!"); } catch (SQLException e) { System.out.println("Warning: Could not establish connection to database to report quest data."); diff --git a/src/main/java/tools/mapletools/SkillMakerFetcher.java b/src/main/java/tools/mapletools/SkillMakerFetcher.java index 08dcf7f885..e8960be230 100644 --- a/src/main/java/tools/mapletools/SkillMakerFetcher.java +++ b/src/main/java/tools/mapletools/SkillMakerFetcher.java @@ -6,6 +6,8 @@ import tools.DatabaseConnection; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -20,8 +22,8 @@ import java.util.Map; */ public class SkillMakerFetcher { - private static final File INPUT_FILE = new File(WZFiles.ETC.getFile(), "ItemMake.img.xml"); - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("maker-data.sql"); + private static final Path INPUT_FILE = WZFiles.ETC.getFile().resolve("ItemMake.img.xml"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("maker-data.sql"); private static final int INITIAL_STRING_LENGTH = 50; private static PrintWriter printWriter = null; @@ -303,10 +305,10 @@ public class SkillMakerFetcher { // This will reference one line at a time String line = null; - try { - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(INPUT_FILE), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE)); + BufferedReader br = Files.newBufferedReader(INPUT_FILE);) { + printWriter = pw; + bufferedReader = br; resetMakerDataFields(); @@ -316,9 +318,6 @@ public class SkillMakerFetcher { WriteMakerTableFile(); - printWriter.close(); - bufferedReader.close(); - fileReader.close(); } catch (FileNotFoundException ex) { System.out.println("Unable to open file '" + INPUT_FILE + "'"); } catch (IOException ex) { diff --git a/src/main/java/tools/mapletools/SkillMakerReagentIndexer.java b/src/main/java/tools/mapletools/SkillMakerReagentIndexer.java index 798bebb3e7..08b3153e8a 100644 --- a/src/main/java/tools/mapletools/SkillMakerReagentIndexer.java +++ b/src/main/java/tools/mapletools/SkillMakerReagentIndexer.java @@ -5,6 +5,8 @@ import tools.Pair; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; @@ -16,8 +18,8 @@ import java.util.List; * by the server source. */ public class SkillMakerReagentIndexer { - private static final File INPUT_FILE = new File(WZFiles.ITEM.getFile(), "Etc/0425.img.xml"); - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("maker-reagent-data.sql"); + private static final Path INPUT_FILE = WZFiles.ITEM.getFile().resolve("Etc/0425.img.xml"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("maker-reagent-data.sql"); private static final int INITIAL_STRING_LENGTH = 50; private static final List>> reagentList = new ArrayList<>(); @@ -151,22 +153,19 @@ public class SkillMakerReagentIndexer { // This will reference one line at a time String line = null; - try { - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(INPUT_FILE), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE)); + BufferedReader br = Files.newBufferedReader(INPUT_FILE);) { + bufferedReader = br; while ((line = bufferedReader.readLine()) != null) { translateToken(line); } - bufferedReader.close(); - fileReader.close(); SortReagentList(); - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); + printWriter = pw; WriteMakerReagentTableFile(); - printWriter.close(); } catch (FileNotFoundException ex) { System.out.println("Unable to open file '" + OUTPUT_FILE + "'"); } catch (IOException ex) { diff --git a/src/main/java/tools/mapletools/SkillbookChanceFetcher.java b/src/main/java/tools/mapletools/SkillbookChanceFetcher.java index 411c7626f2..39a0f19465 100644 --- a/src/main/java/tools/mapletools/SkillbookChanceFetcher.java +++ b/src/main/java/tools/mapletools/SkillbookChanceFetcher.java @@ -7,6 +7,8 @@ import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -27,7 +29,7 @@ import java.util.Map; * drops. */ public class SkillbookChanceFetcher { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("skillbook_drop_data.sql"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("skillbook_drop_data.sql"); private static final Map, Integer> skillbookChances = new HashMap<>(); private static PrintWriter printWriter; @@ -102,8 +104,8 @@ public class SkillbookChanceFetcher { } private static void generateSkillbookChanceUpdateFile() { - try { - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + printWriter = pw; printSkillbookChanceUpdateSqlHeader(); @@ -112,7 +114,6 @@ public class SkillbookChanceFetcher { printWriter.println("(" + e.getKey().getLeft() + ", " + e.getKey().getRight() + ", 1, 1, 0, " + e.getValue() + "),"); } - printWriter.close(); } catch (IOException ioe) { ioe.printStackTrace(); } diff --git a/src/main/java/tools/mapletools/SkillbookStackUpdate.java b/src/main/java/tools/mapletools/SkillbookStackUpdate.java index c25609be87..d540331a24 100644 --- a/src/main/java/tools/mapletools/SkillbookStackUpdate.java +++ b/src/main/java/tools/mapletools/SkillbookStackUpdate.java @@ -3,7 +3,12 @@ package tools.mapletools; import provider.wz.WZFiles; import java.io.*; -import java.nio.charset.StandardCharsets; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; +import java.time.Duration; +import java.time.Instant; /** * @author RonanLana @@ -15,8 +20,8 @@ import java.nio.charset.StandardCharsets; * Estimated parse time: 10 seconds */ public class SkillbookStackUpdate { - private static final File INPUT_DIRECTORY = new File(WZFiles.ITEM.getFile(), "Consume"); - private static final File OUTPUT_DIRECTORY = ToolConstants.getOutputFile("skillbook-update"); + private static final Path INPUT_DIRECTORY = WZFiles.ITEM.getFile().resolve("Consume"); + private static final Path OUTPUT_DIRECTORY = ToolConstants.getOutputFile("skillbook-update"); private static final int INITIAL_STRING_LENGTH = 50; private static PrintWriter printWriter = null; @@ -65,7 +70,6 @@ public class SkillbookStackUpdate { private static void forwardCursor(int st) { String line = null; - try { while (status >= st && (line = bufferedReader.readLine()) != null) { simpleToken(line); @@ -111,47 +115,56 @@ public class SkillbookStackUpdate { printWriter.println(token); } - private static void parseItemFile(File file, File outputFile) { + private static void parseItemFile(Path file, Path outputFile) { setupDirectories(outputFile); - // This will reference one line at a time - String line = null; - - try { - printWriter = new PrintWriter(outputFile); - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); - - while ((line = bufferedReader.readLine()) != null) { - translateItemToken(line); - } - - bufferedReader.close(); - fileReader.close(); - printWriter.close(); + + try(BufferedReader br = Files.newBufferedReader(file); + PrintWriter pw = new PrintWriter(Files.newOutputStream(outputFile))) { + bufferedReader = br; + printWriter = pw; + String line; + while ((line = bufferedReader.readLine()) != null) { + translateItemToken(line); + } } catch (IOException ex) { - System.out.println("Error reading file '" + file.getName() + "'"); + System.out.println("Error reading file '" + file.getFileName() + "'"); ex.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } - private static void setupDirectories(File file) { - if (!file.getParentFile().exists()) { - file.getParentFile().mkdirs(); - } + private static void setupDirectories(Path file) { + if(!Files.exists(file.getParent())) { + try { + Files.createDirectories(file.getParent()); + } catch (IOException e) { + System.out.println("Error creating folder '" + file.getParent() + "'"); + e.printStackTrace(); + } + } } - private static void parseItemDirectory(File inputDirectory, File outputDirectory) { - for (File f : inputDirectory.listFiles()) { - parseItemFile(f, new File(outputDirectory, f.getName())); - } + private static void parseItemDirectory(Path inputDirectory, Path outputDirectory) { + try (DirectoryStream stream = Files.newDirectoryStream(inputDirectory)) { + for (Path path : stream) { + parseItemFile(path, outputDirectory.resolve(path.getFileName())); + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } public static void main(String[] args) { + Instant instantStarted = Instant.now(); System.out.println("Reading item files..."); parseItemDirectory(INPUT_DIRECTORY, OUTPUT_DIRECTORY); System.out.println("Done!"); + Instant instantStopped = Instant.now(); + Duration durationBetween = Duration.between(instantStarted, instantStopped); + System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis()); + System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); } } diff --git a/src/main/java/tools/mapletools/ToolConstants.java b/src/main/java/tools/mapletools/ToolConstants.java index 641d8a7d69..b14a896d4f 100644 --- a/src/main/java/tools/mapletools/ToolConstants.java +++ b/src/main/java/tools/mapletools/ToolConstants.java @@ -1,18 +1,19 @@ package tools.mapletools; -import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; class ToolConstants { - static final File INPUT_DIRECTORY = new File("tools/input"); - static final File OUTPUT_DIRECTORY = new File("tools/output"); + static final Path INPUT_DIRECTORY = Paths.get("tools/input"); + static final Path OUTPUT_DIRECTORY = Paths.get("tools/output"); static final String SCRIPTS_PATH = "scripts"; static final String HANDBOOK_PATH = "handbook"; - static File getInputFile(String fileName) { - return new File(INPUT_DIRECTORY, fileName); + static Path getInputFile(String fileName) { + return INPUT_DIRECTORY.resolve(fileName); } - static File getOutputFile(String fileName) { - return new File(OUTPUT_DIRECTORY, fileName); + static Path getOutputFile(String fileName) { + return OUTPUT_DIRECTORY.resolve(fileName); } } diff --git a/src/main/java/tools/mapletools/WorldmapChecker.java b/src/main/java/tools/mapletools/WorldmapChecker.java index 5fda287730..8c47254752 100644 --- a/src/main/java/tools/mapletools/WorldmapChecker.java +++ b/src/main/java/tools/mapletools/WorldmapChecker.java @@ -5,6 +5,8 @@ import tools.Pair; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.*; /** @@ -14,7 +16,7 @@ import java.util.*; * throughout the map tree (area map -> continent map -> world map) but are currently missing. */ public class WorldmapChecker { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("worldmap_report.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("worldmap_report.txt"); private static final int INITIAL_STRING_LENGTH = 50; private static final Map> worldMapids = new HashMap<>(); private static final Map parentWorldmaps = new HashMap<>(); @@ -186,8 +188,8 @@ public class WorldmapChecker { } private static void verifyWorldmapTreeMapids() { - try { - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + printWriter = pw; printReportFileHeader(); if (rootWorldmaps.size() > 1) { @@ -242,7 +244,6 @@ public class WorldmapChecker { printReportFileResults(unreferencedEntries); } - printWriter.close(); } catch (Exception e) { e.printStackTrace(); }