Skip to content

Commit

Permalink
v1.0.2 fix bug on Windows where chrome can be installed in different …
Browse files Browse the repository at this point in the history
…location rather than hard-coded (#2)

* Allow user provide Google Chrome installed path instead of using a hard-coded path which might be incorrect sometime

* update version to 1.0.2

Co-authored-by: 9-9-9-9 <9-9-9-9>
  • Loading branch information
9-9-9-9 authored Aug 23, 2021
1 parent 3e93540 commit 6cb71ca
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CALL mvn clean package

if not exist out mkdir out
del BitHeroes.jar >nul 2>&1
echo F|xcopy target\ReRun-*-jar-with-dependencies.jar BitHeroes.jar /Y
echo F|xcopy target\BitHeroes-*-jar-with-dependencies.jar BitHeroes.jar /Y
if not exist user-config.properties echo. 2>user-config.properties

rem Generating mini client
Expand Down
1 change: 1 addition & 0 deletions client.bat
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
del mini-game-on-chrome.bat >nul 2>&1
java -jar BitHeroes.jar client
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>bh.bot</groupId>
<artifactId>BitHeroes</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>

<build>
<resources>
Expand Down
3 changes: 3 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ telegram.channel-id=
# Tolerant
tolerant.position=50
tolerant.color=0
# Google Chrome path, for Windows only
external.application.chrome.path=C:\\\\Program Files (x86)\\\\Google\\\\Chrome\\\\Application\\\\chrome.exe
EOF

# Copy files for mini client
Expand Down
38 changes: 35 additions & 3 deletions src/main/java/bh/bot/app/GenMiniClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import static bh.bot.common.Log.err;
import static bh.bot.common.Log.info;
import static bh.bot.common.utils.StringUtil.isBlank;

public class GenMiniClient extends AbstractApplication {
private static final File chromeUserDir = new File("chrome-user-dir");
Expand All @@ -23,8 +24,8 @@ protected void internalRun(String[] args) {
String scriptFileName = String.format("mini-game-on-chrome.%s", Configuration.OS.isWin ? "bat" : "sh");
if (errMsg != null)
{
err("Unable to generate %s with error:", scriptFileName);
err(" %s", errMsg);
err("ERROR: Unable to generate mini-client!!!");
err("Error message: %s", errMsg);
info("To be able to use mini game client (using Google Chrome), the following conditions must be met:");
info(" 1. Google Chrome must be installed");
info(" 2. You can play Bit Heroes game at https://www.kongregate.com/games/Juppiomenz/bit-heroes");
Expand Down Expand Up @@ -69,7 +70,38 @@ protected void internalRun(String[] args) {
chromeArgs.add("--window-position=0,0");
chromeArgs.add(String.format("\"--app=file://%s\"", pathIndex.toAbsolutePath().toString()));
} else if (Configuration.OS.isWin) {
app = "\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\"";
final String keyChromePath = "external.application.chrome.path";
final String defaultChromePath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
String chromePath = Configuration.read(keyChromePath);
if (isBlank(chromePath)) {
info("Missing configuration of Google Chrome path (key %s), going to set to use default path: %s", keyChromePath, defaultChromePath);
chromePath = defaultChromePath;
}

if (!(new File(chromePath)).exists()) {
err("ERROR: Chrome not found");
info("Can not find Google Chrome at provided path %s", chromePath);
info("Please provide a correct path to chrome.exe into key '%s' on user-config.properties file", keyChromePath);
info("To get it, you can do this:");
info("1. Right click on Google Chrome shortcut");
info("2. Select Properties");
info("3. Copy value of Target line");
info("4. Transfrom the value to a correct format. For example:");
info(" - Input value is:");
info(" \"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\"");
info(" (with the double quotes)");
info(" - Should be translated into:");
info(" C:\\\\Program Files (x86)\\\\Google\\\\Chrome\\\\Application\\\\chrome.exe");
info(" (remove the double quotes and double the back slashes)");
info("5. Fill the translated path into key '%s' of the user-config.properties file", keyChromePath);
info(" Example:");
info("%s=C:\\\\Program Files (x86)\\\\Google\\\\Chrome\\\\Application\\\\chrome.exe", keyChromePath);
info("6. Save the file user-config.properties after modified");
info("7. Run script '.\\client.bat' to generate mini-client");
System.exit(1);
}

app = String.format("\"%s\"", chromePath);
chromeArgs.add(String.format("\"--user-data-dir=%s\"", chromeUserDir.getAbsolutePath()));
chromeArgs.add("--window-size=820,565");
chromeArgs.add("--window-position=0,0");
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ offset.fishing.buttons.cast-sp.x=368
offset.fishing.buttons.cast-sp.y=462
# Fishing#Catch
offset.fishing.buttons.catch-sp.x=360
offset.fishing.buttons.catch-sp.y=462
offset.fishing.buttons.catch-sp.y=462

# External
# Google Chrome path, for Windows only
external.application.chrome.path=C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe

0 comments on commit 6cb71ca

Please sign in to comment.