Skip to content

Commit 5a5a2a6

Browse files
committed
Move stage1 assets to separate loader-assets jar
1 parent ea43386 commit 5a5a2a6

File tree

11 files changed

+85
-15
lines changed

11 files changed

+85
-15
lines changed

loader-assets/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version = "1.1.0-alpha.1"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.polyfrost.oneconfig.loader.assets;
2+
3+
/**
4+
* Dummy class
5+
*/
6+
public class AssetsImpl {
7+
}

stage1/src/main/resources/assets/oneconfig-loader/Poppins-Regular.ttf renamed to loader-assets/src/main/resources/assets/oneconfig-loader/Poppins-Regular.ttf

File renamed without changes.

stage1/src/main/resources/assets/oneconfig-loader/oneconfig-icon.png renamed to loader-assets/src/main/resources/assets/oneconfig-loader/oneconfig-icon.png

File renamed without changes.

stage1/src/main/resources/assets/oneconfig-loader/oneconfig.png renamed to loader-assets/src/main/resources/assets/oneconfig-loader/oneconfig.png

File renamed without changes.

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ include("common")
3333
include("stage0")
3434
include("relaunch")
3535
include("stage1")
36+
include("loader-assets")

stage0/build.gradle.kts

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

3-
version = "1.1.0-alpha.53"
3+
version = "1.1.0-alpha.54"
44

55
val include by configurations
66

