| Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
| license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 4 | |
| Takuto Ikuta | c8d6b16f | 2024-04-15 16:59:19 | [diff] [blame] | 5 | #include "base/base_paths.h" |
| 6 | |
| [email protected] | 5d99d63b | 2008-08-19 09:26:57 | [diff] [blame] | 7 | #include <windows.h> |
| Bruce Dawson | a1e1cfcb | 2022-11-22 20:04:35 | [diff] [blame] | 8 | |
| Bruce Dawson | 8dcf6bc6 | 2017-12-07 17:46:04 | [diff] [blame] | 9 | #include <KnownFolders.h> |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 10 | #include <shlobj.h> |
| 11 | |
| wfh | 16d2f12 | 2015-03-13 14:34:47 | [diff] [blame] | 12 | #include "base/environment.h" |
| [email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 13 | #include "base/files/file_path.h" |
| Greg Thompson | 0a8c33ed | 2024-08-20 17:46:41 | [diff] [blame] | 14 | #include "base/files/file_util.h" |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 15 | #include "base/path_service.h" |
| jdoerrie | 5c4dc4e | 2019-02-01 18:02:33 | [diff] [blame] | 16 | #include "base/strings/string_util.h" |
| wfh | 16d2f12 | 2015-03-13 14:34:47 | [diff] [blame] | 17 | #include "base/strings/utf_string_conversions.h" |
| thakis | d62f5447 | 2016-04-04 02:21:10 | [diff] [blame] | 18 | #include "base/win/current_module.h" |
| [email protected] | b2721b0 | 2012-08-30 09:16:55 | [diff] [blame] | 19 | #include "base/win/scoped_co_mem.h" |
| [email protected] | 935aa54 | 2010-10-15 01:59:15 | [diff] [blame] | 20 | #include "base/win/windows_version.h" |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 21 | |
| [email protected] | 631a547 | 2013-02-18 06:14:59 | [diff] [blame] | 22 | using base::FilePath; |
| 23 | |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 24 | namespace base { |
| 25 | |
| [email protected] | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 26 | bool PathProviderWin(int key, FilePath* result) { |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 27 | // We need to go compute the value. It would be nice to support paths with |
| 28 | // names longer than MAX_PATH, but the system functions don't seem to be |
| 29 | // designed for it either, with the exception of GetTempPath (but other |
| 30 | // things will surely break if the temp path is too long, so we don't bother |
| 31 | // handling it. |
| Jan Wilken Dörrie | b630aca | 2019-12-04 10:59:11 | [diff] [blame] | 32 | wchar_t system_buffer[MAX_PATH]; |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 33 | system_buffer[0] = 0; |
| 34 | |
| [email protected] | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 35 | FilePath cur; |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 36 | switch (key) { |
| 37 | case base::FILE_EXE: |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 38 | if (GetModuleFileName(NULL, system_buffer, MAX_PATH) == 0) { |
| aranovskii | 8dcedce | 2015-06-24 09:03:51 | [diff] [blame] | 39 | return false; |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 40 | } |
| [email protected] | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 41 | cur = FilePath(system_buffer); |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 42 | break; |
| 43 | case base::FILE_MODULE: { |
| 44 | // the resource containing module is assumed to be the one that |
| 45 | // this code lives in, whether that's a dll or exe |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 46 | if (GetModuleFileName(CURRENT_MODULE(), system_buffer, MAX_PATH) == 0) { |
| aranovskii | 8dcedce | 2015-06-24 09:03:51 | [diff] [blame] | 47 | return false; |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 48 | } |
| [email protected] | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 49 | cur = FilePath(system_buffer); |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 50 | break; |
| 51 | } |
| 52 | case base::DIR_WINDOWS: |
| Jan Wilken Dörrie | b630aca | 2019-12-04 10:59:11 | [diff] [blame] | 53 | GetWindowsDirectory(system_buffer, MAX_PATH); |
| [email protected] | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 54 | cur = FilePath(system_buffer); |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 55 | break; |
| 56 | case base::DIR_SYSTEM: |
| Jan Wilken Dörrie | b630aca | 2019-12-04 10:59:11 | [diff] [blame] | 57 | GetSystemDirectory(system_buffer, MAX_PATH); |
| [email protected] | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 58 | cur = FilePath(system_buffer); |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 59 | break; |
| [email protected] | 9759ffc | 2011-04-25 18:03:12 | [diff] [blame] | 60 | case base::DIR_PROGRAM_FILESX86: |
| Lei Zhang | 10d9e156 | 2019-03-14 18:46:02 | [diff] [blame] | 61 | if (win::OSInfo::GetArchitecture() != win::OSInfo::X86_ARCHITECTURE) { |
| [email protected] | 9759ffc | 2011-04-25 18:03:12 | [diff] [blame] | 62 | if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILESX86, NULL, |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 63 | SHGFP_TYPE_CURRENT, system_buffer))) { |
| [email protected] | 9759ffc | 2011-04-25 18:03:12 | [diff] [blame] | 64 | return false; |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 65 | } |
| [email protected] | 9759ffc | 2011-04-25 18:03:12 | [diff] [blame] | 66 | cur = FilePath(system_buffer); |
| 67 | break; |
| 68 | } |
| 69 | // Fall through to base::DIR_PROGRAM_FILES if we're on an X86 machine. |
| Roland Bock | f534f6b0 | 2022-01-04 16:09:18 | [diff] [blame] | 70 | [[fallthrough]]; |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 71 | case base::DIR_PROGRAM_FILES: |
| 72 | if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 73 | SHGFP_TYPE_CURRENT, system_buffer))) { |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 74 | return false; |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 75 | } |
| [email protected] | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 76 | cur = FilePath(system_buffer); |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 77 | break; |
| wfh | 16d2f12 | 2015-03-13 14:34:47 | [diff] [blame] | 78 | case base::DIR_PROGRAM_FILES6432: |
| 79 | #if !defined(_WIN64) |
| S. Ganesh | a4c49ce | 2023-11-15 02:04:25 | [diff] [blame] | 80 | if (base::win::OSInfo::GetInstance()->IsWowX86OnAMD64() || |
| 81 | base::win::OSInfo::GetInstance()->IsWowX86OnARM64()) { |
| dcheng | 093de9b | 2016-04-04 21:25:51 | [diff] [blame] | 82 | std::unique_ptr<base::Environment> env(base::Environment::Create()); |
| wfh | 16d2f12 | 2015-03-13 14:34:47 | [diff] [blame] | 83 | // 32-bit process running in WOW64 sets ProgramW6432 environment |
| 84 | // variable. See |
| 85 | // https://msdn.microsoft.com/library/windows/desktop/aa384274.aspx. |
| Helmut Januschka | 726658b | 2025-03-21 22:44:57 | [diff] [blame] | 86 | std::optional<std::string> programfiles_w6432 = |
| 87 | env->GetVar("ProgramW6432"); |
| 88 | if (!programfiles_w6432.has_value()) { |
| wfh | 16d2f12 | 2015-03-13 14:34:47 | [diff] [blame] | 89 | return false; |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 90 | } |
| wfh | 16d2f12 | 2015-03-13 14:34:47 | [diff] [blame] | 91 | // GetVar returns UTF8 - convert back to Wide. |
| Helmut Januschka | 726658b | 2025-03-21 22:44:57 | [diff] [blame] | 92 | cur = FilePath(UTF8ToWide(programfiles_w6432.value())); |
| wfh | 16d2f12 | 2015-03-13 14:34:47 | [diff] [blame] | 93 | break; |
| 94 | } |
| 95 | #endif |
| 96 | if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 97 | SHGFP_TYPE_CURRENT, system_buffer))) { |
| wfh | 16d2f12 | 2015-03-13 14:34:47 | [diff] [blame] | 98 | return false; |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 99 | } |
| wfh | 16d2f12 | 2015-03-13 14:34:47 | [diff] [blame] | 100 | cur = FilePath(system_buffer); |
| 101 | break; |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 102 | case base::DIR_IE_INTERNET_CACHE: |
| 103 | if (FAILED(SHGetFolderPath(NULL, CSIDL_INTERNET_CACHE, NULL, |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 104 | SHGFP_TYPE_CURRENT, system_buffer))) { |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 105 | return false; |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 106 | } |
| [email protected] | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 107 | cur = FilePath(system_buffer); |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 108 | break; |
| 109 | case base::DIR_COMMON_START_MENU: |
| 110 | if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_PROGRAMS, NULL, |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 111 | SHGFP_TYPE_CURRENT, system_buffer))) { |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 112 | return false; |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 113 | } |
| [email protected] | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 114 | cur = FilePath(system_buffer); |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 115 | break; |
| 116 | case base::DIR_START_MENU: |
| jdoerrie | 5c4dc4e | 2019-02-01 18:02:33 | [diff] [blame] | 117 | if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAMS, NULL, SHGFP_TYPE_CURRENT, |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 118 | system_buffer))) { |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 119 | return false; |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 120 | } |
| [email protected] | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 121 | cur = FilePath(system_buffer); |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 122 | break; |
| Carlos Frias | 5ddded6 | 2020-05-27 23:38:18 | [diff] [blame] | 123 | case base::DIR_COMMON_STARTUP: |
| 124 | if (FAILED(SHGetFolderPath(nullptr, CSIDL_COMMON_STARTUP, nullptr, |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 125 | SHGFP_TYPE_CURRENT, system_buffer))) { |
| Carlos Frias | 5ddded6 | 2020-05-27 23:38:18 | [diff] [blame] | 126 | return false; |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 127 | } |
| Carlos Frias | 5ddded6 | 2020-05-27 23:38:18 | [diff] [blame] | 128 | cur = FilePath(system_buffer); |
| 129 | break; |
| 130 | case base::DIR_USER_STARTUP: |
| 131 | if (FAILED(SHGetFolderPath(nullptr, CSIDL_STARTUP, nullptr, |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 132 | SHGFP_TYPE_CURRENT, system_buffer))) { |
| Carlos Frias | 5ddded6 | 2020-05-27 23:38:18 | [diff] [blame] | 133 | return false; |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 134 | } |
| Carlos Frias | 5ddded6 | 2020-05-27 23:38:18 | [diff] [blame] | 135 | cur = FilePath(system_buffer); |
| 136 | break; |
| David Dorwin | 048cb9da | 2021-11-09 00:22:44 | [diff] [blame] | 137 | case base::DIR_ROAMING_APP_DATA: |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 138 | if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 139 | system_buffer))) { |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 140 | return false; |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 141 | } |
| [email protected] | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 142 | cur = FilePath(system_buffer); |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 143 | break; |
| [email protected] | bf3e52c3 | 2012-04-04 05:18:47 | [diff] [blame] | 144 | case base::DIR_COMMON_APP_DATA: |
| 145 | if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 146 | SHGFP_TYPE_CURRENT, system_buffer))) { |
| [email protected] | bf3e52c3 | 2012-04-04 05:18:47 | [diff] [blame] | 147 | return false; |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 148 | } |
| [email protected] | bf3e52c3 | 2012-04-04 05:18:47 | [diff] [blame] | 149 | cur = FilePath(system_buffer); |
| 150 | break; |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 151 | case base::DIR_LOCAL_APP_DATA: |
| 152 | if (FAILED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 153 | SHGFP_TYPE_CURRENT, system_buffer))) { |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 154 | return false; |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 155 | } |
| [email protected] | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 156 | cur = FilePath(system_buffer); |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 157 | break; |
| David Dorwin | c694f72 | 2021-10-29 22:46:59 | [diff] [blame] | 158 | case base::DIR_SRC_TEST_DATA_ROOT: { |
| [email protected] | 14a25e50 | 2010-06-15 06:53:52 | [diff] [blame] | 159 | FilePath executableDir; |
| [email protected] | 37088fef | 2008-08-15 17:32:10 | [diff] [blame] | 160 | // On Windows, unit tests execute two levels deep from the source root. |
| 161 | // For example: chrome/{Debug|Release}/ui_tests.exe |
| [email protected] | 14a25e50 | 2010-06-15 06:53:52 | [diff] [blame] | 162 | PathService::Get(base::DIR_EXE, &executableDir); |
| 163 | cur = executableDir.DirName().DirName(); |
| [email protected] | 37088fef | 2008-08-15 17:32:10 | [diff] [blame] | 164 | break; |
| [email protected] | 14a25e50 | 2010-06-15 06:53:52 | [diff] [blame] | 165 | } |
| [email protected] | b2721b0 | 2012-08-30 09:16:55 | [diff] [blame] | 166 | case base::DIR_APP_SHORTCUTS: { |
| [email protected] | b2721b0 | 2012-08-30 09:16:55 | [diff] [blame] | 167 | base::win::ScopedCoMem<wchar_t> path_buf; |
| 168 | if (FAILED(SHGetKnownFolderPath(FOLDERID_ApplicationShortcuts, 0, NULL, |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 169 | &path_buf))) { |
| [email protected] | b2721b0 | 2012-08-30 09:16:55 | [diff] [blame] | 170 | return false; |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 171 | } |
| [email protected] | b2721b0 | 2012-08-30 09:16:55 | [diff] [blame] | 172 | |
| Jan Wilken Dörrie | b630aca | 2019-12-04 10:59:11 | [diff] [blame] | 173 | cur = FilePath(path_buf.get()); |
| [email protected] | b2721b0 | 2012-08-30 09:16:55 | [diff] [blame] | 174 | break; |
| 175 | } |
| [email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 176 | case base::DIR_USER_DESKTOP: |
| 177 | if (FAILED(SHGetFolderPath(NULL, CSIDL_DESKTOPDIRECTORY, NULL, |
| Jan Wilken Dörrie | b630aca | 2019-12-04 10:59:11 | [diff] [blame] | 178 | SHGFP_TYPE_CURRENT, system_buffer))) { |
| [email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 179 | return false; |
| 180 | } |
| 181 | cur = FilePath(system_buffer); |
| 182 | break; |
| 183 | case base::DIR_COMMON_DESKTOP: |
| 184 | if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_DESKTOPDIRECTORY, NULL, |
| Jan Wilken Dörrie | b630aca | 2019-12-04 10:59:11 | [diff] [blame] | 185 | SHGFP_TYPE_CURRENT, system_buffer))) { |
| [email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 186 | return false; |
| 187 | } |
| 188 | cur = FilePath(system_buffer); |
| 189 | break; |
| 190 | case base::DIR_USER_QUICK_LAUNCH: |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 191 | if (!PathService::Get(base::DIR_ROAMING_APP_DATA, &cur)) { |
| [email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 192 | return false; |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 193 | } |
| [email protected] | da4d4fb | 2014-08-08 18:17:53 | [diff] [blame] | 194 | // According to various sources, appending |
| 195 | // "Microsoft\Internet Explorer\Quick Launch" to %appdata% is the only |
| 196 | // reliable way to get the quick launch folder across all versions of |
| 197 | // Windows. |
| 198 | // http://stackoverflow.com/questions/76080/how-do-you-reliably-get-the-quick- |
| 199 | // http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept05/hey0901.mspx |
| pmonette | 565a880 | 2016-06-21 00:03:43 | [diff] [blame] | 200 | cur = cur.Append(FILE_PATH_LITERAL("Microsoft")) |
| 201 | .Append(FILE_PATH_LITERAL("Internet Explorer")) |
| 202 | .Append(FILE_PATH_LITERAL("Quick Launch")); |
| [email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 203 | break; |
| Greg Thompson | 62b01f8 | 2020-03-11 15:39:00 | [diff] [blame] | 204 | case base::DIR_TASKBAR_PINS: { |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 205 | if (!PathService::Get(base::DIR_USER_QUICK_LAUNCH, &cur)) { |
| [email protected] | e5f9d82 | 2012-11-06 22:27:01 | [diff] [blame] | 206 | return false; |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 207 | } |
| pmonette | 5057ca3b | 2016-07-04 16:48:40 | [diff] [blame] | 208 | cur = cur.Append(FILE_PATH_LITERAL("User Pinned")) |
| 209 | .Append(FILE_PATH_LITERAL("TaskBar")); |
| 210 | break; |
| Greg Thompson | 62b01f8 | 2020-03-11 15:39:00 | [diff] [blame] | 211 | } |
| pmonette | 5057ca3b | 2016-07-04 16:48:40 | [diff] [blame] | 212 | case base::DIR_IMPLICIT_APP_SHORTCUTS: |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 213 | if (!PathService::Get(base::DIR_USER_QUICK_LAUNCH, &cur)) { |
| pmonette | 5057ca3b | 2016-07-04 16:48:40 | [diff] [blame] | 214 | return false; |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 215 | } |
| pmonette | 5057ca3b | 2016-07-04 16:48:40 | [diff] [blame] | 216 | cur = cur.Append(FILE_PATH_LITERAL("User Pinned")) |
| 217 | .Append(FILE_PATH_LITERAL("ImplicitAppShortcuts")); |
| [email protected] | e5f9d82 | 2012-11-06 22:27:01 | [diff] [blame] | 218 | break; |
| [email protected] | 3f18e8d | 2014-03-26 01:41:04 | [diff] [blame] | 219 | case base::DIR_WINDOWS_FONTS: |
| jdoerrie | 5c4dc4e | 2019-02-01 18:02:33 | [diff] [blame] | 220 | if (FAILED(SHGetFolderPath(NULL, CSIDL_FONTS, NULL, SHGFP_TYPE_CURRENT, |
| Jan Wilken Dörrie | b630aca | 2019-12-04 10:59:11 | [diff] [blame] | 221 | system_buffer))) { |
| [email protected] | 3f18e8d | 2014-03-26 01:41:04 | [diff] [blame] | 222 | return false; |
| 223 | } |
| 224 | cur = FilePath(system_buffer); |
| 225 | break; |
| Greg Thompson | 0a8c33ed | 2024-08-20 17:46:41 | [diff] [blame] | 226 | case base::DIR_SYSTEM_TEMP: |
| 227 | // Try C:\Windows\SystemTemp, which was introduced sometime before Windows |
| 228 | // 10 build 19042. Do not use GetTempPath2, as it only appeared later and |
| 229 | // will only return the path for processes running as SYSTEM. |
| 230 | if (PathService::Get(DIR_WINDOWS, &cur)) { |
| 231 | cur = cur.Append(FILE_PATH_LITERAL("SystemTemp")); |
| 232 | if (PathIsWritable(cur)) { |
| 233 | break; |
| 234 | } |
| 235 | } |
| 236 | // Failing that, use C:\Program Files or C:\Program Files (x86) for older |
| 237 | // versions of Windows 10. |
| 238 | if (!PathService::Get(DIR_PROGRAM_FILES, &cur) || !PathIsWritable(cur)) { |
| 239 | return false; |
| 240 | } |
| 241 | break; |
| Foromo Daniel Soromou | a1e334d | 2025-03-06 23:35:36 | [diff] [blame] | 242 | case base::DIR_ONE_DRIVE: { |
| 243 | base::win::ScopedCoMem<wchar_t> path_buf; |
| 244 | // FOLDERID_OneDrive points on the user OneDrive folder. The default path |
| 245 | // is %USERPROFILE%\OneDrive. It is formerly known as FOLDERID_SkyDrive. |
| 246 | if (FAILED(SHGetKnownFolderPath(FOLDERID_OneDrive, 0, NULL, &path_buf))) { |
| 247 | return false; |
| 248 | } |
| 249 | |
| 250 | cur = FilePath(path_buf.get()); |
| 251 | break; |
| 252 | } |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 253 | default: |
| 254 | return false; |
| 255 | } |
| 256 | |
| [email protected] | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 257 | *result = cur; |
| [email protected] | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 258 | return true; |
| 259 | } |
| 260 | |
| 261 | } // namespace base |