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 <windows.h> // NOLINT | 5 #include <windows.h> // NOLINT |
6 #include <fcntl.h> // for _O_* constants | 6 #include <fcntl.h> // for _O_* constants |
7 #include <fdi.h> | 7 #include <fdi.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 | 10 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 } else { | 78 } else { |
79 access = GENERIC_READ; | 79 access = GENERIC_READ; |
80 } | 80 } |
81 | 81 |
82 if (oflag & _O_CREAT) { | 82 if (oflag & _O_CREAT) { |
83 disposition = CREATE_ALWAYS; | 83 disposition = CREATE_ALWAYS; |
84 } else { | 84 } else { |
85 disposition = OPEN_EXISTING; | 85 disposition = OPEN_EXISTING; |
86 } | 86 } |
87 | 87 |
88 scoped_ptr<wchar_t> path(Utf8ToWide(pszFile)); | 88 std::unique_ptr<wchar_t> path(Utf8ToWide(pszFile)); |
Lei Zhang
2016/04/19 01:35:42
Weren't we going to leave this alone?
dcheng
2016/04/19 03:51:33
Done.
| |
89 HANDLE file = CreateFileW(path, access, FILE_SHARE_READ, NULL, disposition, | 89 HANDLE file = CreateFileW(path, access, FILE_SHARE_READ, NULL, disposition, |
90 FILE_ATTRIBUTE_NORMAL, NULL); | 90 FILE_ATTRIBUTE_NORMAL, NULL); |
91 return reinterpret_cast<INT_PTR>(file); | 91 return reinterpret_cast<INT_PTR>(file); |
92 } | 92 } |
93 | 93 |
94 FNREAD(Read) { | 94 FNREAD(Read) { |
95 DWORD read = 0; | 95 DWORD read = 0; |
96 if (!::ReadFile(reinterpret_cast<HANDLE>(hf), pv, cb, &read, NULL)) | 96 if (!::ReadFile(reinterpret_cast<HANDLE>(hf), pv, cb, &read, NULL)) |
97 read = static_cast<DWORD>(-1L); | 97 read = static_cast<DWORD>(-1L); |
98 return read; | 98 return read; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 // Start by splitting up the source path and convert to utf8 since the | 229 // Start by splitting up the source path and convert to utf8 since the |
230 // cabinet API doesn't support wide strings. | 230 // cabinet API doesn't support wide strings. |
231 const wchar_t* source_name = source + lstrlenW(source); | 231 const wchar_t* source_name = source + lstrlenW(source); |
232 while (source_name > source && *source_name != L'\\') | 232 while (source_name > source && *source_name != L'\\') |
233 --source_name; | 233 --source_name; |
234 if (source_name == source) | 234 if (source_name == source) |
235 return false; | 235 return false; |
236 | 236 |
237 // Convert the name to utf8. | 237 // Convert the name to utf8. |
238 source_name++; | 238 source_name++; |
239 scoped_ptr<char> source_name_utf8(WideToUtf8(source_name, -1)); | 239 std::unique_ptr<char> source_name_utf8(WideToUtf8(source_name, -1)); |
240 // The directory part is assumed to have a trailing backslash. | 240 // The directory part is assumed to have a trailing backslash. |
241 scoped_ptr<char> source_path_utf8(WideToUtf8(source, source_name - source)); | 241 std::unique_ptr<char> source_path_utf8( |
242 WideToUtf8(source, source_name - source)); | |
242 | 243 |
243 scoped_ptr<char> dest_utf8(WideToUtf8(destination, -1)); | 244 std::unique_ptr<char> dest_utf8(WideToUtf8(destination, -1)); |
244 if (!dest_utf8 || !source_name_utf8 || !source_path_utf8) | 245 if (!dest_utf8 || !source_name_utf8 || !source_path_utf8) |
245 return false; | 246 return false; |
246 | 247 |
247 bool success = false; | 248 bool success = false; |
248 | 249 |
249 ERF erf = {0}; | 250 ERF erf = {0}; |
250 HFDI fdi = g_FDICreate(&Alloc, &Free, &Open, &Read, &Write, &Close, &Seek, | 251 HFDI fdi = g_FDICreate(&Alloc, &Free, &Open, &Read, &Write, &Close, &Seek, |
251 cpuUNKNOWN, &erf); | 252 cpuUNKNOWN, &erf); |
252 if (fdi) { | 253 if (fdi) { |
253 if (g_FDICopy(fdi, source_name_utf8, source_path_utf8, 0, | 254 if (g_FDICopy(fdi, source_name_utf8, source_path_utf8, 0, |
254 &Notify, NULL, const_cast<wchar_t*>(destination))) { | 255 &Notify, NULL, const_cast<wchar_t*>(destination))) { |
255 success = true; | 256 success = true; |
256 } | 257 } |
257 g_FDIDestroy(fdi); | 258 g_FDIDestroy(fdi); |
258 } | 259 } |
259 | 260 |
260 return success; | 261 return success; |
261 } | 262 } |
262 | 263 |
263 } // namespace mini_installer | 264 } // namespace mini_installer |
OLD | NEW |