= Monitored file updating post-accept now to properly keep tabs on changes

This commit is contained in:
Matthew Cech
2019-06-29 01:16:27 -07:00
parent 26c30cb1c8
commit 84f1c6118b
4 changed files with 17 additions and 11 deletions
+1 -1
View File
@@ -166,7 +166,7 @@
"Localized Strings","InviteInfo","Provides a direct invite link for KittyBot" "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 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","indicator",""
"Localized Commands","yeet","yeet, yeety" "Localized Commands","yeet",""
"Localized Commands","guildroleremove","" "Localized Commands","guildroleremove",""
"Localized Commands","bethistory","" "Localized Commands","bethistory",""
"Localized Commands","benchmark, bench","" "Localized Commands","benchmark, bench",""
1 Type Key Value
166 Localized Strings InviteInfo Provides a direct invite link for KittyBot
167 Localized Strings DBFlushInfo Takes all objects queued for the database and writes them to the database, then says how many were written.
168 Localized Commands indicator
169 Localized Commands yeet yeet, yeety
170 Localized Commands guildroleremove
171 Localized Commands bethistory
172 Localized Commands benchmark, bench
+1 -1
View File
@@ -19,7 +19,7 @@ public class CommandEnabler implements IConfigSection
public static final String enabled = "1"; public static final String enabled = "1";
public static final String disabled = "0"; public static final String disabled = "0";
public static final boolean defaultEnabledState = true; public static final boolean defaultEnabledState = true;
public static final String HeaderName = "Command Management"; public static final String HeaderName = "Command Enabler";
// Local variables // Local variables
private HashMap<String, Boolean> enabledMap; // Quick lookup private HashMap<String, Boolean> enabledMap; // Quick lookup
+11 -8
View File
@@ -15,6 +15,8 @@ import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder; import com.opencsv.CSVReaderBuilder;
import com.opencsv.CSVWriter; import com.opencsv.CSVWriter;
import utils.GlobalLog;
public class ConfigCSV public class ConfigCSV
{ {
// Variables // Variables
@@ -67,12 +69,11 @@ public class ConfigCSV
{ {
if(record.length < ConfigItem.items) 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; continue;
} }
ConfigItem parsedLine = new ConfigItem(record[0], record[1], record[2]); ConfigItem parsedLine = new ConfigItem(record[0], record[1], record[2]);
System.out.println(parsedLine);
fileContents.add(parsedLine); fileContents.add(parsedLine);
++line; ++line;
} }
@@ -111,17 +112,19 @@ public class ConfigCSV
{ {
try try
{ {
Writer writer = Files.newBufferedWriter(Paths.get(path)); List<String[]> toWrite = new Vector<String[]>();
CSVWriter csvWriter = makeWriter(writer); toWrite.add(ConfigItem.header);
csvWriter.writeNext(ConfigItem.header);
for(ConfigItem item : fileContents) 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(); csvWriter.close();
writer.close();
} }
catch (IOException e) catch (IOException e)
{ {
+3
View File
@@ -44,8 +44,11 @@ public class FileMonitor
if(last.longValue() != file.lastModified.longValue()) if(last.longValue() != file.lastModified.longValue())
{ {
IOLog.log("Most recently modified at " + last + ", stored version at " + file.lastModified); IOLog.log("Most recently modified at " + last + ", stored version at " + file.lastModified);
file = new MonitoredFile(file.path, last); file = new MonitoredFile(file.path, last);
fileChanged.accept(file); fileChanged.accept(file);
file = new MonitoredFile(file.path, FileUtils.lastModified(file.path));
} }
} }
} }