22
33import dev .felnull .fnjl .os .OSs ;
44import dev .felnull .fnjl .os .OSs .Type ;
5+ import dev .felnull .imp .IMPConfig ;
6+ import dev .felnull .imp .IamMusicPlayer ;
57import dev .felnull .imp .client .lava .LavaNativeManager ;
68import java .io .*;
7- import java .net .HttpURLConnection ;
89import java .net .URI ;
10+ import java .net .http .HttpClient ;
11+ import java .net .http .HttpRequest ;
12+ import java .net .http .HttpResponse ;
13+ import java .nio .file .Path ;
14+ import java .nio .file .Paths ;
15+ import java .util .Objects ;
916import java .util .Optional ;
1017import org .apache .logging .log4j .LogManager ;
1118import org .apache .logging .log4j .Logger ;
19+ import org .jetbrains .annotations .NotNull ;
20+ import org .json .*;
1221
1322public class IMPRHash {
1423
15- private static final int READ_TIMEOUT = 30000 ; // 30 seconds
16- private static final int CONNECTION_TIMEOUT = 10000 ; // 10 seconds
17-
1824 private static final Logger LOGGER = LogManager .getLogger (IMPRHash .class );
1925
2026 public boolean FileIsValid () {
@@ -29,19 +35,21 @@ public boolean FileIsValid() {
2935 if (os == Type .MAC ) {
3036 return Mac (os , arch );
3137 } else {
32- LOGGER .error ("Your os is {}, with is unsuported " , os );
38+ LOGGER .error ("Your os is {}, with is unsupported " , os );
3339 return false ;
3440 }
3541 }
3642
37- private boolean Linux (Type os , String arch ) {
43+ private boolean Linux (@ NotNull Type os , String arch ) {
3844 String hash = HashUnix (os .toString (), Optional .of (arch ));
45+ Path file_path = Paths .get (
46+ IamMusicPlayer .getConfig ().IMPRFolder ,
47+ IamMusicPlayer .getConfig ().lavaNativesFolder ,
48+ os .toString (),
49+ arch
50+ );
3951 String file_hash = "" ; // TODO!
40- if (hash == file_hash ) {
41- return true ;
42- } else {
43- return false ;
44- }
52+ return Objects .equals (hash , file_hash );
4553 }
4654
4755 private boolean Mac (Type os , String arch ) {
@@ -85,26 +93,20 @@ private String HashUnix(String os, Optional<String> arch) {
8593 }
8694
8795 private String GetHash (String url ) throws Exception {
88- HttpURLConnection connection = (HttpURLConnection ) new URI (url )
89- .toURL ()
90- .openConnection ();
91- connection .setConnectTimeout (CONNECTION_TIMEOUT );
92- connection .setReadTimeout (READ_TIMEOUT );
93- connection .setRequestProperty ("User-Agent" , "IamMusicPlayer" );
94-
95- int responseCode = connection .getResponseCode ();
96- if (responseCode != 200 ) {
97- throw new IOException (
98- "Failed to download manifest. HTTP response code: " + responseCode
96+ try {
97+ HttpClient client = HttpClient .newHttpClient ();
98+ HttpRequest request = HttpRequest .newBuilder ()
99+ .uri (URI .create (url ))
100+ .GET ()
101+ .build ();
102+ HttpResponse <String > response = client .send (
103+ request ,
104+ HttpResponse .BodyHandlers .ofString ()
99105 );
100- }
101-
102- try (
103- BufferedReader reader = new BufferedReader (
104- new InputStreamReader (connection .getInputStream ())
105- )
106- ) {
107- return String .valueOf (reader );
106+ return response .body ();
107+ } catch (Exception e ) {
108+ LOGGER .fatal ("Something Failed during hash download: " + e );
109+ return null ;
108110 }
109111 }
110112}
0 commit comments