Blender V4.3
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
5#ifdef WIN32
6# include <Windows.h>
7
8# include <KnownFolders.h>
9# include <filesystem>
10# include <propkey.h>
11# include <propvarutil.h>
12# include <shlobj_core.h>
13# include <wrl.h>
14
15# include "BLI_path_utils.hh"
16# include "BLI_winstuff.h"
17# include "BLI_winstuff_com.hh"
18
19# include "utf_winfunc.hh"
20# include "utfconv.hh"
21
39bool BLI_windows_update_pinned_launcher(const char *launcher_path)
40{
41 WCHAR launcher_path_w[FILE_MAX];
42
43 if (conv_utf_8_to_16(launcher_path, launcher_path_w, ARRAY_SIZE(launcher_path_w)) != 0) {
44 return false;
45 }
46
47 blender::CoInitializeWrapper initialize(COINIT_APARTMENTTHREADED);
48 if (FAILED(initialize)) {
49 return false;
50 }
51
52 LPWSTR quick_launch_folder_path;
53 if (SHGetKnownFolderPath(
54 FOLDERID_ImplicitAppShortcuts, KF_FLAG_DEFAULT, NULL, &quick_launch_folder_path) != S_OK)
55 {
56 return false;
57 }
58
59 std::wstring search_path = quick_launch_folder_path;
60 CoTaskMemFree(quick_launch_folder_path);
61
62 for (auto const &dir_entry : std::filesystem::recursive_directory_iterator(search_path)) {
63
64 Microsoft::WRL::ComPtr<IShellLinkW> shell_link;
65 if (CoCreateInstance(__uuidof(ShellLink), NULL, CLSCTX_ALL, IID_PPV_ARGS(&shell_link)) != S_OK)
66 {
67 return false;
68 }
69
70 Microsoft::WRL::ComPtr<IPersistFile> persist_file;
71 if (shell_link.As(&persist_file) != S_OK) {
72 return false;
73 }
74
75 if (persist_file->Load(dir_entry.path().c_str(), STGM_READWRITE) != S_OK) {
76 continue;
77 }
78
79 Microsoft::WRL::ComPtr<IPropertyStore> property_store;
80 if (shell_link.As(&property_store) != S_OK) {
81 continue;
82 }
83
84 UTF16_ENCODE(BLENDER_WIN_APPID);
85 PROPVARIANT app_model;
86 PropVariantInit(&app_model);
87 if (property_store->GetValue(PKEY_AppUserModel_ID, &app_model) == S_OK) {
88 if (app_model.vt == VT_LPWSTR && std::wstring(BLENDER_WIN_APPID_16) == app_model.pwszVal) {
89 shell_link->SetPath(launcher_path_w);
90 persist_file->Save(NULL, TRUE);
91 }
92 }
93 PropVariantClear(&app_model);
94 UTF16_UN_ENCODE(BLENDER_WIN_APPID);
95 }
96 return true;
97}
98#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()
#define NULL
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