Skip to content

Commit f022bab

Browse files
committed
version bump to fix updating
1 parent fd5174e commit f022bab

File tree

4 files changed

+42
-12
lines changed

4 files changed

+42
-12
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
<groupId>lol.hyper</groupId>
2525
<artifactId>CustomLauncherRewrite</artifactId>
26-
<version>1.5</version>
26+
<version>1.5.1</version>
2727
<packaging>jar</packaging>
2828

2929
<properties>

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,46 +45,54 @@ public class Main {
4545
public static final File TTR_INSTALL_DIR = new File("ttr-files");
4646

4747
public static void main(String[] args) throws IOException {
48+
// load the log4j2config
4849
System.setProperty("log4j.configurationFile", "log4j2config.xml");
50+
// load the version
4951
final Properties properties = new Properties();
5052
properties.load(Main.class.getClassLoader().getResourceAsStream("project.properties"));
5153
VERSION = properties.getProperty("version");
54+
// log some basic info
5255
logger = LogManager.getLogger(Main.class);
5356
logger.info(System.getProperty("os.name"));
5457
logger.info("Program is starting.");
5558
logger.info("Running version " + VERSION);
5659

60+
// create the config folder
5761
final File configPath = new File("config");
5862
if (!configPath.exists()) {
5963
Files.createDirectory(configPath.toPath());
6064
logger.info("Creating config folder at " + configPath.getAbsolutePath());
6165
}
6266

67+
// create the ttr-files folder
6368
if (!TTR_INSTALL_DIR.exists()) {
6469
Files.createDirectory(TTR_INSTALL_DIR.toPath());
6570
logger.info("Creating TTR install folder at " + TTR_INSTALL_DIR.getAbsolutePath());
6671
}
6772

73+
// load the icon
6874
InputStream iconStream = Main.class.getResourceAsStream("/icon.png");
6975
if (iconStream != null) {
7076
icon = ImageIO.read(iconStream);
7177
}
7278

73-
// create the default file
74-
// accounts.json with no accounts
79+
// create accounts.json with no accounts
7580
if (!JSONManager.accountsFile.exists()) {
7681
JSONArray newAccounts = new JSONArray();
7782
JSONManager.writeFile(newAccounts, JSONManager.accountsFile);
7883
logger.info("Creating base accounts file...");
7984
}
8085

8186
// automatically convert the old format to the new one
87+
// probably not needed anymore
8288
char firstChar = JSONManager.readFile(JSONManager.accountsFile).charAt(0);
8389
if (firstChar == '{') {
8490
JSONManager.convertToNewFormat();
8591
Main.logger.info("Converting account storage to JSONArray format.");
8692
}
8793

94+
// only run the self updater if on windows
95+
// linux support will come in the future
8896
if (SystemUtils.IS_OS_WINDOWS) {
8997
String latestVersion = UpdateChecker.getLatestVersion();
9098
if (!latestVersion.equals(VERSION)) {
@@ -113,9 +121,11 @@ public static void main(String[] args) throws IOException {
113121
}
114122
}
115123

124+
// run the TTR updater
116125
JFrame updater = new TTRUpdater("Updater", Paths.get(TTR_INSTALL_DIR.getAbsolutePath()));
117126
updater.dispose();
118127

128+
// run the main window
119129
JFrame mainWindow = new MainWindow("CustomLauncherRewrite", new InvasionTracker());
120130
mainWindow.dispose();
121131
}

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public static void handleLoginRequest(LoginRequest loginRequest) {
5656
HashMap<String, String> request;
5757
try {
5858
logger.info("Sending login request...");
59+
// send the login request to TTR
5960
request = sendRequest(loginRequest).getRequestDetails();
6061
} catch (Exception e) {
6162
logger.error("Unable to send login request to TTR!", e);
@@ -69,32 +70,32 @@ public static void handleLoginRequest(LoginRequest loginRequest) {
6970
return;
7071
}
7172

73+
// get the login status
7274
String status = request.get("success");
7375
String banner = request.get("banner");
7476

7577
logger.info("banner=" + banner);
7678
logger.info("status=" + status);
7779

80+
// act based on the login status
7881
switch (status) {
79-
case "false":
82+
case "false": // false is invalid login details
8083
{
81-
// handle incorrect login
8284
if (banner.contains("Incorrect username")) {
8385
logger.info("Username or password is wrong.");
8486
JFrame errorWindow = new ErrorWindow("Login details are incorrect.");
8587
errorWindow.dispose();
8688
}
8789
break;
8890
}
89-
case "partial":
91+
case "partial": // partial is used for 2FA or ToonGuard
9092
{
91-
// handle 2fa
9293
logger.info("Asking user for two-factor auth.");
9394
JFrame twoFactorAuth =
9495
new TwoFactorAuth("Enter Code", banner, request.get("responseToken"));
9596
break;
9697
}
97-
case "true":
98+
case "true": // login was successful
9899
{
99100
logger.info("Login successful, launching game.");
100101
String gameServer = request.get("gameserver");
@@ -103,9 +104,8 @@ public static void handleLoginRequest(LoginRequest loginRequest) {
103104
launchGame.start();
104105
break;
105106
}
106-
case "delayed":
107+
case "delayed": // login request was put into a queue
107108
{
108-
// handle queue
109109
logger.info("Stuck in queue.");
110110
JFrame infoWindow =
111111
new InfoWindow(
@@ -116,12 +116,13 @@ public static void handleLoginRequest(LoginRequest loginRequest) {
116116
} catch (InterruptedException e) {
117117
logger.error(e);
118118
}
119+
// send the login request again after 5 seconds
119120
LoginRequest newLoginRequest = new LoginRequest();
120121
newLoginRequest.addDetails("queueToken", request.get("queueToken"));
121122
LoginHandler.handleLoginRequest(newLoginRequest);
122123
break;
123124
}
124-
default:
125+
default: // TTR sent back a weird status that we don't know about
125126
{
126127
logger.error("Weird login response: " + status);
127128
logger.info(request);

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class TTRUpdater extends JFrame {
5252
public final Logger logger = LogManager.getLogger(this);
5353

5454
public TTRUpdater(String title, Path installLocation) throws IOException {
55+
// setup the window elements
5556
JFrame frame = new JFrame(title);
5657
frame.setSize(370, 150);
5758
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@@ -83,6 +84,7 @@ public TTRUpdater(String title, Path installLocation) throws IOException {
8384
frame.setVisible(true);
8485
frame.setLocationRelativeTo(null);
8586

87+
// don't run the updater if the folder doesn't exist
8688
if (!installLocation.toFile().exists()) {
8789
JOptionPane.showMessageDialog(
8890
frame,
@@ -95,6 +97,7 @@ public TTRUpdater(String title, Path installLocation) throws IOException {
9597

9698
logger.info("We are checking for TTR updates!");
9799
String patchesJSONRaw = null;
100+
// read the TTR api to get the files the game needs
98101
URL url = new URL(PATCHES_URL);
99102
URLConnection conn = url.openConnection();
100103
conn.setRequestProperty(
@@ -118,6 +121,7 @@ public TTRUpdater(String title, Path installLocation) throws IOException {
118121
frame.dispose();
119122
}
120123

124+
// if the patchmanifest.txt is empty, it most likely won't be but just in case
121125
if (patchesJSONRaw == null) {
122126
JFrame errorWindow = new ErrorWindow("patchmanifest.txt returned empty.");
123127
logger.error(
@@ -132,6 +136,10 @@ public TTRUpdater(String title, Path installLocation) throws IOException {
132136

133137
String osType = null;
134138

139+
// set which OS we are using
140+
// ttr labels all files for which OS they will be attached to
141+
// windows = win32/win64
142+
// linux = linux/linux2
135143
if (SystemUtils.IS_OS_WINDOWS) {
136144
osType = "win32";
137145
}
@@ -148,14 +156,19 @@ public TTRUpdater(String title, Path installLocation) throws IOException {
148156
}
149157

150158
progressBar.setMaximum(patches.length());
159+
160+
// this loops through the JSON
161+
// key is the file name
151162
for (String key : patches.keySet()) {
152163
progressBar.setValue(progressBar.getValue() + 1);
153164
JSONObject currentFile = (JSONObject) patches.get(key);
154165
String onlineHash = currentFile.getString("hash");
166+
// get the list of OS's the file is for
155167
List<String> only =
156168
currentFile.getJSONArray("only").toList().stream()
157169
.map(object -> Objects.toString(object, null))
158170
.collect(Collectors.toList());
171+
// if we are running the OS the file is for, check it
159172
if (only.contains(osType)) {
160173
File localFile = new File(installLocation + File.separator + key);
161174
updateStatus.setText("Checking file " + localFile.getName());
@@ -170,6 +183,7 @@ public TTRUpdater(String title, Path installLocation) throws IOException {
170183
continue;
171184
}
172185

186+
// the file exists locally, check the SHA1 and compare it to TTR's
173187
String localHash;
174188
try {
175189
localHash = calcSHA1(localFile);
@@ -205,6 +219,9 @@ public TTRUpdater(String title, Path installLocation) throws IOException {
205219
"-----------------------------------------------------------------------");
206220
}
207221
}
222+
223+
// we store files we need to download in filesToDownload
224+
// if there are files in that list, download them
208225
if (filesToDownload.size() > 0) {
209226
File tempFolder = new File("temp");
210227
if (!tempFolder.exists() && !tempFolder.mkdirs()) {
@@ -219,6 +236,7 @@ public TTRUpdater(String title, Path installLocation) throws IOException {
219236

220237
progressBar.setValue(0); //reset
221238

239+
// download each file
222240
for (String fileToDownload : filesToDownload) {
223241
progressBar.setMaximum(fileToDownload.length());
224242
JSONObject file = patches.getJSONObject(fileToDownload);
@@ -251,7 +269,7 @@ public TTRUpdater(String title, Path installLocation) throws IOException {
251269
updateStatus.setText("Extracting file " + dl);
252270
progressBar.setVisible(false);
253271
try {
254-
extractFile(dl, fileToDownload);
272+
extractFile(dl, fileToDownload); // extract the file to the new location
255273
} catch (IOException e) {
256274
logger.error("Unable to extract file" + dl, e);
257275
JFrame errorWindow =
@@ -272,6 +290,7 @@ public TTRUpdater(String title, Path installLocation) throws IOException {
272290
System.nanoTime() - startTime, TimeUnit.NANOSECONDS)
273291
+ " seconds.");
274292
}
293+
// delete the temp folder is there are files in there
275294
File[] tempFolderFiles = tempFolder.listFiles();
276295
if (tempFolderFiles != null) {
277296
for (File currentFile : tempFolderFiles) {

0 commit comments

Comments
 (0)