[WIP] update example config and add JuiceLoaderLibraryPath

This commit is contained in:
xiaozhou233 committed 2025-11-09 15:07:31 +08:00
1 parent acf2cd2c1d
commit 094e7bc0d4
3 files changed
+12 -3

No files matched your search

+1
View File
@@ -1,6 +1,7 @@
# config.toml # config.toml
JuiceLoaderJarPath = "D:\\Development\\JuiceLoader\\JuiceLoader.jar" JuiceLoaderJarPath = "D:\\Development\\JuiceLoader\\JuiceLoader.jar"
JuiceLoaderLibraryPath = "
InjectionDir = "D:\\Development\\JuiceLoader\\injection" InjectionDir = "D:\\Development\\JuiceLoader\\injection"
EntryJarPath = "D:\\Development\\JuiceLoader\\Entry.jar" EntryJarPath = "D:\\Development\\JuiceLoader\\Entry.jar"
EntryClass = "cn.xiaozhou233.test.Entry" EntryClass = "cn.xiaozhou233.test.Entry"
+1
View File
@@ -14,6 +14,7 @@ typedef struct _InjectionInfo {
char EntryClass[INJECT_PATH_MAX]; char EntryClass[INJECT_PATH_MAX];
char EntryMethod[INJECT_PATH_MAX]; char EntryMethod[INJECT_PATH_MAX];
char InjectionDir[INJECT_PATH_MAX]; char InjectionDir[INJECT_PATH_MAX];
char JuiceLoaderLibraryPath[INJECT_PATH_MAX];
} InjectionInfoType; } InjectionInfoType;
extern InjectionInfoType InjectionInfo; extern InjectionInfoType InjectionInfo;
+10 -3
View File
@@ -100,7 +100,7 @@ static int InvokeJuiceLoaderInit(const char* ConfigDir) {
const char *bootstrap_class = "cn/xiaozhou233/juiceloader/JuiceLoaderBootstrap"; const char *bootstrap_class = "cn/xiaozhou233/juiceloader/JuiceLoaderBootstrap";
const char *method_name = "init"; const char *method_name = "init";
const char *method_signature = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"; const char *method_signature = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V";
PLOGI << "Invoke JuiceLoader Init"; PLOGI << "Invoke JuiceLoader Init";
PLOGI << "================ JuiceLoader Init ================="; PLOGI << "================ JuiceLoader Init =================";
@@ -130,7 +130,8 @@ static int InvokeJuiceLoaderInit(const char* ConfigDir) {
env->CallStaticVoidMethod(cls, mid, env->NewStringUTF(InjectionInfo.EntryJarPath), env->CallStaticVoidMethod(cls, mid, env->NewStringUTF(InjectionInfo.EntryJarPath),
env->NewStringUTF(InjectionInfo.EntryClass), env->NewStringUTF(InjectionInfo.EntryClass),
env->NewStringUTF(InjectionInfo.EntryMethod), env->NewStringUTF(InjectionInfo.EntryMethod),
env->NewStringUTF(InjectionInfo.InjectionDir)); env->NewStringUTF(InjectionInfo.InjectionDir),
env->NewStringUTF(InjectionInfo.JuiceLoaderLibraryPath));
if (env->ExceptionCheck()) { if (env->ExceptionCheck()) {
env->ExceptionDescribe(); env->ExceptionDescribe();
env->ExceptionClear(); env->ExceptionClear();
@@ -144,15 +145,18 @@ static int InvokeJuiceLoaderInit(const char* ConfigDir) {
static int ReadConfig(const char* ConfigDir) static int ReadConfig(const char* ConfigDir)
{ {
// ConfigDir/config.toml
std::string path = std::string(ConfigDir) + "\\config.toml"; std::string path = std::string(ConfigDir) + "\\config.toml";
std::ifstream ifs(path); std::ifstream ifs(path);
if (!ifs) return -1; if (!ifs) return -1;
// Parse toml
toml::ParseResult pr = toml::parse(ifs); toml::ParseResult pr = toml::parse(ifs);
if (!pr.valid()) return -2; if (!pr.valid()) return -2;
const toml::Value& tbl = pr.value; const toml::Value& tbl = pr.value;
// Helper function: get string from toml
auto get_str = [&](const char* key, const char* def, char* out) { auto get_str = [&](const char* key, const char* def, char* out) {
const toml::Value* v = tbl.find(key); const toml::Value* v = tbl.find(key);
if (v && v->is<std::string>()) { if (v && v->is<std::string>()) {
@@ -164,18 +168,21 @@ static int ReadConfig(const char* ConfigDir)
out[INJECT_PATH_MAX - 1] = '\0'; out[INJECT_PATH_MAX - 1] = '\0';
}; };
// Default values
std::string defaultJuiceLoader = std::string(ConfigDir) + "\\JuiceLoader.jar"; std::string defaultJuiceLoader = std::string(ConfigDir) + "\\JuiceLoader.jar";
std::string defaultJuiceLoaderLibrary = std::string(ConfigDir) + "\\libjuiceloader.dll";
std::string defaultEntryJar = std::string(ConfigDir) + "\\Entry.jar"; std::string defaultEntryJar = std::string(ConfigDir) + "\\Entry.jar";
std::string defaultInjectionDir = std::string(ConfigDir) + "\\injection"; std::string defaultInjectionDir = std::string(ConfigDir) + "\\injection";
get_str("JuiceLoaderJarPath", defaultJuiceLoader.c_str(), InjectionInfo.JuiceLoaderJarPath); get_str("JuiceLoaderJarPath", defaultJuiceLoader.c_str(), InjectionInfo.JuiceLoaderJarPath);
get_str("JuiceLoaderLibraryPath", defaultJuiceLoaderLibrary.c_str(), InjectionInfo.JuiceLoaderLibraryPath);
get_str("InjectionDir", defaultInjectionDir.c_str(), InjectionInfo.InjectionDir); get_str("InjectionDir", defaultInjectionDir.c_str(), InjectionInfo.InjectionDir);
get_str("EntryJarPath", defaultEntryJar.c_str(), InjectionInfo.EntryJarPath); get_str("EntryJarPath", defaultEntryJar.c_str(), InjectionInfo.EntryJarPath);
get_str("EntryClass", "cn.xiaozhou233.test.Entry", InjectionInfo.EntryClass); get_str("EntryClass", "cn.xiaozhou233.test.Entry", InjectionInfo.EntryClass);
get_str("EntryMethod", "start", InjectionInfo.EntryMethod); get_str("EntryMethod", "start", InjectionInfo.EntryMethod);
PLOGD << "JuiceLoaderJarPath: " << InjectionInfo.JuiceLoaderJarPath; PLOGD << "JuiceLoaderJarPath: " << InjectionInfo.JuiceLoaderJarPath;
PLOGD << "JuiceLoaderLibraryPath: " << InjectionInfo.JuiceLoaderLibraryPath;
PLOGD << "InjectionDir: " << InjectionInfo.InjectionDir; PLOGD << "InjectionDir: " << InjectionInfo.InjectionDir;
PLOGD << "EntryJarPath: " << InjectionInfo.EntryJarPath; PLOGD << "EntryJarPath: " << InjectionInfo.EntryJarPath;
PLOGD << "EntryClass: " << InjectionInfo.EntryClass; PLOGD << "EntryClass: " << InjectionInfo.EntryClass;