Compare commits

...
5 Commits
Author SHA1 Message Date
yyc12345 b45a5c2760 fix: fix the cli option name in qwfassoc 2026-08-18 21:08:22 +08:00
yyc12345 27235c2619 fix: fix qwfassoc build error
- fix qwfassoc build error
- set version of wfassoc to official version
- add version restriction when qwfassoc finding wfassoc
- rename qwfassoc project name in cmake configuration file
- set standalone build to OFF in default
2026-08-18 20:27:08 +08:00
yyc12345 6687ccb143 feat: adapt to new wfassoc lib for qwfassoc 2026-08-17 10:38:39 +08:00
yyc12345 d2e5bcf2ed feat: add wrapper for WFHasPrivilege in c++ header 2026-08-17 10:22:37 +08:00
yyc12345 36330437de feat: update wfassoc c/c++ bindings 2026-08-15 18:06:09 +08:00
13 changed files with 287 additions and 318 deletions
Generated
+3 -3
View File
@@ -720,7 +720,7 @@ dependencies = [
[[package]] [[package]]
name = "wfassoc" name = "wfassoc"
version = "0.1.0" version = "1.0.0"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"regex", "regex",
@@ -734,7 +734,7 @@ dependencies = [
[[package]] [[package]]
name = "wfassoc-cdylib" name = "wfassoc-cdylib"
version = "0.1.0" version = "1.0.0"
dependencies = [ dependencies = [
"num_enum", "num_enum",
"sarasacw-omrf", "sarasacw-omrf",
@@ -745,7 +745,7 @@ dependencies = [
[[package]] [[package]]
name = "wfassoc-exec" name = "wfassoc-exec"
version = "0.1.0" version = "1.0.0"
dependencies = [ dependencies = [
"clap", "clap",
"comfy-table", "comfy-table",
+117
View File
@@ -0,0 +1,117 @@
## ===== Personal =====
build/
install/
## ===== Visual Studio (Partial) =====
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
## ===== C++ =====
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
## ===== Qt =====
# C++ objects and libs
*.slo
*.lo
*.o
*.a
*.la
*.lai
*.so
*.so.*
*.dll
*.dylib
# Qt-es
object_script.*.Release
object_script.*.Debug
*_plugin_import.cpp
/.qmake.cache
/.qmake.stash
*.pro.user
*.pro.user.*
*.qbs.user
*.qbs.user.*
*.moc
moc_*.cpp
moc_*.h
qrc_*.cpp
ui_*.h
*.qmlc
*.jsc
Makefile*
*build-*
*.qm
*.prl
# Qt unit tests
target_wrapper.*
# QtCreator
*.autosave
# QtCreator Qml
*.qmlproject.user
*.qmlproject.user.*
# QtCreator CMake
CMakeLists.txt.user*
# QtCreator 4.8< compilation database
compile_commands.json
# QtCreator local machine specific files for imported projects
*creator.user*
*_qmlcache.qrc
+5 -6
View File
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20) cmake_minimum_required(VERSION 3.20)
project(qwfassoc_suite LANGUAGES CXX) project(qwfassoc LANGUAGES CXX)
# Qt 6 requires C++17 at minimum. # Qt 6 requires C++17 at minimum.
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
@@ -13,20 +13,19 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON) set(CMAKE_AUTORCC ON)
# Make the bundled Findwfassoc.cmake module visible to find_package().
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# Qt and LinguistTools are used by both subprojects, so they are looked up at # Qt and LinguistTools are used by both subprojects, so they are looked up at
# the top level. The same is true for wfassoc: although only the qwfassoc # the top level. The same is true for wfassoc: although only the qwfassoc
# library links against it directly, PUBLIC propagation from the library # library links against it directly, PUBLIC propagation from the library
# target makes the dependency available to qwfassoc-standalone as well. # target makes the dependency available to qwfassoc-standalone as well.
# wfassoc ships a standard config-mode package (wfassocConfig.cmake); point
# CMAKE_PREFIX_PATH or wfassoc_ROOT at its install prefix to locate it.
# toml11 is only needed when the standalone executable is built, so it is # toml11 is only needed when the standalone executable is built, so it is
# looked up conditionally below. # looked up conditionally below.
find_package(Qt6 REQUIRED COMPONENTS Widgets LinguistTools) find_package(Qt6 REQUIRED COMPONENTS Widgets LinguistTools)
find_package(wfassoc REQUIRED) find_package(wfassoc 1.0.0 REQUIRED)
# The standalone executable is optional: embedders may want only the library. # The standalone executable is optional: embedders may want only the library.
option(QWFASSOC_BUILD_STANDALONE "Build the qwfassoc-standalone executable" ON) option(QWFASSOC_BUILD_STANDALONE "Build the qwfassoc-standalone executable" OFF)
add_subdirectory(qwfassoc) add_subdirectory(qwfassoc)
+3 -6
View File
@@ -9,9 +9,6 @@ The project is organized as two CMake subprojects:
qwfassoc/ Parent directory (this README) qwfassoc/ Parent directory (this README)
├── CMakeLists.txt Top-level CMake; add_subdirectory's both ├── CMakeLists.txt Top-level CMake; add_subdirectory's both
│ subprojects and finds Qt, wfassoc, toml11 │ subprojects and finds Qt, wfassoc, toml11
├── cmake/
│ ├── Findwfassoc.cmake Verbatim copy of wfassoc's Find module
│ └── README.md Provenance notes for the copy
├── qwfassoc/ Shared library subproject ├── qwfassoc/ Shared library subproject
│ ├── CMakeLists.txt │ ├── CMakeLists.txt
│ ├── i18n/ │ ├── i18n/
@@ -85,9 +82,9 @@ Reproduces the original tabbed wfassoc configurator by:
* **CMake** 3.20 or newer (3.21+ recommended for `qt6_add_translations`). * **CMake** 3.20 or newer (3.21+ recommended for `qt6_add_translations`).
* A C++17 compiler. * A C++17 compiler.
* **Qt 6** with the `Widgets` and `LinguistTools` components. * **Qt 6** with the `Widgets` and `LinguistTools` components.
* **wfassoc**, with `wfassoc_ROOT` pointing at an installed tree (see * **wfassoc**, installed as a standard config-mode CMake package
[`cmake/Findwfassoc.cmake`](cmake/Findwfassoc.cmake) for the expected (`wfassocConfig.cmake`). Point `wfassoc_ROOT` (or `CMAKE_PREFIX_PATH`) at
directory layout). its install prefix so `find_package(wfassoc)` can locate it.
* **toml11** — only required when building the standalone executable. * **toml11** — only required when building the standalone executable.
## Building ## Building
-101
View File
@@ -1,101 +0,0 @@
# Findwfassoc.cmake
# ----------------
# Find wfassoc library and headers.
#
# This module requires the user to set wfassoc_ROOT to the installation
# directory of wfassoc. The directory structure under wfassoc_ROOT must be:
# bin/ - contains wfassoc_cdylib.dll
# include/ - contains wfassoc.h and wfassoc++.h
# lib/ - contains wfassoc_cdylib.dll.lib (import library)
#
# This module defines the following variables:
# wfassoc_FOUND - True if wfassoc was found
# wfassoc_INCLUDE_DIRS - Path to wfassoc include directory
# wfassoc_LIBRARIES - Path to wfassoc import library
# wfassoc_DLL - Path to wfassoc DLL
# wfassoc_ROOT - The root directory (user-provided)
#
# This module also creates the following imported targets:
# wfassoc::wfassoc - Main wfassoc library (includes both include and link)
#
set(wfassoc_FOUND FALSE)
# Require user to set wfassoc_ROOT
if(NOT wfassoc_ROOT)
message(FATAL_ERROR "wfassoc_ROOT must be set to the installation directory of wfassoc")
endif()
# Check existence of required subdirectories
if(NOT EXISTS ${wfassoc_ROOT})
message(FATAL_ERROR "wfassoc_ROOT directory does not exist: ${wfassoc_ROOT}")
endif()
set(wfassoc_INCLUDE_DIR ${wfassoc_ROOT}/include)
set(wfassoc_LIB_DIR ${wfassoc_ROOT}/lib)
set(wfassoc_BIN_DIR ${wfassoc_ROOT}/bin)
# Find header files
if(EXISTS ${wfassoc_INCLUDE_DIR}/wfassoc.h AND EXISTS ${wfassoc_INCLUDE_DIR}/wfassoc++.h)
set(wfassoc_INCLUDE_DIRS ${wfassoc_INCLUDE_DIR})
else()
message(SEND_ERROR "Missing wfassoc header files in ${wfassoc_INCLUDE_DIR}")
return()
endif()
# Find import library (.lib)
find_file(wfassoc_LIBRARIES
NAMES wfassoc_cdylib.dll.lib
PATHS ${wfassoc_LIB_DIR}
NO_DEFAULT_PATH
DOC "wfassoc import library"
)
if(NOT wfassoc_LIBRARIES)
message(SEND_ERROR "Missing wfassoc import library (wfassoc_cdylib.dll.lib) in ${wfassoc_LIB_DIR}")
return()
endif()
# Find DLL file
find_file(wfassoc_DLL
NAMES wfassoc_cdylib.dll
PATHS ${wfassoc_BIN_DIR}
NO_DEFAULT_PATH
DOC "wfassoc dynamic library"
)
if(NOT wfassoc_DLL)
message(SEND_ERROR "Missing wfassoc DLL (wfassoc_cdylib.dll) in ${wfassoc_BIN_DIR}")
return()
endif()
# Everything found
set(wfassoc_FOUND TRUE)
# Mark variables as advanced for ccmake/cmake-gui
mark_as_advanced(wfassoc_INCLUDE_DIRS wfassoc_LIBRARIES wfassoc_DLL)
# Create imported target for wfassoc
if(wfassoc_FOUND AND NOT TARGET wfassoc::wfassoc)
add_library(wfassoc::wfassoc SHARED IMPORTED)
# Set include directories
set_target_properties(wfassoc::wfassoc PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${wfassoc_INCLUDE_DIRS}
)
# Set import library location
set_target_properties(wfassoc::wfassoc PROPERTIES
IMPORTED_IMPLIB "${wfassoc_LIBRARIES}"
IMPORTED_LOCATION "${wfassoc_DLL}"
)
endif()
# Optional: Print status message
if(wfassoc_FOUND)
message(STATUS "Found wfassoc:")
message(STATUS " Root : ${wfassoc_ROOT}")
message(STATUS " Include : ${wfassoc_INCLUDE_DIRS}")
message(STATUS " Library : ${wfassoc_LIBRARIES}")
message(STATUS " DLL : ${wfassoc_DLL}")
endif()
-19
View File
@@ -1,19 +0,0 @@
# qwfassoc/cmake
This directory holds CMake helper modules used by the `qwfassoc` project.
## `Findwfassoc.cmake`
This file is a verbatim copy of the upstream `Findwfassoc.cmake` shipped with
the wfassoc C dynamic library, located at:
```
wfassoc-cdylib/cbindgen/Findwfassoc.cmake
```
The copy is committed here so that `qwfassoc` can locate the wfassoc library
through a standard `find_package(wfassoc)` call without depending on the source
tree layout at configure time.
To keep this copy in sync with the upstream version, re-run the copy command
shown above whenever `wfassoc-cdylib/cbindgen/Findwfassoc.cmake` is updated.
@@ -89,12 +89,12 @@ int main(int argc, char* argv[]) {
parser.addHelpOption(); parser.addHelpOption();
QCommandLineOption manifestOption( QCommandLineOption manifestOption(
QStringList() << QStringLiteral("c") << QStringLiteral("manifest"), QStringList() << QStringLiteral("m") << QStringLiteral("manifest"),
QCoreApplication::translate(kTranslationContext, QCoreApplication::translate(kTranslationContext,
"Path to the application manifest TOML file."), "Path to the application manifest TOML file."),
QStringLiteral("manifest")); QStringLiteral("manifest"));
QCommandLineOption forOption( QCommandLineOption forOption(
QStringList() << QStringLiteral("f") << QStringLiteral("for"), QStringList() << QStringLiteral("t") << QStringLiteral("target"),
QCoreApplication::translate(kTranslationContext, QCoreApplication::translate(kTranslationContext,
"Target scope: \"user\" or \"system\"."), "Target scope: \"user\" or \"system\"."),
QStringLiteral("scope")); QStringLiteral("scope"));
@@ -111,13 +111,13 @@ int main(int argc, char* argv[]) {
return fatal(nullptr, return fatal(nullptr,
QCoreApplication::translate( QCoreApplication::translate(
kTranslationContext, kTranslationContext,
"The --manifest/-c option is required.")); "The --manifest/-m option is required."));
} }
if (forValue.isEmpty()) { if (forValue.isEmpty()) {
return fatal(nullptr, return fatal(nullptr,
QCoreApplication::translate( QCoreApplication::translate(
kTranslationContext, kTranslationContext,
"The --for/-f option is required.")); "The --target/-t option is required."));
} }
qwfassoc::TargetScope scope; qwfassoc::TargetScope scope;
@@ -127,13 +127,6 @@ int main(int argc, char* argv[]) {
return fatal(nullptr, QString::fromUtf8(e.what())); return fatal(nullptr, QString::fromUtf8(e.what()));
} }
// Initialize the wfassoc runtime. WFStartup must run before most other
// wfassoc calls; if it fails we cannot proceed.
if (!wfassoc::WFStartup()) {
return fatal(nullptr,
QString::fromUtf8(wfassoc::WFGetLastError()));
}
// Build the manifest -> schema -> program pipeline and run the dialog. // Build the manifest -> schema -> program pipeline and run the dialog.
// Program construction consumes the schema (move) and performs the deep // Program construction consumes the schema (move) and performs the deep
// validation (identifier format, dangling references, etc.). // validation (identifier format, dangling references, etc.).
@@ -147,10 +140,8 @@ int main(int argc, char* argv[]) {
qwfassoc::MainWindow window(std::move(program), scope); qwfassoc::MainWindow window(std::move(program), scope);
exitCode = window.exec(); exitCode = window.exec();
} catch (const std::exception& e) { } catch (const std::exception& e) {
wfassoc::WFShutdown();
return fatal(nullptr, QString::fromUtf8(e.what())); return fatal(nullptr, QString::fromUtf8(e.what()));
} }
wfassoc::WFShutdown();
return exitCode; return exitCode;
} }
@@ -91,7 +91,7 @@ Manifest parseManifestFile(const std::string& path) {
} }
} catch (const std::exception& e) { } catch (const std::exception& e) {
throw std::runtime_error( throw std::runtime_error(
"Manifest \"exts\" table contains an invalid entry: " + std::string("Manifest \"exts\" table contains an invalid entry: ") +
e.what()); e.what());
} }
} }
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "wfassoc-cdylib" name = "wfassoc-cdylib"
version = "0.1.0" version = "1.0.0"
authors = ["yyc12345"] authors = ["yyc12345"]
edition = "2024" edition = "2024"
description = "The dynamic library exposed for C/C++ users reading or manipulating Windows file assocation." description = "The dynamic library exposed for C/C++ users reading or manipulating Windows file assocation."
+50 -43
View File
@@ -24,8 +24,16 @@
*/ */
namespace wfassocpp { namespace wfassocpp {
/** @brief Type representing a null-terminated UTF-8 C-style string */ /** @brief Type representing a pointer to a null-terminated UTF-8 C-style string */
using CString = wfassoc::WFCString; using StrPtr = wfassoc::WFStrPtr;
/**
* @brief Type representing an error code returned by FFI functions
*
* WFERROR_OK is the only value representing absolute success.
* Any other value's meaning is decided by this library,
* currently WFERROR_ERR represents a generic failure.
*/
using Error = wfassoc::WFError;
/** /**
* @brief Type representing a handle/token for managed objects * @brief Type representing a handle/token for managed objects
* *
@@ -39,10 +47,12 @@ using Token = wfassoc::WFToken;
* This type is equivalent to the Win32 HICON type. * This type is equivalent to the Win32 HICON type.
*/ */
using HICON = wfassoc::WFHICON; using HICON = wfassoc::WFHICON;
/** @brief Invalid token value used as a sentinel for no object */
constexpr Token INVALID_TOKEN = wfassoc::WF_INVALID_TOKEN;
/** @brief Invalid icon handle value */ /** @brief Invalid icon handle value */
using INVALID_HICON = wfassoc::WF_INVALID_HICON; constexpr HICON INVALID_HICON = wfassoc::WF_INVALID_HICON;
/** @brief Invalid index value used for error conditions */ /** @brief Invalid index value used for error conditions */
using INVALID_INDEX = wfassoc::WF_INVALID_INDEX; constexpr size_t INVALID_INDEX = wfassoc::WF_INVALID_INDEX;
/** /**
* @brief Registration scope for file associations * @brief Registration scope for file associations
* *
@@ -60,28 +70,25 @@ using View = wfassoc::WFView;
* @private * @private
* @brief Check the result of a C API call and throw on failure * @brief Check the result of a C API call and throw on failure
* *
* @param[in] result Boolean result from a C API call * @param[in] result Error code returned from a C API call
* @throws std::runtime_error if result is false, with the error message from WFGetLastError() * @throws std::runtime_error if result is not WFERROR_OK, with the error message from WFGetLastError()
*/ */
inline void _Check(bool result) { inline void _Check(wfassoc::WFError result) {
if (!result) { if (result != wfassoc::WFERROR_OK) {
throw std::runtime_error(wfassoc::WFGetLastError()); throw std::runtime_error(wfassoc::WFGetLastError());
} }
} }
/** /**
* @private * @brief Check if the current process has administrative privileges
* @brief Get the invalid token value
* *
* In theory, invalid token value should be a constant value. * @return true if the current process has administrative privileges, false otherwise
* However, due to the library used in Rust side, this value can only be fetched at runtime. * @throws std::runtime_error if the operation fails
* This function caches the value on first call for subsequent use.
*
* @return An invalid token value
*/ */
inline Token _INVALID_TOKEN() { inline bool HasPrivilege() {
static Token v = wfassoc::WFInvalidToken(); bool result = false;
return v; _Check(wfassoc::WFHasPrivilege(&result));
return result;
} }
/** /**
@@ -106,7 +113,7 @@ public:
* Releases resources associated with the Schema object. * Releases resources associated with the Schema object.
*/ */
~Schema() { ~Schema() {
if (_token != _INVALID_TOKEN()) { if (_token != INVALID_TOKEN) {
wfassoc::WFSchemaDestroy(_token); wfassoc::WFSchemaDestroy(_token);
} }
} }
@@ -117,15 +124,15 @@ public:
Schema& operator=(const Schema&) = delete; Schema& operator=(const Schema&) = delete;
/** @brief Move constructor */ /** @brief Move constructor */
Schema(Schema&& other) noexcept : _token(other._token) { other._token = _INVALID_TOKEN(); } Schema(Schema&& other) noexcept : _token(other._token) { other._token = INVALID_TOKEN; }
/** @brief Move assignment operator */ /** @brief Move assignment operator */
Schema& operator=(Schema&& other) noexcept { Schema& operator=(Schema&& other) noexcept {
if (this != &other) { if (this != &other) {
if (_token != _INVALID_TOKEN()) { if (_token != INVALID_TOKEN) {
wfassoc::WFSchemaDestroy(_token); wfassoc::WFSchemaDestroy(_token);
} }
_token = other._token; _token = other._token;
other._token = _INVALID_TOKEN(); other._token = INVALID_TOKEN;
} }
return *this; return *this;
} }
@@ -240,7 +247,7 @@ private:
*/ */
Token Release() noexcept { Token Release() noexcept {
Token t = _token; Token t = _token;
_token = _INVALID_TOKEN(); _token = INVALID_TOKEN;
return t; return t;
} }
@@ -270,7 +277,7 @@ public:
* Releases resources associated with the icon resource. * Releases resources associated with the icon resource.
*/ */
~IconRc() { ~IconRc() {
if (_token != _INVALID_TOKEN()) { if (_token != INVALID_TOKEN) {
wfassoc::WFIconRcDestroy(_token); wfassoc::WFIconRcDestroy(_token);
} }
} }
@@ -281,15 +288,15 @@ public:
IconRc& operator=(const IconRc&) = delete; IconRc& operator=(const IconRc&) = delete;
/** @brief Move constructor */ /** @brief Move constructor */
IconRc(IconRc&& other) noexcept : _token(other._token) { other._token = _INVALID_TOKEN(); } IconRc(IconRc&& other) noexcept : _token(other._token) { other._token = INVALID_TOKEN; }
/** @brief Move assignment operator */ /** @brief Move assignment operator */
IconRc& operator=(IconRc&& other) noexcept { IconRc& operator=(IconRc&& other) noexcept {
if (this != &other) { if (this != &other) {
if (_token != _INVALID_TOKEN()) { if (_token != INVALID_TOKEN) {
wfassoc::WFIconRcDestroy(_token); wfassoc::WFIconRcDestroy(_token);
} }
_token = other._token; _token = other._token;
other._token = _INVALID_TOKEN(); other._token = INVALID_TOKEN;
} }
return *this; return *this;
} }
@@ -334,7 +341,7 @@ public:
* Releases resources associated with the extension status. * Releases resources associated with the extension status.
*/ */
~ExtStatus() { ~ExtStatus() {
if (_token != _INVALID_TOKEN()) { if (_token != INVALID_TOKEN) {
wfassoc::WFExtStatusDestroy(_token); wfassoc::WFExtStatusDestroy(_token);
} }
} }
@@ -345,15 +352,15 @@ public:
ExtStatus& operator=(const ExtStatus&) = delete; ExtStatus& operator=(const ExtStatus&) = delete;
/** @brief Move constructor */ /** @brief Move constructor */
ExtStatus(ExtStatus&& other) noexcept : _token(other._token) { other._token = _INVALID_TOKEN(); } ExtStatus(ExtStatus&& other) noexcept : _token(other._token) { other._token = INVALID_TOKEN; }
/** @brief Move assignment operator */ /** @brief Move assignment operator */
ExtStatus& operator=(ExtStatus&& other) noexcept { ExtStatus& operator=(ExtStatus&& other) noexcept {
if (this != &other) { if (this != &other) {
if (_token != _INVALID_TOKEN()) { if (_token != INVALID_TOKEN) {
wfassoc::WFExtStatusDestroy(_token); wfassoc::WFExtStatusDestroy(_token);
} }
_token = other._token; _token = other._token;
other._token = _INVALID_TOKEN(); other._token = INVALID_TOKEN;
} }
return *this; return *this;
} }
@@ -415,7 +422,7 @@ public:
* Releases resources associated with the self extension status. * Releases resources associated with the self extension status.
*/ */
~SelfExtStatus() { ~SelfExtStatus() {
if (_token != _INVALID_TOKEN()) { if (_token != INVALID_TOKEN) {
wfassoc::WFSelfExtStatusDestroy(_token); wfassoc::WFSelfExtStatusDestroy(_token);
} }
} }
@@ -426,15 +433,15 @@ public:
SelfExtStatus& operator=(const SelfExtStatus&) = delete; SelfExtStatus& operator=(const SelfExtStatus&) = delete;
/** @brief Move constructor */ /** @brief Move constructor */
SelfExtStatus(SelfExtStatus&& other) noexcept : _token(other._token) { other._token = _INVALID_TOKEN(); } SelfExtStatus(SelfExtStatus&& other) noexcept : _token(other._token) { other._token = INVALID_TOKEN; }
/** @brief Move assignment operator */ /** @brief Move assignment operator */
SelfExtStatus& operator=(SelfExtStatus&& other) noexcept { SelfExtStatus& operator=(SelfExtStatus&& other) noexcept {
if (this != &other) { if (this != &other) {
if (_token != _INVALID_TOKEN()) { if (_token != INVALID_TOKEN) {
wfassoc::WFSelfExtStatusDestroy(_token); wfassoc::WFSelfExtStatusDestroy(_token);
} }
_token = other._token; _token = other._token;
other._token = _INVALID_TOKEN(); other._token = INVALID_TOKEN;
} }
return *this; return *this;
} }
@@ -525,7 +532,7 @@ public:
* Releases resources associated with the Program. * Releases resources associated with the Program.
*/ */
~Program() { ~Program() {
if (_token != _INVALID_TOKEN()) { if (_token != INVALID_TOKEN) {
wfassoc::WFProgramDestroy(_token); wfassoc::WFProgramDestroy(_token);
} }
} }
@@ -536,15 +543,15 @@ public:
Program& operator=(const Program&) = delete; Program& operator=(const Program&) = delete;
/** @brief Move constructor */ /** @brief Move constructor */
Program(Program&& other) noexcept : _token(other._token) { other._token = _INVALID_TOKEN(); } Program(Program&& other) noexcept : _token(other._token) { other._token = INVALID_TOKEN; }
/** @brief Move assignment operator */ /** @brief Move assignment operator */
Program& operator=(Program&& other) noexcept { Program& operator=(Program&& other) noexcept {
if (this != &other) { if (this != &other) {
if (_token != _INVALID_TOKEN()) { if (_token != INVALID_TOKEN) {
wfassoc::WFProgramDestroy(_token); wfassoc::WFProgramDestroy(_token);
} }
_token = other._token; _token = other._token;
other._token = _INVALID_TOKEN(); other._token = INVALID_TOKEN;
} }
return *this; return *this;
} }
@@ -576,7 +583,7 @@ public:
* @throws std::runtime_error if the operation fails * @throws std::runtime_error if the operation fails
*/ */
IconRc ResolveIcon() { IconRc ResolveIcon() {
Token token = _INVALID_TOKEN(); Token token = INVALID_TOKEN;
_Check(wfassoc::WFProgramResolveIcon(_token, &token)); _Check(wfassoc::WFProgramResolveIcon(_token, &token));
return IconRc(token); return IconRc(token);
} }
@@ -614,7 +621,7 @@ public:
* @throws std::runtime_error if the operation fails * @throws std::runtime_error if the operation fails
*/ */
SelfExtStatus ResolveExt(size_t index) { SelfExtStatus ResolveExt(size_t index) {
Token token = _INVALID_TOKEN(); Token token = INVALID_TOKEN;
_Check(wfassoc::WFProgramResolveExt(_token, index, &token)); _Check(wfassoc::WFProgramResolveExt(_token, index, &token));
return SelfExtStatus(token); return SelfExtStatus(token);
} }
@@ -676,9 +683,9 @@ public:
* @throws std::runtime_error if the operation fails * @throws std::runtime_error if the operation fails
*/ */
std::optional<ExtStatus> QueryExt(View view, size_t index) { std::optional<ExtStatus> QueryExt(View view, size_t index) {
Token token = _INVALID_TOKEN(); Token token = INVALID_TOKEN;
_Check(wfassoc::WFProgramQueryExt(_token, view, index, &token)); _Check(wfassoc::WFProgramQueryExt(_token, view, index, &token));
if (token == _INVALID_TOKEN()) { if (token == INVALID_TOKEN) {
return std::nullopt; return std::nullopt;
} }
return ExtStatus(token); return ExtStatus(token);
+101 -123
View File
@@ -34,7 +34,15 @@ namespace wfassoc {
#ifdef __cplusplus #ifdef __cplusplus
/** Type representing a null-terminated UTF-8 C-style string */ /** Type representing a null-terminated UTF-8 C-style string */
using WFCString = const char*; using WFStrPtr = const char*;
/**
* @brief Type representing an error code returned by FFI functions
*
* WFERROR_OK is the only value representing absolute success.
* Any other value's meaning is decided by this library,
* currently WFERROR_ERR represents a generic failure.
*/
using WFError = uint32_t;
/** /**
* @brief Type representing a handle/token for managed objects * @brief Type representing a handle/token for managed objects
* *
@@ -49,18 +57,28 @@ using WFToken = uint64_t;
*/ */
using WFHICON = void*; using WFHICON = void*;
#else // __cplusplus #else // __cplusplus
typedef const char *WFCString; typedef const char *WFStrPtr;
typedef uint32_t WFError;
typedef uint64_t WFToken; typedef uint64_t WFToken;
typedef void *WFHICON; typedef void *WFHICON;
#endif // __cplusplus #endif // __cplusplus
#ifdef __cplusplus #ifdef __cplusplus
/** The error code representing absolute success. */
constexpr WFError WFERROR_OK = 0u;
/** The error code representing a generic failure. */
constexpr WFError WFERROR_ERR = 1u;
/** Invalid token value used as a sentinel for no object */
constexpr WFToken WF_INVALID_TOKEN = 0u;
/** Invalid icon handle value */ /** Invalid icon handle value */
constexpr WFHICON WF_INVALID_HICON = nullptr; constexpr WFHICON WF_INVALID_HICON = nullptr;
/** Invalid index value used for error conditions */ /** Invalid index value used for error conditions */
constexpr size_t WF_INVALID_INDEX = static_cast<size_t>(-1); constexpr size_t WF_INVALID_INDEX = static_cast<size_t>(-1);
#else // __cplusplus #else // __cplusplus
static const WFError WFERROR_OK = 0u;
static const WFError WFERROR_ERR = 1u;
static const WFToken WF_INVALID_TOKEN = 0u;
static const WFHICON WF_INVALID_HICON = NULL; static const WFHICON WF_INVALID_HICON = NULL;
static const size_t WF_INVALID_INDEX = ((size_t)-1); static const size_t WF_INVALID_INDEX = ((size_t)-1);
#endif // __cplusplus #endif // __cplusplus
@@ -111,25 +129,6 @@ static const WFView WF_VIEW_HYBRID = 2u;
extern "C" { extern "C" {
#endif // __cplusplus #endif // __cplusplus
/**
* @brief Initialize the wfassoc library
*
* This function must be called before using the MOST of any other wfassoc functions.
*
* @return true on success, false on failure.
*/
bool WFStartup(void);
/**
* @brief Shutdown the wfassoc library
*
* Cleans up all allocated resources and object pools.
* Should be called when done using the library.
*
* @return true on success, false on failure.
*/
bool WFShutdown(void);
/** /**
* @brief Get the last error message * @brief Get the last error message
* *
@@ -137,46 +136,25 @@ bool WFShutdown(void);
* The returned error message string is valid until the next API call. * The returned error message string is valid until the next API call.
* *
* For most functions located in this library, except some special function indicated in their notes, * For most functions located in this library, except some special function indicated in their notes,
* they return boolean value indicating whether function is successful or not. * they return WFERROR_OK when the function is successful, and WFERROR_ERR when the function is failed.
* Once they fail, you can call this function to get a human-readable error message. * Once they fail, you can call this function to get a human-readable error message.
* *
* The execution of this function do not need to be wrapped by WFStartup() and WFShutdown().
*
* The string this function return use different buffer with function return string value. * The string this function return use different buffer with function return string value.
* So you don't worry about that calling this function may invalidate function function return string value. * So you don't worry about that calling this function may invalidate function return string value.
* *
* @return Null-terminated UTF-8 string containing the error message. * @return Null-terminated UTF-8 string containing the error message.
* If no error has occurred, the string is empty. * If no error has occurred, the string is empty.
* There is no possibility of a NULL return value. * There is no possibility of a NULL return value.
*/ */
WFCString WFGetLastError(void); WFStrPtr WFGetLastError(void);
/** /**
* @brief Check if the current process has administrative privileges * @brief Check if the current process has administrative privileges
* *
* This function will not throw any error. * @param[out] out_has Pointer to receive whether the current process has administrative privileges.
* There is no necessity to call WFGetLastError() after this function. * @return WFERROR_OK on success, WFERROR_ERR on failure.
* The return value only indicates whether the current process has administrative privileges or not.
*
* The execution of this function do not need to be wrapped by WFStartup() and WFShutdown().
*
* @return true if running with admin privileges, false otherwise
*/ */
bool WFHasPrivilege(void); WFError WFHasPrivilege(bool *out_has);
/**
* @brief Get an invalid token value
*
* In theory, invalid token value should be a constant value.
* However, due to the library I used in Rust side, this value only can be fetched at runtime.
* So I expose this function to make programmer can fetch this constant value.
* Theoretically, you just need to fetch this function only once at the beginning of your program.
*
* The execution of this function do not need to be wrapped by WFStartup() and WFShutdown().
*
* @return An invalid token value
*/
WFToken WFInvalidWFToken(void);
/** /**
* @brief Create a new Schema object * @brief Create a new Schema object
@@ -189,9 +167,9 @@ WFToken WFInvalidWFToken(void);
* The receiver take the ownership of this Schema object. * The receiver take the ownership of this Schema object.
* And it should be freed by calling WFSchemaDestroy() when it is no longer needed, * And it should be freed by calling WFSchemaDestroy() when it is no longer needed,
* or consumed by creating a Program object via WFProgramCreate(). * or consumed by creating a Program object via WFProgramCreate().
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFSchemaCreate(WFToken *out_schema); WFError WFSchemaCreate(WFToken *out_schema);
/** /**
* @brief Destroy a Schema object * @brief Destroy a Schema object
@@ -202,9 +180,9 @@ bool WFSchemaCreate(WFToken *out_schema);
* because the convertion function from Schema to Program will consume given Schema object to produce Program object. * because the convertion function from Schema to Program will consume given Schema object to produce Program object.
* *
* @param[in] in_schema Schema token to destroy * @param[in] in_schema Schema token to destroy
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFSchemaDestroy(WFToken in_schema); WFError WFSchemaDestroy(WFToken in_schema);
/** /**
* @brief Set the program identifier for a Schema * @brief Set the program identifier for a Schema
@@ -213,9 +191,9 @@ bool WFSchemaDestroy(WFToken in_schema);
* @param[in] in_value Null-terminated UTF-8 string containing the identifier. * @param[in] in_value Null-terminated UTF-8 string containing the identifier.
* This identifier should not be empty, must start with alphabet character, * This identifier should not be empty, must start with alphabet character,
* and follow with alphabet characters, digits, underline, or hyphens. * and follow with alphabet characters, digits, underline, or hyphens.
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFSchemaSetIdentifier(WFToken in_schema, WFCString in_value); WFError WFSchemaSetIdentifier(WFToken in_schema, WFStrPtr in_value);
/** /**
* @brief Set the program path for a Schema * @brief Set the program path for a Schema
@@ -223,9 +201,9 @@ bool WFSchemaSetIdentifier(WFToken in_schema, WFCString in_value);
* @param[in] in_schema Schema token * @param[in] in_schema Schema token
* @param[in] in_value Null-terminated UTF-8 string containing the program path. * @param[in] in_value Null-terminated UTF-8 string containing the program path.
* This path should be the fully qualified path to the application. * This path should be the fully qualified path to the application.
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFSchemaSetPath(WFToken in_schema, WFCString in_value); WFError WFSchemaSetPath(WFToken in_schema, WFStrPtr in_value);
/** /**
* @brief Set the program CLSID for a Schema * @brief Set the program CLSID for a Schema
@@ -234,36 +212,36 @@ bool WFSchemaSetPath(WFToken in_schema, WFCString in_value);
* @param[in] in_value Null-terminated UTF-8 string containing the CLSID. * @param[in] in_value Null-terminated UTF-8 string containing the CLSID.
* This CLSID string should be in the format of @c {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} . * This CLSID string should be in the format of @c {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} .
* Please note that curly braces are required. * Please note that curly braces are required.
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFSchemaSetClsid(WFToken in_schema, WFCString in_value); WFError WFSchemaSetClsid(WFToken in_schema, WFStrPtr in_value);
/** /**
* @brief Set the program name for a Schema (optional) * @brief Set the program name for a Schema (optional)
* *
* @param[in] in_schema Schema token * @param[in] in_schema Schema token
* @param[in] in_value Null-terminated UTF-8 string containing the name, or NULL to clear * @param[in] in_value Null-terminated UTF-8 string containing the name, or NULL to clear
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFSchemaSetName(WFToken in_schema, WFCString in_value); WFError WFSchemaSetName(WFToken in_schema, WFStrPtr in_value);
/** /**
* @brief Set the program icon for a Schema (optional) * @brief Set the program icon for a Schema (optional)
* *
* @param[in] in_schema Schema token * @param[in] in_schema Schema token
* @param[in] in_value Null-terminated UTF-8 string containing the icon path, or NULL to clear * @param[in] in_value Null-terminated UTF-8 string containing the icon path, or NULL to clear
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFSchemaSetIcon(WFToken in_schema, WFCString in_value); WFError WFSchemaSetIcon(WFToken in_schema, WFStrPtr in_value);
/** /**
* @brief Set the program behavior for a Schema (optional) * @brief Set the program behavior for a Schema (optional)
* *
* @param[in] in_schema Schema token * @param[in] in_schema Schema token
* @param[in] in_value Null-terminated UTF-8 string containing the behavior command, or NULL to clear * @param[in] in_value Null-terminated UTF-8 string containing the behavior command, or NULL to clear
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFSchemaSetBehavior(WFToken in_schema, WFCString in_value); WFError WFSchemaSetBehavior(WFToken in_schema, WFStrPtr in_value);
/** /**
* @brief Add a string resource entry to a Schema * @brief Add a string resource entry to a Schema
@@ -272,9 +250,9 @@ bool WFSchemaSetBehavior(WFToken in_schema, WFCString in_value);
* @param[in] in_name Null-terminated UTF-8 string containing the name of this entry * @param[in] in_name Null-terminated UTF-8 string containing the name of this entry
* @param[in] in_value Null-terminated UTF-8 string containing the value of this entry. * @param[in] in_value Null-terminated UTF-8 string containing the value of this entry.
* It can be a plain string or a reference string to resource. * It can be a plain string or a reference string to resource.
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFSchemaAddStr(WFToken in_schema, WFCString in_name, WFCString in_value); WFError WFSchemaAddStr(WFToken in_schema, WFStrPtr in_name, WFStrPtr in_value);
/** /**
* @brief Add an icon registry entry to a Schema * @brief Add an icon registry entry to a Schema
@@ -283,9 +261,9 @@ bool WFSchemaAddStr(WFToken in_schema, WFCString in_name, WFCString in_value);
* @param[in] in_name Null-terminated UTF-8 string containing the name of this entry * @param[in] in_name Null-terminated UTF-8 string containing the name of this entry
* @param[in] in_value Null-terminated UTF-8 string containing the value of this entry. * @param[in] in_value Null-terminated UTF-8 string containing the value of this entry.
* It can be a path to icon or a reference string to resource. * It can be a path to icon or a reference string to resource.
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFSchemaAddIcon(WFToken in_schema, WFCString in_name, WFCString in_value); WFError WFSchemaAddIcon(WFToken in_schema, WFStrPtr in_name, WFStrPtr in_value);
/** /**
* @brief Add a behavior registry entry to a Schema * @brief Add a behavior registry entry to a Schema
@@ -294,9 +272,9 @@ bool WFSchemaAddIcon(WFToken in_schema, WFCString in_name, WFCString in_value);
* @param[in] in_name Null-terminated UTF-8 string containing the name of this entry * @param[in] in_name Null-terminated UTF-8 string containing the name of this entry
* @param[in] in_value Null-terminated UTF-8 string containing the value of this entry. * @param[in] in_value Null-terminated UTF-8 string containing the value of this entry.
* It should be a valid command line string which use \c %1, \c %2, etc. to represent parameters. * It should be a valid command line string which use \c %1, \c %2, etc. to represent parameters.
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFSchemaAddBehavior(WFToken in_schema, WFCString in_name, WFCString in_value); WFError WFSchemaAddBehavior(WFToken in_schema, WFStrPtr in_name, WFStrPtr in_value);
/** /**
* @brief Add a file extension to a Schema * @brief Add a file extension to a Schema
@@ -309,13 +287,13 @@ bool WFSchemaAddBehavior(WFToken in_schema, WFCString in_name, WFCString in_valu
* This name should be registered by calling WFSchemaAddIcon(). * This name should be registered by calling WFSchemaAddIcon().
* @param[in] in_ext_behavior Null-terminated UTF-8 string containing the name pointing to associated behavior for this extension. * @param[in] in_ext_behavior Null-terminated UTF-8 string containing the name pointing to associated behavior for this extension.
* This name should be registered by calling WFSchemaAddBehavior(). * This name should be registered by calling WFSchemaAddBehavior().
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFSchemaAddExt(WFToken in_schema, WFError WFSchemaAddExt(WFToken in_schema,
WFCString in_ext, WFStrPtr in_ext,
WFCString in_ext_name, WFStrPtr in_ext_name,
WFCString in_ext_icon, WFStrPtr in_ext_icon,
WFCString in_ext_behavior); WFStrPtr in_ext_behavior);
/** /**
* @brief Create a Program object from a Schema * @brief Create a Program object from a Schema
@@ -331,9 +309,9 @@ bool WFSchemaAddExt(WFToken in_schema,
* @param[out] out_program Pointer to receive the Program token. * @param[out] out_program Pointer to receive the Program token.
* The receiver take the ownership of this Program object. * The receiver take the ownership of this Program object.
* And it should be freed by calling WFProgramDestroy() when it is no longer needed. * And it should be freed by calling WFProgramDestroy() when it is no longer needed.
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFProgramCreate(WFToken in_schema, WFToken *out_program); WFError WFProgramCreate(WFToken in_schema, WFToken *out_program);
/** /**
* @brief Destroy a Program object * @brief Destroy a Program object
@@ -341,9 +319,9 @@ bool WFProgramCreate(WFToken in_schema, WFToken *out_program);
* Releases resources associated with the Program. * Releases resources associated with the Program.
* *
* @param[in] in_program Program token to destroy * @param[in] in_program Program token to destroy
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFProgramDestroy(WFToken in_program); WFError WFProgramDestroy(WFToken in_program);
/** /**
* @brief Resolve the provided program name of this Program * @brief Resolve the provided program name of this Program
@@ -356,9 +334,9 @@ bool WFProgramDestroy(WFToken in_program);
* @param[out] out_name Pointer to receive the resolved name. * @param[out] out_name Pointer to receive the resolved name.
* There is no possibility that this value is NULL. * 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. * 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 * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFProgramResolveName(WFToken in_program, WFCString *out_name); WFError WFProgramResolveName(WFToken in_program, WFStrPtr *out_name);
/** /**
* @brief Resolve the Program icon resource * @brief Resolve the Program icon resource
@@ -371,18 +349,18 @@ bool WFProgramResolveName(WFToken in_program, WFCString *out_name);
* @param[out] out_icon_rc Pointer to receive the icon resource token. * @param[out] out_icon_rc Pointer to receive the icon resource token.
* The caller take the ownership of created icon resource object. * The caller take the ownership of created icon resource object.
* And it should be freed by calling WFIconRcDestroy() when it is no longer needed. * And it should be freed by calling WFIconRcDestroy() when it is no longer needed.
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFProgramResolveIcon(WFToken in_program, WFToken *out_icon_rc); WFError WFProgramResolveIcon(WFToken in_program, WFToken *out_icon_rc);
/** /**
* @brief Get the number of file extensions in the Program * @brief Get the number of file extensions in the Program
* *
* @param[in] in_program Program token * @param[in] in_program Program token
* @param[out] out_len Pointer to receive the number of extensions * @param[out] out_len Pointer to receive the number of extensions
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFProgramExtsLen(WFToken in_program, size_t *out_len); WFError WFProgramExtsLen(WFToken in_program, size_t *out_len);
/** /**
* @brief Find a file extension by its body (extension string) * @brief Find a file extension by its body (extension string)
@@ -390,9 +368,9 @@ bool WFProgramExtsLen(WFToken in_program, size_t *out_len);
* @param[in] in_program Program token * @param[in] in_program Program token
* @param[in] in_body Null-terminated UTF-8 string containing the file extension name (without leading dot) to find. * @param[in] in_body Null-terminated UTF-8 string containing the file extension name (without leading dot) to find.
* @param[out] out_index Pointer to receive the file extension index, or WF_INVALID_INDEX if not found. * @param[out] out_index Pointer to receive the file extension index, or WF_INVALID_INDEX if not found.
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFProgramFindExt(WFToken in_program, WFCString in_body, size_t *out_index); WFError WFProgramFindExt(WFToken in_program, WFStrPtr in_body, size_t *out_index);
/** /**
* @brief Resolve this program provided extension's details by index * @brief Resolve this program provided extension's details by index
@@ -402,27 +380,27 @@ bool WFProgramFindExt(WFToken in_program, WFCString in_body, size_t *out_index);
* @param[out] out_self_ext_status Pointer to receive the self extension status token. * @param[out] out_self_ext_status Pointer to receive the self extension status token.
* The caller take the ownership of created self extension status object. * The caller take the ownership of created self extension status object.
* And it should be freed by calling WFSelfExtStatusDestroy() when it is no longer needed. * And it should be freed by calling WFSelfExtStatusDestroy() when it is no longer needed.
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFProgramResolveExt(WFToken in_program, size_t in_index, WFToken *out_self_ext_status); WFError WFProgramResolveExt(WFToken in_program, size_t in_index, WFToken *out_self_ext_status);
/** /**
* @brief Register the Program in the specified scope * @brief Register the Program in the specified scope
* *
* @param[in] in_program Program token * @param[in] in_program Program token
* @param[in] in_scope Registration scope * @param[in] in_scope Registration scope
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFProgramRegister(WFToken in_program, WFScope in_scope); WFError WFProgramRegister(WFToken in_program, WFScope in_scope);
/** /**
* @brief Unregister the Program from the specified scope * @brief Unregister the Program from the specified scope
* *
* @param[in] in_program Program token * @param[in] in_program Program token
* @param[in] in_scope Registration scope * @param[in] in_scope Registration scope
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFProgramUnregister(WFToken in_program, WFScope in_scope); WFError WFProgramUnregister(WFToken in_program, WFScope in_scope);
/** /**
* @brief Check if the Program is registered in the specified scope * @brief Check if the Program is registered in the specified scope
@@ -431,9 +409,9 @@ bool WFProgramUnregister(WFToken in_program, WFScope in_scope);
* @param[in] in_scope Registration scope for checking * @param[in] in_scope Registration scope for checking
* @param[out] out_is_registered Pointer to receive the registration status. * @param[out] out_is_registered Pointer to receive the registration status.
* True if the Program is registered in the specified scope, false otherwise. * True if the Program is registered in the specified scope, false otherwise.
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFProgramIsRegistered(WFToken in_program, WFScope in_scope, bool *out_is_registered); WFError WFProgramIsRegistered(WFToken in_program, WFScope in_scope, bool *out_is_registered);
/** /**
* @brief Link a file extension in the specified scope * @brief Link a file extension in the specified scope
@@ -441,9 +419,9 @@ bool WFProgramIsRegistered(WFToken in_program, WFScope in_scope, bool *out_is_re
* @param[in] in_program Program token * @param[in] in_program Program token
* @param[in] in_scope Registration scope * @param[in] in_scope Registration scope
* @param[in] in_index Index of the extension to link * @param[in] in_index Index of the extension to link
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFProgramLinkExt(WFToken in_program, WFScope in_scope, size_t in_index); WFError WFProgramLinkExt(WFToken in_program, WFScope in_scope, size_t in_index);
/** /**
* @brief Unlink a file extension in the specified scope * @brief Unlink a file extension in the specified scope
@@ -451,9 +429,9 @@ bool WFProgramLinkExt(WFToken in_program, WFScope in_scope, size_t in_index);
* @param[in] in_program Program token * @param[in] in_program Program token
* @param[in] in_scope Registration scope * @param[in] in_scope Registration scope
* @param[in] in_index Index of the extension to unlink * @param[in] in_index Index of the extension to unlink
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFProgramUnlinkExt(WFToken in_program, WFScope in_scope, size_t in_index); WFError WFProgramUnlinkExt(WFToken in_program, WFScope in_scope, size_t in_index);
/** /**
* @brief Query the status of a file extension * @brief Query the status of a file extension
@@ -461,21 +439,21 @@ bool WFProgramUnlinkExt(WFToken in_program, WFScope in_scope, size_t in_index);
* @param[in] in_program Program token * @param[in] in_program Program token
* @param[in] in_view View viewpoint. * @param[in] in_view View viewpoint.
* @param[in] in_index Index of the extension to query * @param[in] in_index Index of the extension to query
* @param[out] out_ext_status Pointer to receive the extension status token, or invalid token if not found. * @param[out] out_ext_status Pointer to receive the extension status token, or WF_INVALID_TOKEN if not found.
* If the extension is not found, it usually means that this extension is not registered in the specified scope. * If the extension is not found, it usually means that this extension is not registered in the specified scope.
* The caller take the ownership of created extension status object. * The caller take the ownership of created extension status object.
* And it should be freed by calling WFExtStatusDestroy() when it is no longer needed. * And it should be freed by calling WFExtStatusDestroy() when it is no longer needed.
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFProgramQueryExt(WFToken in_program, WFView in_view, size_t in_index, WFToken *out_ext_status); WFError WFProgramQueryExt(WFToken in_program, WFView in_view, size_t in_index, WFToken *out_ext_status);
/** /**
* @brief Destroy an extension status object * @brief Destroy an extension status object
* *
* @param[in] in_ext_status Extension status token to destroy * @param[in] in_ext_status Extension status token to destroy
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFExtStatusDestroy(WFToken in_ext_status); WFError WFExtStatusDestroy(WFToken in_ext_status);
/** /**
* @brief Get the display name from an extension status object * @brief Get the display name from an extension status object
@@ -488,9 +466,9 @@ bool WFExtStatusDestroy(WFToken in_ext_status);
* There is no possibility that this value is NULL. * There is no possibility that this value is NULL.
* We will try to use localized name first, then use raw ProgId name if localized name is not available. * We will try to use localized name first, then use raw ProgId name if localized name is not available.
* This string will be freed at the next API call. Please make a copy immediately if you need to use it longer. * 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 * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFExtStatusGetName(WFToken in_ext_status, WFCString *out_name); WFError WFExtStatusGetName(WFToken in_ext_status, WFStrPtr *out_name);
/** /**
* @brief Get the icon from an extension status object * @brief Get the icon from an extension status object
@@ -502,17 +480,17 @@ bool WFExtStatusGetName(WFToken in_ext_status, WFCString *out_name);
* @param[out] out_icon Pointer to receive the icon handle. * @param[out] out_icon Pointer to receive the icon handle.
* This icon handle will be freed once this icon resource object is destroyed. * 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. * Please make a copy immediately if you need to use it longer.
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFExtStatusGetIcon(WFToken in_ext_status, WFHICON *out_icon); WFError WFExtStatusGetIcon(WFToken in_ext_status, WFHICON *out_icon);
/** /**
* @brief Destroy a self extension status object * @brief Destroy a self extension status object
* *
* @param[in] in_self_ext_status Self extension status token to destroy * @param[in] in_self_ext_status Self extension status token to destroy
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFSelfExtStatusDestroy(WFToken in_self_ext_status); WFError WFSelfExtStatusDestroy(WFToken in_self_ext_status);
/** /**
* @brief Get the display name from a self extension status object * @brief Get the display name from a self extension status object
@@ -524,9 +502,9 @@ bool WFSelfExtStatusDestroy(WFToken in_self_ext_status);
* @param[out] out_name Pointer to receive the name string. * @param[out] out_name Pointer to receive the name string.
* There is no possibility that this value is NULL. * 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. * 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 * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFSelfExtStatusGetName(WFToken in_self_ext_status, WFCString *out_name); WFError WFSelfExtStatusGetName(WFToken in_self_ext_status, WFStrPtr *out_name);
/** /**
* @brief Get the icon from a self extension status object * @brief Get the icon from a self extension status object
@@ -538,9 +516,9 @@ bool WFSelfExtStatusGetName(WFToken in_self_ext_status, WFCString *out_name);
* @param[out] out_icon Pointer to receive the icon handle. * @param[out] out_icon Pointer to receive the icon handle.
* This icon handle will be freed once this self extension status object is destroyed. * 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. * Please make a copy immediately if you need to use it longer.
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFSelfExtStatusGetIcon(WFToken in_self_ext_status, WFHICON *out_icon); WFError WFSelfExtStatusGetIcon(WFToken in_self_ext_status, WFHICON *out_icon);
/** /**
* @brief Get the extension string (without leading dot) from a self extension status object * @brief Get the extension string (without leading dot) from a self extension status object
@@ -549,9 +527,9 @@ bool WFSelfExtStatusGetIcon(WFToken in_self_ext_status, WFHICON *out_icon);
* @param[out] out_inner Pointer to receive the file extension name (without leading dot). * @param[out] out_inner Pointer to receive the file extension name (without leading dot).
* There is no possibility that this value is NULL. * 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. * 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 * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFSelfExtStatusGetExt(WFToken in_self_ext_status, WFCString *out_inner); WFError WFSelfExtStatusGetExt(WFToken in_self_ext_status, WFStrPtr *out_inner);
/** /**
* @brief Get the dotted extension string (with leading dot) from a self extension status object * @brief Get the dotted extension string (with leading dot) from a self extension status object
@@ -560,17 +538,17 @@ bool WFSelfExtStatusGetExt(WFToken in_self_ext_status, WFCString *out_inner);
* @param[out] out_inner Pointer to receive the file extension string (with leading dot). * @param[out] out_inner Pointer to receive the file extension string (with leading dot).
* There is no possibility that this value is NULL. * 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. * 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 * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFSelfExtStatusGetDottedExt(WFToken in_self_ext_status, WFCString *out_inner); WFError WFSelfExtStatusGetDottedExt(WFToken in_self_ext_status, WFStrPtr *out_inner);
/** /**
* @brief Destroy an icon resource object * @brief Destroy an icon resource object
* *
* @param[in] in_icon_rc Icon resource token to destroy * @param[in] in_icon_rc Icon resource token to destroy
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFIconRcDestroy(WFToken in_icon_rc); WFError WFIconRcDestroy(WFToken in_icon_rc);
/** /**
* @brief Get the icon handle from an icon resource object * @brief Get the icon handle from an icon resource object
@@ -580,9 +558,9 @@ bool WFIconRcDestroy(WFToken in_icon_rc);
* There is no possibility that this value is WF_INVALID_HICON. * There is no possibility that this value is WF_INVALID_HICON.
* This icon handle will be freed once this icon resource object is destroyed. * 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. * Please make a copy immediately if you need to use it longer.
* @return true on success, false on failure * @return WFERROR_OK on success, WFERROR_ERR on failure
*/ */
bool WFIconRcGetIcon(WFToken in_icon_rc, WFHICON *out_icon); WFError WFIconRcGetIcon(WFToken in_icon_rc, WFHICON *out_icon);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "wfassoc-exec" name = "wfassoc-exec"
version = "0.1.0" version = "1.0.0"
authors = ["yyc12345"] authors = ["yyc12345"]
edition = "2024" edition = "2024"
description = "The executable configuring Windows file assocation according to user given profile and request." description = "The executable configuring Windows file assocation according to user given profile and request."
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "wfassoc" name = "wfassoc"
version = "0.1.0" version = "1.0.0"
authors = ["yyc12345"] authors = ["yyc12345"]
edition = "2024" edition = "2024"
description = "The library reading or manipulating Windows file assocation." description = "The library reading or manipulating Windows file assocation."