📄 files.c
字号:
}
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;
}
/***********************************************************************
* DelNodeA (ADVPACK.@)
*
* See DelNodeW.
*/
HRESULT WINAPI DelNodeA(LPCSTR pszFileOrDirName, DWORD dwFlags)
{
UNICODE_STRING fileordirname;
HRESULT res;
TRACE("(%s, %d)\n", debugstr_a(pszFileOrDirName), dwFlags);
RtlCreateUnicodeStringFromAsciiz(&fileordirname, pszFileOrDirName);
res = DelNodeW(fileordirname.Buffer, dwFlags);
RtlFreeUnicodeString(&fileordirname);
return res;
}
/***********************************************************************
* 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;
}
/***********************************************************************
* DelNodeRunDLL32A (ADVPACK.@)
*
* See DelNodeRunDLL32W.
*/
HRESULT WINAPI DelNodeRunDLL32A(HWND hWnd, HINSTANCE hInst, LPSTR cmdline, INT show)
{
UNICODE_STRING params;
HRESULT hr;
TRACE("(%p, %p, %s, %i)\n", hWnd, hInst, debugstr_a(cmdline), show);
RtlCreateUnicodeStringFromAsciiz(¶ms, cmdline);
hr = DelNodeRunDLL32W(hWnd, hInst, params.Buffer, show);
RtlFreeUnicodeString(¶ms);
return hr;
}
/***********************************************************************
* DelNodeRunDLL32W (ADVPACK.@)
*
* Deletes a file or directory, WinMain style.
*
* PARAMS
* hWnd [I] Handle to the window used for the display.
* hInst [I] Instance of the process.
* cmdline [I] Contains parameters in the order FileOrDirName,Flags.
* show [I] How the window should be shown.
*
* RETURNS
* Success: S_OK.
* Failure: E_FAIL.
*/
HRESULT WINAPI DelNodeRunDLL32W(HWND hWnd, HINSTANCE hInst, LPWSTR cmdline, INT show)
{
LPWSTR szFilename, szFlags;
LPWSTR cmdline_copy, cmdline_ptr;
DWORD dwFlags = 0;
HRESULT res;
TRACE("(%p, %p, %s, %i)\n", hWnd, hInst, debugstr_w(cmdline), show);
cmdline_copy = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline) + 1) * sizeof(WCHAR));
cmdline_ptr = cmdline_copy;
lstrcpyW(cmdline_copy, cmdline);
/* get the parameters at indexes 0 and 1 respectively */
szFilename = get_parameter(&cmdline_ptr, ',');
szFlags = get_parameter(&cmdline_ptr, ',');
if (szFlags)
dwFlags = atolW(szFlags);
res = DelNodeW(szFilename, dwFlags);
HeapFree(GetProcessHeap(), 0, cmdline_copy);
return res;
}
/* The following defintions were copied from dlls/cabinet/cabinet.h */
/* EXTRACTdest flags */
#define EXTRACT_FILLFILELIST 0x00000001
#define EXTRACT_EXTRACTFILES 0x00000002
struct ExtractFileList {
LPSTR filename;
struct ExtractFileList *next;
BOOL unknown; /* always 1L */
} ;
/* the first parameter of the function Extract */
typedef struct {
long result1; /* 0x000 */
long unknown1[3]; /* 0x004 */
struct ExtractFileList *filelist; /* 0x010 */
long filecount; /* 0x014 */
DWORD flags; /* 0x018 */
char directory[0x104]; /* 0x01c */
char lastfile[0x20c]; /* 0x120 */
} EXTRACTdest;
static HRESULT (WINAPI *pExtract)(EXTRACTdest*, LPCSTR);
/* removes legal characters before and after file list, and
* converts the file list to a NULL-separated list
*/
static LPSTR convert_file_list(LPCSTR FileList, DWORD *dwNumFiles)
{
DWORD dwLen;
const char *first = FileList;
const char *last = FileList + strlen(FileList) - 1;
LPSTR szConvertedList, temp;
/* any number of these chars before the list is OK */
while (first < last && (*first == ' ' || *first == '\t' || *first == ':'))
first++;
/* any number of these chars after the list is OK */
while (last > first && (*last == ' ' || *last == '\t' || *last == ':'))
last--;
if (first == last)
return NULL;
dwLen = last - first + 3; /* room for double-null termination */
szConvertedList = HeapAlloc(GetProcessHeap(), 0, dwLen);
lstrcpynA(szConvertedList, first, dwLen - 1);
szConvertedList[dwLen - 1] = '\0';
szConvertedList[dwLen] = '\0';
/* empty list */
if (!lstrlenA(szConvertedList))
{
HeapFree(GetProcessHeap(), 0, szConvertedList);
return NULL;
}
*dwNumFiles = 1;
/* convert the colons to double-null termination */
temp = szConvertedList;
while (*temp)
{
if (*temp == ':')
{
*temp = '\0';
(*dwNumFiles)++;
}
temp++;
}
return szConvertedList;
}
static void free_file_node(struct ExtractFileList *pNode)
{
HeapFree(GetProcessHeap(), 0, pNode->filename);
HeapFree(GetProcessHeap(), 0, pNode);
}
/* determines whether szFile is in the NULL-separated szFileList */
static BOOL file_in_list(LPCSTR szFile, LPCSTR szFileList)
{
DWORD dwLen = lstrlenA(szFile);
DWORD dwTestLen;
while (*szFileList)
{
dwTestLen = lstrlenA(szFileList);
if (dwTestLen == dwLen)
{
if (!lstrcmpiA(szFile, szFileList))
return TRUE;
}
szFileList += dwTestLen + 1;
}
return FALSE;
}
/* removes nodes from the linked list that aren't specified in szFileList
* returns the number of files that are in both the linked list and szFileList
*/
static DWORD fill_file_list(EXTRACTdest *extractDest, LPCSTR szCabName, LPCSTR szFileList)
{
DWORD dwNumFound = 0;
struct ExtractFileList *pNode;
struct ExtractFileList *prev = NULL;
extractDest->flags |= EXTRACT_FILLFILELIST;
if (pExtract(extractDest, szCabName))
{
extractDest->flags &= ~EXTRACT_FILLFILELIST;
return -1;
}
pNode = extractDest->filelist;
while (pNode)
{
if (file_in_list(pNode->filename, szFileList))
{
prev = pNode;
pNode = pNode->next;
dwNumFound++;
}
else if (prev)
{
prev->next = pNode->next;
free_file_node(pNode);
pNode = prev->next;
}
else
{
extractDest->filelist = pNode->next;
free_file_node(pNode);
pNode = extractDest->filelist;
}
}
extractDest->flags &= ~EXTRACT_FILLFILELIST;
return dwNumFound;
}
/***********************************************************************
* ExtractFilesA (ADVPACK.@)
*
* Extracts the specified files from a cab archive into
* a destination directory.
*
* PARAMS
* CabName [I] Filename of the cab archive.
* ExpandDir [I] Destination directory for the extracted files.
* Flags [I] Reserved.
* FileList [I] Optional list of files to extract. See NOTES.
* LReserved [I] Reserved. Must be NULL.
* Reserved [I] Reserved. Must be 0.
*
* RETURNS
* Success: S_OK.
* Failure: E_FAIL.
*
* NOTES
* FileList is a colon-separated list of filenames. If FileList is
* non-NULL, only the files in the list will be extracted from the
* cab file, otherwise all files will be extracted. Any number of
* spaces, tabs, or colons can be before or after the list, but
* the list itself must only be separated by colons.
*/
HRESULT WINAPI ExtractFilesA(LPCSTR CabName, LPCSTR ExpandDir, DWORD Flags,
LPCSTR FileList, LPVOID LReserved, DWORD Reserved)
{
EXTRACTdest extractDest;
HMODULE hCabinet;
HRESULT res = S_OK;
DWORD dwFileCount = 0;
DWORD dwFilesFound = 0;
LPSTR szConvertedList = NULL;
TRACE("(%s, %s, %d, %s, %p, %d)\n", debugstr_a(CabName), debugstr_a(ExpandDir),
Flags, debugstr_a(FileList), LReserved, Reserved);
if (!CabName || !ExpandDir)
return E_INVALIDARG;
if (GetFileAttributesA(ExpandDir) == INVALID_FILE_ATTRIBUTES)
return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
hCabinet = LoadLibraryA("cabinet.dll");
if (!hCabinet)
return E_FAIL;
pExtract = (void *)GetProcAddress(hCabinet, "Extract");
if (!pExtract)
{
res = E_FAIL;
goto done;
}
ZeroMemory(&extractDest, sizeof(EXTRACTdest));
lstrcpyA(extractDest.directory, ExpandDir);
if (FileList)
{
szConvertedList = convert_file_list(FileList, &dwFileCount);
if (!szConvertedList || dwFileCount == -1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -