feat: remove some optional in rust and cbindgen
This commit is contained in:
@@ -230,22 +230,15 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::optional<std::string> ResolveName() {
|
||||
std::string ResolveName() {
|
||||
const char* name = nullptr;
|
||||
_Check(wfassoc::WFProgramResolveName(_token, &name));
|
||||
if (name == nullptr) {
|
||||
return std::nullopt;
|
||||
} else {
|
||||
return std::string(name);
|
||||
}
|
||||
return std::string(name);
|
||||
}
|
||||
|
||||
std::optional<IconRc> ResolveIcon() {
|
||||
IconRc ResolveIcon() {
|
||||
Token token = _INVALID_TOKEN();
|
||||
_Check(wfassoc::WFProgramResolveIcon(_token, &token));
|
||||
if (token == _INVALID_TOKEN()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return IconRc(token);
|
||||
}
|
||||
|
||||
|
||||
@@ -349,9 +349,14 @@ bool WFProgramDestroy(Token in_program);
|
||||
|
||||
/**
|
||||
* @brief Resolve the provided program name of this Program
|
||||
*
|
||||
* The name will be user specified first,
|
||||
* then fallback to program manifest file specified name,
|
||||
* and finally fallback to the file name of executable.
|
||||
*
|
||||
* @param[in] in_program Program token
|
||||
* @param[out] out_name Pointer to receive the resolved name, or NULL if not found.
|
||||
* @param[out] out_name Pointer to receive the resolved name.
|
||||
* There is no possibility that this value is NULL.
|
||||
* This string will be freed at the next API call. Please make a copy immediately if you need to use it longer.
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
@@ -359,9 +364,13 @@ bool WFProgramResolveName(Token in_program, CStyleString *out_name);
|
||||
|
||||
/**
|
||||
* @brief Resolve the Program icon resource
|
||||
*
|
||||
* The icon will be user specified first,
|
||||
* the fallback to the first icon of program,
|
||||
* and finally fallback to the system default executable icon.
|
||||
*
|
||||
* @param[in] in_program Program token
|
||||
* @param[out] out_icon_rc Pointer to receive the icon resource token, or invalid token if not found.
|
||||
* @param[out] out_icon_rc Pointer to receive the icon resource token.
|
||||
* The caller take the ownership of created icon resource object.
|
||||
* And it should be freed by calling WFIconRcDestroy() when it is no longer needed.
|
||||
* @return true on success, false on failure
|
||||
@@ -471,7 +480,10 @@ bool WFProgramQueryExt(Token in_program, View in_view, size_t in_index, Token *o
|
||||
bool WFExtStatusDestroy(Token in_ext_status);
|
||||
|
||||
/**
|
||||
* @brief Get the name from an extension status object
|
||||
* @brief Get the display name from an extension status object
|
||||
*
|
||||
* The display will be user specified first,
|
||||
* the fallback to its ProgId verbatim.
|
||||
*
|
||||
* @param[in] in_ext_status Extension status token
|
||||
* @param[out] out_name Pointer to receive the name.
|
||||
@@ -485,8 +497,11 @@ bool WFExtStatusGetName(Token in_ext_status, CStyleString *out_name);
|
||||
/**
|
||||
* @brief Get the icon from an extension status object
|
||||
*
|
||||
* The icon will be user specified first,
|
||||
* the fallback to the system default file icon.
|
||||
*
|
||||
* @param[in] in_ext_status Extension status token
|
||||
* @param[out] out_icon Pointer to receive the icon handle, or INVALID_HICON if not available.
|
||||
* @param[out] out_icon Pointer to receive the icon handle.
|
||||
* This icon handle will be freed once this icon resource object is destroyed.
|
||||
* Please make a copy immediately if you need to use it longer.
|
||||
* @return true on success, false on failure
|
||||
@@ -503,6 +518,9 @@ bool WFSelfExtStatusDestroy(Token in_self_ext_status);
|
||||
|
||||
/**
|
||||
* @brief Get the display name from a self extension status object
|
||||
*
|
||||
* The display will be user specified first,
|
||||
* the fallback to its ProgId verbatim.
|
||||
*
|
||||
* @param[in] in_self_ext_status Self extension status token
|
||||
* @param[out] out_name Pointer to receive the name string.
|
||||
@@ -514,9 +532,12 @@ bool WFSelfExtStatusGetName(Token in_self_ext_status, CStyleString *out_name);
|
||||
|
||||
/**
|
||||
* @brief Get the icon from a self extension status object
|
||||
*
|
||||
* The icon will be user specified first,
|
||||
* the fallback to the system default file icon.
|
||||
*
|
||||
* @param[in] in_self_ext_status Self extension status token
|
||||
* @param[out] out_icon Pointer to receive the icon handle, or INVALID_HICON if not available.
|
||||
* @param[out] out_icon Pointer to receive the icon handle.
|
||||
* This icon handle will be freed once this self extension status object is destroyed.
|
||||
* Please make a copy immediately if you need to use it longer.
|
||||
* @return true on success, false on failure
|
||||
|
||||
@@ -492,16 +492,9 @@ pub extern "C" fn WFProgramResolveName(
|
||||
let mut pool = pull_writer!(PROGRAM_POOL)?;
|
||||
let program = pool.get_mut(in_program)?;
|
||||
|
||||
let name = match program.resolve_name()? {
|
||||
Some(name) => {
|
||||
cstr_ffi::set_ffi_string(&name)?;
|
||||
cstr_ffi::get_ffi_string()
|
||||
},
|
||||
None => {
|
||||
std::ptr::null()
|
||||
},
|
||||
};
|
||||
Ok(name)
|
||||
let name = program.resolve_name()?;
|
||||
cstr_ffi::set_ffi_string(&name)?;
|
||||
Ok(cstr_ffi::get_ffi_string())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -515,16 +508,8 @@ pub extern "C" fn WFProgramResolveIcon(
|
||||
let program = pool.get_mut(in_program)?;
|
||||
|
||||
let icon = program.resolve_icon()?;
|
||||
let token = match icon {
|
||||
Some(icon) => {
|
||||
let mut pool = pull_writer!(ICON_RC_POOL)?;
|
||||
pool.allocate(icon)?
|
||||
},
|
||||
None => {
|
||||
object_pool::invalid_token()
|
||||
},
|
||||
};
|
||||
Ok(token)
|
||||
let mut pool = pull_writer!(ICON_RC_POOL)?;
|
||||
Ok(pool.allocate(icon)?)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -707,11 +692,8 @@ pub extern "C" fn WFExtStatusGetIcon(
|
||||
let pool = pull_reader!(EXT_STATUS_POOL)?;
|
||||
let ext_status = pool.get(in_ext_status)?;
|
||||
|
||||
let icon = match ext_status.get_icon() {
|
||||
Some(icon) => icon.get_icon(),
|
||||
None => ffi_types::INVALID_HICON,
|
||||
};
|
||||
Ok(icon)
|
||||
let icon = ext_status.get_icon();
|
||||
Ok(icon.get_icon())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -750,11 +732,8 @@ pub extern "C" fn WFSelfExtStatusGetIcon(
|
||||
let pool = pull_reader!(SELF_EXT_STATUS_POOL)?;
|
||||
let self_ext_status = pool.get(in_self_ext_status)?;
|
||||
|
||||
let icon = match self_ext_status.get_icon() {
|
||||
Some(icon) => icon.get_icon(),
|
||||
None => ffi_types::INVALID_HICON,
|
||||
};
|
||||
Ok(icon)
|
||||
let icon = self_ext_status.get_icon();
|
||||
Ok(icon.get_icon())
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user