2 * Advpack file functions
4 * Copyright 2006 James Hawkins
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #include "wine/debug.h"
35 #include "advpack_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(advpack
);
39 /* converts an ansi double null-terminated list to a unicode list */
40 static LPWSTR
ansi_to_unicode_list(LPCSTR ansi_list
)
44 LPCSTR ptr
= ansi_list
;
46 while (*ptr
) ptr
+= lstrlenA(ptr
) + 1;
47 len
= ptr
+ 1 - ansi_list
;
48 wlen
= MultiByteToWideChar(CP_ACP
, 0, ansi_list
, len
, NULL
, 0);
49 list
= HeapAlloc(GetProcessHeap(), 0, wlen
* sizeof(WCHAR
));
50 MultiByteToWideChar(CP_ACP
, 0, ansi_list
, len
, list
, wlen
);
54 /***********************************************************************
55 * AddDelBackupEntryA (ADVPACK.@)
57 * See AddDelBackupEntryW.
59 HRESULT WINAPI
AddDelBackupEntryA(LPCSTR lpcszFileList
, LPCSTR lpcszBackupDir
,
60 LPCSTR lpcszBaseName
, DWORD dwFlags
)
62 UNICODE_STRING backupdir
, basename
;
67 TRACE("(%s, %s, %s, %ld)\n", debugstr_a(lpcszFileList
),
68 debugstr_a(lpcszBackupDir
), debugstr_a(lpcszBaseName
), dwFlags
);
71 filelist
= ansi_to_unicode_list(lpcszFileList
);
75 RtlCreateUnicodeStringFromAsciiz(&backupdir
, lpcszBackupDir
);
76 RtlCreateUnicodeStringFromAsciiz(&basename
, lpcszBaseName
);
79 backup
= backupdir
.Buffer
;
83 res
= AddDelBackupEntryW(filelist
, backup
, basename
.Buffer
, dwFlags
);
85 HeapFree(GetProcessHeap(), 0, filelist
);
87 RtlFreeUnicodeString(&backupdir
);
88 RtlFreeUnicodeString(&basename
);
93 /***********************************************************************
94 * AddDelBackupEntryW (ADVPACK.@)
96 * Either appends the files in the file list to the backup section of
97 * the specified INI, or deletes the entries from the INI file.
100 * lpcszFileList [I] NULL-separated list of filenames.
101 * lpcszBackupDir [I] Path of the backup directory.
102 * lpcszBaseName [I] Basename of the INI file.
103 * dwFlags [I] AADBE_ADD_ENTRY adds the entries in the file list
104 * to the INI file, while AADBE_DEL_ENTRY removes
105 * the entries from the INI file.
111 * If the INI file does not exist before adding entries to it, the file
114 * If lpcszBackupDir is NULL, the INI file is assumed to exist in
115 * c:\windows or created there if it does not exist.
117 HRESULT WINAPI
AddDelBackupEntryW(LPCWSTR lpcszFileList
, LPCWSTR lpcszBackupDir
,
118 LPCWSTR lpcszBaseName
, DWORD dwFlags
)
120 WCHAR szIniPath
[MAX_PATH
];
121 LPCWSTR szString
= NULL
;
123 TRACE("(%s, %s, %s, %ld)\n", debugstr_w(lpcszFileList
),
124 debugstr_w(lpcszBackupDir
), debugstr_w(lpcszBaseName
), dwFlags
);
126 if (!lpcszFileList
|| !*lpcszFileList
)
130 lstrcpyW(szIniPath
, lpcszBackupDir
);
132 GetWindowsDirectoryW(szIniPath
, MAX_PATH
);
134 lstrcatW(szIniPath
, L
"\\");
135 lstrcatW(szIniPath
, lpcszBaseName
);
136 lstrcatW(szIniPath
, L
".ini");
138 SetFileAttributesW(szIniPath
, FILE_ATTRIBUTE_NORMAL
);
140 if (dwFlags
& AADBE_ADD_ENTRY
)
141 szString
= L
"-1,0,0,0,0,0,-1";
142 else if (dwFlags
& AADBE_DEL_ENTRY
)
145 /* add or delete the INI entries */
146 while (*lpcszFileList
)
148 WritePrivateProfileStringW(L
"backup", lpcszFileList
, szString
, szIniPath
);
149 lpcszFileList
+= lstrlenW(lpcszFileList
) + 1;
152 /* hide the INI file */
153 SetFileAttributesW(szIniPath
, FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_HIDDEN
);
158 /* FIXME: this is only for the local case, X:\ */
159 #define ROOT_LENGTH 3
161 static UINT CALLBACK
pQuietQueueCallback(PVOID Context
, UINT Notification
,
162 UINT_PTR Param1
, UINT_PTR Param2
)
167 static UINT CALLBACK
pQueueCallback(PVOID Context
, UINT Notification
,
168 UINT_PTR Param1
, UINT_PTR Param2
)
170 /* only be verbose for error notifications */
172 Notification
== SPFILENOTIFY_RENAMEERROR
||
173 Notification
== SPFILENOTIFY_DELETEERROR
||
174 Notification
== SPFILENOTIFY_COPYERROR
)
176 return SetupDefaultQueueCallbackW(Context
, Notification
,
183 /***********************************************************************
184 * AdvInstallFileA (ADVPACK.@)
186 * See AdvInstallFileW.
188 HRESULT WINAPI
AdvInstallFileA(HWND hwnd
, LPCSTR lpszSourceDir
, LPCSTR lpszSourceFile
,
189 LPCSTR lpszDestDir
, LPCSTR lpszDestFile
,
190 DWORD dwFlags
, DWORD dwReserved
)
192 UNICODE_STRING sourcedir
, sourcefile
;
193 UNICODE_STRING destdir
, destfile
;
196 TRACE("(%p, %s, %s, %s, %s, %ld, %ld)\n", hwnd
, debugstr_a(lpszSourceDir
),
197 debugstr_a(lpszSourceFile
), debugstr_a(lpszDestDir
),
198 debugstr_a(lpszDestFile
), dwFlags
, dwReserved
);
200 if (!lpszSourceDir
|| !lpszSourceFile
|| !lpszDestDir
)
203 RtlCreateUnicodeStringFromAsciiz(&sourcedir
, lpszSourceDir
);
204 RtlCreateUnicodeStringFromAsciiz(&sourcefile
, lpszSourceFile
);
205 RtlCreateUnicodeStringFromAsciiz(&destdir
, lpszDestDir
);
206 RtlCreateUnicodeStringFromAsciiz(&destfile
, lpszDestFile
);
208 res
= AdvInstallFileW(hwnd
, sourcedir
.Buffer
, sourcefile
.Buffer
,
209 destdir
.Buffer
, destfile
.Buffer
, dwFlags
, dwReserved
);
211 RtlFreeUnicodeString(&sourcedir
);
212 RtlFreeUnicodeString(&sourcefile
);
213 RtlFreeUnicodeString(&destdir
);
214 RtlFreeUnicodeString(&destfile
);
219 /***********************************************************************
220 * AdvInstallFileW (ADVPACK.@)
222 * Copies a file from the source to a destination.
225 * hwnd [I] Handle to the window used for messages.
226 * lpszSourceDir [I] Source directory.
227 * lpszSourceFile [I] Source filename.
228 * lpszDestDir [I] Destination directory.
229 * lpszDestFile [I] Optional destination filename.
230 * dwFlags [I] See advpub.h.
231 * dwReserved [I] Reserved. Must be 0.
238 * If lpszDestFile is NULL, the destination filename is the same as
241 HRESULT WINAPI
AdvInstallFileW(HWND hwnd
, LPCWSTR lpszSourceDir
, LPCWSTR lpszSourceFile
,
242 LPCWSTR lpszDestDir
, LPCWSTR lpszDestFile
,
243 DWORD dwFlags
, DWORD dwReserved
)
245 PSP_FILE_CALLBACK_W pFileCallback
;
246 LPWSTR szDestFilename
;
248 WCHAR szRootPath
[ROOT_LENGTH
];
249 DWORD dwLen
, dwLastError
;
253 TRACE("(%p, %s, %s, %s, %s, %ld, %ld)\n", hwnd
, debugstr_w(lpszSourceDir
),
254 debugstr_w(lpszSourceFile
), debugstr_w(lpszDestDir
),
255 debugstr_w(lpszDestFile
), dwFlags
, dwReserved
);
257 if (!lpszSourceDir
|| !lpszSourceFile
|| !lpszDestDir
)
260 fileQueue
= SetupOpenFileQueue();
261 if (fileQueue
== INVALID_HANDLE_VALUE
)
262 return HRESULT_FROM_WIN32(GetLastError());
265 dwLastError
= ERROR_SUCCESS
;
267 lstrcpynW(szRootPath
, lpszSourceDir
, ROOT_LENGTH
);
268 szPath
= lpszSourceDir
+ ROOT_LENGTH
;
270 /* use lpszSourceFile as destination filename if lpszDestFile is NULL */
273 dwLen
= lstrlenW(lpszDestFile
);
274 szDestFilename
= HeapAlloc(GetProcessHeap(), 0, (dwLen
+1) * sizeof(WCHAR
));
275 lstrcpyW(szDestFilename
, lpszDestFile
);
279 dwLen
= lstrlenW(lpszSourceFile
);
280 szDestFilename
= HeapAlloc(GetProcessHeap(), 0, (dwLen
+1) * sizeof(WCHAR
));
281 lstrcpyW(szDestFilename
, lpszSourceFile
);
284 /* add the file copy operation to the setup queue */
285 if (!SetupQueueCopyW(fileQueue
, szRootPath
, szPath
, lpszSourceFile
, NULL
,
286 NULL
, lpszDestDir
, szDestFilename
, dwFlags
))
288 dwLastError
= GetLastError();
292 pContext
= SetupInitDefaultQueueCallbackEx(hwnd
, INVALID_HANDLE_VALUE
,
296 dwLastError
= GetLastError();
300 /* don't output anything for AIF_QUIET */
301 if (dwFlags
& AIF_QUIET
)
302 pFileCallback
= pQuietQueueCallback
;
304 pFileCallback
= pQueueCallback
;
306 /* perform the file copy */
307 if (!SetupCommitFileQueueW(hwnd
, fileQueue
, pFileCallback
, pContext
))
309 dwLastError
= GetLastError();
314 SetupTermDefaultQueueCallback(pContext
);
315 SetupCloseFileQueue(fileQueue
);
317 HeapFree(GetProcessHeap(), 0, szDestFilename
);
319 return HRESULT_FROM_WIN32(dwLastError
);
322 static HRESULT
DELNODE_recurse_dirtree(LPWSTR fname
, DWORD flags
)
324 DWORD fattrs
= GetFileAttributesW(fname
);
325 HRESULT ret
= E_FAIL
;
327 if (fattrs
& FILE_ATTRIBUTE_DIRECTORY
)
330 WIN32_FIND_DATAW w32fd
;
332 int fname_len
= lstrlenW(fname
);
334 /* Generate a path with wildcard suitable for iterating */
335 if (fname_len
&& fname
[fname_len
-1] != '\\') fname
[fname_len
++] = '\\';
336 lstrcpyW(fname
+ fname_len
, L
"*");
338 if ((hFindFile
= FindFirstFileW(fname
, &w32fd
)) != INVALID_HANDLE_VALUE
)
340 /* Iterate through the files in the directory */
341 for (done
= FALSE
; !done
; done
= !FindNextFileW(hFindFile
, &w32fd
))
343 TRACE("%s\n", debugstr_w(w32fd
.cFileName
));
344 if (lstrcmpW(L
".", w32fd
.cFileName
) != 0 && lstrcmpW(L
"..", w32fd
.cFileName
) != 0)
346 lstrcpyW(fname
+ fname_len
, w32fd
.cFileName
);
347 if (DELNODE_recurse_dirtree(fname
, flags
) != S_OK
)
353 FindClose(hFindFile
);
356 /* We're done with this directory, so restore the old path without wildcard */
357 *(fname
+ fname_len
) = '\0';
361 TRACE("%s: directory\n", debugstr_w(fname
));
362 if (SetFileAttributesW(fname
, FILE_ATTRIBUTE_NORMAL
) && RemoveDirectoryW(fname
))
370 TRACE("%s: file\n", debugstr_w(fname
));
371 if (SetFileAttributesW(fname
, FILE_ATTRIBUTE_NORMAL
) && DeleteFileW(fname
))
380 /***********************************************************************
381 * DelNodeA (ADVPACK.@)
385 HRESULT WINAPI
DelNodeA(LPCSTR pszFileOrDirName
, DWORD dwFlags
)
387 UNICODE_STRING fileordirname
;
390 TRACE("(%s, %ld)\n", debugstr_a(pszFileOrDirName
), dwFlags
);
392 RtlCreateUnicodeStringFromAsciiz(&fileordirname
, pszFileOrDirName
);
394 res
= DelNodeW(fileordirname
.Buffer
, dwFlags
);
396 RtlFreeUnicodeString(&fileordirname
);
401 /***********************************************************************
402 * DelNodeW (ADVPACK.@)
404 * Deletes a file or directory
407 * pszFileOrDirName [I] Name of file or directory to delete
408 * dwFlags [I] Flags; see include/advpub.h
416 * - Native version apparently does a lot of checking to make sure
417 * we're not trying to delete a system directory etc.
419 HRESULT WINAPI
DelNodeW(LPCWSTR pszFileOrDirName
, DWORD dwFlags
)
421 WCHAR fname
[MAX_PATH
];
422 HRESULT ret
= E_FAIL
;
424 TRACE("(%s, %ld)\n", debugstr_w(pszFileOrDirName
), dwFlags
);
427 FIXME("Flags ignored!\n");
429 if (pszFileOrDirName
&& *pszFileOrDirName
)
431 lstrcpyW(fname
, pszFileOrDirName
);
433 /* TODO: Should check for system directory deletion etc. here */
435 ret
= DELNODE_recurse_dirtree(fname
, dwFlags
);
441 /***********************************************************************
442 * DelNodeRunDLL32A (ADVPACK.@)
444 * See DelNodeRunDLL32W.
446 HRESULT WINAPI
DelNodeRunDLL32A(HWND hWnd
, HINSTANCE hInst
, LPSTR cmdline
, INT show
)
448 UNICODE_STRING params
;
451 TRACE("(%p, %p, %s, %i)\n", hWnd
, hInst
, debugstr_a(cmdline
), show
);
453 RtlCreateUnicodeStringFromAsciiz(¶ms
, cmdline
);
455 hr
= DelNodeRunDLL32W(hWnd
, hInst
, params
.Buffer
, show
);
457 RtlFreeUnicodeString(¶ms
);
462 /***********************************************************************
463 * DelNodeRunDLL32W (ADVPACK.@)
465 * Deletes a file or directory, WinMain style.
468 * hWnd [I] Handle to the window used for the display.
469 * hInst [I] Instance of the process.
470 * cmdline [I] Contains parameters in the order FileOrDirName,Flags.
471 * show [I] How the window should be shown.
477 HRESULT WINAPI
DelNodeRunDLL32W(HWND hWnd
, HINSTANCE hInst
, LPWSTR cmdline
, INT show
)
479 LPWSTR szFilename
, szFlags
;
480 LPWSTR cmdline_copy
, cmdline_ptr
;
484 TRACE("(%p, %p, %s, %i)\n", hWnd
, hInst
, debugstr_w(cmdline
), show
);
486 cmdline_copy
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline
) + 1) * sizeof(WCHAR
));
487 cmdline_ptr
= cmdline_copy
;
488 lstrcpyW(cmdline_copy
, cmdline
);
490 /* get the parameters at indexes 0 and 1 respectively */
491 szFilename
= get_parameter(&cmdline_ptr
, ',', TRUE
);
492 szFlags
= get_parameter(&cmdline_ptr
, ',', TRUE
);
495 dwFlags
= wcstol(szFlags
, NULL
, 10);
497 res
= DelNodeW(szFilename
, dwFlags
);
499 HeapFree(GetProcessHeap(), 0, cmdline_copy
);
504 /* The following definitions were copied from dlls/cabinet/cabinet.h */
506 /* SESSION Operation */
507 #define EXTRACT_FILLFILELIST 0x00000001
508 #define EXTRACT_EXTRACTFILES 0x00000002
512 struct FILELIST
*next
;
519 struct FILELIST
*FileList
;
522 CHAR Destination
[MAX_PATH
];
523 CHAR CurrentFile
[MAX_PATH
];
524 CHAR Reserved
[MAX_PATH
];
525 struct FILELIST
*FilterList
;
528 static HRESULT (WINAPI
*pExtract
)(SESSION
*, LPCSTR
);
530 /* removes legal characters before and after file list, and
531 * converts the file list to a NULL-separated list
533 static LPSTR
convert_file_list(LPCSTR FileList
, DWORD
*dwNumFiles
)
536 const char *first
= FileList
;
537 const char *last
= FileList
+ strlen(FileList
) - 1;
538 LPSTR szConvertedList
, temp
;
540 /* any number of these chars before the list is OK */
541 while (first
< last
&& (*first
== ' ' || *first
== '\t' || *first
== ':'))
544 /* any number of these chars after the list is OK */
545 while (last
> first
&& (*last
== ' ' || *last
== '\t' || *last
== ':'))
551 dwLen
= last
- first
+ 3; /* room for double-null termination */
552 szConvertedList
= HeapAlloc(GetProcessHeap(), 0, dwLen
);
553 lstrcpynA(szConvertedList
, first
, dwLen
- 1);
554 szConvertedList
[dwLen
- 1] = '\0';
557 if (!szConvertedList
[0])
559 HeapFree(GetProcessHeap(), 0, szConvertedList
);
565 /* convert the colons to double-null termination */
566 temp
= szConvertedList
;
578 return szConvertedList
;
581 static void free_file_node(struct FILELIST
*pNode
)
583 HeapFree(GetProcessHeap(), 0, pNode
->FileName
);
584 HeapFree(GetProcessHeap(), 0, pNode
);
587 /* determines whether szFile is in the NULL-separated szFileList */
588 static BOOL
file_in_list(LPCSTR szFile
, LPCSTR szFileList
)
590 DWORD dwLen
= lstrlenA(szFile
);
595 dwTestLen
= lstrlenA(szFileList
);
597 if (dwTestLen
== dwLen
)
599 if (!lstrcmpiA(szFile
, szFileList
))
603 szFileList
+= dwTestLen
+ 1;
610 /* returns the number of files that are in both the linked list and szFileList */
611 static DWORD
fill_file_list(SESSION
*session
, LPCSTR szCabName
, LPCSTR szFileList
)
613 DWORD dwNumFound
= 0;
614 struct FILELIST
*pNode
;
616 session
->Operation
|= EXTRACT_FILLFILELIST
;
617 if (pExtract(session
, szCabName
) != S_OK
)
619 session
->Operation
&= ~EXTRACT_FILLFILELIST
;
623 pNode
= session
->FileList
;
626 if (!file_in_list(pNode
->FileName
, szFileList
))
627 pNode
->DoExtract
= FALSE
;
634 session
->Operation
&= ~EXTRACT_FILLFILELIST
;
638 static void free_file_list(SESSION
* session
)
640 struct FILELIST
*next
, *curr
= session
->FileList
;
645 free_file_node(curr
);
650 /***********************************************************************
651 * ExtractFilesA (ADVPACK.@)
653 * Extracts the specified files from a cab archive into
654 * a destination directory.
657 * CabName [I] Filename of the cab archive.
658 * ExpandDir [I] Destination directory for the extracted files.
659 * Flags [I] Reserved.
660 * FileList [I] Optional list of files to extract. See NOTES.
661 * LReserved [I] Reserved. Must be NULL.
662 * Reserved [I] Reserved. Must be 0.
669 * FileList is a colon-separated list of filenames. If FileList is
670 * non-NULL, only the files in the list will be extracted from the
671 * cab file, otherwise all files will be extracted. Any number of
672 * spaces, tabs, or colons can be before or after the list, but
673 * the list itself must only be separated by colons.
675 HRESULT WINAPI
ExtractFilesA(LPCSTR CabName
, LPCSTR ExpandDir
, DWORD Flags
,
676 LPCSTR FileList
, LPVOID LReserved
, DWORD Reserved
)
681 DWORD dwFileCount
= 0;
682 DWORD dwFilesFound
= 0;
683 LPSTR szConvertedList
= NULL
;
685 TRACE("(%s, %s, %ld, %s, %p, %ld)\n", debugstr_a(CabName
), debugstr_a(ExpandDir
),
686 Flags
, debugstr_a(FileList
), LReserved
, Reserved
);
688 if (!CabName
|| !ExpandDir
)
691 if (GetFileAttributesA(ExpandDir
) == INVALID_FILE_ATTRIBUTES
)
692 return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
);
694 hCabinet
= LoadLibraryA("cabinet.dll");
698 ZeroMemory(&session
, sizeof(SESSION
));
700 pExtract
= (void *)GetProcAddress(hCabinet
, "Extract");
707 lstrcpyA(session
.Destination
, ExpandDir
);
711 szConvertedList
= convert_file_list(FileList
, &dwFileCount
);
712 if (!szConvertedList
)
718 dwFilesFound
= fill_file_list(&session
, CabName
, szConvertedList
);
719 if (dwFilesFound
!= dwFileCount
)
726 session
.Operation
|= EXTRACT_FILLFILELIST
;
728 session
.Operation
|= EXTRACT_EXTRACTFILES
;
729 res
= pExtract(&session
, CabName
);
732 free_file_list(&session
);
733 FreeLibrary(hCabinet
);
734 HeapFree(GetProcessHeap(), 0, szConvertedList
);
739 /***********************************************************************
740 * ExtractFilesW (ADVPACK.@)
742 * Extracts the specified files from a cab archive into
743 * a destination directory.
746 * CabName [I] Filename of the cab archive.
747 * ExpandDir [I] Destination directory for the extracted files.
748 * Flags [I] Reserved.
749 * FileList [I] Optional list of files to extract. See NOTES.
750 * LReserved [I] Reserved. Must be NULL.
751 * Reserved [I] Reserved. Must be 0.
758 * FileList is a colon-separated list of filenames. If FileList is
759 * non-NULL, only the files in the list will be extracted from the
760 * cab file, otherwise all files will be extracted. Any number of
761 * spaces, tabs, or colons can be before or after the list, but
762 * the list itself must only be separated by colons.
767 HRESULT WINAPI
ExtractFilesW(LPCWSTR CabName
, LPCWSTR ExpandDir
, DWORD Flags
,
768 LPCWSTR FileList
, LPVOID LReserved
, DWORD Reserved
)
770 char *cab_name
= NULL
, *expand_dir
= NULL
, *file_list
= NULL
;
773 TRACE("(%s, %s, %ld, %s, %p, %ld)\n", debugstr_w(CabName
), debugstr_w(ExpandDir
),
774 Flags
, debugstr_w(FileList
), LReserved
, Reserved
);
777 cab_name
= heap_strdupWtoA(CabName
);
779 return E_OUTOFMEMORY
;
783 expand_dir
= heap_strdupWtoA(ExpandDir
);
785 hres
= E_OUTOFMEMORY
;
788 if(SUCCEEDED(hres
) && FileList
) {
789 file_list
= heap_strdupWtoA(FileList
);
791 hres
= E_OUTOFMEMORY
;
794 /* cabinet.dll, which does the real job of extracting files, doesn't have UNICODE API,
795 so we need W->A conversion at some point anyway. */
797 hres
= ExtractFilesA(cab_name
, expand_dir
, Flags
, file_list
, LReserved
, Reserved
);
800 heap_free(expand_dir
);
801 heap_free(file_list
);
805 /***********************************************************************
806 * FileSaveMarkNotExistA (ADVPACK.@)
808 * See FileSaveMarkNotExistW.
810 HRESULT WINAPI
FileSaveMarkNotExistA(LPSTR pszFileList
, LPSTR pszDir
, LPSTR pszBaseName
)
812 TRACE("(%s, %s, %s)\n", debugstr_a(pszFileList
),
813 debugstr_a(pszDir
), debugstr_a(pszBaseName
));
815 return AddDelBackupEntryA(pszFileList
, pszDir
, pszBaseName
, AADBE_DEL_ENTRY
);
818 /***********************************************************************
819 * FileSaveMarkNotExistW (ADVPACK.@)
821 * Marks the files in the file list as not existing so they won't be
822 * backed up during a save.
825 * pszFileList [I] NULL-separated list of filenames.
826 * pszDir [I] Path of the backup directory.
827 * pszBaseName [I] Basename of the INI file.
833 HRESULT WINAPI
FileSaveMarkNotExistW(LPWSTR pszFileList
, LPWSTR pszDir
, LPWSTR pszBaseName
)
835 TRACE("(%s, %s, %s)\n", debugstr_w(pszFileList
),
836 debugstr_w(pszDir
), debugstr_w(pszBaseName
));
838 return AddDelBackupEntryW(pszFileList
, pszDir
, pszBaseName
, AADBE_DEL_ENTRY
);
841 /***********************************************************************
842 * FileSaveRestoreA (ADVPACK.@)
844 * See FileSaveRestoreW.
846 HRESULT WINAPI
FileSaveRestoreA(HWND hDlg
, LPSTR pszFileList
, LPSTR pszDir
,
847 LPSTR pszBaseName
, DWORD dwFlags
)
849 UNICODE_STRING filelist
, dir
, basename
;
852 TRACE("(%p, %s, %s, %s, %ld)\n", hDlg
, debugstr_a(pszFileList
),
853 debugstr_a(pszDir
), debugstr_a(pszBaseName
), dwFlags
);
855 RtlCreateUnicodeStringFromAsciiz(&filelist
, pszFileList
);
856 RtlCreateUnicodeStringFromAsciiz(&dir
, pszDir
);
857 RtlCreateUnicodeStringFromAsciiz(&basename
, pszBaseName
);
859 hr
= FileSaveRestoreW(hDlg
, filelist
.Buffer
, dir
.Buffer
,
860 basename
.Buffer
, dwFlags
);
862 RtlFreeUnicodeString(&filelist
);
863 RtlFreeUnicodeString(&dir
);
864 RtlFreeUnicodeString(&basename
);
869 /***********************************************************************
870 * FileSaveRestoreW (ADVPACK.@)
872 * Saves or restores the files in the specified file list.
875 * hDlg [I] Handle to the dialog used for the display.
876 * pszFileList [I] NULL-separated list of filenames.
877 * pszDir [I] Path of the backup directory.
878 * pszBaseName [I] Basename of the backup files.
879 * dwFlags [I] See advpub.h.
886 * If pszFileList is NULL on restore, all files will be restored.
891 HRESULT WINAPI
FileSaveRestoreW(HWND hDlg
, LPWSTR pszFileList
, LPWSTR pszDir
,
892 LPWSTR pszBaseName
, DWORD dwFlags
)
894 FIXME("(%p, %s, %s, %s, %ld) stub\n", hDlg
, debugstr_w(pszFileList
),
895 debugstr_w(pszDir
), debugstr_w(pszBaseName
), dwFlags
);
900 /***********************************************************************
901 * FileSaveRestoreOnINFA (ADVPACK.@)
903 * See FileSaveRestoreOnINFW.
905 HRESULT WINAPI
FileSaveRestoreOnINFA(HWND hWnd
, LPCSTR pszTitle
, LPCSTR pszINF
,
906 LPCSTR pszSection
, LPCSTR pszBackupDir
,
907 LPCSTR pszBaseBackupFile
, DWORD dwFlags
)
909 UNICODE_STRING title
, inf
, section
;
910 UNICODE_STRING backupdir
, backupfile
;
913 TRACE("(%p, %s, %s, %s, %s, %s, %ld)\n", hWnd
, debugstr_a(pszTitle
),
914 debugstr_a(pszINF
), debugstr_a(pszSection
), debugstr_a(pszBackupDir
),
915 debugstr_a(pszBaseBackupFile
), dwFlags
);
917 RtlCreateUnicodeStringFromAsciiz(&title
, pszTitle
);
918 RtlCreateUnicodeStringFromAsciiz(&inf
, pszINF
);
919 RtlCreateUnicodeStringFromAsciiz(§ion
, pszSection
);
920 RtlCreateUnicodeStringFromAsciiz(&backupdir
, pszBackupDir
);
921 RtlCreateUnicodeStringFromAsciiz(&backupfile
, pszBaseBackupFile
);
923 hr
= FileSaveRestoreOnINFW(hWnd
, title
.Buffer
, inf
.Buffer
, section
.Buffer
,
924 backupdir
.Buffer
, backupfile
.Buffer
, dwFlags
);
926 RtlFreeUnicodeString(&title
);
927 RtlFreeUnicodeString(&inf
);
928 RtlFreeUnicodeString(§ion
);
929 RtlFreeUnicodeString(&backupdir
);
930 RtlFreeUnicodeString(&backupfile
);
935 /***********************************************************************
936 * FileSaveRestoreOnINFW (ADVPACK.@)
940 * hWnd [I] Handle to the window used for the display.
941 * pszTitle [I] Title of the window.
942 * pszINF [I] Fully-qualified INF filename.
943 * pszSection [I] GenInstall INF section name.
944 * pszBackupDir [I] Directory to store the backup file.
945 * pszBaseBackupFile [I] Basename of the backup files.
946 * dwFlags [I] See advpub.h
953 * If pszSection is NULL, the default section will be used.
958 HRESULT WINAPI
FileSaveRestoreOnINFW(HWND hWnd
, LPCWSTR pszTitle
, LPCWSTR pszINF
,
959 LPCWSTR pszSection
, LPCWSTR pszBackupDir
,
960 LPCWSTR pszBaseBackupFile
, DWORD dwFlags
)
962 FIXME("(%p, %s, %s, %s, %s, %s, %ld): stub\n", hWnd
, debugstr_w(pszTitle
),
963 debugstr_w(pszINF
), debugstr_w(pszSection
), debugstr_w(pszBackupDir
),
964 debugstr_w(pszBaseBackupFile
), dwFlags
);
969 /***********************************************************************
970 * GetVersionFromFileA (ADVPACK.@)
972 * See GetVersionFromFileExW.
974 HRESULT WINAPI
GetVersionFromFileA(LPCSTR Filename
, LPDWORD MajorVer
,
975 LPDWORD MinorVer
, BOOL Version
)
977 TRACE("(%s, %p, %p, %d)\n", debugstr_a(Filename
), MajorVer
, MinorVer
, Version
);
978 return GetVersionFromFileExA(Filename
, MajorVer
, MinorVer
, Version
);
981 /***********************************************************************
982 * GetVersionFromFileW (ADVPACK.@)
984 * See GetVersionFromFileExW.
986 HRESULT WINAPI
GetVersionFromFileW(LPCWSTR Filename
, LPDWORD MajorVer
,
987 LPDWORD MinorVer
, BOOL Version
)
989 TRACE("(%s, %p, %p, %d)\n", debugstr_w(Filename
), MajorVer
, MinorVer
, Version
);
990 return GetVersionFromFileExW(Filename
, MajorVer
, MinorVer
, Version
);
993 /* data for GetVersionFromFileEx */
994 typedef struct tagLANGANDCODEPAGE
1000 /***********************************************************************
1001 * GetVersionFromFileExA (ADVPACK.@)
1003 * See GetVersionFromFileExW.
1005 HRESULT WINAPI
GetVersionFromFileExA(LPCSTR lpszFilename
, LPDWORD pdwMSVer
,
1006 LPDWORD pdwLSVer
, BOOL bVersion
)
1008 UNICODE_STRING filename
;
1011 TRACE("(%s, %p, %p, %d)\n", debugstr_a(lpszFilename
),
1012 pdwMSVer
, pdwLSVer
, bVersion
);
1014 RtlCreateUnicodeStringFromAsciiz(&filename
, lpszFilename
);
1016 res
= GetVersionFromFileExW(filename
.Buffer
, pdwMSVer
, pdwLSVer
, bVersion
);
1018 RtlFreeUnicodeString(&filename
);
1023 /***********************************************************************
1024 * GetVersionFromFileExW (ADVPACK.@)
1026 * Gets the files version or language information.
1029 * lpszFilename [I] The file to get the info from.
1030 * pdwMSVer [O] Major version.
1031 * pdwLSVer [O] Minor version.
1032 * bVersion [I] Whether to retrieve version or language info.
1035 * Always returns S_OK.
1038 * If bVersion is TRUE, version information is retrieved, else
1039 * pdwMSVer gets the language ID and pdwLSVer gets the codepage ID.
1041 HRESULT WINAPI
GetVersionFromFileExW(LPCWSTR lpszFilename
, LPDWORD pdwMSVer
,
1042 LPDWORD pdwLSVer
, BOOL bVersion
)
1044 VS_FIXEDFILEINFO
*pFixedVersionInfo
;
1045 LANGANDCODEPAGE
*pLangAndCodePage
;
1046 DWORD dwHandle
, dwInfoSize
;
1047 WCHAR szWinDir
[MAX_PATH
];
1048 WCHAR szFile
[MAX_PATH
];
1049 LPVOID pVersionInfo
= NULL
;
1050 BOOL bFileCopied
= FALSE
;
1053 TRACE("(%s, %p, %p, %d)\n", debugstr_w(lpszFilename
),
1054 pdwMSVer
, pdwLSVer
, bVersion
);
1059 lstrcpynW(szFile
, lpszFilename
, MAX_PATH
);
1061 dwInfoSize
= GetFileVersionInfoSizeW(szFile
, &dwHandle
);
1064 /* check that the file exists */
1065 if (GetFileAttributesW(szFile
) == INVALID_FILE_ATTRIBUTES
)
1068 /* file exists, but won't be found by GetFileVersionInfoSize,
1069 * so copy it to the temp dir where it will be found.
1071 GetWindowsDirectoryW(szWinDir
, MAX_PATH
);
1072 GetTempFileNameW(szWinDir
, NULL
, 0, szFile
);
1073 CopyFileW(lpszFilename
, szFile
, FALSE
);
1076 dwInfoSize
= GetFileVersionInfoSizeW(szFile
, &dwHandle
);
1081 pVersionInfo
= HeapAlloc(GetProcessHeap(), 0, dwInfoSize
);
1085 if (!GetFileVersionInfoW(szFile
, dwHandle
, dwInfoSize
, pVersionInfo
))
1090 if (!VerQueryValueW(pVersionInfo
, L
"\\", (void **)&pFixedVersionInfo
, &uValueLen
))
1096 *pdwMSVer
= pFixedVersionInfo
->dwFileVersionMS
;
1097 *pdwLSVer
= pFixedVersionInfo
->dwFileVersionLS
;
1101 if (!VerQueryValueW(pVersionInfo
, L
"\\VarFileInfo\\Translation",
1102 (LPVOID
*)&pLangAndCodePage
, &uValueLen
))
1108 *pdwMSVer
= pLangAndCodePage
->wLanguage
;
1109 *pdwLSVer
= pLangAndCodePage
->wCodePage
;
1113 HeapFree(GetProcessHeap(), 0, pVersionInfo
);
1116 DeleteFileW(szFile
);