OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/utility/importer/ie_importer_win.h" | 5 #include "chrome/utility/importer/ie_importer_win.h" |
6 | 6 |
7 #include <ole2.h> | 7 #include <ole2.h> |
8 #include <intshcut.h> | 8 #include <intshcut.h> |
9 #include <shlobj.h> | 9 #include <shlobj.h> |
10 #include <urlhist.h> | 10 #include <urlhist.h> |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 // recorded in the REG_BINARY value named "Order" of the corresponding key. | 153 // recorded in the REG_BINARY value named "Order" of the corresponding key. |
154 // The content of the "Order" value is a raw binary dump of an array of the | 154 // The content of the "Order" value is a raw binary dump of an array of the |
155 // following data structure | 155 // following data structure |
156 // struct { | 156 // struct { |
157 // uint32 size; // Note that ITEMIDLIST is variably-sized. | 157 // uint32 size; // Note that ITEMIDLIST is variably-sized. |
158 // uint32 sort_index; // 0 means this is the first item, 1 the second, ... | 158 // uint32 sort_index; // 0 means this is the first item, 1 the second, ... |
159 // ITEMIDLIST item_id; | 159 // ITEMIDLIST item_id; |
160 // }; | 160 // }; |
161 // where each item_id should correspond to a favorites link file (*.url) in | 161 // where each item_id should correspond to a favorites link file (*.url) in |
162 // the current folder. | 162 // the current folder. |
163 bool ParseFavoritesOrderBlob( | 163 // gcc, in its infinite wisdom, only allows WARN_UNUSED_RESULT for prototypes. |
164 const Importer* importer, | 164 // Clang, to be compatible with gcc, warns if WARN_UNUSED_RESULT is used in a |
165 const std::vector<uint8>& blob, | 165 // non-gcc compatible manner (-Wgcc-compat). So even though gcc isn't used to |
166 const base::FilePath& path, | 166 // build on Windows, declare some prototypes anyway to satisfy Clang's gcc |
167 std::map<base::FilePath, uint32>* sort_index) WARN_UNUSED_RESULT { | 167 // compatibility warnings. |
| 168 bool ParseFavoritesOrderBlob(const Importer* importer, |
| 169 const std::vector<uint8>& blob, |
| 170 const base::FilePath& path, |
| 171 std::map<base::FilePath, uint32>* sort_index) |
| 172 WARN_UNUSED_RESULT; |
| 173 bool ParseFavoritesOrderBlob(const Importer* importer, |
| 174 const std::vector<uint8>& blob, |
| 175 const base::FilePath& path, |
| 176 std::map<base::FilePath, uint32>* sort_index) { |
168 static const int kItemCountOffset = 16; | 177 static const int kItemCountOffset = 16; |
169 static const int kItemListStartOffset = 20; | 178 static const int kItemListStartOffset = 20; |
170 | 179 |
171 // Read the number of items. | 180 // Read the number of items. |
172 uint32 item_count = 0; | 181 uint32 item_count = 0; |
173 if (!BinaryRead(&item_count, kItemCountOffset, blob)) | 182 if (!BinaryRead(&item_count, kItemCountOffset, blob)) |
174 return false; | 183 return false; |
175 | 184 |
176 // Traverse over the items. | 185 // Traverse over the items. |
177 size_t base_offset = kItemListStartOffset; | 186 size_t base_offset = kItemListStartOffset; |
(...skipping 27 matching lines...) Expand all Loading... |
205 sort_index->insert(std::make_pair(item_relative_path, item_sort_index)); | 214 sort_index->insert(std::make_pair(item_relative_path, item_sort_index)); |
206 base_offset += item_size; | 215 base_offset += item_size; |
207 } | 216 } |
208 return true; | 217 return true; |
209 } | 218 } |
210 | 219 |
211 bool ParseFavoritesOrderRegistryTree( | 220 bool ParseFavoritesOrderRegistryTree( |
212 const Importer* importer, | 221 const Importer* importer, |
213 const base::win::RegKey& key, | 222 const base::win::RegKey& key, |
214 const base::FilePath& path, | 223 const base::FilePath& path, |
215 std::map<base::FilePath, uint32>* sort_index) WARN_UNUSED_RESULT { | 224 std::map<base::FilePath, uint32>* sort_index) WARN_UNUSED_RESULT; |
| 225 bool ParseFavoritesOrderRegistryTree( |
| 226 const Importer* importer, |
| 227 const base::win::RegKey& key, |
| 228 const base::FilePath& path, |
| 229 std::map<base::FilePath, uint32>* sort_index) { |
216 // Parse the order information of the current folder. | 230 // Parse the order information of the current folder. |
217 DWORD blob_length = 0; | 231 DWORD blob_length = 0; |
218 if (key.ReadValue(L"Order", NULL, &blob_length, NULL) == ERROR_SUCCESS) { | 232 if (key.ReadValue(L"Order", NULL, &blob_length, NULL) == ERROR_SUCCESS) { |
219 std::vector<uint8> blob(blob_length); | 233 std::vector<uint8> blob(blob_length); |
220 if (blob_length > 0 && | 234 if (blob_length > 0 && |
221 key.ReadValue(L"Order", reinterpret_cast<DWORD*>(&blob[0]), | 235 key.ReadValue(L"Order", reinterpret_cast<DWORD*>(&blob[0]), |
222 &blob_length, NULL) == ERROR_SUCCESS) { | 236 &blob_length, NULL) == ERROR_SUCCESS) { |
223 if (!ParseFavoritesOrderBlob(importer, blob, path, sort_index)) | 237 if (!ParseFavoritesOrderBlob(importer, blob, path, sort_index)) |
224 return false; | 238 return false; |
225 } | 239 } |
226 } | 240 } |
227 | 241 |
228 // Recursively parse subfolders. | 242 // Recursively parse subfolders. |
229 for (base::win::RegistryKeyIterator child(key.Handle(), L""); | 243 for (base::win::RegistryKeyIterator child(key.Handle(), L""); |
230 child.Valid() && !importer->cancelled(); | 244 child.Valid() && !importer->cancelled(); |
231 ++child) { | 245 ++child) { |
232 base::win::RegKey subkey(key.Handle(), child.Name(), KEY_READ); | 246 base::win::RegKey subkey(key.Handle(), child.Name(), KEY_READ); |
233 if (subkey.Valid()) { | 247 if (subkey.Valid()) { |
234 base::FilePath subpath(path.Append(child.Name())); | 248 base::FilePath subpath(path.Append(child.Name())); |
235 if (!ParseFavoritesOrderRegistryTree(importer, subkey, subpath, | 249 if (!ParseFavoritesOrderRegistryTree(importer, subkey, subpath, |
236 sort_index)) { | 250 sort_index)) { |
237 return false; | 251 return false; |
238 } | 252 } |
239 } | 253 } |
240 } | 254 } |
241 return true; | 255 return true; |
242 } | 256 } |
243 | 257 |
244 bool ParseFavoritesOrderInfo( | 258 bool ParseFavoritesOrderInfo(const Importer* importer, |
245 const Importer* importer, | 259 std::map<base::FilePath, uint32>* sort_index) |
246 std::map<base::FilePath, uint32>* sort_index) WARN_UNUSED_RESULT { | 260 WARN_UNUSED_RESULT; |
| 261 bool ParseFavoritesOrderInfo(const Importer* importer, |
| 262 std::map<base::FilePath, uint32>* sort_index) { |
247 base::string16 key_path(importer::GetIEFavoritesOrderKey()); | 263 base::string16 key_path(importer::GetIEFavoritesOrderKey()); |
248 base::win::RegKey key(HKEY_CURRENT_USER, key_path.c_str(), KEY_READ); | 264 base::win::RegKey key(HKEY_CURRENT_USER, key_path.c_str(), KEY_READ); |
249 if (!key.Valid()) | 265 if (!key.Valid()) |
250 return false; | 266 return false; |
251 return ParseFavoritesOrderRegistryTree(importer, key, base::FilePath(), | 267 return ParseFavoritesOrderRegistryTree(importer, key, base::FilePath(), |
252 sort_index); | 268 sort_index); |
253 } | 269 } |
254 | 270 |
255 // Reads the sort order from registry. If failed, we don't touch the list | 271 // Reads the sort order from registry. If failed, we don't touch the list |
256 // and use the default (alphabetical) order. | 272 // and use the default (alphabetical) order. |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 static int version = -1; | 901 static int version = -1; |
886 if (version < 0) { | 902 if (version < 0) { |
887 wchar_t buffer[128]; | 903 wchar_t buffer[128]; |
888 DWORD buffer_length = sizeof(buffer); | 904 DWORD buffer_length = sizeof(buffer); |
889 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); | 905 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); |
890 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); | 906 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); |
891 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); | 907 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); |
892 } | 908 } |
893 return version; | 909 return version; |
894 } | 910 } |
OLD | NEW |