Skip to content

Commit f739c9e

Browse files
committed
Only load stage1 UI if downloading is required
1 parent e327423 commit f739c9e

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

stage0/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
22

3-
version = "1.1.0-alpha.46"
3+
version = "1.1.0-alpha.47"
44

55
val include by configurations
66

stage1/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = "1.1.0-alpha.47"
1+
version = "1.1.0-alpha.48" // When you bump this, you should also bump stage0, cause stage0 includes a copy of stage1 too
22

33
sourceSets {
44
val main by this

stage1/src/main/java/org/polyfrost/oneconfig/loader/stage1/Stage1Loader.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public class Stage1Loader extends LoaderBase {
6262
private Class<?> oneconfigMainClass;
6363
private Object oneconfigMainInstance;
6464

65+
private LoaderFrame loaderFrame = null;
66+
6567
public Stage1Loader(Capabilities capabilities) {
6668
super(
6769
"stage1",
@@ -80,16 +82,14 @@ public void load() {
8082
String targetSpecifier = gameMetadata.getTargetSpecifier();
8183
log.info("Target specifier: {}", targetSpecifier);
8284

83-
log.info("Creating UI");
84-
LoaderFrame loaderFrame = new LoaderFrame();
85-
loaderFrame.display();
86-
87-
checkForUpdates(loaderFrame);
88-
maybeDownloadRelaunch(loaderFrame);
89-
downloadOneConfigArtifacts(loaderFrame);
85+
checkForUpdates();
86+
maybeDownloadRelaunch();
87+
downloadOneConfigArtifacts();
9088

9189
// Close our updater window, we're done
92-
loaderFrame.destroy();
90+
if (this.loaderFrame != null) {
91+
this.loaderFrame.destroy();
92+
}
9393

9494
try {
9595
ClassLoader classLoader = runtimeAccess.getClassLoader();
@@ -119,7 +119,7 @@ public void postLoad() {
119119
}
120120
}
121121

122-
private void checkForUpdates(LoaderFrame loaderFrame) {
122+
private void checkForUpdates() {
123123
if (isUpdateChecked) {
124124
return;
125125
}
@@ -141,6 +141,7 @@ private void checkForUpdates(LoaderFrame loaderFrame) {
141141
Path selfFile = dataDir.resolve("stage1.jar");
142142

143143
if (!stage1Artifact.checksum.isMatching(selfFile)) {
144+
requestLoaderFrame();
144145
loaderFrame.updateMessage("Downloading OneConfig Loader stage 1...");
145146
stage1Artifact.downloadTo(getRequestHelper(), dataDir.resolve("stage1.update.jar"), loaderFrame::updateProgress);
146147

@@ -151,7 +152,7 @@ private void checkForUpdates(LoaderFrame loaderFrame) {
151152
}
152153

153154
@SneakyThrows
154-
private void maybeDownloadRelaunch(LoaderFrame loaderFrame) {
155+
private void maybeDownloadRelaunch() {
155156
if (isRelaunchDownloaded) {
156157
return;
157158
}
@@ -176,6 +177,7 @@ private void maybeDownloadRelaunch(LoaderFrame loaderFrame) {
176177
Path relaunchFile = dataDir.resolve("relaunch.jar");
177178

178179
if (!Files.exists(relaunchFile) || !relaunchArtifact.checksum.isMatching(relaunchFile)) {
180+
requestLoaderFrame();
179181
loaderFrame.updateMessage("Downloading OneConfig Loader Relaunch...");
180182
relaunchArtifact.downloadTo(getRequestHelper(), relaunchFile, loaderFrame::updateProgress);
181183
}
@@ -185,7 +187,7 @@ private void maybeDownloadRelaunch(LoaderFrame loaderFrame) {
185187
}
186188

187189
@SneakyThrows
188-
private void downloadOneConfigArtifacts(LoaderFrame loaderFrame) {
190+
private void downloadOneConfigArtifacts() {
189191
if (isOneConfigDownloaded) {
190192
return;
191193
}
@@ -232,6 +234,7 @@ private void downloadOneConfigArtifacts(LoaderFrame loaderFrame) {
232234
for (BackendArtifact artifact : artifacts) {
233235
Path artifactFile = dataDir.resolve(artifact.name + ".jar");
234236
if (!Files.exists(artifactFile) || !artifact.checksum.isMatching(artifactFile)) {
237+
requestLoaderFrame();
235238
loaderFrame.updateMessage("Downloading OneConfig artifact: " + artifact.name);
236239
artifact.downloadTo(getRequestHelper(), artifactFile, loaderFrame::updateProgress);
237240
}
@@ -283,6 +286,14 @@ private void downloadOneConfigArtifacts(LoaderFrame loaderFrame) {
283286
isOneConfigDownloaded = true;
284287
}
285288

289+
private void requestLoaderFrame() {
290+
if (this.loaderFrame == null) {
291+
log.info("Creating UI");
292+
loaderFrame = new LoaderFrame();
293+
loaderFrame.display();
294+
}
295+
}
296+
286297
@SneakyThrows
287298
private BackendArtifact readArtifactAt(String url) {
288299
URLConnection connection = getRequestHelper().establishConnection(URI.create(url).toURL());

0 commit comments

Comments
 (0)