Skip to content

Commit

Permalink
revert some format churn, port more stuff to logger
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssaruth committed Nov 22, 2023
1 parent 3d07f70 commit 509e8d8
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 221 deletions.
10 changes: 10 additions & 0 deletions client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ application {
// Define the main class for the application.
mainClass.set("EntropyMain")
}

task<JavaExec>("runDev") {
configure(
closureOf<JavaExec> {
group = "run"
classpath = project.the<SourceSetContainer>()["main"].runtimeClasspath
args = listOf("devMode")
},
)
}
1 change: 0 additions & 1 deletion client/src/main/java/EntropyMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ else if (!bindOnPort(BIND_PORT_NUMBER))

private static void setLookAndFeel()
{
AbstractClient.setOs();
logger.info("laf.init", "Initialising Look & Feel - Operating System: " + AbstractClient.operatingSystem);

String lookAndFeel = null;
Expand Down
2 changes: 1 addition & 1 deletion client/src/main/java/bean/AbstractDevScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import util.Debug;

public abstract class AbstractDevScreen extends JFrame
public abstract class AbstractDevScreen extends FocusableWindow
{
public AbstractDevScreen()
{
Expand Down
4 changes: 3 additions & 1 deletion client/src/main/java/bean/FileUploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import util.Debug;
import util.DialogUtil;

import static utils.InjectedThings.logger;

public class FileUploader extends JPanel
implements ActionListener
{
Expand Down Expand Up @@ -79,7 +81,7 @@ private void selectFile()
selectedFile = fc.getSelectedFile();
textField.setText(selectedFile.getPath());

Debug.append("Selected " + selectedFile.getName());
logger.info("fileSelected", "Selected " + selectedFile.getName());
}
}

Expand Down
82 changes: 39 additions & 43 deletions client/src/main/java/object/ReplayTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import util.ReplayRowWrapper;
import util.TableUtil;

import static utils.InjectedThings.logger;

public class ReplayTable extends JTable
implements MouseListener,
Registry
Expand Down Expand Up @@ -198,16 +200,16 @@ private void stripOutHiddenAndRemovedColumns()

private void fillReplayList()
{
Debug.append("Filling " + folder + " replay list");
logger.info("initReplayList", "Filling " + folder + " replay list");

String replayDirectory = ReplayFileUtil.getDirectoryFromPreferences();
String directoryStr = replayDirectory + "//Replays//" + folder;

//if the 'Replays' directory doesn't exist, just return.
File directory = new File(directoryStr);
if (!directory.isDirectory())
{
Debug.append("Directory " + directory + " does not exist.");
logger.info("initReplayList", "Directory " + directory + " does not exist.");
return;
}

Expand All @@ -230,8 +232,8 @@ else if (!fileName.equals(FILE_NAME_INDEX))
corruptFiles.add(file);
}
}
Debug.append("Finished filling " + folder + " replay list [size: " + replayFilenames.size() + "]");

logger.info("initReplayList", "Finished filling " + folder + " replay list [size: " + replayFilenames.size() + "]");
if (!corruptReplayMessage.isEmpty() )
{
promptToDeleteCorruptReplays(corruptReplayMessage);
Expand Down Expand Up @@ -269,14 +271,14 @@ private void initialiseCacheFromIndexFile()
{
if (!rowWrapperByFileName.isEmpty())
{
Debug.append("Not reading index file as rows are already cached.");
logger.info("replayListIndex", "Not reading index file as rows are already cached.");
return;
}

File indexFile = getIndexFileIfExists();
if (indexFile == null)
{
Debug.append("No index file for " + folder + " replays");
logger.info("replayListIndex", "No index file for " + folder + " replays");
return;
}

Expand All @@ -287,15 +289,16 @@ private void initialiseCacheFromIndexFile()
}

String[] lines = contents.split("\n");
Debug.append("Found " + lines.length + " lines in index file.");
logger.info("replayListIndex", "Found " + lines.length + " lines in index file.");
for (int i=0; i<lines.length; i++)
{
String rowWrapperStr = lines[i];
ReplayRowWrapper wrapper = new ReplayRowWrapper(rowWrapperStr);
String filename = wrapper.getFilename();
if (!replayFilenames.contains(filename))
{
Debug.append("Not caching " + filename + " as file no longer exists.");

logger.info("replayListIndex", "Not caching " + filename + " as file no longer exists.");
continue;
}

Expand Down Expand Up @@ -328,7 +331,7 @@ private void writeOutIndexFileFromCache()
File directory = new File(replayDirectory);
if (!directory.isDirectory())
{
Debug.append("Directory " + directory + " does not exist, not writing out index file.");
logger.info("replayListIndex", "Directory " + directory + " does not exist, not writing out index file.");
return;
}

Expand Down Expand Up @@ -359,7 +362,9 @@ private void populateFilteredList(boolean init)
replayFilenamesFiltered.clear();

int fullSize = replayFilenames.size();
Debug.append("Populating filtered list for " + this + " - total files: " + fullSize, init);
if (init) {
logger.info("populateFilteredList", "Populating filtered list for " + this + " - total files: " + fullSize);
}

int cachedCount = 0;
for (int i=0; i<fullSize; i++)
Expand All @@ -376,8 +381,10 @@ private void populateFilteredList(boolean init)
replayFilenamesFiltered.add(name);
}
}

Debug.append("Finished populating filtered list for " + this + " - files found in cache: " + cachedCount, init);

if (init) {
logger.info("populateFilteredList", "Finished populating filtered list for " + this + " - files found in cache: " + cachedCount);
}
}

