mfplat: Add MFCreateAMMediaTypeFromMFMediaType stub.
[wine.git] / dlls / advpack / files.c
blob2bf2481cca47bac604a0a1a27c8ae7a660823f58
1 /*
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
21 #include <stdarg.h>
22 #include <stdlib.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "winreg.h"
28 #include "winnls.h"
29 #include "winver.h"
30 #include "winternl.h"
31 #include "setupapi.h"
32 #include "advpub.h"
33 #include "fdi.h"
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)
42 DWORD len, wlen = 0;
43 LPWSTR 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);
51 return list;
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;
63 LPWSTR filelist;
64 LPCWSTR backup;
65 HRESULT res;
67 TRACE("(%s, %s, %s, %ld)\n", debugstr_a(lpcszFileList),
68 debugstr_a(lpcszBackupDir), debugstr_a(lpcszBaseName), dwFlags);
70 if (lpcszFileList)
71 filelist = ansi_to_unicode_list(lpcszFileList);
72 else
73 filelist = NULL;
75 RtlCreateUnicodeStringFromAsciiz(&backupdir, lpcszBackupDir);
76 RtlCreateUnicodeStringFromAsciiz(&basename, lpcszBaseName);
78 if (lpcszBackupDir)
79 backup = backupdir.Buffer;
80 else
81 backup = NULL;
83 res = AddDelBackupEntryW(filelist, backup, basename.Buffer, dwFlags);
85 free(filelist);
87 RtlFreeUnicodeString(&backupdir);
88 RtlFreeUnicodeString(&basename);
90 return res;
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.
99 * PARAMS
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.
107 * RETURNS
108 * S_OK in all cases.
110 * NOTES
111 * If the INI file does not exist before adding entries to it, the file
112 * will be created.
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)
127 return S_OK;
129 if (lpcszBackupDir)
130 lstrcpyW(szIniPath, lpcszBackupDir);
131 else
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)
143 szString = NULL;
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);
155 return S_OK;
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)
164 return 1;
167 static UINT CALLBACK pQueueCallback(PVOID Context, UINT Notification,
168 UINT_PTR Param1, UINT_PTR Param2)
170 /* only be verbose for error notifications */
171 if (!Notification ||
172 Notification == SPFILENOTIFY_RENAMEERROR ||
173 Notification == SPFILENOTIFY_DELETEERROR ||
174 Notification == SPFILENOTIFY_COPYERROR)
176 return SetupDefaultQueueCallbackW(Context, Notification,
177 Param1, Param2);
180 return 1;
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;
194 HRESULT res;
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)
201 return E_INVALIDARG;
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);
216 return res;
219 /***********************************************************************
220 * AdvInstallFileW (ADVPACK.@)
222 * Copies a file from the source to a destination.
224 * PARAMS
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.
233 * RETURNS
234 * Success: S_OK.
235 * Failure: E_FAIL.
237 * NOTES
238 * If lpszDestFile is NULL, the destination filename is the same as
239 * lpszSourceFIle.
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;
247 LPCWSTR szPath;
248 WCHAR szRootPath[ROOT_LENGTH];
249 DWORD dwLastError;
250 HSPFILEQ fileQueue;
251 PVOID pContext;
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)
258 return E_INVALIDARG;
260 fileQueue = SetupOpenFileQueue();
261 if (fileQueue == INVALID_HANDLE_VALUE)
262 return HRESULT_FROM_WIN32(GetLastError());
264 pContext = NULL;
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();
278 goto done;
281 pContext = SetupInitDefaultQueueCallbackEx(hwnd, INVALID_HANDLE_VALUE,
282 0, 0, NULL);
283 if (!pContext)
285 dwLastError = GetLastError();
286 goto done;
289 /* don't output anything for AIF_QUIET */
290 if (dwFlags & AIF_QUIET)
291 pFileCallback = pQuietQueueCallback;
292 else
293 pFileCallback = pQueueCallback;
295 /* perform the file copy */
296 if (!SetupCommitFileQueueW(hwnd, fileQueue, pFileCallback, pContext))
298 dwLastError = GetLastError();
299 goto done;
302 done:
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)
318 HANDLE hFindFile;
319 WIN32_FIND_DATAW w32fd;
320 BOOL done = TRUE;
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)
338 break; /* Failure */
342 FindClose(hFindFile);
345 /* We're done with this directory, so restore the old path without wildcard */
346 *(fname + fname_len) = '\0';
348 if (done)
350 TRACE("%s: directory\n", debugstr_w(fname));
351 if (SetFileAttributesW(fname, FILE_ATTRIBUTE_NORMAL) && RemoveDirectoryW(fname))
353 ret = S_OK;
357 else
359 TRACE("%s: file\n", debugstr_w(fname));
360 if (SetFileAttributesW(fname, FILE_ATTRIBUTE_NORMAL) && DeleteFileW(fname))
362 ret = S_OK;
366 return ret;
369 /***********************************************************************
370 * DelNodeA (ADVPACK.@)
372 * See DelNodeW.
374 HRESULT WINAPI DelNodeA(LPCSTR pszFileOrDirName, DWORD dwFlags)
376 UNICODE_STRING fileordirname;
377 HRESULT res;
379 TRACE("(%s, %ld)\n", debugstr_a(pszFileOrDirName), dwFlags);
381 RtlCreateUnicodeStringFromAsciiz(&fileordirname, pszFileOrDirName);
383 res = DelNodeW(fileordirname.Buffer, dwFlags);
385 RtlFreeUnicodeString(&fileordirname);
387 return res;
390 /***********************************************************************
391 * DelNodeW (ADVPACK.@)
393 * Deletes a file or directory
395 * PARAMS
396 * pszFileOrDirName [I] Name of file or directory to delete
397 * dwFlags [I] Flags; see include/advpub.h
399 * RETURNS
400 * Success: S_OK
401 * Failure: E_FAIL
403 * BUGS
404 * - Ignores flags
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);
415 if (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);
427 return ret;
430 /***********************************************************************
431 * DelNodeRunDLL32A (ADVPACK.@)
433 * See DelNodeRunDLL32W.
435 HRESULT WINAPI DelNodeRunDLL32A(HWND hWnd, HINSTANCE hInst, LPSTR cmdline, INT show)
437 UNICODE_STRING params;
438 HRESULT hr;
440 TRACE("(%p, %p, %s, %i)\n", hWnd, hInst, debugstr_a(cmdline), show);
442 RtlCreateUnicodeStringFromAsciiz(&params, cmdline);
444 hr = DelNodeRunDLL32W(hWnd, hInst, params.Buffer, show);
446 RtlFreeUnicodeString(&params);
448 return hr;
451 /***********************************************************************
452 * DelNodeRunDLL32W (ADVPACK.@)
454 * Deletes a file or directory, WinMain style.
456 * PARAMS
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.
462 * RETURNS
463 * Success: S_OK.
464 * Failure: E_FAIL.
466 HRESULT WINAPI DelNodeRunDLL32W(HWND hWnd, HINSTANCE hInst, LPWSTR cmdline, INT show)
468 LPWSTR szFilename, szFlags;
469 LPWSTR cmdline_copy, cmdline_ptr;
470 DWORD dwFlags = 0;
471 HRESULT res;
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);
482 if (szFlags)
483 dwFlags = wcstol(szFlags, NULL, 10);
485 res = DelNodeW(szFilename, dwFlags);
487 free(cmdline_copy);
489 return res;
492 /* The following definitions were copied from dlls/cabinet/cabinet.h */
494 /* SESSION Operation */
495 #define EXTRACT_FILLFILELIST 0x00000001
496 #define EXTRACT_EXTRACTFILES 0x00000002
498 struct FILELIST{
499 LPSTR FileName;
500 struct FILELIST *next;
501 BOOL DoExtract;
504 typedef struct {
505 INT FileSize;
506 ERF Error;
507 struct FILELIST *FileList;
508 INT FileCount;
509 INT Operation;
510 CHAR Destination[MAX_PATH];
511 CHAR CurrentFile[MAX_PATH];
512 CHAR Reserved[MAX_PATH];
513 struct FILELIST *FilterList;
514 } SESSION;
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)
523 DWORD dwLen;
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 == ':'))
530 first++;
532 /* any number of these chars after the list is OK */
533 while (last > first && (*last == ' ' || *last == '\t' || *last == ':'))
534 last--;
536 if (first == last)
537 return NULL;
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';
544 /* empty list */
545 if (!szConvertedList[0])
547 free(szConvertedList);
548 return NULL;
551 *dwNumFiles = 1;
553 /* convert the colons to double-null termination */
554 temp = szConvertedList;
555 while (*temp)
557 if (*temp == ':')
559 *temp = '\0';
560 (*dwNumFiles)++;
563 temp++;
566 return szConvertedList;
569 static void free_file_node(struct FILELIST *pNode)
571 free(pNode->FileName);
572 free(pNode);
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);
579 DWORD dwTestLen;
581 while (*szFileList)
583 dwTestLen = lstrlenA(szFileList);
585 if (dwTestLen == dwLen)
587 if (!lstrcmpiA(szFile, szFileList))
588 return TRUE;
591 szFileList += dwTestLen + 1;
594 return FALSE;
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;
608 return -1;
611 pNode = session->FileList;
612 while (pNode)
614 if (!file_in_list(pNode->FileName, szFileList))
615 pNode->DoExtract = FALSE;
616 else
617 dwNumFound++;
619 pNode = pNode->next;
622 session->Operation &= ~EXTRACT_FILLFILELIST;
623 return dwNumFound;
626 static void free_file_list(SESSION* session)
628 struct FILELIST *next, *curr = session->FileList;
630 while (curr)
632 next = curr->next;
633 free_file_node(curr);
634 curr = next;
638 /***********************************************************************
639 * ExtractFilesA (ADVPACK.@)
641 * Extracts the specified files from a cab archive into
642 * a destination directory.
644 * PARAMS
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.
652 * RETURNS
653 * Success: S_OK.
654 * Failure: E_FAIL.
656 * NOTES
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)
666 SESSION session;
667 HMODULE hCabinet;
668 HRESULT res = S_OK;
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)
677 return E_INVALIDARG;
679 if (GetFileAttributesA(ExpandDir) == INVALID_FILE_ATTRIBUTES)
680 return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
682 hCabinet = LoadLibraryA("cabinet.dll");
683 if (!hCabinet)
684 return E_FAIL;
686 ZeroMemory(&session, sizeof(SESSION));
688 pExtract = (void *)GetProcAddress(hCabinet, "Extract");
689 if (!pExtract)
691 res = E_FAIL;
692 goto done;
695 lstrcpyA(session.Destination, ExpandDir);
697 if (FileList)
699 szConvertedList = convert_file_list(FileList, &dwFileCount);
700 if (!szConvertedList)
702 res = E_FAIL;
703 goto done;
706 dwFilesFound = fill_file_list(&session, CabName, szConvertedList);
707 if (dwFilesFound != dwFileCount)
709 res = E_FAIL;
710 goto done;
713 else
714 session.Operation |= EXTRACT_FILLFILELIST;
716 session.Operation |= EXTRACT_EXTRACTFILES;
717 res = pExtract(&session, CabName);
719 done:
720 free_file_list(&session);
721 FreeLibrary(hCabinet);
722 free(szConvertedList);
724 return res;
727 /***********************************************************************
728 * ExtractFilesW (ADVPACK.@)
730 * Extracts the specified files from a cab archive into
731 * a destination directory.
733 * PARAMS
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.
741 * RETURNS
742 * Success: S_OK.
743 * Failure: E_FAIL.
745 * NOTES
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.
752 * BUGS
753 * Unimplemented.
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;
759 HRESULT hres = S_OK;
761 TRACE("(%s, %s, %ld, %s, %p, %ld)\n", debugstr_w(CabName), debugstr_w(ExpandDir),
762 Flags, debugstr_w(FileList), LReserved, Reserved);
764 if(CabName) {
765 cab_name = strdupWtoA(CabName);
766 if(!cab_name)
767 return E_OUTOFMEMORY;
770 if(ExpandDir) {
771 expand_dir = strdupWtoA(ExpandDir);
772 if(!expand_dir)
773 hres = E_OUTOFMEMORY;
776 if(SUCCEEDED(hres) && FileList) {
777 file_list = strdupWtoA(FileList);
778 if(!file_list)
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. */
784 if(SUCCEEDED(hres))
785 hres = ExtractFilesA(cab_name, expand_dir, Flags, file_list, LReserved, Reserved);
787 free(cab_name);
788 free(expand_dir);
789 free(file_list);
790 return hres;
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.
812 * PARAMS
813 * pszFileList [I] NULL-separated list of filenames.
814 * pszDir [I] Path of the backup directory.
815 * pszBaseName [I] Basename of the INI file.
817 * RETURNS
818 * Success: S_OK.
819 * Failure: E_FAIL.
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;
838 HRESULT hr;
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);
854 return hr;
857 /***********************************************************************
858 * FileSaveRestoreW (ADVPACK.@)
860 * Saves or restores the files in the specified file list.
862 * PARAMS
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.
869 * RETURNS
870 * Success: S_OK.
871 * Failure: E_FAIL.
873 * NOTES
874 * If pszFileList is NULL on restore, all files will be restored.
876 * BUGS
877 * Unimplemented.
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);
885 return E_FAIL;
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;
899 HRESULT hr;
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(&section, 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(&section);
917 RtlFreeUnicodeString(&backupdir);
918 RtlFreeUnicodeString(&backupfile);
920 return hr;
923 /***********************************************************************
924 * FileSaveRestoreOnINFW (ADVPACK.@)
927 * PARAMS
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
936 * RETURNS
937 * Success: S_OK.
938 * Failure: E_FAIL.
940 * NOTES
941 * If pszSection is NULL, the default section will be used.
943 * BUGS
944 * Unimplemented.
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);
954 return E_FAIL;
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
984 WORD wLanguage;
985 WORD wCodePage;
986 } LANGANDCODEPAGE;
988 /***********************************************************************
989 * GetVersionFromFileExA (ADVPACK.@)
991 * See GetVersionFromFileExW.
993 HRESULT WINAPI GetVersionFromFileExA(LPCSTR lpszFilename, LPDWORD pdwMSVer,
994 LPDWORD pdwLSVer, BOOL bVersion )
996 UNICODE_STRING filename;
997 HRESULT res;
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);
1008 return res;
1011 /***********************************************************************
1012 * GetVersionFromFileExW (ADVPACK.@)
1014 * Gets the files version or language information.
1016 * PARAMS
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.
1022 * RETURNS
1023 * Always returns S_OK.
1025 * NOTES
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;
1039 UINT uValueLen;
1041 TRACE("(%s, %p, %p, %d)\n", debugstr_w(lpszFilename),
1042 pdwMSVer, pdwLSVer, bVersion);
1044 *pdwLSVer = 0;
1045 *pdwMSVer = 0;
1047 lstrcpynW(szFile, lpszFilename, MAX_PATH);
1049 dwInfoSize = GetFileVersionInfoSizeW(szFile, &dwHandle);
1050 if (!dwInfoSize)
1052 /* check that the file exists */
1053 if (GetFileAttributesW(szFile) == INVALID_FILE_ATTRIBUTES)
1054 return S_OK;
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);
1062 bFileCopied = TRUE;
1064 dwInfoSize = GetFileVersionInfoSizeW(szFile, &dwHandle);
1065 if (!dwInfoSize)
1066 goto done;
1069 pVersionInfo = malloc(dwInfoSize);
1070 if (!pVersionInfo)
1071 goto done;
1073 if (!GetFileVersionInfoW(szFile, dwHandle, dwInfoSize, pVersionInfo))
1074 goto done;
1076 if (bVersion)
1078 if (!VerQueryValueW(pVersionInfo, L"\\", (void **)&pFixedVersionInfo, &uValueLen))
1079 goto done;
1081 if (!uValueLen)
1082 goto done;
1084 *pdwMSVer = pFixedVersionInfo->dwFileVersionMS;
1085 *pdwLSVer = pFixedVersionInfo->dwFileVersionLS;
1087 else
1089 if (!VerQueryValueW(pVersionInfo, L"\\VarFileInfo\\Translation",
1090 (LPVOID *)&pLangAndCodePage, &uValueLen))
1091 goto done;
1093 if (!uValueLen)
1094 goto done;
1096 *pdwMSVer = pLangAndCodePage->wLanguage;
1097 *pdwLSVer = pLangAndCodePage->wCodePage;
1100 done:
1101 free(pVersionInfo);
1103 if (bFileCopied)
1104 DeleteFileW(szFile);
1106 return S_OK;