Skip to content

Commit

Permalink
Merge pull request inwc3#67 from Cokemonkey11/cokemonkey11/62-1
Browse files Browse the repository at this point in the history
inwc3#62: info-level logs for game exe version parsing
  • Loading branch information
Frotty authored Mar 28, 2021
2 parents ca3c159 + e5aa86c commit 251638c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main/java/net/moonlightflower/wc3libs/bin/GameExe.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import net.moonlightflower.wc3libs.port.GameVersion;

import javax.annotation.Nonnull;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand All @@ -15,13 +19,18 @@
import java.util.regex.Pattern;

public class GameExe {
private static final Logger log = LoggerFactory.getLogger(GameExe.class.getName());

@Nonnull
public static String getVersionString(@Nonnull File file) throws IOException {
try {
String s = file.getAbsolutePath();
log.info("Querying {} with dorkbox PE", s);

return PE.getVersion(s);
} catch (Exception e) {
log.info("Falling back to WMIC due to {}", e);

File tmpBat = File.createTempFile("getVersionString", "tmp_proxy.bat");

tmpBat.deleteOnExit();
Expand Down Expand Up @@ -65,7 +74,12 @@ public static String getVersionString(@Nonnull File file) throws IOException {
if (versionString.isEmpty()) versionString = null;

if (versionString == null) {
throw new IOException(e.getMessage() + "; " + sb.toString());
throw new IOException(
"Version string "
+ sb.toString()
+ " from file produced by WMIC wasn't readable. "
+ "This is the second failed attempt after dorkbox PE failed with exception.",
e);
}

return versionString;
Expand Down

0 comments on commit 251638c

Please sign in to comment.