Skip to content

Commit 1da08f6

Browse files
committed
Exp: Use short path on Windows
1 parent 805f2f4 commit 1da08f6

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src-tauri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ nix = "=0.30.1"
6363

6464
[target.'cfg(windows)'.dependencies]
6565
libc = "0.2.172"
66+
windows-sys = { version = "0.60.2", features = ["Win32_Storage_FileSystem"] }
6667

6768
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
6869
tauri-plugin-updater = "2"

src-tauri/src/core/utils/extensions/inference_llamacpp_extension/server.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,32 @@ pub struct DeviceInfo {
6767
pub free: i32,
6868
}
6969

70+
#[cfg(windows)]
71+
use std::os::windows::ffi::OsStrExt;
72+
73+
#[cfg(windows)]
74+
use std::ffi::OsStr;
75+
76+
#[cfg(windows)]
77+
use windows_sys::Win32::Storage::FileSystem::GetShortPathNameW;
78+
79+
#[cfg(windows)]
80+
pub fn get_short_path<P: AsRef<std::path::Path>>(path: P) -> Option<String> {
81+
let wide: Vec<u16> = OsStr::new(path.as_ref())
82+
.encode_wide()
83+
.chain(Some(0))
84+
.collect();
85+
86+
let mut buffer = vec![0u16; 260];
87+
let len = unsafe { GetShortPathNameW(wide.as_ptr(), buffer.as_mut_ptr(), buffer.len() as u32) };
88+
89+
if len > 0 {
90+
Some(String::from_utf16_lossy(&buffer[..len as usize]))
91+
} else {
92+
None
93+
}
94+
}
95+
7096
// --- Load Command ---
7197
#[tauri::command]
7298
pub async fn load_llama_model(
@@ -123,7 +149,17 @@ pub async fn load_llama_model(
123149
model_path_pb.display().to_string(),
124150
)));
125151
}
126-
args[model_path_index + 1] = model_path_pb.display().to_string();
152+
#[cfg(windows)]
153+
{
154+
// use short path on Windows
155+
if let Some(short) = get_short_path(&model_path_pb) {
156+
args[model_path_index + 1] = short;
157+
}
158+
}
159+
#[cfg(not(windows))]
160+
{
161+
args[model_path_index + 1] = model_path_pb.display().to_string();
162+
}
127163
// -----------------------------------------------------------------
128164

129165
let api_key = args

0 commit comments

Comments
 (0)