Skip to content

Commit 3adea09

Browse files
committed
fixed weird path stuff
also fixes launching the game on linux
1 parent b02f04a commit 3adea09

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

src/main/java/lol/hyper/customlauncher/ConfigHandler.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public class ConfigHandler {
2929
public final File CONFIG_FILE = new File("config", "config.json");
3030
public final int CONFIG_VERSION = 1;
3131
public static File INSTALL_LOCATION;
32-
public static String installLocation;
3332
private JSONObject jsonObject;
3433
private final Logger logger = LogManager.getLogger(this);
3534

@@ -38,7 +37,7 @@ public ConfigHandler() {
3837
logger.info("Config version: " + jsonObject.getInt("version"));
3938
logger.info("showInvasionNotifications: " + showCogInvasionNotifications());
4039
logger.info("showFieldOfficeNotifications: " + showFieldOfficeNotifications());
41-
logger.info("ttrInstallLocation: " + installLocation);
40+
logger.info("ttrInstallLocation: " + INSTALL_LOCATION.getAbsolutePath());
4241
}
4342

4443
public boolean showCogInvasionNotifications() {
@@ -96,7 +95,6 @@ public void loadConfig() {
9695
}
9796
}
9897
setDefaults();
99-
installLocation = jsonObject.getString("ttrInstallLocation");
100-
INSTALL_LOCATION = new File(installLocation);
98+
INSTALL_LOCATION = new File(jsonObject.getString("ttrInstallLocation"));
10199
}
102100
}

src/main/java/lol/hyper/customlauncher/accounts/windows/ConfigWindow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public ConfigWindow(ConfigHandler configHandler) {
4747
panel.setLayout(null);
4848

4949
JLabel ttrInstall = new JLabel("<html>TTR Installation</html>");
50-
JTextField ttrInstallBox = new JTextField(ConfigHandler.installLocation);
50+
JTextField ttrInstallBox = new JTextField(ConfigHandler.INSTALL_LOCATION.getAbsolutePath());
5151
JLabel showInvasionNotifications = new JLabel("<html>Show invasion notifications?</html>");
5252
JCheckBox showInvasionNotificationsBox = new JCheckBox();
5353
JLabel showFieldOfficeNotifications =

src/main/java/lol/hyper/customlauncher/login/LaunchGame.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,38 @@ public void run() {
5050
windowsCommand = new String[] {"cmd", "/c", "TTREngine.exe"};
5151
}
5252
pb.command(windowsCommand);
53+
logger.info("Launching game from " + ConfigHandler.INSTALL_LOCATION);
5354
}
5455
if (SystemUtils.IS_OS_LINUX) {
5556
String linuxCommand = "./TTREngine";
5657

5758
// Make sure it's executable before running
58-
boolean result =
59-
new File(ConfigHandler.installLocation + linuxCommand).setExecutable(true);
59+
boolean result;
60+
File fullPath = new File(ConfigHandler.INSTALL_LOCATION, "TTREngine");
61+
try {
62+
result = fullPath.setExecutable(true);
63+
} catch (SecurityException exception) {
64+
logger.error(
65+
"Unable to set " + fullPath.getAbsolutePath() + " as an executable!",
66+
exception);
67+
ErrorWindow errorWindow = new ErrorWindow(null, exception);
68+
errorWindow.dispose();
69+
return;
70+
}
71+
6072
if (!result) {
73+
logger.error("Unable to set " + fullPath.getAbsolutePath() + " as an executable!");
6174
ErrorWindow errorWindow =
6275
new ErrorWindow(
6376
"Unable to set "
64-
+ ConfigHandler.installLocation
65-
+ "TTREngine as executable. Please make sure this file has the correct permissions!",
77+
+ fullPath.getAbsolutePath()
78+
+ " as an executable!\nMake sure this file is executable!",
6679
null);
6780
errorWindow.dispose();
6881
return;
6982
}
70-
7183
pb.command(linuxCommand);
84+
logger.info("Launching game from " + fullPath.getAbsolutePath());
7285
}
7386

7487
// dirty little trick to redirect the output
@@ -82,8 +95,6 @@ public void run() {
8295
env.put("TTR_GAMESERVER", this.gameServer);
8396
env.put("TTR_PLAYCOOKIE", this.cookie);
8497

85-
logger.info("Launching game from " + ConfigHandler.installLocation);
86-
8798
Thread t1 =
8899
new Thread(
89100
() -> {

src/main/java/lol/hyper/customlauncher/ttrupdater/TTRUpdater.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public TTRUpdater(String title) {
157157
if (!localFile.exists()) {
158158
logger.info(
159159
"-----------------------------------------------------------------------");
160-
logger.info(ConfigHandler.installLocation + File.separator + key);
160+
logger.info(ConfigHandler.INSTALL_LOCATION.getAbsolutePath() + File.separator + key);
161161
logger.info("This file is missing and will be downloaded.");
162162
logger.info(
163163
"-----------------------------------------------------------------------");
@@ -180,7 +180,7 @@ public TTRUpdater(String title) {
180180
}
181181
logger.info(
182182
"-----------------------------------------------------------------------");
183-
logger.info(ConfigHandler.installLocation + File.separator + key);
183+
logger.info(ConfigHandler.INSTALL_LOCATION.getAbsolutePath() + File.separator + key);
184184
logger.info("Local hash: " + localHash.toLowerCase(Locale.ENGLISH));
185185
logger.info("Expected hash: " + onlineHash);
186186
logger.info("Type: " + osType);

0 commit comments

Comments
 (0)