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. |
erikkay@google.com | 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 | |
deanm@google.com | 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 | 8dcf6bc | 2017-12-07 17:46:04 | [diff] [blame] | 9 | #include<KnownFolders.h> |
erikkay@google.com | 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" |
brettw@chromium.org | 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" |
erikkay@google.com | 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" |
benwells@chromium.org | b2721b0 | 2012-08-30 09:16:55 | [diff] [blame] | 19 | #include"base/win/scoped_co_mem.h" |
brettw@chromium.org | 935aa54 | 2010-10-15 01:59:15 | [diff] [blame] | 20 | #include"base/win/windows_version.h" |
erikkay@google.com | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 21 | |
brettw@chromium.org | 631a547 | 2013-02-18 06:14:59 | [diff] [blame] | 22 | using base::FilePath; |
| 23 | |
erikkay@google.com | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 24 | namespace base{ |
| 25 | |
evanm@google.com | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 26 | boolPathProviderWin(int key,FilePath* result){ |
erikkay@google.com | 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]; |
erikkay@google.com | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 33 | system_buffer[0]=0; |
| 34 | |
evanm@google.com | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 35 | FilePath cur; |
erikkay@google.com | 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 | returnfalse; |
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 40 | } |
evanm@google.com | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 41 | cur=FilePath(system_buffer); |
erikkay@google.com | 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 | returnfalse; |
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 48 | } |
evanm@google.com | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 49 | cur=FilePath(system_buffer); |
erikkay@google.com | 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); |
evanm@google.com | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 54 | cur=FilePath(system_buffer); |
erikkay@google.com | 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); |
evanm@google.com | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 58 | cur=FilePath(system_buffer); |
erikkay@google.com | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 59 | break; |
abodenha@chromium.org | 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){ |
abodenha@chromium.org | 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))){ |
abodenha@chromium.org | 9759ffc | 2011-04-25 18:03:12 | [diff] [blame] | 64 | returnfalse; |
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 65 | } |
abodenha@chromium.org | 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]]; |
erikkay@google.com | 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))){ |
erikkay@google.com | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 74 | returnfalse; |
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 75 | } |
evanm@google.com | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 76 | cur=FilePath(system_buffer); |
erikkay@google.com | 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 | returnfalse; |
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 | returnfalse; |
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; |
erikkay@google.com | 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))){ |
erikkay@google.com | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 105 | returnfalse; |
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 106 | } |
evanm@google.com | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 107 | cur=FilePath(system_buffer); |
erikkay@google.com | 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))){ |
erikkay@google.com | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 112 | returnfalse; |
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 113 | } |
evanm@google.com | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 114 | cur=FilePath(system_buffer); |
erikkay@google.com | 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))){ |
erikkay@google.com | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 119 | returnfalse; |
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 120 | } |
evanm@google.com | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 121 | cur=FilePath(system_buffer); |
erikkay@google.com | 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 | returnfalse; |
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 | returnfalse; |
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: |
erikkay@google.com | 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))){ |
erikkay@google.com | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 140 | returnfalse; |
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 141 | } |
evanm@google.com | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 142 | cur=FilePath(system_buffer); |
erikkay@google.com | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 143 | break; |
alexeypa@chromium.org | 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))){ |
alexeypa@chromium.org | bf3e52c3 | 2012-04-04 05:18:47 | [diff] [blame] | 147 | returnfalse; |
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 148 | } |
alexeypa@chromium.org | bf3e52c3 | 2012-04-04 05:18:47 | [diff] [blame] | 149 | cur=FilePath(system_buffer); |
| 150 | break; |
erikkay@google.com | 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))){ |
erikkay@google.com | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 154 | returnfalse; |
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 155 | } |
evanm@google.com | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 156 | cur=FilePath(system_buffer); |
erikkay@google.com | 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:{ |
tkent@chromium.org | 14a25e50 | 2010-06-15 06:53:52 | [diff] [blame] | 159 | FilePath executableDir; |
erikkay@google.com | 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 |
tkent@chromium.org | 14a25e50 | 2010-06-15 06:53:52 | [diff] [blame] | 162 | PathService::Get(base::DIR_EXE,&executableDir); |
| 163 | cur= executableDir.DirName().DirName(); |
erikkay@google.com | 37088fef | 2008-08-15 17:32:10 | [diff] [blame] | 164 | break; |
tkent@chromium.org | 14a25e50 | 2010-06-15 06:53:52 | [diff] [blame] | 165 | } |
benwells@chromium.org | b2721b0 | 2012-08-30 09:16:55 | [diff] [blame] | 166 | case base::DIR_APP_SHORTCUTS:{ |
benwells@chromium.org | 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))){ |
benwells@chromium.org | b2721b0 | 2012-08-30 09:16:55 | [diff] [blame] | 170 | returnfalse; |
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 171 | } |
benwells@chromium.org | 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()); |
benwells@chromium.org | b2721b0 | 2012-08-30 09:16:55 | [diff] [blame] | 174 | break; |
| 175 | } |
gab@chromium.org | 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))){ |
gab@chromium.org | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 179 | returnfalse; |
| 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))){ |
gab@chromium.org | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 186 | returnfalse; |
| 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)){ |
gab@chromium.org | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 192 | returnfalse; |
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 193 | } |
gab@chromium.org | 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")); |
gab@chromium.org | 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)){ |
gab@chromium.org | e5f9d82 | 2012-11-06 22:27:01 | [diff] [blame] | 206 | returnfalse; |
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 | returnfalse; |
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")); |
gab@chromium.org | e5f9d82 | 2012-11-06 22:27:01 | [diff] [blame] | 218 | break; |
scottmg@chromium.org | 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))){ |
scottmg@chromium.org | 3f18e8d | 2014-03-26 01:41:04 | [diff] [blame] | 222 | returnfalse; |
| 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 | returnfalse; |
| 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 | returnfalse; |
| 248 | } |
| 249 | |
| 250 | cur=FilePath(path_buf.get()); |
| 251 | break; |
| 252 | } |
erikkay@google.com | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 253 | default: |
| 254 | returnfalse; |
| 255 | } |
| 256 | |
evanm@google.com | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 257 | *result= cur; |
erikkay@google.com | ac510e1 | 2008-08-05 19:46:31 | [diff] [blame] | 258 | returntrue; |
| 259 | } |
| 260 | |
| 261 | }// namespace base |