Compare commits
7
Commits
4fcdf902f7
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b45a5c2760 | ||
|
|
27235c2619 | ||
|
|
6687ccb143 | ||
|
|
d2e5bcf2ed | ||
|
|
36330437de | ||
|
|
a595d7e6e7 | ||
|
|
64ccc083fb |
Generated
+44
-8
@@ -75,9 +75,9 @@ checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
version = "1.0.3"
|
version = "1.0.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
|
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
@@ -136,6 +136,12 @@ dependencies = [
|
|||||||
"unicode-width",
|
"unicode-width",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crossbeam-utils"
|
||||||
|
version = "0.8.22"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "61803da095bee82a81bb1a452ecc25d3b2f1416d1897eb86430c6159ef717c17"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossterm"
|
name = "crossterm"
|
||||||
version = "0.29.0"
|
version = "0.29.0"
|
||||||
@@ -159,6 +165,20 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dashmap"
|
||||||
|
version = "6.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e6361d5c062261c78a176addb82d4c821ae42bed6089de0e12603cd25de2059c"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"crossbeam-utils",
|
||||||
|
"hashbrown 0.14.5",
|
||||||
|
"lock_api",
|
||||||
|
"once_cell",
|
||||||
|
"parking_lot_core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "document-features"
|
name = "document-features"
|
||||||
version = "0.2.11"
|
version = "0.2.11"
|
||||||
@@ -196,6 +216,12 @@ dependencies = [
|
|||||||
"wasip2",
|
"wasip2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hashbrown"
|
||||||
|
version = "0.14.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashbrown"
|
name = "hashbrown"
|
||||||
version = "0.16.0"
|
version = "0.16.0"
|
||||||
@@ -215,7 +241,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "4b0f83760fb341a774ed326568e19f5a863af4a952def8c39f9ab92fd95b88e5"
|
checksum = "4b0f83760fb341a774ed326568e19f5a863af4a952def8c39f9ab92fd95b88e5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"equivalent",
|
"equivalent",
|
||||||
"hashbrown",
|
"hashbrown 0.16.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -297,9 +323,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.21.3"
|
version = "1.21.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell_polyfill"
|
name = "once_cell_polyfill"
|
||||||
@@ -420,6 +446,15 @@ version = "1.0.22"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sarasacw-omrf"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "git+https://github.com/SarasasChipWorkshop/sarasacw-omrf.git#38b64a10928566fc9193c3c0c5138901b6cd952e"
|
||||||
|
dependencies = [
|
||||||
|
"dashmap",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "scopeguard"
|
name = "scopeguard"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
@@ -685,7 +720,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wfassoc"
|
name = "wfassoc"
|
||||||
version = "0.1.0"
|
version = "1.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"regex",
|
"regex",
|
||||||
@@ -699,9 +734,10 @@ 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",
|
||||||
"slotmap",
|
"slotmap",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"wfassoc",
|
"wfassoc",
|
||||||
@@ -709,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",
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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)
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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()
|
|
||||||
@@ -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,16 +1,34 @@
|
|||||||
[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 wfassoc library exposed for C/C++ and other languages users."
|
description = "The dynamic library exposed for C/C++ users reading or manipulating Windows file assocation."
|
||||||
license = "SPDX:MIT"
|
license = "MIT"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
|
sarasacw-omrf = { git = "https://github.com/SarasasChipWorkshop/sarasacw-omrf.git"}
|
||||||
|
# sarasacw-omrf = { version="1.0.0", git = "https://github.com/SarasasChipWorkshop/sarasacw-omrf.git", tag = "omrf/1.0.0" }
|
||||||
wfassoc = { path="../wfassoc" }
|
wfassoc = { path="../wfassoc" }
|
||||||
slotmap = "1.1.1"
|
slotmap = "1.1.1"
|
||||||
num_enum = "0.7.6"
|
num_enum = "0.7.6"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
# Any panics is seen as `std::abort` in production environment.
|
||||||
|
panic = "abort"
|
||||||
|
|
||||||
|
[package.metadata.omrf]
|
||||||
|
min_version = "1.0.0"
|
||||||
|
headers = [
|
||||||
|
{ from = "cbinding/*.h", to = "" }
|
||||||
|
]
|
||||||
|
[package.metadata.omrf.cmake]
|
||||||
|
namespace_name = "wfassoc"
|
||||||
|
target_name = "wfassoc"
|
||||||
|
[package.metadata.omrf.pkgconfig]
|
||||||
|
id = "wfassoc"
|
||||||
|
name = "Windows file association manipulation library"
|
||||||
|
|||||||
@@ -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()
|
|
||||||
@@ -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);
|
||||||
@@ -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,101 +0,0 @@
|
|||||||
//! When calling this dynamic library with outside programs,
|
|
||||||
//! outer programs may usually need to fetch string resource produced by Rust code.
|
|
||||||
//! However it is impossible pass Rust string directly to outer program.
|
|
||||||
//!
|
|
||||||
//! This module provide **thread independent** string cache for resolving this issue.
|
|
||||||
//! When we need pass string to outer programs, we push that string into this string as C-like format,
|
|
||||||
//! then return its pointer to outer program.
|
|
||||||
//! So that outside program can utilize it like calling C/C++ library.
|
|
||||||
//! The only thing that outer programs should note is that this string is volatile,
|
|
||||||
//! once they get it, they must dupliate it immediately before any futher calling to this dynamic library.
|
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::ffi::{CStr, CString};
|
|
||||||
use thiserror::Error as TeError;
|
|
||||||
use crate::ffi_types::CStyleString;
|
|
||||||
|
|
||||||
// region: Error
|
|
||||||
|
|
||||||
/// Error occurs in this crate.
|
|
||||||
#[derive(Debug, TeError)]
|
|
||||||
pub enum Error {
|
|
||||||
#[error("unexpected NUL when parsing into C/C++ string")]
|
|
||||||
UnexpectedNul(#[from] std::ffi::NulError),
|
|
||||||
|
|
||||||
#[error("given string pointer is nullptr when parsing from C/C++ string")]
|
|
||||||
NullPtr,
|
|
||||||
#[error("invalid UTF8 sequence when parsing from C/C++ string")]
|
|
||||||
InvalidEncoding(#[from] std::str::Utf8Error),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Result type used in this crate.
|
|
||||||
type Result<T> = std::result::Result<T, Error>;
|
|
||||||
|
|
||||||
// endregion
|
|
||||||
|
|
||||||
// region: String Cache for Exposing
|
|
||||||
|
|
||||||
struct StringCache {
|
|
||||||
msg: CString,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl StringCache {
|
|
||||||
fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
msg: CString::new("").expect("empty string must be valid for CString"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_msg(&mut self, msg: &str) -> Result<()> {
|
|
||||||
self.msg = CString::new(msg)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_msg(&self) -> CStyleString {
|
|
||||||
self.msg.as_ptr()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn clear_msg(&mut self) {
|
|
||||||
self.msg = CString::new("").expect("empty string must be valid for CString");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// endregion
|
|
||||||
|
|
||||||
// region: Exposed Functions
|
|
||||||
|
|
||||||
thread_local! {
|
|
||||||
static STRING_CACHE: RefCell<StringCache> = RefCell::new(StringCache::new());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set thread local string exposed for C code.
|
|
||||||
pub fn set_ffi_string(msg: &str) -> Result<()> {
|
|
||||||
STRING_CACHE.with(|e| {
|
|
||||||
e.borrow_mut().set_msg(msg)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get const pointer to thread local string exposed for C code.
|
|
||||||
pub fn get_ffi_string() -> CStyleString {
|
|
||||||
STRING_CACHE.with(|e| e.borrow().get_msg())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clear thread local string exposed for C code.
|
|
||||||
///
|
|
||||||
/// This function usually should be called at the beginning of every exposed C functions.
|
|
||||||
pub fn clear_ffi_string() {
|
|
||||||
STRING_CACHE.with(|e| {
|
|
||||||
e.borrow_mut().clear_msg();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parse string given by C code into Rust string.
|
|
||||||
pub fn parse_ffi_string<'a>(ptr: CStyleString) -> Result<&'a str> {
|
|
||||||
if ptr.is_null() {
|
|
||||||
Err(Error::NullPtr)
|
|
||||||
} else {
|
|
||||||
let c_str = unsafe { CStr::from_ptr(ptr) };
|
|
||||||
Ok(c_str.to_str()?)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// endregion
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
//! When calling function with dynamic library,
|
|
||||||
//! function return value indicates whether function has been successfully executed.
|
|
||||||
//! When function return `false`, programmer may want to know which error occurs.
|
|
||||||
//!
|
|
||||||
//! This module provide **thread independent** error message string storage,
|
|
||||||
//! which is more like Win32 `GetLastError()` but return error message instead of error code.
|
|
||||||
//! These module provided functions will be called when executing main module functions.
|
|
||||||
|
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::ffi::{CString, c_char};
|
|
||||||
|
|
||||||
struct LastError {
|
|
||||||
msg: CString,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LastError {
|
|
||||||
fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
msg: CString::new("").expect("empty string must be valid for CString"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_msg(&mut self, msg: &str) {
|
|
||||||
self.msg = CString::new(msg).expect("unexpected blank in error message output");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_msg(&self) -> *const c_char {
|
|
||||||
self.msg.as_ptr()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn clear_msg(&mut self) {
|
|
||||||
self.msg = CString::new("").expect("empty string must be valid for CString");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
thread_local! {
|
|
||||||
static LAST_ERROR: RefCell<LastError> = RefCell::new(LastError::new());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set thread local error message.
|
|
||||||
pub fn set_last_error(msg: &str) {
|
|
||||||
LAST_ERROR.with(|e| {
|
|
||||||
e.borrow_mut().set_msg(msg);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get const pointer to thread local error message string.
|
|
||||||
/// If there is no error, return pointer will point to empty string.
|
|
||||||
pub fn get_last_error() -> *const c_char {
|
|
||||||
LAST_ERROR.with(|e| e.borrow().get_msg())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clear thread local error message (reset to empty string).
|
|
||||||
pub fn clear_last_error() {
|
|
||||||
LAST_ERROR.with(|e| {
|
|
||||||
e.borrow_mut().clear_msg();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
+207
-354
@@ -1,10 +1,8 @@
|
|||||||
mod cstr_ffi;
|
mod wrapper;
|
||||||
mod ffi_types;
|
|
||||||
mod last_error;
|
|
||||||
mod object_pool;
|
|
||||||
|
|
||||||
use object_pool::ObjectPool;
|
use sarasacw_omrf::object_pool::ObjectPool;
|
||||||
use std::sync::{LazyLock, RwLock};
|
use sarasacw_omrf::{cffi_wrapper, cstr_ffi, in_param_ty, last_error, object_pool, out_param_ty};
|
||||||
|
use std::sync::LazyLock;
|
||||||
use thiserror::Error as TeError;
|
use thiserror::Error as TeError;
|
||||||
use wfassoc::highlevel::{Program, Schema};
|
use wfassoc::highlevel::{Program, Schema};
|
||||||
|
|
||||||
@@ -12,7 +10,7 @@ use wfassoc::highlevel::{Program, Schema};
|
|||||||
|
|
||||||
/// Error occurs in this crate.
|
/// Error occurs in this crate.
|
||||||
#[derive(Debug, TeError)]
|
#[derive(Debug, TeError)]
|
||||||
enum Error {
|
enum UserError {
|
||||||
/// Error when operating Schema.
|
/// Error when operating Schema.
|
||||||
#[error("wfassoc error: {0}")]
|
#[error("wfassoc error: {0}")]
|
||||||
Schema(#[from] wfassoc::highlevel::SchemaError),
|
Schema(#[from] wfassoc::highlevel::SchemaError),
|
||||||
@@ -33,180 +31,65 @@ enum Error {
|
|||||||
/// Error occurs when checking enum value
|
/// Error occurs when checking enum value
|
||||||
#[error("the enumeration value provided to FFI function is out of its range")]
|
#[error("the enumeration value provided to FFI function is out of its range")]
|
||||||
EnumOutOfRange,
|
EnumOutOfRange,
|
||||||
/// Error when manipulating with poison RwLock
|
}
|
||||||
#[error("concurrency error: RwLock is poisonous")]
|
|
||||||
PoisonRwLock,
|
impl From<UserError> for WFError {
|
||||||
|
fn from(_: UserError) -> Self {
|
||||||
|
WFERROR_ERR
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Result type used in this crate.
|
/// Result type used in this crate.
|
||||||
type Result<T> = std::result::Result<T, Error>;
|
type Result<T> = std::result::Result<T, UserError>;
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region: Macros
|
// region: Macros
|
||||||
|
|
||||||
macro_rules! in_param_ty {
|
|
||||||
($t:ty) => {
|
|
||||||
$t
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! out_param_ty {
|
|
||||||
($t:ty) => {
|
|
||||||
*mut $t
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! set_out_param {
|
|
||||||
($lhs:expr, $rhs:expr) => {
|
|
||||||
unsafe { *$lhs = $rhs };
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! resolve_enum {
|
macro_rules! resolve_enum {
|
||||||
($t:ty, $v:expr) => {
|
($t:ty, $v:expr) => {
|
||||||
<$t>::try_from($v).map_err(|_| Error::EnumOutOfRange)
|
<$t>::try_from($v).map_err(|_| UserError::EnumOutOfRange)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! pull_reader {
|
|
||||||
($pool:expr) => {
|
|
||||||
$pool.read().map_err(|_| Error::PoisonRwLock)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! pull_writer {
|
|
||||||
($pool:expr) => {
|
|
||||||
$pool.write().map_err(|_| Error::PoisonRwLock)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Macro to wrap inner function execution with standard error handling pattern.
|
|
||||||
///
|
|
||||||
/// For functions with no output parameter and no input parameters:
|
|
||||||
/// ```ignore
|
|
||||||
/// cffi_wrapper!(|| {
|
|
||||||
/// // inner function body returning Result<()>
|
|
||||||
/// });
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// For functions with no output parameter and with input parameters:
|
|
||||||
/// ```ignore
|
|
||||||
/// cffi_wrapper!(|param1: Type1, param2: Type2| {
|
|
||||||
/// // inner function body using param1, param2 returning Result<()>
|
|
||||||
/// });
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// For functions with one output parameter and no input parameters:
|
|
||||||
/// ```ignore
|
|
||||||
/// cffi_wrapper!(|| -> (out_param, OutType) {
|
|
||||||
/// // inner function body returning Result<T>
|
|
||||||
/// });
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// For functions with one output parameter and with input parameters:
|
|
||||||
/// ```ignore
|
|
||||||
/// cffi_wrapper!(|param1: Type1| -> (out_param, OutType) {
|
|
||||||
/// // inner function body using param1 returning Result<T>
|
|
||||||
/// });
|
|
||||||
/// ```
|
|
||||||
macro_rules! cffi_wrapper {
|
|
||||||
// Case with output parameter and input parameters
|
|
||||||
(|$($param:ident: $param_ty:ty),*| -> ($out_param:ident: $out_param_ty:ty) $inner_body:block) => {{
|
|
||||||
fn inner($($param: $param_ty),*) -> Result<$out_param_ty> $inner_body
|
|
||||||
|
|
||||||
match inner($($param),*) {
|
|
||||||
Ok(rv) => {
|
|
||||||
set_out_param!($out_param, rv);
|
|
||||||
last_error::clear_last_error();
|
|
||||||
true
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
last_error::set_last_error(e.to_string().as_str());
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}};
|
|
||||||
|
|
||||||
// Case with output parameter and no input parameters
|
|
||||||
(|| -> ($out_param:ident: $out_param_ty:ty) $inner_body:block) => {{
|
|
||||||
fn inner() -> Result<$out_param_ty> $inner_body
|
|
||||||
|
|
||||||
match inner() {
|
|
||||||
Ok(rv) => {
|
|
||||||
set_out_param!($out_param, rv);
|
|
||||||
last_error::clear_last_error();
|
|
||||||
true
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
last_error::set_last_error(e.to_string().as_str());
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}};
|
|
||||||
|
|
||||||
// Case without output parameter but with input parameters
|
|
||||||
(|$($param:ident: $param_ty:ty),*| $inner_body:block) => {{
|
|
||||||
fn inner($($param: $param_ty),*) -> Result<()> $inner_body
|
|
||||||
|
|
||||||
match inner($($param),*) {
|
|
||||||
Ok(_) => {
|
|
||||||
last_error::clear_last_error();
|
|
||||||
true
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
last_error::set_last_error(e.to_string().as_str());
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}};
|
|
||||||
|
|
||||||
// Case without output parameter and no input parameters
|
|
||||||
(|| $inner_body:block) => {{
|
|
||||||
fn inner() -> Result<()> $inner_body
|
|
||||||
|
|
||||||
match inner() {
|
|
||||||
Ok(_) => {
|
|
||||||
last_error::clear_last_error();
|
|
||||||
true
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
last_error::set_last_error(e.to_string().as_str());
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region: Object Pools
|
// region: Object Pools
|
||||||
|
|
||||||
static SCHEMA_POOL: LazyLock<RwLock<ObjectPool<Schema>>> =
|
struct State {
|
||||||
LazyLock::new(|| RwLock::new(ObjectPool::new()));
|
schema_pool: ObjectPool<Schema>,
|
||||||
|
program_pool: ObjectPool<Program>,
|
||||||
|
ext_status_pool: ObjectPool<wfassoc::highlevel::ProgramExtStatus>,
|
||||||
|
self_ext_status_pool: ObjectPool<wfassoc::highlevel::ProgramSelfExtStatus>,
|
||||||
|
icon_rc_pool: ObjectPool<wfassoc::win32::concept::IconRc>,
|
||||||
|
}
|
||||||
|
|
||||||
static PROGRAM_POOL: LazyLock<RwLock<ObjectPool<Program>>> =
|
impl State {
|
||||||
LazyLock::new(|| RwLock::new(ObjectPool::new()));
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
schema_pool: ObjectPool::new(),
|
||||||
|
program_pool: ObjectPool::new(),
|
||||||
|
ext_status_pool: ObjectPool::new(),
|
||||||
|
self_ext_status_pool: ObjectPool::new(),
|
||||||
|
icon_rc_pool: ObjectPool::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static EXT_STATUS_POOL: LazyLock<RwLock<ObjectPool<wfassoc::highlevel::ProgramExtStatus>>> =
|
static CONTEXT: LazyLock<State> = LazyLock::new(|| State::new());
|
||||||
LazyLock::new(|| RwLock::new(ObjectPool::new()));
|
|
||||||
|
|
||||||
static SELF_EXT_STATUS_POOL: LazyLock<
|
|
||||||
RwLock<ObjectPool<wfassoc::highlevel::ProgramSelfExtStatus>>,
|
|
||||||
> = LazyLock::new(|| RwLock::new(ObjectPool::new()));
|
|
||||||
|
|
||||||
static ICON_RC_POOL: LazyLock<RwLock<ObjectPool<wfassoc::win32::concept::IconRc>>> =
|
|
||||||
LazyLock::new(|| RwLock::new(ObjectPool::new()));
|
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region: Exposed Types
|
// region: Exposed Types
|
||||||
|
|
||||||
pub use ffi_types::{
|
pub use last_error::CERROR_OK as WFERROR_OK;
|
||||||
CStyleString as WFCString, HICON as WFHICON, Scope as WFScope, View as WFView,
|
pub use last_error::CError as WFError;
|
||||||
};
|
pub const WFERROR_ERR: WFError = 1;
|
||||||
pub use ffi_types::{INVALID_HICON as WF_INVALID_HICON, INVALID_INDEX as WF_INVALID_INDEX};
|
|
||||||
pub use object_pool::Token as WFToken;
|
pub use cstr_ffi::CStrPtr as WFStrPtr;
|
||||||
|
pub use object_pool::{INVALID_TOKEN as WF_INVALID_TOKEN, Token as WFToken};
|
||||||
|
pub use wrapper::{HICON as WFHICON, Scope as WFScope, View as WFView};
|
||||||
|
pub use wrapper::{INVALID_HICON as WF_INVALID_HICON, INVALID_INDEX as WF_INVALID_INDEX};
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
@@ -215,67 +98,37 @@ pub use object_pool::Token as WFToken;
|
|||||||
// region: Facilities
|
// region: Facilities
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFStartup() -> bool {
|
pub extern "C" fn WFGetLastError() -> WFStrPtr {
|
||||||
// Initialize all pool by fetching writer from them
|
last_error::get_error_message()
|
||||||
cffi_wrapper!(|| {
|
}
|
||||||
let _pool = pull_writer!(SCHEMA_POOL)?;
|
|
||||||
let _pool = pull_writer!(PROGRAM_POOL)?;
|
// endregion
|
||||||
let _pool = pull_writer!(EXT_STATUS_POOL)?;
|
|
||||||
let _pool = pull_writer!(SELF_EXT_STATUS_POOL)?;
|
// region: Global Functions
|
||||||
let _pool = pull_writer!(ICON_RC_POOL)?;
|
|
||||||
Ok(())
|
#[unsafe(no_mangle)]
|
||||||
|
pub extern "C" fn WFHasPrivilege(out_has: out_param_ty!(bool)) -> WFError {
|
||||||
|
cffi_wrapper!(|| -> (out_has: bool) {
|
||||||
|
Ok(wfassoc::win32::utilities::has_privilege())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
|
||||||
pub extern "C" fn WFShutdown() -> bool {
|
|
||||||
// Free all pool stored objects
|
|
||||||
cffi_wrapper!(|| {
|
|
||||||
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
|
||||||
pool.clear();
|
|
||||||
let mut pool = pull_writer!(PROGRAM_POOL)?;
|
|
||||||
pool.clear();
|
|
||||||
let mut pool = pull_writer!(EXT_STATUS_POOL)?;
|
|
||||||
pool.clear();
|
|
||||||
let mut pool = pull_writer!(SELF_EXT_STATUS_POOL)?;
|
|
||||||
pool.clear();
|
|
||||||
let mut pool = pull_writer!(ICON_RC_POOL)?;
|
|
||||||
pool.clear();
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
|
||||||
pub extern "C" fn WFGetLastError() -> WFCString {
|
|
||||||
last_error::get_last_error()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
|
||||||
pub extern "C" fn WFHasPrivilege() -> bool {
|
|
||||||
wfassoc::win32::utilities::has_privilege()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
|
||||||
pub extern "C" fn WFInvalidToken() -> WFToken {
|
|
||||||
object_pool::invalid_token()
|
|
||||||
}
|
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region: Schema
|
// region: Schema
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFSchemaCreate(out_schema: out_param_ty!(WFToken)) -> bool {
|
pub extern "C" fn WFSchemaCreate(out_schema: out_param_ty!(WFToken)) -> WFError {
|
||||||
cffi_wrapper!(|| -> (out_schema: WFToken) {
|
cffi_wrapper!(|| -> (out_schema: WFToken) {
|
||||||
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
let pool = &CONTEXT.schema_pool;
|
||||||
Ok(pool.allocate(Schema::new())?)
|
Ok(pool.allocate(Schema::new()))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFSchemaDestroy(in_schema: in_param_ty!(WFToken)) -> bool {
|
pub extern "C" fn WFSchemaDestroy(in_schema: in_param_ty!(WFToken)) -> WFError {
|
||||||
cffi_wrapper!(|in_schema: WFToken| {
|
cffi_wrapper!(|in_schema: WFToken| {
|
||||||
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
let pool = &CONTEXT.schema_pool;
|
||||||
Ok(pool.free(in_schema)?)
|
Ok(pool.free(in_schema)?)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -283,11 +136,11 @@ pub extern "C" fn WFSchemaDestroy(in_schema: in_param_ty!(WFToken)) -> bool {
|
|||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFSchemaSetIdentifier(
|
pub extern "C" fn WFSchemaSetIdentifier(
|
||||||
in_schema: in_param_ty!(WFToken),
|
in_schema: in_param_ty!(WFToken),
|
||||||
in_value: in_param_ty!(WFCString),
|
in_value: in_param_ty!(WFStrPtr),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_schema: WFToken, in_value: WFCString| {
|
cffi_wrapper!(|in_schema: WFToken, in_value: WFStrPtr| {
|
||||||
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
let pool = &CONTEXT.schema_pool;
|
||||||
let schema = pool.get_mut(in_schema)?;
|
let mut schema = pool.get_mut(in_schema)?;
|
||||||
schema.set_identifier(cstr_ffi::parse_ffi_string(in_value)?);
|
schema.set_identifier(cstr_ffi::parse_ffi_string(in_value)?);
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
@@ -296,11 +149,11 @@ pub extern "C" fn WFSchemaSetIdentifier(
|
|||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFSchemaSetPath(
|
pub extern "C" fn WFSchemaSetPath(
|
||||||
in_schema: in_param_ty!(WFToken),
|
in_schema: in_param_ty!(WFToken),
|
||||||
in_value: in_param_ty!(WFCString),
|
in_value: in_param_ty!(WFStrPtr),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_schema: WFToken, in_value: WFCString| {
|
cffi_wrapper!(|in_schema: WFToken, in_value: WFStrPtr| {
|
||||||
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
let pool = &CONTEXT.schema_pool;
|
||||||
let schema = pool.get_mut(in_schema)?;
|
let mut schema = pool.get_mut(in_schema)?;
|
||||||
schema.set_path(cstr_ffi::parse_ffi_string(in_value)?);
|
schema.set_path(cstr_ffi::parse_ffi_string(in_value)?);
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
@@ -309,11 +162,11 @@ pub extern "C" fn WFSchemaSetPath(
|
|||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFSchemaSetClsid(
|
pub extern "C" fn WFSchemaSetClsid(
|
||||||
in_schema: in_param_ty!(WFToken),
|
in_schema: in_param_ty!(WFToken),
|
||||||
in_value: in_param_ty!(WFCString),
|
in_value: in_param_ty!(WFStrPtr),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_schema: WFToken, in_value: WFCString| {
|
cffi_wrapper!(|in_schema: WFToken, in_value: WFStrPtr| {
|
||||||
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
let pool = &CONTEXT.schema_pool;
|
||||||
let schema = pool.get_mut(in_schema)?;
|
let mut schema = pool.get_mut(in_schema)?;
|
||||||
schema.set_clsid(cstr_ffi::parse_ffi_string(in_value)?);
|
schema.set_clsid(cstr_ffi::parse_ffi_string(in_value)?);
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
@@ -322,17 +175,17 @@ pub extern "C" fn WFSchemaSetClsid(
|
|||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFSchemaSetName(
|
pub extern "C" fn WFSchemaSetName(
|
||||||
in_schema: in_param_ty!(WFToken),
|
in_schema: in_param_ty!(WFToken),
|
||||||
in_value: in_param_ty!(WFCString),
|
in_value: in_param_ty!(WFStrPtr),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_schema: WFToken, in_value: WFCString| {
|
cffi_wrapper!(|in_schema: WFToken, in_value: WFStrPtr| {
|
||||||
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
|
||||||
let schema = pool.get_mut(in_schema)?;
|
|
||||||
|
|
||||||
let name = if in_value.is_null() {
|
let name = if in_value.is_null() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(cstr_ffi::parse_ffi_string(in_value)?)
|
Some(cstr_ffi::parse_ffi_string(in_value)?)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let pool = &CONTEXT.schema_pool;
|
||||||
|
let mut schema = pool.get_mut(in_schema)?;
|
||||||
schema.set_name(name);
|
schema.set_name(name);
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
@@ -341,17 +194,17 @@ pub extern "C" fn WFSchemaSetName(
|
|||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFSchemaSetIcon(
|
pub extern "C" fn WFSchemaSetIcon(
|
||||||
in_schema: in_param_ty!(WFToken),
|
in_schema: in_param_ty!(WFToken),
|
||||||
in_value: in_param_ty!(WFCString),
|
in_value: in_param_ty!(WFStrPtr),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_schema: WFToken, in_value: WFCString| {
|
cffi_wrapper!(|in_schema: WFToken, in_value: WFStrPtr| {
|
||||||
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
|
||||||
let schema = pool.get_mut(in_schema)?;
|
|
||||||
|
|
||||||
let icon = if in_value.is_null() {
|
let icon = if in_value.is_null() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(cstr_ffi::parse_ffi_string(in_value)?)
|
Some(cstr_ffi::parse_ffi_string(in_value)?)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let pool = &CONTEXT.schema_pool;
|
||||||
|
let mut schema = pool.get_mut(in_schema)?;
|
||||||
schema.set_icon(icon);
|
schema.set_icon(icon);
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
@@ -360,17 +213,17 @@ pub extern "C" fn WFSchemaSetIcon(
|
|||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFSchemaSetBehavior(
|
pub extern "C" fn WFSchemaSetBehavior(
|
||||||
in_schema: in_param_ty!(WFToken),
|
in_schema: in_param_ty!(WFToken),
|
||||||
in_value: in_param_ty!(WFCString),
|
in_value: in_param_ty!(WFStrPtr),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_schema: WFToken, in_value: WFCString| {
|
cffi_wrapper!(|in_schema: WFToken, in_value: WFStrPtr| {
|
||||||
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
|
||||||
let schema = pool.get_mut(in_schema)?;
|
|
||||||
|
|
||||||
let behavior = if in_value.is_null() {
|
let behavior = if in_value.is_null() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(cstr_ffi::parse_ffi_string(in_value)?)
|
Some(cstr_ffi::parse_ffi_string(in_value)?)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let pool = &CONTEXT.schema_pool;
|
||||||
|
let mut schema = pool.get_mut(in_schema)?;
|
||||||
schema.set_behavior(behavior);
|
schema.set_behavior(behavior);
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
@@ -379,13 +232,13 @@ pub extern "C" fn WFSchemaSetBehavior(
|
|||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFSchemaAddStr(
|
pub extern "C" fn WFSchemaAddStr(
|
||||||
in_schema: in_param_ty!(WFToken),
|
in_schema: in_param_ty!(WFToken),
|
||||||
in_name: in_param_ty!(WFCString),
|
in_name: in_param_ty!(WFStrPtr),
|
||||||
in_value: in_param_ty!(WFCString),
|
in_value: in_param_ty!(WFStrPtr),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(
|
cffi_wrapper!(
|
||||||
|in_schema: WFToken, in_name: WFCString, in_value: WFCString| {
|
|in_schema: WFToken, in_name: WFStrPtr, in_value: WFStrPtr| {
|
||||||
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
let pool = &CONTEXT.schema_pool;
|
||||||
let schema = pool.get_mut(in_schema)?;
|
let mut schema = pool.get_mut(in_schema)?;
|
||||||
schema.add_str(
|
schema.add_str(
|
||||||
cstr_ffi::parse_ffi_string(in_name)?,
|
cstr_ffi::parse_ffi_string(in_name)?,
|
||||||
cstr_ffi::parse_ffi_string(in_value)?,
|
cstr_ffi::parse_ffi_string(in_value)?,
|
||||||
@@ -398,13 +251,13 @@ pub extern "C" fn WFSchemaAddStr(
|
|||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFSchemaAddIcon(
|
pub extern "C" fn WFSchemaAddIcon(
|
||||||
in_schema: in_param_ty!(WFToken),
|
in_schema: in_param_ty!(WFToken),
|
||||||
in_name: in_param_ty!(WFCString),
|
in_name: in_param_ty!(WFStrPtr),
|
||||||
in_value: in_param_ty!(WFCString),
|
in_value: in_param_ty!(WFStrPtr),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(
|
cffi_wrapper!(
|
||||||
|in_schema: WFToken, in_name: WFCString, in_value: WFCString| {
|
|in_schema: WFToken, in_name: WFStrPtr, in_value: WFStrPtr| {
|
||||||
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
let pool = &CONTEXT.schema_pool;
|
||||||
let schema = pool.get_mut(in_schema)?;
|
let mut schema = pool.get_mut(in_schema)?;
|
||||||
schema.add_icon(
|
schema.add_icon(
|
||||||
cstr_ffi::parse_ffi_string(in_name)?,
|
cstr_ffi::parse_ffi_string(in_name)?,
|
||||||
cstr_ffi::parse_ffi_string(in_value)?,
|
cstr_ffi::parse_ffi_string(in_value)?,
|
||||||
@@ -417,13 +270,13 @@ pub extern "C" fn WFSchemaAddIcon(
|
|||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFSchemaAddBehavior(
|
pub extern "C" fn WFSchemaAddBehavior(
|
||||||
in_schema: in_param_ty!(WFToken),
|
in_schema: in_param_ty!(WFToken),
|
||||||
in_name: in_param_ty!(WFCString),
|
in_name: in_param_ty!(WFStrPtr),
|
||||||
in_value: in_param_ty!(WFCString),
|
in_value: in_param_ty!(WFStrPtr),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(
|
cffi_wrapper!(
|
||||||
|in_schema: WFToken, in_name: WFCString, in_value: WFCString| {
|
|in_schema: WFToken, in_name: WFStrPtr, in_value: WFStrPtr| {
|
||||||
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
let pool = &CONTEXT.schema_pool;
|
||||||
let schema = pool.get_mut(in_schema)?;
|
let mut schema = pool.get_mut(in_schema)?;
|
||||||
schema.add_behavior(
|
schema.add_behavior(
|
||||||
cstr_ffi::parse_ffi_string(in_name)?,
|
cstr_ffi::parse_ffi_string(in_name)?,
|
||||||
cstr_ffi::parse_ffi_string(in_value)?,
|
cstr_ffi::parse_ffi_string(in_value)?,
|
||||||
@@ -436,18 +289,18 @@ pub extern "C" fn WFSchemaAddBehavior(
|
|||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFSchemaAddExt(
|
pub extern "C" fn WFSchemaAddExt(
|
||||||
in_schema: in_param_ty!(WFToken),
|
in_schema: in_param_ty!(WFToken),
|
||||||
in_ext: in_param_ty!(WFCString),
|
in_ext: in_param_ty!(WFStrPtr),
|
||||||
in_ext_name: in_param_ty!(WFCString),
|
in_ext_name: in_param_ty!(WFStrPtr),
|
||||||
in_ext_icon: in_param_ty!(WFCString),
|
in_ext_icon: in_param_ty!(WFStrPtr),
|
||||||
in_ext_behavior: in_param_ty!(WFCString),
|
in_ext_behavior: in_param_ty!(WFStrPtr),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_schema: WFToken,
|
cffi_wrapper!(|in_schema: WFToken,
|
||||||
in_ext: WFCString,
|
in_ext: WFStrPtr,
|
||||||
in_ext_name: WFCString,
|
in_ext_name: WFStrPtr,
|
||||||
in_ext_icon: WFCString,
|
in_ext_icon: WFStrPtr,
|
||||||
in_ext_behavior: WFCString| {
|
in_ext_behavior: WFStrPtr| {
|
||||||
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
let pool = &CONTEXT.schema_pool;
|
||||||
let schema = pool.get_mut(in_schema)?;
|
let mut schema = pool.get_mut(in_schema)?;
|
||||||
schema.add_ext(
|
schema.add_ext(
|
||||||
cstr_ffi::parse_ffi_string(in_ext)?,
|
cstr_ffi::parse_ffi_string(in_ext)?,
|
||||||
cstr_ffi::parse_ffi_string(in_ext_name)?,
|
cstr_ffi::parse_ffi_string(in_ext_name)?,
|
||||||
@@ -466,21 +319,21 @@ pub extern "C" fn WFSchemaAddExt(
|
|||||||
pub extern "C" fn WFProgramCreate(
|
pub extern "C" fn WFProgramCreate(
|
||||||
in_schema: in_param_ty!(WFToken),
|
in_schema: in_param_ty!(WFToken),
|
||||||
out_program: out_param_ty!(WFToken),
|
out_program: out_param_ty!(WFToken),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_schema: WFToken| -> (out_program: WFToken) {
|
cffi_wrapper!(|in_schema: WFToken| -> (out_program: WFToken) {
|
||||||
let mut pool = pull_writer!(SCHEMA_POOL)?;
|
let pool = &CONTEXT.schema_pool;
|
||||||
let schema = pool.pop(in_schema)?;
|
let schema = pool.pop(in_schema)?;
|
||||||
|
|
||||||
let mut pool = pull_writer!(PROGRAM_POOL)?;
|
let pool = &CONTEXT.program_pool;
|
||||||
let program = Program::new(schema)?;
|
let program = Program::new(schema)?;
|
||||||
Ok(pool.allocate(program)?)
|
Ok(pool.allocate(program))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFProgramDestroy(in_program: in_param_ty!(WFToken)) -> bool {
|
pub extern "C" fn WFProgramDestroy(in_program: in_param_ty!(WFToken)) -> WFError {
|
||||||
cffi_wrapper!(|in_program: WFToken| {
|
cffi_wrapper!(|in_program: WFToken| {
|
||||||
let mut pool = pull_writer!(PROGRAM_POOL)?;
|
let pool = &CONTEXT.program_pool;
|
||||||
Ok(pool.free(in_program)?)
|
Ok(pool.free(in_program)?)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -488,15 +341,14 @@ pub extern "C" fn WFProgramDestroy(in_program: in_param_ty!(WFToken)) -> bool {
|
|||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFProgramResolveName(
|
pub extern "C" fn WFProgramResolveName(
|
||||||
in_program: in_param_ty!(WFToken),
|
in_program: in_param_ty!(WFToken),
|
||||||
out_name: out_param_ty!(WFCString),
|
out_name: out_param_ty!(WFStrPtr),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_program: WFToken| -> (out_name: WFCString) {
|
cffi_wrapper!(|in_program: WFToken| -> (out_name: WFStrPtr) {
|
||||||
let mut pool = pull_writer!(PROGRAM_POOL)?;
|
let pool = &CONTEXT.program_pool;
|
||||||
let program = pool.get_mut(in_program)?;
|
let program = pool.get(in_program)?;
|
||||||
|
|
||||||
let name = program.resolve_name()?;
|
let name = program.resolve_name()?;
|
||||||
cstr_ffi::set_ffi_string(&name)?;
|
Ok(cstr_ffi::push_ffi_string(&name)?)
|
||||||
Ok(cstr_ffi::get_ffi_string())
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -504,14 +356,14 @@ pub extern "C" fn WFProgramResolveName(
|
|||||||
pub extern "C" fn WFProgramResolveIcon(
|
pub extern "C" fn WFProgramResolveIcon(
|
||||||
in_program: in_param_ty!(WFToken),
|
in_program: in_param_ty!(WFToken),
|
||||||
out_icon_rc: out_param_ty!(WFToken),
|
out_icon_rc: out_param_ty!(WFToken),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_program: WFToken| -> (out_icon_rc: WFToken) {
|
cffi_wrapper!(|in_program: WFToken| -> (out_icon_rc: WFToken) {
|
||||||
let mut pool = pull_writer!(PROGRAM_POOL)?;
|
let pool = &CONTEXT.program_pool;
|
||||||
let program = pool.get_mut(in_program)?;
|
let program = pool.get(in_program)?;
|
||||||
|
|
||||||
let icon = program.resolve_icon()?;
|
let icon = program.resolve_icon()?;
|
||||||
let mut pool = pull_writer!(ICON_RC_POOL)?;
|
let pool = &CONTEXT.icon_rc_pool;
|
||||||
Ok(pool.allocate(icon)?)
|
Ok(pool.allocate(icon))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -519,10 +371,10 @@ pub extern "C" fn WFProgramResolveIcon(
|
|||||||
pub extern "C" fn WFProgramExtsLen(
|
pub extern "C" fn WFProgramExtsLen(
|
||||||
in_program: in_param_ty!(WFToken),
|
in_program: in_param_ty!(WFToken),
|
||||||
out_len: out_param_ty!(usize),
|
out_len: out_param_ty!(usize),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_program: WFToken| -> (out_len: usize) {
|
cffi_wrapper!(|in_program: WFToken| -> (out_len: usize) {
|
||||||
let mut pool = pull_writer!(PROGRAM_POOL)?;
|
let pool = &CONTEXT.program_pool;
|
||||||
let program = pool.get_mut(in_program)?;
|
let program = pool.get(in_program)?;
|
||||||
Ok(program.exts_len())
|
Ok(program.exts_len())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -530,12 +382,12 @@ pub extern "C" fn WFProgramExtsLen(
|
|||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFProgramFindExt(
|
pub extern "C" fn WFProgramFindExt(
|
||||||
in_program: in_param_ty!(WFToken),
|
in_program: in_param_ty!(WFToken),
|
||||||
in_body: in_param_ty!(WFCString),
|
in_body: in_param_ty!(WFStrPtr),
|
||||||
out_index: out_param_ty!(usize),
|
out_index: out_param_ty!(usize),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_program: WFToken, in_body: WFCString| -> (out_index: usize) {
|
cffi_wrapper!(|in_program: WFToken, in_body: WFStrPtr| -> (out_index: usize) {
|
||||||
let mut pool = pull_writer!(PROGRAM_POOL)?;
|
let pool = &CONTEXT.program_pool;
|
||||||
let program = pool.get_mut(in_program)?;
|
let program = pool.get(in_program)?;
|
||||||
|
|
||||||
let body = cstr_ffi::parse_ffi_string(in_body)?;
|
let body = cstr_ffi::parse_ffi_string(in_body)?;
|
||||||
let index = match program.find_ext(body) {
|
let index = match program.find_ext(body) {
|
||||||
@@ -551,14 +403,14 @@ pub extern "C" fn WFProgramResolveExt(
|
|||||||
in_program: in_param_ty!(WFToken),
|
in_program: in_param_ty!(WFToken),
|
||||||
in_index: in_param_ty!(usize),
|
in_index: in_param_ty!(usize),
|
||||||
out_self_ext_status: out_param_ty!(WFToken),
|
out_self_ext_status: out_param_ty!(WFToken),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_program: WFToken, in_index: usize| -> (out_self_ext_status: WFToken) {
|
cffi_wrapper!(|in_program: WFToken, in_index: usize| -> (out_self_ext_status: WFToken) {
|
||||||
let mut pool = pull_writer!(PROGRAM_POOL)?;
|
let pool = &CONTEXT.program_pool;
|
||||||
let program = pool.get_mut(in_program)?;
|
let program = pool.get(in_program)?;
|
||||||
|
|
||||||
let self_ext_status = program.resolve_ext(in_index)?;
|
let self_ext_status = program.resolve_ext(in_index)?;
|
||||||
let mut pool = pull_writer!(SELF_EXT_STATUS_POOL)?;
|
let pool = &CONTEXT.self_ext_status_pool;
|
||||||
let token = pool.allocate(self_ext_status)?;
|
let token = pool.allocate(self_ext_status);
|
||||||
Ok(token)
|
Ok(token)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -567,11 +419,12 @@ pub extern "C" fn WFProgramResolveExt(
|
|||||||
pub extern "C" fn WFProgramRegister(
|
pub extern "C" fn WFProgramRegister(
|
||||||
in_program: in_param_ty!(WFToken),
|
in_program: in_param_ty!(WFToken),
|
||||||
in_scope: in_param_ty!(u32),
|
in_scope: in_param_ty!(u32),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_program: WFToken, in_scope: u32| {
|
cffi_wrapper!(|in_program: WFToken, in_scope: u32| {
|
||||||
let mut pool = pull_writer!(PROGRAM_POOL)?;
|
|
||||||
let program = pool.get_mut(in_program)?;
|
|
||||||
let scope = resolve_enum!(WFScope, in_scope)?;
|
let scope = resolve_enum!(WFScope, in_scope)?;
|
||||||
|
|
||||||
|
let pool = &CONTEXT.program_pool;
|
||||||
|
let mut program = pool.get_mut(in_program)?;
|
||||||
program.register(scope.into())?;
|
program.register(scope.into())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
@@ -581,11 +434,12 @@ pub extern "C" fn WFProgramRegister(
|
|||||||
pub extern "C" fn WFProgramUnregister(
|
pub extern "C" fn WFProgramUnregister(
|
||||||
in_program: in_param_ty!(WFToken),
|
in_program: in_param_ty!(WFToken),
|
||||||
in_scope: in_param_ty!(u32),
|
in_scope: in_param_ty!(u32),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_program: WFToken, in_scope: u32| {
|
cffi_wrapper!(|in_program: WFToken, in_scope: u32| {
|
||||||
let mut pool = pull_writer!(PROGRAM_POOL)?;
|
|
||||||
let program = pool.get_mut(in_program)?;
|
|
||||||
let scope = resolve_enum!(WFScope, in_scope)?;
|
let scope = resolve_enum!(WFScope, in_scope)?;
|
||||||
|
|
||||||
|
let pool = &CONTEXT.program_pool;
|
||||||
|
let mut program = pool.get_mut(in_program)?;
|
||||||
program.unregister(scope.into())?;
|
program.unregister(scope.into())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
@@ -596,11 +450,12 @@ pub extern "C" fn WFProgramIsRegistered(
|
|||||||
in_program: in_param_ty!(WFToken),
|
in_program: in_param_ty!(WFToken),
|
||||||
in_scope: in_param_ty!(u32),
|
in_scope: in_param_ty!(u32),
|
||||||
out_is_registered: out_param_ty!(bool),
|
out_is_registered: out_param_ty!(bool),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_program: WFToken, in_scope: u32| -> (out_is_registered: bool) {
|
cffi_wrapper!(|in_program: WFToken, in_scope: u32| -> (out_is_registered: bool) {
|
||||||
let pool = pull_reader!(PROGRAM_POOL)?;
|
|
||||||
let program = pool.get(in_program)?;
|
|
||||||
let scope = resolve_enum!(WFScope, in_scope)?;
|
let scope = resolve_enum!(WFScope, in_scope)?;
|
||||||
|
|
||||||
|
let pool = &CONTEXT.program_pool;
|
||||||
|
let program = pool.get(in_program)?;
|
||||||
Ok(program.is_registered(scope.into())?)
|
Ok(program.is_registered(scope.into())?)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -610,11 +465,12 @@ pub extern "C" fn WFProgramLinkExt(
|
|||||||
in_program: in_param_ty!(WFToken),
|
in_program: in_param_ty!(WFToken),
|
||||||
in_scope: in_param_ty!(u32),
|
in_scope: in_param_ty!(u32),
|
||||||
in_index: in_param_ty!(usize),
|
in_index: in_param_ty!(usize),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_program: WFToken, in_scope: u32, in_index: usize| {
|
cffi_wrapper!(|in_program: WFToken, in_scope: u32, in_index: usize| {
|
||||||
let mut pool = pull_writer!(PROGRAM_POOL)?;
|
|
||||||
let program = pool.get_mut(in_program)?;
|
|
||||||
let scope = resolve_enum!(WFScope, in_scope)?;
|
let scope = resolve_enum!(WFScope, in_scope)?;
|
||||||
|
|
||||||
|
let pool = &CONTEXT.program_pool;
|
||||||
|
let mut program = pool.get_mut(in_program)?;
|
||||||
program.link_ext(scope.into(), in_index)?;
|
program.link_ext(scope.into(), in_index)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
@@ -625,11 +481,12 @@ pub extern "C" fn WFProgramUnlinkExt(
|
|||||||
in_program: in_param_ty!(WFToken),
|
in_program: in_param_ty!(WFToken),
|
||||||
in_scope: in_param_ty!(u32),
|
in_scope: in_param_ty!(u32),
|
||||||
in_index: in_param_ty!(usize),
|
in_index: in_param_ty!(usize),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_program: WFToken, in_scope: u32, in_index: usize| {
|
cffi_wrapper!(|in_program: WFToken, in_scope: u32, in_index: usize| {
|
||||||
let mut pool = pull_writer!(PROGRAM_POOL)?;
|
|
||||||
let program = pool.get_mut(in_program)?;
|
|
||||||
let scope = resolve_enum!(WFScope, in_scope)?;
|
let scope = resolve_enum!(WFScope, in_scope)?;
|
||||||
|
|
||||||
|
let pool = &CONTEXT.program_pool;
|
||||||
|
let mut program = pool.get_mut(in_program)?;
|
||||||
program.unlink_ext(scope.into(), in_index)?;
|
program.unlink_ext(scope.into(), in_index)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
@@ -641,19 +498,19 @@ pub extern "C" fn WFProgramQueryExt(
|
|||||||
in_view: in_param_ty!(u32),
|
in_view: in_param_ty!(u32),
|
||||||
in_index: in_param_ty!(usize),
|
in_index: in_param_ty!(usize),
|
||||||
out_ext_status: out_param_ty!(WFToken),
|
out_ext_status: out_param_ty!(WFToken),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_program: WFToken, in_view: u32, in_index: usize| -> (out_ext_status: WFToken) {
|
cffi_wrapper!(|in_program: WFToken, in_view: u32, in_index: usize| -> (out_ext_status: WFToken) {
|
||||||
let pool = pull_reader!(PROGRAM_POOL)?;
|
|
||||||
let program = pool.get(in_program)?;
|
|
||||||
let view = resolve_enum!(WFView, in_view)?;
|
let view = resolve_enum!(WFView, in_view)?;
|
||||||
|
|
||||||
|
let pool = &CONTEXT.program_pool;
|
||||||
|
let program = pool.get(in_program)?;
|
||||||
let ext_status = program.query_ext(view.into(), in_index)?;
|
let ext_status = program.query_ext(view.into(), in_index)?;
|
||||||
let token = match ext_status {
|
let token = match ext_status {
|
||||||
Some(ext_status) => {
|
Some(ext_status) => {
|
||||||
let mut pool = pull_writer!(EXT_STATUS_POOL)?;
|
let pool = &CONTEXT.ext_status_pool;
|
||||||
pool.allocate(ext_status)?
|
pool.allocate(ext_status)
|
||||||
},
|
},
|
||||||
None => object_pool::invalid_token(),
|
None => WF_INVALID_TOKEN,
|
||||||
};
|
};
|
||||||
Ok(token)
|
Ok(token)
|
||||||
})
|
})
|
||||||
@@ -664,9 +521,9 @@ pub extern "C" fn WFProgramQueryExt(
|
|||||||
// region: Extension Status
|
// region: Extension Status
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFExtStatusDestroy(in_ext_status: in_param_ty!(WFToken)) -> bool {
|
pub extern "C" fn WFExtStatusDestroy(in_ext_status: in_param_ty!(WFToken)) -> WFError {
|
||||||
cffi_wrapper!(|in_ext_status: WFToken| {
|
cffi_wrapper!(|in_ext_status: WFToken| {
|
||||||
let mut pool = pull_writer!(EXT_STATUS_POOL)?;
|
let pool = &CONTEXT.ext_status_pool;
|
||||||
Ok(pool.free(in_ext_status)?)
|
Ok(pool.free(in_ext_status)?)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -674,14 +531,13 @@ pub extern "C" fn WFExtStatusDestroy(in_ext_status: in_param_ty!(WFToken)) -> bo
|
|||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFExtStatusGetName(
|
pub extern "C" fn WFExtStatusGetName(
|
||||||
in_ext_status: in_param_ty!(WFToken),
|
in_ext_status: in_param_ty!(WFToken),
|
||||||
out_name: out_param_ty!(WFCString),
|
out_name: out_param_ty!(WFStrPtr),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_ext_status: WFToken| -> (out_name: WFCString) {
|
cffi_wrapper!(|in_ext_status: WFToken| -> (out_name: WFStrPtr) {
|
||||||
let pool = pull_reader!(EXT_STATUS_POOL)?;
|
let pool = &CONTEXT.ext_status_pool;
|
||||||
let ext_status = pool.get(in_ext_status)?;
|
let ext_status = pool.get(in_ext_status)?;
|
||||||
|
|
||||||
cstr_ffi::set_ffi_string(ext_status.get_name())?;
|
Ok(cstr_ffi::push_ffi_string(ext_status.get_name())?)
|
||||||
Ok(cstr_ffi::get_ffi_string())
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -689,9 +545,9 @@ pub extern "C" fn WFExtStatusGetName(
|
|||||||
pub extern "C" fn WFExtStatusGetIcon(
|
pub extern "C" fn WFExtStatusGetIcon(
|
||||||
in_ext_status: in_param_ty!(WFToken),
|
in_ext_status: in_param_ty!(WFToken),
|
||||||
out_icon: out_param_ty!(WFHICON),
|
out_icon: out_param_ty!(WFHICON),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_ext_status: WFToken| -> (out_icon: WFHICON) {
|
cffi_wrapper!(|in_ext_status: WFToken| -> (out_icon: WFHICON) {
|
||||||
let pool = pull_reader!(EXT_STATUS_POOL)?;
|
let pool = &CONTEXT.ext_status_pool;
|
||||||
let ext_status = pool.get(in_ext_status)?;
|
let ext_status = pool.get(in_ext_status)?;
|
||||||
|
|
||||||
let icon = ext_status.get_icon();
|
let icon = ext_status.get_icon();
|
||||||
@@ -704,9 +560,9 @@ pub extern "C" fn WFExtStatusGetIcon(
|
|||||||
// region: Self Extension Status
|
// region: Self Extension Status
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFSelfExtStatusDestroy(in_self_ext_status: in_param_ty!(WFToken)) -> bool {
|
pub extern "C" fn WFSelfExtStatusDestroy(in_self_ext_status: in_param_ty!(WFToken)) -> WFError {
|
||||||
cffi_wrapper!(|in_self_ext_status: WFToken| {
|
cffi_wrapper!(|in_self_ext_status: WFToken| {
|
||||||
let mut pool = pull_writer!(SELF_EXT_STATUS_POOL)?;
|
let pool = &CONTEXT.self_ext_status_pool;
|
||||||
Ok(pool.free(in_self_ext_status)?)
|
Ok(pool.free(in_self_ext_status)?)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -714,14 +570,13 @@ pub extern "C" fn WFSelfExtStatusDestroy(in_self_ext_status: in_param_ty!(WFToke
|
|||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFSelfExtStatusGetName(
|
pub extern "C" fn WFSelfExtStatusGetName(
|
||||||
in_self_ext_status: in_param_ty!(WFToken),
|
in_self_ext_status: in_param_ty!(WFToken),
|
||||||
out_name: out_param_ty!(WFCString),
|
out_name: out_param_ty!(WFStrPtr),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_self_ext_status: WFToken| -> (out_name: WFCString) {
|
cffi_wrapper!(|in_self_ext_status: WFToken| -> (out_name: WFStrPtr) {
|
||||||
let pool = pull_reader!(SELF_EXT_STATUS_POOL)?;
|
let pool = &CONTEXT.self_ext_status_pool;
|
||||||
let self_ext_status = pool.get(in_self_ext_status)?;
|
let self_ext_status = pool.get(in_self_ext_status)?;
|
||||||
|
|
||||||
cstr_ffi::set_ffi_string(self_ext_status.get_name())?;
|
Ok(cstr_ffi::push_ffi_string(self_ext_status.get_name())?)
|
||||||
Ok(cstr_ffi::get_ffi_string())
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -729,9 +584,9 @@ pub extern "C" fn WFSelfExtStatusGetName(
|
|||||||
pub extern "C" fn WFSelfExtStatusGetIcon(
|
pub extern "C" fn WFSelfExtStatusGetIcon(
|
||||||
in_self_ext_status: in_param_ty!(WFToken),
|
in_self_ext_status: in_param_ty!(WFToken),
|
||||||
out_icon: out_param_ty!(WFHICON),
|
out_icon: out_param_ty!(WFHICON),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_self_ext_status: WFToken| -> (out_icon: WFHICON) {
|
cffi_wrapper!(|in_self_ext_status: WFToken| -> (out_icon: WFHICON) {
|
||||||
let pool = pull_reader!(SELF_EXT_STATUS_POOL)?;
|
let pool = &CONTEXT.self_ext_status_pool;
|
||||||
let self_ext_status = pool.get(in_self_ext_status)?;
|
let self_ext_status = pool.get(in_self_ext_status)?;
|
||||||
|
|
||||||
let icon = self_ext_status.get_icon();
|
let icon = self_ext_status.get_icon();
|
||||||
@@ -742,28 +597,26 @@ pub extern "C" fn WFSelfExtStatusGetIcon(
|
|||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFSelfExtStatusGetExt(
|
pub extern "C" fn WFSelfExtStatusGetExt(
|
||||||
in_self_ext_status: in_param_ty!(WFToken),
|
in_self_ext_status: in_param_ty!(WFToken),
|
||||||
out_inner: out_param_ty!(WFCString),
|
out_inner: out_param_ty!(WFStrPtr),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_self_ext_status: WFToken| -> (out_inner: WFCString) {
|
cffi_wrapper!(|in_self_ext_status: WFToken| -> (out_inner: WFStrPtr) {
|
||||||
let pool = pull_reader!(SELF_EXT_STATUS_POOL)?;
|
let pool = &CONTEXT.self_ext_status_pool;
|
||||||
let self_ext_status = pool.get(in_self_ext_status)?;
|
let self_ext_status = pool.get(in_self_ext_status)?;
|
||||||
|
|
||||||
cstr_ffi::set_ffi_string(self_ext_status.get_ext())?;
|
Ok(cstr_ffi::push_ffi_string(self_ext_status.get_ext())?)
|
||||||
Ok(cstr_ffi::get_ffi_string())
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFSelfExtStatusGetDottedExt(
|
pub extern "C" fn WFSelfExtStatusGetDottedExt(
|
||||||
in_self_ext_status: in_param_ty!(WFToken),
|
in_self_ext_status: in_param_ty!(WFToken),
|
||||||
out_inner: out_param_ty!(WFCString),
|
out_inner: out_param_ty!(WFStrPtr),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_self_ext_status: WFToken| -> (out_inner: WFCString) {
|
cffi_wrapper!(|in_self_ext_status: WFToken| -> (out_inner: WFStrPtr) {
|
||||||
let pool = pull_reader!(SELF_EXT_STATUS_POOL)?;
|
let pool = &CONTEXT.self_ext_status_pool;
|
||||||
let self_ext_status = pool.get(in_self_ext_status)?;
|
let self_ext_status = pool.get(in_self_ext_status)?;
|
||||||
|
|
||||||
cstr_ffi::set_ffi_string(self_ext_status.get_dotted_ext().as_str())?;
|
Ok(cstr_ffi::push_ffi_string(self_ext_status.get_dotted_ext().as_str())?)
|
||||||
Ok(cstr_ffi::get_ffi_string())
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -772,9 +625,9 @@ pub extern "C" fn WFSelfExtStatusGetDottedExt(
|
|||||||
// region: Icon Resource
|
// region: Icon Resource
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn WFIconRcDestroy(in_icon_rc: in_param_ty!(WFToken)) -> bool {
|
pub extern "C" fn WFIconRcDestroy(in_icon_rc: in_param_ty!(WFToken)) -> WFError {
|
||||||
cffi_wrapper!(|in_icon_rc: WFToken| {
|
cffi_wrapper!(|in_icon_rc: WFToken| {
|
||||||
let mut pool = pull_writer!(ICON_RC_POOL)?;
|
let pool = &CONTEXT.icon_rc_pool;
|
||||||
Ok(pool.free(in_icon_rc)?)
|
Ok(pool.free(in_icon_rc)?)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -783,9 +636,9 @@ pub extern "C" fn WFIconRcDestroy(in_icon_rc: in_param_ty!(WFToken)) -> bool {
|
|||||||
pub extern "C" fn WFIconRcGetIcon(
|
pub extern "C" fn WFIconRcGetIcon(
|
||||||
in_icon_rc: in_param_ty!(WFToken),
|
in_icon_rc: in_param_ty!(WFToken),
|
||||||
out_icon: out_param_ty!(WFHICON),
|
out_icon: out_param_ty!(WFHICON),
|
||||||
) -> bool {
|
) -> WFError {
|
||||||
cffi_wrapper!(|in_icon_rc: WFToken| -> (out_icon: WFHICON) {
|
cffi_wrapper!(|in_icon_rc: WFToken| -> (out_icon: WFHICON) {
|
||||||
let pool = pull_reader!(ICON_RC_POOL)?;
|
let pool = &CONTEXT.icon_rc_pool;
|
||||||
let icon_rc = pool.get(in_icon_rc)?;
|
let icon_rc = pool.get(in_icon_rc)?;
|
||||||
|
|
||||||
Ok(icon_rc.get_icon())
|
Ok(icon_rc.get_icon())
|
||||||
|
|||||||
@@ -1,95 +0,0 @@
|
|||||||
//! When exporting resources for C interface, resource management and ownership are important things.
|
|
||||||
//! In this dynamic library, we hold all resources' ownership in Rust world,
|
|
||||||
//! and only expose a token for C code manipulation.
|
|
||||||
//!
|
|
||||||
//! We need to create a container for holding all resources and providing corresponding operations.
|
|
||||||
//! So we introduce [ObjectPool] in this module for this purpose.
|
|
||||||
use slotmap::{DefaultKey, Key, KeyData, SlotMap};
|
|
||||||
use thiserror::Error as TeError;
|
|
||||||
|
|
||||||
/// Error occurs when operating with [ObjectPool].
|
|
||||||
#[derive(Debug, TeError)]
|
|
||||||
pub enum Error {
|
|
||||||
#[error("given token is not presented in object pool")]
|
|
||||||
NoSuchToken,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The token for fetching object in [ObjectPool].
|
|
||||||
pub type Token = u64;
|
|
||||||
|
|
||||||
/// Get the invalid token.
|
|
||||||
///
|
|
||||||
/// Invalid token is always invalid for fetching object in pool,
|
|
||||||
/// And can be useful in FFI scenario.
|
|
||||||
pub fn invalid_token() -> Token {
|
|
||||||
DefaultKey::null().data().as_ffi()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A pool for managing objects with unique tokens.
|
|
||||||
///
|
|
||||||
/// It is highly suggested to use this pool with [std::sync::RwLock] guard.
|
|
||||||
pub struct ObjectPool<T> {
|
|
||||||
objs: SlotMap<DefaultKey, T>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> ObjectPool<T> {
|
|
||||||
/// Create a new [ObjectPool].
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
objs: SlotMap::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Convert [slotmap] crate's [DefaultKey] to our [Token].
|
|
||||||
fn key_to_token(key: &DefaultKey) -> Token {
|
|
||||||
key.data().as_ffi()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Convert our [Token] to [slotmap] crate's [DefaultKey].
|
|
||||||
fn token_to_key(token: Token) -> DefaultKey {
|
|
||||||
DefaultKey::from(KeyData::from_ffi(token))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Put given object into the pool and return its token.
|
|
||||||
///
|
|
||||||
/// The ownership of given object is transferred to the pool.
|
|
||||||
pub fn allocate(&mut self, value: T) -> Result<Token, Error> {
|
|
||||||
let key = self.objs.insert(value);
|
|
||||||
Ok(Self::key_to_token(&key))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Free the object in the pool corresponding to the given token.
|
|
||||||
pub fn free(&mut self, token: Token) -> Result<(), Error> {
|
|
||||||
let _ = self.pop(token)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Remove the object from the pool corresponding to the given token and return it.
|
|
||||||
///
|
|
||||||
/// The ownership of the object is transferred to the caller.
|
|
||||||
pub fn pop(&mut self, token: Token) -> Result<T, Error> {
|
|
||||||
match self.objs.remove(Self::token_to_key(token)) {
|
|
||||||
Some(obj) => Ok(obj),
|
|
||||||
None => Err(Error::NoSuchToken),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clear all objects in the pool.
|
|
||||||
pub fn clear(&mut self) -> () {
|
|
||||||
self.objs.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get a reference to the object in the pool corresponding to the given token.
|
|
||||||
pub fn get(&self, token: Token) -> Result<&T, Error> {
|
|
||||||
self.objs
|
|
||||||
.get(Self::token_to_key(token))
|
|
||||||
.ok_or(Error::NoSuchToken)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get a mutable reference to the object in the pool corresponding to the given token.
|
|
||||||
pub fn get_mut(&mut self, token: Token) -> Result<&mut T, Error> {
|
|
||||||
self.objs
|
|
||||||
.get_mut(Self::token_to_key(token))
|
|
||||||
.ok_or(Error::NoSuchToken)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +1,8 @@
|
|||||||
//! The module including all FFI types used by this crate, except string type.
|
//! The module including all wrapper types for FFI.
|
||||||
//! For string type, see also [crate::cstr_ffi].
|
|
||||||
|
|
||||||
use std::ffi::{c_void, c_char};
|
use std::ffi::c_void;
|
||||||
use num_enum::TryFromPrimitive;
|
use num_enum::TryFromPrimitive;
|
||||||
|
|
||||||
// region: Misc Types and Constants
|
|
||||||
|
|
||||||
/// The type representing the raw pointer to immutable C-style NUL-terminated string.
|
|
||||||
pub type CStyleString = *const c_char;
|
|
||||||
|
|
||||||
/// The invalid value of index.
|
|
||||||
pub const INVALID_INDEX: usize = usize::MAX;
|
|
||||||
|
|
||||||
// endregion
|
|
||||||
|
|
||||||
// region: HICON
|
// region: HICON
|
||||||
|
|
||||||
/// The type representing Win32 HICON handle.
|
/// The type representing Win32 HICON handle.
|
||||||
@@ -75,3 +64,10 @@ impl From<View> for wfassoc::View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
// region: Misc Types and Constants
|
||||||
|
|
||||||
|
/// The invalid value of index.
|
||||||
|
pub const INVALID_INDEX: usize = usize::MAX;
|
||||||
|
|
||||||
|
// endregion
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
[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."
|
||||||
license = "SPDX:MIT"
|
license = "MIT"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
|
|||||||
+2
-2
@@ -1,10 +1,10 @@
|
|||||||
[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."
|
||||||
license = "SPDX:MIT"
|
license = "MIT"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
|
|||||||
Reference in New Issue
Block a user