source: trunk/src/shell32/shlfileop.c@ 5544

Last change on this file since 5544 was 5544, checked in by sandervl, 24 years ago

update with latest wine

File size: 6.5 KB
Line 
1/*
2 * SHFileOperation
3 */
4#ifdef __WIN32OS2__
5#define ICOM_CINTERFACE 1
6#include <odin.h>
7#endif
8#include <string.h>
9#include "debugtools.h"
10#include "shellapi.h"
11#include "shlwapi.h"
12
13#include "shlobj.h"
14#include "shresdef.h"
15#include "shell32_main.h"
16#include "wine/undocshell.h"
17#include "shlwapi.h"
18
19DEFAULT_DEBUG_CHANNEL(shell);
20
21BOOL SHELL_WarnItemDelete (int nKindOfDialog, LPCSTR szDir)
22{
23 char szCaption[255], szText[255], szBuffer[MAX_PATH + 256];
24
25 if(nKindOfDialog == ASK_DELETE_FILE)
26 {
27 LoadStringA(shell32_hInstance, IDS_DELETEITEM_TEXT, szText,
28 sizeof(szText));
29 LoadStringA(shell32_hInstance, IDS_DELETEITEM_CAPTION,
30 szCaption, sizeof(szCaption));
31 }
32 else if(nKindOfDialog == ASK_DELETE_FOLDER)
33 {
34 LoadStringA(shell32_hInstance, IDS_DELETEITEM_TEXT, szText,
35 sizeof(szText));
36 LoadStringA(shell32_hInstance, IDS_DELETEFOLDER_CAPTION,
37 szCaption, sizeof(szCaption));
38 }
39 else if(nKindOfDialog == ASK_DELETE_MULTIPLE_ITEM)
40 {
41 LoadStringA(shell32_hInstance, IDS_DELETEMULTIPLE_TEXT, szText,
42 sizeof(szText));
43 LoadStringA(shell32_hInstance, IDS_DELETEITEM_CAPTION,
44 szCaption, sizeof(szCaption));
45 }
46 else {
47 FIXME("Called without a valid nKindOfDialog specified!");
48 LoadStringA(shell32_hInstance, IDS_DELETEITEM_TEXT, szText,
49 sizeof(szText));
50 LoadStringA(shell32_hInstance, IDS_DELETEITEM_CAPTION,
51 szCaption, sizeof(szCaption));
52 }
53
54 FormatMessageA(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
55 szText, 0, 0, szBuffer, sizeof(szBuffer), (va_list*)&szDir);
56
57 return (IDOK == MessageBoxA(GetActiveWindow(), szBuffer, szCaption, MB_OKCANCEL | MB_ICONEXCLAMATION));
58}
59
60/**************************************************************************
61 * SHELL_DeleteDirectoryA()
62 *
63 * like rm -r
64 */
65
66BOOL SHELL_DeleteDirectoryA(LPCSTR pszDir, BOOL bShowUI)
67{
68 BOOL ret = FALSE;
69 HANDLE hFind;
70 WIN32_FIND_DATAA wfd;
71 char szTemp[MAX_PATH];
72
73 strcpy(szTemp, pszDir);
74 PathAddBackslashA(szTemp);
75 strcat(szTemp, "*.*");
76
77 if (bShowUI && !SHELL_WarnItemDelete(ASK_DELETE_FOLDER, pszDir))
78 return FALSE;
79
80 if(INVALID_HANDLE_VALUE != (hFind = FindFirstFileA(szTemp, &wfd)))
81 {
82 do
83 {
84 if(strcasecmp(wfd.cFileName, ".") && strcasecmp(wfd.cFileName, ".."))
85 {
86 strcpy(szTemp, pszDir);
87 PathAddBackslashA(szTemp);
88 strcat(szTemp, wfd.cFileName);
89
90 if(FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
91 SHELL_DeleteDirectoryA(szTemp, FALSE);
92 else
93 DeleteFileA(szTemp);
94 }
95 } while(FindNextFileA(hFind, &wfd));
96
97 FindClose(hFind);
98 ret = RemoveDirectoryA(pszDir);
99 }
100
101 return ret;
102}
103
104/**************************************************************************
105 * SHELL_DeleteFileA()
106 */
107
108BOOL SHELL_DeleteFileA(LPCSTR pszFile, BOOL bShowUI)
109{
110 if (bShowUI && !SHELL_WarnItemDelete(ASK_DELETE_FILE, pszFile))
111 return FALSE;
112
113 return DeleteFileA(pszFile);
114}
115
116/*************************************************************************
117 * SHCreateDirectory [SHELL32.165]
118 *
119 * NOTES
120 * exported by ordinal
121 * not sure about LPSECURITY_ATTRIBUTES
122 */
123DWORD WINAPI SHCreateDirectory(LPSECURITY_ATTRIBUTES sec,LPCSTR path)
124{
125 DWORD ret;
126 TRACE("(%p,%s)\n",sec,path);
127 if ((ret = CreateDirectoryA(path,sec)))
128 {
129 SHChangeNotifyA(SHCNE_MKDIR, SHCNF_PATHA, path, NULL);
130 }
131 return ret;
132}
133
134/************************************************************************
135 * Win32DeleteFile [SHELL32.164]
136 *
137 * Deletes a file. Also triggers a change notify if one exists.
138 *
139 * FIXME:
140 * Verified on Win98 / IE 5 (SHELL32 4.72, March 1999 build) to be
141 * ANSI. Is this Unicode on NT?
142 *
143 */
144
145BOOL WINAPI Win32DeleteFile(LPSTR fName)
146{
147 TRACE("%p(%s)\n", fName, fName);
148
149 DeleteFileA(fName);
150 SHChangeNotifyA(SHCNE_DELETE, SHCNF_PATHA, fName, NULL);
151 return TRUE;
152}
153
154/*************************************************************************
155 * SHFileOperationA [SHELL32.243]
156 *
157 * NOTES
158 * exported by name
159 */
160DWORD WINAPI SHFileOperationA (LPSHFILEOPSTRUCTA lpFileOp)
161{
162 LPSTR pFrom = (LPSTR)lpFileOp->pFrom;
163 LPSTR pTo = (LPSTR)lpFileOp->pTo;
164 LPSTR pTempTo;
165
166 switch(lpFileOp->wFunc) {
167 case FO_COPY:
168 TRACE("File Copy:\n");
169 while(1) {
170 if(!pFrom[0]) break;
171 if(!pTo[0]) break;
172 TRACE(" From='%s' To='%s'\n", pFrom, pTo);
173
174 pTempTo = HeapAlloc(GetProcessHeap(), 0, strlen(pTo)+1);
175 if (pTempTo)
176 {
177 strcpy( pTempTo, pTo );
178 PathRemoveFileSpecA(pTempTo);
179 TRACE(" Creating Directory '%s'\n", pTempTo);
180 SHCreateDirectory(NULL,pTempTo);
181 HeapFree(GetProcessHeap(), 0, pTempTo);
182 }
183 CopyFileA(pFrom, pTo, FALSE);
184
185 pFrom += strlen(pFrom) + 1;
186 pTo += strlen(pTo) + 1;
187 }
188 TRACE("Setting AnyOpsAborted=FALSE\n");
189 lpFileOp->fAnyOperationsAborted=FALSE;
190 return 0;
191
192 case FO_DELETE:
193 TRACE("File Delete:\n");
194 while(1) {
195 if(!pFrom[0]) break;
196 TRACE(" File='%s'\n", pFrom);
197 DeleteFileA(pFrom);
198 pFrom += strlen(pFrom) + 1;
199 }
200 TRACE("Setting AnyOpsAborted=FALSE\n");
201 lpFileOp->fAnyOperationsAborted=FALSE;
202 return 0;
203
204 default:
205 FIXME("Unhandled shell file operation %d\n", lpFileOp->wFunc);
206 }
207
208 return 1;
209}
210
211/*************************************************************************
212 * SHFileOperationW [SHELL32.244]
213 *
214 * NOTES
215 * exported by name
216 */
217DWORD WINAPI SHFileOperationW (LPSHFILEOPSTRUCTW lpFileOp)
218{
219 FIXME("(%p):stub.\n", lpFileOp);
220 return 1;
221}
222
223/*************************************************************************
224 * SHFileOperation [SHELL32.242]
225 *
226 */
227DWORD WINAPI SHFileOperationAW(LPVOID lpFileOp)
228{
229 if (SHELL_OsIsUnicode())
230 return SHFileOperationW(lpFileOp);
231 return SHFileOperationA(lpFileOp);
232}
233
234/*************************************************************************
235 * SheGetDirW [SHELL32.281]
236 *
237 */
238HRESULT WINAPI SheGetDirW(LPWSTR u, LPWSTR v)
239{ FIXME("%p %p stub\n",u,v);
240 return 0;
241}
242
243/*************************************************************************
244 * SheChangeDirW [SHELL32.274]
245 *
246 */
247HRESULT WINAPI SheChangeDirW(LPWSTR u)
248{ FIXME("(%s),stub\n",debugstr_w(u));
249 return 0;
250}
251
252/*************************************************************************
253 * IsNetDrive [SHELL32.66]
254 */
255BOOL WINAPI IsNetDrive(DWORD drive)
256{
257 char root[4];
258 strcpy(root, "A:\\");
259 root[0] += drive;
260 return (GetDriveTypeA(root) == DRIVE_REMOTE);
261}
Note: See TracBrowser for help on using the repository browser.