Skip to content

Commit 4414a00

Browse files
committed
🎨 loadu関数を実装
1 parent b705595 commit 4414a00

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ukaing"
3-
version = "0.2.1"
3+
version = "0.2.2"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

src/lib.rs

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,46 @@ use simplelog::*;
2727

2828
static mut RPCCLIENT: Lazy<RpcClient> = Lazy::new(RpcClient::new);
2929

30+
#[no_mangle]
31+
pub extern "cdecl" fn loadu(h: HGLOBAL, len: c_long) -> BOOL {
32+
let v = GStr::capture(h, len as usize);
33+
let s = match v.to_utf8_str() {
34+
Ok(st) => {
35+
// UTF-8に変換
36+
st.to_string()
37+
}
38+
Err(e) => {
39+
eprintln!("Failed to convert HGLOBAL to UTF-8: {:?}", e);
40+
return FALSE;
41+
}
42+
};
43+
44+
match common_load_process(&s) {
45+
Ok(_) => {
46+
debug!("loadu");
47+
TRUE
48+
}
49+
Err(_) => {
50+
error!("load failed");
51+
FALSE
52+
}
53+
}
54+
}
55+
3056
#[no_mangle]
3157
pub extern "cdecl" fn load(h: HGLOBAL, len: c_long) -> BOOL {
3258
let v = GStr::capture(h, len as usize);
33-
let s: String;
34-
match v.to_utf8_str() {
59+
let s = match v.to_utf8_str() {
3560
Ok(st) => {
3661
// UTF-8に変換
37-
s = st.to_string();
62+
st.to_string()
3863
}
3964
Err(e) => {
4065
eprintln!("Failed to convert HGLOBAL to UTF-8: {:?}", e);
4166
match v.to_ansi_str() {
4267
Ok(st) => {
4368
// ANSIに変換
44-
s = st.to_string_lossy().to_string();
69+
st.to_string_lossy().to_string()
4570
}
4671
Err(e) => {
4772
eprintln!("Failed to convert HGLOBAL to ANSI: {:?}", e);
@@ -51,8 +76,21 @@ pub extern "cdecl" fn load(h: HGLOBAL, len: c_long) -> BOOL {
5176
}
5277
};
5378

79+
match common_load_process(&s) {
80+
Ok(_) => {
81+
debug!("load");
82+
TRUE
83+
}
84+
Err(_) => {
85+
error!("load failed");
86+
FALSE
87+
}
88+
}
89+
}
90+
91+
fn common_load_process(dll_dir: &str) -> Result<(), ()> {
5492
// Windows(UTF-16)を想定しPathBufでパスを作成
55-
let log_path = PathBuf::from(&s).join("ukaing.log");
93+
let log_path = PathBuf::from(dll_dir).join("ukaing.log");
5694
WriteLogger::init(
5795
LevelFilter::Debug,
5896
Config::default(),
@@ -64,10 +102,9 @@ pub extern "cdecl" fn load(h: HGLOBAL, len: c_long) -> BOOL {
64102
debug!("{}", panic_info);
65103
}));
66104

67-
debug!("load");
68105
unsafe { RPCCLIENT.start() };
69106

70-
TRUE
107+
Ok(())
71108
}
72109

73110
#[no_mangle]

0 commit comments

Comments
 (0)