advpack: Forward GetVersionFromFileA/ExA to their Unicode counterparts.
[wine/gsoc_dplay.git] / dlls / advpack / files.c
blobfa994e35b1935db456f1c03c53f8684a9be48741
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 "winver.h"
29 #include "winternl.h"
30 #include "setupapi.h"
31 #include "advpub.h"
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(advpack);
37 /* converts an ansi double null-terminated list to a unicode list */
38 static LPWSTR ansi_to_unicode_list(LPCSTR ansi_list)
40 DWORD len, wlen = 0;
41 LPWSTR list;
42 LPCSTR ptr = ansi_list;
44 while (*ptr) ptr += lstrlenA(ptr) + 1;
45 len = ptr + 1 - ansi_list;
46 wlen = MultiByteToWideChar(CP_ACP, 0, ansi_list, len, NULL, 0);
47 list = HeapAlloc(GetProcessHeap(), 0, wlen * sizeof(WCHAR));
48 MultiByteToWideChar(CP_ACP, 0, ansi_list, len, list, wlen);
49 return list;
52 /***********************************************************************
53 * AddDelBackupEntryA (ADVPACK.@)
55 * See AddDelBackupEntryW.
57 HRESULT WINAPI AddDelBackupEntryA(LPCSTR lpcszFileList, LPCSTR lpcszBackupDir,
58 LPCSTR lpcszBaseName, DWORD dwFlags)
60 UNICODE_STRING backupdir, basename;
61 LPWSTR filelist, backup;
62 HRESULT res;
64 TRACE("(%p, %p, %p, %ld)\n", lpcszFileList, lpcszBackupDir,
65 lpcszBaseName, dwFlags);
67 if (lpcszFileList)
68 filelist = ansi_to_unicode_list(lpcszFileList);
69 else
70 filelist = NULL;
72 RtlCreateUnicodeStringFromAsciiz(&backupdir, lpcszBackupDir);
73 RtlCreateUnicodeStringFromAsciiz(&basename, lpcszBaseName);
75 if (lpcszBackupDir)
76 backup = backupdir.Buffer;
77 else
78 backup = NULL;
80 res = AddDelBackupEntryW(filelist, backup, basename.Buffer, dwFlags);
82 HeapFree(GetProcessHeap(), 0, filelist);
84 RtlFreeUnicodeString(&backupdir);
85 RtlFreeUnicodeString(&basename);
87 return res;
90 /***********************************************************************
91 * AddDelBackupEntryW (ADVPACK.@)
93 * Either appends the files in the file list to the backup section of
94 * the specified INI, or deletes the entries from the INI file.
96 * PARAMS
97 * lpcszFileList [I] NULL-separated list of filenames.
98 * lpcszBackupDir [I] Path of the backup directory.
99 * lpcszBaseName [I] Basename of the INI file.
100 * dwFlags [I] AADBE_ADD_ENTRY adds the entries in the file list
101 * to the INI file, while AADBE_DEL_ENTRY removes
102 * the entries from the INI file.
104 * RETURNS
105 * S_OK in all cases.
107 * NOTES
108 * If the INI file does not exist before adding entries to it, the file
109 * will be created.
111 * If lpcszBackupDir is NULL, the INI file is assumed to exist in
112 * c:\windows or created there if it does not exist.
114 HRESULT WINAPI AddDelBackupEntryW(LPCWSTR lpcszFileList, LPCWSTR lpcszBackupDir,
115 LPCWSTR lpcszBaseName, DWORD dwFlags)
117 WCHAR szIniPath[MAX_PATH];
118 LPWSTR szString = NULL;
120 static const WCHAR szBackupEntry[] = {
121 '-','1',',','0',',','0',',','0',',','0',',','0',',','-','1',0
124 static const WCHAR backslash[] = {'\\',0};
125 static const WCHAR ini[] = {'.','i','n','i',0};
126 static const WCHAR backup[] = {'b','a','c','k','u','p',0};
128 TRACE("(%p, %p, %p, %ld)\n", lpcszFileList, lpcszBackupDir,
129 lpcszBaseName, dwFlags);
131 if (!lpcszFileList || !*lpcszFileList)
132 return S_OK;
134 if (lpcszBackupDir)
135 lstrcpyW(szIniPath, lpcszBackupDir);
136 else
137 GetWindowsDirectoryW(szIniPath, MAX_PATH);
139 lstrcatW(szIniPath, backslash);
140 lstrcatW(szIniPath, lpcszBaseName);
141 lstrcatW(szIniPath, ini);
143 SetFileAttributesW(szIniPath, FILE_ATTRIBUTE_NORMAL);
145 if (dwFlags & AADBE_ADD_ENTRY)
146 szString = (LPWSTR)szBackupEntry;
147 else if (dwFlags & AADBE_DEL_ENTRY)
148 szString = NULL;
150 /* add or delete the INI entries */
151 while (*lpcszFileList)
153 WritePrivateProfileStringW(backup, lpcszFileList, szString, szIniPath);
154 lpcszFileList += lstrlenW(lpcszFileList) + 1;
157 /* hide the INI file */
158 SetFileAttributesW(szIniPath, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN);
160 return S_OK;
163 /* FIXME: this is only for the local case, X:\ */
164 #define ROOT_LENGTH 3
166 UINT CALLBACK pQuietQueueCallback(PVOID Context, UINT Notification,
167 UINT_PTR Param1, UINT_PTR Param2)
169 return 1;
172 UINT CALLBACK pQueueCallback(PVOID Context, UINT Notification,
173 UINT_PTR Param1, UINT_PTR Param2)
175 /* only be verbose for error notifications */
176 if (!Notification ||
177 Notification == SPFILENOTIFY_RENAMEERROR ||
178 Notification == SPFILENOTIFY_DELETEERROR ||
179 Notification == SPFILENOTIFY_COPYERROR)
181 return SetupDefaultQueueCallbackW(Context, Notification,
182 Param1, Param2);
185 return 1;
188 /***********************************************************************
189 * AdvInstallFileA (ADVPACK.@)
191 * See AdvInstallFileW.
193 HRESULT WINAPI AdvInstallFileA(HWND hwnd, LPCSTR lpszSourceDir, LPCSTR lpszSourceFile,
194 LPCSTR lpszDestDir, LPCSTR lpszDestFile,
195 DWORD dwFlags, DWORD dwReserved)
197 UNICODE_STRING sourcedir, sourcefile;
198 UNICODE_STRING destdir, destfile;
199 HRESULT res;
201 TRACE("(%p,%s,%s,%s,%s,%ld,%ld)\n", hwnd, debugstr_a(lpszSourceDir),
202 debugstr_a(lpszSourceFile), debugstr_a(lpszDestDir),
203 debugstr_a(lpszDestFile), dwFlags, dwReserved);
205 if (!lpszSourceDir || !lpszSourceFile || !lpszDestDir)
206 return E_INVALIDARG;
208 RtlCreateUnicodeStringFromAsciiz(&sourcedir, lpszSourceDir);
209 RtlCreateUnicodeStringFromAsciiz(&sourcefile, lpszSourceFile);
210 RtlCreateUnicodeStringFromAsciiz(&destdir, lpszDestDir);
211 RtlCreateUnicodeStringFromAsciiz(&destfile, lpszDestFile);
213 res = AdvInstallFileW(hwnd, sourcedir.Buffer, sourcefile.Buffer,
214 destdir.Buffer, destfile.Buffer, dwFlags, dwReserved);
216 RtlFreeUnicodeString(&sourcedir);
217 RtlFreeUnicodeString(&sourcefile);
218 RtlFreeUnicodeString(&destdir);
219 RtlFreeUnicodeString(&destfile);
221 return res;
224 /***********************************************************************
225 * AdvInstallFileW (ADVPACK.@)
227 * Copies a file from the source to a destination.
229 * PARAMS
230 * hwnd [I] Handle to the window used for messages.
231 * lpszSourceDir [I] Source directory.
232 * lpszSourceFile [I] Source filename.
233 * lpszDestDir [I] Destination directory.
234 * lpszDestFile [I] Optional destination filename.
235 * dwFlags [I] See advpub.h.
236 * dwReserved [I] Reserved. Must be 0.
238 * RETURNS
239 * Success: S_OK.
240 * Failure: E_FAIL.
242 * NOTES
243 * If lpszDestFile is NULL, the destination filename is the same as
244 * lpszSourceFIle.
246 HRESULT WINAPI AdvInstallFileW(HWND hwnd, LPCWSTR lpszSourceDir, LPCWSTR lpszSourceFile,
247 LPCWSTR lpszDestDir, LPCWSTR lpszDestFile,
248 DWORD dwFlags, DWORD dwReserved)
250 PSP_FILE_CALLBACK_W pFileCallback;
251 LPWSTR szPath, szDestFilename;
252 WCHAR szRootPath[ROOT_LENGTH];
253 DWORD dwLen, dwLastError;
254 HSPFILEQ fileQueue;
255 PVOID pContext;
257 TRACE("(%p,%s,%s,%s,%s,%ld,%ld)\n", hwnd, debugstr_w(lpszSourceDir),
258 debugstr_w(lpszSourceFile), debugstr_w(lpszDestDir),
259 debugstr_w(lpszDestFile), dwFlags, dwReserved);
261 if (!lpszSourceDir || !lpszSourceFile || !lpszDestDir)
262 return E_INVALIDARG;
264 fileQueue = SetupOpenFileQueue();
265 if (fileQueue == INVALID_HANDLE_VALUE)
266 return HRESULT_FROM_WIN32(GetLastError());
268 pContext = NULL;
269 dwLastError = ERROR_SUCCESS;
271 lstrcpynW(szRootPath, lpszSourceDir, ROOT_LENGTH);
272 szPath = (LPWSTR)lpszSourceDir + ROOT_LENGTH;
274 /* use lpszSourceFile as destination filename if lpszDestFile is NULL */
275 if (lpszDestFile)
277 dwLen = lstrlenW(lpszDestFile);
278 szDestFilename = HeapAlloc(GetProcessHeap(), 0, dwLen * sizeof(WCHAR));
279 lstrcpyW(szDestFilename, lpszDestFile);
281 else
283 dwLen = lstrlenW(lpszSourceFile);
284 szDestFilename = HeapAlloc(GetProcessHeap(), 0, dwLen * sizeof(WCHAR));
285 lstrcpyW(szDestFilename, lpszSourceFile);
288 /* add the file copy operation to the setup queue */
289 if (!SetupQueueCopyW(fileQueue, szRootPath, szPath, lpszSourceFile, NULL,
290 NULL, lpszDestDir, szDestFilename, dwFlags))
292 dwLastError = GetLastError();
293 goto done;
296 pContext = SetupInitDefaultQueueCallbackEx(hwnd, INVALID_HANDLE_VALUE,
297 0, 0, NULL);
298 if (!pContext)
300 dwLastError = GetLastError();
301 goto done;
304 /* don't output anything for AIF_QUIET */
305 if (dwFlags & AIF_QUIET)
306 pFileCallback = pQuietQueueCallback;
307 else
308 pFileCallback = pQueueCallback;
310 /* perform the file copy */
311 if (!SetupCommitFileQueueW(hwnd, fileQueue, pFileCallback, pContext))
313 dwLastError = GetLastError();
314 goto done;
317 done:
318 SetupTermDefaultQueueCallback(pContext);
319 SetupCloseFileQueue(fileQueue);
321 HeapFree(GetProcessHeap(), 0, szDestFilename);
323 return HRESULT_FROM_WIN32(dwLastError);
326 static HRESULT DELNODE_recurse_dirtree(LPSTR fname, DWORD flags)
328 DWORD fattrs = GetFileAttributesA(fname);
329 HRESULT ret = E_FAIL;
331 if (fattrs & FILE_ATTRIBUTE_DIRECTORY)
333 HANDLE hFindFile;
334 WIN32_FIND_DATAA w32fd;
335 BOOL done = TRUE;
336 int fname_len = lstrlenA(fname);
338 /* Generate a path with wildcard suitable for iterating */
339 if (CharPrevA(fname, fname + fname_len) != "\\")
341 lstrcpyA(fname + fname_len, "\\");
342 ++fname_len;
344 lstrcpyA(fname + fname_len, "*");
346 if ((hFindFile = FindFirstFileA(fname, &w32fd)) != INVALID_HANDLE_VALUE)
348 /* Iterate through the files in the directory */
349 for (done = FALSE; !done; done = !FindNextFileA(hFindFile, &w32fd))
351 TRACE("%s\n", w32fd.cFileName);
352 if (lstrcmpA(".", w32fd.cFileName) != 0 &&
353 lstrcmpA("..", w32fd.cFileName) != 0)
355 lstrcpyA(fname + fname_len, w32fd.cFileName);
356 if (DELNODE_recurse_dirtree(fname, flags) != S_OK)
358 break; /* Failure */
362 FindClose(hFindFile);
365 /* We're done with this directory, so restore the old path without wildcard */
366 *(fname + fname_len) = '\0';
368 if (done)
370 TRACE("%s: directory\n", fname);
371 if (SetFileAttributesA(fname, FILE_ATTRIBUTE_NORMAL) && RemoveDirectoryA(fname))
373 ret = S_OK;
377 else
379 TRACE("%s: file\n", fname);
380 if (SetFileAttributesA(fname, FILE_ATTRIBUTE_NORMAL) && DeleteFileA(fname))
382 ret = S_OK;
386 return ret;
389 /***********************************************************************
390 * DelNodeA (ADVPACK.@)
392 * Deletes a file or directory
394 * PARAMS
395 * pszFileOrDirName [I] Name of file or directory to delete
396 * dwFlags [I] Flags; see include/advpub.h
398 * RETURNS
399 * Success: S_OK
400 * Failure: E_FAIL
402 * BUGS
403 * - Ignores flags
404 * - Native version apparently does a lot of checking to make sure
405 * we're not trying to delete a system directory etc.
407 HRESULT WINAPI DelNodeA( LPCSTR pszFileOrDirName, DWORD dwFlags )
409 CHAR fname[MAX_PATH];
410 HRESULT ret = E_FAIL;
412 TRACE("(%s, 0x%08lx)\n", debugstr_a(pszFileOrDirName), dwFlags);
414 if (dwFlags)
415 FIXME("Flags ignored!\n");
417 if (pszFileOrDirName && *pszFileOrDirName)
419 lstrcpyA(fname, pszFileOrDirName);
421 /* TODO: Should check for system directory deletion etc. here */
423 ret = DELNODE_recurse_dirtree(fname, dwFlags);
426 return ret;
429 /* returns the parameter at dwIndex in a list of parameters
430 * separated by the cSeparator character
432 static LPSTR get_parameter(LPSTR szParameters, CHAR cSeparator, DWORD dwIndex)
434 LPSTR szParam = NULL;
435 DWORD i = 0;
437 while (*szParameters && i < dwIndex)
439 if (*szParameters == cSeparator)
440 i++;
442 szParameters++;
445 if (!*szParameters)
446 return NULL;
448 szParam = HeapAlloc(GetProcessHeap(), 0, lstrlenA(szParameters));
449 lstrcpyA(szParam, szParameters);
451 return szParam;
454 /***********************************************************************
455 * DelNodeRunDLL32A (ADVPACK.@)
457 * Deletes a file or directory, WinMain style.
459 * PARAMS
460 * hWnd [I] Handle to the window used for the display.
461 * hInst [I] Instance of the process.
462 * cmdline [I] Contains parameters in the order FileOrDirName,Flags.
463 * show [I] How the window should be shown.
465 * RETURNS
466 * Success: S_OK.
467 * Failure: E_FAIL.
469 HRESULT WINAPI DelNodeRunDLL32A( HWND hWnd, HINSTANCE hInst, LPSTR cmdline, INT show )
471 LPSTR szFilename, szFlags;
472 DWORD dwFlags;
473 HRESULT res;
475 TRACE("(%s)\n", debugstr_a(cmdline));
477 /* get the parameters at indexes 0 and 1 respectively */
478 szFilename = get_parameter(cmdline, ',', 0);
479 szFlags = get_parameter(cmdline, ',', 1);
481 dwFlags = atol(szFlags);
483 res = DelNodeA(szFilename, dwFlags);
485 HeapFree(GetProcessHeap(), 0, szFilename);
486 HeapFree(GetProcessHeap(), 0, szFlags);
488 return res;
491 /* The following defintions were copied from dlls/cabinet/cabinet.h */
493 /* EXTRACTdest flags */
494 #define EXTRACT_FILLFILELIST 0x00000001
495 #define EXTRACT_EXTRACTFILES 0x00000002
497 struct ExtractFileList {
498 LPSTR filename;
499 struct ExtractFileList *next;
500 BOOL unknown; /* always 1L */
503 /* the first parameter of the function Extract */
504 typedef struct {
505 long result1; /* 0x000 */
506 long unknown1[3]; /* 0x004 */
507 struct ExtractFileList *filelist; /* 0x010 */
508 long filecount; /* 0x014 */
509 DWORD flags; /* 0x018 */
510 char directory[0x104]; /* 0x01c */
511 char lastfile[0x20c]; /* 0x120 */
512 } EXTRACTdest;
514 static HRESULT (WINAPI *pExtract)(EXTRACTdest*, LPCSTR);
516 /* removes legal characters before and after file list, and
517 * converts the file list to a NULL-separated list
519 static LPSTR convert_file_list(LPCSTR FileList, DWORD *dwNumFiles)
521 DWORD dwLen;
522 char *first = (char *)FileList;
523 char *last = (char *)FileList + strlen(FileList) - 1;
524 LPSTR szConvertedList, temp;
526 /* any number of these chars before the list is OK */
527 while (first < last && (*first == ' ' || *first == '\t' || *first == ':'))
528 first++;
530 /* any number of these chars after the list is OK */
531 while (last > first && (*last == ' ' || *last == '\t' || *last == ':'))
532 last--;
534 if (first == last)
535 return NULL;
537 dwLen = last - first + 3; /* room for double-null termination */
538 szConvertedList = HeapAlloc(GetProcessHeap(), 0, dwLen);
539 lstrcpynA(szConvertedList, first, dwLen - 1);
541 szConvertedList[dwLen - 1] = '\0';
542 szConvertedList[dwLen] = '\0';
544 /* empty list */
545 if (!lstrlenA(szConvertedList))
546 return NULL;
548 *dwNumFiles = 1;
550 /* convert the colons to double-null termination */
551 temp = szConvertedList;
552 while (*temp)
554 if (*temp == ':')
556 *temp = '\0';
557 (*dwNumFiles)++;
560 temp++;
563 return szConvertedList;
566 static void free_file_node(struct ExtractFileList *pNode)
568 HeapFree(GetProcessHeap(), 0, pNode->filename);
569 HeapFree(GetProcessHeap(), 0, pNode);
572 /* determines whether szFile is in the NULL-separated szFileList */
573 static BOOL file_in_list(LPSTR szFile, LPSTR szFileList)
575 DWORD dwLen = lstrlenA(szFile);
576 DWORD dwTestLen;
578 while (*szFileList)
580 dwTestLen = lstrlenA(szFileList);
582 if (dwTestLen == dwLen)
584 if (!lstrcmpiA(szFile, szFileList))
585 return TRUE;
588 szFileList += dwTestLen + 1;
591 return FALSE;
594 /* removes nodes from the linked list that aren't specified in szFileList
595 * returns the number of files that are in both the linked list and szFileList
597 static DWORD fill_file_list(EXTRACTdest *extractDest, LPCSTR szCabName, LPSTR szFileList)
599 DWORD dwNumFound = 0;
600 struct ExtractFileList *pNode;
601 struct ExtractFileList *prev = NULL;
603 extractDest->flags |= EXTRACT_FILLFILELIST;
604 if (pExtract(extractDest, szCabName))
606 extractDest->flags &= ~EXTRACT_FILLFILELIST;
607 return -1;
610 pNode = extractDest->filelist;
611 while (pNode)
613 if (file_in_list(pNode->filename, szFileList))
615 prev = pNode;
616 pNode = pNode->next;
617 dwNumFound++;
619 else if (prev)
621 prev->next = pNode->next;
622 free_file_node(pNode);
623 pNode = prev->next;
625 else
627 extractDest->filelist = pNode->next;
628 free_file_node(pNode);
629 pNode = extractDest->filelist;
633 extractDest->flags &= ~EXTRACT_FILLFILELIST;
634 return dwNumFound;
637 /***********************************************************************
638 * ExtractFilesA (ADVPACK.@)
640 * Extracts the specified files from a cab archive into
641 * a destination directory.
643 * PARAMS
644 * CabName [I] Filename of the cab archive.
645 * ExpandDir [I] Destination directory for the extracted files.
646 * Flags [I] Reserved.
647 * FileList [I] Optional list of files to extract. See NOTES.
648 * LReserved [I] Reserved. Must be NULL.
649 * Reserved [I] Reserved. Must be 0.
651 * RETURNS
652 * Success: S_OK.
653 * Failure: E_FAIL.
655 * NOTES
656 * FileList is a colon-separated list of filenames. If FileList is
657 * non-NULL, only the files in the list will be extracted from the
658 * cab file, otherwise all files will be extracted. Any number of
659 * spaces, tabs, or colons can be before or after the list, but
660 * the list itself must only be separated by colons.
662 HRESULT WINAPI ExtractFilesA( LPCSTR CabName, LPCSTR ExpandDir, DWORD Flags,
663 LPCSTR FileList, LPVOID LReserved, DWORD Reserved)
665 EXTRACTdest extractDest;
666 HMODULE hCabinet;
667 HRESULT res = S_OK;
668 DWORD dwFileCount = 0;
669 DWORD dwFilesFound = 0;
670 LPSTR szConvertedList = NULL;
672 TRACE("(%p %p %ld %p %p %ld)\n", CabName, ExpandDir, Flags,
673 FileList, LReserved, Reserved);
675 if (!CabName || !ExpandDir)
676 return E_INVALIDARG;
678 if (GetFileAttributesA(ExpandDir) == INVALID_FILE_ATTRIBUTES)
679 return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
681 hCabinet = LoadLibraryA("cabinet.dll");
682 if (!hCabinet)
683 return E_FAIL;
685 pExtract = (void *)GetProcAddress(hCabinet, "Extract");
686 if (!pExtract)
688 res = E_FAIL;
689 goto done;
692 ZeroMemory(&extractDest, sizeof(EXTRACTdest));
693 lstrcpyA(extractDest.directory, ExpandDir);
695 if (FileList)
697 szConvertedList = convert_file_list(FileList, &dwFileCount);
698 if (!szConvertedList || dwFileCount == -1)
700 res = E_FAIL;
701 goto done;
704 dwFilesFound = fill_file_list(&extractDest, CabName, szConvertedList);
705 if (dwFilesFound != dwFileCount)
707 res = E_FAIL;
708 goto done;
711 else
712 extractDest.flags |= EXTRACT_FILLFILELIST;
714 extractDest.flags |= EXTRACT_EXTRACTFILES;
715 res = pExtract(&extractDest, CabName);
717 done:
718 FreeLibrary(hCabinet);
719 HeapFree(GetProcessHeap(), 0, szConvertedList);
721 return res;
724 /***********************************************************************
725 * FileSaveMarkNotExistA (ADVPACK.@)
727 * See FileSaveMarkNotExistW.
729 HRESULT WINAPI FileSaveMarkNotExistA(LPSTR pszFileList, LPSTR pszDir, LPSTR pszBaseName)
731 TRACE("(%p, %p, %p)\n", pszFileList, pszDir, pszBaseName);
733 return AddDelBackupEntryA(pszFileList, pszDir, pszBaseName, AADBE_DEL_ENTRY);
736 /***********************************************************************
737 * FileSaveMarkNotExistW (ADVPACK.@)
739 * Marks the files in the file list as not existing so they won't be
740 * backed up during a save.
742 * PARAMS
743 * pszFileList [I] NULL-separated list of filenames.
744 * pszDir [I] Path of the backup directory.
745 * pszBaseName [I] Basename of the INI file.
747 * RETURNS
748 * Success: S_OK.
749 * Failure: E_FAIL.
751 HRESULT WINAPI FileSaveMarkNotExistW(LPWSTR pszFileList, LPWSTR pszDir, LPWSTR pszBaseName)
753 TRACE("(%p, %p, %p)\n", pszFileList, pszDir, pszBaseName);
755 return AddDelBackupEntryW(pszFileList, pszDir, pszBaseName, AADBE_DEL_ENTRY);
758 /***********************************************************************
759 * FileSaveRestoreA (ADVPACK.@)
761 * Saves or restores the files in the specified file list.
763 * PARAMS
764 * hDlg [I] Handle to the dialog used for the display.
765 * pszFileList [I] NULL-separated list of filenames.
766 * pszDir [I] Path of the backup directory.
767 * pszBaseName [I] Basename of the backup files.
768 * dwFlags [I] See advpub.h.
770 * RETURNS
771 * Success: S_OK.
772 * Failure: E_FAIL.
774 * NOTES
775 * If pszFileList is NULL on restore, all files will be restored.
777 * BUGS
778 * Unimplemented.
780 HRESULT WINAPI FileSaveRestoreA(HWND hDlg, LPSTR pszFileList, LPSTR pszDir,
781 LPSTR pszBaseName, DWORD dwFlags)
783 FIXME("(%p, %p, %p, %p, %ld) stub\n", hDlg, pszFileList, pszDir,
784 pszBaseName, dwFlags);
786 return E_FAIL;
789 /***********************************************************************
790 * FileSaveRestoreOnINFA (ADVPACK.@)
793 * PARAMS
794 * hWnd [I] Handle to the window used for the display.
795 * pszTitle [I] Title of the window.
796 * pszINF [I] Fully-qualified INF filename.
797 * pszSection [I] GenInstall INF section name.
798 * pszBackupDir [I] Directory to store the backup file.
799 * pszBaseBackupFile [I] Basename of the backup files.
800 * dwFlags [I] See advpub.h
802 * RETURNS
803 * Success: S_OK.
804 * Failure: E_FAIL.
806 * NOTES
807 * If pszSection is NULL, the default section will be used.
809 * BUGS
810 * Unimplemented.
812 HRESULT WINAPI FileSaveRestoreOnINFA(HWND hWnd, LPCSTR pszTitle, LPCSTR pszINF,
813 LPCSTR pszSection, LPCSTR pszBackupDir,
814 LPCSTR pszBaseBackupFile, DWORD dwFlags)
816 FIXME("(%p, %p, %p, %p, %p, %p, %ld) stub\n", hWnd, pszTitle, pszINF,
817 pszSection, pszBackupDir, pszBaseBackupFile, dwFlags);
819 return E_FAIL;
822 /***********************************************************************
823 * GetVersionFromFileA (ADVPACK.@)
825 * See GetVersionFromFileExW.
827 HRESULT WINAPI GetVersionFromFileA(LPCSTR Filename, LPDWORD MajorVer,
828 LPDWORD MinorVer, BOOL Version )
830 TRACE("(%s, %p, %p, %d)\n", Filename, MajorVer, MinorVer, Version);
831 return GetVersionFromFileExA(Filename, MajorVer, MinorVer, Version);
834 /***********************************************************************
835 * GetVersionFromFileW (ADVPACK.@)
837 * See GetVersionFromFileExW.
839 HRESULT WINAPI GetVersionFromFileW(LPCWSTR Filename, LPDWORD MajorVer,
840 LPDWORD MinorVer, BOOL Version )
842 TRACE("(%s, %p, %p, %d)\n", debugstr_w(Filename), MajorVer, MinorVer, Version);
843 return GetVersionFromFileExW(Filename, MajorVer, MinorVer, Version);
846 /* data for GetVersionFromFileEx */
847 typedef struct tagLANGANDCODEPAGE
849 WORD wLanguage;
850 WORD wCodePage;
851 } LANGANDCODEPAGE;
853 /***********************************************************************
854 * GetVersionFromFileExA (ADVPACK.@)
856 * See GetVersionFromFileExW.
858 HRESULT WINAPI GetVersionFromFileExA(LPCSTR lpszFilename, LPDWORD pdwMSVer,
859 LPDWORD pdwLSVer, BOOL bVersion )
861 UNICODE_STRING filename;
862 HRESULT res;
864 TRACE("(%s, %p, %p, %d)\n", lpszFilename, pdwMSVer, pdwLSVer, bVersion);
866 RtlCreateUnicodeStringFromAsciiz(&filename, lpszFilename);
868 res = GetVersionFromFileExW(filename.Buffer, pdwMSVer, pdwLSVer, bVersion);
870 RtlFreeUnicodeString(&filename);
872 return res;
875 /***********************************************************************
876 * GetVersionFromFileExW (ADVPACK.@)
878 * Gets the files version or language information.
880 * PARAMS
881 * lpszFilename [I] The file to get the info from.
882 * pdwMSVer [O] Major version.
883 * pdwLSVer [O] Minor version.
884 * bVersion [I] Whether to retrieve version or language info.
886 * RETURNS
887 * Always returns S_OK.
889 * NOTES
890 * If bVersion is TRUE, version information is retrieved, else
891 * pdwMSVer gets the language ID and pdwLSVer gets the codepage ID.
893 HRESULT WINAPI GetVersionFromFileExW(LPCWSTR lpszFilename, LPDWORD pdwMSVer,
894 LPDWORD pdwLSVer, BOOL bVersion )
896 VS_FIXEDFILEINFO *pFixedVersionInfo;
897 LANGANDCODEPAGE *pLangAndCodePage;
898 DWORD dwHandle, dwInfoSize;
899 WCHAR szWinDir[MAX_PATH];
900 WCHAR szFile[MAX_PATH];
901 LPVOID pVersionInfo = NULL;
902 BOOL bFileCopied = FALSE;
903 UINT uValueLen;
905 static WCHAR backslash[] = {'\\',0};
906 static WCHAR translation[] = {
907 '\\','V','a','r','F','i','l','e','I','n','f','o',
908 '\\','T','r','a','n','s','l','a','t','i','o','n',0
911 TRACE("(%s, %p, %p, %d)\n", debugstr_w(lpszFilename),
912 pdwMSVer, pdwLSVer, bVersion);
914 *pdwLSVer = 0;
915 *pdwMSVer = 0;
917 lstrcpynW(szFile, lpszFilename, MAX_PATH);
919 dwInfoSize = GetFileVersionInfoSizeW(szFile, &dwHandle);
920 if (!dwInfoSize)
922 /* check that the file exists */
923 if (GetFileAttributesW(szFile) == INVALID_FILE_ATTRIBUTES)
924 return S_OK;
926 /* file exists, but won't be found by GetFileVersionInfoSize,
927 * so copy it to the temp dir where it will be found.
929 GetWindowsDirectoryW(szWinDir, MAX_PATH);
930 GetTempFileNameW(szWinDir, NULL, 0, szFile);
931 CopyFileW(lpszFilename, szFile, FALSE);
932 bFileCopied = TRUE;
934 dwInfoSize = GetFileVersionInfoSizeW(szFile, &dwHandle);
935 if (!dwInfoSize)
936 goto done;
939 pVersionInfo = HeapAlloc(GetProcessHeap(), 0, dwInfoSize);
940 if (!pVersionInfo)
941 goto done;
943 if (!GetFileVersionInfoW(szFile, dwHandle, dwInfoSize, pVersionInfo))
944 goto done;
946 if (bVersion)
948 if (!VerQueryValueW(pVersionInfo, backslash,
949 (LPVOID *)&pFixedVersionInfo, &uValueLen))
950 goto done;
952 if (!uValueLen)
953 goto done;
955 *pdwMSVer = pFixedVersionInfo->dwFileVersionMS;
956 *pdwLSVer = pFixedVersionInfo->dwFileVersionLS;
958 else
960 if (!VerQueryValueW(pVersionInfo, translation,
961 (LPVOID *)&pLangAndCodePage, &uValueLen))
962 goto done;
964 if (!uValueLen)
965 goto done;
967 *pdwMSVer = pLangAndCodePage->wLanguage;
968 *pdwLSVer = pLangAndCodePage->wCodePage;
971 done:
972 HeapFree(GetProcessHeap(), 0, pVersionInfo);
974 if (bFileCopied)
975 DeleteFileW(szFile);
977 return S_OK;