ipc/chromium/src/base/base_paths_win.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #include "base/base_paths_win.h"
michael@0 6
michael@0 7 #include <windows.h>
michael@0 8 #include <shlobj.h>
michael@0 9
michael@0 10 #include "base/file_path.h"
michael@0 11 #include "base/file_util.h"
michael@0 12 #include "base/path_service.h"
michael@0 13 #include "base/win_util.h"
michael@0 14
michael@0 15 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
michael@0 16 extern "C" IMAGE_DOS_HEADER __ImageBase;
michael@0 17
michael@0 18 namespace base {
michael@0 19
michael@0 20 bool PathProviderWin(int key, FilePath* result) {
michael@0 21
michael@0 22 // We need to go compute the value. It would be nice to support paths with
michael@0 23 // names longer than MAX_PATH, but the system functions don't seem to be
michael@0 24 // designed for it either, with the exception of GetTempPath (but other
michael@0 25 // things will surely break if the temp path is too long, so we don't bother
michael@0 26 // handling it.
michael@0 27 wchar_t system_buffer[MAX_PATH];
michael@0 28 system_buffer[0] = 0;
michael@0 29
michael@0 30 FilePath cur;
michael@0 31 std::wstring wstring_path;
michael@0 32 switch (key) {
michael@0 33 case base::FILE_EXE:
michael@0 34 GetModuleFileName(NULL, system_buffer, MAX_PATH);
michael@0 35 cur = FilePath(system_buffer);
michael@0 36 break;
michael@0 37 case base::FILE_MODULE: {
michael@0 38 // the resource containing module is assumed to be the one that
michael@0 39 // this code lives in, whether that's a dll or exe
michael@0 40 HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase);
michael@0 41 GetModuleFileName(this_module, system_buffer, MAX_PATH);
michael@0 42 cur = FilePath(system_buffer);
michael@0 43 break;
michael@0 44 }
michael@0 45 case base::DIR_WINDOWS:
michael@0 46 GetWindowsDirectory(system_buffer, MAX_PATH);
michael@0 47 cur = FilePath(system_buffer);
michael@0 48 break;
michael@0 49 case base::DIR_SYSTEM:
michael@0 50 GetSystemDirectory(system_buffer, MAX_PATH);
michael@0 51 cur = FilePath(system_buffer);
michael@0 52 break;
michael@0 53 case base::DIR_PROGRAM_FILES:
michael@0 54 if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL,
michael@0 55 SHGFP_TYPE_CURRENT, system_buffer)))
michael@0 56 return false;
michael@0 57 cur = FilePath(system_buffer);
michael@0 58 break;
michael@0 59 case base::DIR_IE_INTERNET_CACHE:
michael@0 60 if (FAILED(SHGetFolderPath(NULL, CSIDL_INTERNET_CACHE, NULL,
michael@0 61 SHGFP_TYPE_CURRENT, system_buffer)))
michael@0 62 return false;
michael@0 63 cur = FilePath(system_buffer);
michael@0 64 break;
michael@0 65 case base::DIR_COMMON_START_MENU:
michael@0 66 if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_PROGRAMS, NULL,
michael@0 67 SHGFP_TYPE_CURRENT, system_buffer)))
michael@0 68 return false;
michael@0 69 cur = FilePath(system_buffer);
michael@0 70 break;
michael@0 71 case base::DIR_START_MENU:
michael@0 72 if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAMS, NULL,
michael@0 73 SHGFP_TYPE_CURRENT, system_buffer)))
michael@0 74 return false;
michael@0 75 cur = FilePath(system_buffer);
michael@0 76 break;
michael@0 77 case base::DIR_APP_DATA:
michael@0 78 if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT,
michael@0 79 system_buffer)))
michael@0 80 return false;
michael@0 81 cur = FilePath(system_buffer);
michael@0 82 break;
michael@0 83 case base::DIR_LOCAL_APP_DATA_LOW:
michael@0 84 if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) {
michael@0 85 return false;
michael@0 86 }
michael@0 87 // TODO(nsylvain): We should use SHGetKnownFolderPath instead. Bug 1281128
michael@0 88 if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT,
michael@0 89 system_buffer)))
michael@0 90 return false;
michael@0 91 wstring_path = system_buffer;
michael@0 92 file_util::UpOneDirectory(&wstring_path);
michael@0 93 file_util::AppendToPath(&wstring_path, L"LocalLow");
michael@0 94 cur = FilePath(wstring_path);
michael@0 95 break;
michael@0 96 case base::DIR_LOCAL_APP_DATA:
michael@0 97 if (FAILED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL,
michael@0 98 SHGFP_TYPE_CURRENT, system_buffer)))
michael@0 99 return false;
michael@0 100 cur = FilePath(system_buffer);
michael@0 101 break;
michael@0 102 case base::DIR_SOURCE_ROOT:
michael@0 103 // On Windows, unit tests execute two levels deep from the source root.
michael@0 104 // For example: chrome/{Debug|Release}/ui_tests.exe
michael@0 105 PathService::Get(base::DIR_EXE, &wstring_path);
michael@0 106 file_util::UpOneDirectory(&wstring_path);
michael@0 107 file_util::UpOneDirectory(&wstring_path);
michael@0 108 cur = FilePath(wstring_path);
michael@0 109 break;
michael@0 110 default:
michael@0 111 return false;
michael@0 112 }
michael@0 113
michael@0 114 *result = cur;
michael@0 115 return true;
michael@0 116 }
michael@0 117
michael@0 118 } // namespace base

mercurial