1 | /*
|
---|
2 | * SHFileOperation
|
---|
3 | *
|
---|
4 | * Copyright 2000 Juergen Schmied
|
---|
5 | * Copyright 2002 Andriy Palamarchuk
|
---|
6 | * Copyright 2002 Dietrich Teickner (from Odin)
|
---|
7 | * Copyright 2002 Rolf Kalbermatter
|
---|
8 | *
|
---|
9 | * This library is free software; you can redistribute it and/or
|
---|
10 | * modify it under the terms of the GNU Lesser General Public
|
---|
11 | * License as published by the Free Software Foundation; either
|
---|
12 | * version 2.1 of the License, or (at your option) any later version.
|
---|
13 | *
|
---|
14 | * This library is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
17 | * Lesser General Public License for more details.
|
---|
18 | *
|
---|
19 | * You should have received a copy of the GNU Lesser General Public
|
---|
20 | * License along with this library; if not, write to the Free Software
|
---|
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
22 | */
|
---|
23 |
|
---|
24 | #include "config.h"
|
---|
25 | #include "wine/port.h"
|
---|
26 |
|
---|
27 | #include <string.h>
|
---|
28 | #include <ctype.h>
|
---|
29 |
|
---|
30 | #include "winreg.h"
|
---|
31 | #include "shellapi.h"
|
---|
32 | #include "shlobj.h"
|
---|
33 | #include "shresdef.h"
|
---|
34 | #include "shell32_main.h"
|
---|
35 | #include "undocshell.h"
|
---|
36 | #include "shlwapi.h"
|
---|
37 | #include "wine/debug.h"
|
---|
38 |
|
---|
39 | #define IsAttribFile(x) (!(x == -1) && !(x & FILE_ATTRIBUTE_DIRECTORY))
|
---|
40 | #define IsAttribDir(x) (!(x == -1) && (x & FILE_ATTRIBUTE_DIRECTORY))
|
---|
41 |
|
---|
42 | #define IsDotDir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
|
---|
43 |
|
---|
44 | WINE_DEFAULT_DEBUG_CHANNEL(shell);
|
---|
45 |
|
---|
46 | CHAR aWildcardFile[] = {'*','.','*',0};
|
---|
47 | WCHAR wWildcardFile[] = {'*','.','*',0};
|
---|
48 | WCHAR wWildcardChars[] = {'*','?',0};
|
---|
49 | WCHAR wBackslash[] = {'\\',0};
|
---|
50 |
|
---|
51 | static BOOL SHNotifyCreateDirectoryA(LPCSTR path, LPSECURITY_ATTRIBUTES sec);
|
---|
52 | static BOOL SHNotifyCreateDirectoryW(LPCWSTR path, LPSECURITY_ATTRIBUTES sec);
|
---|
53 | static BOOL SHNotifyRemoveDirectoryA(LPCSTR path);
|
---|
54 | static BOOL SHNotifyRemoveDirectoryW(LPCWSTR path);
|
---|
55 | static BOOL SHNotifyDeleteFileA(LPCSTR path);
|
---|
56 | static BOOL SHNotifyDeleteFileW(LPCWSTR path);
|
---|
57 |
|
---|
58 | typedef struct
|
---|
59 | {
|
---|
60 | UINT caption_resource_id, text_resource_id;
|
---|
61 | } SHELL_ConfirmIDstruc;
|
---|
62 |
|
---|
63 | static BOOL SHELL_ConfirmIDs(int nKindOfDialog, SHELL_ConfirmIDstruc *ids)
|
---|
64 | {
|
---|
65 | switch (nKindOfDialog) {
|
---|
66 | case ASK_DELETE_FILE:
|
---|
67 | ids->caption_resource_id = IDS_DELETEITEM_CAPTION;
|
---|
68 | ids->text_resource_id = IDS_DELETEITEM_TEXT;
|
---|
69 | return TRUE;
|
---|
70 | case ASK_DELETE_FOLDER:
|
---|
71 | ids->caption_resource_id = IDS_DELETEFOLDER_CAPTION;
|
---|
72 | ids->text_resource_id = IDS_DELETEITEM_TEXT;
|
---|
73 | return TRUE;
|
---|
74 | case ASK_DELETE_MULTIPLE_ITEM:
|
---|
75 | ids->caption_resource_id = IDS_DELETEITEM_CAPTION;
|
---|
76 | ids->text_resource_id = IDS_DELETEMULTIPLE_TEXT;
|
---|
77 | return TRUE;
|
---|
78 | case ASK_OVERWRITE_FILE:
|
---|
79 | ids->caption_resource_id = IDS_OVERWRITEFILE_CAPTION;
|
---|
80 | ids->text_resource_id = IDS_OVERWRITEFILE_TEXT;
|
---|
81 | return TRUE;
|
---|
82 | default:
|
---|
83 | FIXME(" Unhandled nKindOfDialog %d stub\n", nKindOfDialog);
|
---|
84 | }
|
---|
85 | return FALSE;
|
---|
86 | }
|
---|
87 |
|
---|
88 | BOOL SHELL_ConfirmDialog(int nKindOfDialog, LPCSTR szDir)
|
---|
89 | {
|
---|
90 | CHAR szCaption[255], szText[255], szBuffer[MAX_PATH + 256];
|
---|
91 | SHELL_ConfirmIDstruc ids;
|
---|
92 |
|
---|
93 | if (!SHELL_ConfirmIDs(nKindOfDialog, &ids))
|
---|
94 | return FALSE;
|
---|
95 |
|
---|
96 | LoadStringA(shell32_hInstance, ids.caption_resource_id, szCaption, sizeof(szCaption));
|
---|
97 | LoadStringA(shell32_hInstance, ids.text_resource_id, szText, sizeof(szText));
|
---|
98 |
|
---|
99 | FormatMessageA(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
|
---|
100 | szText, 0, 0, szBuffer, sizeof(szBuffer), (va_list*)&szDir);
|
---|
101 |
|
---|
102 | return (IDOK == MessageBoxA(GetActiveWindow(), szBuffer, szCaption, MB_OKCANCEL | MB_ICONEXCLAMATION));
|
---|
103 | }
|
---|
104 |
|
---|
105 | BOOL SHELL_ConfirmDialogW(int nKindOfDialog, LPCWSTR szDir)
|
---|
106 | {
|
---|
107 | WCHAR szCaption[255], szText[255], szBuffer[MAX_PATH + 256];
|
---|
108 | SHELL_ConfirmIDstruc ids;
|
---|
109 |
|
---|
110 | if (!SHELL_ConfirmIDs(nKindOfDialog, &ids))
|
---|
111 | return FALSE;
|
---|
112 |
|
---|
113 | LoadStringW(shell32_hInstance, ids.caption_resource_id, szCaption, sizeof(szCaption));
|
---|
114 | LoadStringW(shell32_hInstance, ids.text_resource_id, szText, sizeof(szText));
|
---|
115 |
|
---|
116 | FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
|
---|
117 | szText, 0, 0, szBuffer, sizeof(szBuffer), (va_list*)&szDir);
|
---|
118 |
|
---|
119 | return (IDOK == MessageBoxW(GetActiveWindow(), szBuffer, szCaption, MB_OKCANCEL | MB_ICONEXCLAMATION));
|
---|
120 | }
|
---|
121 |
|
---|
122 | /**************************************************************************
|
---|
123 | * SHELL_DeleteDirectoryA()
|
---|
124 | *
|
---|
125 | * like rm -r
|
---|
126 | */
|
---|
127 | BOOL SHELL_DeleteDirectoryA(LPCSTR pszDir, BOOL bShowUI)
|
---|
128 | {
|
---|
129 | BOOL ret = TRUE;
|
---|
130 | HANDLE hFind;
|
---|
131 | WIN32_FIND_DATAA wfd;
|
---|
132 | char szTemp[MAX_PATH];
|
---|
133 |
|
---|
134 | /* Make sure the directory exists before eventually prompting the user */
|
---|
135 | PathCombineA(szTemp, pszDir, aWildcardFile);
|
---|
136 | hFind = FindFirstFileA(szTemp, &wfd);
|
---|
137 | if (hFind == INVALID_HANDLE_VALUE)
|
---|
138 | return FALSE;
|
---|
139 |
|
---|
140 | if (!bShowUI || SHELL_ConfirmDialog(ASK_DELETE_FOLDER, pszDir))
|
---|
141 | {
|
---|
142 | do
|
---|
143 | {
|
---|
144 | LPSTR lp = wfd.cAlternateFileName;
|
---|
145 | if (!lp[0])
|
---|
146 | lp = wfd.cFileName;
|
---|
147 | if (IsDotDir(lp))
|
---|
148 | continue;
|
---|
149 | PathCombineA(szTemp, pszDir, lp);
|
---|
150 | if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
|
---|
151 | ret = SHELL_DeleteDirectoryA(szTemp, FALSE);
|
---|
152 | else
|
---|
153 | ret = SHNotifyDeleteFileA(szTemp);
|
---|
154 | } while (ret && FindNextFileA(hFind, &wfd));
|
---|
155 | }
|
---|
156 | FindClose(hFind);
|
---|
157 | if (ret)
|
---|
158 | ret = SHNotifyRemoveDirectoryA(pszDir);
|
---|
159 | return ret;
|
---|
160 | }
|
---|
161 |
|
---|
162 | BOOL SHELL_DeleteDirectoryW(LPCWSTR pszDir, BOOL bShowUI)
|
---|
163 | {
|
---|
164 | BOOL ret = TRUE;
|
---|
165 | HANDLE hFind;
|
---|
166 | WIN32_FIND_DATAW wfd;
|
---|
167 | WCHAR szTemp[MAX_PATH];
|
---|
168 |
|
---|
169 | /* Make sure the directory exists before eventually prompting the user */
|
---|
170 | PathCombineW(szTemp, pszDir, wWildcardFile);
|
---|
171 | hFind = FindFirstFileW(szTemp, &wfd);
|
---|
172 | if (hFind == INVALID_HANDLE_VALUE)
|
---|
173 | return FALSE;
|
---|
174 |
|
---|
175 | if (!bShowUI || SHELL_ConfirmDialogW(ASK_DELETE_FOLDER, pszDir))
|
---|
176 | {
|
---|
177 | do
|
---|
178 | {
|
---|
179 | LPWSTR lp = wfd.cAlternateFileName;
|
---|
180 | if (!lp[0])
|
---|
181 | lp = wfd.cFileName;
|
---|
182 | if (IsDotDir(lp))
|
---|
183 | continue;
|
---|
184 | PathCombineW(szTemp, pszDir, lp);
|
---|
185 | if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
|
---|
186 | ret = SHELL_DeleteDirectoryW(szTemp, FALSE);
|
---|
187 | else
|
---|
188 | ret = SHNotifyDeleteFileW(szTemp);
|
---|
189 | } while (ret && FindNextFileW(hFind, &wfd));
|
---|
190 | }
|
---|
191 | FindClose(hFind);
|
---|
192 | if (ret)
|
---|
193 | ret = SHNotifyRemoveDirectoryW(pszDir);
|
---|
194 | return ret;
|
---|
195 | }
|
---|
196 |
|
---|
197 | /**************************************************************************
|
---|
198 | * SHELL_DeleteFileA()
|
---|
199 | */
|
---|
200 | BOOL SHELL_DeleteFileA(LPCSTR pszFile, BOOL bShowUI)
|
---|
201 | {
|
---|
202 | if (bShowUI && !SHELL_ConfirmDialog(ASK_DELETE_FILE, pszFile))
|
---|
203 | return FALSE;
|
---|
204 |
|
---|
205 | return SHNotifyDeleteFileA(pszFile);
|
---|
206 | }
|
---|
207 |
|
---|
208 | BOOL SHELL_DeleteFileW(LPCWSTR pszFile, BOOL bShowUI)
|
---|
209 | {
|
---|
210 | if (bShowUI && !SHELL_ConfirmDialogW(ASK_DELETE_FILE, pszFile))
|
---|
211 | return FALSE;
|
---|
212 |
|
---|
213 | return SHNotifyDeleteFileW(pszFile);
|
---|
214 | }
|
---|
215 |
|
---|
216 | /**************************************************************************
|
---|
217 | * Win32CreateDirectory (SHELL32_93) [SHELL32.93]
|
---|
218 | *
|
---|
219 | * Creates a directory. Also triggers a change notify if one exists.
|
---|
220 | */
|
---|
221 | static BOOL SHNotifyCreateDirectoryA(LPCSTR path, LPSECURITY_ATTRIBUTES sec)
|
---|
222 | {
|
---|
223 | BOOL ret;
|
---|
224 | TRACE("(%s, %p)\n", debugstr_a(path), sec);
|
---|
225 |
|
---|
226 | ret = CreateDirectoryA(path, sec);
|
---|
227 | if (ret)
|
---|
228 | {
|
---|
229 | SHChangeNotify(SHCNE_MKDIR, SHCNF_PATHA, path, NULL);
|
---|
230 | }
|
---|
231 | return ret;
|
---|
232 | }
|
---|
233 |
|
---|
234 | static BOOL SHNotifyCreateDirectoryW(LPCWSTR path, LPSECURITY_ATTRIBUTES sec)
|
---|
235 | {
|
---|
236 | BOOL ret;
|
---|
237 | TRACE("(%s, %p)\n", debugstr_w(path), sec);
|
---|
238 |
|
---|
239 | ret = CreateDirectoryW(path, sec);
|
---|
240 | if (ret)
|
---|
241 | {
|
---|
242 | SHChangeNotify(SHCNE_MKDIR, SHCNF_PATHW, path, NULL);
|
---|
243 | }
|
---|
244 | return ret;
|
---|
245 | }
|
---|
246 |
|
---|
247 | BOOL WINAPI Win32CreateDirectoryAW(LPCVOID path, LPSECURITY_ATTRIBUTES sec)
|
---|
248 | {
|
---|
249 | if (SHELL_OsIsUnicode())
|
---|
250 | return SHNotifyCreateDirectoryW(path, sec);
|
---|
251 | return SHNotifyCreateDirectoryA(path, sec);
|
---|
252 | }
|
---|
253 |
|
---|
254 | /************************************************************************
|
---|
255 | * Win32RemoveDirectory (SHELL32_94) [SHELL32.94]
|
---|
256 | *
|
---|
257 | * Deletes a directory. Also triggers a change notify if one exists.
|
---|
258 | */
|
---|
259 | static BOOL SHNotifyRemoveDirectoryA(LPCSTR path)
|
---|
260 | {
|
---|
261 | BOOL ret;
|
---|
262 | TRACE("(%s)\n", debugstr_a(path));
|
---|
263 |
|
---|
264 | ret = RemoveDirectoryA(path);
|
---|
265 | if (!ret)
|
---|
266 | {
|
---|
267 | /* Directory may be write protected */
|
---|
268 | DWORD dwAttr = GetFileAttributesA(path);
|
---|
269 | if (dwAttr != -1 && dwAttr & FILE_ATTRIBUTE_READONLY)
|
---|
270 | if (SetFileAttributesA(path, dwAttr & ~FILE_ATTRIBUTE_READONLY))
|
---|
271 | ret = RemoveDirectoryA(path);
|
---|
272 | }
|
---|
273 | if (ret)
|
---|
274 | SHChangeNotify(SHCNE_RMDIR, SHCNF_PATHA, path, NULL);
|
---|
275 | return ret;
|
---|
276 | }
|
---|
277 |
|
---|
278 | static BOOL SHNotifyRemoveDirectoryW(LPCWSTR path)
|
---|
279 | {
|
---|
280 | BOOL ret;
|
---|
281 | TRACE("(%s)\n", debugstr_w(path));
|
---|
282 |
|
---|
283 | ret = RemoveDirectoryW(path);
|
---|
284 | if (!ret)
|
---|
285 | {
|
---|
286 | /* Directory may be write protected */
|
---|
287 | DWORD dwAttr = GetFileAttributesW(path);
|
---|
288 | if (dwAttr != -1 && dwAttr & FILE_ATTRIBUTE_READONLY)
|
---|
289 | if (SetFileAttributesW(path, dwAttr & ~FILE_ATTRIBUTE_READONLY))
|
---|
290 | ret = RemoveDirectoryW(path);
|
---|
291 | }
|
---|
292 | if (ret)
|
---|
293 | SHChangeNotify(SHCNE_RMDIR, SHCNF_PATHW, path, NULL);
|
---|
294 | return ret;
|
---|
295 | }
|
---|
296 |
|
---|
297 | BOOL WINAPI Win32RemoveDirectoryAW(LPCVOID path)
|
---|
298 | {
|
---|
299 | if (SHELL_OsIsUnicode())
|
---|
300 | return SHNotifyRemoveDirectoryW(path);
|
---|
301 | return SHNotifyRemoveDirectoryA(path);
|
---|
302 | }
|
---|
303 |
|
---|
304 | /************************************************************************
|
---|
305 | * Win32DeleteFile (SHELL32_164) [SHELL32.164]
|
---|
306 | *
|
---|
307 | * Deletes a file. Also triggers a change notify if one exists.
|
---|
308 | *
|
---|
309 | * NOTES:
|
---|
310 | * Verified on Win98 / IE 5 (SHELL32 4.72, March 1999 build) to be ANSI.
|
---|
311 | * This is Unicode on NT/2000
|
---|
312 | */
|
---|
313 | static BOOL SHNotifyDeleteFileA(LPCSTR path)
|
---|
314 | {
|
---|
315 | BOOL ret;
|
---|
316 |
|
---|
317 | TRACE("(%s)\n", debugstr_a(path));
|
---|
318 |
|
---|
319 | ret = DeleteFileA(path);
|
---|
320 | if (!ret)
|
---|
321 | {
|
---|
322 | /* File may be write protected or a system file */
|
---|
323 | DWORD dwAttr = GetFileAttributesA(path);
|
---|
324 | if ((dwAttr != -1) && (dwAttr & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM)))
|
---|
325 | if (SetFileAttributesA(path, dwAttr & ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM)))
|
---|
326 | ret = DeleteFileA(path);
|
---|
327 | }
|
---|
328 | if (ret)
|
---|
329 | SHChangeNotify(SHCNE_DELETE, SHCNF_PATHA, path, NULL);
|
---|
330 | return ret;
|
---|
331 | }
|
---|
332 |
|
---|
333 | static BOOL SHNotifyDeleteFileW(LPCWSTR path)
|
---|
334 | {
|
---|
335 | BOOL ret;
|
---|
336 |
|
---|
337 | TRACE("(%s)\n", debugstr_w(path));
|
---|
338 |
|
---|
339 | ret = DeleteFileW(path);
|
---|
340 | if (!ret)
|
---|
341 | {
|
---|
342 | /* File may be write protected or a system file */
|
---|
343 | DWORD dwAttr = GetFileAttributesW(path);
|
---|
344 | if ((dwAttr != -1) && (dwAttr & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM)))
|
---|
345 | if (SetFileAttributesW(path, dwAttr & ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM)))
|
---|
346 | ret = DeleteFileW(path);
|
---|
347 | }
|
---|
348 | if (ret)
|
---|
349 | SHChangeNotify(SHCNE_DELETE, SHCNF_PATHW, path, NULL);
|
---|
350 | return ret;
|
---|
351 | }
|
---|
352 |
|
---|
353 | DWORD WINAPI Win32DeleteFileAW(LPCVOID path)
|
---|
354 | {
|
---|
355 | if (SHELL_OsIsUnicode())
|
---|
356 | return SHNotifyDeleteFileW(path);
|
---|
357 | return SHNotifyDeleteFileA(path);
|
---|
358 | }
|
---|
359 |
|
---|
360 | /*************************************************************************
|
---|
361 | * SHCreateDirectory [SHELL32.165]
|
---|
362 | *
|
---|
363 | * NOTES
|
---|
364 | * exported by ordinal
|
---|
365 | * WinNT/2000 exports Unicode
|
---|
366 | */
|
---|
367 | DWORD WINAPI SHCreateDirectory(HWND hWnd, LPCVOID path)
|
---|
368 | {
|
---|
369 | if (SHELL_OsIsUnicode())
|
---|
370 | return SHCreateDirectoryExW(hWnd, path, NULL);
|
---|
371 | return SHCreateDirectoryExA(hWnd, path, NULL);
|
---|
372 | }
|
---|
373 |
|
---|
374 | /*************************************************************************
|
---|
375 | * SHCreateDirectoryExA [SHELL32.@]
|
---|
376 | */
|
---|
377 | DWORD WINAPI SHCreateDirectoryExA(HWND hWnd, LPCSTR path, LPSECURITY_ATTRIBUTES sec)
|
---|
378 | {
|
---|
379 | WCHAR wPath[MAX_PATH];
|
---|
380 | TRACE("(%p, %s, %p)\n",hWnd, debugstr_a(path), sec);
|
---|
381 |
|
---|
382 | MultiByteToWideChar(CP_ACP, 0, path, -1, wPath, MAX_PATH);
|
---|
383 | return SHCreateDirectoryExW(hWnd, wPath, sec);
|
---|
384 | }
|
---|
385 |
|
---|
386 | /*************************************************************************
|
---|
387 | * SHCreateDirectoryExW [SHELL32.@]
|
---|
388 | */
|
---|
389 | DWORD WINAPI SHCreateDirectoryExW(HWND hWnd, LPCWSTR path, LPSECURITY_ATTRIBUTES sec)
|
---|
390 | {
|
---|
391 | DWORD ret = ERROR_SUCCESS;
|
---|
392 | TRACE("(%p, %s, %p)\n",hWnd, debugstr_w(path), sec);
|
---|
393 |
|
---|
394 | if (PathIsRelativeW(path))
|
---|
395 | {
|
---|
396 | ret = ERROR_BAD_PATHNAME;
|
---|
397 | SetLastError(ERROR_BAD_PATHNAME);
|
---|
398 | }
|
---|
399 | else
|
---|
400 | {
|
---|
401 | if (!SHNotifyCreateDirectoryW(path, sec))
|
---|
402 | {
|
---|
403 | ret = GetLastError();
|
---|
404 | if (ret != ERROR_FILE_EXISTS &&
|
---|
405 | ret != ERROR_ALREADY_EXISTS &&
|
---|
406 | ret != ERROR_FILENAME_EXCED_RANGE)
|
---|
407 | {
|
---|
408 | /*lstrcpynW(pathName, path, MAX_PATH);
|
---|
409 | lpStr = PathAddBackslashW(pathName);*/
|
---|
410 | FIXME("Semi-stub, non zero hWnd should be used somehow?");
|
---|
411 | }
|
---|
412 | }
|
---|
413 | }
|
---|
414 | return ret;
|
---|
415 | }
|
---|
416 |
|
---|
417 | /*************************************************************************
|
---|
418 | *
|
---|
419 | * SHFileStrICmp HelperFunction for SHFileOperationW
|
---|
420 | *
|
---|
421 | */
|
---|
422 | BOOL SHFileStrICmpW(LPWSTR p1, LPWSTR p2, LPWSTR p1End, LPWSTR p2End)
|
---|
423 | {
|
---|
424 | WCHAR C1 = '\0';
|
---|
425 | WCHAR C2 = '\0';
|
---|
426 | int i_Temp = -1;
|
---|
427 | int i_len1 = lstrlenW(p1);
|
---|
428 | int i_len2 = lstrlenW(p2);
|
---|
429 |
|
---|
430 | if (p1End && (&p1[i_len1] >= p1End) && ('\\' == p1End[0]))
|
---|
431 | {
|
---|
432 | C1 = p1End[0];
|
---|
433 | p1End[0] = '\0';
|
---|
434 | i_len1 = lstrlenW(p1);
|
---|
435 | }
|
---|
436 | if (p2End)
|
---|
437 | {
|
---|
438 | if ((&p2[i_len2] >= p2End) && ('\\' == p2End[0]))
|
---|
439 | {
|
---|
440 | C2 = p2End[0];
|
---|
441 | if (C2)
|
---|
442 | p2End[0] = '\0';
|
---|
443 | }
|
---|
444 | }
|
---|
445 | else
|
---|
446 | {
|
---|
447 | if ((i_len1 <= i_len2) && ('\\' == p2[i_len1]))
|
---|
448 | {
|
---|
449 | C2 = p2[i_len1];
|
---|
450 | if (C2)
|
---|
451 | p2[i_len1] = '\0';
|
---|
452 | }
|
---|
453 | }
|
---|
454 | i_len2 = lstrlenW(p2);
|
---|
455 | if (i_len1 == i_len2)
|
---|
456 | i_Temp = lstrcmpiW(p1,p2);
|
---|
457 | if (C1)
|
---|
458 | p1[i_len1] = C1;
|
---|
459 | if (C2)
|
---|
460 | p2[i_len2] = C2;
|
---|
461 | return !(i_Temp);
|
---|
462 | }
|
---|
463 |
|
---|
464 | /*************************************************************************
|
---|
465 | *
|
---|
466 | * SHFileStrCpyCat HelperFunction for SHFileOperationW
|
---|
467 | *
|
---|
468 | */
|
---|
469 | LPWSTR SHFileStrCpyCatW(LPWSTR pTo, LPCWSTR pFrom, LPCWSTR pCatStr)
|
---|
470 | {
|
---|
471 | LPWSTR pToFile = NULL;
|
---|
472 | int i_len;
|
---|
473 | if (pTo)
|
---|
474 | {
|
---|
475 | if (pFrom)
|
---|
476 | lstrcpyW(pTo, pFrom);
|
---|
477 | if (pCatStr)
|
---|
478 | {
|
---|
479 | i_len = lstrlenW(pTo);
|
---|
480 | if ((i_len) && (pTo[--i_len] != '\\'))
|
---|
481 | i_len++;
|
---|
482 | pTo[i_len] = '\\';
|
---|
483 | if (pCatStr[0] == '\\')
|
---|
484 | pCatStr++; \
|
---|
485 | lstrcpyW(&pTo[i_len+1], pCatStr);
|
---|
486 | }
|
---|
487 | pToFile = StrRChrW(pTo,NULL,'\\');
|
---|
488 | /* !! termination of the new string-group */
|
---|
489 | pTo[(lstrlenW(pTo)) + 1] = '\0';
|
---|
490 | }
|
---|
491 | return pToFile;
|
---|
492 | }
|
---|
493 |
|
---|
494 | /**************************************************************************
|
---|
495 | * SHELL_FileNamesMatch()
|
---|
496 | *
|
---|
497 | * Accepts two \0 delimited lists of the file names. Checks whether number of
|
---|
498 | * files in the both lists is the same,
|
---|
499 | * and checks also if source-name exists.
|
---|
500 | */
|
---|
501 | BOOL SHELL_FileNamesMatch(LPCWSTR pszFiles1, LPCWSTR pszFiles2, BOOL B_OnlyFrom)
|
---|
502 | {
|
---|
503 | while ( (pszFiles1[0] != '\0') &&
|
---|
504 | (B_OnlyFrom || (pszFiles2[0] != '\0')))
|
---|
505 | {
|
---|
506 | if (NULL == StrPBrkW(pszFiles1, wWildcardChars))
|
---|
507 | {
|
---|
508 | if (-1 == GetFileAttributesW(pszFiles1))
|
---|
509 | return FALSE;
|
---|
510 | }
|
---|
511 | pszFiles1 += lstrlenW(pszFiles1) + 1;
|
---|
512 | if (!B_OnlyFrom)
|
---|
513 | pszFiles2 += lstrlenW(pszFiles2) + 1;
|
---|
514 | }
|
---|
515 | return
|
---|
516 | ( (pszFiles1[0] == '\0') &&
|
---|
517 | (B_OnlyFrom || (pszFiles2[0] == '\0')));
|
---|
518 | }
|
---|
519 |
|
---|
520 | /*************************************************************************
|
---|
521 | *
|
---|
522 | * SHName(s)Translate HelperFunction for SHFileOperationA
|
---|
523 | *
|
---|
524 | */
|
---|
525 | DWORD SHNameTranslate(LPWSTR* wString, LPCWSTR* pWToFrom, BOOL more)
|
---|
526 | {
|
---|
527 | DWORD retSize = 0, size;
|
---|
528 | LPCSTR aString = (LPSTR)pWToFrom[0];
|
---|
529 | if (pWToFrom[0])
|
---|
530 | {
|
---|
531 | if (wString[0]) /* only in the second loop */
|
---|
532 | pWToFrom[0] = wString[0];
|
---|
533 | do
|
---|
534 | {
|
---|
535 | size = lstrlenA(aString) + 1;
|
---|
536 | if (wString[0]) /* only in the second loop */
|
---|
537 | {
|
---|
538 | MultiByteToWideChar(CP_ACP, 0, aString, size, wString[0], size);
|
---|
539 | wString[0] += size;
|
---|
540 | }
|
---|
541 | aString += size;
|
---|
542 | retSize += size;
|
---|
543 | } while ((size != 1) & more);
|
---|
544 | retSize = ((retSize+0x7) & -8);
|
---|
545 | }
|
---|
546 | return retSize;
|
---|
547 | }
|
---|
548 | /*************************************************************************
|
---|
549 | * SHFileOperationA [SHELL32.@]
|
---|
550 | *
|
---|
551 | * NOTES
|
---|
552 | * exported by name
|
---|
553 | */
|
---|
554 | DWORD WINAPI SHFileOperationA(LPSHFILEOPSTRUCTA lpFileOp)
|
---|
555 | {
|
---|
556 | SHFILEOPSTRUCTW nFileOp = *((LPSHFILEOPSTRUCTW)lpFileOp);
|
---|
557 | DWORD retCode = 0, size = 0;
|
---|
558 | LPWSTR wString = NULL; /* we change this in SHNameTranlate */
|
---|
559 | LPWSTR ForFree = NULL;
|
---|
560 |
|
---|
561 | TRACE("SHFileOperationA");
|
---|
562 | if (FO_DELETE == (nFileOp.wFunc & 0xf))
|
---|
563 | nFileOp.pTo = NULL; /* we need a NULL or a valid pointer for translation */
|
---|
564 | if (!(nFileOp.fFlags & FOF_SIMPLEPROGRESS))
|
---|
565 | nFileOp.lpszProgressTitle = NULL; /* we need a NULL or a valid pointer for translation */
|
---|
566 | do
|
---|
567 | {
|
---|
568 | if (size)
|
---|
569 | {
|
---|
570 | ForFree = wString = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
|
---|
571 | if (!wString)
|
---|
572 | {
|
---|
573 | retCode = ERROR_OUTOFMEMORY;
|
---|
574 | SetLastError(retCode);
|
---|
575 | goto shfileop_error;
|
---|
576 | }
|
---|
577 | }
|
---|
578 | size = SHNameTranslate(&wString, &nFileOp.lpszProgressTitle, FALSE); /* no loop */
|
---|
579 | size += SHNameTranslate(&wString, &nFileOp.pFrom, TRUE); /* internal loop */
|
---|
580 | size += SHNameTranslate(&wString, &nFileOp.pTo, TRUE); /* internal loop */
|
---|
581 | /* first loop only for calculate size, no translation, we hav a NULL-pointer */
|
---|
582 | } while (!ForFree); /* second loop calculate size, also translation. We have a valid pointer */
|
---|
583 |
|
---|
584 | retCode = SHFileOperationW(&nFileOp);
|
---|
585 |
|
---|
586 | shfileop_error:
|
---|
587 | if (ForFree)
|
---|
588 | HeapFree(GetProcessHeap(), 0, ForFree);
|
---|
589 |
|
---|
590 | if (retCode)
|
---|
591 | {
|
---|
592 | nFileOp.fAnyOperationsAborted = TRUE;
|
---|
593 | }
|
---|
594 | lpFileOp->hNameMappings = nFileOp.hNameMappings;
|
---|
595 | lpFileOp->fAnyOperationsAborted = nFileOp.fAnyOperationsAborted;
|
---|
596 | return retCode;
|
---|
597 | }
|
---|
598 |
|
---|
599 | /*************************************************************************
|
---|
600 | * SHFileOperationW [SHELL32.@]
|
---|
601 | *
|
---|
602 | * NOTES
|
---|
603 | * exported by name
|
---|
604 | */
|
---|
605 |
|
---|
606 | /* in w98 brings shell32_test.exe this 4 failures
|
---|
607 | shlfileop.c:177: Test failed: Can't rename many files
|
---|
608 | * W98 return 0 without action
|
---|
609 | shlfileop.c:185: Test failed: Can't rename many files
|
---|
610 | * W98 return 0 without action
|
---|
611 | shlfileop.c:286: Test failed: Files are copied to other directory
|
---|
612 | shlfileop.c:287: Test failed: The file is copied
|
---|
613 | * This two messages are in W98 / W2K also
|
---|
614 | shlfileop: 121 tests executed, 0 marked as todo, 4 failures.
|
---|
615 | * this implementation has only the last 2 messages (W2K lyke)
|
---|
616 | */
|
---|
617 |
|
---|
618 | DWORD WINAPI SHFileOperationW(LPSHFILEOPSTRUCTW lpFileOp)
|
---|
619 | {
|
---|
620 | SHFILEOPSTRUCTW nFileOp = *(lpFileOp);
|
---|
621 |
|
---|
622 | LPCWSTR pNextFrom = nFileOp.pFrom;
|
---|
623 | LPCWSTR pNextTo = nFileOp.pTo;
|
---|
624 | LPCWSTR pFrom = pNextFrom;
|
---|
625 | LPCWSTR pTo = NULL;
|
---|
626 | LPCSTR Debug_pFrom;
|
---|
627 | LPCSTR Debug_pTo;
|
---|
628 | HANDLE hFind = INVALID_HANDLE_VALUE;
|
---|
629 | WIN32_FIND_DATAW wfd;
|
---|
630 | LPWSTR pTempFrom = NULL;
|
---|
631 | LPWSTR pTempTo = NULL;
|
---|
632 | LPWSTR pFromFile;
|
---|
633 | LPWSTR pToFile;
|
---|
634 | LPWSTR lpFileName;
|
---|
635 | long retCode = 0;
|
---|
636 | DWORD ToAttr;
|
---|
637 | DWORD ToPathAttr;
|
---|
638 | DWORD FromPathAttr;
|
---|
639 | FILEOP_FLAGS OFl = ((FILEOP_FLAGS)lpFileOp->fFlags & 0x7ff);
|
---|
640 |
|
---|
641 | BOOL b_Multi = (nFileOp.fFlags & FOF_MULTIDESTFILES);
|
---|
642 |
|
---|
643 | BOOL b_MultiTo = (FO_DELETE != (lpFileOp->wFunc & 0xf));
|
---|
644 | BOOL b_MultiPaired = (!b_MultiTo);
|
---|
645 | BOOL b_MultiFrom = FALSE;
|
---|
646 | BOOL not_overwrite;
|
---|
647 | BOOL ask_overwrite;
|
---|
648 | BOOL b_SameRoot;
|
---|
649 | BOOL b_SameTailName;
|
---|
650 | BOOL b_ToInvalidTail;
|
---|
651 | BOOL b_ToValid; /* for W98-Bug for FO_MOVE with source and taget in same rootdrive */
|
---|
652 | BOOL b_Mask; /* wird als Schalter benutzt, vieleicht finde ich die richtige bitposition */
|
---|
653 | BOOL b_ToTailSlash;
|
---|
654 | LPCSTR cFO_Name [] = {"FO_????","FO_MOVE","FO_COPY","FO_DELETE","FO_RENAME"};
|
---|
655 |
|
---|
656 | long FuncSwitch = (nFileOp.wFunc & 0xf);
|
---|
657 | long level= nFileOp.wFunc>>4;
|
---|
658 |
|
---|
659 | /* default no error */
|
---|
660 | nFileOp.fAnyOperationsAborted = FALSE;
|
---|
661 |
|
---|
662 | if ((FuncSwitch < FO_MOVE) || (FuncSwitch > FO_RENAME))
|
---|
663 | goto shfileop_normal; /* no valid FunctionCode */
|
---|
664 |
|
---|
665 | cFO_Name[0] = cFO_Name [FuncSwitch];
|
---|
666 | if (level == 0)
|
---|
667 | TRACE("%s: flags (0x%04x) : %s%s%s%s%s%s%s%s%s%s%s%s \n",cFO_Name[0], nFileOp.fFlags,
|
---|
668 | nFileOp.fFlags & FOF_MULTIDESTFILES ? "FOF_MULTIDESTFILES " : "",
|
---|
669 | nFileOp.fFlags & FOF_CONFIRMMOUSE ? "FOF_CONFIRMMOUSE " : "",
|
---|
670 | nFileOp.fFlags & FOF_SILENT ? "FOF_SILENT " : "",
|
---|
671 | nFileOp.fFlags & FOF_RENAMEONCOLLISION ? "FOF_RENAMEONCOLLISION " : "",
|
---|
672 | nFileOp.fFlags & FOF_NOCONFIRMATION ? "FOF_NOCONFIRMATION " : "",
|
---|
673 | nFileOp.fFlags & FOF_WANTMAPPINGHANDLE ? "FOF_WANTMAPPINGHANDLE " : "",
|
---|
674 | nFileOp.fFlags & FOF_ALLOWUNDO ? "FOF_ALLOWUNDO " : "",
|
---|
675 | nFileOp.fFlags & FOF_FILESONLY ? "FOF_FILESONLY " : "",
|
---|
676 | nFileOp.fFlags & FOF_SIMPLEPROGRESS ? "FOF_SIMPLEPROGRESS " : "",
|
---|
677 | nFileOp.fFlags & FOF_NOCONFIRMMKDIR ? "FOF_NOCONFIRMMKDIR " : "",
|
---|
678 | nFileOp.fFlags & FOF_NOERRORUI ? "FOF_NOERRORUI " : "",
|
---|
679 | nFileOp.fFlags & 0xf800 ? "MORE-UNKNOWN-Flags" : "");
|
---|
680 | ;
|
---|
681 | {
|
---|
682 | /* establish when pTo is interpreted as the name of the destination file
|
---|
683 | * or the directory where the Fromfile should be copied to.
|
---|
684 | * This depends on:
|
---|
685 | * (1) pTo points to the name of an existing directory;
|
---|
686 | * (2) the flag FOF_MULTIDESTFILES is present;
|
---|
687 | * (3) whether pFrom point to multiple filenames.
|
---|
688 | *
|
---|
689 | * Some experiments:
|
---|
690 | *
|
---|
691 | * destisdir 1 1 1 1 0 0 0 0
|
---|
692 | * FOF_MULTIDESTFILES 1 1 0 0 1 1 0 0
|
---|
693 | * multiple from filenames 1 0 1 0 1 0 1 0
|
---|
694 | * ---------------
|
---|
695 | * copy files to dir 1 0 1 1 0 0 1 0
|
---|
696 | * create dir 0 0 0 0 0 0 1 0
|
---|
697 | */
|
---|
698 | /*
|
---|
699 | * FOF_MULTIDESTFILES, FOF_NOCONFIRMATION, FOF_FILESONLY are implemented
|
---|
700 | * FOF_CONFIRMMOUSE, FOF_SILENT, FOF_NOCONFIRMMKDIR, FOF_SIMPLEPROGRESS are not implemented and ignored
|
---|
701 | * FOF_RENAMEONCOLLISION are implemented partially and breaks if file exist
|
---|
702 | * FOF_ALLOWUNDO, FOF_WANTMAPPINGHANDLE are not implemented and breaks
|
---|
703 | * if any other flag set, an error occurs
|
---|
704 | */
|
---|
705 | TRACE(" %s level=%d nFileOp.fFlags=0x%x\n", cFO_Name[0], level, lpFileOp->fFlags);
|
---|
706 |
|
---|
707 | /* OFl &= (-1 - (FOF_MULTIDESTFILES | FOF_FILESONLY)); */
|
---|
708 | /* OFl ^= (FOF_SILENT | FOF_NOCONFIRMATION | FOF_SIMPLEPROGRESS | FOF_NOCONFIRMMKDIR); */
|
---|
709 | OFl &= (~(FOF_MULTIDESTFILES | FOF_NOCONFIRMATION | FOF_FILESONLY)); /* implemented */
|
---|
710 | OFl ^= (FOF_SILENT | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI); /* ignored, if one */
|
---|
711 | OFl &= (~FOF_SIMPLEPROGRESS); /* ignored, only with FOF_SILENT */
|
---|
712 | if (OFl)
|
---|
713 | {
|
---|
714 | if (OFl & ( ~ (FOF_CONFIRMMOUSE | FOF_SILENT | FOF_RENAMEONCOLLISION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI)))
|
---|
715 | {
|
---|
716 | TRACE("%s level=%d lpFileOp->fFlags=0x%x not implemented, Aborted=TRUE, stub\n", cFO_Name[0], level, OFl);
|
---|
717 | retCode = 0x403; /* 1027, we need a extension of shlfileop */
|
---|
718 | goto shfileop_error;
|
---|
719 | }
|
---|
720 | else
|
---|
721 | {
|
---|
722 | TRACE("%s level=%d lpFileOp->fFlags=0x%x not full implemented ,stub\n", cFO_Name[0], level, OFl);
|
---|
723 | } /* endif */
|
---|
724 | } /* endif */
|
---|
725 |
|
---|
726 | if ((pNextFrom) && (!(b_MultiTo) || (pNextTo)))
|
---|
727 | {
|
---|
728 | nFileOp.pFrom = pTempFrom = HeapAlloc(GetProcessHeap(), 0, ((1 + 2 * (b_MultiTo)) * MAX_PATH + 6) * sizeof(WCHAR));
|
---|
729 | if (!pTempFrom)
|
---|
730 | {
|
---|
731 | retCode = ERROR_OUTOFMEMORY;
|
---|
732 | SetLastError(retCode);
|
---|
733 | goto shfileop_error;
|
---|
734 | }
|
---|
735 | if (b_MultiTo)
|
---|
736 | pTempTo = &pTempFrom[MAX_PATH + 4];
|
---|
737 | nFileOp.pTo = pTempTo;
|
---|
738 | ask_overwrite = (!(nFileOp.fFlags & FOF_NOCONFIRMATION) && !(nFileOp.fFlags & FOF_RENAMEONCOLLISION));
|
---|
739 | not_overwrite = (!(nFileOp.fFlags & FOF_NOCONFIRMATION) || (nFileOp.fFlags & FOF_RENAMEONCOLLISION));
|
---|
740 | }
|
---|
741 | else
|
---|
742 | {
|
---|
743 | retCode = 0x402; /* 1026 */
|
---|
744 | goto shfileop_error;
|
---|
745 | }
|
---|
746 | /* need break at error before change sourcepointer */
|
---|
747 | while(!nFileOp.fAnyOperationsAborted && (pNextFrom[0]))
|
---|
748 | {
|
---|
749 | nFileOp.wFunc = ((level + 1) << 4) + FuncSwitch;
|
---|
750 | nFileOp.fFlags = lpFileOp->fFlags;
|
---|
751 |
|
---|
752 | if (b_MultiTo)
|
---|
753 | {
|
---|
754 | pTo = pNextTo;
|
---|
755 | pNextTo = &pNextTo[lstrlenW(pTo)+1];
|
---|
756 | b_MultiTo = (b_Multi && pNextTo[0]);
|
---|
757 | }
|
---|
758 |
|
---|
759 | pFrom = pNextFrom;
|
---|
760 | pNextFrom = &pNextFrom[lstrlenW(pNextFrom)+1];
|
---|
761 | if (!b_MultiFrom && !b_MultiTo)
|
---|
762 | b_MultiFrom = (pNextFrom[0]);
|
---|
763 |
|
---|
764 | pFromFile = SHFileStrCpyCatW(pTempFrom, pFrom, NULL);
|
---|
765 |
|
---|
766 | /* for seeing in debugger outside from TRACE */
|
---|
767 | Debug_pFrom = debugstr_w(pFrom);
|
---|
768 | Debug_pTo = debugstr_w(pTo);
|
---|
769 | TRACE("%s level=%d with %s %s%s\n",
|
---|
770 | cFO_Name[0], level, Debug_pFrom, pTo ? "-> ":"", Debug_pTo);
|
---|
771 |
|
---|
772 | if (pTo)
|
---|
773 | {
|
---|
774 | pToFile = SHFileStrCpyCatW(pTempTo, pTo, NULL);
|
---|
775 | }
|
---|
776 | if (!b_MultiPaired)
|
---|
777 | {
|
---|
778 | b_MultiPaired =
|
---|
779 | SHELL_FileNamesMatch(lpFileOp->pFrom, lpFileOp->pTo, (!b_Multi || b_MultiFrom));
|
---|
780 | } /* endif */
|
---|
781 | if (!(b_MultiPaired) || !(pFromFile) || !(pFromFile[1]) || ((pTo) && !(pToFile)))
|
---|
782 | {
|
---|
783 | retCode = 0x402; /* 1026 */
|
---|
784 | goto shfileop_error;
|
---|
785 | }
|
---|
786 | if (pTo)
|
---|
787 | {
|
---|
788 | b_ToTailSlash = (!pToFile[1]);
|
---|
789 | if (b_ToTailSlash)
|
---|
790 | {
|
---|
791 | pToFile[0] = '\0';
|
---|
792 | if (StrChrW(pTempTo,'\\'))
|
---|
793 | {
|
---|
794 | pToFile = SHFileStrCpyCatW(pTempTo, NULL, NULL);
|
---|
795 | }
|
---|
796 | }
|
---|
797 | b_ToInvalidTail = (NULL != StrPBrkW(&pToFile[1], wWildcardChars));
|
---|
798 | }
|
---|
799 |
|
---|
800 | /* for all */
|
---|
801 | b_Mask = (NULL != StrPBrkW(&pFromFile[1], wWildcardChars));
|
---|
802 | if (FO_RENAME == FuncSwitch)
|
---|
803 | {
|
---|
804 | /* temporary only for FO_RENAME */
|
---|
805 | /* ??? b_Mask = (NULL != strrbrk(pFrom,"*?")); */
|
---|
806 | if (b_MultiTo || b_MultiFrom || (b_Mask && !b_ToInvalidTail))
|
---|
807 | {
|
---|
808 | /* no work, only RC=0 */
|
---|
809 | /* ??? nFileOp.fAnyOperationsAborted = TRUE; */
|
---|
810 | //#define W98_FO_RENEME
|
---|
811 | #ifdef W98_FO_RENEME
|
---|
812 | goto shfileop_normal;
|
---|
813 | #endif
|
---|
814 | retCode = 0x1; /* 1 value unknown, W98 returns no error */
|
---|
815 | goto shfileop_error;
|
---|
816 | }
|
---|
817 | }
|
---|
818 |
|
---|
819 | hFind = FindFirstFileW(pFrom, &wfd);
|
---|
820 | if (INVALID_HANDLE_VALUE == hFind)
|
---|
821 | {
|
---|
822 | if ((FO_DELETE == FuncSwitch) && (b_Mask))
|
---|
823 | {
|
---|
824 | pFromFile[0] = '\0';
|
---|
825 | FromPathAttr = GetFileAttributesW(pTempFrom);
|
---|
826 | pFromFile[0] = '\\';
|
---|
827 | if (IsAttribDir(FromPathAttr))
|
---|
828 | {
|
---|
829 | /* FO_DELETE with mask and without found is valid */
|
---|
830 | goto shfileop_normal;
|
---|
831 | } /* endif */
|
---|
832 | } /* endif */
|
---|
833 | /* root (without mask) is also not allowed as source, tested in W98 */
|
---|
834 | retCode = 0x402; /* 1026 */
|
---|
835 | goto shfileop_error;
|
---|
836 | } /* endif */
|
---|
837 |
|
---|
838 | /* for all */
|
---|
839 | #define HIGH_ADR (LPWSTR)0xffffffff
|
---|
840 |
|
---|
841 | /* ??? b_Mask = (!SHFileStrICmpA(&pFromFile[1], &wfd.cFileName[0], HIGH_ADR, HIGH_ADR)); */
|
---|
842 |
|
---|
843 | if (!pTo) /* FO_DELETE */
|
---|
844 | {
|
---|
845 | do
|
---|
846 | {
|
---|
847 | lpFileName = wfd.cAlternateFileName;
|
---|
848 | if (!lpFileName[0])
|
---|
849 | lpFileName = wfd.cFileName;
|
---|
850 | if (IsDotDir(lpFileName) ||
|
---|
851 | ((b_Mask) && IsAttribDir(wfd.dwFileAttributes) && (nFileOp.fFlags & FOF_FILESONLY)))
|
---|
852 | continue; /* next name in pTempFrom(dir) */
|
---|
853 | SHFileStrCpyCatW(&pFromFile[1], lpFileName, NULL);
|
---|
854 | /* TODO: Check the SHELL_DeleteFileOrDirectoryW() function in shell32.dll */
|
---|
855 | if (IsAttribFile(wfd.dwFileAttributes))
|
---|
856 | {
|
---|
857 | nFileOp.fAnyOperationsAborted = (!SHNotifyDeleteFileW(pTempFrom));
|
---|
858 | retCode = 0x78; /* value unknown */
|
---|
859 | }
|
---|
860 | else
|
---|
861 | {
|
---|
862 | nFileOp.fAnyOperationsAborted = (!SHELL_DeleteDirectoryW(pTempFrom, (!(nFileOp.fFlags & FOF_NOCONFIRMATION))));
|
---|
863 | retCode = 0x79; /* value unknown */
|
---|
864 | }
|
---|
865 | } while (!nFileOp.fAnyOperationsAborted && FindNextFileW(hFind, &wfd));
|
---|
866 | FindClose(hFind);
|
---|
867 | hFind = INVALID_HANDLE_VALUE;
|
---|
868 | if (nFileOp.fAnyOperationsAborted)
|
---|
869 | {
|
---|
870 | goto shfileop_error;
|
---|
871 | }
|
---|
872 | continue;
|
---|
873 | } /* FO_DELETE ends, pTo must be always valid from here */
|
---|
874 |
|
---|
875 | b_SameRoot = (towupper(pTempFrom[0]) == towupper(pTempTo[0]));
|
---|
876 | b_SameTailName = SHFileStrICmpW(pToFile, pFromFile, NULL, NULL);
|
---|
877 |
|
---|
878 | ToPathAttr = ToAttr = GetFileAttributesW(pTempTo);
|
---|
879 | if (!b_Mask && (ToAttr -1) && (pToFile))
|
---|
880 | {
|
---|
881 | pToFile[0] = '\0';
|
---|
882 | ToPathAttr = GetFileAttributesW(pTempTo);
|
---|
883 | pToFile[0] = '\\';
|
---|
884 | }
|
---|
885 |
|
---|
886 | if (FO_RENAME == FuncSwitch)
|
---|
887 | {
|
---|
888 | if (!b_SameRoot || b_Mask /* FO_RENAME works not with Mask */
|
---|
889 | || !SHFileStrICmpW(pTempFrom, pTempTo, pFromFile, NULL)
|
---|
890 | || (SHFileStrICmpW(pTempFrom, pTempTo, pFromFile, HIGH_ADR) && !b_ToTailSlash))
|
---|
891 | {
|
---|
892 | retCode = 0x73;
|
---|
893 | goto shfileop_error;
|
---|
894 | }
|
---|
895 | if (b_ToInvalidTail)
|
---|
896 | {
|
---|
897 | retCode=0x2;
|
---|
898 | goto shfileop_error;
|
---|
899 | }
|
---|
900 | if (-1 == ToPathAttr)
|
---|
901 | {
|
---|
902 | retCode = 0x75;
|
---|
903 | goto shfileop_error;
|
---|
904 | }
|
---|
905 | if (IsAttribDir(wfd.dwFileAttributes) && IsAttribDir(ToAttr))
|
---|
906 | {
|
---|
907 | retCode = (b_ToTailSlash) ? 0xb7 : 0x7b;
|
---|
908 | goto shfileop_error;
|
---|
909 | } /* endif */
|
---|
910 | /* TODO: use SHNotifyMoveFile() instead ?? */
|
---|
911 | if (!MoveFileW(pTempFrom, pTempTo))
|
---|
912 | {
|
---|
913 | /* we need still the value for the returncode, we use the mostly assumed */
|
---|
914 | retCode = 0xb7;
|
---|
915 | goto shfileop_error;
|
---|
916 | }
|
---|
917 | goto shfileop_normal;
|
---|
918 | }
|
---|
919 |
|
---|
920 | /* W98 Bug with FO_MOVE different to FO_COPY, better the same as FO_COPY */
|
---|
921 | b_ToValid = ((b_SameTailName && b_SameRoot && (FO_COPY == FuncSwitch)) ||
|
---|
922 | (b_SameTailName && !b_SameRoot) || (b_ToInvalidTail));
|
---|
923 |
|
---|
924 | /* handle mask in source */
|
---|
925 | if (b_Mask)
|
---|
926 | {
|
---|
927 | if (!IsAttribDir(ToAttr))
|
---|
928 | {
|
---|
929 | retCode = (b_ToInvalidTail &&/* b_SameTailName &&*/ (FO_MOVE == FuncSwitch)) \
|
---|
930 | ? 0x2 : 0x75;
|
---|
931 | goto shfileop_error;
|
---|
932 | }
|
---|
933 | pToFile = SHFileStrCpyCatW(pTempTo, NULL, wBackslash);
|
---|
934 | nFileOp.fFlags = (nFileOp.fFlags | FOF_MULTIDESTFILES);
|
---|
935 | do
|
---|
936 | {
|
---|
937 | lpFileName = wfd.cAlternateFileName;
|
---|
938 | if (!lpFileName[0])
|
---|
939 | lpFileName = wfd.cFileName;
|
---|
940 | if (IsDotDir(lpFileName) ||
|
---|
941 | (IsAttribDir(wfd.dwFileAttributes) && (nFileOp.fFlags & FOF_FILESONLY)))
|
---|
942 | continue; /* next name in pTempFrom(dir) */
|
---|
943 | SHFileStrCpyCatW(&pToFile[1], lpFileName, NULL);
|
---|
944 | SHFileStrCpyCatW(&pFromFile[1], lpFileName, NULL);
|
---|
945 | retCode = SHFileOperationW (&nFileOp);
|
---|
946 | } while(!nFileOp.fAnyOperationsAborted && FindNextFileW(hFind, &wfd));
|
---|
947 | }
|
---|
948 | FindClose(hFind);
|
---|
949 | hFind = INVALID_HANDLE_VALUE;
|
---|
950 | /* FO_COPY/FO_MOVE with mask, FO_DELETE and FO_RENAME are solved */
|
---|
951 | if (b_Mask)
|
---|
952 | continue;
|
---|
953 |
|
---|
954 | /* only FO_COPY/FO_MOVE without mask, all others are (must be) solved */
|
---|
955 | if (IsAttribDir(wfd.dwFileAttributes) && (ToAttr -1))
|
---|
956 | {
|
---|
957 | if (pToFile)
|
---|
958 | {
|
---|
959 | pToFile[0] = '\0';
|
---|
960 | ToPathAttr = GetFileAttributesW(pTempTo);
|
---|
961 | if ((ToPathAttr == -1) && b_ToValid)
|
---|
962 | {
|
---|
963 | /* create dir must be here, sample target D:\y\ *.* create with RC=10003 */
|
---|
964 | if (SHCreateDirectoryExW(NULL, pTempTo, NULL))
|
---|
965 | {
|
---|
966 | retCode = 0x73;/* value unknown */
|
---|
967 | goto shfileop_error;
|
---|
968 | }
|
---|
969 | ToPathAttr = GetFileAttributesW(pTempTo);
|
---|
970 | }
|
---|
971 | pToFile[0] = '\\';
|
---|
972 | if (b_ToInvalidTail)
|
---|
973 | {
|
---|
974 | retCode = 0x10003;
|
---|
975 | goto shfileop_error;
|
---|
976 | }
|
---|
977 | }
|
---|
978 | }
|
---|
979 |
|
---|
980 | /* trailing BackSlash is ever removed and pToFile points to BackSlash before */
|
---|
981 | if (!b_MultiTo && (b_MultiFrom || (!(b_Multi) && IsAttribDir(ToAttr))))
|
---|
982 | {
|
---|
983 | if ((FO_MOVE == FuncSwitch) && IsAttribDir(ToAttr) && IsAttribDir(wfd.dwFileAttributes))
|
---|
984 | {
|
---|
985 | if (b_Multi)
|
---|
986 | {
|
---|
987 | retCode = 0x73; /* !b_Multi = 0x8 ?? */
|
---|
988 | goto shfileop_error;
|
---|
989 | }
|
---|
990 | }
|
---|
991 | pToFile = SHFileStrCpyCatW(pTempTo, NULL, wfd.cFileName);
|
---|
992 | ToAttr = GetFileAttributesW(pTempTo);
|
---|
993 | }
|
---|
994 |
|
---|
995 | if (IsAttribDir(ToAttr))
|
---|
996 | {
|
---|
997 | if (IsAttribFile(wfd.dwFileAttributes))
|
---|
998 | {
|
---|
999 | retCode = (FO_COPY == FuncSwitch) ? 0x75 : 0xb7;
|
---|
1000 | goto shfileop_error;
|
---|
1001 | }
|
---|
1002 | }
|
---|
1003 | else
|
---|
1004 | {
|
---|
1005 | pToFile[0] = '\0';
|
---|
1006 | ToPathAttr = GetFileAttributesW(pTempTo);
|
---|
1007 | pToFile[0] = '\\';
|
---|
1008 | if (IsAttribFile(ToPathAttr))
|
---|
1009 | {
|
---|
1010 | /* error, is this tested ? */
|
---|
1011 | retCode = 0x777402;
|
---|
1012 | goto shfileop_error;
|
---|
1013 | } /* endif */
|
---|
1014 | }
|
---|
1015 |
|
---|
1016 | /* singlesource + no mask */
|
---|
1017 | if (-1 == (ToAttr & ToPathAttr))
|
---|
1018 | {
|
---|
1019 | /* Target-dir does not exist, and cannot be created */
|
---|
1020 | retCode=0x75;
|
---|
1021 | goto shfileop_error;
|
---|
1022 | }
|
---|
1023 |
|
---|
1024 | switch(FuncSwitch)
|
---|
1025 | {
|
---|
1026 | case FO_MOVE:
|
---|
1027 | pToFile = NULL;
|
---|
1028 | if ((ToAttr == -1) && SHFileStrICmpW(pTempFrom, pTempTo, pFromFile, NULL))
|
---|
1029 | {
|
---|
1030 | nFileOp.wFunc = ((level+1)<<4) + FO_RENAME;
|
---|
1031 | }
|
---|
1032 | else
|
---|
1033 | {
|
---|
1034 | if (b_SameRoot && IsAttribDir(ToAttr) && IsAttribDir(wfd.dwFileAttributes))
|
---|
1035 | {
|
---|
1036 | /* we need pToFile for FO_DELETE after FO_MOVE contence */
|
---|
1037 | pToFile = SHFileStrCpyCatW(pTempFrom, NULL, wWildcardFile);
|
---|
1038 | }
|
---|
1039 | else
|
---|
1040 | {
|
---|
1041 | nFileOp.wFunc = ((level+1)<<4) + FO_COPY;
|
---|
1042 | }
|
---|
1043 | }
|
---|
1044 | retCode = SHFileOperationW(&nFileOp);
|
---|
1045 | if (pToFile)
|
---|
1046 | ((DWORD*)pToFile)[0] = '\0';
|
---|
1047 | if (!nFileOp.fAnyOperationsAborted && (FO_RENAME != (nFileOp.wFunc & 0xf)))
|
---|
1048 | {
|
---|
1049 | nFileOp.wFunc = ((level+1)<<4) + FO_DELETE;
|
---|
1050 | retCode = SHFileOperationW(&nFileOp);
|
---|
1051 | }
|
---|
1052 | continue;
|
---|
1053 | case FO_COPY:
|
---|
1054 | if (SHFileStrICmpW(pTempFrom, pTempTo, NULL, NULL))
|
---|
1055 | { /* target is the same as source ? */
|
---|
1056 | /* we still need the value for the returncode, we assume 0x71 */
|
---|
1057 | retCode = 0x71;
|
---|
1058 | goto shfileop_error;
|
---|
1059 | } /* endif */
|
---|
1060 | if (IsAttribDir((ToAttr & wfd.dwFileAttributes)))
|
---|
1061 | {
|
---|
1062 | if (IsAttribDir(ToAttr) || !SHCreateDirectoryExW(NULL,pTempTo, NULL))
|
---|
1063 | {
|
---|
1064 | /* ??? nFileOp.fFlags = (nFileOp.fFlags | FOF_MULTIDESTFILES); */
|
---|
1065 | SHFileStrCpyCatW(pTempFrom, NULL, wWildcardFile);
|
---|
1066 | retCode = SHFileOperationW(&nFileOp);
|
---|
1067 | }
|
---|
1068 | else
|
---|
1069 | {
|
---|
1070 | retCode = 0x750;/* value unknown */
|
---|
1071 | goto shfileop_error;
|
---|
1072 | }
|
---|
1073 | }
|
---|
1074 | else
|
---|
1075 | {
|
---|
1076 | if (!(ask_overwrite && SHELL_ConfirmDialogW(ASK_OVERWRITE_FILE, pTempTo))
|
---|
1077 | && (not_overwrite))
|
---|
1078 | {
|
---|
1079 | /* we still need the value for the returncode, we use the mostly assumed */
|
---|
1080 | retCode = 0x73;
|
---|
1081 | goto shfileop_error;
|
---|
1082 | }
|
---|
1083 | /* TODO: use SHNotifyCopyFile() */
|
---|
1084 | if (!(CopyFileW(pTempFrom, pTempTo, FALSE)))
|
---|
1085 | {
|
---|
1086 | retCode = 0x77; /* value unknown */
|
---|
1087 | goto shfileop_error;
|
---|
1088 | }
|
---|
1089 | }
|
---|
1090 | } /* end-switch */
|
---|
1091 | } /* end-while */
|
---|
1092 | }
|
---|
1093 | shfileop_normal:
|
---|
1094 | if (!(nFileOp.fAnyOperationsAborted))
|
---|
1095 | retCode = 0;
|
---|
1096 | shfileop_error:
|
---|
1097 | if (hFind != INVALID_HANDLE_VALUE)
|
---|
1098 | FindClose(hFind);
|
---|
1099 | hFind = INVALID_HANDLE_VALUE;
|
---|
1100 | if (pTempFrom)
|
---|
1101 | HeapFree(GetProcessHeap(), 0, pTempFrom);
|
---|
1102 | if (retCode)
|
---|
1103 | {
|
---|
1104 | nFileOp.fAnyOperationsAborted = TRUE;
|
---|
1105 | }
|
---|
1106 | TRACE("%s level=%d AnyOpsAborted=%s ret=0x%x, with %s %s%s\n",
|
---|
1107 | cFO_Name[0], level, nFileOp.fAnyOperationsAborted ? "TRUE":"FALSE",
|
---|
1108 | retCode, debugstr_w(pFrom), pTo ? "-> ":"", debugstr_w(pTo));
|
---|
1109 |
|
---|
1110 | lpFileOp->fAnyOperationsAborted = nFileOp.fAnyOperationsAborted;
|
---|
1111 | return retCode;
|
---|
1112 | }
|
---|
1113 |
|
---|
1114 | /*************************************************************************
|
---|
1115 | * SHFileOperation [SHELL32.@]
|
---|
1116 | *
|
---|
1117 | */
|
---|
1118 | DWORD WINAPI SHFileOperationAW(LPVOID lpFileOp)
|
---|
1119 | {
|
---|
1120 | if (SHELL_OsIsUnicode())
|
---|
1121 | return SHFileOperationW(lpFileOp);
|
---|
1122 | return SHFileOperationA(lpFileOp);
|
---|
1123 | }
|
---|
1124 |
|
---|
1125 | /*************************************************************************
|
---|
1126 | * SheGetDirW [SHELL32.281]
|
---|
1127 | *
|
---|
1128 | */
|
---|
1129 | HRESULT WINAPI SheGetDirW(LPWSTR u, LPWSTR v)
|
---|
1130 | { FIXME("%p %p stub\n",u,v);
|
---|
1131 | return 0;
|
---|
1132 | }
|
---|
1133 |
|
---|
1134 | /*************************************************************************
|
---|
1135 | * SheChangeDirW [SHELL32.274]
|
---|
1136 | *
|
---|
1137 | */
|
---|
1138 | HRESULT WINAPI SheChangeDirW(LPWSTR u)
|
---|
1139 | { FIXME("(%s),stub\n",debugstr_w(u));
|
---|
1140 | return 0;
|
---|
1141 | }
|
---|
1142 |
|
---|
1143 | /*************************************************************************
|
---|
1144 | * IsNetDrive [SHELL32.66]
|
---|
1145 | */
|
---|
1146 | BOOL WINAPI IsNetDrive(DWORD drive)
|
---|
1147 | {
|
---|
1148 | char root[4];
|
---|
1149 | strcpy(root, "A:\\");
|
---|
1150 | root[0] += (char)drive;
|
---|
1151 | return (GetDriveTypeA(root) == DRIVE_REMOTE);
|
---|
1152 | }
|
---|
1153 |
|
---|
1154 |
|
---|
1155 |
|
---|
1156 |
|
---|
1157 |
|
---|