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.

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

mercurial