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 "base/file_util.h" | 5 #include "base/file_util.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <psapi.h> | 8 #include <psapi.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #include <shlobj.h> | 10 #include <shlobj.h> |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 if (from_path.value().length() >= MAX_PATH || | 197 if (from_path.value().length() >= MAX_PATH || |
198 to_path.value().length() >= MAX_PATH) { | 198 to_path.value().length() >= MAX_PATH) { |
199 return false; | 199 return false; |
200 } | 200 } |
201 return (::CopyFile(from_path.value().c_str(), to_path.value().c_str(), | 201 return (::CopyFile(from_path.value().c_str(), to_path.value().c_str(), |
202 false) != 0); | 202 false) != 0); |
203 } | 203 } |
204 | 204 |
205 bool ShellCopy(const FilePath& from_path, const FilePath& to_path, | 205 bool ShellCopy(const FilePath& from_path, const FilePath& to_path, |
206 bool recursive) { | 206 bool recursive) { |
| 207 // WinXP SHFileOperation doesn't like trailing separators. |
| 208 FilePath stripped_from = from_path.StripTrailingSeparators(); |
| 209 FilePath stripped_to = to_path.StripTrailingSeparators(); |
| 210 |
207 base::ThreadRestrictions::AssertIOAllowed(); | 211 base::ThreadRestrictions::AssertIOAllowed(); |
208 | 212 |
209 // NOTE: I suspect we could support longer paths, but that would involve | 213 // NOTE: I suspect we could support longer paths, but that would involve |
210 // analyzing all our usage of files. | 214 // analyzing all our usage of files. |
211 if (from_path.value().length() >= MAX_PATH || | 215 if (stripped_from.value().length() >= MAX_PATH || |
212 to_path.value().length() >= MAX_PATH) { | 216 stripped_to.value().length() >= MAX_PATH) { |
213 return false; | 217 return false; |
214 } | 218 } |
215 | 219 |
216 // SHFILEOPSTRUCT wants the path to be terminated with two NULLs, | 220 // SHFILEOPSTRUCT wants the path to be terminated with two NULLs, |
217 // so we have to use wcscpy because wcscpy_s writes non-NULLs | 221 // so we have to use wcscpy because wcscpy_s writes non-NULLs |
218 // into the rest of the buffer. | 222 // into the rest of the buffer. |
219 wchar_t double_terminated_path_from[MAX_PATH + 1] = {0}; | 223 wchar_t double_terminated_path_from[MAX_PATH + 1] = {0}; |
220 wchar_t double_terminated_path_to[MAX_PATH + 1] = {0}; | 224 wchar_t double_terminated_path_to[MAX_PATH + 1] = {0}; |
221 #pragma warning(suppress:4996) // don't complain about wcscpy deprecation | 225 #pragma warning(suppress:4996) // don't complain about wcscpy deprecation |
222 wcscpy(double_terminated_path_from, from_path.value().c_str()); | 226 wcscpy(double_terminated_path_from, stripped_from.value().c_str()); |
223 #pragma warning(suppress:4996) // don't complain about wcscpy deprecation | 227 #pragma warning(suppress:4996) // don't complain about wcscpy deprecation |
224 wcscpy(double_terminated_path_to, to_path.value().c_str()); | 228 wcscpy(double_terminated_path_to, stripped_to.value().c_str()); |
225 | 229 |
226 SHFILEOPSTRUCT file_operation = {0}; | 230 SHFILEOPSTRUCT file_operation = {0}; |
227 file_operation.wFunc = FO_COPY; | 231 file_operation.wFunc = FO_COPY; |
228 file_operation.pFrom = double_terminated_path_from; | 232 file_operation.pFrom = double_terminated_path_from; |
229 file_operation.pTo = double_terminated_path_to; | 233 file_operation.pTo = double_terminated_path_to; |
230 file_operation.fFlags = FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION | | 234 file_operation.fFlags = FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION | |
231 FOF_NOCONFIRMMKDIR; | 235 FOF_NOCONFIRMMKDIR; |
232 if (!recursive) | 236 if (!recursive) |
233 file_operation.fFlags |= FOF_NORECURSION | FOF_FILESONLY; | 237 file_operation.fFlags |= FOF_NORECURSION | FOF_FILESONLY; |
234 | 238 |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 HANDLE cp = GetCurrentProcess(); | 942 HANDLE cp = GetCurrentProcess(); |
939 if (::GetMappedFileNameW(cp, file_view, mapped_file_path, kMaxPathLength)) { | 943 if (::GetMappedFileNameW(cp, file_view, mapped_file_path, kMaxPathLength)) { |
940 *nt_path = FilePath(mapped_file_path); | 944 *nt_path = FilePath(mapped_file_path); |
941 success = true; | 945 success = true; |
942 } | 946 } |
943 ::UnmapViewOfFile(file_view); | 947 ::UnmapViewOfFile(file_view); |
944 return success; | 948 return success; |
945 } | 949 } |
946 | 950 |
947 } // namespace file_util | 951 } // namespace file_util |
OLD | NEW |