11
11
import org .kettingpowered .ketting .internal .KettingFileVersioned ;
12
12
import org .kettingpowered .ketting .internal .KettingFiles ;
13
13
import org .kettingpowered .launcher .betterui .BetterUI ;
14
+ import org .kettingpowered .launcher .internal .utils .Hash ;
14
15
import org .kettingpowered .launcher .internal .utils .NetworkUtils ;
15
16
import org .kettingpowered .launcher .utils .Processors ;
16
17
18
+ import java .io .BufferedReader ;
19
+ import java .io .BufferedWriter ;
17
20
import java .io .File ;
18
21
import java .io .FileOutputStream ;
19
22
import java .io .FileReader ;
23
+ import java .io .FileWriter ;
20
24
import java .io .IOException ;
21
25
import java .io .PrintStream ;
26
+ import java .security .NoSuchAlgorithmException ;
22
27
import java .util .ArrayList ;
23
28
import java .util .HashMap ;
24
29
import java .util .List ;
@@ -32,7 +37,7 @@ public class Patcher {
32
37
private final PrintStream out = System .out ;
33
38
private PrintStream log ;
34
39
35
- public Patcher () throws IOException {
40
+ public Patcher () throws IOException , NoSuchAlgorithmException {
36
41
downloadServer ();
37
42
readInstallScript ();
38
43
prepareTokens ();
@@ -119,7 +124,7 @@ private void prepareTokens() {
119
124
tokens .put ("{BINPATCH}" , KettingFiles .SERVER_LZMA .getAbsolutePath ());
120
125
}
121
126
122
- private void readAndExecuteProcessors () throws IOException {
127
+ private void readAndExecuteProcessors () throws IOException , NoSuchAlgorithmException {
123
128
final File logFile = KettingFiles .PATCHER_LOGS ;
124
129
if (!logFile .exists ()) {
125
130
try {
@@ -182,6 +187,43 @@ public void write(int b) {
182
187
}
183
188
});
184
189
}
190
+ writeStoredHashes ();
191
+ }
192
+ private static void writeStoredHashes () throws IOException , NoSuchAlgorithmException {
193
+ try (BufferedWriter writer = new BufferedWriter (new FileWriter (KettingFiles .STORED_HASHES ))){
194
+ writer
195
+ .append ("installJson=" )
196
+ .append (Hash .getHash (KettingFileVersioned .FORGE_INSTALL_JSON , "SHA3-512" ))
197
+ .append ("\n serverLzma=" )
198
+ .append (Hash .getHash (KettingFiles .SERVER_LZMA , "SHA3-512" ))
199
+ .append ("\n server=" )
200
+ .append (Hash .getHash (KettingFileVersioned .SERVER_JAR , "SHA3-512" ));
201
+ }
202
+ }
203
+ public static boolean checkUpdateNeeded () {
204
+ if (!KettingFiles .STORED_HASHES .exists ()) return true ;
205
+ try (BufferedReader reader = new BufferedReader (new FileReader (KettingFiles .STORED_HASHES ))){
206
+ return !reader .lines ()
207
+ .allMatch (string -> {
208
+ String [] args = string .split ("=" );
209
+ String value = args [1 ].trim ();
210
+ try {
211
+ return switch (args [0 ].trim ()) {
212
+ case "installJson" ->
213
+ value .equals (Hash .getHash (KettingFileVersioned .FORGE_INSTALL_JSON , "SHA3-512" ));
214
+ case "serverLzma" ->
215
+ value .equals (Hash .getHash (KettingFiles .SERVER_LZMA , "SHA3-512" ));
216
+ case "server" ->
217
+ value .equals (Hash .getHash (KettingFileVersioned .SERVER_JAR , "SHA3-512" ));
218
+ default -> false ;
219
+ };
220
+ } catch (NoSuchAlgorithmException | IOException e ) {
221
+ return false ;
222
+ }
223
+ });
224
+ }catch (Exception ignored ) {
225
+ return true ;
226
+ }
185
227
}
186
228
187
229
private void mute () {
0 commit comments