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
= malloc(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
);
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
];
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 */
271 szDestFilename
= wcsdup(lpszDestFile
? lpszDestFile
: lpszSourceFile
);
273 /* add the file copy operation to the setup queue */
274 if (!SetupQueueCopyW(fileQueue
, szRootPath
, szPath
, lpszSourceFile
, NULL
,
275 NULL
, lpszDestDir
, szDestFilename
, dwFlags
))
277 dwLastError
= GetLastError();
281 pContext
= SetupInitDefaultQueueCallbackEx(hwnd
, INVALID_HANDLE_VALUE
,
285 dwLastError
= GetLastError();
289 /* don't output anything for AIF_QUIET */
290 if (dwFlags
& AIF_QUIET
)
291 pFileCallback
= pQuietQueueCallback
;
293 pFileCallback
= pQueueCallback
;
295 /* perform the file copy */
296 if (!SetupCommitFileQueueW(hwnd
, fileQueue
, pFileCallback
, pContext
))
298 dwLastError
= GetLastError();
303 SetupTermDefaultQueueCallback(pContext
);
304 SetupCloseFileQueue(fileQueue
);
306 free(szDestFilename
);
308 return HRESULT_FROM_WIN32(dwLastError
);
311 static HRESULT
DELNODE_recurse_dirtree(LPWSTR fname
, DWORD flags
)
313 DWORD fattrs
= GetFileAttributesW(fname
);
314 HRESULT ret
= E_FAIL
;
316 if (fattrs
& FILE_ATTRIBUTE_DIRECTORY
)
319 WIN32_FIND_DATAW w32fd
;
321 int fname_len
= lstrlenW(fname
);
323 /* Generate a path with wildcard suitable for iterating */
324 if (fname_len
&& fname
[fname_len
-1] != '\\') fname
[fname_len
++] = '\\';
325 lstrcpyW(fname
+ fname_len
, L
"*");
327 if ((hFindFile
= FindFirstFileW(fname
, &w32fd
)) != INVALID_HANDLE_VALUE
)
329 /* Iterate through the files in the directory */
330 for (done
= FALSE
; !done
; done
= !FindNextFileW(hFindFile
, &w32fd
))
332 TRACE("%s\n", debugstr_w(w32fd
.cFileName
));
333 if (lstrcmpW(L
".", w32fd
.cFileName
) != 0 && lstrcmpW(L
"..", w32fd
.cFileName
) != 0)
335 lstrcpyW(fname
+ fname_len
, w32fd
.cFileName
);
336 if (DELNODE_recurse_dirtree(fname
, flags
) != S_OK
)
342 FindClose(hFindFile
);
345 /* We're done with this directory, so restore the old path without wildcard */
346 *(fname
+ fname_len
) = '\0';
350 TRACE("%s: directory\n", debugstr_w(fname
));
351 if (SetFileAttributesW(fname
, FILE_ATTRIBUTE_NORMAL
) && RemoveDirectoryW(fname
))
359 TRACE("%s: file\n", debugstr_w(fname
));
360 if (SetFileAttributesW(fname
, FILE_ATTRIBUTE_NORMAL
) && DeleteFileW(fname
))
369 /***********************************************************************
370 * DelNodeA (ADVPACK.@)
374 HRESULT WINAPI
DelNodeA(LPCSTR pszFileOrDirName
, DWORD dwFlags
)
376 UNICODE_STRING fileordirname
;
379 TRACE("(%s, %ld)\n", debugstr_a(pszFileOrDirName
), dwFlags
);
381 RtlCreateUnicodeStringFromAsciiz(&fileordirname
, pszFileOrDirName
);
383 res
= DelNodeW(fileordirname
.Buffer
, dwFlags
);
385 RtlFreeUnicodeString(&fileordirname
);
390 /***********************************************************************
391 * DelNodeW (ADVPACK.@)
393 * Deletes a file or directory
396 * pszFileOrDirName [I] Name of file or directory to delete
397 * dwFlags [I] Flags; see include/advpub.h
405 * - Native version apparently does a lot of checking to make sure
406 * we're not trying to delete a system directory etc.
408 HRESULT WINAPI
DelNodeW(LPCWSTR pszFileOrDirName
, DWORD dwFlags
)
410 WCHAR fname
[MAX_PATH
];
411 HRESULT ret
= E_FAIL
;
413 TRACE("(%s, %ld)\n", debugstr_w(pszFileOrDirName
), dwFlags
);
416 FIXME("Flags ignored!\n");
418 if (pszFileOrDirName
&& *pszFileOrDirName
)
420 lstrcpyW(fname
, pszFileOrDirName
);
422 /* TODO: Should check for system directory deletion etc. here */
424 ret
= DELNODE_recurse_dirtree(fname
, dwFlags
);
430 /***********************************************************************
431 * DelNodeRunDLL32A (ADVPACK.@)
433 * See DelNodeRunDLL32W.
435 HRESULT WINAPI
DelNodeRunDLL32A(HWND hWnd
, HINSTANCE hInst
, LPSTR cmdline
, INT show
)
437 UNICODE_STRING params
;
440 TRACE("(%p, %p, %s, %i)\n", hWnd
, hInst
, debugstr_a(cmdline
), show
);
442 RtlCreateUnicodeStringFromAsciiz(¶ms
, cmdline
);
444 hr
= DelNodeRunDLL32W(hWnd
, hInst
, params
.Buffer
, show
);
446 RtlFreeUnicodeString(¶ms
);
451 /***********************************************************************
452 * DelNodeRunDLL32W (ADVPACK.@)
454 * Deletes a file or directory, WinMain style.
457 * hWnd [I] Handle to the window used for the display.
458 * hInst [I] Instance of the process.
459 * cmdline [I] Contains parameters in the order FileOrDirName,Flags.
460 * show [I] How the window should be shown.
466 HRESULT WINAPI
DelNodeRunDLL32W(HWND hWnd
, HINSTANCE hInst
, LPWSTR cmdline
, INT show
)
468 LPWSTR szFilename
, szFlags
;
469 LPWSTR cmdline_copy
, cmdline_ptr
;
473 TRACE("(%p, %p, %s, %i)\n", hWnd
, hInst
, debugstr_w(cmdline
), show
);
475 cmdline_copy
= wcsdup(cmdline
);
476 cmdline_ptr
= cmdline_copy
;
478 /* get the parameters at indexes 0 and 1 respectively */
479 szFilename
= get_parameter(&cmdline_ptr
, ',', TRUE
);
480 szFlags
= get_parameter(&cmdline_ptr
, ',', TRUE
);
483 dwFlags
= wcstol(szFlags
, NULL
, 10);
485 res
= DelNodeW(szFilename
, dwFlags
);
492 /* The following definitions were copied from dlls/cabinet/cabinet.h */
494 /* SESSION Operation */
495 #define EXTRACT_FILLFILELIST 0x00000001
496 #define EXTRACT_EXTRACTFILES 0x00000002
500 struct FILELIST
*next
;
507 struct FILELIST
*FileList
;
510 CHAR Destination
[MAX_PATH
];
511 CHAR CurrentFile
[MAX_PATH
];
512 CHAR Reserved
[MAX_PATH
];
513 struct FILELIST
*FilterList
;
516 static HRESULT (WINAPI
*pExtract
)(SESSION
*, LPCSTR
);
518 /* removes legal characters before and after file list, and
519 * converts the file list to a NULL-separated list
521 static LPSTR
convert_file_list(LPCSTR FileList
, DWORD
*dwNumFiles
)
524 const char *first
= FileList
;
525 const char *last
= FileList
+ strlen(FileList
) - 1;
526 LPSTR szConvertedList
, temp
;
528 /* any number of these chars before the list is OK */
529 while (first
< last
&& (*first
== ' ' || *first
== '\t' || *first
== ':'))
532 /* any number of these chars after the list is OK */
533 while (last
> first
&& (*last
== ' ' || *last
== '\t' || *last
== ':'))
539 dwLen
= last
- first
+ 3; /* room for double-null termination */
540 szConvertedList
= malloc(dwLen
);
541 lstrcpynA(szConvertedList
, first
, dwLen
- 1);
542 szConvertedList
[dwLen
- 1] = '\0';
545 if (!szConvertedList
[0])
547 free(szConvertedList
);
553 /* convert the colons to double-null termination */
554 temp
= szConvertedList
;
566 return szConvertedList
;
569 static void free_file_node(struct FILELIST
*pNode
)
571 free(pNode
->FileName
);
575 /* determines whether szFile is in the NULL-separated szFileList */
576 static BOOL
file_in_list(LPCSTR szFile
, LPCSTR szFileList
)
578 DWORD dwLen
= lstrlenA(szFile
);
583 dwTestLen
= lstrlenA(szFileList
);
585 if (dwTestLen
== dwLen
)
587 if (!lstrcmpiA(szFile
, szFileList
))
591 szFileList
+= dwTestLen
+ 1;
598 /* returns the number of files that are in both the linked list and szFileList */
599 static DWORD
fill_file_list(SESSION
*session
, LPCSTR szCabName
, LPCSTR szFileList
)
601 DWORD dwNumFound
= 0;
602 struct FILELIST
*pNode
;
604 session
->Operation
|= EXTRACT_FILLFILELIST
;
605 if (pExtract(session
, szCabName
) != S_OK
)
607 session
->Operation
&= ~EXTRACT_FILLFILELIST
;
611 pNode
= session
->FileList
;
614 if (!file_in_list(pNode
->FileName
, szFileList
))
615 pNode
->DoExtract
= FALSE
;
622 session
->Operation
&= ~EXTRACT_FILLFILELIST
;
626 static void free_file_list(SESSION
* session
)
628 struct FILELIST
*next
, *curr
= session
->FileList
;
633 free_file_node(curr
);
638 /***********************************************************************
639 * ExtractFilesA (ADVPACK.@)
641 * Extracts the specified files from a cab archive into
642 * a destination directory.
645 * CabName [I] Filename of the cab archive.
646 * ExpandDir [I] Destination directory for the extracted files.
647 * Flags [I] Reserved.
648 * FileList [I] Optional list of files to extract. See NOTES.
649 * LReserved [I] Reserved. Must be NULL.
650 * Reserved [I] Reserved. Must be 0.
657 * FileList is a colon-separated list of filenames. If FileList is
658 * non-NULL, only the files in the list will be extracted from the
659 * cab file, otherwise all files will be extracted. Any number of
660 * spaces, tabs, or colons can be before or after the list, but
661 * the list itself must only be separated by colons.
663 HRESULT WINAPI
ExtractFilesA(LPCSTR CabName
, LPCSTR ExpandDir
, DWORD Flags
,
664 LPCSTR FileList
, LPVOID LReserved
, DWORD Reserved
)
669 DWORD dwFileCount
= 0;
670 DWORD dwFilesFound
= 0;
671 LPSTR szConvertedList
= NULL
;
673 TRACE("(%s, %s, %ld, %s, %p, %ld)\n", debugstr_a(CabName
), debugstr_a(ExpandDir
),
674 Flags
, debugstr_a(FileList
), LReserved
, Reserved
);
676 if (!CabName
|| !ExpandDir
)
679 if (GetFileAttributesA(ExpandDir
) == INVALID_FILE_ATTRIBUTES
)
680 return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
);
682 hCabinet
= LoadLibraryA("cabinet.dll");
686 ZeroMemory(&session
, sizeof(SESSION
));
688 pExtract
= (void *)GetProcAddress(hCabinet
, "Extract");
695 lstrcpyA(session
.Destination
, ExpandDir
);
699 szConvertedList
= convert_file_list(FileList
, &dwFileCount
);
700 if (!szConvertedList
)
706 dwFilesFound
= fill_file_list(&session
, CabName
, szConvertedList
);
707 if (dwFilesFound
!= dwFileCount
)
714 session
.Operation
|= EXTRACT_FILLFILELIST
;
716 session
.Operation
|= EXTRACT_EXTRACTFILES
;
717 res
= pExtract(&session
, CabName
);
720 free_file_list(&session
);
721 FreeLibrary(hCabinet
);
722 free(szConvertedList
);
727 /***********************************************************************
728 * ExtractFilesW (ADVPACK.@)
730 * Extracts the specified files from a cab archive into
731 * a destination directory.
734 * CabName [I] Filename of the cab archive.
735 * ExpandDir [I] Destination directory for the extracted files.
736 * Flags [I] Reserved.
737 * FileList [I] Optional list of files to extract. See NOTES.
738 * LReserved [I] Reserved. Must be NULL.
739 * Reserved [I] Reserved. Must be 0.
746 * FileList is a colon-separated list of filenames. If FileList is
747 * non-NULL, only the files in the list will be extracted from the
748 * cab file, otherwise all files will be extracted. Any number of
749 * spaces, tabs, or colons can be before or after the list, but
750 * the list itself must only be separated by colons.
755 HRESULT WINAPI
ExtractFilesW(LPCWSTR CabName
, LPCWSTR ExpandDir
, DWORD Flags
,
756 LPCWSTR FileList
, LPVOID LReserved
, DWORD Reserved
)
758 char *cab_name
= NULL
, *expand_dir
= NULL
, *file_list
= NULL
;
761 TRACE("(%s, %s, %ld, %s, %p, %ld)\n", debugstr_w(CabName
), debugstr_w(ExpandDir
),
762 Flags
, debugstr_w(FileList
), LReserved
, Reserved
);
765 cab_name
= strdupWtoA(CabName
);
767 return E_OUTOFMEMORY
;
771 expand_dir
= strdupWtoA(ExpandDir
);
773 hres
= E_OUTOFMEMORY
;
776 if(SUCCEEDED(hres
) && FileList
) {
777 file_list
= strdupWtoA(FileList
);
779 hres
= E_OUTOFMEMORY
;
782 /* cabinet.dll, which does the real job of extracting files, doesn't have UNICODE API,
783 so we need W->A conversion at some point anyway. */
785 hres
= ExtractFilesA(cab_name
, expand_dir
, Flags
, file_list
, LReserved
, Reserved
);
793 /***********************************************************************
794 * FileSaveMarkNotExistA (ADVPACK.@)
796 * See FileSaveMarkNotExistW.
798 HRESULT WINAPI
FileSaveMarkNotExistA(LPSTR pszFileList
, LPSTR pszDir
, LPSTR pszBaseName
)
800 TRACE("(%s, %s, %s)\n", debugstr_a(pszFileList
),
801 debugstr_a(pszDir
), debugstr_a(pszBaseName
));
803 return AddDelBackupEntryA(pszFileList
, pszDir
, pszBaseName
, AADBE_DEL_ENTRY
);
806 /***********************************************************************
807 * FileSaveMarkNotExistW (ADVPACK.@)
809 * Marks the files in the file list as not existing so they won't be
810 * backed up during a save.
813 * pszFileList [I] NULL-separated list of filenames.
814 * pszDir [I] Path of the backup directory.
815 * pszBaseName [I] Basename of the INI file.
821 HRESULT WINAPI
FileSaveMarkNotExistW(LPWSTR pszFileList
, LPWSTR pszDir
, LPWSTR pszBaseName
)
823 TRACE("(%s, %s, %s)\n", debugstr_w(pszFileList
),
824 debugstr_w(pszDir
), debugstr_w(pszBaseName
));
826 return AddDelBackupEntryW(pszFileList
, pszDir
, pszBaseName
, AADBE_DEL_ENTRY
);
829 /***********************************************************************
830 * FileSaveRestoreA (ADVPACK.@)
832 * See FileSaveRestoreW.
834 HRESULT WINAPI
FileSaveRestoreA(HWND hDlg
, LPSTR pszFileList
, LPSTR pszDir
,
835 LPSTR pszBaseName
, DWORD dwFlags
)
837 UNICODE_STRING filelist
, dir
, basename
;
840 TRACE("(%p, %s, %s, %s, %ld)\n", hDlg
, debugstr_a(pszFileList
),
841 debugstr_a(pszDir
), debugstr_a(pszBaseName
), dwFlags
);
843 RtlCreateUnicodeStringFromAsciiz(&filelist
, pszFileList
);
844 RtlCreateUnicodeStringFromAsciiz(&dir
, pszDir
);
845 RtlCreateUnicodeStringFromAsciiz(&basename
, pszBaseName
);
847 hr
= FileSaveRestoreW(hDlg
, filelist
.Buffer
, dir
.Buffer
,
848 basename
.Buffer
, dwFlags
);
850 RtlFreeUnicodeString(&filelist
);
851 RtlFreeUnicodeString(&dir
);
852 RtlFreeUnicodeString(&basename
);
857 /***********************************************************************
858 * FileSaveRestoreW (ADVPACK.@)
860 * Saves or restores the files in the specified file list.
863 * hDlg [I] Handle to the dialog used for the display.
864 * pszFileList [I] NULL-separated list of filenames.
865 * pszDir [I] Path of the backup directory.
866 * pszBaseName [I] Basename of the backup files.
867 * dwFlags [I] See advpub.h.
874 * If pszFileList is NULL on restore, all files will be restored.
879 HRESULT WINAPI
FileSaveRestoreW(HWND hDlg
, LPWSTR pszFileList
, LPWSTR pszDir
,
880 LPWSTR pszBaseName
, DWORD dwFlags
)
882 FIXME("(%p, %s, %s, %s, %ld) stub\n", hDlg
, debugstr_w(pszFileList
),
883 debugstr_w(pszDir
), debugstr_w(pszBaseName
), dwFlags
);
888 /***********************************************************************
889 * FileSaveRestoreOnINFA (ADVPACK.@)
891 * See FileSaveRestoreOnINFW.
893 HRESULT WINAPI
FileSaveRestoreOnINFA(HWND hWnd
, LPCSTR pszTitle
, LPCSTR pszINF
,
894 LPCSTR pszSection
, LPCSTR pszBackupDir
,
895 LPCSTR pszBaseBackupFile
, DWORD dwFlags
)
897 UNICODE_STRING title
, inf
, section
;
898 UNICODE_STRING backupdir
, backupfile
;
901 TRACE("(%p, %s, %s, %s, %s, %s, %ld)\n", hWnd
, debugstr_a(pszTitle
),
902 debugstr_a(pszINF
), debugstr_a(pszSection
), debugstr_a(pszBackupDir
),
903 debugstr_a(pszBaseBackupFile
), dwFlags
);
905 RtlCreateUnicodeStringFromAsciiz(&title
, pszTitle
);
906 RtlCreateUnicodeStringFromAsciiz(&inf
, pszINF
);
907 RtlCreateUnicodeStringFromAsciiz(§ion
, pszSection
);
908 RtlCreateUnicodeStringFromAsciiz(&backupdir
, pszBackupDir
);
909 RtlCreateUnicodeStringFromAsciiz(&backupfile
, pszBaseBackupFile
);
911 hr
= FileSaveRestoreOnINFW(hWnd
, title
.Buffer
, inf
.Buffer
, section
.Buffer
,
912 backupdir
.Buffer
, backupfile
.Buffer
, dwFlags
);
914 RtlFreeUnicodeString(&title
);
915 RtlFreeUnicodeString(&inf
);
916 RtlFreeUnicodeString(§ion
);
917 RtlFreeUnicodeString(&backupdir
);
918 RtlFreeUnicodeString(&backupfile
);
923 /***********************************************************************
924 * FileSaveRestoreOnINFW (ADVPACK.@)
928 * hWnd [I] Handle to the window used for the display.
929 * pszTitle [I] Title of the window.
930 * pszINF [I] Fully-qualified INF filename.
931 * pszSection [I] GenInstall INF section name.
932 * pszBackupDir [I] Directory to store the backup file.
933 * pszBaseBackupFile [I] Basename of the backup files.
934 * dwFlags [I] See advpub.h
941 * If pszSection is NULL, the default section will be used.
946 HRESULT WINAPI
FileSaveRestoreOnINFW(HWND hWnd
, LPCWSTR pszTitle
, LPCWSTR pszINF
,
947 LPCWSTR pszSection
, LPCWSTR pszBackupDir
,
948 LPCWSTR pszBaseBackupFile
, DWORD dwFlags
)
950 FIXME("(%p, %s, %s, %s, %s, %s, %ld): stub\n", hWnd
, debugstr_w(pszTitle
),
951 debugstr_w(pszINF
), debugstr_w(pszSection
), debugstr_w(pszBackupDir
),
952 debugstr_w(pszBaseBackupFile
), dwFlags
);
957 /***********************************************************************
958 * GetVersionFromFileA (ADVPACK.@)
960 * See GetVersionFromFileExW.
962 HRESULT WINAPI
GetVersionFromFileA(LPCSTR Filename
, LPDWORD MajorVer
,
963 LPDWORD MinorVer
, BOOL Version
)
965 TRACE("(%s, %p, %p, %d)\n", debugstr_a(Filename
), MajorVer
, MinorVer
, Version
);
966 return GetVersionFromFileExA(Filename
, MajorVer
, MinorVer
, Version
);
969 /***********************************************************************
970 * GetVersionFromFileW (ADVPACK.@)
972 * See GetVersionFromFileExW.
974 HRESULT WINAPI
GetVersionFromFileW(LPCWSTR Filename
, LPDWORD MajorVer
,
975 LPDWORD MinorVer
, BOOL Version
)
977 TRACE("(%s, %p, %p, %d)\n", debugstr_w(Filename
), MajorVer
, MinorVer
, Version
);
978 return GetVersionFromFileExW(Filename
, MajorVer
, MinorVer
, Version
);
981 /* data for GetVersionFromFileEx */
982 typedef struct tagLANGANDCODEPAGE
988 /***********************************************************************
989 * GetVersionFromFileExA (ADVPACK.@)
991 * See GetVersionFromFileExW.
993 HRESULT WINAPI
GetVersionFromFileExA(LPCSTR lpszFilename
, LPDWORD pdwMSVer
,
994 LPDWORD pdwLSVer
, BOOL bVersion
)
996 UNICODE_STRING filename
;
999 TRACE("(%s, %p, %p, %d)\n", debugstr_a(lpszFilename
),
1000 pdwMSVer
, pdwLSVer
, bVersion
);
1002 RtlCreateUnicodeStringFromAsciiz(&filename
, lpszFilename
);
1004 res
= GetVersionFromFileExW(filename
.Buffer
, pdwMSVer
, pdwLSVer
, bVersion
);
1006 RtlFreeUnicodeString(&filename
);
1011 /***********************************************************************
1012 * GetVersionFromFileExW (ADVPACK.@)
1014 * Gets the files version or language information.
1017 * lpszFilename [I] The file to get the info from.
1018 * pdwMSVer [O] Major version.
1019 * pdwLSVer [O] Minor version.
1020 * bVersion [I] Whether to retrieve version or language info.
1023 * Always returns S_OK.
1026 * If bVersion is TRUE, version information is retrieved, else
1027 * pdwMSVer gets the language ID and pdwLSVer gets the codepage ID.
1029 HRESULT WINAPI
GetVersionFromFileExW(LPCWSTR lpszFilename
, LPDWORD pdwMSVer
,
1030 LPDWORD pdwLSVer
, BOOL bVersion
)
1032 VS_FIXEDFILEINFO
*pFixedVersionInfo
;
1033 LANGANDCODEPAGE
*pLangAndCodePage
;
1034 DWORD dwHandle
, dwInfoSize
;
1035 WCHAR szWinDir
[MAX_PATH
];
1036 WCHAR szFile
[MAX_PATH
];
1037 LPVOID pVersionInfo
= NULL
;
1038 BOOL bFileCopied
= FALSE
;
1041 TRACE("(%s, %p, %p, %d)\n", debugstr_w(lpszFilename
),
1042 pdwMSVer
, pdwLSVer
, bVersion
);
1047 lstrcpynW(szFile
, lpszFilename
, MAX_PATH
);
1049 dwInfoSize
= GetFileVersionInfoSizeW(szFile
, &dwHandle
);
1052 /* check that the file exists */
1053 if (GetFileAttributesW(szFile
) == INVALID_FILE_ATTRIBUTES
)
1056 /* file exists, but won't be found by GetFileVersionInfoSize,
1057 * so copy it to the temp dir where it will be found.
1059 GetWindowsDirectoryW(szWinDir
, MAX_PATH
);
1060 GetTempFileNameW(szWinDir
, NULL
, 0, szFile
);
1061 CopyFileW(lpszFilename
, szFile
, FALSE
);
1064 dwInfoSize
= GetFileVersionInfoSizeW(szFile
, &dwHandle
);
1069 pVersionInfo
= malloc(dwInfoSize
);
1073 if (!GetFileVersionInfoW(szFile
, dwHandle
, dwInfoSize
, pVersionInfo
))
1078 if (!VerQueryValueW(pVersionInfo
, L
"\\", (void **)&pFixedVersionInfo
, &uValueLen
))
1084 *pdwMSVer
= pFixedVersionInfo
->dwFileVersionMS
;
1085 *pdwLSVer
= pFixedVersionInfo
->dwFileVersionLS
;
1089 if (!VerQueryValueW(pVersionInfo
, L
"\\VarFileInfo\\Translation",
1090 (LPVOID
*)&pLangAndCodePage
, &uValueLen
))
1096 *pdwMSVer
= pLangAndCodePage
->wLanguage
;
1097 *pdwLSVer
= pLangAndCodePage
->wCodePage
;
1104 DeleteFileW(szFile
);