fn signature(&self, hash_buffer_size: usize) -> AppResult<Signature> {
        use std::os::windows::fs::MetadataExt;
        use widestring::U16CString;

        let win_sign = WinSign::default();

        // convert path to UTF16 Windows string
        let u16_path = U16CString::from_os_str(self.as_os_str()).unwrap();

        // println!("signature for {}", self.display());
        // println!("u16_path for {:?}, length={}", &u16_path, u16_path.len());

        let rc = unsafe { get_signature_w(u16_path.as_ptr(), &win_sign) };

        // windows DLL rc should be 0, or rc from GetLastError() API
        if rc != 0 {
            return Err(AppError::new_custom(
                AppCustomErrorKind::WindowsApiError,
                &format!(
                    "Windows API error trying to get file signature = {} for file {}",
                    rc,
                    self.display()
                ),
            ));
        }

        // now get metadata fields for signature
        let metadata = self
            .metadata()
            .map_err(|e| context!(e, "error fetching metadata for file {:?} ", self))?;

        let mut signature = Signature::default();
        signature.inode = win_sign.inode;
        signature.dev = win_sign.dev;
        signature.size = metadata.file_size();

        // only calculate hash if file size is larger than hash buffer size
        signature.hash = if signature.size < hash_buffer_size as u64 {
            None
        } else {
            let hash = Signature::hash(&self, hash_buffer_size)?;
            Some(hash)
        };

        Ok(signature)
    }
// needs to convert a regular Rust string to an UTF16 unicode null-terminated string
// this is because Win32 APIs needs a LPWCSTR type which a pointer on a null-terminated
// UTF16 string
needs to convert a regular Rust string to an UTF16 unicode null-terminated string
this is because Win32 APIs needs a LPWCSTR type which a pointer on a null-terminated
UTF16 string
needs to convert a regular Rust string to an UTF16 unicode null - terminated string this is because Win32 APIs needs a LPWCSTR type which a pointer on a null - terminated UTF16 string
fn signature(&self, hash_buffer_size: usize) -> AppResult<Signature> {
        use std::os::windows::fs::MetadataExt;
        use widestring::U16CString;
        let win_sign = WinSign::default();
        // convert path to UTF16 Windows string
        let u16_path = U16CString::from_os_str(self.as_os_str()).unwrap();
        // println!("signature for {}", self.display());
        // println!("u16_path for {:?}, length={}", &u16_path, u16_path.len());
        let rc = unsafe { get_signature_w(u16_path.as_ptr(), &win_sign) };
        // windows DLL rc should be 0, or rc from GetLastError() API
        if rc != 0 {
            return Err(AppError::new_custom(
                AppCustomErrorKind::WindowsApiError,
                &format!(
                    "Windows API error trying to get file signature = {} for file {}",
                    rc,
                    self.display()
                ),
            ));
        }
        // now get metadata fields for signature
        let metadata = self
            .metadata()
            .map_err(|e| context!(e, "error fetching metadata for file {:?} ", self))?;
        let mut signature = Signature::default();
        signature.inode = win_sign.inode;
        signature.dev = win_sign.dev;
        signature.size = metadata.file_size();
        // only calculate hash if file size is larger than hash buffer size
        signature.hash = if signature.size < hash_buffer_size as u64 {
            None
        } else {
            let hash = Signature::hash(&self, hash_buffer_size)?;
            Some(hash)
        };
        Ok(signature)
    }
fn signature ( & self , hash_buffer_size : usize ) -> AppResult < Signature > { use std :: os :: windows :: fs :: MetadataExt ; use widestring :: U16CString ; let win_sign = WinSign :: default ( ) ; // convert path to UTF16 Windows string let u16_path = U16CString :: from_os_str ( self . as_os_str ( ) ) . unwrap ( ) ; // println!("signature for {}", self.display()); // println!("u16_path for {:?}, length={}", &u16_path, u16_path.len()); let rc = unsafe { get_signature_w ( u16_path . as_ptr ( ) , & win_sign ) } ; // windows DLL rc should be 0, or rc from GetLastError() API if rc != 0 { return Err ( AppError :: new_custom ( AppCustomErrorKind :: WindowsApiError , & format ! ( " " rc self display ( ) ) , ) ) ; } // now get metadata fields for signature let metadata = self . metadata ( ) . map_err ( | e | context ! ( e " " self ) ) ? ; let mut signature = Signature :: default ( ) ; signature . inode = win_sign . inode ; signature . dev = win_sign . dev ; signature . size = metadata . file_size ( ) ; // only calculate hash if file size is larger than hash buffer size signature . hash = if signature . size < hash_buffer_size as u64 { None } else { let hash = Signature :: hash ( & self , hash_buffer_size ) ? ; Some ( hash ) } ; Ok ( signature ) }
needs to convert a regular Rust string to an UTF16 unicode null-terminated string
this is because Win32 APIs needs a LPWCSTR type which a pointer on a null-terminated
UTF16 string
needs to convert a regular Rust string to an UTF16 unicode null - terminated string this is because Win32 APIs needs a LPWCSTR type which a pointer on a null - terminated UTF16 string
&self
hash_buffer_size
usize
&self
hash_buffer_size
usize