= Updated utils and logging subsystem formatting
This commit is contained in:
@@ -63,8 +63,8 @@ public class CommandBlurry extends Command
|
|||||||
postProcessed = new File(name);
|
postProcessed = new File(name);
|
||||||
res.sendFile(postProcessed, "png");
|
res.sendFile(postProcessed, "png");
|
||||||
|
|
||||||
ImageUtils.BlockingFileDelete(preProcessed);
|
ImageUtils.blockingFileDelete(preProcessed);
|
||||||
ImageUtils.BlockingFileDelete(postProcessed);
|
ImageUtils.blockingFileDelete(postProcessed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ApplySnap(BufferedImage image, String name) throws IOException
|
private static void ApplySnap(BufferedImage image, String name) throws IOException
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class CommandBoop extends Command
|
|||||||
}
|
}
|
||||||
catch (NumberFormatException e)
|
catch (NumberFormatException e)
|
||||||
{
|
{
|
||||||
GlobalLog.Warn(LogFilter.Command, "No valid value was found for boops! Starting over at 0!");
|
GlobalLog.warn(LogFilter.Command, "No valid value was found for boops! Starting over at 0!");
|
||||||
boops = 0;
|
boops = 0;
|
||||||
markDirty();
|
markDirty();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class CommandCatch extends Command
|
|||||||
|
|
||||||
catcheeFile = new File(catchFilename);
|
catcheeFile = new File(catchFilename);
|
||||||
ImageOverlayBuilder builder = new ImageOverlayBuilder("assets/catch/frames/", "catch ", 92, 18);
|
ImageOverlayBuilder builder = new ImageOverlayBuilder("assets/catch/frames/", "catch ", 92, 18);
|
||||||
builder.Overlay(ImageIO.read(catcheeFile), name);
|
builder.overlay(ImageIO.read(catcheeFile), name);
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
@@ -65,7 +65,7 @@ public class CommandCatch extends Command
|
|||||||
res.sendFile(catchFile, "gif");
|
res.sendFile(catchFile, "gif");
|
||||||
|
|
||||||
// Thread cleanup...
|
// Thread cleanup...
|
||||||
ImageUtils.BlockingFileDelete(catchFile);
|
ImageUtils.blockingFileDelete(catchFile);
|
||||||
ImageUtils.BlockingFileDelete(catcheeFile);
|
ImageUtils.blockingFileDelete(catcheeFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class CommandColiru extends Command
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.send(compiler.compileCPlus(input.args));
|
res.send(compiler.compileCPlusPlus(input.args));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class CommandColor extends Command
|
|||||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||||
{
|
{
|
||||||
// First, try and parse out the color to make sure we can even get it.
|
// First, try and parse out the color to make sure we can even get it.
|
||||||
ColorData colorData = theColorAPI.LookupHex(input.args.trim());
|
ColorData colorData = theColorAPI.lookupHex(input.args.trim());
|
||||||
|
|
||||||
// Verify the color was even found
|
// Verify the color was even found
|
||||||
if(colorData == null)
|
if(colorData == null)
|
||||||
@@ -77,7 +77,7 @@ public class CommandColor extends Command
|
|||||||
|
|
||||||
// Send then delete the temp local files
|
// Send then delete the temp local files
|
||||||
res.send(response);
|
res.send(response);
|
||||||
ImageUtils.BlockingFileDelete(file);
|
ImageUtils.blockingFileDelete(file);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,13 +63,13 @@ public class CommandHelpBuilder extends Command {
|
|||||||
}
|
}
|
||||||
catch (FileNotFoundException e)
|
catch (FileNotFoundException e)
|
||||||
{
|
{
|
||||||
GlobalLog.Error(e.toString());
|
GlobalLog.error(e.toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
File file = new File(filename);
|
File file = new File(filename);
|
||||||
res.sendFile(file, "txt");
|
res.sendFile(file, "txt");
|
||||||
ImageUtils.BlockingFileDelete(file);
|
ImageUtils.blockingFileDelete(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generates the section for a specific role, optionally adding spacing after for another section
|
// Generates the section for a specific role, optionally adding spacing after for another section
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class CommandLeaderboard extends Command
|
|||||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||||
{
|
{
|
||||||
// Start by force-flushing. We need to be up-to-date.
|
// Start by force-flushing. We need to be up-to-date.
|
||||||
GlobalLog.Log("Flushed database for " + DatabaseManager.instance.upkeep() + " items.");
|
GlobalLog.log("Flushed database for " + DatabaseManager.instance.upkeep() + " items.");
|
||||||
|
|
||||||
// Get all users associated with a guild and get their bean count
|
// Get all users associated with a guild and get their bean count
|
||||||
String guildID = guild.uniqueID;
|
String guildID = guild.uniqueID;
|
||||||
@@ -74,7 +74,7 @@ public class CommandLeaderboard extends Command
|
|||||||
return (int)difference;
|
return (int)difference;
|
||||||
});
|
});
|
||||||
|
|
||||||
GlobalLog.Log(LogFilter.Command, "Sorted through " + users.size() + " KittyUsers for leaderboard purposes.");
|
GlobalLog.log(LogFilter.Command, "Sorted through " + users.size() + " KittyUsers for leaderboard purposes.");
|
||||||
|
|
||||||
// Configure output
|
// Configure output
|
||||||
final int listSize = 10;
|
final int listSize = 10;
|
||||||
|
|||||||
@@ -43,18 +43,18 @@ public class CommandMap extends Command
|
|||||||
{
|
{
|
||||||
OptionParser parser = new OptionParser(input.args);
|
OptionParser parser = new OptionParser(input.args);
|
||||||
|
|
||||||
String seedStr = parser.GetOption("-s", true);
|
String seedStr = parser.getOption("-s", true);
|
||||||
if(seedStr != null)
|
if(seedStr != null)
|
||||||
{
|
{
|
||||||
seed = Long.parseLong(seedStr);
|
seed = Long.parseLong(seedStr);
|
||||||
hasSeed = true;
|
hasSeed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String widthStr = parser.GetOption("-w", true);
|
String widthStr = parser.getOption("-w", true);
|
||||||
if(widthStr != null)
|
if(widthStr != null)
|
||||||
width = ValidateSize(Integer.parseInt(widthStr), MaxWidth);
|
width = ValidateSize(Integer.parseInt(widthStr), MaxWidth);
|
||||||
|
|
||||||
String heightStr = parser.GetOption("-h", true);
|
String heightStr = parser.getOption("-h", true);
|
||||||
if(heightStr != null)
|
if(heightStr != null)
|
||||||
height = ValidateSize(Integer.parseInt(heightStr), MaxHeight);
|
height = ValidateSize(Integer.parseInt(heightStr), MaxHeight);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,8 +69,8 @@ public class CommandPerish extends Command
|
|||||||
postProcessed = new File(name);
|
postProcessed = new File(name);
|
||||||
res.sendFile(postProcessed, "png");
|
res.sendFile(postProcessed, "png");
|
||||||
|
|
||||||
ImageUtils.BlockingFileDelete(preProcessed);
|
ImageUtils.blockingFileDelete(preProcessed);
|
||||||
ImageUtils.BlockingFileDelete(postProcessed);
|
ImageUtils.blockingFileDelete(postProcessed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ApplyTintEffect(BufferedImage image, String name) throws IOException
|
private static void ApplyTintEffect(BufferedImage image, String name) throws IOException
|
||||||
|
|||||||
@@ -48,14 +48,14 @@ public class CommandShutdown extends Command
|
|||||||
// Force upkeep, this works so long as upkeep is on the main thread.
|
// Force upkeep, this works so long as upkeep is on the main thread.
|
||||||
res.sendImmediate(LocStrings.stub("ShutdownSafe"));
|
res.sendImmediate(LocStrings.stub("ShutdownSafe"));
|
||||||
DatabaseManager.instance.upkeep();
|
DatabaseManager.instance.upkeep();
|
||||||
GlobalLog.Warn(LogFilter.Command, LocStrings.lookup("ShutdownSafe"));
|
GlobalLog.warn(LogFilter.Command, LocStrings.lookup("ShutdownSafe"));
|
||||||
|
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
res.sendImmediate(LocStrings.stub("ShutdownUnsafe"));// "``");
|
res.sendImmediate(LocStrings.stub("ShutdownUnsafe"));// "``");
|
||||||
GlobalLog.Warn(LogFilter.Command, LocStrings.lookup("ShutdownSafe"));
|
GlobalLog.warn(LogFilter.Command, LocStrings.lookup("ShutdownSafe"));
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ public class CommandStark extends Command
|
|||||||
postProcessed = new File(name);
|
postProcessed = new File(name);
|
||||||
res.sendFile(postProcessed, "png");
|
res.sendFile(postProcessed, "png");
|
||||||
|
|
||||||
ImageUtils.BlockingFileDelete(preProcessed);
|
ImageUtils.blockingFileDelete(preProcessed);
|
||||||
ImageUtils.BlockingFileDelete(postProcessed);
|
ImageUtils.blockingFileDelete(postProcessed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ApplySnap(BufferedImage image, String name) throws IOException
|
private static void ApplySnap(BufferedImage image, String name) throws IOException
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class CommandTeey extends Command
|
|||||||
|
|
||||||
teeyeeFile = new File(yeeteeFilename);
|
teeyeeFile = new File(yeeteeFilename);
|
||||||
ImageOverlayBuilder builder = new ImageOverlayBuilder("assets/teey/frames/", "teey ", 24, 18);
|
ImageOverlayBuilder builder = new ImageOverlayBuilder("assets/teey/frames/", "teey ", 24, 18);
|
||||||
builder.Overlay(ImageIO.read(teeyeeFile), name);
|
builder.overlay(ImageIO.read(teeyeeFile), name);
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
@@ -65,7 +65,7 @@ public class CommandTeey extends Command
|
|||||||
res.sendFile(teeyFile, "gif");
|
res.sendFile(teeyFile, "gif");
|
||||||
|
|
||||||
// Thread cleanup...
|
// Thread cleanup...
|
||||||
ImageUtils.BlockingFileDelete(teeyFile);
|
ImageUtils.blockingFileDelete(teeyFile);
|
||||||
ImageUtils.BlockingFileDelete(teeyeeFile);
|
ImageUtils.blockingFileDelete(teeyeeFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class CommandWolfram extends Command
|
|||||||
{
|
{
|
||||||
File pic = new File(searcher.getWolfram(input.args));
|
File pic = new File(searcher.getWolfram(input.args));
|
||||||
res.sendFile(pic, "png");
|
res.sendFile(pic, "png");
|
||||||
ImageUtils.BlockingFileDelete(pic);
|
ImageUtils.blockingFileDelete(pic);
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class CommandYeet extends Command
|
|||||||
|
|
||||||
yeeteeFile = new File(yeeteeFilename);
|
yeeteeFile = new File(yeeteeFilename);
|
||||||
ImageOverlayBuilder builder = new ImageOverlayBuilder("assets/yeet/frames/", "yeet ", 24, 18);
|
ImageOverlayBuilder builder = new ImageOverlayBuilder("assets/yeet/frames/", "yeet ", 24, 18);
|
||||||
builder.Overlay(ImageIO.read(yeeteeFile), name);
|
builder.overlay(ImageIO.read(yeeteeFile), name);
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
@@ -65,7 +65,7 @@ public class CommandYeet extends Command
|
|||||||
res.sendFile(yeetFile, "gif");
|
res.sendFile(yeetFile, "gif");
|
||||||
|
|
||||||
// Thread cleanup...
|
// Thread cleanup...
|
||||||
ImageUtils.BlockingFileDelete(yeetFile);
|
ImageUtils.blockingFileDelete(yeetFile);
|
||||||
ImageUtils.BlockingFileDelete(yeeteeFile);
|
ImageUtils.blockingFileDelete(yeeteeFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class BaseKeyValueFile
|
|||||||
File f = new File(filename);
|
File f = new File(filename);
|
||||||
if(f.isFile() && f.canRead())
|
if(f.isFile() && f.canRead())
|
||||||
{
|
{
|
||||||
String content = FileUtils.ReadContent(f).trim();
|
String content = FileUtils.readContent(f).trim();
|
||||||
String[] lines = content.split("" + pairSeparator);
|
String[] lines = content.split("" + pairSeparator);
|
||||||
|
|
||||||
for(int i = 0; i < lines.length; ++i)
|
for(int i = 0; i < lines.length; ++i)
|
||||||
@@ -84,7 +84,7 @@ public class BaseKeyValueFile
|
|||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
GlobalLog.Error(LogFilter.Core, "Issue writing file " + filename + ": " + e.getMessage());
|
GlobalLog.error(LogFilter.Core, "Issue writing file " + filename + ": " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ public abstract class BaseLocFile
|
|||||||
protected TaggedPairStore stringStore;
|
protected TaggedPairStore stringStore;
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
private void log(String str) { GlobalLog.Log(LogFilter.Strings, str); }
|
private void log(String str) { GlobalLog.log(LogFilter.Strings, str); }
|
||||||
private void warn(String str) { GlobalLog.Warn(LogFilter.Strings, str); }
|
private void warn(String str) { GlobalLog.warn(LogFilter.Strings, str); }
|
||||||
private void error(String str) { GlobalLog.Error(LogFilter.Strings, str); }
|
private void error(String str) { GlobalLog.error(LogFilter.Strings, str); }
|
||||||
|
|
||||||
// File monitoring
|
// File monitoring
|
||||||
protected FileMonitor fileMonitor;
|
protected FileMonitor fileMonitor;
|
||||||
@@ -49,7 +49,7 @@ public abstract class BaseLocFile
|
|||||||
{
|
{
|
||||||
synchronized(stringStore)
|
synchronized(stringStore)
|
||||||
{
|
{
|
||||||
fileMonitor.Update(this::onFileChange);
|
fileMonitor.update(this::onFileChange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ public abstract class BaseLocFile
|
|||||||
String filename = path.getFileName().toString();
|
String filename = path.getFileName().toString();
|
||||||
if(filename.contains(".java"))
|
if(filename.contains(".java"))
|
||||||
{
|
{
|
||||||
String contents = FileUtils.ReadContent(path);
|
String contents = FileUtils.readContent(path);
|
||||||
String[] split = contents.split(functionName);
|
String[] split = contents.split(functionName);
|
||||||
|
|
||||||
// Identify all localizer function calls
|
// Identify all localizer function calls
|
||||||
@@ -203,7 +203,7 @@ public abstract class BaseLocFile
|
|||||||
public void scrapeAll()
|
public void scrapeAll()
|
||||||
{
|
{
|
||||||
ArrayList<LocInfo> localizeList = new ArrayList<LocInfo>();
|
ArrayList<LocInfo> localizeList = new ArrayList<LocInfo>();
|
||||||
FileUtils.AcquireAllFiles(KittySourceDirectory).forEach((path) -> tryStripSpecified(path, localizeList));
|
FileUtils.acquireAllFiles(KittySourceDirectory).forEach((path) -> tryStripSpecified(path, localizeList));
|
||||||
|
|
||||||
for(LocInfo toStub : localizeList)
|
for(LocInfo toStub : localizeList)
|
||||||
stringStore.addKeyValue(toStub.file, toStub.phrase, toStub.phrase);
|
stringStore.addKeyValue(toStub.file, toStub.phrase, toStub.phrase);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class CharacterManager
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GlobalLog.Error(LogFilter.Core, "Attempted to create a second CharacterManager singleton!");
|
GlobalLog.error(LogFilter.Core, "Attempted to create a second CharacterManager singleton!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public abstract class Command
|
|||||||
|
|
||||||
private void reject(KittyUser user, String reason)
|
private void reject(KittyUser user, String reason)
|
||||||
{
|
{
|
||||||
GlobalLog.Warn(LogFilter.Command, this.getClass().getSimpleName() + " from " + user.name + " rejected due to command's " + reason);
|
GlobalLog.warn(LogFilter.Command, this.getClass().getSimpleName() + " from " + user.name + " rejected due to command's " + reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine if we're exclusive enough for this command and
|
// Determine if we're exclusive enough for this command and
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class CommandEnabler extends BaseKeyValueFile
|
|||||||
super(name);
|
super(name);
|
||||||
|
|
||||||
// Create/Init variables
|
// Create/Init variables
|
||||||
GlobalLog.Log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName());
|
GlobalLog.log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName());
|
||||||
enabledMap = new HashMap<>();
|
enabledMap = new HashMap<>();
|
||||||
keyList = new ArrayList<>();
|
keyList = new ArrayList<>();
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ public class CommandEnabler extends BaseKeyValueFile
|
|||||||
|
|
||||||
if(enabledMap.putIfAbsent(command, defaultEnabledState) == null)
|
if(enabledMap.putIfAbsent(command, defaultEnabledState) == null)
|
||||||
{
|
{
|
||||||
GlobalLog.Log(LogFilter.Strings, "Identified new toggleable raw command: " + command);
|
GlobalLog.log(LogFilter.Strings, "Identified new toggleable raw command: " + command);
|
||||||
keyList.add(command);
|
keyList.add(command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,11 +59,11 @@ public class CommandManager
|
|||||||
|
|
||||||
if(old != null)
|
if(old != null)
|
||||||
{
|
{
|
||||||
GlobalLog.Warn(LogFilter.Core, "Writing over a command with the key " + key);
|
GlobalLog.warn(LogFilter.Core, "Writing over a command with the key " + key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalLog.Log(LogFilter.Core, "Command registered under key " + key);
|
GlobalLog.log(LogFilter.Core, "Command registered under key " + key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Registers a command under multiple names!
|
// Registers a command under multiple names!
|
||||||
@@ -91,7 +91,7 @@ public class CommandManager
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GlobalLog.Warn(LogFilter.Command, "User " + user.name + " tried to invoke command that doesn't exist: " + input.key);
|
GlobalLog.warn(LogFilter.Command, "User " + user.name + " tried to invoke command that doesn't exist: " + input.key);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,14 +38,14 @@ public class DatabaseDriverKeyValue
|
|||||||
public void ensureTableExists(String tableName, String keyName, String valueName)
|
public void ensureTableExists(String tableName, String keyName, String valueName)
|
||||||
{
|
{
|
||||||
// Require a global table if it doesn't exist already
|
// Require a global table if it doesn't exist already
|
||||||
driver.ExecuteStatement(JDBCStatementType.Create, "CREATE TABLE IF NOT EXISTS " + tableName + " (" + keyName + " text PRIMARY KEY, " + valueName + " text)", null);
|
driver.executeStatement(JDBCStatementType.Create, "CREATE TABLE IF NOT EXISTS " + tableName + " (" + keyName + " text PRIMARY KEY, " + valueName + " text)", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up and create a table in the database
|
// Set up and create a table in the database
|
||||||
public boolean connect()
|
public boolean connect()
|
||||||
{
|
{
|
||||||
driver = new JDBCDriverSQLite();
|
driver = new JDBCDriverSQLite();
|
||||||
if(driver.Connect() == false)
|
if(driver.connect() == false)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -59,7 +59,7 @@ public class DatabaseDriverKeyValue
|
|||||||
// The key will be created if it doesn't exist and the value specified will be stored.
|
// The key will be created if it doesn't exist and the value specified will be stored.
|
||||||
public void createSetKey(String key, String value)
|
public void createSetKey(String key, String value)
|
||||||
{
|
{
|
||||||
GlobalLog.Log(LogFilter.Database, "CreateSetKey: Key-" + key + " value-" + value);
|
GlobalLog.log(LogFilter.Database, "CreateSetKey: Key-" + key + " value-" + value);
|
||||||
|
|
||||||
if(hasKey(key))
|
if(hasKey(key))
|
||||||
{
|
{
|
||||||
@@ -74,7 +74,7 @@ public class DatabaseDriverKeyValue
|
|||||||
// Creates a key. The key will be created if it doesn't exist, and the default value returned.
|
// Creates a key. The key will be created if it doesn't exist, and the default value returned.
|
||||||
public String createGetKey(String key)
|
public String createGetKey(String key)
|
||||||
{
|
{
|
||||||
GlobalLog.Log(LogFilter.Database, "CreateGetKey: " + key);
|
GlobalLog.log(LogFilter.Database, "CreateGetKey: " + key);
|
||||||
|
|
||||||
if(hasKey(key))
|
if(hasKey(key))
|
||||||
{
|
{
|
||||||
@@ -92,15 +92,15 @@ public class DatabaseDriverKeyValue
|
|||||||
private void updateKey(String key, String value)
|
private void updateKey(String key, String value)
|
||||||
{
|
{
|
||||||
String command = "UPDATE " + tableName + " SET " + valueColumnName + " = ? WHERE " + keyColumnName + " = ?";
|
String command = "UPDATE " + tableName + " SET " + valueColumnName + " = ? WHERE " + keyColumnName + " = ?";
|
||||||
boolean status = driver.ExecuteStatement(JDBCStatementType.Update, command, new String[] { value, key });
|
boolean status = driver.executeStatement(JDBCStatementType.Update, command, new String[] { value, key });
|
||||||
GlobalLog.Log(LogFilter.Database, "UpdateKey status: " + status);
|
GlobalLog.log(LogFilter.Database, "UpdateKey status: " + status);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Protoype updating for seeing if a key exists
|
// Protoype updating for seeing if a key exists
|
||||||
private boolean hasKey(String key)
|
private boolean hasKey(String key)
|
||||||
{
|
{
|
||||||
String command = "SELECT COUNT(1) as count FROM " + tableName + " WHERE " + keyColumnName + " = ?";
|
String command = "SELECT COUNT(1) as count FROM " + tableName + " WHERE " + keyColumnName + " = ?";
|
||||||
ResultSet set = driver.ExecuteReturningStatement(JDBCStatementType.Select, command, new String[] { key });
|
ResultSet set = driver.executeReturningStatement(JDBCStatementType.Select, command, new String[] { key });
|
||||||
String out = resultAsString(set, "count");
|
String out = resultAsString(set, "count");
|
||||||
return out.charAt(0) == '1';
|
return out.charAt(0) == '1';
|
||||||
}
|
}
|
||||||
@@ -109,7 +109,7 @@ public class DatabaseDriverKeyValue
|
|||||||
private String getKey(String key)
|
private String getKey(String key)
|
||||||
{
|
{
|
||||||
String command = "SELECT " + valueColumnName + " as searchedKey FROM " + tableName +" WHERE " + keyColumnName + " = ?";
|
String command = "SELECT " + valueColumnName + " as searchedKey FROM " + tableName +" WHERE " + keyColumnName + " = ?";
|
||||||
ResultSet set = driver.ExecuteReturningStatement(JDBCStatementType.Select, command, new String[] { key });
|
ResultSet set = driver.executeReturningStatement(JDBCStatementType.Select, command, new String[] { key });
|
||||||
return resultAsString(set, "searchedKey");
|
return resultAsString(set, "searchedKey");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,15 +117,15 @@ public class DatabaseDriverKeyValue
|
|||||||
private void createKey(String key, String value)
|
private void createKey(String key, String value)
|
||||||
{
|
{
|
||||||
String command = "INSERT INTO " + tableName + " (GlobalKey, GlobalValue) VALUES (?, ?)";
|
String command = "INSERT INTO " + tableName + " (GlobalKey, GlobalValue) VALUES (?, ?)";
|
||||||
boolean status = driver.ExecuteStatement(JDBCStatementType.Insert, command, new String[] { key, value });
|
boolean status = driver.executeStatement(JDBCStatementType.Insert, command, new String[] { key, value });
|
||||||
GlobalLog.Log(LogFilter.Database, "CreateKey status: " + status);
|
GlobalLog.log(LogFilter.Database, "CreateKey status: " + status);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all keys containing a substring
|
// Get all keys containing a substring
|
||||||
public List<String> getKeysWith(String keySubstring)
|
public List<String> getKeysWith(String keySubstring)
|
||||||
{
|
{
|
||||||
String command = "SELECT * FROM " + tableName + " WHERE " + keyColumnName + " like ?";
|
String command = "SELECT * FROM " + tableName + " WHERE " + keyColumnName + " like ?";
|
||||||
ResultSet result = driver.ExecuteReturningStatement(JDBCStatementType.Select, command, new String[] { "%" + keySubstring + "%" });
|
ResultSet result = driver.executeReturningStatement(JDBCStatementType.Select, command, new String[] { "%" + keySubstring + "%" });
|
||||||
|
|
||||||
List<String> keys = new ArrayList<String>();
|
List<String> keys = new ArrayList<String>();
|
||||||
|
|
||||||
@@ -165,7 +165,7 @@ public class DatabaseDriverKeyValue
|
|||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
GlobalLog.Error(LogFilter.Database, e.toString());
|
GlobalLog.error(LogFilter.Database, e.toString());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class DatabaseManager
|
|||||||
// Constructor to enforce singleton.
|
// Constructor to enforce singleton.
|
||||||
public DatabaseManager()
|
public DatabaseManager()
|
||||||
{
|
{
|
||||||
GlobalLog.Log(LogFilter.Database, "Creating database manager");
|
GlobalLog.log(LogFilter.Database, "Creating database manager");
|
||||||
|
|
||||||
if(instance == null)
|
if(instance == null)
|
||||||
{
|
{
|
||||||
@@ -43,7 +43,7 @@ public class DatabaseManager
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GlobalLog.Error(LogFilter.Database, "Attempted to register a second DataBase manager!");
|
GlobalLog.error(LogFilter.Database, "Attempted to register a second DataBase manager!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,13 +59,13 @@ public class DatabaseManager
|
|||||||
// Connect data sets
|
// Connect data sets
|
||||||
if(globalDataDriver.connect() == false)
|
if(globalDataDriver.connect() == false)
|
||||||
{
|
{
|
||||||
GlobalLog.Error("Global database failed to connect. Without this DB, this bot can not run.");
|
GlobalLog.error("Global database failed to connect. Without this DB, this bot can not run.");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(characterDataDriver.connect() == false)
|
if(characterDataDriver.connect() == false)
|
||||||
{
|
{
|
||||||
GlobalLog.Error("Character database failed to connect. Without this DB, this bot can not run.");
|
GlobalLog.error("Character database failed to connect. Without this DB, this bot can not run.");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public class LocCommands extends BaseLocFile
|
|||||||
{
|
{
|
||||||
super(fileName, function);
|
super(fileName, function);
|
||||||
|
|
||||||
GlobalLog.Log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName());
|
GlobalLog.log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName());
|
||||||
|
|
||||||
if(instance == null)
|
if(instance == null)
|
||||||
{
|
{
|
||||||
@@ -33,7 +33,7 @@ public class LocCommands extends BaseLocFile
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GlobalLog.Error(LogFilter.Core, "You can't have two of the following: " + this.getClass().getSimpleName());
|
GlobalLog.error(LogFilter.Core, "You can't have two of the following: " + this.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class LocStrings extends BaseLocFile
|
|||||||
{
|
{
|
||||||
super(fileName, function);
|
super(fileName, function);
|
||||||
|
|
||||||
GlobalLog.Log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName());
|
GlobalLog.log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName());
|
||||||
|
|
||||||
if(instance == null)
|
if(instance == null)
|
||||||
{
|
{
|
||||||
@@ -32,7 +32,7 @@ public class LocStrings extends BaseLocFile
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GlobalLog.Error(LogFilter.Core, "You can't have two of the following: " + this.getClass().getSimpleName());
|
GlobalLog.error(LogFilter.Core, "You can't have two of the following: " + this.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ public class ObjectBuilderFactory
|
|||||||
}
|
}
|
||||||
catch(InterruptedException ie)
|
catch(InterruptedException ie)
|
||||||
{
|
{
|
||||||
GlobalLog.Error(LogFilter.Core, "Issue during object builder lazy initialization."
|
GlobalLog.error(LogFilter.Core, "Issue during object builder lazy initialization."
|
||||||
+ " The factory was not initialized, and kitty will not be able to continue functionally.");
|
+ " The factory was not initialized, and kitty will not be able to continue functionally.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class RPManager
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GlobalLog.Error(LogFilter.Core, "Attempted to create a second RP Manager!");
|
GlobalLog.error(LogFilter.Core, "Attempted to create a second RP Manager!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ public class Stats
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GlobalLog.Error(LogFilter.Core, "Attempted to create a second Stats singleton!");
|
GlobalLog.error(LogFilter.Core, "Attempted to create a second Stats singleton!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public class BenchmarkInput
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
raw = raw.trim();
|
raw = raw.trim();
|
||||||
int whitespacePos = StringUtils.FindFirstWhitespace(raw);
|
int whitespacePos = StringUtils.findFirstWhitespace(raw);
|
||||||
|
|
||||||
if(whitespacePos == -1)
|
if(whitespacePos == -1)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import utils.GlobalLog;
|
|||||||
//Logging shim
|
//Logging shim
|
||||||
public class BenchmarkLog
|
public class BenchmarkLog
|
||||||
{
|
{
|
||||||
public static void log(String str) { GlobalLog.Log("[Benchmark] " + str); }
|
public static void log(String str) { GlobalLog.log("[Benchmark] " + str); }
|
||||||
public static void warn(String str) { GlobalLog.Warn("[Benchmark] " + str); }
|
public static void warn(String str) { GlobalLog.warn("[Benchmark] " + str); }
|
||||||
public static void error(String str) { GlobalLog.Error(" [Benchmark] " + str); }
|
public static void error(String str) { GlobalLog.error(" [Benchmark] " + str); }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class BenchmarkManager
|
|||||||
|
|
||||||
rebuildLookup();
|
rebuildLookup();
|
||||||
|
|
||||||
BenchmarkLog.log("Took " + (Instant.now().toEpochMilli() - start) + " ms to load " + raw.size() + " entries from " + directoryMonitor.GetCurrentFiles().size() + " file" + (raw.size() > 1 ? "s" : ""));
|
BenchmarkLog.log("Took " + (Instant.now().toEpochMilli() - start) + " ms to load " + raw.size() + " entries from " + directoryMonitor.getCurrentFiles().size() + " file" + (raw.size() > 1 ? "s" : ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rebuilds the files being monitored
|
// Rebuilds the files being monitored
|
||||||
@@ -50,14 +50,14 @@ public class BenchmarkManager
|
|||||||
|
|
||||||
synchronized(directoryMonitor)
|
synchronized(directoryMonitor)
|
||||||
{
|
{
|
||||||
files = directoryMonitor.GetCurrentFiles();
|
files = directoryMonitor.getCurrentFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(files != null)
|
if(files != null)
|
||||||
{
|
{
|
||||||
for(MonitoredFile mf : files)
|
for(MonitoredFile mf : files)
|
||||||
{
|
{
|
||||||
String contents = FileUtils.ReadContent(mf.path);
|
String contents = FileUtils.readContent(mf.path);
|
||||||
String[] lines = contents.split(lineDelimiter);
|
String[] lines = contents.split(lineDelimiter);
|
||||||
|
|
||||||
for(int i = 1; i < lines.length; ++i)
|
for(int i = 1; i < lines.length; ++i)
|
||||||
@@ -169,7 +169,7 @@ public class BenchmarkManager
|
|||||||
public void update()
|
public void update()
|
||||||
{
|
{
|
||||||
needsUpdate = false;
|
needsUpdate = false;
|
||||||
directoryMonitor.Update(this::onRescan, this::onRescan, this::onRescan);
|
directoryMonitor.update(this::onRescan, this::onRescan, this::onRescan);
|
||||||
|
|
||||||
if(needsUpdate)
|
if(needsUpdate)
|
||||||
rebuildLookup();
|
rebuildLookup();
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import utils.LogFilter;
|
|||||||
|
|
||||||
public class PluginLog
|
public class PluginLog
|
||||||
{
|
{
|
||||||
public static void log(String s) { GlobalLog.Log(LogFilter.Plugin, s); }
|
public static void log(String s) { GlobalLog.log(LogFilter.Plugin, s); }
|
||||||
public static void warn(String s) { GlobalLog.Warn(LogFilter.Plugin, s); }
|
public static void warn(String s) { GlobalLog.warn(LogFilter.Plugin, s); }
|
||||||
public static void error(String s) { GlobalLog.Error(LogFilter.Plugin, s); }
|
public static void error(String s) { GlobalLog.error(LogFilter.Plugin, s); }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class RPGInput
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
raw = raw.trim();
|
raw = raw.trim();
|
||||||
int whitespacePos = StringUtils.FindFirstWhitespace(raw);
|
int whitespacePos = StringUtils.findFirstWhitespace(raw);
|
||||||
|
|
||||||
if(whitespacePos == -1)
|
if(whitespacePos == -1)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,6 +7,6 @@ public class RPGLog
|
|||||||
{
|
{
|
||||||
public static void log(String toWrite)
|
public static void log(String toWrite)
|
||||||
{
|
{
|
||||||
GlobalLog.Log(LogFilter.Command, "[RPG] " + toWrite);
|
GlobalLog.log(LogFilter.Command, "[RPG] " + toWrite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public class KittyTrackedLong extends DatabaseTrackedObject
|
|||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
tracked = 0;
|
tracked = 0;
|
||||||
GlobalLog.Error(LogFilter.Core, "Falling back to default of 0 due to failure to deserialize long with database ID " + identifier);
|
GlobalLog.error(LogFilter.Core, "Falling back to default of 0 due to failure to deserialize long with database ID " + identifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class KittyTrackedString extends DatabaseTrackedObject
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GlobalLog.Log(LogFilter.Database, "String had null or empty value with identifier: " + identifier);
|
GlobalLog.log(LogFilter.Database, "String had null or empty value with identifier: " + identifier);
|
||||||
string = "";
|
string = "";
|
||||||
markDirty();
|
markDirty();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ public class KittyUser extends DatabaseTrackedObject
|
|||||||
String[] strings = prepareFromString(string);
|
String[] strings = prepareFromString(string);
|
||||||
if(strings.length < 2)
|
if(strings.length < 2)
|
||||||
{
|
{
|
||||||
GlobalLog.Log(LogFilter.Database, "Upgrading user " + name + " to include 'role' in DB");
|
GlobalLog.log(LogFilter.Database, "Upgrading user " + name + " to include 'role' in DB");
|
||||||
|
|
||||||
// Mark ourselves dirty to re-write the role information stored in the user.
|
// Mark ourselves dirty to re-write the role information stored in the user.
|
||||||
// Just uses defaults from earlier again.
|
// Just uses defaults from earlier again.
|
||||||
@@ -101,7 +101,7 @@ public class KittyUser extends DatabaseTrackedObject
|
|||||||
}
|
}
|
||||||
catch (NumberFormatException e)
|
catch (NumberFormatException e)
|
||||||
{
|
{
|
||||||
GlobalLog.Warn(LogFilter.Database, "Invalid user data for user " + name + "! "
|
GlobalLog.warn(LogFilter.Database, "Invalid user data for user " + name + "! "
|
||||||
+ "Starting over at 0 beans with a general role!");
|
+ "Starting over at 0 beans with a general role!");
|
||||||
|
|
||||||
// We don't need to specify the role at this point because it is set at this point.
|
// We don't need to specify the role at this point because it is set at this point.
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ public class Response
|
|||||||
// Queues a standard text-based message response to the channel that issued the command.
|
// Queues a standard text-based message response to the channel that issued the command.
|
||||||
public void send(String toRespondWith)
|
public void send(String toRespondWith)
|
||||||
{
|
{
|
||||||
GlobalLog.Log(LogFilter.Response, "Sending response: " + toRespondWith);
|
GlobalLog.log(LogFilter.Response, "Sending response: " + toRespondWith);
|
||||||
if(toRespondWith.length() > discordMessageMax)
|
if(toRespondWith.length() > discordMessageMax)
|
||||||
{
|
{
|
||||||
event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!").queue();
|
event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!").queue();
|
||||||
@@ -119,7 +119,7 @@ public class Response
|
|||||||
// Immediately dispatches the message to the channel that issued the command.
|
// Immediately dispatches the message to the channel that issued the command.
|
||||||
public void sendImmediate(String toRespondWith)
|
public void sendImmediate(String toRespondWith)
|
||||||
{
|
{
|
||||||
GlobalLog.Log(LogFilter.Response, "Sending immediate response: " + toRespondWith);
|
GlobalLog.log(LogFilter.Response, "Sending immediate response: " + toRespondWith);
|
||||||
if(toRespondWith.length() > discordMessageMax)
|
if(toRespondWith.length() > discordMessageMax)
|
||||||
{
|
{
|
||||||
event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!");
|
event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!");
|
||||||
@@ -133,14 +133,14 @@ public class Response
|
|||||||
// Queues a file response to the channel that issued the command.
|
// Queues a file response to the channel that issued the command.
|
||||||
public void sendFile(File toRespondWith, String extension)
|
public void sendFile(File toRespondWith, String extension)
|
||||||
{
|
{
|
||||||
GlobalLog.Log(LogFilter.Response, "Sending file response");
|
GlobalLog.log(LogFilter.Response, "Sending file response");
|
||||||
event.getChannel().sendFile(toRespondWith, "return." + extension).queue();
|
event.getChannel().sendFile(toRespondWith, "return." + extension).queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Queues an input stream response to the channel that issued the command.
|
// Queues an input stream response to the channel that issued the command.
|
||||||
public void sendFile(InputStream in, String extension)
|
public void sendFile(InputStream in, String extension)
|
||||||
{
|
{
|
||||||
GlobalLog.Log(LogFilter.Response, "Sending input stream response");
|
GlobalLog.log(LogFilter.Response, "Sending input stream response");
|
||||||
event.getChannel().sendFile(in, "return." + extension).queue();
|
event.getChannel().sendFile(in, "return." + extension).queue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,8 +93,8 @@ public class TaggedPairStore
|
|||||||
Map.Entry internalPair = (Map.Entry)internal.next();
|
Map.Entry internalPair = (Map.Entry)internal.next();
|
||||||
String key = (String)internalPair.getKey();
|
String key = (String)internalPair.getKey();
|
||||||
String value = (String)internalPair.getValue();
|
String value = (String)internalPair.getValue();
|
||||||
key = StringUtils.ReEscape(key);
|
key = StringUtils.reEscape(key);
|
||||||
value = StringUtils.ReEscape(value);
|
value = StringUtils.reEscape(value);
|
||||||
|
|
||||||
if(key.endsWith("\\r"))
|
if(key.endsWith("\\r"))
|
||||||
{
|
{
|
||||||
@@ -160,8 +160,8 @@ public class TaggedPairStore
|
|||||||
|
|
||||||
String key = line.substring(0, splitPos);
|
String key = line.substring(0, splitPos);
|
||||||
String value = line.substring(splitPos + PairSplit.length());
|
String value = line.substring(splitPos + PairSplit.length());
|
||||||
key = StringUtils.UnEscape(key);
|
key = StringUtils.unEscape(key);
|
||||||
value = StringUtils.UnEscape(value);
|
value = StringUtils.unEscape(value);
|
||||||
|
|
||||||
taggedPairs.get(sectionName).putIfAbsent(key, value);
|
taggedPairs.get(sectionName).putIfAbsent(key, value);
|
||||||
allPairs.putIfAbsent(key, value);
|
allPairs.putIfAbsent(key, value);
|
||||||
|
|||||||
@@ -7,14 +7,14 @@ import java.sql.ResultSet;
|
|||||||
public abstract class JDBCDriver
|
public abstract class JDBCDriver
|
||||||
{
|
{
|
||||||
// Connects to the database, returns a bool if it succeeded.
|
// Connects to the database, returns a bool if it succeeded.
|
||||||
public abstract boolean Connect();
|
public abstract boolean connect();
|
||||||
|
|
||||||
// Disconnects the driver. Returns if the driver is disconnected now, regardless of connection status.
|
// Disconnects the driver. Returns if the driver is disconnected now, regardless of connection status.
|
||||||
public abstract boolean Disconnect();
|
public abstract boolean disconnect();
|
||||||
|
|
||||||
// Executes a SQL command with the database. Returns if it was executed successfully, or in the
|
// Executes a SQL command with the database. Returns if it was executed successfully, or in the
|
||||||
// case of the returning statement, returns the ResultSet. Args are placed into the prepared statement
|
// case of the returning statement, returns the ResultSet. Args are placed into the prepared statement
|
||||||
// in place of each '?' places into it.
|
// in place of each '?' places into it.
|
||||||
public abstract boolean ExecuteStatement(JDBCStatementType type, String command, String[] args);
|
public abstract boolean executeStatement(JDBCStatementType type, String command, String[] args);
|
||||||
public abstract ResultSet ExecuteReturningStatement(JDBCStatementType type, String command, String[] args);
|
public abstract ResultSet executeReturningStatement(JDBCStatementType type, String command, String[] args);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,25 +5,25 @@ import java.sql.ResultSet;
|
|||||||
public class JDBCDriverMySQL extends JDBCDriver
|
public class JDBCDriverMySQL extends JDBCDriver
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean Connect() {
|
public boolean connect() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean Disconnect() {
|
public boolean disconnect() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean ExecuteStatement(JDBCStatementType type, String statement, String[] args) {
|
public boolean executeStatement(JDBCStatementType type, String statement, String[] args) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultSet ExecuteReturningStatement(JDBCStatementType type, String statement, String[] args) {
|
public ResultSet executeReturningStatement(JDBCStatementType type, String statement, String[] args) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,25 +5,25 @@ import java.sql.ResultSet;
|
|||||||
public class JDBCDriverPostgreSQL extends JDBCDriver
|
public class JDBCDriverPostgreSQL extends JDBCDriver
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean Connect() {
|
public boolean connect() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean Disconnect() {
|
public boolean disconnect() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean ExecuteStatement(JDBCStatementType type, String statement, String[] args) {
|
public boolean executeStatement(JDBCStatementType type, String statement, String[] args) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultSet ExecuteReturningStatement(JDBCStatementType type, String statement, String[] args) {
|
public ResultSet executeReturningStatement(JDBCStatementType type, String statement, String[] args) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class JDBCDriverSQLite extends JDBCDriver
|
|||||||
public static final String databaseName = "catfood";
|
public static final String databaseName = "catfood";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean Connect()
|
public boolean connect()
|
||||||
{
|
{
|
||||||
if(connection == null)
|
if(connection == null)
|
||||||
{
|
{
|
||||||
@@ -38,23 +38,23 @@ public class JDBCDriverSQLite extends JDBCDriver
|
|||||||
// create a connection to the database
|
// create a connection to the database
|
||||||
connection = DriverManager.getConnection(url);
|
connection = DriverManager.getConnection(url);
|
||||||
|
|
||||||
GlobalLog.Log(LogFilter.Database, "Connection to SQLite has been established.");
|
GlobalLog.log(LogFilter.Database, "Connection to SQLite has been established.");
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
GlobalLog.Error(e.getMessage());
|
GlobalLog.error(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GlobalLog.Log(LogFilter.Database, "SQLite database asked to connect a second time. This is perfectly fine as this app has all its data tied together.");
|
GlobalLog.log(LogFilter.Database, "SQLite database asked to connect a second time. This is perfectly fine as this app has all its data tied together.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return connection != null;
|
return connection != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean Disconnect()
|
public boolean disconnect()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -67,13 +67,13 @@ public class JDBCDriverSQLite extends JDBCDriver
|
|||||||
}
|
}
|
||||||
catch (SQLException ex)
|
catch (SQLException ex)
|
||||||
{
|
{
|
||||||
GlobalLog.Error(ex.getMessage());
|
GlobalLog.error(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultSet ExecuteReturningStatement(JDBCStatementType type, String command, String[] args)
|
public ResultSet executeReturningStatement(JDBCStatementType type, String command, String[] args)
|
||||||
{
|
{
|
||||||
if(connection == null)
|
if(connection == null)
|
||||||
return null;
|
return null;
|
||||||
@@ -114,7 +114,7 @@ public class JDBCDriverSQLite extends JDBCDriver
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GlobalLog.Fatal(e.getMessage());
|
GlobalLog.fatal(e.getMessage());
|
||||||
}
|
}
|
||||||
catch (Exception e1)
|
catch (Exception e1)
|
||||||
{
|
{
|
||||||
@@ -125,7 +125,7 @@ public class JDBCDriverSQLite extends JDBCDriver
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean ExecuteStatement(JDBCStatementType type, String command, String[] args)
|
public boolean executeStatement(JDBCStatementType type, String command, String[] args)
|
||||||
{
|
{
|
||||||
if(connection == null)
|
if(connection == null)
|
||||||
return false;
|
return false;
|
||||||
@@ -178,7 +178,7 @@ public class JDBCDriverSQLite extends JDBCDriver
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GlobalLog.Fatal(e.getMessage());
|
GlobalLog.fatal(e.getMessage());
|
||||||
}
|
}
|
||||||
catch (Exception e1)
|
catch (Exception e1)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import utils.HTTPUtils;
|
|||||||
|
|
||||||
public class NetworkColiru
|
public class NetworkColiru
|
||||||
{
|
{
|
||||||
public String compileCPlus(String query)
|
public String compileCPlusPlus(String query)
|
||||||
{
|
{
|
||||||
// Escape characters that need escaping.
|
// Escape characters that need escaping.
|
||||||
// Primarily types of whitespace.
|
// Primarily types of whitespace.
|
||||||
@@ -15,7 +15,7 @@ public class NetworkColiru
|
|||||||
query = query.replace("\t", "\\t");
|
query = query.replace("\t", "\\t");
|
||||||
|
|
||||||
// Send the compilation request!
|
// Send the compilation request!
|
||||||
String result = HTTPUtils.SendPOSTRequest("http://coliru.stacked-crooked.com/compile"
|
String result = HTTPUtils.sendPOSTRequest("http://coliru.stacked-crooked.com/compile"
|
||||||
, "{ \"cmd\": \"g++ main.cpp && ./a.out\", \"src\": \"" + query + "\" }");
|
, "{ \"cmd\": \"g++ main.cpp && ./a.out\", \"src\": \"" + query + "\" }");
|
||||||
|
|
||||||
// If we got a valid response...
|
// If we got a valid response...
|
||||||
@@ -23,6 +23,7 @@ public class NetworkColiru
|
|||||||
{
|
{
|
||||||
result = "Here's what happened when I went to compiled that! \n```" + result + "```";
|
result = "Here's what happened when I went to compiled that! \n```" + result + "```";
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class NetworkDerpi
|
|||||||
GenericImage image = new GenericImage(" ", " ", " ");
|
GenericImage image = new GenericImage(" ", " ", " ");
|
||||||
query = query.trim();
|
query = query.trim();
|
||||||
query = query.replace(" ", ",");
|
query = query.replace(" ", ",");
|
||||||
String res = HTTPUtils.SendGETRequest(mainURL + query + "&random_image=1&key=" + Ref.derpiKey);
|
String res = HTTPUtils.sendGETRequest(mainURL + query + "&random_image=1&key=" + Ref.derpiKey);
|
||||||
if(res != null)
|
if(res != null)
|
||||||
{
|
{
|
||||||
// Use class evaluation on an array of the response object to be able to hold multiple.
|
// Use class evaluation on an array of the response object to be able to hold multiple.
|
||||||
@@ -34,7 +34,7 @@ public class NetworkDerpi
|
|||||||
if(res != null)
|
if(res != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
String res2 = HTTPUtils.SendGETRequest("https://derpibooru.org/" + obj.id + ".json");
|
String res2 = HTTPUtils.sendGETRequest("https://derpibooru.org/" + obj.id + ".json");
|
||||||
image.editPostURL("<https://derpibooru.org/" + obj.id +">");
|
image.editPostURL("<https://derpibooru.org/" + obj.id +">");
|
||||||
DerpiResponseObject imageObj = jsonParser_.fromJson(res2, DerpiResponseObject.class);
|
DerpiResponseObject imageObj = jsonParser_.fromJson(res2, DerpiResponseObject.class);
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public class NetworkE621
|
|||||||
// Configure and send request. Note: Random ordering added as first
|
// Configure and send request. Note: Random ordering added as first
|
||||||
// tag by default. User-provided tags, therefore, will override it.
|
// tag by default. User-provided tags, therefore, will override it.
|
||||||
// If order:score is provided, that will be honored over order:random.
|
// If order:score is provided, that will be honored over order:random.
|
||||||
String res = HTTPUtils.SendPOSTRequest(API_ROOT
|
String res = HTTPUtils.sendPOSTRequest(API_ROOT
|
||||||
, "tags=order:random%20" + input + "&limit=" + maxSearchResults_);
|
, "tags=order:random%20" + input + "&limit=" + maxSearchResults_);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ public class NetworkJDoodle
|
|||||||
String input = "{\"clientId\": \"" + Ref.jdoodleID + "\",\"clientSecret\":\"" + Ref.jdoodleSecret + "\",\"script\":\"" + query +
|
String input = "{\"clientId\": \"" + Ref.jdoodleID + "\",\"clientSecret\":\"" + Ref.jdoodleSecret + "\",\"script\":\"" + query +
|
||||||
"\",\"language\":\"" + lang + "\",\"versionIndex\":\"" + version + "\"} ";
|
"\",\"language\":\"" + lang + "\",\"versionIndex\":\"" + version + "\"} ";
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
URL url = new URL("https://api.jdoodle.com/v1/execute");
|
URL url = new URL("https://api.jdoodle.com/v1/execute");
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
@@ -69,10 +70,12 @@ public class NetworkJDoodle
|
|||||||
result += "The CPU time was " + doodle.cpuTime + "\n";
|
result += "The CPU time was " + doodle.cpuTime + "\n";
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
return result;
|
return result;
|
||||||
} catch (MalformedURLException e)
|
}
|
||||||
|
catch (MalformedURLException e)
|
||||||
{
|
{
|
||||||
return "You probably shouldn't be seeing this";
|
return "You probably shouldn't be seeing this";
|
||||||
} catch (IOException e)
|
}
|
||||||
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
return "You probably shouldn't be seeing this";
|
return "You probably shouldn't be seeing this";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,12 +71,12 @@ public class NetworkTheColorAPI
|
|||||||
public tca_XYZ XYZ;
|
public tca_XYZ XYZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColorData LookupHex(String hex)
|
public ColorData lookupHex(String hex)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
hex = hex.replace("#", "");
|
hex = hex.replace("#", "");
|
||||||
String response = HTTPUtils.SendGETRequest("https://www.thecolorapi.com/id?hex=" + hex);
|
String response = HTTPUtils.sendGETRequest("https://www.thecolorapi.com/id?hex=" + hex);
|
||||||
|
|
||||||
ColorData data = jsonParser.fromJson(response, ColorData.class);
|
ColorData data = jsonParser.fromJson(response, ColorData.class);
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ public class NetworkTwitter
|
|||||||
.setOAuthConsumerSecret(Ref.twitterAPISecret)
|
.setOAuthConsumerSecret(Ref.twitterAPISecret)
|
||||||
.setOAuthAccessToken(Ref.twitterAccessToken)
|
.setOAuthAccessToken(Ref.twitterAccessToken)
|
||||||
.setOAuthAccessTokenSecret(Ref.twitterAccessTokenSecret);
|
.setOAuthAccessTokenSecret(Ref.twitterAccessTokenSecret);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String tweet(String tweetText) throws Exception
|
public String tweet(String tweetText) throws Exception
|
||||||
@@ -28,6 +26,5 @@ public class NetworkTwitter
|
|||||||
Twitter twitter = tf.getInstance();
|
Twitter twitter = tf.getInstance();
|
||||||
Status status = twitter.updateStatus(tweetText);
|
Status status = twitter.updateStatus(tweetText);
|
||||||
return "Status set to: `" + status.getText() + "`!";
|
return "Status set to: `" + status.getText() + "`!";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-11
@@ -23,12 +23,12 @@ public class GlobalLog
|
|||||||
DateFormat dF = new SimpleDateFormat("yyyy_MM_dd_HH-mm");
|
DateFormat dF = new SimpleDateFormat("yyyy_MM_dd_HH-mm");
|
||||||
Date today = new Date();
|
Date today = new Date();
|
||||||
|
|
||||||
FileUtils.CreateDirectoryIfDoesntExist(directory);
|
FileUtils.createDirectoryIfDoesntExist(directory);
|
||||||
outputLog = new PrintWriter(directory + (dF.format(today) + ".log"), "UTF-8");
|
outputLog = new PrintWriter(directory + (dF.format(today) + ".log"), "UTF-8");
|
||||||
GlobalLog.Log(LogFilter.Util, "Finished initializing logging system");
|
GlobalLog.log(LogFilter.Util, "Finished initializing logging system");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Write(String status, LogFilter filter, String body)
|
private static void write(String status, LogFilter filter, String body)
|
||||||
{
|
{
|
||||||
String logLine = "[" + status + "] " + "[" + filter.name() + "] " + body;
|
String logLine = "[" + status + "] " + "[" + filter.name() + "] " + body;
|
||||||
outputLog.write(logLine + "\n");
|
outputLog.write(logLine + "\n");
|
||||||
@@ -36,13 +36,13 @@ public class GlobalLog
|
|||||||
System.out.println(logLine);
|
System.out.println(logLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Log(String msg) { Write(log, LogFilter.Debug, msg); }
|
public static void log(String msg) { write(log, LogFilter.Debug, msg); }
|
||||||
public static void Warn(String msg) { Write(warn, LogFilter.Debug, msg); }
|
public static void warn(String msg) { write(warn, LogFilter.Debug, msg); }
|
||||||
public static void Error(String msg) { Write(error, LogFilter.Debug, msg); }
|
public static void error(String msg) { write(error, LogFilter.Debug, msg); }
|
||||||
public static void Fatal(String msg) throws Exception { Write(fatal, LogFilter.Debug, msg); throw new Exception(msg); }
|
public static void fatal(String msg) throws Exception { write(fatal, LogFilter.Debug, msg); throw new Exception(msg); }
|
||||||
|
|
||||||
public static void Log(LogFilter filter, String msg) { Write(log, filter, msg); }
|
public static void log(LogFilter filter, String msg) { write(log, filter, msg); }
|
||||||
public static void Warn(LogFilter filter, String msg) { Write(warn, filter, msg); }
|
public static void warn(LogFilter filter, String msg) { write(warn, filter, msg); }
|
||||||
public static void Error(LogFilter filter, String msg) { Write(error, filter, msg); }
|
public static void error(LogFilter filter, String msg) { write(error, filter, msg); }
|
||||||
public static void Fatal(LogFilter filter, String msg) throws Exception { Write(fatal, filter, msg); throw new Exception(msg); }
|
public static void fatal(LogFilter filter, String msg) throws Exception { write(fatal, filter, msg); throw new Exception(msg); }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class HTTPUtils
|
|||||||
|
|
||||||
|
|
||||||
// Sends a GET request for the specified URL.
|
// Sends a GET request for the specified URL.
|
||||||
public static String SendGETRequest(String url)
|
public static String sendGETRequest(String url)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -45,8 +45,8 @@ public class HTTPUtils
|
|||||||
|
|
||||||
// Sends a POST request to the desired URL.
|
// Sends a POST request to the desired URL.
|
||||||
// There are two forms of this function, one of which takes
|
// There are two forms of this function, one of which takes
|
||||||
public static String SendPOSTRequest(String url) { return SendPOSTRequest(url, ""); }
|
public static String sendPOSTRequest(String url) { return sendPOSTRequest(url, ""); }
|
||||||
public static String SendPOSTRequest(String url, String params)
|
public static String sendPOSTRequest(String url, String params)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -103,8 +103,10 @@ public class HTTPUtils
|
|||||||
// Close and return our data
|
// Close and return our data
|
||||||
in.close();
|
in.close();
|
||||||
return new String(String.toString());
|
return new String(String.toString());
|
||||||
} else {
|
}
|
||||||
GlobalLog.Error(LogFilter.Network, con.getRequestMethod() + " responded with " + responseCode + " instead of 200.");
|
else
|
||||||
|
{
|
||||||
|
GlobalLog.error(LogFilter.Network, con.getRequestMethod() + " responded with " + responseCode + " instead of 200.");
|
||||||
return Integer.toString(responseCode);
|
return Integer.toString(responseCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,10 +34,10 @@ public class ImageOverlayBuilder
|
|||||||
public static final String LOG_HEADER = "[Overlay] ";
|
public static final String LOG_HEADER = "[Overlay] ";
|
||||||
|
|
||||||
// Logging intermediate functions
|
// Logging intermediate functions
|
||||||
private static void Verbose(String str) { if(VERBOSE) Log("[Verbose] " + str); }
|
private static void verbose(String str) { if(VERBOSE) log("[Verbose] " + str); }
|
||||||
private static void Log(String str) { GlobalLog.Log(LogFilter.Util, LOG_HEADER + str); }
|
private static void log(String str) { GlobalLog.log(LogFilter.Util, LOG_HEADER + str); }
|
||||||
private static void Warn(String str) { GlobalLog.Warn(LogFilter.Util, LOG_HEADER + str); }
|
private static void warn(String str) { GlobalLog.warn(LogFilter.Util, LOG_HEADER + str); }
|
||||||
private static void Error(String str) { GlobalLog.Error(LogFilter.Util, LOG_HEADER + str); }
|
private static void error(String str) { GlobalLog.error(LogFilter.Util, LOG_HEADER + str); }
|
||||||
|
|
||||||
// Local variables
|
// Local variables
|
||||||
private final String basePath; // The folder location of the files
|
private final String basePath; // The folder location of the files
|
||||||
@@ -61,46 +61,46 @@ public class ImageOverlayBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Performs a per-frame overlay, catches IO errors as a note.)
|
// Performs a per-frame overlay, catches IO errors as a note.)
|
||||||
public void Overlay(BufferedImage overlay, String outpath)
|
public void overlay(BufferedImage overlay, String outpath)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
long start = Calendar.getInstance().getTimeInMillis();
|
long start = Calendar.getInstance().getTimeInMillis();
|
||||||
|
|
||||||
ProcessOverlay(overlay, outpath);
|
processOverlay(overlay, outpath);
|
||||||
|
|
||||||
long end = Calendar.getInstance().getTimeInMillis();
|
long end = Calendar.getInstance().getTimeInMillis();
|
||||||
Log("Took " + (end - start) + "ms");
|
log("Took " + (end - start) + "ms");
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
Error(e.getMessage());
|
error(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Processing the image frames to construct a gif. Relies on (0,255,0) pixel for image center specification.
|
// Processing the image frames to construct a gif. Relies on (0,255,0) pixel for image center specification.
|
||||||
private void ProcessOverlay(BufferedImage overlay, String outfileName) throws IOException
|
private void processOverlay(BufferedImage overlay, String outfileName) throws IOException
|
||||||
{
|
{
|
||||||
ArrayList<BufferedImage> frames = new ArrayList<BufferedImage>(frameCount);
|
ArrayList<BufferedImage> frames = new ArrayList<BufferedImage>(frameCount);
|
||||||
//BufferedImage[] frames = new BufferedImage[frameCount];
|
//BufferedImage[] frames = new BufferedImage[frameCount];
|
||||||
|
|
||||||
for(int i = 0; i < frameCount; ++i)
|
for(int i = 0; i < frameCount; ++i)
|
||||||
{
|
{
|
||||||
BufferedImage out = CombineImages(basePath + baseName + i + FRAME_FILE_EXTENSION , overlay);
|
BufferedImage out = combineImages(basePath + baseName + i + FRAME_FILE_EXTENSION , overlay);
|
||||||
|
|
||||||
if(out != null)
|
if(out != null)
|
||||||
frames.add(out);// = out;
|
frames.add(out);// = out;
|
||||||
else
|
else
|
||||||
Warn("Skipping frame " + i + " of base " + basePath + baseName);
|
warn("Skipping frame " + i + " of base " + basePath + baseName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(frames.isEmpty())
|
if(frames.isEmpty())
|
||||||
{
|
{
|
||||||
Error("No frames were found at all, so the gif could not be made!");
|
error("No frames were found at all, so the gif could not be made!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Verbose("Processed " + frameCount + " frames, found " + frames.size() + " valid, writing...");
|
verbose("Processed " + frameCount + " frames, found " + frames.size() + " valid, writing...");
|
||||||
ImageOutputStream output = new FileImageOutputStream(new File(outfileName));
|
ImageOutputStream output = new FileImageOutputStream(new File(outfileName));
|
||||||
GifSequenceWriter writer = new GifSequenceWriter(output, frames.get(0).getType(), fps, true);
|
GifSequenceWriter writer = new GifSequenceWriter(output, frames.get(0).getType(), fps, true);
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ public class ImageOverlayBuilder
|
|||||||
// Performs an overlay at a pixel location. We're making some assumptions here, mostly that there is going
|
// Performs an overlay at a pixel location. We're making some assumptions here, mostly that there is going
|
||||||
// to be an RGBA-32-bit encoded PNG image read in for our parsing purposes. We then look for a 0, 255, 0
|
// to be an RGBA-32-bit encoded PNG image read in for our parsing purposes. We then look for a 0, 255, 0
|
||||||
// green pixel on the base frame to apply the overlay buffer to, centered.
|
// green pixel on the base frame to apply the overlay buffer to, centered.
|
||||||
private BufferedImage CombineImages(String pathBase, BufferedImage overlay) throws IOException
|
private BufferedImage combineImages(String pathBase, BufferedImage overlay) throws IOException
|
||||||
{
|
{
|
||||||
// Acquire images
|
// Acquire images
|
||||||
BufferedImage imageBase = null;
|
BufferedImage imageBase = null;
|
||||||
@@ -137,7 +137,7 @@ public class ImageOverlayBuilder
|
|||||||
|
|
||||||
// Warn about odd sizing when applicable
|
// Warn about odd sizing when applicable
|
||||||
if(overlayHeight > baseHeight || overlayWidth > baseWidth)
|
if(overlayHeight > baseHeight || overlayWidth > baseWidth)
|
||||||
Warn("Size mismatch, overlay is larger. May function, but not supported.");
|
warn("Size mismatch, overlay is larger. May function, but not supported.");
|
||||||
|
|
||||||
// Skim base picture for solid green pixel to use as target center
|
// Skim base picture for solid green pixel to use as target center
|
||||||
int targetX = NONE;
|
int targetX = NONE;
|
||||||
@@ -165,7 +165,7 @@ public class ImageOverlayBuilder
|
|||||||
// Skip overlay if we have no target location
|
// Skip overlay if we have no target location
|
||||||
if(targetX == NONE || targetY == NONE)
|
if(targetX == NONE || targetY == NONE)
|
||||||
{
|
{
|
||||||
Verbose("No overlay required for this frame.");
|
verbose("No overlay required for this frame.");
|
||||||
return imageBase;
|
return imageBase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class ImageUtils
|
|||||||
boolean didWrite = ImageIO.write(data, extension, outputfile);
|
boolean didWrite = ImageIO.write(data, extension, outputfile);
|
||||||
if(!didWrite)
|
if(!didWrite)
|
||||||
{
|
{
|
||||||
GlobalLog.Error(LogFilter.Util, "Could not identify the writer for extension type '" + extension + "' - Did you accidentally include a period or other punctuation?");
|
GlobalLog.error(LogFilter.Util, "Could not identify the writer for extension type '" + extension + "' - Did you accidentally include a period or other punctuation?");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ public class ImageUtils
|
|||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
GlobalLog.Error(LogFilter.Util, "Exception in writeTempImageData: " + e.toString());
|
GlobalLog.error(LogFilter.Util, "Exception in writeTempImageData: " + e.toString());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,14 +90,14 @@ public class ImageUtils
|
|||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
GlobalLog.Error(LogFilter.Util, "Exception in downloadFromURL: " + e.toString());
|
GlobalLog.error(LogFilter.Util, "Exception in downloadFromURL: " + e.toString());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deletes the file provided, if it exists. Will continue, in a blocking way,
|
// Deletes the file provided, if it exists. Will continue, in a blocking way,
|
||||||
// to attempt to delete the file 10 times a second until thread termination.
|
// to attempt to delete the file 10 times a second until thread termination.
|
||||||
public static void BlockingFileDelete(File file)
|
public static void blockingFileDelete(File file)
|
||||||
{
|
{
|
||||||
if(file == null)
|
if(file == null)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -40,10 +40,10 @@ public class OptionParser
|
|||||||
floating = new ArrayList<String>();
|
floating = new ArrayList<String>();
|
||||||
|
|
||||||
if(toParse != null && toParse.length() > 0)
|
if(toParse != null && toParse.length() > 0)
|
||||||
Parse(toParse);
|
parse(toParse);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Parse(String vals)
|
public void parse(String vals)
|
||||||
{
|
{
|
||||||
String[] strings = vals.split("\\s+");
|
String[] strings = vals.split("\\s+");
|
||||||
|
|
||||||
@@ -84,17 +84,17 @@ public class OptionParser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> GetFloating()
|
public ArrayList<String> getFloating()
|
||||||
{
|
{
|
||||||
return floating;
|
return floating;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String GetOption(String arg)
|
public String getOption(String arg)
|
||||||
{
|
{
|
||||||
return GetOption(arg, false);
|
return getOption(arg, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String GetOption(String option, boolean isCaseInsensitive)
|
public String getOption(String option, boolean isCaseInsensitive)
|
||||||
{
|
{
|
||||||
if(option == null)
|
if(option == null)
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package utils;
|
|||||||
|
|
||||||
public class StringUtils
|
public class StringUtils
|
||||||
{
|
{
|
||||||
public static String UnEscape(String str)
|
public static String unEscape(String str)
|
||||||
{
|
{
|
||||||
str = str.replaceAll("\\\\b", "\b");
|
str = str.replaceAll("\\\\b", "\b");
|
||||||
str = str.replaceAll("\\\\n", "\n");
|
str = str.replaceAll("\\\\n", "\n");
|
||||||
@@ -15,7 +15,7 @@ public class StringUtils
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String ReEscape(String str)
|
public static String reEscape(String str)
|
||||||
{
|
{
|
||||||
str = str.replaceAll("\\\b", "\\\\\\b");
|
str = str.replaceAll("\\\b", "\\\\\\b");
|
||||||
str = str.replaceAll("\\\n", "\\\\\\n");
|
str = str.replaceAll("\\\n", "\\\\\\n");
|
||||||
@@ -27,7 +27,7 @@ public class StringUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Finds first whitespace in the string
|
// Finds first whitespace in the string
|
||||||
public static int FindFirstWhitespace(String str)
|
public static int findFirstWhitespace(String str)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < str.length(); ++i)
|
for (int i = 0; i < str.length(); ++i)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,16 +20,16 @@ public class DirectoryMonitor
|
|||||||
// Constructs a new file monitor and logs initialization
|
// Constructs a new file monitor and logs initialization
|
||||||
public DirectoryMonitor(String directory)
|
public DirectoryMonitor(String directory)
|
||||||
{
|
{
|
||||||
IOLog.Log("Reading directory files for montioring in: " + directory.toString());
|
IOLog.log("Reading directory files for montioring in: " + directory.toString());
|
||||||
|
|
||||||
this.directory = directory;
|
this.directory = directory;
|
||||||
this.last = Scrape();
|
this.last = scrape();
|
||||||
|
|
||||||
Print(last);
|
print(last);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scrape the target directory for all files and store them as custom objects in the list
|
// Scrape the target directory for all files and store them as custom objects in the list
|
||||||
private ArrayList<MonitoredFile> Scrape()
|
private ArrayList<MonitoredFile> scrape()
|
||||||
{
|
{
|
||||||
ArrayList<MonitoredFile> files = new ArrayList<MonitoredFile>();
|
ArrayList<MonitoredFile> files = new ArrayList<MonitoredFile>();
|
||||||
|
|
||||||
@@ -39,13 +39,13 @@ public class DirectoryMonitor
|
|||||||
{
|
{
|
||||||
paths.filter(Files::isRegularFile).forEach((path)->
|
paths.filter(Files::isRegularFile).forEach((path)->
|
||||||
{
|
{
|
||||||
files.add(new MonitoredFile(path, FileUtils.LastModified(path)));
|
files.add(new MonitoredFile(path, FileUtils.lastModified(path)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
IOLog.Error(e.getMessage());
|
IOLog.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return files;
|
return files;
|
||||||
@@ -54,10 +54,10 @@ public class DirectoryMonitor
|
|||||||
// Update function - the first callback is called if a new item is added to the directory,
|
// Update function - the first callback is called if a new item is added to the directory,
|
||||||
// second is called if an item is updated, and third is called if an item is removed.
|
// second is called if an item is updated, and third is called if an item is removed.
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void Update(Consumer<? super MonitoredFile> onAdd, Consumer<? super MonitoredFile> onUpdate, Consumer<? super MonitoredFile> onDelete)
|
public void update(Consumer<? super MonitoredFile> onAdd, Consumer<? super MonitoredFile> onUpdate, Consumer<? super MonitoredFile> onDelete)
|
||||||
{
|
{
|
||||||
// Unparsed
|
// Unparsed
|
||||||
ArrayList<MonitoredFile> active = Scrape();
|
ArrayList<MonitoredFile> active = scrape();
|
||||||
ArrayList<MonitoredFile> curr = (ArrayList<MonitoredFile>)active.clone();
|
ArrayList<MonitoredFile> curr = (ArrayList<MonitoredFile>)active.clone();
|
||||||
ArrayList<MonitoredFile> prev = (ArrayList<MonitoredFile>)last.clone();
|
ArrayList<MonitoredFile> prev = (ArrayList<MonitoredFile>)last.clone();
|
||||||
|
|
||||||
@@ -125,19 +125,19 @@ public class DirectoryMonitor
|
|||||||
Collections.sort(last);
|
Collections.sort(last);
|
||||||
|
|
||||||
if(last.size() == 0)
|
if(last.size() == 0)
|
||||||
IOLog.Warn("There's nothing at all in a FileMonitor's target folder! Folder: " + directory);
|
IOLog.warn("There's nothing at all in a FileMonitor's target folder! Folder: " + directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the current list of files the monitor is tracking in the directory.
|
// Returns the current list of files the monitor is tracking in the directory.
|
||||||
public List<MonitoredFile> GetCurrentFiles()
|
public List<MonitoredFile> getCurrentFiles()
|
||||||
{
|
{
|
||||||
return last;
|
return last;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints out an arraylist of items from a directory by path
|
// Prints out an arraylist of items from a directory by path
|
||||||
private void Print(ArrayList<MonitoredFile> toPrint)
|
private void print(ArrayList<MonitoredFile> toPrint)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < toPrint.size(); ++i)
|
for(int i = 0; i < toPrint.size(); ++i)
|
||||||
IOLog.Log(toPrint.get(i).path.toString());
|
IOLog.log(toPrint.get(i).path.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ public class FileMonitor
|
|||||||
// Constructs file monitor for a given file at a specific path.
|
// Constructs file monitor for a given file at a specific path.
|
||||||
public FileMonitor(String path)
|
public FileMonitor(String path)
|
||||||
{
|
{
|
||||||
Long last = FileUtils.LastModified(Paths.get(path));
|
Long last = FileUtils.lastModified(Paths.get(path));
|
||||||
|
|
||||||
if(last == null)
|
if(last == null)
|
||||||
{
|
{
|
||||||
file = null;
|
file = null;
|
||||||
IOLog.Error("Couldn't find a readable file at " + path + "!");
|
IOLog.error("Couldn't find a readable file at " + path + "!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -26,24 +26,24 @@ public class FileMonitor
|
|||||||
|
|
||||||
// Looks at the file and sees if it has undergone any changes.
|
// Looks at the file and sees if it has undergone any changes.
|
||||||
// If so, the fileChanged function provided is called!
|
// If so, the fileChanged function provided is called!
|
||||||
public void Update(Consumer<? super MonitoredFile> fileChanged)
|
public void update(Consumer<? super MonitoredFile> fileChanged)
|
||||||
{
|
{
|
||||||
if(file == null)
|
if(file == null)
|
||||||
{
|
{
|
||||||
IOLog.Error("Attempted to update a file that doesn't exist");
|
IOLog.error("Attempted to update a file that doesn't exist");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Long last = FileUtils.LastModified(file.path);
|
Long last = FileUtils.lastModified(file.path);
|
||||||
if(last == null)
|
if(last == null)
|
||||||
{
|
{
|
||||||
IOLog.Error("The file previously at " + file.path + " couldn't be read!");
|
IOLog.error("The file previously at " + file.path + " couldn't be read!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import utils.LogFilter;
|
|||||||
|
|
||||||
public class FileUtils
|
public class FileUtils
|
||||||
{
|
{
|
||||||
public static void CreateDirectoryIfDoesntExist(String directoryName)
|
public static void createDirectoryIfDoesntExist(String directoryName)
|
||||||
{
|
{
|
||||||
File directory = new File(directoryName);
|
File directory = new File(directoryName);
|
||||||
|
|
||||||
@@ -24,8 +24,8 @@ public class FileUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reads all lines from a file as a string
|
// Reads all lines from a file as a string
|
||||||
public static String ReadContent(File file) { return ReadContent(file.toPath()); }
|
public static String readContent(File file) { return readContent(file.toPath()); }
|
||||||
public static String ReadContent(Path filePath)
|
public static String readContent(Path filePath)
|
||||||
{
|
{
|
||||||
StringBuilder contentBuilder = new StringBuilder();
|
StringBuilder contentBuilder = new StringBuilder();
|
||||||
|
|
||||||
@@ -38,14 +38,14 @@ public class FileUtils
|
|||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
GlobalLog.Error(LogFilter.Util, e.getMessage());
|
GlobalLog.error(LogFilter.Util, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return contentBuilder.toString();
|
return contentBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recursively acquires all files at and below the specified directory, returning them as an arraylist of paths.
|
// Recursively acquires all files at and below the specified directory, returning them as an arraylist of paths.
|
||||||
public static ArrayList<Path> AcquireAllFiles(String startingDir)
|
public static ArrayList<Path> acquireAllFiles(String startingDir)
|
||||||
{
|
{
|
||||||
ArrayList<Path> items = new ArrayList<Path>();
|
ArrayList<Path> items = new ArrayList<Path>();
|
||||||
|
|
||||||
@@ -59,14 +59,14 @@ public class FileUtils
|
|||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
GlobalLog.Error(LogFilter.Util, e.getMessage());
|
GlobalLog.error(LogFilter.Util, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check when a file was last modified by path
|
// Check when a file was last modified by path
|
||||||
public static Long LastModified(Path path)
|
public static Long lastModified(Path path)
|
||||||
{
|
{
|
||||||
File file = new File(path.toString());
|
File file = new File(path.toString());
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ public class FileUtils
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GlobalLog.Error(LogFilter.Util, "File doesn't exist at path: " + path);
|
GlobalLog.error(LogFilter.Util, "File doesn't exist at path: " + path);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import utils.LogFilter;
|
|||||||
// Logging shim
|
// Logging shim
|
||||||
public class IOLog
|
public class IOLog
|
||||||
{
|
{
|
||||||
public static void Log(String s) { GlobalLog.Log(LogFilter.Util, s); }
|
public static void log(String s) { GlobalLog.log(LogFilter.Util, s); }
|
||||||
public static void Warn(String s) { GlobalLog.Warn(LogFilter.Util, s); }
|
public static void warn(String s) { GlobalLog.warn(LogFilter.Util, s); }
|
||||||
public static void Error(String s) { GlobalLog.Error(LogFilter.Util, s); }
|
public static void error(String s) { GlobalLog.error(LogFilter.Util, s); }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user