pacenotes_installer\i18n/
string_table.rs1pub fn load_string(id: u16) -> String {
4 unsafe {
5 let mut resource: *mut u16 = core::ptr::null_mut();
6 let point_into_resource = 0;
7 let length = windows_sys::Win32::UI::WindowsAndMessaging::LoadStringW(
8 instance(),
9 id as u32,
10 &mut resource as *mut *mut u16 as windows_sys::core::PWSTR,
11 point_into_resource,
12 );
13 if length <= 0 || resource.is_null() {
14 return format!("<{id}>");
15 }
16 String::from_utf16_lossy(core::slice::from_raw_parts(resource, length as usize))
17 }
18}
19
20pub fn load_string_arg(id: u16, argument: &str) -> String {
23 let template = load_string(id);
24 match template.find("%s") {
25 Some(at) => format!("{}{argument}{}", &template[..at], &template[at + 2..]),
26 None => template,
27 }
28}
29
30pub fn instance() -> windows_sys::Win32::Foundation::HMODULE {
32 unsafe { windows_sys::Win32::System::LibraryLoader::GetModuleHandleW(core::ptr::null()) }
33}