Skip to content

Commit

Permalink
Updated log4j
Browse files Browse the repository at this point in the history
Credentials file location no longer hardcoded (oops)
Reworded error messages to be more specific
McCree is now Cassidy
JDK changed to OpenJDK
  • Loading branch information
NC256 committed Feb 6, 2022
1 parent 5a49f1f commit c6eb305
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions .idea/runConfigurations.xml

This file was deleted.

4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ repositories {

dependencies {

compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.14.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.14.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
compile 'junit:junit:4.13.2'
Expand Down
25 changes: 9 additions & 16 deletions src/main/java/com/github/NC256/overwatchstats/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,7 @@ public class Main {

public static void main(String[] args) throws IOException, InterruptedException, GeneralSecurityException {

Configurator.setRootLevel(Level.DEBUG);

logger.trace("Trace Message!");
logger.debug("Debug Message!");
logger.info("Info Message!");
logger.warn("Warn Message!");
logger.error("Error Message!");
logger.fatal("Fatal Message!");
System.out.println("Logger should have already logged");
Configurator.setRootLevel(Level.WARN);

if (!new File("properties.properties").exists()) {
generatePropertiesFile();
Expand All @@ -51,20 +43,20 @@ public static void main(String[] args) throws IOException, InterruptedException,

List<CanonicalHero> heroData = ParseHeroData.parse(); // Canonical game reference data
if (heroData == null){
logger.fatal("Unable to parse hero reference data.");
logger.fatal("Unable to parse hero reference data. Is the file missing?");
System.exit(-1);
}

List<CanonicalMode> modeData = ParseModeData.parse();
if (modeData == null){
logger.fatal("Unable to parse mode reference data.");
logger.fatal("Unable to parse gamemode reference data. Is the file missing?");
System.exit(-1);
}

boolean liveMode = true; // Always automatically switch to newly created files.
boolean googleSheetsLive = true; // Transmit to Google Sheets
if (googleSheetsLive){
TalkToGoogle.initalize();
TalkToGoogle.initalize(new File(preferences.getProperty("Google_Credentials_File_Location")));
}

File logDirectory = new File(preferences.getProperty("Overwatch_Log_Directory"));
Expand Down Expand Up @@ -144,7 +136,7 @@ static File getLatestLogFile (File logDirectory){
}
}
if (latest == null){
logger.fatal("Couldn't find the latest file.");
logger.fatal("Couldn't find the latest log file. Is the directory location correct? Are there logs in it?");
System.exit(-1);
}
return latest;
Expand All @@ -157,23 +149,24 @@ static void generatePropertiesFile () throws IOException {
preferences.setProperty("Google_Sheet_Insertion_Cell", "B2");
preferences.setProperty("Overwatch_Log_Directory", "C:\\Users\\USERNAME\\Documents\\Overwatch\\Workshop\\");
preferences.setProperty("Transmission_Interval", "2000");
preferences.setProperty("Google_Credentials_File_Location", "C:\\Folder\\credentials.json");
preferences.store(new FileWriter(new File("properties.properties")), "Documentation on Github.");
return;
}

static Properties loadAndValidateProperties() throws IOException {
Properties preferences = new Properties();
preferences.load(new FileReader(new File("properties.properties")));
if (preferences.stringPropertyNames().size() != 5){
if (preferences.stringPropertyNames().size() != 6){
logger.fatal("Invalid number of properties, is properties file out of date? Perhaps delete it and let the program generate a new one.");
System.exit(-1);
}
if (!new File(preferences.getProperty("Overwatch_Log_Directory")).exists()){
logger.fatal("Cannot find that log directory! Check your formatting.");
logger.fatal("Cannot find the log directory. Check you've set the path properly in the properties file.");
System.exit(-1);
}
if (Integer.parseInt(preferences.getProperty("Transmission_Interval")) < 1100){
logger.error("Cannot transmit to the spreadsheet more frequently than every 1100 milliseconds. Current Transmission_Interval is too short!");
logger.error("Cannot transmit to the spreadsheet more frequently than every 1100 milliseconds. Current Transmission_Interval property is too short!");
}
//TODO how to test API communication is working?
return preferences;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void run() {
message.updateStats(match);
}
catch (Exception e){
logger.warn("Unable to update stats for the following: " + line);
logger.warn("Unable to parse stats for the following line: " + line);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ else if (teamOrFFA.equals("free-for-all")){
return canonicalModes;
}
catch (Exception e){
logger.error("Couldn't parse mode names.");
logger.error("Couldn't parse gamemode names.");
logger.error(e);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void collectAndTransmit(GameMatch match) throws IOException {
data.get(6).add(0, System.currentTimeMillis());
}
catch (Exception e){
logger.error("Error packing data for spreadsheet!");
logger.error("Error packing data for spreadsheet transmission!");
logger.error(e);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.api.services.sheets.v4.model.UpdateValuesResponse;
import com.google.api.services.sheets.v4.model.ValueRange;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
Expand Down Expand Up @@ -46,11 +47,12 @@ public class TalkToGoogle {
* @return An authorized Credential object.
* @throws IOException If the credentials.json file cannot be found.
*/
private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT) throws IOException {
private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT, File credentials) throws IOException {
// Load client secrets.
//InputStream in = TalkToGoogle.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
InputStream in = new FileInputStream("C:\\All\\Programming\\Projects\\Overwatch Stats Proof of " +
"Concept\\src\\main\\java\\com\\github\\NC256\\overwatchstats\\spreadsheets\\credentials.json");
// InputStream in = new FileInputStream("C:\\All\\Programming\\Projects\\Overwatch Stats Proof of " +
// "Concept\\src\\main\\java\\com\\github\\NC256\\overwatchstats\\spreadsheets\\credentials.json");
InputStream in = new FileInputStream(credentials);
if (in == null) {
throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH);
}
Expand All @@ -66,10 +68,10 @@ private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT)
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}

public static void initalize () throws IOException, GeneralSecurityException {
public static void initalize (File credentialsFile) throws IOException, GeneralSecurityException {
// Build a new authorized API client service.
final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
service = new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT))
service = new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT, credentialsFile))
.setApplicationName(APPLICATION_NAME)
.build();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/HeroDamageSourceMap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Hanzo
Storm Bow;Primary Fire, Sonic Arrow;Ability 1, Storm Arrow;Ability 2, Dragonstrike;Ultimate
Junkrat
Frag Launcher;Primary Fire, Concussion Mine;Ability 1, Steel Trap;Ability 2, RIP-Tire;Ultimate
McCree
Cassidy
Peacekeeper;Primary Fire, Flashbang;Ability 2, Deadeye; Ultimate
Mei
Endothermic Blaster;Primary Fire, Endothermic Blaster;Secondary Fire, Blizzard;Ultimate
Expand Down

0 comments on commit c6eb305

Please sign in to comment.