ipc/chromium/src/base/base_paths_win.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/base/base_paths_win.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,118 @@
     1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#include "base/base_paths_win.h"
     1.9 +
    1.10 +#include <windows.h>
    1.11 +#include <shlobj.h>
    1.12 +
    1.13 +#include "base/file_path.h"
    1.14 +#include "base/file_util.h"
    1.15 +#include "base/path_service.h"
    1.16 +#include "base/win_util.h"
    1.17 +
    1.18 +// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
    1.19 +extern "C" IMAGE_DOS_HEADER __ImageBase;
    1.20 +
    1.21 +namespace base {
    1.22 +
    1.23 +bool PathProviderWin(int key, FilePath* result) {
    1.24 +
    1.25 +  // We need to go compute the value. It would be nice to support paths with
    1.26 +  // names longer than MAX_PATH, but the system functions don't seem to be
    1.27 +  // designed for it either, with the exception of GetTempPath (but other
    1.28 +  // things will surely break if the temp path is too long, so we don't bother
    1.29 +  // handling it.
    1.30 +  wchar_t system_buffer[MAX_PATH];
    1.31 +  system_buffer[0] = 0;
    1.32 +
    1.33 +  FilePath cur;
    1.34 +  std::wstring wstring_path;
    1.35 +  switch (key) {
    1.36 +    case base::FILE_EXE:
    1.37 +      GetModuleFileName(NULL, system_buffer, MAX_PATH);
    1.38 +      cur = FilePath(system_buffer);
    1.39 +      break;
    1.40 +    case base::FILE_MODULE: {
    1.41 +      // the resource containing module is assumed to be the one that
    1.42 +      // this code lives in, whether that's a dll or exe
    1.43 +      HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase);
    1.44 +      GetModuleFileName(this_module, system_buffer, MAX_PATH);
    1.45 +      cur = FilePath(system_buffer);
    1.46 +      break;
    1.47 +    }
    1.48 +    case base::DIR_WINDOWS:
    1.49 +      GetWindowsDirectory(system_buffer, MAX_PATH);
    1.50 +      cur = FilePath(system_buffer);
    1.51 +      break;
    1.52 +    case base::DIR_SYSTEM:
    1.53 +      GetSystemDirectory(system_buffer, MAX_PATH);
    1.54 +      cur = FilePath(system_buffer);
    1.55 +      break;
    1.56 +    case base::DIR_PROGRAM_FILES:
    1.57 +      if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL,
    1.58 +                                 SHGFP_TYPE_CURRENT, system_buffer)))
    1.59 +        return false;
    1.60 +      cur = FilePath(system_buffer);
    1.61 +      break;
    1.62 +    case base::DIR_IE_INTERNET_CACHE:
    1.63 +      if (FAILED(SHGetFolderPath(NULL, CSIDL_INTERNET_CACHE, NULL,
    1.64 +                                 SHGFP_TYPE_CURRENT, system_buffer)))
    1.65 +        return false;
    1.66 +      cur = FilePath(system_buffer);
    1.67 +      break;
    1.68 +    case base::DIR_COMMON_START_MENU:
    1.69 +      if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_PROGRAMS, NULL,
    1.70 +                                 SHGFP_TYPE_CURRENT, system_buffer)))
    1.71 +        return false;
    1.72 +      cur = FilePath(system_buffer);
    1.73 +      break;
    1.74 +    case base::DIR_START_MENU:
    1.75 +      if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAMS, NULL,
    1.76 +                                 SHGFP_TYPE_CURRENT, system_buffer)))
    1.77 +        return false;
    1.78 +      cur = FilePath(system_buffer);
    1.79 +      break;
    1.80 +    case base::DIR_APP_DATA:
    1.81 +      if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT,
    1.82 +                                 system_buffer)))
    1.83 +        return false;
    1.84 +      cur = FilePath(system_buffer);
    1.85 +      break;
    1.86 +    case base::DIR_LOCAL_APP_DATA_LOW:
    1.87 +      if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) {
    1.88 +        return false;
    1.89 +      }
    1.90 +      // TODO(nsylvain): We should use SHGetKnownFolderPath instead. Bug 1281128
    1.91 +      if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT,
    1.92 +                                 system_buffer)))
    1.93 +        return false;
    1.94 +      wstring_path = system_buffer;
    1.95 +      file_util::UpOneDirectory(&wstring_path);
    1.96 +      file_util::AppendToPath(&wstring_path, L"LocalLow");
    1.97 +      cur = FilePath(wstring_path);
    1.98 +      break;
    1.99 +    case base::DIR_LOCAL_APP_DATA:
   1.100 +      if (FAILED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL,
   1.101 +                                 SHGFP_TYPE_CURRENT, system_buffer)))
   1.102 +        return false;
   1.103 +      cur = FilePath(system_buffer);
   1.104 +      break;
   1.105 +    case base::DIR_SOURCE_ROOT:
   1.106 +      // On Windows, unit tests execute two levels deep from the source root.
   1.107 +      // For example:  chrome/{Debug|Release}/ui_tests.exe
   1.108 +      PathService::Get(base::DIR_EXE, &wstring_path);
   1.109 +      file_util::UpOneDirectory(&wstring_path);
   1.110 +      file_util::UpOneDirectory(&wstring_path);
   1.111 +      cur = FilePath(wstring_path);
   1.112 +      break;
   1.113 +    default:
   1.114 +      return false;
   1.115 +  }
   1.116 +
   1.117 +  *result = cur;
   1.118 +  return true;
   1.119 +}
   1.120 +
   1.121 +}  // namespace base

mercurial