diff --git a/.cspell/words.txt b/.cspell/words.txt index ea9944f4..7ca74458 100644 --- a/.cspell/words.txt +++ b/.cspell/words.txt @@ -16,9 +16,11 @@ boost_asio_has_std_string_view bugprone cflags chrono +clsid cmake_current_source_dir coinit_apartmentthreaded comdlg32 +conin$ cppcoreguidelines cppdbg cppflags @@ -110,6 +112,7 @@ filebase flac_version flag_nopath flarge +folderid fontconfig_version foob fooba @@ -125,11 +128,14 @@ gpath gtest_version has_setxattr hkey +hresult httpapi httplib +hwnd icudata icui18n icuuc +inproc iostreams iphlpapi ipstream @@ -208,13 +214,16 @@ renterd richtext rocksdb_library rpcrt4 +runas s_igid s_isvtx s_iuid sddl_revision_1 secp256k1 secur32 +see_mask_nocloseprocess sfml_project +shellexecuteinfoa shlwapi sigchld skynet diff --git a/repertory/librepertory/src/initialize.cpp b/repertory/librepertory/src/initialize.cpp index eee78752..47c82b7a 100644 --- a/repertory/librepertory/src/initialize.cpp +++ b/repertory/librepertory/src/initialize.cpp @@ -53,6 +53,10 @@ #include #endif // defined(__APPLE__) +#if defined(_WIN32) +#include "utils/com_init_wrapper.hpp" +#endif // defined(_WIN32) + namespace { #if defined(PROJECT_ENABLE_CURL) bool curl_initialized{false}; @@ -65,6 +69,10 @@ bool spdlog_initialized{false}; #if defined(PROJECT_ENABLE_SQLITE) bool sqlite3_initialized{false}; #endif // defined(PROJECT_ENABLE_SQLITE) + +#if defined(_WIN32) +[[maybe_unused]] const repertory::utils::com_init_wrapper wrapper; +#endif // defined(_WIN32) } // namespace namespace repertory { diff --git a/repertory/repertory/include/cli/common.hpp b/repertory/repertory/include/cli/common.hpp index cc6b3c24..187fecdb 100644 --- a/repertory/repertory/include/cli/common.hpp +++ b/repertory/repertory/include/cli/common.hpp @@ -40,7 +40,6 @@ #include "drives/winfsp/remotewinfsp/remote_client.hpp" #include "drives/winfsp/remotewinfsp/remote_winfsp_drive.hpp" #include "drives/winfsp/winfsp_drive.hpp" -#include "utils/com_init_wrapper.hpp" using repertory_drive = repertory::winfsp_drive; using remote_client = repertory::remote_winfsp::remote_client; diff --git a/repertory/repertory/include/cli/mount.hpp b/repertory/repertory/include/cli/mount.hpp index f0276a6e..b0ed709e 100644 --- a/repertory/repertory/include/cli/mount.hpp +++ b/repertory/repertory/include/cli/mount.hpp @@ -99,7 +99,6 @@ mount(std::vector args, std::string data_directory, #if defined(_WIN32) if (config.get_enable_mount_manager() && not utils::is_process_elevated()) { - utils::com_init_wrapper wrapper; if (not lock.set_mount_state(true, "elevating", -1)) { std::cerr << "failed to set mount state" << std::endl; } diff --git a/repertory/repertory/include/ui/mgmt_app_config.hpp b/repertory/repertory/include/ui/mgmt_app_config.hpp index 6276d321..c512e265 100644 --- a/repertory/repertory/include/ui/mgmt_app_config.hpp +++ b/repertory/repertory/include/ui/mgmt_app_config.hpp @@ -39,7 +39,7 @@ private: utils::atomic api_password_{"repertory"}; std::atomic api_port_{default_ui_mgmt_port}; utils::atomic api_user_{"repertory"}; - std::atomic auto_start_{false}; + std::atomic auto_start_{true}; std::unordered_map> locations_; diff --git a/repertory/repertory/src/ui/mgmt_app_config.cpp b/repertory/repertory/src/ui/mgmt_app_config.cpp index ba481b3f..e7b58e83 100644 --- a/repertory/repertory/src/ui/mgmt_app_config.cpp +++ b/repertory/repertory/src/ui/mgmt_app_config.cpp @@ -261,7 +261,7 @@ void mgmt_app_config::set_auto_start(bool auto_start) { #if defined(_WIN32) if (auto_start) { utils::shortcut_cfg cfg{}; - cfg.arguments = {L"-ui", L"-lo"}; + cfg.arguments = L"-ui -lo"; cfg.exe_path = utils::path::combine(L".", {L"repertory"}); cfg.icon_path = utils::path::combine(L".", {L"icon.ico"}); cfg.shortcut_name = L"repertory"; diff --git a/support/src/utils/windows.cpp b/support/src/utils/windows.cpp index 577dd63e..5c46d858 100644 --- a/support/src/utils/windows.cpp +++ b/support/src/utils/windows.cpp @@ -23,6 +23,7 @@ #include "utils/windows.hpp" +#include "utils/com_init_wrapper.hpp" #include "utils/error.hpp" #include "utils/file.hpp" #include "utils/path.hpp" @@ -91,10 +92,11 @@ auto is_process_elevated() -> bool { auto ret{false}; HANDLE token{INVALID_HANDLE_VALUE}; if (::OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token)) { - TOKEN_ELEVATION te{}; - DWORD sz = sizeof(te); - if (::GetTokenInformation(token, TokenElevation, &te, sizeof(te), &sz)) { - ret = (te.TokenIsElevated != 0); + TOKEN_ELEVATION token_elevation{}; + DWORD size = sizeof(token_elevation); + if (::GetTokenInformation(token, TokenElevation, &token_elevation, + sizeof(token_elevation), &size)) { + ret = (token_elevation.TokenIsElevated != 0); } } @@ -141,6 +143,8 @@ auto run_process_elevated(std::vector args) -> int { void set_last_error_code(DWORD error_code) { ::SetLastError(error_code); } auto get_startup_folder() -> std::wstring { + utils::com_init_wrapper wrapper; + PWSTR raw{nullptr}; auto result = ::SHGetKnownFolderPath(FOLDERID_Startup, 0, nullptr, &raw); if (FAILED(result)) { @@ -159,10 +163,12 @@ auto get_startup_folder() -> std::wstring { auto create_shortcut(const shortcut_cfg &cfg, bool overwrite_existing) -> bool { REPERTORY_USES_FUNCTION_NAME(); - const auto hr_hex = [](HRESULT hr) -> std::string { + utils::com_init_wrapper wrapper; + + const auto hr_hex = [](HRESULT result) -> std::string { std::ostringstream oss; oss << "0x" << std::uppercase << std::hex << std::setw(8) - << std::setfill('0') << static_cast(hr); + << std::setfill('0') << static_cast(result); return oss.str(); }; @@ -191,8 +197,8 @@ auto create_shortcut(const shortcut_cfg &cfg, bool overwrite_existing) -> bool { } IShellLinkW *psl{nullptr}; - HRESULT result = ::CoCreateInstance(CLSID_ShellLink, nullptr, - CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&psl)); + auto result = ::CoCreateInstance(CLSID_ShellLink, nullptr, + CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&psl)); if (FAILED(result)) { utils::error::handle_error( function_name,