Skip to content

Commit f00b603

Browse files
committed
Erase Version History.
1 parent 73fb8bd commit f00b603

21 files changed

Lines changed: 354 additions & 58 deletions

.github/workflows/gradle.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: Java CI
22

3+
permissions:
4+
actions: write
5+
36
on:
47
push:
58
pull_request:
@@ -33,3 +36,12 @@ jobs:
3336
with:
3437
name: HMCL-${{ env.SHORT_SHA }}
3538
path: HMCL/build/libs
39+
- name: 'PR Collection: Trigger CI'
40+
if: ${{ github.event_name == 'push' }}
41+
run: |
42+
branch=$(git branch --show-current)
43+
if [ "$branch" = "prs" ]; then
44+
gh workflow --repo burningtnt/HMCL-Snapshot-Update run check.yml
45+
fi
46+
env:
47+
GH_TOKEN: ${{ secrets.HMCL_PR_COLLECTION_GITHUB_TOKEN }}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package net.burningtnt.hmclprs;
2+
3+
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
4+
5+
public final class Constants {
6+
private Constants() {
7+
}
8+
9+
public static final FinalValue<String> DEFAULT_FULL_NAME = new FinalValue<>();
10+
11+
public static final FinalValue<String> DEFAULT_VERSION = new FinalValue<>();
12+
13+
public static final String PR_COLLECTION_SUFFIX = " (PR Collection)";
14+
15+
public static final String HOME_PAGE = "https://github.com/burningtnt/HMCL/pull/9";
16+
17+
public static final String UPDATE_LINK = "https://hmcl-snapshot-update-73w.pages.dev/redirect/v1/type/pr-collection";
18+
19+
public static final String[] UPDATE_FALLBACKS = {
20+
"https://cdn.crashmc.com/https://raw.githubusercontent.com/burningtnt/HMCL-Snapshot-Update/v5/artifacts/v5/uploaders/local-storage.proxy.crashmc/burningtnt/HMCL/prs/gradle.yml.jar.json"
21+
};
22+
23+
public static final boolean SHOULD_DISPLAY_LAUNCH_WARNING = shouldDisplayWarningMessage("hmcl.pr.warning", "HMCL_PR_WARNING");
24+
25+
public static String getWarningTitle() {
26+
return i18n("prs.title");
27+
}
28+
29+
public static String getWarningBody() {
30+
return i18n("prs.warning", HOME_PAGE);
31+
}
32+
33+
private static boolean shouldDisplayWarningMessage(String propertyKey, String envKey) {
34+
String p1 = System.getProperty(propertyKey);
35+
if (p1 != null) {
36+
switch (p1) {
37+
case "ignore": {
38+
return false;
39+
}
40+
case "display": {
41+
return true;
42+
}
43+
default: {
44+
throw new IllegalArgumentException(String.format("Property %s should only be 'ignore', 'display', or null.", propertyKey));
45+
}
46+
}
47+
}
48+
49+
String p2 = System.getenv(envKey);
50+
if (p2 == null) {
51+
return true;
52+
}
53+
switch (p2) {
54+
case "ignore": {
55+
return false;
56+
}
57+
case "display": {
58+
return true;
59+
}
60+
default: {
61+
throw new IllegalArgumentException(String.format("Environmental argument %s should only be 'ignore', 'display', or null.", envKey));
62+
}
63+
}
64+
}
65+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package net.burningtnt.hmclprs;
2+
3+
public final class FinalValue<T> {
4+
private volatile T value;
5+
6+
public FinalValue() {
7+
}
8+
9+
public T getValue() {
10+
T v = value;
11+
if (v == null) {
12+
throw new IllegalStateException("Final Value hasn't been initialized.");
13+
}
14+
return v;
15+
}
16+
17+
public void setValue(T v) {
18+
synchronized (this) {
19+
if (value != null) {
20+
throw new IllegalStateException("Final Value has been initialized.");
21+
}
22+
this.value = v;
23+
}
24+
}
25+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package net.burningtnt.hmclprs.hooks;
2+
3+
import net.burningtnt.hmclprs.Constants;
4+
import net.burningtnt.hmclprs.patch.Inject;
5+
import net.burningtnt.hmclprs.patch.Redirect;
6+
import net.burningtnt.hmclprs.patch.ValueMutation;
7+
8+
import javax.swing.*;
9+
10+
public final class PRCollectionBootstrap {
11+
private PRCollectionBootstrap() {
12+
}
13+
14+
@Inject
15+
public static void onApplicationLaunch() {
16+
if (Constants.SHOULD_DISPLAY_LAUNCH_WARNING && JOptionPane.showConfirmDialog(
17+
null, Constants.getWarningBody(), Constants.getWarningTitle(), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE
18+
) != JOptionPane.OK_OPTION) {
19+
System.exit(1);
20+
}
21+
}
22+
23+
@ValueMutation
24+
public static String onInitApplicationName(String name) {
25+
return name + Constants.PR_COLLECTION_SUFFIX;
26+
}
27+
28+
@ValueMutation
29+
public static String onInitApplicationFullName(String fullName) {
30+
Constants.DEFAULT_FULL_NAME.setValue(fullName);
31+
return fullName + Constants.PR_COLLECTION_SUFFIX;
32+
}
33+
34+
@ValueMutation
35+
public static String onInitApplicationVersion(String version) {
36+
Constants.DEFAULT_VERSION.setValue(version);
37+
return version + Constants.PR_COLLECTION_SUFFIX;
38+
}
39+
40+
@Redirect
41+
public static String onInitApplicationTitle() {
42+
return Constants.DEFAULT_FULL_NAME.getValue() + " v" + Constants.DEFAULT_VERSION.getValue() + Constants.PR_COLLECTION_SUFFIX;
43+
}
44+
45+
@Redirect
46+
public static String onInitApplicationPublishURL() {
47+
return Constants.HOME_PAGE;
48+
}
49+
50+
@Redirect
51+
public static String onInitApplicationDefaultUpdateLink() {
52+
return Constants.UPDATE_LINK;
53+
}
54+
55+
@Inject
56+
public static void importRef(Class<?>... clazz) {
57+
}
58+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package net.burningtnt.hmclprs.hooks;
2+
3+
import javafx.collections.ObservableList;
4+
import javafx.scene.Node;
5+
import javafx.scene.control.Label;
6+
import javafx.scene.layout.BorderPane;
7+
import javafx.scene.layout.VBox;
8+
import javafx.scene.text.TextFlow;
9+
import net.burningtnt.hmclprs.Constants;
10+
import net.burningtnt.hmclprs.patch.Inject;
11+
import net.burningtnt.hmclprs.patch.Redirect;
12+
import net.burningtnt.hmclprs.patch.ValueMutation;
13+
import org.jackhuang.hmcl.game.DefaultGameRepository;
14+
import org.jackhuang.hmcl.task.FileDownloadTask;
15+
import org.jackhuang.hmcl.ui.Controllers;
16+
import org.jackhuang.hmcl.ui.FXUtils;
17+
import org.jackhuang.hmcl.ui.animation.ContainerAnimations;
18+
import org.jackhuang.hmcl.ui.animation.TransitionPane;
19+
import org.jackhuang.hmcl.upgrade.RemoteVersion;
20+
import org.jackhuang.hmcl.util.Lang;
21+
import org.jackhuang.hmcl.util.Pair;
22+
import org.jackhuang.hmcl.util.io.Zipper;
23+
24+
import java.io.IOException;
25+
import java.net.MalformedURLException;
26+
import java.net.URL;
27+
import java.util.Arrays;
28+
import java.util.Collections;
29+
import java.util.List;
30+
import java.util.Objects;
31+
import java.util.stream.Collectors;
32+
import java.util.stream.Stream;
33+
34+
public final class PRCollectionRuntime {
35+
private PRCollectionRuntime() {
36+
}
37+
38+
@Redirect
39+
public static String onGetApplicationRawVersion() {
40+
return Constants.DEFAULT_VERSION.getValue();
41+
}
42+
43+
@ValueMutation
44+
public static String onInitDisableSelfIntegrityCheckProperty(String value) {
45+
return value == null ? "true" : value;
46+
}
47+
48+
@Redirect
49+
public static TransitionPane onBuildAnnouncementPane(ObservableList<Node> nodes) {
50+
if (!Constants.SHOULD_DISPLAY_LAUNCH_WARNING) {
51+
return null;
52+
}
53+
54+
VBox card = new VBox();
55+
56+
BorderPane title = new BorderPane();
57+
title.getStyleClass().add("title");
58+
title.setLeft(new Label(Constants.getWarningTitle()));
59+
60+
TextFlow body = FXUtils.segmentToTextFlow(Constants.getWarningBody(), Controllers::onHyperlinkAction);
61+
body.setLineSpacing(4);
62+
63+
card.getChildren().setAll(title, body);
64+
card.setSpacing(16);
65+
card.getStyleClass().addAll("card", "announcement");
66+
67+
VBox box = new VBox(16);
68+
box.getChildren().add(card);
69+
70+
TransitionPane pane = new TransitionPane();
71+
pane.setContent(box, ContainerAnimations.NONE);
72+
73+
nodes.add(pane);
74+
return pane;
75+
}
76+
77+
@Redirect
78+
public static List<String> prepareFallbackURLs(RemoteVersion rv) {
79+
if (rv.getChannel() == null) {
80+
return Collections.emptyList();
81+
}
82+
83+
return Arrays.stream(Constants.UPDATE_FALLBACKS).parallel().map(s -> {
84+
try {
85+
RemoteVersion r = RemoteVersion.fetch(null, s);
86+
FileDownloadTask.IntegrityCheck r1 = r.getIntegrityCheck(), r2 = rv.getIntegrityCheck();
87+
if (!Objects.equals(r1.getAlgorithm(), r2.getAlgorithm()) || !Objects.equals(r1.getChecksum(), r2.getChecksum())) {
88+
return null;
89+
}
90+
91+
return r.getUrl();
92+
} catch (IOException e) {
93+
return null;
94+
}
95+
}).filter(Objects::nonNull).collect(Collectors.toList());
96+
}
97+
98+
@Redirect
99+
public static List<URL> onGetRemoteVersionUpdateLinks(RemoteVersion rv) {
100+
return Stream.concat(Stream.of(rv.getUrl()), rv.prc$fallbackURL.stream()).map(s -> {
101+
try {
102+
return new URL(s);
103+
} catch (MalformedURLException e) {
104+
return null;
105+
}
106+
}).filter(Objects::nonNull).collect(Collectors.toList());
107+
}
108+
109+
@Inject
110+
public static void onCreateUpgradeDialog() {
111+
throw new UnsupportedOperationException("UpdateDialog has been deprecated");
112+
}
113+
114+
@Inject
115+
public static void onCreateGameCrashReport(DefaultGameRepository repository, String versionID, Zipper zipper) throws IOException {
116+
zipper.putTextFile(Lang.mapOf(
117+
Pair.pair(
118+
"launcher",
119+
repository.getVersion(versionID).getPatches().stream().anyMatch(v -> "game".equals(v.getId())) ? "HMCL" : "OTHERS"
120+
)
121+
).entrySet().stream().map(e -> e.getKey() + ": " + e.getValue()).collect(Collectors.joining("\n")), ".pr-collection.log");
122+
}
123+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package net.burningtnt.hmclprs.patch;
2+
3+
import java.lang.annotation.*;
4+
5+
@Documented
6+
@Retention(RetentionPolicy.SOURCE)
7+
@Target(ElementType.METHOD)
8+
public @interface Inject {
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package net.burningtnt.hmclprs.patch;
2+
3+
import java.lang.annotation.*;
4+
5+
@Documented
6+
@Retention(RetentionPolicy.SOURCE)
7+
@Target(ElementType.METHOD)
8+
public @interface Redirect {
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package net.burningtnt.hmclprs.patch;
2+
3+
import java.lang.annotation.*;
4+
5+
@Documented
6+
@Retention(RetentionPolicy.SOURCE)
7+
@Target(ElementType.METHOD)
8+
public @interface ValueMutation {
9+
}

HMCL/src/main/java/org/jackhuang/hmcl/Main.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ private Main() {
5454
}
5555

5656
public static void main(String[] args) {
57+
net.burningtnt.hmclprs.hooks.PRCollectionBootstrap.onApplicationLaunch();
58+
5759
System.getProperties().putIfAbsent("java.net.useSystemProxies", "true");
5860
System.getProperties().putIfAbsent("javafx.autoproxy.disable", "true");
5961
System.getProperties().putIfAbsent("http.agent", "HMCL/" + Metadata.VERSION);

HMCL/src/main/java/org/jackhuang/hmcl/Metadata.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@
3030
public final class Metadata {
3131
private Metadata() {}
3232

33-
public static final String NAME = "HMCL";
34-
public static final String FULL_NAME = "Hello Minecraft! Launcher";
35-
public static final String VERSION = System.getProperty("hmcl.version.override", JarUtils.getManifestAttribute("Implementation-Version", "@develop@"));
33+
public static final String NAME = net.burningtnt.hmclprs.hooks.PRCollectionBootstrap.onInitApplicationName("HMCL");
34+
public static final String FULL_NAME = net.burningtnt.hmclprs.hooks.PRCollectionBootstrap.onInitApplicationFullName("Hello Minecraft! Launcher");
35+
public static final String VERSION = net.burningtnt.hmclprs.hooks.PRCollectionBootstrap.onInitApplicationVersion(System.getProperty("hmcl.version.override", JarUtils.getManifestAttribute("Implementation-Version", "@develop@")));
3636

3737
public static final String TITLE = NAME + " " + VERSION;
38-
public static final String FULL_TITLE = FULL_NAME + " v" + VERSION;
38+
public static final String FULL_TITLE = net.burningtnt.hmclprs.hooks.PRCollectionBootstrap.onInitApplicationTitle();
3939

40-
public static final String PUBLISH_URL = "https://hmcl.huangyuhui.net";
40+
public static final String PUBLISH_URL = net.burningtnt.hmclprs.hooks.PRCollectionBootstrap.onInitApplicationPublishURL();;
4141
public static final String ABOUT_URL = PUBLISH_URL + "/about";
4242
public static final String DOWNLOAD_URL = PUBLISH_URL + "/download";
43-
public static final String HMCL_UPDATE_URL = System.getProperty("hmcl.update_source.override", PUBLISH_URL + "/api/update_link");
43+
public static final String HMCL_UPDATE_URL = System.getProperty("hmcl.update_source.override", net.burningtnt.hmclprs.hooks.PRCollectionBootstrap.onInitApplicationDefaultUpdateLink());
4444

4545
public static final String DOCS_URL = "https://docs.hmcl.net";
4646
public static final String CONTACT_URL = DOCS_URL + "/help.html";

0 commit comments

Comments
 (0)