77
dependencies {
88
include(projects.common)
9-
include("com.github.zafarkhaja:java-semver:0.10.2")
109

1110
@Suppress("RedundantSuppression", "VulnerableLibrariesLocal")
1211
compileOnly("net.minecraft:launchwrapper:1.12")

stage0/src/main/java/org/polyfrost/oneconfig/loader/stage0/Stage0Loader.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import java.util.jar.JarInputStream;
1212
import java.util.jar.Manifest;
1313

14-
import com.github.zafarkhaja.semver.Version;
1514
import lombok.SneakyThrows;
1615

1716
import org.polyfrost.oneconfig.loader.base.Capabilities;
@@ -117,7 +116,7 @@ private Path lookupStage1() throws IOException {
117116
Files.createDirectories(dataDir);
118117

119118
URL latestUrl = null;
120-
Version latestVersion = null;
119+
Integer latestVersion = null;
121120

122121
if (Files.exists(stage1File)) {
123122
latestVersion = getJarVersion(stage1File.toUri().toURL());
@@ -130,14 +129,14 @@ private Path lookupStage1() throws IOException {
130129

131130
while (resources.hasMoreElements()) {
132131
URL url = resources.nextElement();
133-
Version version = getJarVersion(url);
132+
Integer version = getJarVersion(url);
134133
logger.info("Found stage1 at {} with version {}", url, version);
135134

136135
if (version == null) {
137136
continue;
138137
}
139138

140-
if (latestVersion == null || version.isHigherThan(latestVersion)) {
139+
if (latestVersion == null || version > latestVersion) {
141140
latestUrl = url;
142141
latestVersion = version;
143142
}
@@ -154,7 +153,7 @@ private Path lookupStage1() throws IOException {
154153
}
155154

156155
@SneakyThrows
157-
public static Version getJarVersion(URL jarFile) {
156+
public static Integer getJarVersion(URL jarFile) {
158157
try (JarInputStream inputStream = new JarInputStream(jarFile.openStream(), false)) {
159158
Manifest manifest = inputStream.getManifest();
160159
if (manifest == null) {
@@ -166,7 +165,7 @@ public static Version getJarVersion(URL jarFile) {
166165
return null;
167166
}
168167

169-
return Version.parse(version);
168+
return Integer.parseInt(version.substring(version.lastIndexOf('.') + 1));
170169
}
171170
}
172171

stage1/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = "1.1.0-alpha.53" // When you bump this, you should also bump stage0, cause stage0 includes a copy of stage1 too
1+
version = "54" // 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
@@ -30,7 +30,7 @@ dependencies {
3030
tasks.jar {
3131
manifest {
3232
attributes(
33-
"Implementation-Version" to version,
33+
"Implementation-Version" to "999.999.999-alpha.$version", // Compat with old versions of stage0
3434
)
3535
}
3636
}

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.polyfrost.oneconfig.loader.relaunch.Relaunch;
3535
import org.polyfrost.oneconfig.loader.stage1.backend.BackendArtifact;
3636
import org.polyfrost.oneconfig.loader.stage1.ui.LoaderFrame;
37+
import org.polyfrost.oneconfig.loader.stage1.ui.Resources;
3738
import org.polyfrost.oneconfig.loader.utils.IOUtils;
3839
import org.polyfrost.oneconfig.loader.utils.XDG;
3940

@@ -55,13 +56,16 @@ public class Stage1Loader extends LoaderBase {
5556
propertyOf("oneconfig.loader.stage1.update.snapshots", false);
5657
private static final Property<Boolean> RELAUNCH_ARTIFACT_SNAPSHOTS =
5758
propertyOf("oneconfig.loader.stage1.relaunch.snapshots", false);
59+
private static final Property<Boolean> ASSETS_ARTIFACT_SNAPSHOTS =
60+
propertyOf("oneconfig.loader.stage1.assets.snapshots", false);
5861
private static final Property<Boolean> ONECONFIG_ARTIFACT_SNAPSHOTS =
5962
propertyOf("oneconfig.loader.stage1.oneconfig.snapshots", false);
6063
private static final Property<Boolean> IGNORE_UPDATES =
6164
propertyOf("oneconfig.loader.stage1.ignoreupdates", false);
6265

6366
private static boolean isUpdateChecked = false;
6467
private static boolean isRelaunchDownloaded = false;
68+
private static boolean isAssetsDownloaded = false;
6569
private static boolean isOneConfigDownloaded = false;
6670

6771
private Class<?> oneconfigMainClass;
@@ -105,6 +109,14 @@ public void load() {
105109
String targetSpecifier = gameMetadata.getTargetSpecifier();
106110
log.info("Target specifier: {}", targetSpecifier);
107111

112+
try {
113+
downloadAssetsArtifact();
114+
Resources.loadAssetsClass(runtimeAccess);
115+
} catch (Exception e) {
116+
log.error("Failed to load assets, continuing without them", e);
117+
}
118+
119+
// Loader frame requested from this point on
108120
checkForUpdates();
109121
maybeDownloadRelaunch();
110122
downloadOneConfigArtifacts();
@@ -219,6 +231,42 @@ private void maybeDownloadRelaunch() {
219231
isRelaunchDownloaded = true;
220232
}
221233

234+
@SneakyThrows
235+
private void downloadAssetsArtifact() {
236+
if (isAssetsDownloaded) {
237+
return;
238+
}
239+
240+
Capabilities capabilities = getCapabilities();
241+
Capabilities.RuntimeAccess runtimeAccess = capabilities.getRuntimeAccess();
242+
243+
boolean usingAssetsSnapshots = shouldUseSnapshots(ASSETS_ARTIFACT_SNAPSHOTS);
244+
BackendArtifact assetsArtifact = null;
245+
if (!IGNORE_UPDATES.get()) {
246+
assetsArtifact = readArtifactAt("https://api.polyfrost.org/v1/artifacts/loader-assets?snapshots=" + usingAssetsSnapshots);
247+
if (assetsArtifact == null) {
248+
// Retry with the opposite snapshot setting
249+
assetsArtifact = readArtifactAt("https://api.polyfrost.org/v1/artifacts/loader-assets?snapshots=" + !usingAssetsSnapshots);
250+
if (assetsArtifact == null) {
251+
throw new RuntimeException("Failed to fetch loader assets artifact");
252+
}
253+
}
254+
}
255+
256+
Path dataDir = XDG
257+
.provideCacheDir("OneConfig")
258+
.resolve("loader")
259+
.resolve("data");
260+
Path assetsFile = dataDir.resolve("loader-assets.jar");
261+
262+
if (!IGNORE_UPDATES.get() && (!Files.exists(assetsFile) || !assetsArtifact.checksum.isMatching(assetsFile))) {
263+
assetsArtifact.downloadTo(getRequestHelper(), assetsFile, (ignored) -> {});
264+
}
265+
266+
runtimeAccess.appendToClassPath("loader-assets", false, assetsFile.toUri().toURL());
267+
isAssetsDownloaded = true;
268+
}
269+
222270
@SneakyThrows
223271
private void downloadOneConfigArtifacts() {
224272
if (isOneConfigDownloaded) {

0 commit comments

Comments
 (0)