Blender V4.3
GHOST_SystemPathsWin32.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10#include "GHOST_Debug.hh"
11
12#ifndef _WIN32_IE
13# define _WIN32_IE 0x0501
14#endif
15#include "utfconv.hh"
16#include <shlobj.h>
17
19
21
22const char *GHOST_SystemPathsWin32::getSystemDir(int, const char *versionstr) const
23{
24 const char *system_dir = nullptr;
25
26 /* 1 utf-16 might translate into 3 utf-8. 2 utf-16 translates into 4 utf-8. */
27 static char knownpath[MAX_PATH * 3 + 128] = {0};
28 PWSTR knownpath_16 = nullptr;
29
30 HRESULT hResult = SHGetKnownFolderPath(
31 FOLDERID_ProgramData, KF_FLAG_DEFAULT, nullptr, &knownpath_16);
32
33 if (hResult == S_OK) {
34 conv_utf_16_to_8(knownpath_16, knownpath, MAX_PATH * 3);
35 strcat(knownpath, "\\Blender Foundation\\Blender\\");
36 strcat(knownpath, versionstr);
37 system_dir = knownpath;
38 }
39
40 CoTaskMemFree(knownpath_16);
41 return system_dir;
42}
43
44const char *GHOST_SystemPathsWin32::getUserDir(int, const char *versionstr) const
45{
46 const char *user_dir = nullptr;
47
48 static char knownpath[MAX_PATH * 3 + 128] = {0};
49 PWSTR knownpath_16 = nullptr;
50
51 HRESULT hResult = SHGetKnownFolderPath(
52 FOLDERID_RoamingAppData, KF_FLAG_DEFAULT, nullptr, &knownpath_16);
53
54 if (hResult == S_OK) {
55 conv_utf_16_to_8(knownpath_16, knownpath, MAX_PATH * 3);
56 strcat(knownpath, "\\Blender Foundation\\Blender\\");
57 strcat(knownpath, versionstr);
58 user_dir = knownpath;
59 }
60
61 CoTaskMemFree(knownpath_16);
62 return user_dir;
63}
64
66{
67 const char *special_dir = nullptr;
68
69 GUID folderid;
70 switch (type) {
72 folderid = FOLDERID_Desktop;
73 break;
75 folderid = FOLDERID_Documents;
76 break;
78 folderid = FOLDERID_Downloads;
79 break;
81 folderid = FOLDERID_Music;
82 break;
84 folderid = FOLDERID_Pictures;
85 break;
87 folderid = FOLDERID_Videos;
88 break;
90 folderid = FOLDERID_LocalAppData;
91 break;
92 default:
94 false,
95 "GHOST_SystemPathsWin32::getUserSpecialDir(): Invalid enum value for type parameter");
96 return nullptr;
97 }
98
99 static char knownpath[MAX_PATH * 3] = {0};
100 PWSTR knownpath_16 = nullptr;
101 HRESULT hResult = SHGetKnownFolderPath(folderid, KF_FLAG_DEFAULT, nullptr, &knownpath_16);
102
103 if (hResult == S_OK) {
104 conv_utf_16_to_8(knownpath_16, knownpath, MAX_PATH * 3);
105 special_dir = knownpath;
106 }
107
108 CoTaskMemFree(knownpath_16);
109 return special_dir;
110}
111
113{
114 static char fullname[MAX_PATH * 3] = {0};
115 wchar_t fullname_16[MAX_PATH * 3];
116
117 if (GetModuleFileNameW(0, fullname_16, MAX_PATH)) {
118 conv_utf_16_to_8(fullname_16, fullname, MAX_PATH * 3);
119 return fullname;
120 }
121
122 return nullptr;
123}
124
126{
127 UTF16_ENCODE(filepath);
128 UTF16_ENCODE(BLENDER_WIN_APPID);
129 SHARDAPPIDINFO info;
130 IShellItem *shell_item;
131
132 HRESULT hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
133 if (!SUCCEEDED(hr)) {
134 return;
135 }
136
137 hr = SHCreateItemFromParsingName(filepath_16, nullptr, IID_PPV_ARGS(&shell_item));
138 if (SUCCEEDED(hr)) {
139 info.psi = shell_item;
140 info.pszAppID = BLENDER_WIN_APPID_16;
141 SHAddToRecentDocs(SHARD_APPIDINFO, &info);
142 }
143
144 CoUninitialize();
145 UTF16_UN_ENCODE(BLENDER_WIN_APPID);
146 UTF16_UN_ENCODE(filepath);
147}
#define GHOST_ASSERT(x, info)
GHOST_TUserSpecialDirTypes
@ GHOST_kUserSpecialDirDesktop
@ GHOST_kUserSpecialDirMusic
@ GHOST_kUserSpecialDirPictures
@ GHOST_kUserSpecialDirVideos
@ GHOST_kUserSpecialDirDownloads
@ GHOST_kUserSpecialDirCaches
@ GHOST_kUserSpecialDirDocuments
void addToSystemRecentFiles(const char *filepath) const
const char * getSystemDir(int version, const char *versionstr) const
const char * getBinaryDir() const
const char * getUserSpecialDir(GHOST_TUserSpecialDirTypes type) const
const char * getUserDir(int version, const char *versionstr) const
int conv_utf_16_to_8(const wchar_t *in16, char *out8, size_t size8)
Definition utfconv.cc:116
#define UTF16_ENCODE(in8str)
Definition utfconv.hh:80
#define UTF16_UN_ENCODE(in8str)
Definition utfconv.hh:84