OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/importer/firefox_importer_utils.h" | 5 #include "chrome/browser/importer/firefox_importer_utils.h" |
6 | 6 |
7 #include <shlobj.h> | 7 #include <shlobj.h> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/string16.h" |
10 #include "base/win/registry.h" | 11 #include "base/win/registry.h" |
11 | 12 |
12 // NOTE: Keep these in order since we need test all those paths according | 13 // NOTE: Keep these in order since we need test all those paths according |
13 // to priority. For example. One machine has multiple users. One non-admin | 14 // to priority. For example. One machine has multiple users. One non-admin |
14 // user installs Firefox 2, which causes there is a Firefox2 entry under HKCU. | 15 // user installs Firefox 2, which causes there is a Firefox2 entry under HKCU. |
15 // One admin user installs Firefox 3, which causes there is a Firefox 3 entry | 16 // One admin user installs Firefox 3, which causes there is a Firefox 3 entry |
16 // under HKLM. So when the non-admin user log in, we should deal with Firefox 2 | 17 // under HKLM. So when the non-admin user log in, we should deal with Firefox 2 |
17 // related data instead of Firefox 3. | 18 // related data instead of Firefox 3. |
18 static const HKEY kFireFoxRegistryPaths[] = { | 19 static const HKEY kFireFoxRegistryPaths[] = { |
19 HKEY_CURRENT_USER, | 20 HKEY_CURRENT_USER, |
(...skipping 15 matching lines...) Expand all Loading... |
35 &ver_buffer_length, NULL); | 36 &ver_buffer_length, NULL); |
36 if (result != ERROR_SUCCESS) | 37 if (result != ERROR_SUCCESS) |
37 continue; | 38 continue; |
38 highest_version = std::max(highest_version, _wtoi(ver_buffer)); | 39 highest_version = std::max(highest_version, _wtoi(ver_buffer)); |
39 } | 40 } |
40 return highest_version; | 41 return highest_version; |
41 } | 42 } |
42 | 43 |
43 FilePath GetFirefoxInstallPathFromRegistry() { | 44 FilePath GetFirefoxInstallPathFromRegistry() { |
44 // Detects the path that Firefox is installed in. | 45 // Detects the path that Firefox is installed in. |
45 std::wstring registry_path = L"Software\\Mozilla\\Mozilla Firefox"; | 46 string16 registry_path = L"Software\\Mozilla\\Mozilla Firefox"; |
46 wchar_t buffer[MAX_PATH]; | 47 wchar_t buffer[MAX_PATH]; |
47 DWORD buffer_length = sizeof(buffer); | 48 DWORD buffer_length = sizeof(buffer); |
48 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, registry_path.c_str(), | 49 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, registry_path.c_str(), |
49 KEY_READ); | 50 KEY_READ); |
50 LONG result = reg_key.ReadValue(L"CurrentVersion", buffer, | 51 LONG result = reg_key.ReadValue(L"CurrentVersion", buffer, |
51 &buffer_length, NULL); | 52 &buffer_length, NULL); |
52 if (result != ERROR_SUCCESS) | 53 if (result != ERROR_SUCCESS) |
53 return FilePath(); | 54 return FilePath(); |
54 | 55 |
55 registry_path += L"\\" + std::wstring(buffer) + L"\\Main"; | 56 registry_path += L"\\" + string16(buffer) + L"\\Main"; |
56 buffer_length = sizeof(buffer); | 57 buffer_length = sizeof(buffer); |
57 base::win::RegKey reg_key_directory(HKEY_LOCAL_MACHINE, | 58 base::win::RegKey reg_key_directory(HKEY_LOCAL_MACHINE, |
58 registry_path.c_str(), KEY_READ); | 59 registry_path.c_str(), KEY_READ); |
59 result = reg_key_directory.ReadValue(L"Install Directory", buffer, | 60 result = reg_key_directory.ReadValue(L"Install Directory", buffer, |
60 &buffer_length, NULL); | 61 &buffer_length, NULL); |
61 | 62 |
62 return (result != ERROR_SUCCESS) ? FilePath() : FilePath(buffer); | 63 return (result != ERROR_SUCCESS) ? FilePath() : FilePath(buffer); |
63 } | 64 } |
64 | 65 |
65 FilePath GetProfilesINI() { | 66 FilePath GetProfilesINI() { |
66 FilePath ini_file; | 67 FilePath ini_file; |
67 // The default location of the profile folder containing user data is | 68 // The default location of the profile folder containing user data is |
68 // under the "Application Data" folder in Windows XP. | 69 // under the "Application Data" folder in Windows XP. |
69 wchar_t buffer[MAX_PATH] = {0}; | 70 wchar_t buffer[MAX_PATH] = {0}; |
70 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, | 71 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, |
71 SHGFP_TYPE_CURRENT, buffer))) { | 72 SHGFP_TYPE_CURRENT, buffer))) { |
72 ini_file = FilePath(buffer).Append(L"Mozilla\\Firefox\\profiles.ini"); | 73 ini_file = FilePath(buffer).Append(L"Mozilla\\Firefox\\profiles.ini"); |
73 } | 74 } |
74 if (file_util::PathExists(ini_file)) | 75 if (file_util::PathExists(ini_file)) |
75 return ini_file; | 76 return ini_file; |
76 | 77 |
77 return FilePath(); | 78 return FilePath(); |
78 } | 79 } |
OLD | NEW |