-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #197 from PBH-BTN/master
v4.3.0
- Loading branch information
Showing
37 changed files
with
2,030 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/com/ghostchu/peerbanhelper/MainJumpLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.ghostchu.peerbanhelper; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.StringTokenizer; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
public class MainJumpLoader { | ||
public static void main(String[] args) { | ||
// Do something before real Main class | ||
if (System.getProperty("os.name").toLowerCase().contains("windows")) { | ||
setupCharsets(); | ||
} | ||
Main.main(args); | ||
} | ||
|
||
private static void setupCharsets() { | ||
try { | ||
invokeCommand("cmd.exe /c chcp 65001", Collections.emptyMap()); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public static int invokeCommand(String command, Map<String, String> env) throws IOException, ExecutionException, InterruptedException, TimeoutException { | ||
StringTokenizer st = new StringTokenizer(command); | ||
String[] cmdarray = new String[st.countTokens()]; | ||
for (int i = 0; st.hasMoreTokens(); i++) { | ||
cmdarray[i] = st.nextToken(); | ||
} | ||
ProcessBuilder builder = new ProcessBuilder(cmdarray) | ||
.inheritIO(); | ||
Map<String, String> liveEnv = builder.environment(); | ||
liveEnv.putAll(env); | ||
Process p = builder.start(); | ||
Process process = p.onExit().get(10, TimeUnit.SECONDS); | ||
if (process.isAlive()) { | ||
process.destroy(); | ||
return -9999; | ||
} | ||
return process.exitValue(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.