2006-01-13 14:16:02 +01:00
|
|
|
/*
|
|
|
|
* Advpack file functions
|
|
|
|
*
|
|
|
|
* Copyright 2006 James Hawkins
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2006-01-13 14:16:02 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2006-01-21 19:18:40 +01:00
|
|
|
#include <stdlib.h>
|
2006-01-13 14:16:02 +01:00
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
2006-01-13 14:16:29 +01:00
|
|
|
#include "winreg.h"
|
|
|
|
#include "winver.h"
|
2006-03-22 20:51:44 +01:00
|
|
|
#include "winternl.h"
|
2006-01-13 14:16:29 +01:00
|
|
|
#include "setupapi.h"
|
2006-01-13 14:16:02 +01:00
|
|
|
#include "advpub.h"
|
2007-08-23 02:41:04 +02:00
|
|
|
#include "fdi.h"
|
2006-01-13 14:16:02 +01:00
|
|
|
#include "wine/debug.h"
|
2006-03-22 20:51:44 +01:00
|
|
|
#include "wine/unicode.h"
|
2006-04-18 23:13:26 +02:00
|
|
|
#include "advpack_private.h"
|
2006-01-13 14:16:02 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(advpack);
|
|
|
|
|
2006-03-22 20:51:44 +01:00
|
|
|
/* converts an ansi double null-terminated list to a unicode list */
|
|
|
|
static LPWSTR ansi_to_unicode_list(LPCSTR ansi_list)
|
|
|
|
{
|
|
|
|
DWORD len, wlen = 0;
|
|
|
|
LPWSTR list;
|
|
|
|
LPCSTR ptr = ansi_list;
|
|
|
|
|
|
|
|
while (*ptr) ptr += lstrlenA(ptr) + 1;
|
|
|
|
len = ptr + 1 - ansi_list;
|
|
|
|
wlen = MultiByteToWideChar(CP_ACP, 0, ansi_list, len, NULL, 0);
|
|
|
|
list = HeapAlloc(GetProcessHeap(), 0, wlen * sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, ansi_list, len, list, wlen);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2006-01-14 17:09:02 +01:00
|
|
|
/***********************************************************************
|
2006-02-24 16:09:42 +01:00
|
|
|
* AddDelBackupEntryA (ADVPACK.@)
|
2006-01-14 17:09:02 +01:00
|
|
|
*
|
2006-03-22 20:51:44 +01:00
|
|
|
* See AddDelBackupEntryW.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI AddDelBackupEntryA(LPCSTR lpcszFileList, LPCSTR lpcszBackupDir,
|
|
|
|
LPCSTR lpcszBaseName, DWORD dwFlags)
|
|
|
|
{
|
|
|
|
UNICODE_STRING backupdir, basename;
|
2006-09-21 04:51:53 +02:00
|
|
|
LPWSTR filelist;
|
|
|
|
LPCWSTR backup;
|
2006-03-22 20:51:44 +01:00
|
|
|
HRESULT res;
|
|
|
|
|
2006-10-07 04:06:59 +02:00
|
|
|
TRACE("(%s, %s, %s, %d)\n", debugstr_a(lpcszFileList),
|
2006-04-11 07:17:13 +02:00
|
|
|
debugstr_a(lpcszBackupDir), debugstr_a(lpcszBaseName), dwFlags);
|
2006-03-22 20:51:44 +01:00
|
|
|
|
|
|
|
if (lpcszFileList)
|
|
|
|
filelist = ansi_to_unicode_list(lpcszFileList);
|
|
|
|
else
|
|
|
|
filelist = NULL;
|
|
|
|
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&backupdir, lpcszBackupDir);
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&basename, lpcszBaseName);
|
|
|
|
|
|
|
|
if (lpcszBackupDir)
|
|
|
|
backup = backupdir.Buffer;
|
|
|
|
else
|
|
|
|
backup = NULL;
|
|
|
|
|
|
|
|
res = AddDelBackupEntryW(filelist, backup, basename.Buffer, dwFlags);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, filelist);
|
|
|
|
|
|
|
|
RtlFreeUnicodeString(&backupdir);
|
|
|
|
RtlFreeUnicodeString(&basename);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* AddDelBackupEntryW (ADVPACK.@)
|
|
|
|
*
|
2006-01-21 19:21:51 +01:00
|
|
|
* Either appends the files in the file list to the backup section of
|
|
|
|
* the specified INI, or deletes the entries from the INI file.
|
2006-01-14 17:09:02 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpcszFileList [I] NULL-separated list of filenames.
|
|
|
|
* lpcszBackupDir [I] Path of the backup directory.
|
2006-01-21 19:21:51 +01:00
|
|
|
* lpcszBaseName [I] Basename of the INI file.
|
|
|
|
* dwFlags [I] AADBE_ADD_ENTRY adds the entries in the file list
|
|
|
|
* to the INI file, while AADBE_DEL_ENTRY removes
|
|
|
|
* the entries from the INI file.
|
2006-01-14 17:09:02 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2006-02-21 04:46:19 +01:00
|
|
|
* S_OK in all cases.
|
2006-01-14 17:09:02 +01:00
|
|
|
*
|
2006-01-21 19:21:51 +01:00
|
|
|
* NOTES
|
|
|
|
* If the INI file does not exist before adding entries to it, the file
|
|
|
|
* will be created.
|
|
|
|
*
|
|
|
|
* If lpcszBackupDir is NULL, the INI file is assumed to exist in
|
|
|
|
* c:\windows or created there if it does not exist.
|
2006-01-14 17:09:02 +01:00
|
|
|
*/
|
2006-03-22 20:51:44 +01:00
|
|
|
HRESULT WINAPI AddDelBackupEntryW(LPCWSTR lpcszFileList, LPCWSTR lpcszBackupDir,
|
|
|
|
LPCWSTR lpcszBaseName, DWORD dwFlags)
|
2006-01-14 17:09:02 +01:00
|
|
|
{
|
2006-03-22 20:51:44 +01:00
|
|
|
WCHAR szIniPath[MAX_PATH];
|
2006-08-29 21:12:39 +02:00
|
|
|
LPCWSTR szString = NULL;
|
2006-02-21 04:49:27 +01:00
|
|
|
|
2006-03-22 20:51:44 +01:00
|
|
|
static const WCHAR szBackupEntry[] = {
|
|
|
|
'-','1',',','0',',','0',',','0',',','0',',','0',',','-','1',0
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WCHAR backslash[] = {'\\',0};
|
|
|
|
static const WCHAR ini[] = {'.','i','n','i',0};
|
|
|
|
static const WCHAR backup[] = {'b','a','c','k','u','p',0};
|
2006-02-21 04:49:27 +01:00
|
|
|
|
2006-10-07 04:06:59 +02:00
|
|
|
TRACE("(%s, %s, %s, %d)\n", debugstr_w(lpcszFileList),
|
2006-04-11 07:17:13 +02:00
|
|
|
debugstr_w(lpcszBackupDir), debugstr_w(lpcszBaseName), dwFlags);
|
2006-01-14 17:09:02 +01:00
|
|
|
|
2006-02-21 04:49:27 +01:00
|
|
|
if (!lpcszFileList || !*lpcszFileList)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
if (lpcszBackupDir)
|
2006-03-22 20:51:44 +01:00
|
|
|
lstrcpyW(szIniPath, lpcszBackupDir);
|
2006-02-21 04:49:27 +01:00
|
|
|
else
|
2006-03-22 20:51:44 +01:00
|
|
|
GetWindowsDirectoryW(szIniPath, MAX_PATH);
|
2006-02-21 04:49:27 +01:00
|
|
|
|
2006-03-22 20:51:44 +01:00
|
|
|
lstrcatW(szIniPath, backslash);
|
|
|
|
lstrcatW(szIniPath, lpcszBaseName);
|
|
|
|
lstrcatW(szIniPath, ini);
|
2006-02-21 04:49:27 +01:00
|
|
|
|
2006-03-22 20:51:44 +01:00
|
|
|
SetFileAttributesW(szIniPath, FILE_ATTRIBUTE_NORMAL);
|
2006-02-21 04:49:27 +01:00
|
|
|
|
|
|
|
if (dwFlags & AADBE_ADD_ENTRY)
|
2006-08-29 21:12:39 +02:00
|
|
|
szString = szBackupEntry;
|
2006-02-21 04:49:27 +01:00
|
|
|
else if (dwFlags & AADBE_DEL_ENTRY)
|
|
|
|
szString = NULL;
|
|
|
|
|
|
|
|
/* add or delete the INI entries */
|
|
|
|
while (*lpcszFileList)
|
|
|
|
{
|
2006-03-22 20:51:44 +01:00
|
|
|
WritePrivateProfileStringW(backup, lpcszFileList, szString, szIniPath);
|
|
|
|
lpcszFileList += lstrlenW(lpcszFileList) + 1;
|
2006-02-21 04:49:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* hide the INI file */
|
2006-03-22 20:51:44 +01:00
|
|
|
SetFileAttributesW(szIniPath, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN);
|
2006-02-21 04:49:27 +01:00
|
|
|
|
2006-02-21 04:46:19 +01:00
|
|
|
return S_OK;
|
2006-01-14 17:09:02 +01:00
|
|
|
}
|
|
|
|
|
2006-01-13 14:16:29 +01:00
|
|
|
/* FIXME: this is only for the local case, X:\ */
|
|
|
|
#define ROOT_LENGTH 3
|
|
|
|
|
2006-10-09 09:04:08 +02:00
|
|
|
static UINT CALLBACK pQuietQueueCallback(PVOID Context, UINT Notification,
|
|
|
|
UINT_PTR Param1, UINT_PTR Param2)
|
2006-01-13 14:16:29 +01:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-10-09 09:04:08 +02:00
|
|
|
static UINT CALLBACK pQueueCallback(PVOID Context, UINT Notification,
|
|
|
|
UINT_PTR Param1, UINT_PTR Param2)
|
2006-01-13 14:16:29 +01:00
|
|
|
{
|
|
|
|
/* only be verbose for error notifications */
|
|
|
|
if (!Notification ||
|
|
|
|
Notification == SPFILENOTIFY_RENAMEERROR ||
|
|
|
|
Notification == SPFILENOTIFY_DELETEERROR ||
|
|
|
|
Notification == SPFILENOTIFY_COPYERROR)
|
|
|
|
{
|
2006-03-22 21:34:41 +01:00
|
|
|
return SetupDefaultQueueCallbackW(Context, Notification,
|
2006-01-13 14:16:29 +01:00
|
|
|
Param1, Param2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2006-02-24 16:09:42 +01:00
|
|
|
* AdvInstallFileA (ADVPACK.@)
|
2006-01-13 14:16:29 +01:00
|
|
|
*
|
2006-03-22 21:34:41 +01:00
|
|
|
* See AdvInstallFileW.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI AdvInstallFileA(HWND hwnd, LPCSTR lpszSourceDir, LPCSTR lpszSourceFile,
|
2006-04-11 07:08:54 +02:00
|
|
|
LPCSTR lpszDestDir, LPCSTR lpszDestFile,
|
|
|
|
DWORD dwFlags, DWORD dwReserved)
|
2006-03-22 21:34:41 +01:00
|
|
|
{
|
|
|
|
UNICODE_STRING sourcedir, sourcefile;
|
|
|
|
UNICODE_STRING destdir, destfile;
|
|
|
|
HRESULT res;
|
|
|
|
|
2006-10-07 04:06:59 +02:00
|
|
|
TRACE("(%p, %s, %s, %s, %s, %d, %d)\n", hwnd, debugstr_a(lpszSourceDir),
|
2006-03-22 21:34:41 +01:00
|
|
|
debugstr_a(lpszSourceFile), debugstr_a(lpszDestDir),
|
|
|
|
debugstr_a(lpszDestFile), dwFlags, dwReserved);
|
|
|
|
|
|
|
|
if (!lpszSourceDir || !lpszSourceFile || !lpszDestDir)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&sourcedir, lpszSourceDir);
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&sourcefile, lpszSourceFile);
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&destdir, lpszDestDir);
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&destfile, lpszDestFile);
|
|
|
|
|
|
|
|
res = AdvInstallFileW(hwnd, sourcedir.Buffer, sourcefile.Buffer,
|
|
|
|
destdir.Buffer, destfile.Buffer, dwFlags, dwReserved);
|
|
|
|
|
|
|
|
RtlFreeUnicodeString(&sourcedir);
|
|
|
|
RtlFreeUnicodeString(&sourcefile);
|
|
|
|
RtlFreeUnicodeString(&destdir);
|
|
|
|
RtlFreeUnicodeString(&destfile);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* AdvInstallFileW (ADVPACK.@)
|
|
|
|
*
|
2006-01-13 14:16:29 +01:00
|
|
|
* Copies a file from the source to a destination.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hwnd [I] Handle to the window used for messages.
|
|
|
|
* lpszSourceDir [I] Source directory.
|
|
|
|
* lpszSourceFile [I] Source filename.
|
|
|
|
* lpszDestDir [I] Destination directory.
|
|
|
|
* lpszDestFile [I] Optional destination filename.
|
|
|
|
* dwFlags [I] See advpub.h.
|
|
|
|
* dwReserved [I] Reserved. Must be 0.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK.
|
|
|
|
* Failure: E_FAIL.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If lpszDestFile is NULL, the destination filename is the same as
|
|
|
|
* lpszSourceFIle.
|
|
|
|
*/
|
2006-03-22 21:34:41 +01:00
|
|
|
HRESULT WINAPI AdvInstallFileW(HWND hwnd, LPCWSTR lpszSourceDir, LPCWSTR lpszSourceFile,
|
|
|
|
LPCWSTR lpszDestDir, LPCWSTR lpszDestFile,
|
|
|
|
DWORD dwFlags, DWORD dwReserved)
|
2006-01-13 14:16:29 +01:00
|
|
|
{
|
2006-03-22 21:34:41 +01:00
|
|
|
PSP_FILE_CALLBACK_W pFileCallback;
|
2006-08-29 21:12:39 +02:00
|
|
|
LPWSTR szDestFilename;
|
|
|
|
LPCWSTR szPath;
|
2006-03-22 21:34:41 +01:00
|
|
|
WCHAR szRootPath[ROOT_LENGTH];
|
2006-01-13 14:16:29 +01:00
|
|
|
DWORD dwLen, dwLastError;
|
|
|
|
HSPFILEQ fileQueue;
|
|
|
|
PVOID pContext;
|
|
|
|
|
2006-10-07 04:06:59 +02:00
|
|
|
TRACE("(%p, %s, %s, %s, %s, %d, %d)\n", hwnd, debugstr_w(lpszSourceDir),
|
2006-03-22 21:34:41 +01:00
|
|
|
debugstr_w(lpszSourceFile), debugstr_w(lpszDestDir),
|
|
|
|
debugstr_w(lpszDestFile), dwFlags, dwReserved);
|
2006-01-13 14:16:29 +01:00
|
|
|
|
|
|
|
if (!lpszSourceDir || !lpszSourceFile || !lpszDestDir)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
fileQueue = SetupOpenFileQueue();
|
|
|
|
if (fileQueue == INVALID_HANDLE_VALUE)
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
|
|
|
|
pContext = NULL;
|
|
|
|
dwLastError = ERROR_SUCCESS;
|
|
|
|
|
2006-03-22 21:34:41 +01:00
|
|
|
lstrcpynW(szRootPath, lpszSourceDir, ROOT_LENGTH);
|
2006-08-29 21:12:39 +02:00
|
|
|
szPath = lpszSourceDir + ROOT_LENGTH;
|
2006-01-13 14:16:29 +01:00
|
|
|
|
|
|
|
/* use lpszSourceFile as destination filename if lpszDestFile is NULL */
|
|
|
|
if (lpszDestFile)
|
|
|
|
{
|
2006-03-22 21:34:41 +01:00
|
|
|
dwLen = lstrlenW(lpszDestFile);
|
2009-11-27 06:46:51 +01:00
|
|
|
szDestFilename = HeapAlloc(GetProcessHeap(), 0, (dwLen+1) * sizeof(WCHAR));
|
2006-03-22 21:34:41 +01:00
|
|
|
lstrcpyW(szDestFilename, lpszDestFile);
|
2006-01-13 14:16:29 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-22 21:34:41 +01:00
|
|
|
dwLen = lstrlenW(lpszSourceFile);
|
2009-11-27 06:46:51 +01:00
|
|
|
szDestFilename = HeapAlloc(GetProcessHeap(), 0, (dwLen+1) * sizeof(WCHAR));
|
2006-03-22 21:34:41 +01:00
|
|
|
lstrcpyW(szDestFilename, lpszSourceFile);
|
2006-01-13 14:16:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* add the file copy operation to the setup queue */
|
2006-03-22 21:34:41 +01:00
|
|
|
if (!SetupQueueCopyW(fileQueue, szRootPath, szPath, lpszSourceFile, NULL,
|
2006-01-13 14:16:29 +01:00
|
|
|
NULL, lpszDestDir, szDestFilename, dwFlags))
|
|
|
|
{
|
|
|
|
dwLastError = GetLastError();
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
pContext = SetupInitDefaultQueueCallbackEx(hwnd, INVALID_HANDLE_VALUE,
|
|
|
|
0, 0, NULL);
|
|
|
|
if (!pContext)
|
|
|
|
{
|
|
|
|
dwLastError = GetLastError();
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* don't output anything for AIF_QUIET */
|
|
|
|
if (dwFlags & AIF_QUIET)
|
|
|
|
pFileCallback = pQuietQueueCallback;
|
|
|
|
else
|
|
|
|
pFileCallback = pQueueCallback;
|
|
|
|
|
|
|
|
/* perform the file copy */
|
2006-03-22 21:34:41 +01:00
|
|
|
if (!SetupCommitFileQueueW(hwnd, fileQueue, pFileCallback, pContext))
|
2006-01-13 14:16:29 +01:00
|
|
|
{
|
|
|
|
dwLastError = GetLastError();
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
SetupTermDefaultQueueCallback(pContext);
|
|
|
|
SetupCloseFileQueue(fileQueue);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, szDestFilename);
|
|
|
|
|
|
|
|
return HRESULT_FROM_WIN32(dwLastError);
|
|
|
|
}
|
|
|
|
|
2006-03-24 06:11:00 +01:00
|
|
|
static HRESULT DELNODE_recurse_dirtree(LPWSTR fname, DWORD flags)
|
2006-01-13 14:16:29 +01:00
|
|
|
{
|
2006-03-24 06:11:00 +01:00
|
|
|
DWORD fattrs = GetFileAttributesW(fname);
|
2006-01-13 14:16:29 +01:00
|
|
|
HRESULT ret = E_FAIL;
|
|
|
|
|
2006-03-24 06:11:00 +01:00
|
|
|
static const WCHAR asterisk[] = {'*',0};
|
|
|
|
static const WCHAR dot[] = {'.',0};
|
|
|
|
static const WCHAR dotdot[] = {'.','.',0};
|
|
|
|
|
2006-01-13 14:16:29 +01:00
|
|
|
if (fattrs & FILE_ATTRIBUTE_DIRECTORY)
|
|
|
|
{
|
|
|
|
HANDLE hFindFile;
|
2006-03-24 06:11:00 +01:00
|
|
|
WIN32_FIND_DATAW w32fd;
|
2006-01-13 14:16:29 +01:00
|
|
|
BOOL done = TRUE;
|
2006-03-24 06:11:00 +01:00
|
|
|
int fname_len = lstrlenW(fname);
|
2006-01-13 14:16:29 +01:00
|
|
|
|
|
|
|
/* Generate a path with wildcard suitable for iterating */
|
2007-06-25 14:02:29 +02:00
|
|
|
if (fname_len && fname[fname_len-1] != '\\') fname[fname_len++] = '\\';
|
2006-03-24 06:11:00 +01:00
|
|
|
lstrcpyW(fname + fname_len, asterisk);
|
2006-01-13 14:16:29 +01:00
|
|
|
|
2006-03-24 06:11:00 +01:00
|
|
|
if ((hFindFile = FindFirstFileW(fname, &w32fd)) != INVALID_HANDLE_VALUE)
|
2006-01-13 14:16:29 +01:00
|
|
|
{
|
|
|
|
/* Iterate through the files in the directory */
|
2006-03-24 06:11:00 +01:00
|
|
|
for (done = FALSE; !done; done = !FindNextFileW(hFindFile, &w32fd))
|
2006-01-13 14:16:29 +01:00
|
|
|
{
|
2006-03-24 06:11:00 +01:00
|
|
|
TRACE("%s\n", debugstr_w(w32fd.cFileName));
|
|
|
|
if (lstrcmpW(dot, w32fd.cFileName) != 0 &&
|
|
|
|
lstrcmpW(dotdot, w32fd.cFileName) != 0)
|
2006-01-13 14:16:29 +01:00
|
|
|
{
|
2006-03-24 06:11:00 +01:00
|
|
|
lstrcpyW(fname + fname_len, w32fd.cFileName);
|
2006-01-13 14:16:29 +01:00
|
|
|
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)
|
|
|
|
{
|
2006-03-24 06:11:00 +01:00
|
|
|
TRACE("%s: directory\n", debugstr_w(fname));
|
|
|
|
if (SetFileAttributesW(fname, FILE_ATTRIBUTE_NORMAL) && RemoveDirectoryW(fname))
|
2006-01-13 14:16:29 +01:00
|
|
|
{
|
|
|
|
ret = S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-24 06:11:00 +01:00
|
|
|
TRACE("%s: file\n", debugstr_w(fname));
|
|
|
|
if (SetFileAttributesW(fname, FILE_ATTRIBUTE_NORMAL) && DeleteFileW(fname))
|
2006-01-13 14:16:29 +01:00
|
|
|
{
|
|
|
|
ret = S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2006-02-24 16:09:42 +01:00
|
|
|
* DelNodeA (ADVPACK.@)
|
2006-01-13 14:16:29 +01:00
|
|
|
*
|
2006-03-24 06:11:00 +01:00
|
|
|
* See DelNodeW.
|
|
|
|
*/
|
2006-04-11 07:08:54 +02:00
|
|
|
HRESULT WINAPI DelNodeA(LPCSTR pszFileOrDirName, DWORD dwFlags)
|
2006-03-24 06:11:00 +01:00
|
|
|
{
|
|
|
|
UNICODE_STRING fileordirname;
|
|
|
|
HRESULT res;
|
|
|
|
|
2006-10-07 04:06:59 +02:00
|
|
|
TRACE("(%s, %d)\n", debugstr_a(pszFileOrDirName), dwFlags);
|
2006-03-24 06:11:00 +01:00
|
|
|
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&fileordirname, pszFileOrDirName);
|
|
|
|
|
|
|
|
res = DelNodeW(fileordirname.Buffer, dwFlags);
|
|
|
|
|
|
|
|
RtlFreeUnicodeString(&fileordirname);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DelNodeW (ADVPACK.@)
|
|
|
|
*
|
2006-01-13 14:16:29 +01:00
|
|
|
* 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.
|
|
|
|
*/
|
2006-04-11 07:08:54 +02:00
|
|
|
HRESULT WINAPI DelNodeW(LPCWSTR pszFileOrDirName, DWORD dwFlags)
|
2006-01-13 14:16:29 +01:00
|
|
|
{
|
2006-03-24 06:11:00 +01:00
|
|
|
WCHAR fname[MAX_PATH];
|
2006-01-13 14:16:29 +01:00
|
|
|
HRESULT ret = E_FAIL;
|
|
|
|
|
2006-10-07 04:06:59 +02:00
|
|
|
TRACE("(%s, %d)\n", debugstr_w(pszFileOrDirName), dwFlags);
|
2006-01-13 14:16:29 +01:00
|
|
|
|
|
|
|
if (dwFlags)
|
|
|
|
FIXME("Flags ignored!\n");
|
|
|
|
|
|
|
|
if (pszFileOrDirName && *pszFileOrDirName)
|
|
|
|
{
|
2006-03-24 06:11:00 +01:00
|
|
|
lstrcpyW(fname, pszFileOrDirName);
|
2006-01-13 14:16:29 +01:00
|
|
|
|
|
|
|
/* TODO: Should check for system directory deletion etc. here */
|
|
|
|
|
|
|
|
ret = DELNODE_recurse_dirtree(fname, dwFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2006-02-24 16:09:42 +01:00
|
|
|
* DelNodeRunDLL32A (ADVPACK.@)
|
2006-01-13 14:16:29 +01:00
|
|
|
*
|
2006-04-07 12:28:17 +02:00
|
|
|
* 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.@)
|
|
|
|
*
|
2006-01-13 14:16:29 +01:00
|
|
|
* 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.
|
|
|
|
*/
|
2006-04-07 12:28:17 +02:00
|
|
|
HRESULT WINAPI DelNodeRunDLL32W(HWND hWnd, HINSTANCE hInst, LPWSTR cmdline, INT show)
|
2006-01-13 14:16:29 +01:00
|
|
|
{
|
2006-04-07 12:28:17 +02:00
|
|
|
LPWSTR szFilename, szFlags;
|
|
|
|
LPWSTR cmdline_copy, cmdline_ptr;
|
2006-04-07 12:20:58 +02:00
|
|
|
DWORD dwFlags = 0;
|
2006-01-21 19:18:40 +01:00
|
|
|
HRESULT res;
|
|
|
|
|
2006-04-07 12:28:17 +02:00
|
|
|
TRACE("(%p, %p, %s, %i)\n", hWnd, hInst, debugstr_w(cmdline), show);
|
2006-04-07 12:20:58 +02:00
|
|
|
|
2006-04-07 12:28:17 +02:00
|
|
|
cmdline_copy = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline) + 1) * sizeof(WCHAR));
|
2006-04-07 12:20:58 +02:00
|
|
|
cmdline_ptr = cmdline_copy;
|
2006-04-07 12:28:17 +02:00
|
|
|
lstrcpyW(cmdline_copy, cmdline);
|
2006-01-21 19:18:40 +01:00
|
|
|
|
|
|
|
/* get the parameters at indexes 0 and 1 respectively */
|
2006-04-07 12:20:58 +02:00
|
|
|
szFilename = get_parameter(&cmdline_ptr, ',');
|
|
|
|
szFlags = get_parameter(&cmdline_ptr, ',');
|
2006-01-21 19:18:40 +01:00
|
|
|
|
2006-04-07 12:20:58 +02:00
|
|
|
if (szFlags)
|
2006-04-07 12:28:17 +02:00
|
|
|
dwFlags = atolW(szFlags);
|
2006-01-21 19:18:40 +01:00
|
|
|
|
2006-04-07 12:28:17 +02:00
|
|
|
res = DelNodeW(szFilename, dwFlags);
|
2006-01-21 19:18:40 +01:00
|
|
|
|
2006-04-07 12:20:58 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, cmdline_copy);
|
2006-01-21 19:18:40 +01:00
|
|
|
|
|
|
|
return res;
|
2006-01-13 14:16:29 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 00:04:38 +01:00
|
|
|
/* The following definitions were copied from dlls/cabinet/cabinet.h */
|
2006-01-13 14:16:29 +01:00
|
|
|
|
2007-08-23 02:41:04 +02:00
|
|
|
/* SESSION Operation */
|
2006-01-13 14:16:29 +01:00
|
|
|
#define EXTRACT_FILLFILELIST 0x00000001
|
|
|
|
#define EXTRACT_EXTRACTFILES 0x00000002
|
|
|
|
|
2007-08-23 02:41:04 +02:00
|
|
|
struct FILELIST{
|
|
|
|
LPSTR FileName;
|
|
|
|
struct FILELIST *next;
|
2007-08-27 03:15:41 +02:00
|
|
|
BOOL DoExtract;
|
2007-08-23 02:41:04 +02:00
|
|
|
};
|
2006-01-13 14:16:29 +01:00
|
|
|
|
|
|
|
typedef struct {
|
2007-08-23 02:41:04 +02:00
|
|
|
INT FileSize;
|
|
|
|
ERF Error;
|
|
|
|
struct FILELIST *FileList;
|
|
|
|
INT FileCount;
|
|
|
|
INT Operation;
|
|
|
|
CHAR Destination[MAX_PATH];
|
|
|
|
CHAR CurrentFile[MAX_PATH];
|
|
|
|
CHAR Reserved[MAX_PATH];
|
|
|
|
struct FILELIST *FilterList;
|
|
|
|
} SESSION;
|
|
|
|
|
|
|
|
static HRESULT (WINAPI *pExtract)(SESSION*, LPCSTR);
|
2006-01-13 14:16:29 +01:00
|
|
|
|
|
|
|
/* 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;
|
2006-09-07 23:25:14 +02:00
|
|
|
const char *first = FileList;
|
|
|
|
const char *last = FileList + strlen(FileList) - 1;
|
2006-01-13 14:16:29 +01:00
|
|
|
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';
|
|
|
|
|
|
|
|
/* empty list */
|
|
|
|
if (!lstrlenA(szConvertedList))
|
2006-10-21 08:49:10 +02:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, szConvertedList);
|
2006-01-13 14:16:29 +01:00
|
|
|
return NULL;
|
2006-10-21 08:49:10 +02:00
|
|
|
}
|
2006-01-13 14:16:29 +01:00
|
|
|
|
|
|
|
*dwNumFiles = 1;
|
|
|
|
|
|
|
|
/* convert the colons to double-null termination */
|
|
|
|
temp = szConvertedList;
|
|
|
|
while (*temp)
|
|
|
|
{
|
|
|
|
if (*temp == ':')
|
|
|
|
{
|
|
|
|
*temp = '\0';
|
|
|
|
(*dwNumFiles)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
temp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return szConvertedList;
|
|
|
|
}
|
|
|
|
|
2007-08-23 02:41:04 +02:00
|
|
|
static void free_file_node(struct FILELIST *pNode)
|
2006-01-13 14:16:29 +01:00
|
|
|
{
|
2007-08-23 02:41:04 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, pNode->FileName);
|
2006-01-13 14:16:29 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, pNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* determines whether szFile is in the NULL-separated szFileList */
|
2007-03-12 21:49:29 +01:00
|
|
|
static BOOL file_in_list(LPCSTR szFile, LPCSTR szFileList)
|
2006-01-13 14:16:29 +01:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-08-27 03:15:41 +02:00
|
|
|
|
|
|
|
/* returns the number of files that are in both the linked list and szFileList */
|
2007-08-23 02:41:04 +02:00
|
|
|
static DWORD fill_file_list(SESSION *session, LPCSTR szCabName, LPCSTR szFileList)
|
2006-01-13 14:16:29 +01:00
|
|
|
{
|
|
|
|
DWORD dwNumFound = 0;
|
2007-08-23 02:41:04 +02:00
|
|
|
struct FILELIST *pNode;
|
2006-01-13 14:16:29 +01:00
|
|
|
|
2007-08-23 02:41:04 +02:00
|
|
|
session->Operation |= EXTRACT_FILLFILELIST;
|
2008-09-12 14:00:55 +02:00
|
|
|
if (pExtract(session, szCabName) != S_OK)
|
2006-01-13 14:16:29 +01:00
|
|
|
{
|
2007-08-23 02:41:04 +02:00
|
|
|
session->Operation &= ~EXTRACT_FILLFILELIST;
|
2006-01-13 14:16:29 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-08-23 02:41:04 +02:00
|
|
|
pNode = session->FileList;
|
2006-01-13 14:16:29 +01:00
|
|
|
while (pNode)
|
|
|
|
{
|
2007-08-27 03:15:41 +02:00
|
|
|
if (!file_in_list(pNode->FileName, szFileList))
|
|
|
|
pNode->DoExtract = FALSE;
|
2006-01-13 14:16:29 +01:00
|
|
|
else
|
2007-08-27 03:15:41 +02:00
|
|
|
dwNumFound++;
|
|
|
|
|
|
|
|
pNode = pNode->next;
|
2006-01-13 14:16:29 +01:00
|
|
|
}
|
|
|
|
|
2007-08-23 02:41:04 +02:00
|
|
|
session->Operation &= ~EXTRACT_FILLFILELIST;
|
2006-01-13 14:16:29 +01:00
|
|
|
return dwNumFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2006-02-24 16:09:42 +01:00
|
|
|
* ExtractFilesA (ADVPACK.@)
|
2006-01-13 14:16:29 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2006-04-11 07:08:54 +02:00
|
|
|
HRESULT WINAPI ExtractFilesA(LPCSTR CabName, LPCSTR ExpandDir, DWORD Flags,
|
|
|
|
LPCSTR FileList, LPVOID LReserved, DWORD Reserved)
|
2006-01-13 14:16:29 +01:00
|
|
|
{
|
2007-08-23 02:41:04 +02:00
|
|
|
SESSION session;
|
2006-01-13 14:16:29 +01:00
|
|
|
HMODULE hCabinet;
|
|
|
|
HRESULT res = S_OK;
|
|
|
|
DWORD dwFileCount = 0;
|
|
|
|
DWORD dwFilesFound = 0;
|
|
|
|
LPSTR szConvertedList = NULL;
|
|
|
|
|
2006-10-07 04:06:59 +02:00
|
|
|
TRACE("(%s, %s, %d, %s, %p, %d)\n", debugstr_a(CabName), debugstr_a(ExpandDir),
|
2006-04-11 07:17:13 +02:00
|
|
|
Flags, debugstr_a(FileList), LReserved, Reserved);
|
2006-01-13 14:16:29 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-08-23 02:41:04 +02:00
|
|
|
ZeroMemory(&session, sizeof(SESSION));
|
|
|
|
lstrcpyA(session.Destination, ExpandDir);
|
2006-01-13 14:16:29 +01:00
|
|
|
|
|
|
|
if (FileList)
|
|
|
|
{
|
|
|
|
szConvertedList = convert_file_list(FileList, &dwFileCount);
|
2008-07-19 11:08:00 +02:00
|
|
|
if (!szConvertedList)
|
2006-01-13 14:16:29 +01:00
|
|
|
{
|
|
|
|
res = E_FAIL;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2007-08-23 02:41:04 +02:00
|
|
|
dwFilesFound = fill_file_list(&session, CabName, szConvertedList);
|
2006-01-13 14:16:29 +01:00
|
|
|
if (dwFilesFound != dwFileCount)
|
|
|
|
{
|
|
|
|
res = E_FAIL;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2007-08-23 02:41:04 +02:00
|
|
|
session.Operation |= EXTRACT_FILLFILELIST;
|
2006-01-13 14:16:29 +01:00
|
|
|
|
2007-08-23 02:41:04 +02:00
|
|
|
session.Operation |= EXTRACT_EXTRACTFILES;
|
|
|
|
res = pExtract(&session, CabName);
|
2006-01-13 14:16:29 +01:00
|
|
|
|
2007-08-23 02:41:04 +02:00
|
|
|
if (session.FileList)
|
2006-10-21 08:49:10 +02:00
|
|
|
{
|
2007-08-23 02:41:04 +02:00
|
|
|
struct FILELIST *curr = session.FileList;
|
|
|
|
struct FILELIST *next;
|
2006-10-21 08:49:10 +02:00
|
|
|
|
|
|
|
while (curr)
|
|
|
|
{
|
|
|
|
next = curr->next;
|
|
|
|
free_file_node(curr);
|
|
|
|
curr = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-13 14:16:29 +01:00
|
|
|
done:
|
|
|
|
FreeLibrary(hCabinet);
|
|
|
|
HeapFree(GetProcessHeap(), 0, szConvertedList);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2009-06-09 19:15:12 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ExtractFilesW (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.
|
|
|
|
*
|
|
|
|
* BUGS
|
|
|
|
* Unimplemented.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI ExtractFilesW(LPCWSTR CabName, LPCWSTR ExpandDir, DWORD Flags,
|
|
|
|
LPCWSTR FileList, LPVOID LReserved, DWORD Reserved)
|
|
|
|
{
|
|
|
|
|
|
|
|
FIXME("(%s, %s, %d, %s, %p, %d) stub!\n", debugstr_w(CabName), debugstr_w(ExpandDir),
|
|
|
|
Flags, debugstr_w(FileList), LReserved, Reserved);
|
|
|
|
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2006-01-13 14:16:02 +01:00
|
|
|
/***********************************************************************
|
2006-02-24 16:09:42 +01:00
|
|
|
* FileSaveMarkNotExistA (ADVPACK.@)
|
2006-01-13 14:16:02 +01:00
|
|
|
*
|
2006-03-22 21:40:55 +01:00
|
|
|
* See FileSaveMarkNotExistW.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI FileSaveMarkNotExistA(LPSTR pszFileList, LPSTR pszDir, LPSTR pszBaseName)
|
|
|
|
{
|
2006-04-11 07:17:13 +02:00
|
|
|
TRACE("(%s, %s, %s)\n", debugstr_a(pszFileList),
|
|
|
|
debugstr_a(pszDir), debugstr_a(pszBaseName));
|
2006-03-22 21:40:55 +01:00
|
|
|
|
|
|
|
return AddDelBackupEntryA(pszFileList, pszDir, pszBaseName, AADBE_DEL_ENTRY);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FileSaveMarkNotExistW (ADVPACK.@)
|
|
|
|
*
|
2006-01-13 14:16:02 +01:00
|
|
|
* Marks the files in the file list as not existing so they won't be
|
|
|
|
* backed up during a save.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pszFileList [I] NULL-separated list of filenames.
|
|
|
|
* pszDir [I] Path of the backup directory.
|
2006-01-21 19:21:07 +01:00
|
|
|
* pszBaseName [I] Basename of the INI file.
|
2006-01-13 14:16:02 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK.
|
|
|
|
* Failure: E_FAIL.
|
|
|
|
*/
|
2006-03-22 21:40:55 +01:00
|
|
|
HRESULT WINAPI FileSaveMarkNotExistW(LPWSTR pszFileList, LPWSTR pszDir, LPWSTR pszBaseName)
|
2006-01-13 14:16:02 +01:00
|
|
|
{
|
2006-04-11 07:17:13 +02:00
|
|
|
TRACE("(%s, %s, %s)\n", debugstr_w(pszFileList),
|
|
|
|
debugstr_w(pszDir), debugstr_w(pszBaseName));
|
2006-01-13 14:16:02 +01:00
|
|
|
|
2006-03-22 21:40:55 +01:00
|
|
|
return AddDelBackupEntryW(pszFileList, pszDir, pszBaseName, AADBE_DEL_ENTRY);
|
2006-01-13 14:16:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2006-02-24 16:09:42 +01:00
|
|
|
* FileSaveRestoreA (ADVPACK.@)
|
2006-01-13 14:16:02 +01:00
|
|
|
*
|
2006-03-24 06:10:43 +01:00
|
|
|
* See FileSaveRestoreW.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI FileSaveRestoreA(HWND hDlg, LPSTR pszFileList, LPSTR pszDir,
|
|
|
|
LPSTR pszBaseName, DWORD dwFlags)
|
|
|
|
{
|
|
|
|
UNICODE_STRING filelist, dir, basename;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2006-10-07 04:06:59 +02:00
|
|
|
TRACE("(%p, %s, %s, %s, %d)\n", hDlg, debugstr_a(pszFileList),
|
2006-04-11 07:17:13 +02:00
|
|
|
debugstr_a(pszDir), debugstr_a(pszBaseName), dwFlags);
|
2006-03-24 06:10:43 +01:00
|
|
|
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&filelist, pszFileList);
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&dir, pszDir);
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&basename, pszBaseName);
|
|
|
|
|
|
|
|
hr = FileSaveRestoreW(hDlg, filelist.Buffer, dir.Buffer,
|
|
|
|
basename.Buffer, dwFlags);
|
|
|
|
|
|
|
|
RtlFreeUnicodeString(&filelist);
|
|
|
|
RtlFreeUnicodeString(&dir);
|
|
|
|
RtlFreeUnicodeString(&basename);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FileSaveRestoreW (ADVPACK.@)
|
|
|
|
*
|
2006-01-13 14:16:02 +01:00
|
|
|
* Saves or restores the files in the specified file list.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hDlg [I] Handle to the dialog used for the display.
|
|
|
|
* pszFileList [I] NULL-separated list of filenames.
|
|
|
|
* pszDir [I] Path of the backup directory.
|
|
|
|
* pszBaseName [I] Basename of the backup files.
|
|
|
|
* dwFlags [I] See advpub.h.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK.
|
|
|
|
* Failure: E_FAIL.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If pszFileList is NULL on restore, all files will be restored.
|
|
|
|
*
|
|
|
|
* BUGS
|
|
|
|
* Unimplemented.
|
|
|
|
*/
|
2006-03-24 06:10:43 +01:00
|
|
|
HRESULT WINAPI FileSaveRestoreW(HWND hDlg, LPWSTR pszFileList, LPWSTR pszDir,
|
|
|
|
LPWSTR pszBaseName, DWORD dwFlags)
|
2006-01-13 14:16:02 +01:00
|
|
|
{
|
2006-10-07 04:06:59 +02:00
|
|
|
FIXME("(%p, %s, %s, %s, %d) stub\n", hDlg, debugstr_w(pszFileList),
|
2006-03-24 06:10:43 +01:00
|
|
|
debugstr_w(pszDir), debugstr_w(pszBaseName), dwFlags);
|
2006-01-13 14:16:02 +01:00
|
|
|
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2006-02-24 16:09:42 +01:00
|
|
|
* FileSaveRestoreOnINFA (ADVPACK.@)
|
2006-01-13 14:16:02 +01:00
|
|
|
*
|
2006-03-24 06:10:43 +01:00
|
|
|
* See FileSaveRestoreOnINFW.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI FileSaveRestoreOnINFA(HWND hWnd, LPCSTR pszTitle, LPCSTR pszINF,
|
|
|
|
LPCSTR pszSection, LPCSTR pszBackupDir,
|
|
|
|
LPCSTR pszBaseBackupFile, DWORD dwFlags)
|
|
|
|
{
|
|
|
|
UNICODE_STRING title, inf, section;
|
|
|
|
UNICODE_STRING backupdir, backupfile;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2006-10-07 04:06:59 +02:00
|
|
|
TRACE("(%p, %s, %s, %s, %s, %s, %d)\n", hWnd, debugstr_a(pszTitle),
|
2006-04-11 07:17:13 +02:00
|
|
|
debugstr_a(pszINF), debugstr_a(pszSection), debugstr_a(pszBackupDir),
|
|
|
|
debugstr_a(pszBaseBackupFile), dwFlags);
|
2006-03-24 06:10:43 +01:00
|
|
|
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&title, pszTitle);
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&inf, pszINF);
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(§ion, pszSection);
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&backupdir, pszBackupDir);
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&backupfile, pszBaseBackupFile);
|
|
|
|
|
|
|
|
hr = FileSaveRestoreOnINFW(hWnd, title.Buffer, inf.Buffer, section.Buffer,
|
|
|
|
backupdir.Buffer, backupfile.Buffer, dwFlags);
|
|
|
|
|
|
|
|
RtlFreeUnicodeString(&title);
|
|
|
|
RtlFreeUnicodeString(&inf);
|
|
|
|
RtlFreeUnicodeString(§ion);
|
|
|
|
RtlFreeUnicodeString(&backupdir);
|
|
|
|
RtlFreeUnicodeString(&backupfile);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FileSaveRestoreOnINFW (ADVPACK.@)
|
|
|
|
*
|
2006-01-13 14:16:02 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hWnd [I] Handle to the window used for the display.
|
|
|
|
* pszTitle [I] Title of the window.
|
|
|
|
* pszINF [I] Fully-qualified INF filename.
|
|
|
|
* pszSection [I] GenInstall INF section name.
|
|
|
|
* pszBackupDir [I] Directory to store the backup file.
|
|
|
|
* pszBaseBackupFile [I] Basename of the backup files.
|
|
|
|
* dwFlags [I] See advpub.h
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK.
|
|
|
|
* Failure: E_FAIL.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If pszSection is NULL, the default section will be used.
|
|
|
|
*
|
|
|
|
* BUGS
|
|
|
|
* Unimplemented.
|
|
|
|
*/
|
2006-03-24 06:10:43 +01:00
|
|
|
HRESULT WINAPI FileSaveRestoreOnINFW(HWND hWnd, LPCWSTR pszTitle, LPCWSTR pszINF,
|
|
|
|
LPCWSTR pszSection, LPCWSTR pszBackupDir,
|
|
|
|
LPCWSTR pszBaseBackupFile, DWORD dwFlags)
|
2006-01-13 14:16:02 +01:00
|
|
|
{
|
2006-10-07 04:06:59 +02:00
|
|
|
FIXME("(%p, %s, %s, %s, %s, %s, %d): stub\n", hWnd, debugstr_w(pszTitle),
|
2006-03-24 06:10:43 +01:00
|
|
|
debugstr_w(pszINF), debugstr_w(pszSection), debugstr_w(pszBackupDir),
|
|
|
|
debugstr_w(pszBaseBackupFile), dwFlags);
|
2006-01-13 14:16:02 +01:00
|
|
|
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2006-01-13 14:16:29 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
2006-02-24 16:09:42 +01:00
|
|
|
* GetVersionFromFileA (ADVPACK.@)
|
2006-01-13 14:16:29 +01:00
|
|
|
*
|
2006-03-24 06:10:21 +01:00
|
|
|
* See GetVersionFromFileExW.
|
2006-01-13 14:16:29 +01:00
|
|
|
*/
|
2006-02-24 16:09:42 +01:00
|
|
|
HRESULT WINAPI GetVersionFromFileA(LPCSTR Filename, LPDWORD MajorVer,
|
2006-01-13 14:16:29 +01:00
|
|
|
LPDWORD MinorVer, BOOL Version )
|
|
|
|
{
|
2006-04-11 07:17:13 +02:00
|
|
|
TRACE("(%s, %p, %p, %d)\n", debugstr_a(Filename), MajorVer, MinorVer, Version);
|
2006-02-24 16:09:42 +01:00
|
|
|
return GetVersionFromFileExA(Filename, MajorVer, MinorVer, Version);
|
2006-01-13 14:16:29 +01:00
|
|
|
}
|
|
|
|
|
2006-03-24 06:10:21 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* GetVersionFromFileW (ADVPACK.@)
|
|
|
|
*
|
|
|
|
* See GetVersionFromFileExW.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI GetVersionFromFileW(LPCWSTR Filename, LPDWORD MajorVer,
|
|
|
|
LPDWORD MinorVer, BOOL Version )
|
|
|
|
{
|
|
|
|
TRACE("(%s, %p, %p, %d)\n", debugstr_w(Filename), MajorVer, MinorVer, Version);
|
|
|
|
return GetVersionFromFileExW(Filename, MajorVer, MinorVer, Version);
|
|
|
|
}
|
|
|
|
|
2006-01-13 14:16:29 +01:00
|
|
|
/* data for GetVersionFromFileEx */
|
|
|
|
typedef struct tagLANGANDCODEPAGE
|
|
|
|
{
|
|
|
|
WORD wLanguage;
|
|
|
|
WORD wCodePage;
|
|
|
|
} LANGANDCODEPAGE;
|
|
|
|
|
|
|
|
/***********************************************************************
|
2006-02-24 16:09:42 +01:00
|
|
|
* GetVersionFromFileExA (ADVPACK.@)
|
2006-01-13 14:16:29 +01:00
|
|
|
*
|
2006-03-24 06:10:21 +01:00
|
|
|
* See GetVersionFromFileExW.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI GetVersionFromFileExA(LPCSTR lpszFilename, LPDWORD pdwMSVer,
|
|
|
|
LPDWORD pdwLSVer, BOOL bVersion )
|
|
|
|
{
|
|
|
|
UNICODE_STRING filename;
|
|
|
|
HRESULT res;
|
|
|
|
|
2006-04-11 07:17:13 +02:00
|
|
|
TRACE("(%s, %p, %p, %d)\n", debugstr_a(lpszFilename),
|
|
|
|
pdwMSVer, pdwLSVer, bVersion);
|
2006-03-24 06:10:21 +01:00
|
|
|
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&filename, lpszFilename);
|
|
|
|
|
|
|
|
res = GetVersionFromFileExW(filename.Buffer, pdwMSVer, pdwLSVer, bVersion);
|
|
|
|
|
|
|
|
RtlFreeUnicodeString(&filename);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetVersionFromFileExW (ADVPACK.@)
|
|
|
|
*
|
2006-01-13 14:16:29 +01:00
|
|
|
* Gets the files version or language information.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszFilename [I] The file to get the info from.
|
|
|
|
* pdwMSVer [O] Major version.
|
|
|
|
* pdwLSVer [O] Minor version.
|
|
|
|
* bVersion [I] Whether to retrieve version or language info.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Always returns S_OK.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If bVersion is TRUE, version information is retrieved, else
|
|
|
|
* pdwMSVer gets the language ID and pdwLSVer gets the codepage ID.
|
|
|
|
*/
|
2006-03-24 06:10:21 +01:00
|
|
|
HRESULT WINAPI GetVersionFromFileExW(LPCWSTR lpszFilename, LPDWORD pdwMSVer,
|
2006-01-13 14:16:29 +01:00
|
|
|
LPDWORD pdwLSVer, BOOL bVersion )
|
|
|
|
{
|
|
|
|
VS_FIXEDFILEINFO *pFixedVersionInfo;
|
|
|
|
LANGANDCODEPAGE *pLangAndCodePage;
|
|
|
|
DWORD dwHandle, dwInfoSize;
|
2006-03-24 06:10:21 +01:00
|
|
|
WCHAR szWinDir[MAX_PATH];
|
|
|
|
WCHAR szFile[MAX_PATH];
|
2006-01-13 14:16:29 +01:00
|
|
|
LPVOID pVersionInfo = NULL;
|
|
|
|
BOOL bFileCopied = FALSE;
|
|
|
|
UINT uValueLen;
|
|
|
|
|
2008-06-19 00:32:00 +02:00
|
|
|
static const WCHAR backslash[] = {'\\',0};
|
|
|
|
static const WCHAR translation[] = {
|
2006-03-24 06:10:21 +01:00
|
|
|
'\\','V','a','r','F','i','l','e','I','n','f','o',
|
|
|
|
'\\','T','r','a','n','s','l','a','t','i','o','n',0
|
|
|
|
};
|
|
|
|
|
|
|
|
TRACE("(%s, %p, %p, %d)\n", debugstr_w(lpszFilename),
|
|
|
|
pdwMSVer, pdwLSVer, bVersion);
|
2006-01-13 14:16:29 +01:00
|
|
|
|
|
|
|
*pdwLSVer = 0;
|
|
|
|
*pdwMSVer = 0;
|
|
|
|
|
2006-03-24 06:10:21 +01:00
|
|
|
lstrcpynW(szFile, lpszFilename, MAX_PATH);
|
2006-01-13 14:16:29 +01:00
|
|
|
|
2006-03-24 06:10:21 +01:00
|
|
|
dwInfoSize = GetFileVersionInfoSizeW(szFile, &dwHandle);
|
2006-01-13 14:16:29 +01:00
|
|
|
if (!dwInfoSize)
|
|
|
|
{
|
|
|
|
/* check that the file exists */
|
2006-03-24 06:10:21 +01:00
|
|
|
if (GetFileAttributesW(szFile) == INVALID_FILE_ATTRIBUTES)
|
2006-01-13 14:16:29 +01:00
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
/* file exists, but won't be found by GetFileVersionInfoSize,
|
|
|
|
* so copy it to the temp dir where it will be found.
|
|
|
|
*/
|
2006-03-24 06:10:21 +01:00
|
|
|
GetWindowsDirectoryW(szWinDir, MAX_PATH);
|
|
|
|
GetTempFileNameW(szWinDir, NULL, 0, szFile);
|
|
|
|
CopyFileW(lpszFilename, szFile, FALSE);
|
2006-01-13 14:16:29 +01:00
|
|
|
bFileCopied = TRUE;
|
|
|
|
|
2006-03-24 06:10:21 +01:00
|
|
|
dwInfoSize = GetFileVersionInfoSizeW(szFile, &dwHandle);
|
2006-01-13 14:16:29 +01:00
|
|
|
if (!dwInfoSize)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
pVersionInfo = HeapAlloc(GetProcessHeap(), 0, dwInfoSize);
|
|
|
|
if (!pVersionInfo)
|
|
|
|
goto done;
|
|
|
|
|
2006-03-24 06:10:21 +01:00
|
|
|
if (!GetFileVersionInfoW(szFile, dwHandle, dwInfoSize, pVersionInfo))
|
2006-01-13 14:16:29 +01:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (bVersion)
|
|
|
|
{
|
2006-03-24 06:10:21 +01:00
|
|
|
if (!VerQueryValueW(pVersionInfo, backslash,
|
2006-01-13 14:16:29 +01:00
|
|
|
(LPVOID *)&pFixedVersionInfo, &uValueLen))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (!uValueLen)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
*pdwMSVer = pFixedVersionInfo->dwFileVersionMS;
|
|
|
|
*pdwLSVer = pFixedVersionInfo->dwFileVersionLS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-24 06:10:21 +01:00
|
|
|
if (!VerQueryValueW(pVersionInfo, translation,
|
2006-01-13 14:16:29 +01:00
|
|
|
(LPVOID *)&pLangAndCodePage, &uValueLen))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (!uValueLen)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
*pdwMSVer = pLangAndCodePage->wLanguage;
|
|
|
|
*pdwLSVer = pLangAndCodePage->wCodePage;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
HeapFree(GetProcessHeap(), 0, pVersionInfo);
|
|
|
|
|
|
|
|
if (bFileCopied)
|
2006-03-24 06:10:21 +01:00
|
|
|
DeleteFileW(szFile);
|
2006-01-13 14:16:29 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|