Skip to content

Commit

Permalink
Improved EM scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
syd711 committed Aug 25, 2023
1 parent ae8fd5a commit 2221920
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.mephisto.vpin.server.highscores;

import de.mephisto.vpin.restclient.HighscoreType;
import de.mephisto.vpin.commons.utils.SystemCommandExecutor;
import de.mephisto.vpin.restclient.HighscoreType;
import de.mephisto.vpin.server.games.Game;
import de.mephisto.vpin.server.system.SystemService;
import de.mephisto.vpin.server.util.vpreg.VPReg;
Expand All @@ -14,7 +14,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Date;
Expand Down Expand Up @@ -51,7 +53,11 @@ public HighscoreMetadata readHighscore(Game game) {
try {
String romName = game.getRom();
if (StringUtils.isEmpty(romName)) {
String msg = "No rom name found.";
romName = game.getTableName();
}

if (StringUtils.isEmpty(romName)) {
String msg = "No rom or table name found.";
metadata.setStatus(msg);
return metadata;
}
Expand Down Expand Up @@ -112,6 +118,26 @@ private String parseHSFileHighscore(Game game, HighscoreMetadata metadata) throw

index++;
}
return builder.toString();
}
else if (lines.size() == 8) {
StringBuilder builder = new StringBuilder("HIGHEST SCORES\n");

String score1 = lines.get(1);
String score2 = lines.get(2);
builder.append("#1");
builder.append(" ");
builder.append("???");
builder.append(" ");
builder.append(score2);
builder.append("\n");

builder.append("#2");
builder.append(" ");
builder.append("???");
builder.append(" ");
builder.append(score1);
builder.append("\n");

return builder.toString();
}
Expand Down Expand Up @@ -198,7 +224,7 @@ private String executePINemHi(String nvRamFileName, HighscoreMetadata metadata)
StringBuilder standardOutputFromCommand = executor.getStandardOutputFromCommand();
StringBuilder standardErrorFromCommand = executor.getStandardErrorFromCommand();
if (!StringUtils.isEmpty(standardErrorFromCommand.toString())) {
String error = "Pinemhi command (" + commandFile.getCanonicalPath() + " "+ nvRamFileName + ") failed: " + standardErrorFromCommand;
String error = "Pinemhi command (" + commandFile.getCanonicalPath() + " " + nvRamFileName + ") failed: " + standardErrorFromCommand;
LOG.error(error);
metadata.setStatus(error);
throw new Exception(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import de.mephisto.vpin.server.vpx.VPXUtil;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
Expand Down Expand Up @@ -56,14 +57,19 @@ public static ScanResult scan(@NonNull File gameFile) {
Collections.reverse(split);
scanLines(gameFile, start, result, split);

if(StringUtils.isEmpty(result.getRom())) {
if (StringUtils.isEmpty(result.getRom())) {
LOG.info("Regular scan failed, running deep scan for " + gameFile.getAbsolutePath());
runDeepScan(gameFile, result);
}

if (!StringUtils.isEmpty(result.getRom())) {
LOG.info("Finished scan of table " + gameFile.getAbsolutePath() + ", found ROM '" + result.getRom() + "', took " + (System.currentTimeMillis() - start) + " ms.");
} else {
}
else if(StringUtils.isEmpty(result.getRom()) && StringUtils.isEmpty(result.getTableName()) && !StringUtils.isEmpty(result.getHsFileName())) {
result.setTableName(FilenameUtils.getBaseName(result.getHsFileName()));
LOG.info("Finished scan of table " + gameFile.getAbsolutePath() + ", found EM highscore filename '" + result.getHsFileName() + "', took " + (System.currentTimeMillis() - start) + " ms.");
}
else {
LOG.info("Finished scan of table " + gameFile.getAbsolutePath() + ", no ROM found" + "', took " + (System.currentTimeMillis() - start) + " ms.");
}
return result;
Expand Down Expand Up @@ -99,6 +105,7 @@ private static void runDeepScan(File gameFile, ScanResult result) {
lineSearchNvOffset(result, line);
lineSearchHsFileName(result, line);
lineSearchAsset(gameFile, result, line);
lineSearchEMHighscore(gameFile, result, line);
}
} catch (Exception e) {
LOG.error("Failed to read rom line '" + line + "' for " + gameFile.getAbsolutePath() + ": " + e.getMessage(), e);
Expand All @@ -117,6 +124,16 @@ private static void runDeepScan(File gameFile, ScanResult result) {
}
}

private static void lineSearchEMHighscore(File gameFile, ScanResult result, String line) {
if (!StringUtils.isEmpty(line) && line.contains(".txt\"")) {
String emFilename = line.substring(0, line.lastIndexOf(".txt\"") + 4);
emFilename = emFilename.substring(emFilename.lastIndexOf("\"") + 1);
if (result.getHsFileName() == null) {
result.setHsFileName(emFilename);
}
}
}

private static void scanLines(@NotNull File gameFile, long start, ScanResult result, List<String> split) {
String l;
for (String line : split) {
Expand Down Expand Up @@ -200,8 +217,7 @@ private static void lineSearchNvOffset(@NonNull ScanResult result, @NonNull Stri
try {
nvOffsetString = line.substring(line.indexOf("(") + 1, line.indexOf(")"));
result.setNvOffset(Integer.parseInt(nvOffsetString));
}
catch (Exception e) {
} catch (Exception e) {
LOG.error("Failed to read NVOffset from line \"" + line + "\" and segment \"" + nvOffsetString + "\": " + e.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public void refreshView(Optional<GameRepresentation> g, boolean forceRescan) {

if (!summary.getScores().isEmpty()) {
cardBtn.setDisable(false);
resetBtn.setDisable(false);
resetBtn.setDisable(StringUtils.isEmpty(rom));

rawTitleLabel.setVisible(true);
rawScoreWrapper.setVisible(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import org.apache.commons.lang3.StringUtils;

public class ResetHighscoreDialogController implements DialogController {

Expand Down Expand Up @@ -52,8 +53,13 @@ public void setGame(GameRepresentation game) {
this.game = game;
okButton.setDisable(true);

String rom = game.getRom();
if (!StringUtils.isEmpty(rom)) {
rom = game.getTableName();
}

this.textLabel.setText("Reset the highscore of \"" + game.getGameDisplayName() + "\"?");
this.descriptionLabel.setText("Enter the ROM name (\"" + game.getRom() + "\") to confirm the reset:");
this.descriptionLabel.setText("Enter the ROM name (\"" + rom + "\") to confirm the reset:");
textField.requestFocus();
textField.textProperty().addListener((observable, oldValue, newValue) -> {
String romName = game.getRom();
Expand Down

0 comments on commit 2221920

Please sign in to comment.