11package fr .jachou .jvm ;
22
3- import java .io .File ;
4- import java .io .IOException ;
3+ import fr .jachou .jvm .managers .utils .JavaVersionList ;
4+ import fr .jachou .jvm .ui .JVMGui ;
5+ import fr .jachou .jvm .utils .CustomOutputStream ;
6+ import fr .jachou .jvm .utils .Logger ;
7+
8+ import javax .swing .*;
9+ import java .io .*;
510import java .net .URL ;
611import java .nio .file .Files ;
712import java .nio .file .Path ;
813import java .nio .file .Paths ;
914import java .nio .file .StandardCopyOption ;
15+ import java .util .Objects ;
1016import java .util .Scanner ;
1117import java .util .zip .ZipEntry ;
1218import java .util .zip .ZipInputStream ;
@@ -18,7 +24,7 @@ public class JavaVersionDownloader {
1824 * Colors class
1925 * This class is used to color the text in the console
2026 */
21- static class Colors {
27+ public static class Colors {
2228 public static final String HEADER = "\033 [95m" ;
2329 public static final String OKBLUE = "\033 [94m" ;
2430 public static final String OKCYAN = "\033 [96m" ;
@@ -36,29 +42,62 @@ static class Colors {
3642 */
3743
3844 public static void main (String [] args ) {
39- boolean loop = true ;
40-
41- while (loop ) {
42- Scanner scanner = new Scanner (System .in );
43-
44- // Message JVM = JavaVersionManager
45- System .out .println (Colors .HEADER + " \n "
46- + "____________ ________ ___\n "
47- + "______ /__ | / /___ |/ /\n "
48- + "___ _ / __ | / / __ /|_/ /\n "
49- + "/ /_/ / __ |/ / _ / / / \n "
50- + "\\ ____/ _____/ /_/ /_/ \n "
51- + " \n " );
52-
53- try {
54- System .out .print (Colors .OKCYAN + "Choose your version (only number) : " );
55- int version = Integer .parseInt (scanner .nextLine ());
56- downloader (version );
57- } catch (NumberFormatException e ) {
58- System .out .println (Colors .FAIL + "You must enter an integer!" );
45+
46+ if (args != null ) {
47+ if (Objects .equals (args [0 ], "-p" ) || Objects .equals (args [0 ], "--python" )) {
48+ Logger .log ("Python mod enabled!" );
49+
50+ String pythonFile = "src/main/java/fr/jachou/jvm/py/java_dl.py" ;
51+
52+ try {
53+ Runtime runtime = Runtime .getRuntime ();
54+ Process process = runtime .exec ("python " + pythonFile );
55+
56+ // Lire la sortie du processus Python
57+ InputStream inputStream = process .getInputStream ();
58+ BufferedReader reader = new BufferedReader (new InputStreamReader (inputStream ));
59+ String line ;
60+ while ((line = reader .readLine ()) != null ) {
61+ System .out .println (line );
62+ }
63+
64+ // Attendre que le processus Python se termine
65+ int exitCode = process .waitFor ();
66+ System .out .println ("Le processus Python s'est terminé avec le code de sortie : " + exitCode );
67+ } catch (IOException | InterruptedException e ) {
68+ e .printStackTrace ();
69+ }
70+ } else if (Objects .equals (args [0 ], "-g" ) || Objects .equals (args [0 ], "--gui" )) {
71+ Logger .log ("GUI mod enabled!" );
72+
73+ new JVMGui ();
5974 }
75+ } else {
76+ boolean loop = true ;
6077
61- System .out .println ();
78+ while (loop ) {
79+ // Message JVM = JavaVersionManager
80+ System .out .println (Colors .HEADER + " \n "
81+ + "____________ ________ ___\n "
82+ + "______ /__ | / /___ |/ /\n "
83+ + "___ _ / __ | / / __ /|_/ /\n "
84+ + "/ /_/ / __ |/ / _ / / / \n "
85+ + "\\ ____/ _____/ /_/ /_/ \n "
86+ + " \n " );
87+
88+ try {
89+ System .out .print (Colors .OKCYAN + "Choose your version (only number) : " );
90+ Scanner scanner = new Scanner (System .in );
91+ int version = Integer .parseInt (scanner .nextLine ());
92+ if (version == 0 ) {
93+ Logger .log ("Exiting..." );
94+ System .exit (0 );
95+ }
96+ downloader (version );
97+ } catch (NumberFormatException e ) {
98+ System .out .println (Colors .FAIL + "You must enter an integer!" );
99+ }
100+ }
62101 }
63102 }
64103
@@ -68,6 +107,16 @@ public static void main(String[] args) {
68107 */
69108
70109 private static void downloader (int version ) {
110+ try {
111+ String versionString = "Java_" + version ;
112+ JavaVersionList .valueOf (versionString );
113+ } catch (IllegalArgumentException e ) {
114+ System .out .println (Colors .FAIL + "[X] The version " + version + " does not exist!" );
115+ return ;
116+ }
117+
118+ Logger .logPass ("The version " + version + " exists!" );
119+
71120 System .out .print (Colors .BOLD + "[~] Checking if the link is good..." );
72121 String url = String .format ("https://chiss.fr/jvm/download/Java_%d.zip" , version );
73122 try {
@@ -103,6 +152,7 @@ private static void downloader(int version) {
103152 Thread .sleep (1000 );
104153 } catch (IOException e ) {
105154 System .out .println (Colors .FAIL + "[X] The link does not exist!" );
155+ e .printStackTrace ();
106156 } catch (InterruptedException e ) {
107157 e .printStackTrace ();
108158 }
0 commit comments