= Updated naming and created base class stub for kv pair file

This commit is contained in:
Matthew Cech
2019-05-24 02:01:28 -07:00
parent 25c3327651
commit 6cf5a03186
8 changed files with 36 additions and 7 deletions
+6
View File
@@ -0,0 +1,6 @@
package core;
public class BaseKeyValueFile
{
}
@@ -17,7 +17,7 @@ import utils.io.MonitoredFile;
// A quick-and-dirty localization tool that scrapes the project for calls to itself, then
// generates/updates a file externally with all the stub values as keys that are localized.
public abstract class LocBase
public abstract class BaseLocFile
{
// Pre-defined values
public static final String KittySourceDirectory = "./src";
@@ -38,7 +38,7 @@ public abstract class LocBase
protected FileMonitor fileMonitor;
// Ok... so this is an array because if it's not an array, the parser will parse the string
public LocBase(String filename, String functionName)
public BaseLocFile(String filename, String functionName)
{
this.filename = filename;
this.functionName = functionName;
+7 -2
View File
@@ -15,10 +15,11 @@ import utils.LogFilter;
// commands that are being looked up will behave slightly differently so trimming
// rules for this file are different than the localization ones - this is more
// aggresive with whitespace removal.
public class CommandEnabler
public class CommandEnabler extends BaseKeyValueFile
{
// Config/const variables
public static final String header = "[CommandEnabler]"; // For consistency in files
public static final String headerStart = "[";
public static final String headerEnd = "]";
public static final String filename = "commands.config";
public static final String pairSplit = "=";
public static final char pairSeparator = '\n';
@@ -29,13 +30,17 @@ public class CommandEnabler
// Local variables
private HashMap<String, Boolean> enabledMap; // Quick lookup
private ArrayList<String> keyList; // Tracking ordering for later
private final String header;
public CommandEnabler()
{
// Create/Init variables
GlobalLog.Log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName());
enabledMap = new HashMap<>();
keyList = new ArrayList<>();
header = headerStart + this.getClass().getSimpleName() + headerEnd;
// Startup
ReadIn();
GetTrackedCommands();
WriteOut();
+1 -1
View File
@@ -8,7 +8,7 @@ import dataStructures.Pair;
// Performs the same localization for the strings associated with command names as
// is performed with general strings in the application
public class LocCommands extends LocBase
public class LocCommands extends BaseLocFile
{
public static final String fileName = "locCommands.config";
public static final String function = "LocCommands.Stub";
+1 -1
View File
@@ -7,7 +7,7 @@ import utils.io.FileMonitor;
// A quick-and-dirty localization tool that scrapes the project for calls to itself, then
// generates/updates a file externally (phrases.config) with all the stub values as keys that
// can then be localized.
public class LocStrings extends LocBase
public class LocStrings extends BaseLocFile
{
public static final String fileName = "locStrings.config";
public static final String function = "LocStrings.Stub";
+5
View File
@@ -0,0 +1,5 @@
package core;
public class Settings {
}
+9
View File
@@ -11,6 +11,15 @@ import java.util.stream.Stream;
public class FileUtils
{
public static void CreateDirectoryIfDoesntExist(String directoryName)
{
File directory = new File(directoryName);
if (! directory.exists()){
directory.mkdir();
}
}
// Reads all lines from a file as a string
public static String ReadContent(File file) { return ReadContent(file.toPath()); }
public static String ReadContent(Path filePath)
+5 -1
View File
@@ -9,6 +9,7 @@ import java.util.Date;
public class GlobalLog
{
private static final String directory = "logs/";
private static final String log = "Log";
private static final String warn = "Warning";
private static final String error = "ERROR";
@@ -19,7 +20,10 @@ public class GlobalLog
{
DateFormat dF = new SimpleDateFormat("yyyy_MM_dd_HH-mm");
Date today = new Date();
outputLog = new PrintWriter((dF.format(today) + ".log"), "UTF-8");
FileUtils.CreateDirectoryIfDoesntExist(directory);
outputLog = new PrintWriter(directory + (dF.format(today) + ".log"), "UTF-8");
GlobalLog.Log(LogFilter.Util, "Finished initializing logging system");
}
private static void Write(String status, LogFilter filter, String body)