From 84f1c6118b7ea852cf63374d3988afe0c1b7eacd Mon Sep 17 00:00:00 2001 From: Matthew Cech Date: Sat, 29 Jun 2019 01:16:27 -0700 Subject: [PATCH] = Monitored file updating post-accept now to properly keep tabs on changes --- assets/config.csv | 2 +- src/core/CommandEnabler.java | 2 +- src/core/ConfigCSV.java | 21 ++++++++++++--------- src/utils/io/FileMonitor.java | 3 +++ 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/assets/config.csv b/assets/config.csv index cf1a9f9..9aa88c4 100644 --- a/assets/config.csv +++ b/assets/config.csv @@ -166,7 +166,7 @@ "Localized Strings","InviteInfo","Provides a direct invite link for KittyBot" "Localized Strings","DBFlushInfo","Takes all objects queued for the database and writes them to the database, then says how many were written." "Localized Commands","indicator","" -"Localized Commands","yeet","yeet, yeety" +"Localized Commands","yeet","" "Localized Commands","guildroleremove","" "Localized Commands","bethistory","" "Localized Commands","benchmark, bench","" diff --git a/src/core/CommandEnabler.java b/src/core/CommandEnabler.java index 7e26d86..3eec255 100644 --- a/src/core/CommandEnabler.java +++ b/src/core/CommandEnabler.java @@ -19,7 +19,7 @@ public class CommandEnabler implements IConfigSection public static final String enabled = "1"; public static final String disabled = "0"; public static final boolean defaultEnabledState = true; - public static final String HeaderName = "Command Management"; + public static final String HeaderName = "Command Enabler"; // Local variables private HashMap enabledMap; // Quick lookup diff --git a/src/core/ConfigCSV.java b/src/core/ConfigCSV.java index 9f5d36a..36870a0 100644 --- a/src/core/ConfigCSV.java +++ b/src/core/ConfigCSV.java @@ -15,6 +15,8 @@ import com.opencsv.CSVReader; import com.opencsv.CSVReaderBuilder; import com.opencsv.CSVWriter; +import utils.GlobalLog; + public class ConfigCSV { // Variables @@ -67,12 +69,11 @@ public class ConfigCSV { if(record.length < ConfigItem.items) { - System.out.println("Incorrect number of items on line " + line + " in " + path); + GlobalLog.warn("Incorrect number of items on line " + line + " in " + path); continue; } - ConfigItem parsedLine = new ConfigItem(record[0], record[1], record[2]); - System.out.println(parsedLine); + ConfigItem parsedLine = new ConfigItem(record[0], record[1], record[2]); fileContents.add(parsedLine); ++line; } @@ -111,17 +112,19 @@ public class ConfigCSV { try { - Writer writer = Files.newBufferedWriter(Paths.get(path)); - CSVWriter csvWriter = makeWriter(writer); - - csvWriter.writeNext(ConfigItem.header); + List toWrite = new Vector(); + toWrite.add(ConfigItem.header); for(ConfigItem item : fileContents) { - csvWriter.writeNext(item.getAll()); + toWrite.add(item.getAll()); } - + Writer writer = Files.newBufferedWriter(Paths.get(path)); + CSVWriter csvWriter = makeWriter(writer); + csvWriter.writeAll(toWrite); + csvWriter.flush(); csvWriter.close(); + writer.close(); } catch (IOException e) { diff --git a/src/utils/io/FileMonitor.java b/src/utils/io/FileMonitor.java index f634e45..700d1c6 100644 --- a/src/utils/io/FileMonitor.java +++ b/src/utils/io/FileMonitor.java @@ -44,8 +44,11 @@ public class FileMonitor if(last.longValue() != file.lastModified.longValue()) { IOLog.log("Most recently modified at " + last + ", stored version at " + file.lastModified); + file = new MonitoredFile(file.path, last); fileChanged.accept(file); + + file = new MonitoredFile(file.path, FileUtils.lastModified(file.path)); } } }