mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-22 11:14:55 +08:00
runtime 主机名显示,信息容错报错
- 在 runtime - system 栏中添加主机名显示 - 如果显示出错则会是 "<unknown>" - runtime - morny version 改名为 coeur version - MornySystem.getJarMd5 出错时现在不会再直接返回错误而是会返回 "<non-jar-runtime>" 或是 "<calculation-error>" 信息
This commit is contained in:
parent
82c9faea1e
commit
5046a27266
@ -1,6 +1,6 @@
|
||||
## Core
|
||||
|
||||
VERSION = 0.7.0.0
|
||||
VERSION = 0.7.0.1
|
||||
|
||||
# dependencies
|
||||
|
||||
|
@ -4,6 +4,6 @@ package cc.sukazyo.cono.morny;
|
||||
* the final field that will be updated by gradle automatically.
|
||||
*/
|
||||
public class GradleProjectConfigures {
|
||||
public static final String VERSION = "0.7.0.0";
|
||||
public static final long COMPILE_TIMESTAMP = 1647369713069L;
|
||||
public static final String VERSION = "0.7.0.1";
|
||||
public static final long COMPILE_TIMESTAMP = 1647424091182L;
|
||||
}
|
||||
|
@ -3,7 +3,9 @@ package cc.sukazyo.cono.morny;
|
||||
import cc.sukazyo.cono.morny.util.FileUtils;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* Morny Cono 的 Coeur 的程序属性存放类
|
||||
@ -20,20 +22,22 @@ public class MornySystem {
|
||||
* 获取程序 jar 文件的 md5-hash 值<br>
|
||||
* <br>
|
||||
* 只支持 jar 文件方式启动的程序 ——
|
||||
* 如果是通过 classpath 来启动,则会返回找不到文件的错误数据<br>
|
||||
* - 或许需要注意,这种情况下会出现程序文件所在的路径<br>
|
||||
* 如果是通过 classpath 来启动,程序无法找到本体jar文件,则会返回 {@code <non-jar-runtime>} 文本
|
||||
* <br>
|
||||
* 值格式为 {@link java.lang.String}
|
||||
*
|
||||
* @return 程序jar文件的 md5-hash 值字符串,或错误信息
|
||||
* @return 程序jar文件的 md5-hash 值字符串,或 {@code <non-jar-runtime>} 如果出现错误
|
||||
*/
|
||||
@Nonnull
|
||||
public static String getJarMd5() {
|
||||
try {
|
||||
return FileUtils.getMD5Three(MornyCoeur.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
|
||||
} catch (URISyntaxException e) {
|
||||
} catch (IOException | URISyntaxException e) {
|
||||
e.printStackTrace(System.out);
|
||||
return e.getMessage();
|
||||
return "<non-jar-runtime>";
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace(System.out);
|
||||
return "<calculation-error>";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,8 @@ import com.pengrad.telegrambot.request.SetMyCommands;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@ -245,19 +247,26 @@ public class MornyCommands {
|
||||
* @since 0.4.1.2
|
||||
*/
|
||||
private static void onCommandRuntimeExec (@Nonnull Update event) {
|
||||
String hostname;
|
||||
try {
|
||||
hostname = InetAddress.getLocalHost().getHostName();
|
||||
} catch (UnknownHostException e) {
|
||||
hostname = "<unknown>";
|
||||
}
|
||||
MornyCoeur.extra().exec(new SendMessage(
|
||||
event.message().chat().id(),
|
||||
String.format("""
|
||||
system:
|
||||
- <code>%s</code>
|
||||
- <code>%s</code>
|
||||
- <code>%s</code>
|
||||
- <code>%d</code> cores
|
||||
java runtime:
|
||||
- <code>%s</code>
|
||||
- <code>%s</code>
|
||||
vm memory:
|
||||
- <code>%d</code> / <code>%d</code> MB
|
||||
morny version:
|
||||
coeur version:
|
||||
- <code>%s</code>
|
||||
- <code>%s</code>
|
||||
- <code>%s [UTC]</code>
|
||||
@ -268,6 +277,7 @@ public class MornyCommands {
|
||||
- <code>%s [UTC]</code>
|
||||
- [<code>%d</code>]""",
|
||||
// system
|
||||
escapeHtml(hostname),
|
||||
escapeHtml(System.getProperty("os.name")),
|
||||
escapeHtml(System.getProperty("os.version")),
|
||||
Runtime.getRuntime().availableProcessors(),
|
||||
|
@ -10,23 +10,18 @@ import java.security.NoSuchAlgorithmException;
|
||||
public class FileUtils {
|
||||
|
||||
@Nonnull
|
||||
public static String getMD5Three (@Nonnull String path) {
|
||||
public static String getMD5Three (@Nonnull String path) throws IOException, NoSuchAlgorithmException {
|
||||
final BigInteger bi;
|
||||
try {
|
||||
final byte[] buffer = new byte[8192];
|
||||
int len;
|
||||
final MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
final FileInputStream fis = new FileInputStream(path);
|
||||
while ((len = fis.read(buffer)) != -1) {
|
||||
md.update(buffer, 0, len);
|
||||
}
|
||||
fis.close();
|
||||
final byte[] b = md.digest();
|
||||
bi = new BigInteger(1, b);
|
||||
} catch (NoSuchAlgorithmException | IOException e) {
|
||||
e.printStackTrace(System.out);
|
||||
return e.getMessage();
|
||||
final byte[] buffer = new byte[8192];
|
||||
int len;
|
||||
final MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
final FileInputStream fis = new FileInputStream(path);
|
||||
while ((len = fis.read(buffer)) != -1) {
|
||||
md.update(buffer, 0, len);
|
||||
}
|
||||
fis.close();
|
||||
final byte[] b = md.digest();
|
||||
bi = new BigInteger(1, b);
|
||||
return bi.toString(16);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user