|
20 | 20 | import lol.hyper.customlauncher.accounts.JSONManager; |
21 | 21 | import lol.hyper.customlauncher.accounts.windows.MainWindow; |
22 | 22 | import lol.hyper.customlauncher.fieldofficetracker.FieldOfficeTracker; |
| 23 | +import lol.hyper.customlauncher.generic.ErrorWindow; |
23 | 24 | import lol.hyper.customlauncher.invasiontracker.InvasionTracker; |
24 | 25 | import lol.hyper.customlauncher.ttrupdater.TTRUpdater; |
25 | 26 | import lol.hyper.customlauncher.updater.UpdateChecker; |
@@ -107,43 +108,52 @@ public static void main(String[] args) throws IOException, InterruptedException |
107 | 108 | } |
108 | 109 |
|
109 | 110 | // check for updates using my own api |
110 | | - GitHubReleaseAPI api = new GitHubReleaseAPI("CustomLauncherRewrite", "hyperdefined"); |
111 | | - GitHubRelease latest = api.getLatestVersion(); |
112 | | - String latestVersion = latest.getTagVersion(); |
113 | | - GitHubRelease current = api.getReleaseByTag(VERSION); |
114 | | - int behind = api.getBuildsBehind(current); |
115 | | - UpdateChecker updateChecker = new UpdateChecker(api); |
116 | | - StringBuilder updates = new StringBuilder(); |
117 | | - // if the user is 1 or more build behind, ask to update |
118 | | - if (behind > 0) { |
119 | | - JTextArea textArea = new JTextArea(); |
120 | | - JScrollPane scrollPane = new JScrollPane(textArea); |
121 | | - textArea.setLineWrap(true); |
122 | | - textArea.setWrapStyleWord(true); |
123 | | - scrollPane.setPreferredSize(new Dimension(500, 500)); |
124 | | - updates.append("You are running an outdated version! You are running ") |
125 | | - .append(VERSION) |
126 | | - .append(" currently."); |
127 | | - updates.append(" Would you like to update?\n\n"); |
128 | | - for (int i = behind - 1; i >= 0; i--) { |
129 | | - String tag = api.getAllReleases().get(i).getTagVersion(); |
130 | | - updates.append("----------------------------------------\nVersion: ") |
131 | | - .append(tag) |
132 | | - .append("\n") |
133 | | - .append(api.getReleaseByTag(tag).getReleaseNotes()) |
134 | | - .append("\n"); |
135 | | - } |
136 | | - textArea.setText(updates.toString()); |
137 | | - logger.info("A new version is available! Version: " + latestVersion); |
138 | | - |
139 | | - int dialogResult = |
140 | | - JOptionPane.showConfirmDialog( |
141 | | - null, scrollPane, "Updates", JOptionPane.YES_NO_OPTION); |
142 | | - if (dialogResult == JOptionPane.YES_OPTION) { |
143 | | - // download the latest version and run it |
144 | | - updateChecker.downloadLatestVersion(); |
145 | | - updateChecker.launchNewVersion(latestVersion); |
146 | | - System.exit(0); |
| 111 | + GitHubReleaseAPI api; |
| 112 | + try { |
| 113 | + api = new GitHubReleaseAPI("CustomLauncherRewrite", "hyperdefined"); |
| 114 | + } catch (IOException e) { |
| 115 | + api = null; |
| 116 | + ErrorWindow errorWindow = new ErrorWindow(null, e); |
| 117 | + errorWindow.dispose(); |
| 118 | + } |
| 119 | + if (api != null) { |
| 120 | + GitHubRelease latest = api.getLatestVersion(); |
| 121 | + String latestVersion = latest.getTagVersion(); |
| 122 | + GitHubRelease current = api.getReleaseByTag(VERSION); |
| 123 | + int behind = api.getBuildsBehind(current); |
| 124 | + UpdateChecker updateChecker = new UpdateChecker(api); |
| 125 | + StringBuilder updates = new StringBuilder(); |
| 126 | + // if the user is 1 or more build behind, ask to update |
| 127 | + if (behind > 0) { |
| 128 | + JTextArea textArea = new JTextArea(); |
| 129 | + JScrollPane scrollPane = new JScrollPane(textArea); |
| 130 | + textArea.setLineWrap(true); |
| 131 | + textArea.setWrapStyleWord(true); |
| 132 | + scrollPane.setPreferredSize(new Dimension(500, 500)); |
| 133 | + updates.append("You are running an outdated version! You are running ") |
| 134 | + .append(VERSION) |
| 135 | + .append(" currently."); |
| 136 | + updates.append(" Would you like to update?\n\n"); |
| 137 | + for (int i = behind - 1; i >= 0; i--) { |
| 138 | + String tag = api.getAllReleases().get(i).getTagVersion(); |
| 139 | + updates.append("----------------------------------------\nVersion: ") |
| 140 | + .append(tag) |
| 141 | + .append("\n") |
| 142 | + .append(api.getReleaseByTag(tag).getReleaseNotes()) |
| 143 | + .append("\n"); |
| 144 | + } |
| 145 | + textArea.setText(updates.toString()); |
| 146 | + logger.info("A new version is available! Version: " + latestVersion); |
| 147 | + |
| 148 | + int dialogResult = |
| 149 | + JOptionPane.showConfirmDialog( |
| 150 | + null, scrollPane, "Updates", JOptionPane.YES_NO_OPTION); |
| 151 | + if (dialogResult == JOptionPane.YES_OPTION) { |
| 152 | + // download the latest version and run it |
| 153 | + updateChecker.downloadLatestVersion(); |
| 154 | + updateChecker.launchNewVersion(latestVersion); |
| 155 | + System.exit(0); |
| 156 | + } |
147 | 157 | } |
148 | 158 | } |
149 | 159 |
|
|
0 commit comments