Skip to content

Commit

Permalink
增强日志,重命名ui活动栏类,更新部分语言,优化平台检测逻辑,去除不需要的类
Browse files Browse the repository at this point in the history
  • Loading branch information
zedoCN committed Mar 1, 2024
1 parent 7dbe735 commit f363072
Show file tree
Hide file tree
Showing 40 changed files with 823 additions and 789 deletions.
1 change: 0 additions & 1 deletion .idea/artifacts/ZXNoter_jar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions .idea/libraries/apache_commons_lang3.xml

This file was deleted.

14 changes: 0 additions & 14 deletions .idea/libraries/net_java_dev_jna.xml

This file was deleted.

3 changes: 1 addition & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions ZXNoter.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="CheckStyle-IDEA-Module" serialisationVersion="2">
<option name="activeLocationsIds" />
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
Expand Down
Binary file modified ZXNoter.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion module/ExtensionLoader/ExtensionLoader.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="CheckStyle-IDEA-Module" serialisationVersion="2">
<option name="activeLocationsIds" />
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
Expand All @@ -10,6 +13,5 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="google.code.gson" level="project" />
<orderEntry type="library" exported="" name="apache.commons.lang3" level="project" />
</component>
</module>
17 changes: 14 additions & 3 deletions module/ExtensionLoader/resources/languages/zh-cn.json5
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
resourcePack: {
initialize: "初始化资源包...⏳",
lost: "丢失资源包: {0}",
loading: "正在载入资源包: {0}",
loading: "正在加载资源包: {0}",
reloaded: "重载资源完成,用时 {0} ms",
notFound: "资源包不存在: {0}",
loadFailed: "资源包载入失败: {0} 异常: {1}",
loadFailed: "资源包加载失败: {0} 异常: {1}",
application: "正在应用资源包: {0}",
noName: "未命名的资源包",
noDescription: "没有描述",
Expand Down Expand Up @@ -85,8 +85,19 @@
dependExtensionNotCompatible: "{{cantLoad}} ,依赖的扩展 ({1}) 的版本不兼容,需要版本 {2} ,当前版本 {3} 。",
entrypointNotFound: "加载扩展 ({0}) 时,入口点 {1} 类未找到。",
entrypointNotImplemented: "加载扩展({0}) 时,入口点 {1} 类未实现 ExtensionEntrypoint 接口。",
entrypointInstanceFailed: "加载扩展 ({0}) 时,入口点 {1} 实例化失败: {1}"
entrypointInstanceFailed: "加载扩展 ({0}) 时,入口点 {1} 实例化失败: {2}",
entrypointOnLoadedException: "初始化扩展 ({0}) 时,入口点 {1} 在载入时异常: {2}",
entrypointInitializeException: "初始化扩展 ({0}) 时,入口点 {1} 在初始化时异常: {2}",
entrypointAllInitializedException: "初始化扩展 ({0}) 时,入口点 {1} 在全初始化时异常: {2}"
}
},
library: {
loadingAll: "加载所有库中...⏳",
loading: "正在加载库: {0}",
cantLoad: "无法加载库 {0}",
loaded: "已载入 {0} 个库,用时 {1} ms",
error: "{{cantLoad}} ,加载库时发生异常: {1}",
repeat: "{{cantLoad}} ,因为库被重复加载。"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public <T> T get(Class<T> clazz) {
Path jsonPath = getConfigPath(clazz);
boolean isNewConfig = false;
if (Files.exists(jsonPath)) {
System.out.println("读取配置: " + jsonPath);
//System.out.println("读取配置: " + jsonPath);
result = GsonManager.fromJson(jsonPath, clazz);
} else {
isNewConfig = true;
System.out.println("配置不存在,创建新配置: " + getConfigPath(clazz));
//System.out.println("配置不存在,创建新配置: " + getConfigPath(clazz));
try {
result = clazz.getDeclaredConstructor().newInstance();
GsonManager.checkNullValue(result);
Expand Down Expand Up @@ -128,7 +128,7 @@ public static void save() {
for (Object object : config.configObject.values()) {
if (object instanceof ConfigData configData) {
if (configData.needSave) {
System.out.println("自动保存配置: " + configData.getClass().getSimpleName());
//System.out.println("自动保存配置: " + configData.getClass().getSimpleName());
configData.save();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private static String getLang(String value) {
public static String get(String key, Object... args) {
String v = getOrNull(key, args);
if (v == null) {
Logger.printStackTrace();
Logger.logStackTrace();
v = Language.getOrNull(LanguageKey.MESSAGE_LANGUAGE_LOST, key);
v = (v == null ? "LOST_LANGUAGE: " + key : v);
Logger.warning(v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public String format(LogRecord record) {

StringBuilder sb = new StringBuilder();
for (int i = 0; i < messageLines.length; i++) {
sb.append(prefix).append(messageLines[i]).append("\n");
sb.append(prefix).append(messageLines[i].trim()).append("\n");
}
return sb.toString();
}
Expand Down Expand Up @@ -209,7 +209,11 @@ public static StackTraceElement getStackTraceElement(String className, int cutof
return null;
}


/**
* 记录异常的堆栈追踪信息
*
* @param e 异常
*/
public static void logExceptionStackTrace(Exception e) {
StringWriter sw = new StringWriter();
try (PrintWriter pw = new PrintWriter(sw)) {
Expand All @@ -218,9 +222,14 @@ public static void logExceptionStackTrace(Exception e) {
log(Level.WARNING, sw.toString(), 0);
}

public static void printStackTrace() {
for (StackTraceElement stackTraceElement : Thread.currentThread().getStackTrace()) {
warning(stackTraceElement.toString());
/**
* 记录堆栈追踪信息
*/
public static void logStackTrace() {
StackTraceElement[] elements = Thread.currentThread().getStackTrace();
log(Level.WARNING, "----StackTrace----", 0);
for (int i = 2; i < elements.length; i++) {
log(Level.WARNING, "at " + elements[i].toString(), 0);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package team.zxorg.extensionloader.core;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public enum PlatformType {
MAC_ARM("mac", "aarch64"),
MAC("mac"),
LINUX_ARM("linux", "aarch64"),
LINUX("linux"),
WINDOWS("win"),
ALL("");
public static final PlatformType CURRENT_PLATFORM = detectCurrentPlatform();
private final Set<String> keywords;

public Set<String> getKeywords() {
return keywords;
}

PlatformType(String... keywords) {
this.keywords = new HashSet<>(List.of(keywords));
}

public boolean isMac() {
return keywords.contains("mac");
}

public boolean isLinux() {
return keywords.contains("linux");
}

public boolean isWindows() {
return keywords.contains("win");
}

public boolean isArm() {
return keywords.contains("aarch64");
}

public boolean isAll() {
return this == ALL;
}

private static PlatformType detectCurrentPlatform() {
String osName = System.getProperty("os.name").toLowerCase();
String arch = System.getProperty("os.arch").toLowerCase();

if (osName.contains("mac")) {
return arch.contains("aarch64") ? MAC_ARM : MAC;
} else if (osName.contains("linux")) {
return arch.contains("aarch64") ? LINUX_ARM : LINUX;
} else if (osName.contains("windows")) {
return WINDOWS;
} else {
return ALL;
}
}

@Override
public String toString() {
return name().toLowerCase();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package team.zxorg.extensionloader.core;

import org.apache.commons.lang3.time.StopWatch;
import team.zxorg.extensionloader.event.ResourceEventListener;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package team.zxorg.extensionloader.core;

public class StopWatch {
private long startTime;
private long stopTime;
private boolean isRunning;

public void start() {
if (!isRunning) {
startTime = System.currentTimeMillis();
isRunning = true;
}
}

public void stop() {
if (isRunning) {
stopTime = System.currentTimeMillis();
isRunning = false;
}
}

public long getTime() {
if (isRunning) {
return System.currentTimeMillis() - startTime;
} else {
return stopTime - startTime;
}
}

public void reset() {
startTime = 0;
stopTime = 0;
isRunning = false;
}

public boolean isRunning() {
return isRunning;
}
}
Loading

0 comments on commit f363072

Please sign in to comment.