Skip to content

Commit e842475

Browse files
committed
Somewhat working.
1 parent 17be0a8 commit e842475

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

src/main/java/org/mcphackers/mcp/MCP.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
import org.mcphackers.mcp.tools.VersionsParser;
99

1010
import java.io.IOException;
11+
import java.net.URISyntaxException;
1112
import java.nio.file.Files;
1213
import java.nio.file.Paths;
1314
import java.util.*;
1415

1516
public class MCP {
1617

17-
public static final String VERSION = "v0.1";
18+
public static final String VERSION = "Test";
1819
public static EnumMode mode = null;
1920
public static EnumMode helpCommand = null;
2021
public static MCPLogger logger;
@@ -30,24 +31,31 @@ public class MCP {
3031
.fgCyan().a(" |_| \\_\\___|\\__|_| \\___/").fgYellow().a("|_| |_|\\_____|_| ").a('\n')
3132
.fgDefault();
3233

33-
private static boolean checkIfUpdating(String[] args) throws IOException {
34-
if(args.length == 2) {
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) {
3541
if(args[0].equals("update")) {
42+
Files.deleteIfExists(Paths.get(args[1]));
43+
Files.copy(Paths.get(MCPConfig.UPDATE_JAR), Paths.get(args[1]));
3644
Util.runCommand(new String[] {
3745
Util.getJava(),
3846
"-jar",
3947
args[1]
4048
});
41-
return true;
4249
}
50+
return true;
4351
}
4452
return false;
4553
}
4654

4755
public static void main(String[] args) throws Exception {
48-
if(checkIfUpdating(args)) return;
49-
Files.deleteIfExists(Paths.get(MCPConfig.UPDATE_JAR));
5056
SelfCommandPrompt.runWithCMD(SelfCommandPrompt.suggestAppId(), "RetroMCP " + VERSION, args);
57+
if(checkIfUpdating(args)) System.exit(0);
58+
//Files.deleteIfExists(Paths.get(MCPConfig.UPDATE_JAR));
5159
AnsiConsole.systemInstall();
5260
logger = new MCPLogger();
5361
config = new MCPConfig();

src/main/java/org/mcphackers/mcp/tasks/TaskDownloadUpdate.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import org.mcphackers.mcp.tools.FileUtil;
1515
import org.mcphackers.mcp.tools.Util;
1616

17+
import jredfox.selfcmd.SelfCommandPrompt;
18+
1719
public class TaskDownloadUpdate extends Task {
1820

1921
private static final String API = "https://api.github.com/repos/MCPHackers/RetroMCP-Java/releases/latest";
@@ -39,6 +41,7 @@ public void doTask() throws Exception {
3941
continue;
4042
}
4143
FileUtil.downloadFile(new URL(assetObj.getString("browser_download_url")), Paths.get(MCPConfig.UPDATE_JAR));
44+
//if(!Files.exists(Paths.get(MCPConfig.UPDATE_JAR)))Files.copy(Paths.get("test.jar"), Paths.get(MCPConfig.UPDATE_JAR));
4245
}
4346
}
4447
MCP.logger.info("Press return key to continue");
@@ -49,14 +52,15 @@ public void doTask() throws Exception {
4952
.getLocation()
5053
.toURI());
5154
if(!Files.isDirectory(jarPath)) {
52-
Util.runCommand(new String[] {
55+
String[] cmd = new String[] {
5356
Util.getJava(),
5457
"-jar",
5558
MCPConfig.UPDATE_JAR,
5659
"update",
5760
jarPath.toString()
58-
});
59-
System.exit(0);
61+
};
62+
Util.runCommand(cmd);
63+
SelfCommandPrompt.shutdown();
6064
}
6165
else {
6266
throw new IOException("Running from a folder! Aborting");

src/main/java/org/mcphackers/mcp/tools/Util.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public void run() {
5151

5252
public static void runCommand(String[] cmd) throws IOException {
5353
ProcessBuilder procBuilder = new ProcessBuilder(cmd);
54-
procBuilder.start();
54+
Process proc = procBuilder.start();
55+
while(proc.isAlive());
56+
proc.exitValue();
5557
}
5658

5759
public static OS getOperatingSystem() {

test.jar

1.92 MB
Binary file not shown.

0 commit comments

Comments
 (0)