44import org .fusesource .jansi .Ansi ;
55import org .fusesource .jansi .AnsiConsole ;
66import org .mcphackers .mcp .tasks .info .TaskInfo ;
7- import org .mcphackers .mcp .tools .Util ;
87import org .mcphackers .mcp .tools .VersionsParser ;
98
109import java .io .IOException ;
11- import java .net .URISyntaxException ;
1210import java .nio .file .Files ;
1311import java .nio .file .Paths ;
1412import java .util .*;
1513
1614public class MCP {
1715
18- public static final String VERSION = "Test " ;
16+ public static final String VERSION = "v0.2 " ;
1917 public static EnumMode mode = null ;
2018 public static EnumMode helpCommand = null ;
2119 public static MCPLogger logger ;
@@ -31,31 +29,22 @@ public class MCP {
3129 .fgCyan ().a (" |_| \\ _\\ ___|\\ __|_| \\ ___/" ).fgYellow ().a ("|_| |_|\\ _____|_| " ).a ('\n' )
3230 .fgDefault ();
3331
34- private static boolean checkIfUpdating (String [] args ) throws URISyntaxException , IOException {
35- System .out .println (Paths .get (MCP .class
36- .getProtectionDomain ()
37- .getCodeSource ()
38- .getLocation ()
39- .toURI ()));
40- if (args .length >= 2 ) {
41- if (args [0 ].equals ("update" )) {
42- Files .deleteIfExists (Paths .get (args [1 ]));
43- Files .copy (Paths .get (MCPConfig .UPDATE_JAR ), Paths .get (args [1 ]));
44- Util .runCommand (new String [] {
45- Util .getJava (),
46- "-jar" ,
47- args [1 ]
48- });
32+ private static void attemptToDeleteUpdateJar () {
33+ long startTime = System .currentTimeMillis ();
34+ boolean keepTrying = true ;
35+ while (keepTrying ) {
36+ try {
37+ Files .deleteIfExists (Paths .get (MCPConfig .UPDATE_JAR ));
38+ keepTrying = false ;
39+ } catch (IOException e ) {
40+ keepTrying = System .currentTimeMillis () - startTime < 10000 ;
4941 }
50- return true ;
51- }
52- return false ;
42+ }
5343 }
5444
5545 public static void main (String [] args ) throws Exception {
5646 SelfCommandPrompt .runWithCMD (SelfCommandPrompt .suggestAppId (), "RetroMCP " + VERSION , args );
57- if (checkIfUpdating (args )) System .exit (0 );
58- //Files.deleteIfExists(Paths.get(MCPConfig.UPDATE_JAR));
47+ attemptToDeleteUpdateJar ();
5948 AnsiConsole .systemInstall ();
6049 logger = new MCPLogger ();
6150 config = new MCPConfig ();
0 commit comments