Skip to content

Commit 49c319a

Browse files
committed
improve the robustness of the update checker, plus RFB compat
1 parent b252491 commit 49c319a

21 files changed

+508
-138
lines changed

dependencies.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ dependencies {
77

88
compileOnly("org.jetbrains:annotations:24.0.1")
99

10+
compileOnly("com.gtnewhorizons.retrofuturabootstrap:RetroFuturaBootstrap:1.0.2")
11+
1012
//Mod deps
1113
def unimixinsVersion = "0.1.17"
1214
compileOnly("com.github.LegacyModdingMC.UniMixins:unimixins-all-1.7.10:$unimixinsVersion:dev")

repositories.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,11 @@ repositories {
1515
name = "repsy_ventooth"
1616
url = "https://repo.repsy.io/mvn/ventooth/public/"
1717
}
18+
maven {
19+
name = "horizon"
20+
url = "https://mvn.falsepattern.com/horizon/"
21+
content {
22+
includeGroup("com.gtnewhorizons.retrofuturabootstrap")
23+
}
24+
}
1825
}

src/main/java/com/falsepattern/lib/config/event/ConfigValidationFailureEvent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.falsepattern.lib.StableAPI;
2424
import com.falsepattern.lib.config.Config;
2525
import com.falsepattern.lib.internal.EventUtil;
26+
import com.falsepattern.lib.internal.FPLog;
2627
import com.falsepattern.lib.internal.Share;
2728
import com.falsepattern.lib.text.FormattedText;
2829
import com.falsepattern.lib.toasts.GuiToast;
@@ -131,7 +132,7 @@ public void logWarn() {
131132
}
132133
customText(errorString);
133134
for (val line : errorString.toString().split("\n")) {
134-
Share.LOG.error(line);
135+
FPLog.LOG.error(line);
135136
}
136137
}
137138

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (C) 2022-2023 FalsePattern
3+
* All Rights Reserved
4+
*
5+
* The above copyright notice and this permission notice
6+
* shall be included in all copies or substantial portions of the Software.
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*/
21+
22+
package com.falsepattern.lib.internal;
23+
24+
import lombok.AccessLevel;
25+
import lombok.NoArgsConstructor;
26+
import org.apache.logging.log4j.LogManager;
27+
import org.apache.logging.log4j.Logger;
28+
29+
@NoArgsConstructor(access = AccessLevel.PRIVATE)
30+
public final class FPLog {
31+
public static final Logger LOG = LogManager.getLogger(Tags.MODNAME);
32+
33+
public static void deprecatedWarning(Throwable stacktrace) {
34+
LOG.warn("DEPRECATED API CALLED!", stacktrace);
35+
}
36+
}

