In this following main method, I am calling the VersionManager.getVersionsFile() getter, which retrieves a "versions.json" file from a url:
public static void main(String[] args) {
ELookAndFeel.setLookAndFeel();
LauncherConfig config = LauncherConfig.load();
if (config.getClientToken() == null) {
ConfigManager.initConfig();
}
VersionManager.getVersionsFile();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
LauncherFrame.frameInstance = new LauncherFrame();
LauncherFrame.frameInstance.setVisible(true);
}
});
}
Unfortunately, it completes the download and then exits the program with error code 1. I don't know why or how. It gives me zero information. No exceptions, no nothing.
Here's the getter for reference (the String values are placeholders for now):
public static void getVersionsFile() {
File workingDirectory = DirectoryManager.getWorkingDirectory();
File versionsDirectory = new File(workingDirectory, "versions");
if (!versionsDirectory.exists() && !versionsDirectory.mkdir()) {
throw new RuntimeException("Failed to create versions directory");
}
File versionsFile = new File(versionsDirectory, "versions.json");
if (!versionsFile.exists()) {
versionsFile = FilesManager.downloadFile(FilesManager.VERSIONS_JSON_URL,
versionsFile.getAbsolutePath());
}
try (FileReader fr = new FileReader(versionsFile)) {
JSONTokener tokener = new JSONTokener(fr);
JSONObject versions = new JSONObject(tokener);
String id = versions.getString("id");
String port = versions.getString("port");
System.out.println("Version: " + id + " (" + port + ")");
} catch (IOException e) {
throw new RuntimeException("Can't read versions file", e);
} catch (JSONException e) {
throw new RuntimeException("Failed to parse versions file", e);
}
}