-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
158e39e
commit 0d19f6f
Showing
14 changed files
with
143 additions
and
14 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
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
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
71 changes: 71 additions & 0 deletions
71
src/main/java/cn/powernukkitx/cli/util/CheckUpdateUtil.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,71 @@ | ||
package cn.powernukkitx.cli.util; | ||
|
||
import cn.powernukkitx.cli.share.CLIConstant; | ||
import com.google.gson.JsonParser; | ||
import org.fusesource.jansi.Ansi; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.net.URI; | ||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpResponse; | ||
import java.time.Duration; | ||
import java.util.ResourceBundle; | ||
import java.util.Timer; | ||
import java.util.TimerTask; | ||
|
||
public final class CheckUpdateUtil { | ||
private CheckUpdateUtil() { | ||
|
||
} | ||
|
||
public static void scheduleCheckUpdate(@NotNull Timer timer) { | ||
timer.schedule(new TimerTask() { | ||
@Override | ||
public void run() { | ||
var apiURL = HttpUtils.getAPIUrl("/git/latest-release/PowerNukkitX/PNX-CLI"); | ||
var client = HttpUtils.getClient(); | ||
try { | ||
var result = client.send(HttpRequest.newBuilder(URI.create(apiURL)).GET() | ||
.timeout(Duration.ofSeconds(10)).build(), HttpResponse.BodyHandlers.ofString()).body(); | ||
var jsonObject = JsonParser.parseString(result).getAsJsonObject(); | ||
var tagName = jsonObject.get("tagName").getAsString(); | ||
if (compareVersion(tagName, CLIConstant.version) > 0) { | ||
var str = ResourceBundle.getBundle("cn.powernukkitx.cli.util.CheckUpdate") | ||
.getString("new-version-detected"); | ||
Logger.info(Ansi.ansi().fgBrightYellow().a(str.formatted(tagName)).fgDefault()); | ||
} | ||
} catch (Exception ignored) { | ||
// ignored | ||
} | ||
} | ||
}, 1000 * 30, 1000 * 60 * 60 * 24); | ||
} | ||
|
||
/** | ||
* 比较版本号(如0.1.2) | ||
* | ||
* @param a 版本号a | ||
* @param b 版本号b | ||
* @return a > b 返回1,a = b 返回0,a < b 返回-1 | ||
*/ | ||
public static int compareVersion(@NotNull String a, @NotNull String b) { | ||
var aSplit = a.split("\\."); | ||
var bSplit = b.split("\\."); | ||
var length = Math.min(aSplit.length, bSplit.length); | ||
for (var i = 0; i < length; i++) { | ||
var ai = Integer.parseInt(aSplit[i]); | ||
var bi = Integer.parseInt(bSplit[i]); | ||
if (ai > bi) { | ||
return 1; | ||
} else if (ai < bi) { | ||
return -1; | ||
} | ||
} | ||
if (aSplit.length > bSplit.length) { | ||
return 1; | ||
} else if (aSplit.length < bSplit.length) { | ||
return -1; | ||
} | ||
return 0; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
lang = Select the language to use temporarily to execute this command. | ||
args = If you want to start pnx with some arguments, you should use `%1s start YOUR_ARGS` instead. | ||
config-path = Select which config file will be used. (Default pnx-cli-config.ini) | ||
invalid-file = Cannot find or no IO permission of config file: %1s. | ||
invalid-file = Cannot find or no IO permission of config file: %1s. | ||
update=Check for PNX-CLI updates. |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
lang = \u9009\u62e9\u6267\u884c\u6b64\u6b21\u547d\u4ee4\u6240\u7528\u7684\u8bed\u8a00\u4ee3\u7801\u3002 | ||
args = \u82e5\u8981\u4f7f\u7528\u81ea\u5b9a\u4e49\u53c2\u6570\u542f\u52a8\u0050\u004e\u0058\uff0c\u0020\u8bf7\u4f7f\u7528`%1s start YOUR_ARGS`\u547d\u4ee4\u3002 | ||
config-path = \u6307\u5b9a\u914d\u7f6e\u6587\u4ef6\u8def\u5f84\uff08\u9ed8\u8ba4\u4e3apnx-cli-config.ini\uff09 | ||
invalid-file = \u627e\u4e0d\u5230\u6216\u6ca1\u6709\u914d\u7f6e\u6587\u4ef6 %1s \u7684\u0049\u004f\u6743\u9650 | ||
lang = \u9009\u62E9\u6267\u884C\u6B64\u6B21\u547D\u4EE4\u6240\u7528\u7684\u8BED\u8A00\u4EE3\u7801\u3002 | ||
args = \u82E5\u8981\u4F7F\u7528\u81EA\u5B9A\u4E49\u53C2\u6570\u542F\u52A8PNX\uFF0C\u0020\u8BF7\u4F7F\u7528`%1s start YOUR_ARGS`\u547D\u4EE4\u3002 | ||
config-path = \u6307\u5B9A\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84\uFF08\u9ED8\u8BA4\u4E3Apnx-cli-config.ini\uFF09 | ||
invalid-file = \u627E\u4E0D\u5230\u6216\u6CA1\u6709\u914D\u7F6E\u6587\u4EF6 %1s \u7684IO\u6743\u9650 | ||
update=\u662F\u5426\u68C0\u67E5PNX-CLI\u66F4\u65B0\u3002 |
3 changes: 2 additions & 1 deletion
3
src/main/resources/cn/powernukkitx/cli/Preprocessor.properties
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
lang = Select the language to use temporarily to execute this command. | ||
lang = Select the language to use temporarily to execute this command. | ||
update=Select the language to use temporarily to execute this command. |
3 changes: 2 additions & 1 deletion
3
src/main/resources/cn/powernukkitx/cli/Preprocessor_zh.properties
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
lang = \u9009\u62e9\u6267\u884c\u6b64\u6b21\u547d\u4ee4\u6240\u7528\u7684\u8bed\u8a00\u4ee3\u7801\u3002 | ||
lang = \u9009\u62E9\u6267\u884C\u6B64\u6B21\u547D\u4EE4\u6240\u7528\u7684\u8BED\u8A00\u4EE3\u7801\u3002 | ||
update=\u662F\u5426\u68C0\u67E5PNX-CLI\u66F4\u65B0\u3002 |
1 change: 1 addition & 0 deletions
1
src/main/resources/cn/powernukkitx/cli/util/CheckUpdate.properties
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 @@ | ||
new-version-detected=New version %1s of PNX-CLI has been released, you can get the new version on GitHub. |
1 change: 1 addition & 0 deletions
1
src/main/resources/cn/powernukkitx/cli/util/CheckUpdate_zh.properties
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 @@ | ||
new-version-detected=\u68C0\u6D4B\u5230PNX-CLI\u6709\u65B0\u7248\u672C%1s\uFF0C\u8BF7\u60A8\u5C3D\u5FEB\u66F4\u65B0\u3002 |