(&self, name: &str)
| 394 | } |
| 395 | |
| 396 | pub fn get_capability_info(&self, name: &str) -> Result<DismCapabilityResult, String> { |
| 397 | let get_cap_info = self.api.get_capability_info |
| 398 | .ok_or_else(|| t!("dism.capabilitiesNotSupported").to_string())?; |
| 399 | |
| 400 | let wide_name = to_wide_null(name); |
| 401 | let mut info_ptr: *mut DismCapabilityDetail = std::ptr::null_mut(); |
| 402 | |
| 403 | let hr = unsafe { |
| 404 | get_cap_info( |
| 405 | self.handle, |
| 406 | wide_name.as_ptr(), |
| 407 | &mut info_ptr, |
| 408 | ) |
| 409 | }; |
| 410 | |
| 411 | if hr == DISMAPI_E_UNKNOWN_FEATURE { |
| 412 | return Ok(DismCapabilityResult { |
| 413 | name: name.to_string(), |
| 414 | unknown: true, |
| 415 | state: 0, |
| 416 | display_name: String::new(), |
| 417 | description: String::new(), |
| 418 | download_size: 0, |
| 419 | install_size: 0, |
| 420 | }); |
| 421 | } |
| 422 | |
| 423 | if hr < 0 { |
| 424 | return Err(t!("dism.getCapabilityInfoFailed", name = name, hr = format!("0x{:08X}", hr as u32)).to_string()); |
| 425 | } |
| 426 | |
| 427 | let result = unsafe { |
| 428 | let detail = &*info_ptr; |
| 429 | let cap_info = DismCapabilityResult { |
| 430 | name: from_wide_ptr(detail.name), |
| 431 | unknown: false, |
| 432 | state: detail.state, |
| 433 | display_name: from_wide_ptr(detail.display_name), |
| 434 | description: from_wide_ptr(detail.description), |
| 435 | download_size: detail.download_size, |
| 436 | install_size: detail.install_size, |
| 437 | }; |
| 438 | (self.api.delete)(info_ptr as *const c_void); |
| 439 | cap_info |
| 440 | }; |
| 441 | |
| 442 | // Some Windows versions return success with empty name for unknown capabilities |
| 443 | // instead of DISMAPI_E_UNKNOWN_FEATURE; detect and treat as unknown. |
| 444 | if result.name.is_empty() { |
| 445 | return Ok(DismCapabilityResult { |
| 446 | name: name.to_string(), |
| 447 | unknown: true, |
| 448 | state: 0, |
| 449 | display_name: String::new(), |
| 450 | description: String::new(), |
| 451 | download_size: 0, |
| 452 | install_size: 0, |
| 453 | }); |
no test coverage detected