Blender V5.0
winstuff_registration.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#ifdef WIN32
10# include <Windows.h>
11
12# include <KnownFolders.h>
13# include <filesystem>
14# include <propkey.h>
15# include <propvarutil.h>
16# include <shlobj_core.h>
17# include <wrl.h>
18
19# include "BLI_path_utils.hh"
20# include "BLI_winstuff.h"
21# include "BLI_winstuff_com.hh"
22
23# include "utf_winfunc.hh"
24# include "utfconv.hh"
25
43bool BLI_windows_update_pinned_launcher(const char *launcher_path)
44{
45 WCHAR launcher_path_w[FILE_MAX];
46
47 if (conv_utf_8_to_16(launcher_path, launcher_path_w, ARRAY_SIZE(launcher_path_w)) != 0) {
48 return false;
49 }
50
51 blender::CoInitializeWrapper initialize(COINIT_APARTMENTTHREADED);
52 if (FAILED(initialize)) {
53 return false;
54 }
55
56 LPWSTR quick_launch_folder_path;
57 if (SHGetKnownFolderPath(
58 FOLDERID_ImplicitAppShortcuts, KF_FLAG_DEFAULT, nullptr, &quick_launch_folder_path) !=
59 S_OK)
60 {
61 return false;
62 }
63
64 std::wstring search_path = quick_launch_folder_path;
65 CoTaskMemFree(quick_launch_folder_path);
66
67 for (auto const &dir_entry : std::filesystem::recursive_directory_iterator(search_path)) {
68
69 Microsoft::WRL::ComPtr<IShellLinkW> shell_link;
70 if (CoCreateInstance(__uuidof(ShellLink), nullptr, CLSCTX_ALL, IID_PPV_ARGS(&shell_link)) !=
71 S_OK)
72 {
73 return false;
74 }
75
76 Microsoft::WRL::ComPtr<IPersistFile> persist_file;
77 if (shell_link.As(&persist_file) != S_OK) {
78 return false;
79 }
80
81 if (persist_file->Load(dir_entry.path().c_str(), STGM_READWRITE) != S_OK) {
82 continue;
83 }
84
85 Microsoft::WRL::ComPtr<IPropertyStore> property_store;
86 if (shell_link.As(&property_store) != S_OK) {
87 continue;
88 }
89
90 UTF16_ENCODE(BLENDER_WIN_APPID);
91 PROPVARIANT app_model;
92 PropVariantInit(&app_model);
93 if (property_store->GetValue(PKEY_AppUserModel_ID, &app_model) == S_OK) {
94 if (app_model.vt == VT_LPWSTR && std::wstring(BLENDER_WIN_APPID_16) == app_model.pwszVal) {
95 shell_link->SetPath(launcher_path_w);
96 persist_file->Save(nullptr, TRUE);
97 }
98 }
99 PropVariantClear(&app_model);
100 UTF16_UN_ENCODE(BLENDER_WIN_APPID);
101 }
102 return true;
103}
104#endif
#define FILE_MAX
#define ARRAY_SIZE(arr)
Compatibility-like things for windows.
bool BLI_windows_update_pinned_launcher(const char *launcher_path)
COM helper functions for windows.
void initialize()
static void initialize(const Object *obj, pxr::UsdSkelSkeleton &skel, pxr::UsdSkelAnimation &skel_anim, const blender::Map< blender::StringRef, const Bone * > *deform_bones, bool allow_unicode)
int conv_utf_8_to_16(const char *in8, wchar_t *out16, size_t size16)
Definition utfconv.cc:182
#define UTF16_ENCODE(in8str)
Definition utfconv.hh:80
#define UTF16_UN_ENCODE(in8str)
Definition utfconv.hh:84