private boolean includeRowBasedOnFilters(ReplayRowWrapper wrapper)
Expand Down Expand Up @@ -519,10 +526,8 @@ private void deleteReplays()

//Confirm the deletion
int size = replaysToDelete.size();
Debug.append("Pressed delete for " + size + " files " + replaysToDelete);
if (!confirmDeletion(size))
{
Debug.append("Cancelled deletion.");
return;
}

Expand Down Expand Up @@ -562,15 +567,15 @@ private boolean deleteWithCatch(String replayPath, String filename)
{
try
{
Debug.append("Deleting " + replayPath);
logger.info("deleteReplay", "Deleting " + replayPath);
Files.delete(Paths.get(replayPath));

replayFilenames.remove(filename);
replayFilenamesFiltered.remove(filename);
}
catch (IOException x)
{
Debug.append("Caught " + x + " deleting file " + replayPath);
logger.info("deleteReplay", "Caught " + x + " deleting file " + replayPath);
return false;
}

Expand Down Expand Up @@ -602,33 +607,26 @@ public String getFolder()

public void showReplay()
{
try
int viewRow = getSelectedRow();
if (viewRow == -1)
{
int viewRow = getSelectedRow();
if (viewRow == -1)
{
return;
}

int internalRow = convertRowIndexToModel(viewRow);

String filename = (String)model.getValueAt(internalRow, INDEX_OF_FILENAME_COLUMN);
Debug.append("Double clicked to open file " + filename, true);
if (!validateReplayContents(filename))
{
return;
}

ReplayDialog replayDialog = ScreenCache.getFileReplayDialog();
replayDialog.setLocationRelativeTo(null);
replayDialog.setResizable(false);
replayDialog.initForFileReplay(filename, folder);
replayDialog.setVisible(true);
return;
}
catch (Throwable t)

int internalRow = convertRowIndexToModel(viewRow);

String filename = (String)model.getValueAt(internalRow, INDEX_OF_FILENAME_COLUMN);
logger.info("showReplay", "Opening file " + filename);
if (!validateReplayContents(filename))
{
Debug.stackTrace(t);
return;
}

ReplayDialog replayDialog = ScreenCache.getFileReplayDialog();
replayDialog.setLocationRelativeTo(null);
replayDialog.setResizable(false);
replayDialog.initForFileReplay(filename, folder);
replayDialog.setVisible(true);
}

private boolean validateReplayContents(String filename)
Expand All @@ -654,7 +652,6 @@ else if (replayVersion < ReplayConverter.REPLAY_VERSION)

private void dealWithCorruptReplay(String filePath, String filename, String question)
{
Debug.append(filename + " is corrupt, prompting user to delete it");
int option = DialogUtil.showQuestion(question, false);
if (option == JOptionPane.YES_OPTION)
{
Expand All @@ -672,13 +669,12 @@ private void dealWithCorruptReplay(String filePath, String filename, String ques

private boolean convertReplayToLatestVersion(String filePath, String filename, int replayVersion)
{
Debug.append(filename + " is out of date (version " + replayVersion + "), will convert it now");
String message = "The file you selected is in an out of date format - it will be updated now.";
DialogUtil.showInfo(message);
boolean success = ReplayConverter.convertReplay(filePath, replayVersion);
if (success)
{
Debug.append("Converted successfully, launching replay");
logger.info("replayConverted", "Successfully converted replay");
return true;
}

Expand Down
Loading

0 comments on commit 509e8d8

Please sign in to comment.