/*********************************************************************** * DelNode (ADVPACK.@) * * Deletes a file or directory * * PARAMS * pszFileOrDirName [I] Name of file or directory to delete * dwFlags [I] Flags; see include/advpub.h * * RETURNS * Success: S_OK * Failure: E_FAIL * * BUGS * - Ignores flags * - Native version apparently does a lot of checking to make sure * we're not trying to delete a system directory etc. */ HRESULT WINAPI DelNode( LPCSTR pszFileOrDirName, DWORD dwFlags ) { CHAR fname[MAX_PATH]; HRESULT ret = E_FAIL; FIXME("(%s, 0x%08x): flags ignored\n", debugstr_a(pszFileOrDirName), dwFlags); if (pszFileOrDirName && *pszFileOrDirName) { lstrcpyA(fname, pszFileOrDirName); /* TODO: Should check for system directory deletion etc. here */ ret = DELNODE_recurse_dirtree(fname, dwFlags); } return ret; }
/*********************************************************************** * DelNodeW (ADVPACK.@) * * Deletes a file or directory * * PARAMS * pszFileOrDirName [I] Name of file or directory to delete * dwFlags [I] Flags; see include/advpub.h * * RETURNS * Success: S_OK * Failure: E_FAIL * * BUGS * - Ignores flags * - Native version apparently does a lot of checking to make sure * we're not trying to delete a system directory etc. */ HRESULT WINAPI DelNodeW(LPCWSTR pszFileOrDirName, DWORD dwFlags) { WCHAR fname[MAX_PATH]; HRESULT ret = E_FAIL; TRACE("(%s, %d)\n", debugstr_w(pszFileOrDirName), dwFlags); if (dwFlags) FIXME("Flags ignored!\n"); if (pszFileOrDirName && *pszFileOrDirName) { lstrcpyW(fname, pszFileOrDirName); /* TODO: Should check for system directory deletion etc. here */ ret = DELNODE_recurse_dirtree(fname, dwFlags); } return ret; }
static HRESULT DELNODE_recurse_dirtree(LPWSTR fname, DWORD flags) { DWORD fattrs = GetFileAttributesW(fname); HRESULT ret = E_FAIL; static const WCHAR asterisk[] = {'*',0}; static const WCHAR dot[] = {'.',0}; static const WCHAR dotdot[] = {'.','.',0}; if (fattrs & FILE_ATTRIBUTE_DIRECTORY) { HANDLE hFindFile; WIN32_FIND_DATAW w32fd; BOOL done = TRUE; int fname_len = lstrlenW(fname); /* Generate a path with wildcard suitable for iterating */ if (fname_len && fname[fname_len-1] != '\\') fname[fname_len++] = '\\'; lstrcpyW(fname + fname_len, asterisk); if ((hFindFile = FindFirstFileW(fname, &w32fd)) != INVALID_HANDLE_VALUE) { /* Iterate through the files in the directory */ for (done = FALSE; !done; done = !FindNextFileW(hFindFile, &w32fd)) { TRACE("%s\n", debugstr_w(w32fd.cFileName)); if (lstrcmpW(dot, w32fd.cFileName) != 0 && lstrcmpW(dotdot, w32fd.cFileName) != 0) { lstrcpyW(fname + fname_len, w32fd.cFileName); if (DELNODE_recurse_dirtree(fname, flags) != S_OK) { break; /* Failure */ } } } FindClose(hFindFile); } /* We're done with this directory, so restore the old path without wildcard */ *(fname + fname_len) = '\0'; if (done) { TRACE("%s: directory\n", debugstr_w(fname)); if (SetFileAttributesW(fname, FILE_ATTRIBUTE_NORMAL) && RemoveDirectoryW(fname)) { ret = S_OK; } } } else { TRACE("%s: file\n", debugstr_w(fname)); if (SetFileAttributesW(fname, FILE_ATTRIBUTE_NORMAL) && DeleteFileW(fname)) { ret = S_OK; } } return ret; }
static HRESULT DELNODE_recurse_dirtree(LPSTR fname, DWORD flags) { DWORD fattrs = GetFileAttributesA(fname); HRESULT ret = E_FAIL; if (fattrs & FILE_ATTRIBUTE_DIRECTORY) { HANDLE hFindFile; WIN32_FIND_DATAA w32fd; BOOL done = TRUE; int fname_len = lstrlenA(fname); /* Generate a path with wildcard suitable for iterating */ if (fname[fname_len - 1] != '\\') { lstrcpyA(fname + fname_len, "\\"); ++fname_len; } lstrcpyA(fname + fname_len, "*"); if ((hFindFile = FindFirstFileA(fname, &w32fd)) != INVALID_HANDLE_VALUE) { /* Iterate through the files in the directory */ for (done = FALSE; !done; done = !FindNextFileA(hFindFile, &w32fd)) { TRACE("%s\n", w32fd.cFileName); if (lstrcmpA(".", w32fd.cFileName) != 0 && lstrcmpA("..", w32fd.cFileName) != 0) { lstrcpyA(fname + fname_len, w32fd.cFileName); if (DELNODE_recurse_dirtree(fname, flags) != S_OK) { break; /* Failure */ } } } FindClose(hFindFile); } /* We're done with this directory, so restore the old path without wildcard */ *(fname + fname_len) = '\0'; if (done) { TRACE("%s: directory\n", fname); if (SetFileAttributesA(fname, FILE_ATTRIBUTE_NORMAL) && RemoveDirectoryA(fname)) { ret = S_OK; } } } else { TRACE("%s: file\n", fname); if (SetFileAttributesA(fname, FILE_ATTRIBUTE_NORMAL) && DeleteFileA(fname)) { ret = S_OK; } } return ret; }