src/main/java/com/falsepattern/lib/internal/FalsePatternLib.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class FalsePatternLib {
5252
private static CommonProxy proxy;
5353

5454
public FalsePatternLib() {
55-
Share.LOG.info("Version " + Tags.VERSION + " initialized!");
55+
FPLog.LOG.info("Version " + Tags.VERSION + " initialized!");
5656
}
5757

5858
@Mod.EventHandler

src/main/java/com/falsepattern/lib/internal/Internet.java

Lines changed: 8 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,11 @@
4545
public class Internet {
4646
private static final Map<String, String> NO_HEADERS = Collections.emptyMap();
4747

48-
public static void connect(URL URL, Consumer<Exception> onError, Consumer<InputStream> onSuccess) {
49-
connect(URL, NO_HEADERS, onError, onSuccess);
48+
public static void connect(URL URL, Consumer<Exception> onError, Consumer<InputStream> onSuccess, Consumer<Long> contentLengthCallback) {
49+
connect(URL, NO_HEADERS, onError, onSuccess, contentLengthCallback);
5050
}
5151

52-
public static Map<String, String> constructHeaders(String... entries) {
53-
if (entries.length % 2 != 0) {
54-
throw new IllegalArgumentException("Entries must be in pairs");
55-
}
56-
val map = new java.util.HashMap<String, String>();
57-
for (int i = 0; i < entries.length; i += 2) {
58-
map.put(entries[i], entries[i + 1]);
59-
}
60-
return map;
61-
}
62-
63-
public static void connect(URL URL, Map<String, String> headers, Consumer<Exception> onError, Consumer<InputStream> onSuccess) {
52+
public static void connect(URL URL, Map<String, String> headers, Consumer<Exception> onError, Consumer<InputStream> onSuccess, Consumer<Long> contentLengthCallback) {
6453
try {
6554
val connection = (HttpURLConnection) URL.openConnection();
6655
connection.setConnectTimeout(3500);
@@ -85,6 +74,7 @@ public static void connect(URL URL, Map<String, String> headers, Consumer<Except
8574
if (connection.getResponseCode() != 200) {
8675
onError.accept(new Exception("HTTP response code " + connection.getResponseCode()));
8776
} else {
77+
contentLengthCallback.accept(connection.getContentLengthLong());
8878
onSuccess.accept(connection.getInputStream());
8979
}
9080
connection.disconnect();
@@ -103,57 +93,14 @@ public static void connect(URL URL, Map<String, String> headers, Consumer<Except
10393
}
10494
}
10595

106-
public static CompletableFuture<byte[]> download(URL... urls) {
107-
return CompletableFuture.supplyAsync(() -> {
108-
val result = new ByteArrayOutputStream();
109-
val caught = new AtomicReference<Exception>();
110-
val success = new AtomicBoolean(false);
111-
for (val url : urls) {
112-
connect(url, caught::set, (input) -> {
113-
try {
114-
transferAndClose(input, result);
115-
success.set(true);
116-
} catch (IOException e) {
117-
throw new CompletionException(e);
118-
}
119-
});
120-
if (success.get()) {
121-
return result.toByteArray();
122-
}
123-
}
124-
throw new CompletionException(caught.get());
125-
});
126-
}
127-
128-
public static CompletableFuture<Void> downloadFile(File file, URL... urls) {
129-
return CompletableFuture.runAsync(() -> {
130-
val caught = new AtomicReference<Exception>();
131-
val success = new AtomicBoolean(false);
132-
for (val url : urls) {
133-
connect(url, caught::set, (input) -> {
134-
try {
135-
@Cleanup val outputStream = Files.newOutputStream(file.toPath());
136-
transferAndClose(input, outputStream);
137-
success.set(true);
138-
} catch (IOException e) {
139-
throw new CompletionException(e);
140-
}
141-
});
142-
if (success.get()) {
143-
return;
144-
}
145-
}
146-
throw new CompletionException(caught.get());
147-
});
148-
}
149-
150-
151-
public static void transferAndClose(InputStream is, OutputStream target) throws IOException {
96+
public static void transferAndClose(InputStream is, OutputStream target, Consumer<Integer> downloadSizeCallback)
97+
throws IOException {
15298
var bytesRead = 0;
15399

154-
byte[] smallBuffer = new byte[4096];
100+
byte[] smallBuffer = new byte[256 * 1024];
155101
while ((bytesRead = is.read(smallBuffer)) >= 0) {
156102
target.write(smallBuffer, 0, bytesRead);
103+
downloadSizeCallback.accept(bytesRead);
157104
}
158105
target.close();
159106
is.close();

src/main/java/com/falsepattern/lib/internal/asm/CoreLoadingPlugin.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121
package com.falsepattern.lib.internal.asm;
2222

23+
import com.falsepattern.lib.internal.FPLog;
2324
import com.falsepattern.lib.internal.Share;
2425
import com.falsepattern.lib.internal.Tags;
2526
import com.falsepattern.lib.internal.impl.dependencies.DependencyLoaderImpl;
@@ -48,19 +49,19 @@ public class CoreLoadingPlugin implements IFMLLoadingPlugin {
4849
private static boolean obfuscated;
4950

5051
static {
51-
Share.LOG.info("Removing skill issues...");
52+
FPLog.LOG.info("Removing skill issues...");
5253
try {
5354
Class.forName("thermos.Thermos");
54-
Share.LOG.fatal("Sorry, i prefer iced coffee.");
55+
FPLog.LOG.fatal("Sorry, i prefer iced coffee.");
5556
throw skillIssue("Thermos is not supported by FalsePatternLib, please use a normal forge server.");
5657
} catch (ClassNotFoundException ignored) {
5758
}
5859
//Scan for dependencies now
59-
Share.LOG.info("Scanning for deps...");
60+
FPLog.LOG.info("Scanning for deps...");
6061
long start = System.nanoTime();
61-
DependencyLoaderImpl.scanDeps();
62+
DependencyLoaderImpl.executeDependencyLoading(true);
6263
long end = System.nanoTime();
63-
Share.LOG.info("Scanned in " + (end - start) / 1000000 + "ms");
64+
FPLog.LOG.info("Scanned in " + (end - start) / 1000000 + "ms");
6465
//Initializing the rest
6566
MappingManager.initialize();
6667
}
@@ -116,7 +117,7 @@ private static Error skillIssue(String message) {
116117
}
117118

118119
public static void validateGasStation() {
119-
Share.LOG.info("Got any gas?");
120+
FPLog.LOG.info("Got any gas?");
120121
//Make sure everything is loaded correctly, crash if gasstation is bugged
121122
// @formatter:off
122123
if (!isClassPresentSafe("com.falsepattern.gasstation.core.GasStationCore") //Validate core class
@@ -126,7 +127,7 @@ public static void validateGasStation() {
126127
|| !isClassPresentSafe("org.spongepowered.asm.lib.Opcodes") //Validate correct mixins class
127128
|| isClassPresentSafe("org.spongepowered.libraries.org.objectweb.asm.Opcodes")
128129
) {
129-
Share.LOG.fatal("Somebody put diesel in my gas tank!");
130+
FPLog.LOG.fatal("Somebody put diesel in my gas tank!");
130131
throw new Error("Failed to validate your GasStation mixin plugin installation. "
131132
+ "Please make sure you have the latest GasStation installed from the official source: "
132133
+ "https://github.com/FalsePattern/GasStation");
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (C) 2022-2023 FalsePattern
3+
* All Rights Reserved
4+
*
5+
* The above copyright notice and this permission notice
6+
* shall be included in all copies or substantial portions of the Software.
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*/
21+
22+
package com.falsepattern.lib.internal.asm;
23+
24+
import com.falsepattern.lib.internal.core.LowLevelCallMultiplexer;
25+
import com.falsepattern.lib.internal.impl.dependencies.DependencyLoaderImpl;
26+
import com.gtnewhorizons.retrofuturabootstrap.api.RfbPlugin;
27+
28+
public class RFBLoadingPlugin implements RfbPlugin {
29+
static {
30+
LowLevelCallMultiplexer.rfbDetected();
31+
DependencyLoaderImpl.executeDependencyLoading(false);
32+
}
33+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (C) 2022-2023 FalsePattern
3+
* All Rights Reserved
4+
*
5+
* The above copyright notice and this permission notice
6+
* shall be included in all copies or substantial portions of the Software.
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*/
21+
22+
package com.falsepattern.lib.internal.config;
23+
24+
import com.falsepattern.lib.StableAPI;
25+
import com.falsepattern.lib.internal.core.LowLevelCallMultiplexer;
26+
import com.google.gson.Gson;
27+
import com.google.gson.annotations.Expose;
28+
import lombok.Data;
29+
import lombok.SneakyThrows;
30+
import lombok.experimental.Accessors;
31+
import lombok.val;
32+
33+
import java.io.FileInputStream;
34+
import java.io.InputStreamReader;
35+
import java.nio.charset.StandardCharsets;
36+
import java.nio.file.Files;
37+
38+
//For stuff that runs before FML does
39+
@Data
40+
@Accessors(fluent = true)
41+
public class EarlyConfig {
42+
@Expose
43+
@StableAPI.Expose(since = "__INTERNAL__")
44+
private boolean enableLibraryDownloads;
45+
46+
private static EarlyConfig instance = null;
47+
48+
@SneakyThrows
49+
public static EarlyConfig load() {
50+
if (instance != null)
51+
return instance;
52+
val configFile = LowLevelCallMultiplexer.gameDir().resolve("config").resolve("falsepatternlib-early.json");
53+
val gson = new Gson();
54+
EarlyConfig config;
55+
if (!Files.exists(configFile)) {
56+
config = new EarlyConfig();
57+
config.enableLibraryDownloads(true);
58+
} else {
59+
config = gson.fromJson(new String(Files.readAllBytes(configFile), StandardCharsets.UTF_8), EarlyConfig.class);
60+
}
61+
Files.write(configFile, gson.toJson(config).getBytes(StandardCharsets.UTF_8));
62+
instance = config;
63+
return config;
64+
}
65+
}

src/main/java/com/falsepattern/lib/internal/config/InGameModOptionsFix.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.falsepattern.lib.internal.config;
22

3+
import com.falsepattern.lib.internal.FPLog;
34
import com.falsepattern.lib.internal.Share;
45
import lombok.AccessLevel;
56
import lombok.NoArgsConstructor;
@@ -37,7 +38,7 @@ public static void init() {
3738
MODS_FIELD.setAccessible(true);
3839
} catch (NoSuchFieldException e) {
3940
MODS_FIELD = null;
40-
Share.LOG.error("Failed to get field: cpw.mods.fml.client.GuiModList.mods,"
41+
FPLog.LOG.error("Failed to get field: cpw.mods.fml.client.GuiModList.mods,"
4142
+ " In-Game Mod Options Fix will not work", e);
4243
return;
4344
}

0 commit comments

Comments
 (0)