Skip to content

Commit 77d315d

Browse files
committed
Add mcversion.txt fallback
1 parent 7381d43 commit 77d315d

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

src/main/java/org/kettingpowered/launcher/info/MCVersion.java

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package org.kettingpowered.launcher.info;
22

3+
import org.jetbrains.annotations.Nullable;
34
import org.kettingpowered.ketting.internal.KettingFiles;
45
import org.kettingpowered.ketting.internal.MajorMinorPatchVersion;
56
import org.kettingpowered.ketting.internal.Tuple;
67
import org.kettingpowered.launcher.ParsedArgs;
78
import org.kettingpowered.launcher.utils.FileUtils;
89

9-
import java.io.BufferedReader;
10-
import java.io.File;
11-
import java.io.IOException;
12-
import java.io.InputStream;
13-
import java.io.InputStreamReader;
10+
import java.io.*;
1411
import java.util.ArrayList;
1512
import java.util.Arrays;
1613
import java.util.Comparator;
@@ -28,6 +25,21 @@ public class MCVersion {
2825
private static String mc;
2926
public static String getMc(ParsedArgs args){
3027
if (mc != null) return mc;
28+
29+
//Check for a mcversion.txt file, this has priority
30+
{
31+
File mcversion = new File(KettingFiles.MAIN_FOLDER_FILE, "mcversion.txt");
32+
if (mcversion.exists()){
33+
try {
34+
String version = readFromIS(new FileInputStream(mcversion));
35+
if (version != null) {
36+
mc = version;
37+
return mc;
38+
}
39+
} catch (FileNotFoundException ignored) {} //File is known to exist, so this should never happen.
40+
}
41+
}
42+
3143
//If you want to manually specify the version
3244
//via args
3345
if (args.minecraftVersion() != null) {
@@ -55,12 +67,10 @@ public static String getMc(ParsedArgs args){
5567
//Get the last saved mc version
5668
{
5769
final InputStream mcv = MCVersion.class.getResourceAsStream("/minecraftVersion");
58-
if (mcv != null){
59-
try (BufferedReader reader = new BufferedReader(new InputStreamReader(mcv))){
60-
mc = reader.readLine().trim();
61-
return mc;
62-
} catch (IOException ignored) {
63-
}
70+
String version = readFromIS(mcv);
71+
if (version != null) {
72+
mc = version;
73+
return mc;
6474
}
6575
}
6676
//Get the version via mcp mappings, since they are not wiped.
@@ -90,4 +100,13 @@ public static String getMc(ParsedArgs args){
90100
System.exit(1);
91101
throw new RuntimeException();//bogus, but has to be there to stop the compiler from complaining, that there is no return value here.
92102
}
103+
104+
private static String readFromIS(@Nullable InputStream versionStream) {
105+
if (versionStream == null) return null;
106+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(versionStream))){
107+
return reader.readLine().trim();
108+
} catch (IOException ignored) {
109+
return null;
110+
}
111+
}
93112
}

0 commit comments

Comments
 (0)