11use std:: ffi:: { c_char, c_void, CStr } ;
22
3- use windows_sys:: Win32 :: Foundation :: { HANDLE , INVALID_HANDLE_VALUE } ;
3+ use windows_sys:: Win32 :: Foundation :: INVALID_HANDLE_VALUE ;
44use windows_sys:: Win32 :: Storage :: FileSystem :: {
55 FindClose , FindFirstFileA , FindNextFileA , GetFileAttributesA , FILE_ATTRIBUTE_DIRECTORY ,
66 INVALID_FILE_ATTRIBUTES , WIN32_FIND_DATAA ,
@@ -10,59 +10,21 @@ use super::log::log_info;
1010
1111extern "system" {
1212 fn CreateDirectoryA ( path : * const u8 , security : * const c_void ) -> i32 ;
13- fn GetPrivateProfileStringA (
14- app : * const u8 ,
15- key : * const u8 ,
16- default : * const u8 ,
17- ret : * mut u8 ,
18- size : u32 ,
19- file : * const u8 ,
20- ) -> u32 ;
2113}
2214
23- pub fn ensure_mods_layout ( base_dir : & str ) -> ( String , String ) {
15+ pub fn ensure_mods_dir ( base_dir : & str ) -> String {
2416 unsafe {
2517 let mods_dir = format ! ( "{}\\ mods" , base_dir) ;
26- let ini_path = format ! ( "{}\\ mods.ini" , base_dir) ;
27-
2818 let mods_dir_c = format ! ( "{}\0 " , mods_dir) ;
2919 if GetFileAttributesA ( mods_dir_c. as_ptr ( ) ) == INVALID_FILE_ATTRIBUTES {
3020 CreateDirectoryA ( mods_dir_c. as_ptr ( ) , std:: ptr:: null ( ) ) ;
3121 log_info ( & format ! ( "created mods dir: {}" , mods_dir) ) ;
3222 }
33-
34- ( mods_dir, ini_path)
23+ mods_dir
3524 }
3625}
3726
38- pub fn is_mod_enabled ( ini_path : & str , mod_name : & str ) -> bool {
39- unsafe {
40- let mut value = [ 0u8 ; 32 ] ;
41- let section = b"mods\0 " ;
42- let ini_cstr = format ! ( "{}\0 " , ini_path) ;
43- let mod_cstr = format ! ( "{}\0 " , mod_name) ;
44- let empty = b"\0 " ;
45-
46- GetPrivateProfileStringA (
47- section. as_ptr ( ) ,
48- mod_cstr. as_ptr ( ) ,
49- empty. as_ptr ( ) ,
50- value. as_mut_ptr ( ) ,
51- value. len ( ) as u32 ,
52- ini_cstr. as_ptr ( ) ,
53- ) ;
54-
55- if value[ 0 ] == 0 {
56- return true ;
57- }
58-
59- let s = CStr :: from_ptr ( value. as_ptr ( ) as * const c_char ) ;
60- s. to_str ( )
61- . map_or ( true , |v| v. parse :: < i32 > ( ) . unwrap_or ( 1 ) != 0 )
62- }
63- }
64-
65- pub fn scan_mod_files ( mods_dir : & str , ini_path : & str ) -> Vec < ( String , String ) > {
27+ pub fn scan_mod_files ( mods_dir : & str ) -> Vec < ( String , String ) > {
6628 unsafe {
6729 let pattern = format ! ( "{}\\ *.dll\0 " , mods_dir) ;
6830 let mut find_data: WIN32_FIND_DATAA = std:: mem:: zeroed ( ) ;
@@ -78,12 +40,7 @@ pub fn scan_mod_files(mods_dir: &str, ini_path: &str) -> Vec<(String, String)> {
7840 let mod_name_cstr = CStr :: from_ptr ( find_data. cFileName . as_ptr ( ) as * const c_char ) ;
7941 let mod_name = mod_name_cstr. to_string_lossy ( ) . into_owned ( ) ;
8042 let full_path = format ! ( "{}\\ {}" , mods_dir, mod_name) ;
81-
82- if is_mod_enabled ( ini_path, & mod_name) {
83- mods. push ( ( mod_name, full_path) ) ;
84- } else {
85- log_info ( & format ! ( "mod disabled: {}" , full_path) ) ;
86- }
43+ mods. push ( ( mod_name, full_path) ) ;
8744 }
8845
8946 if FindNextFileA ( find_handle, & mut find_data) == 0 {
0 commit comments