📄 shlfileop.c
字号:
retCode = SHNotifyDeleteFileW(wPath);
SHELL32_FreeUnicodeBuf(wPath);
}
return retCode;
}
/***********************************************************************/
static DWORD SHNotifyDeleteFileW(LPCWSTR path)
{
BOOL ret;
TRACE("(%s)\n", debugstr_w(path));
ret = DeleteFileW(path);
if (!ret)
{
/* File may be write protected or a system file */
DWORD dwAttr = GetFileAttributesW(path);
if (IsAttrib(dwAttr, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM))
if (SetFileAttributesW(path, dwAttr & ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM)))
ret = DeleteFileW(path);
}
if (ret)
{
SHChangeNotify(SHCNE_DELETE, SHCNF_PATHW, path, NULL);
return ERROR_SUCCESS;
}
return GetLastError();
}
/***********************************************************************/
DWORD WINAPI Win32DeleteFileAW(LPCVOID path)
{
if (SHELL_OsIsUnicode())
return (SHNotifyDeleteFileW(path) == ERROR_SUCCESS);
return (SHNotifyDeleteFileA(path) == ERROR_SUCCESS);
}
/************************************************************************
* SHNotifyMoveFile [internal]
*
* Moves a file. Also triggers a change notify if one exists.
*
* PARAMS
* src [I] path to source file to move
* dest [I] path to target file to move to
*
* RETURNS
* ERORR_SUCCESS if successful
*/
static DWORD SHNotifyMoveFileW(LPCWSTR src, LPCWSTR dest)
{
BOOL ret;
TRACE("(%s %s)\n", debugstr_w(src), debugstr_w(dest));
ret = MoveFileW(src, dest);
if (!ret)
{
DWORD dwAttr;
dwAttr = SHFindAttrW(dest, FALSE);
if (INVALID_FILE_ATTRIBUTES == dwAttr)
{
/* Source file may be write protected or a system file */
dwAttr = GetFileAttributesW(src);
if (IsAttrib(dwAttr, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM))
if (SetFileAttributesW(src, dwAttr & ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM)))
ret = MoveFileW(src, dest);
}
}
if (ret)
{
SHChangeNotify(SHCNE_RENAMEITEM, SHCNF_PATHW, src, dest);
return ERROR_SUCCESS;
}
return GetLastError();
}
/************************************************************************
* SHNotifyCopyFile [internal]
*
* Copies a file. Also triggers a change notify if one exists.
*
* PARAMS
* src [I] path to source file to move
* dest [I] path to target file to move to
* bFailIfExists [I] if TRUE, the target file will not be overwritten if
* a file with this name already exists
*
* RETURNS
* ERROR_SUCCESS if successful
*/
static DWORD SHNotifyCopyFileW(LPCWSTR src, LPCWSTR dest, BOOL bFailIfExists)
{
BOOL ret;
TRACE("(%s %s %s)\n", debugstr_w(src), debugstr_w(dest), bFailIfExists ? "failIfExists" : "");
ret = CopyFileW(src, dest, bFailIfExists);
if (ret)
{
SHChangeNotify(SHCNE_CREATE, SHCNF_PATHW, dest, NULL);
return ERROR_SUCCESS;
}
return GetLastError();
}
/*************************************************************************
* SHCreateDirectory [SHELL32.165]
*
* This function creates a file system folder whose fully qualified path is
* given by path. If one or more of the intermediate folders do not exist,
* they will be created as well.
*
* PARAMS
* hWnd [I]
* path [I] path of directory to create
*
* RETURNS
* ERRROR_SUCCESS or one of the following values:
* ERROR_BAD_PATHNAME if the path is relative
* ERROR_FILE_EXISTS when a file with that name exists
* ERROR_PATH_NOT_FOUND can't find the path, probably invalid
* ERROR_INVLID_NAME if the path contains invalid chars
* ERROR_ALREADY_EXISTS when the directory already exists
* ERROR_FILENAME_EXCED_RANGE if the filename was to long to process
*
* NOTES
* exported by ordinal
* Win9x exports ANSI
* WinNT/2000 exports Unicode
*/
DWORD WINAPI SHCreateDirectory(HWND hWnd, LPCVOID path)
{
if (SHELL_OsIsUnicode())
return SHCreateDirectoryExW(hWnd, path, NULL);
return SHCreateDirectoryExA(hWnd, path, NULL);
}
/*************************************************************************
* SHCreateDirectoryExA [SHELL32.@]
*
* This function creates a file system folder whose fully qualified path is
* given by path. If one or more of the intermediate folders do not exist,
* they will be created as well.
*
* PARAMS
* hWnd [I]
* path [I] path of directory to create
* sec [I] security attributes to use or NULL
*
* RETURNS
* ERRROR_SUCCESS or one of the following values:
* ERROR_BAD_PATHNAME or ERROR_PATH_NOT_FOUND if the path is relative
* ERROR_INVLID_NAME if the path contains invalid chars
* ERROR_FILE_EXISTS when a file with that name exists
* ERROR_ALREADY_EXISTS when the directory already exists
* ERROR_FILENAME_EXCED_RANGE if the filename was to long to process
*
* FIXME: Not implemented yet;
* SHCreateDirectoryEx also verifies that the files in the directory will be visible
* if the path is a network path to deal with network drivers which might have a limited
* but unknown maximum path length. If not:
*
* If hWnd is set to a valid window handle, a message box is displayed warning
* the user that the files may not be accessible. If the user chooses not to
* proceed, the function returns ERROR_CANCELLED.
*
* If hWnd is set to NULL, no user interface is displayed and the function
* returns ERROR_CANCELLED.
*/
int WINAPI SHCreateDirectoryExA(HWND hWnd, LPCSTR path, LPSECURITY_ATTRIBUTES sec)
{
LPWSTR wPath;
DWORD retCode;
TRACE("(%s, %p)\n", debugstr_a(path), sec);
retCode = SHELL32_AnsiToUnicodeBuf(path, &wPath, 0);
if (!retCode)
{
retCode = SHCreateDirectoryExW(hWnd, wPath, sec);
SHELL32_FreeUnicodeBuf(wPath);
}
return retCode;
}
/*************************************************************************
* SHCreateDirectoryExW [SHELL32.@]
*
* See SHCreateDirectoryExA.
*/
int WINAPI SHCreateDirectoryExW(HWND hWnd, LPCWSTR path, LPSECURITY_ATTRIBUTES sec)
{
int ret = ERROR_BAD_PATHNAME;
TRACE("(%p, %s, %p)\n", hWnd, debugstr_w(path), sec);
if (PathIsRelativeW(path))
{
SetLastError(ret);
}
else
{
ret = SHNotifyCreateDirectoryW(path, sec);
/* Refuse to work on certain error codes before trying to create directories recursively */
if (ret != ERROR_FILE_EXISTS &&
ret != ERROR_ALREADY_EXISTS &&
ret != ERROR_FILENAME_EXCED_RANGE)
{
WCHAR *pEnd, *pSlash, szTemp[MAX_PATH + 1]; /* extra for PathAddBackslash() */
lstrcpynW(szTemp, path, MAX_PATH);
pEnd = PathAddBackslashW(szTemp);
pSlash = szTemp + 3;
while (*pSlash)
{
while (*pSlash && *pSlash != '\\')
pSlash = CharNextW(pSlash);
if (*pSlash)
{
*pSlash = 0; /* terminate path at separator */
ret = SHNotifyCreateDirectoryW(szTemp, pSlash + 1 == pEnd ? sec : NULL);
}
*pSlash++ = '\\'; /* put the separator back */
}
}
if (ret && hWnd && (ERROR_CANCELLED != ret))
{
/* We failed and should show a dialog box */
FIXME("Show system error message, creating path %s, failed with error %d\n", debugstr_w(path), ret);
ret = ERROR_CANCELLED; /* Error has been already presented to user (not really yet!) */
}
}
return ret;
}
/*************************************************************************
* SHFindAttrW [internal]
*
* Get the Attributes for a file or directory. The difference to GetAttributes()
* is that this function will also work for paths containing wildcard characters
* in its filename.
* PARAMS
* path [I] path of directory or file to check
* fileOnly [I] TRUE if only files should be found
*
* RETURNS
* INVALID_FILE_ATTRIBUTES if the path does not exist, the actual attributes of
* the first file or directory found otherwise
*/
static DWORD SHFindAttrW(LPCWSTR pName, BOOL fileOnly)
{
WIN32_FIND_DATAW wfd;
BOOL b_FileMask = fileOnly && (NULL != StrPBrkW(pName, wWildcardChars));
DWORD dwAttr = INVALID_FILE_ATTRIBUTES;
HANDLE hFind = FindFirstFileW(pName, &wfd);
TRACE("%s %d\n", debugstr_w(pName), fileOnly);
if (INVALID_HANDLE_VALUE != hFind)
{
do
{
if (b_FileMask && IsAttribDir(wfd.dwFileAttributes))
continue;
dwAttr = wfd.dwFileAttributes;
break;
}
while (FindNextFileW(hFind, &wfd));
FindClose(hFind);
}
return dwAttr;
}
/*************************************************************************
*
* SHFileStrICmp HelperFunction for SHFileOperationW
*
*/
BOOL SHFileStrICmpW(LPWSTR p1, LPWSTR p2, LPWSTR p1End, LPWSTR p2End)
{
WCHAR C1 = '\0';
WCHAR C2 = '\0';
int i_Temp = -1;
int i_len1 = lstrlenW(p1);
int i_len2 = lstrlenW(p2);
if (p1End && (&p1[i_len1] >= p1End) && ('\\' == p1End[0]))
{
C1 = p1End[0];
p1End[0] = '\0';
i_len1 = lstrlenW(p1);
}
if (p2End)
{
if ((&p2[i_len2] >= p2End) && ('\\' == p2End[0]))
{
C2 = p2End[0];
if (C2)
p2End[0] = '\0';
}
}
else
{
if ((i_len1 <= i_len2) && ('\\' == p2[i_len1]))
{
C2 = p2[i_len1];
if (C2)
p2[i_len1] = '\0';
}
}
i_len2 = lstrlenW(p2);
if (i_len1 == i_len2)
i_Temp = lstrcmpiW(p1,p2);
if (C1)
p1[i_len1] = C1;
if (C2)
p2[i_len2] = C2;
return !(i_Temp);
}
/*************************************************************************
*
* SHFileStrCpyCat HelperFunction for SHFileOperationW
*
*/
LPWSTR SHFileStrCpyCatW(LPWSTR pTo, LPCWSTR pFrom, LPCWSTR pCatStr)
{
LPWSTR pToFile = NULL;
int i_len;
if (pTo)
{
if (pFrom)
lstrcpyW(pTo, pFrom);
if (pCatStr)
{
i_len = lstrlenW(pTo);
if ((i_len) && (pTo[--i_len] != '\\'))
i_len++;
pTo[i_len] = '\\';
if (pCatStr[0] == '\\')
pCatStr++; \
lstrcpyW(&pTo[i_len+1], pCatStr);
}
pToFile = StrRChrW(pTo,NULL,'\\');
if (!pToFile)
pToFile = pTo;
/* termination of the new string-group */
pTo[(lstrlenW(pTo)) + 1] = '\0';
}
return pToFile;
}
/**************************************************************************
* SHELL_FileNamesMatch()
*
* Accepts two \0 delimited lists of the file names. Checks whether number of
* files in both lists is the same, and checks also if source-name exists.
*/
BOOL SHELL_FileNamesMatch(LPCWSTR pszFiles1, LPCWSTR pszFiles2, BOOL bOnlySrc)
{
while ((pszFiles1[0] != '\0') &&
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -