= Iterative step towards combined config file
file shall be config.config, because config.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
package commands;
|
package commands;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
import core.Config;
|
import core.Constants;
|
||||||
import core.DatabaseManager;
|
import core.DatabaseManager;
|
||||||
import core.LocStrings;
|
import core.LocStrings;
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
@@ -28,7 +28,7 @@ public class CommandDBFlush extends Command
|
|||||||
KittyEmbed embed = new KittyEmbed();
|
KittyEmbed embed = new KittyEmbed();
|
||||||
embed.title = "Database queue flushed";
|
embed.title = "Database queue flushed";
|
||||||
embed.descriptionText = "**Dirty:** " + numUpdated;
|
embed.descriptionText = "**Dirty:** " + numUpdated;
|
||||||
embed.color = Config.ColorDefault;
|
embed.color = Constants.ColorDefault;
|
||||||
|
|
||||||
res.send(embed);
|
res.send(embed);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.text.DateFormat;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
import core.Config;
|
import core.Constants;
|
||||||
import core.DatabaseManager;
|
import core.DatabaseManager;
|
||||||
import core.LocStrings;
|
import core.LocStrings;
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
@@ -36,7 +36,7 @@ public class CommandDBStats extends Command
|
|||||||
embed.descriptionText = "**Tracked Items:** " + DatabaseManager.instance.getTrackedObjectsSize();
|
embed.descriptionText = "**Tracked Items:** " + DatabaseManager.instance.getTrackedObjectsSize();
|
||||||
embed.descriptionText += "\n";
|
embed.descriptionText += "\n";
|
||||||
embed.descriptionText += "**Last Upkeep:** " + dateFormat.format(DatabaseManager.instance.getLastUpkeep()) + " UTC-7";
|
embed.descriptionText += "**Last Upkeep:** " + dateFormat.format(DatabaseManager.instance.getLastUpkeep()) + " UTC-7";
|
||||||
embed.color = Config.ColorDefault;
|
embed.color = Constants.ColorDefault;
|
||||||
|
|
||||||
res.send(embed);
|
res.send(embed);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
import core.Config;
|
import core.Constants;
|
||||||
import core.DatabaseManager;
|
import core.DatabaseManager;
|
||||||
import core.LocStrings;
|
import core.LocStrings;
|
||||||
import core.ObjectBuilderFactory;
|
import core.ObjectBuilderFactory;
|
||||||
@@ -79,7 +79,7 @@ public class CommandLeaderboard extends Command
|
|||||||
// Configure output
|
// Configure output
|
||||||
final int listSize = 10;
|
final int listSize = 10;
|
||||||
KittyEmbed embed = new KittyEmbed();
|
KittyEmbed embed = new KittyEmbed();
|
||||||
embed.color = Config.ColorDefault;
|
embed.color = Constants.ColorDefault;
|
||||||
embed.title = LocStrings.stub("LeaderboardTitle");
|
embed.title = LocStrings.stub("LeaderboardTitle");
|
||||||
embed.descriptionText = "";
|
embed.descriptionText = "";
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package commands;
|
|||||||
import core.Command;
|
import core.Command;
|
||||||
import core.LocStrings;
|
import core.LocStrings;
|
||||||
import core.CommandManager.ThreadData;
|
import core.CommandManager.ThreadData;
|
||||||
import core.Config;
|
import core.Constants;
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
import dataStructures.KittyEmbed;
|
import dataStructures.KittyEmbed;
|
||||||
import dataStructures.KittyGuild;
|
import dataStructures.KittyGuild;
|
||||||
@@ -82,7 +82,7 @@ public class CommandStats extends Command
|
|||||||
KittyEmbed embed = new KittyEmbed();
|
KittyEmbed embed = new KittyEmbed();
|
||||||
embed.title = "Bot Stats";
|
embed.title = "Bot Stats";
|
||||||
embed.descriptionText = out;
|
embed.descriptionText = out;
|
||||||
embed.color = Config.ColorDefault;
|
embed.color = Constants.ColorDefault;
|
||||||
|
|
||||||
res.send(embed);
|
res.send(embed);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import core.Command;
|
import core.Command;
|
||||||
import core.Config;
|
import core.Constants;
|
||||||
import core.LocStrings;
|
import core.LocStrings;
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
import dataStructures.KittyGuild;
|
import dataStructures.KittyGuild;
|
||||||
@@ -54,7 +54,7 @@ public class CommandTeey extends Command
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
teeyeeFile = new File(yeeteeFilename);
|
teeyeeFile = new File(yeeteeFilename);
|
||||||
ImageOverlayBuilder builder = new ImageOverlayBuilder(Config.AssetDirectory + "teey/frames/", "teey ", 24, 18);
|
ImageOverlayBuilder builder = new ImageOverlayBuilder(Constants.AssetDirectory + "teey/frames/", "teey ", 24, 18);
|
||||||
builder.overlay(ImageIO.read(teeyeeFile), name);
|
builder.overlay(ImageIO.read(teeyeeFile), name);
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import core.Command;
|
import core.Command;
|
||||||
import core.Config;
|
import core.Constants;
|
||||||
import core.LocStrings;
|
import core.LocStrings;
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
import dataStructures.KittyGuild;
|
import dataStructures.KittyGuild;
|
||||||
@@ -54,7 +54,7 @@ public class CommandYeet extends Command
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
yeeteeFile = new File(yeeteeFilename);
|
yeeteeFile = new File(yeeteeFilename);
|
||||||
ImageOverlayBuilder builder = new ImageOverlayBuilder(Config.AssetDirectory + "yeet/frames/", "yeet ", 24, 18);
|
ImageOverlayBuilder builder = new ImageOverlayBuilder(Constants.AssetDirectory + "yeet/frames/", "yeet ", 24, 18);
|
||||||
builder.overlay(ImageIO.read(yeeteeFile), name);
|
builder.overlay(ImageIO.read(yeeteeFile), name);
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ public abstract class BaseLocFile
|
|||||||
public static final String KittySourceDirectory = "./src";
|
public static final String KittySourceDirectory = "./src";
|
||||||
|
|
||||||
// Filename
|
// Filename
|
||||||
public final String filename; // Example: "localization.config";
|
|
||||||
public final String functionName; // Example: "Localizer.Stub";
|
public final String functionName; // Example: "Localizer.Stub";
|
||||||
|
|
||||||
// Local translation storage
|
// Local translation storage
|
||||||
@@ -38,28 +37,11 @@ public abstract class BaseLocFile
|
|||||||
protected FileMonitor fileMonitor;
|
protected FileMonitor fileMonitor;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
public BaseLocFile(String filename, String functionName)
|
public BaseLocFile(String functionName)
|
||||||
{
|
{
|
||||||
this.filename = filename;
|
|
||||||
this.functionName = functionName;
|
this.functionName = functionName;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks the file specified for updates
|
|
||||||
public void update()
|
|
||||||
{
|
|
||||||
synchronized(stringStore)
|
|
||||||
{
|
|
||||||
fileMonitor.update(this::onFileChange);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// When the file is changed
|
|
||||||
protected void onFileChange(MonitoredFile file)
|
|
||||||
{
|
|
||||||
log("Loc file was modified at path " + file.path);
|
|
||||||
updateLocFromDisk();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Structure used for holding a pair of strings and any other info we need
|
// Structure used for holding a pair of strings and any other info we need
|
||||||
// about localized information that is being looked up.
|
// about localized information that is being looked up.
|
||||||
private class LocInfo
|
private class LocInfo
|
||||||
@@ -128,62 +110,13 @@ public abstract class BaseLocFile
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reads a file to string, adapted from https://stackoverflow.com/a/326440/5383198
|
|
||||||
private String readFileAsString(String path, Charset encoding)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
byte[] encoded = Files.readAllBytes(Paths.get(path));
|
|
||||||
return new String(encoded, encoding);
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
warn("No file found to read from!");
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update localization from the disk on file. Creates the file if it doesn't exist.
|
// Update localization from the disk on file. Creates the file if it doesn't exist.
|
||||||
// This file is internally formatted as an ini file.
|
// This file is internally formatted as an ini file.
|
||||||
public void updateLocFromDisk()
|
public void updateLocFromString(String fileContents)
|
||||||
{
|
{
|
||||||
log("Attempting to read localization file: " + filename);
|
log("Attempting to read localization file contents");
|
||||||
|
|
||||||
try
|
stringStore = new TaggedPairStore(fileContents);
|
||||||
{
|
|
||||||
String fileContents = readFileAsString(filename, Charset.defaultCharset());
|
|
||||||
|
|
||||||
if(fileContents == null)
|
|
||||||
{
|
|
||||||
File file = new File(filename);
|
|
||||||
file.createNewFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
stringStore = new TaggedPairStore(fileContents);
|
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
|
||||||
error("IO exception during localization file read");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rewrites out at the specified filename with existing stubs.
|
|
||||||
// This preserves existing localized phrases.
|
|
||||||
public void saveLocToDisk()
|
|
||||||
{
|
|
||||||
log("Attempting to write updated localization file");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
PrintWriter pw = new PrintWriter(filename);
|
|
||||||
pw.println(stringStore.toString());
|
|
||||||
pw.close();
|
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
|
||||||
error("IO exception during localization file write");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tryStripSpecified(Path path, ArrayList<LocInfo> toFill)
|
private void tryStripSpecified(Path path, ArrayList<LocInfo> toFill)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class CommandEnabler extends BaseKeyValueFile
|
|||||||
// Local variables
|
// Local variables
|
||||||
private HashMap<String, Boolean> enabledMap; // Quick lookup
|
private HashMap<String, Boolean> enabledMap; // Quick lookup
|
||||||
private ArrayList<String> keyList; // Tracking ordering for later
|
private ArrayList<String> keyList; // Tracking ordering for later
|
||||||
private final static String name = Config.AssetDirectory + "commands.config";
|
private final static String name = Constants.AssetDirectory + "commands.config";
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
public CommandEnabler()
|
public CommandEnabler()
|
||||||
|
|||||||
+23
-4
@@ -1,9 +1,28 @@
|
|||||||
package core;
|
package core;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
import java.awt.Color;
|
import utils.GlobalLog;
|
||||||
|
import utils.LogFilter;
|
||||||
|
import utils.io.MonitoredFile;
|
||||||
|
|
||||||
public final class Config
|
public class Config
|
||||||
{
|
{
|
||||||
public static final Color ColorDefault = new Color(7*16, 8*16, 9*16); // A slate-grey
|
private static final Path filepath = Constants.AssetDirectory + Constants.ConfigFilename;
|
||||||
public static final String AssetDirectory = "./assets/";
|
MonitoredFile configFile;
|
||||||
|
|
||||||
|
Config instance;
|
||||||
|
|
||||||
|
public Config()
|
||||||
|
{
|
||||||
|
if(instance == null)
|
||||||
|
{
|
||||||
|
configFile = new MonitoredFile(filepath);
|
||||||
|
instance = this;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GlobalLog.error(LogFilter.Core, "You can't have two of the following: " + this.getClass().getSimpleName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package core;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
|
||||||
|
// Things that are internal only and aren't put inside an external config file.
|
||||||
|
public final class Constants
|
||||||
|
{
|
||||||
|
public static final Color ColorDefault = new Color(7*16, 8*16, 9*16); // A slate-grey
|
||||||
|
public static final String AssetDirectory = "./assets/";
|
||||||
|
public static final String ConfigFilename = "config.config";
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package core;
|
||||||
|
|
||||||
|
public abstract interface IConfigSection
|
||||||
|
{
|
||||||
|
public abstract String getHeader();
|
||||||
|
public abstract void preUpdate();
|
||||||
|
public abstract void init();
|
||||||
|
public abstract String getContent();
|
||||||
|
}
|
||||||
+25
-12
@@ -8,28 +8,22 @@ import dataStructures.Pair;
|
|||||||
|
|
||||||
// Performs the same localization for the strings associated with command names as
|
// Performs the same localization for the strings associated with command names as
|
||||||
// is performed with general strings in the application
|
// is performed with general strings in the application
|
||||||
public class LocCommands extends BaseLocFile
|
public class LocCommands extends BaseLocFile implements IConfigSection
|
||||||
{
|
{
|
||||||
public static final String fileName = Config.AssetDirectory + "locCommands.config";
|
public static final String HeaderName = "Localized Commands";
|
||||||
public static final String function = "LocCommands.stub";
|
public static final String function = "LocCommands.stub";
|
||||||
|
|
||||||
private static LocCommands instance;
|
private static LocCommands instance;
|
||||||
|
|
||||||
public LocCommands()
|
public LocCommands()
|
||||||
{
|
{
|
||||||
super(fileName, function);
|
super(function);
|
||||||
|
|
||||||
GlobalLog.log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName());
|
GlobalLog.log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName());
|
||||||
|
|
||||||
if(instance == null)
|
if(instance == null)
|
||||||
{
|
{
|
||||||
instance = this;
|
instance = this;
|
||||||
|
|
||||||
updateLocFromDisk();
|
|
||||||
scrapeAll();
|
|
||||||
saveLocToDisk();
|
|
||||||
|
|
||||||
fileMonitor = new FileMonitor(filename);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -51,8 +45,27 @@ public class LocCommands extends BaseLocFile
|
|||||||
return raw;
|
return raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void upkeep()
|
@Override
|
||||||
{
|
public String getHeader() {
|
||||||
instance.update();
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void preUpdate() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getContent() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,26 +9,20 @@ import utils.io.FileMonitor;
|
|||||||
// can then be localized.
|
// can then be localized.
|
||||||
public class LocStrings extends BaseLocFile
|
public class LocStrings extends BaseLocFile
|
||||||
{
|
{
|
||||||
public static final String fileName = Config.AssetDirectory + "locStrings.config";
|
public static final String fileName = Constants.AssetDirectory + "locStrings.config";
|
||||||
public static final String function = "LocStrings.stub";
|
public static final String function = "LocStrings.stub";
|
||||||
|
|
||||||
private static LocStrings instance;
|
private static LocStrings instance;
|
||||||
|
|
||||||
public LocStrings()
|
public LocStrings()
|
||||||
{
|
{
|
||||||
super(fileName, function);
|
super(function);
|
||||||
|
|
||||||
GlobalLog.log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName());
|
GlobalLog.log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName());
|
||||||
|
|
||||||
if(instance == null)
|
if(instance == null)
|
||||||
{
|
{
|
||||||
instance = this;
|
instance = this;
|
||||||
|
|
||||||
updateLocFromDisk();
|
|
||||||
scrapeAll();
|
|
||||||
saveLocToDisk();
|
|
||||||
|
|
||||||
fileMonitor = new FileMonitor(filename);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -492,7 +492,7 @@ public class ObjectBuilderFactory
|
|||||||
lazyInit();
|
lazyInit();
|
||||||
|
|
||||||
if(pluginManager == null)
|
if(pluginManager == null)
|
||||||
pluginManager = new PluginManager(Config.AssetDirectory + "plugins/");
|
pluginManager = new PluginManager(Constants.AssetDirectory + "plugins/");
|
||||||
|
|
||||||
return pluginManager;
|
return pluginManager;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import core.Config;
|
import core.Constants;
|
||||||
import dataStructures.Pair;
|
import dataStructures.Pair;
|
||||||
import utils.io.DirectoryMonitor;
|
import utils.io.DirectoryMonitor;
|
||||||
import utils.io.FileUtils;
|
import utils.io.FileUtils;
|
||||||
@@ -17,7 +17,7 @@ import utils.io.MonitoredFile;
|
|||||||
public class BenchmarkManager
|
public class BenchmarkManager
|
||||||
{
|
{
|
||||||
// Variables
|
// Variables
|
||||||
public final String directory = Config.AssetDirectory + "userbench/";
|
public final String directory = Constants.AssetDirectory + "userbench/";
|
||||||
public final String extension = ".csv";
|
public final String extension = ".csv";
|
||||||
public final String lineDelimiter = "\n";
|
public final String lineDelimiter = "\n";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user