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
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
)
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
);
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
;
64 TRACE("(%p, %p, %p, %ld)\n", lpcszFileList
, lpcszBackupDir
,
65 lpcszBaseName
, dwFlags
);
68 filelist
= ansi_to_unicode_list(lpcszFileList
);
72 RtlCreateUnicodeStringFromAsciiz(&backupdir
, lpcszBackupDir
);
73 RtlCreateUnicodeStringFromAsciiz(&basename
, lpcszBaseName
);
76 backup
= backupdir
.Buffer
;
80 res
= AddDelBackupEntryW(filelist
, backup
, basename
.Buffer
, dwFlags
);
82 HeapFree(GetProcessHeap(), 0, filelist
);
84 RtlFreeUnicodeString(&backupdir
);
85 RtlFreeUnicodeString(&basename
);
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.
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.
108 * If the INI file does not exist before adding entries to it, the file
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
)
135 lstrcpyW(szIniPath
, lpcszBackupDir
);
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
)
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
);
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
)
172 UINT CALLBACK
pQueueCallback(PVOID Context
, UINT Notification
,
173 UINT_PTR Param1
, UINT_PTR Param2
)
175 /* only be verbose for error notifications */
177 Notification
== SPFILENOTIFY_RENAMEERROR
||
178 Notification
== SPFILENOTIFY_DELETEERROR
||
179 Notification
== SPFILENOTIFY_COPYERROR
)
181 return SetupDefaultQueueCallbackA(Context
, Notification
,
188 /***********************************************************************
189 * AdvInstallFileA (ADVPACK.@)
191 * Copies a file from the source to a destination.
194 * hwnd [I] Handle to the window used for messages.
195 * lpszSourceDir [I] Source directory.
196 * lpszSourceFile [I] Source filename.
197 * lpszDestDir [I] Destination directory.
198 * lpszDestFile [I] Optional destination filename.
199 * dwFlags [I] See advpub.h.
200 * dwReserved [I] Reserved. Must be 0.
207 * If lpszDestFile is NULL, the destination filename is the same as
210 HRESULT WINAPI
AdvInstallFileA(HWND hwnd
, LPCSTR lpszSourceDir
, LPCSTR lpszSourceFile
,
211 LPCSTR lpszDestDir
, LPCSTR lpszDestFile
,
212 DWORD dwFlags
, DWORD dwReserved
)
214 PSP_FILE_CALLBACK_A pFileCallback
;
215 LPSTR szPath
, szDestFilename
;
216 char szRootPath
[ROOT_LENGTH
];
217 DWORD dwLen
, dwLastError
;
221 TRACE("(%p,%p,%p,%p,%p,%ld,%ld)\n", hwnd
, debugstr_a(lpszSourceDir
),
222 debugstr_a(lpszSourceFile
), debugstr_a(lpszDestDir
),
223 debugstr_a(lpszDestFile
), dwFlags
, dwReserved
);
225 if (!lpszSourceDir
|| !lpszSourceFile
|| !lpszDestDir
)
228 fileQueue
= SetupOpenFileQueue();
229 if (fileQueue
== INVALID_HANDLE_VALUE
)
230 return HRESULT_FROM_WIN32(GetLastError());
233 dwLastError
= ERROR_SUCCESS
;
235 lstrcpynA(szRootPath
, lpszSourceDir
, ROOT_LENGTH
);
236 szPath
= (LPSTR
)lpszSourceDir
+ ROOT_LENGTH
;
238 /* use lpszSourceFile as destination filename if lpszDestFile is NULL */
241 dwLen
= lstrlenA(lpszDestFile
);
242 szDestFilename
= HeapAlloc(GetProcessHeap(), 0, dwLen
);
243 lstrcpyA(szDestFilename
, lpszDestFile
);
247 dwLen
= lstrlenA(lpszSourceFile
);
248 szDestFilename
= HeapAlloc(GetProcessHeap(), 0, dwLen
);
249 lstrcpyA(szDestFilename
, lpszSourceFile
);
252 /* add the file copy operation to the setup queue */
253 if (!SetupQueueCopyA(fileQueue
, szRootPath
, szPath
, lpszSourceFile
, NULL
,
254 NULL
, lpszDestDir
, szDestFilename
, dwFlags
))
256 dwLastError
= GetLastError();
260 pContext
= SetupInitDefaultQueueCallbackEx(hwnd
, INVALID_HANDLE_VALUE
,
264 dwLastError
= GetLastError();
268 /* don't output anything for AIF_QUIET */
269 if (dwFlags
& AIF_QUIET
)
270 pFileCallback
= pQuietQueueCallback
;
272 pFileCallback
= pQueueCallback
;
274 /* perform the file copy */
275 if (!SetupCommitFileQueueA(hwnd
, fileQueue
, pFileCallback
, pContext
))
277 dwLastError
= GetLastError();
282 SetupTermDefaultQueueCallback(pContext
);
283 SetupCloseFileQueue(fileQueue
);
285 HeapFree(GetProcessHeap(), 0, szDestFilename
);
287 return HRESULT_FROM_WIN32(dwLastError
);
290 static HRESULT
DELNODE_recurse_dirtree(LPSTR fname
, DWORD flags
)
292 DWORD fattrs
= GetFileAttributesA(fname
);
293 HRESULT ret
= E_FAIL
;
295 if (fattrs
& FILE_ATTRIBUTE_DIRECTORY
)
298 WIN32_FIND_DATAA w32fd
;
300 int fname_len
= lstrlenA(fname
);
302 /* Generate a path with wildcard suitable for iterating */
303 if (CharPrevA(fname
, fname
+ fname_len
) != "\\")
305 lstrcpyA(fname
+ fname_len
, "\\");
308 lstrcpyA(fname
+ fname_len
, "*");
310 if ((hFindFile
= FindFirstFileA(fname
, &w32fd
)) != INVALID_HANDLE_VALUE
)
312 /* Iterate through the files in the directory */
313 for (done
= FALSE
; !done
; done
= !FindNextFileA(hFindFile
, &w32fd
))
315 TRACE("%s\n", w32fd
.cFileName
);
316 if (lstrcmpA(".", w32fd
.cFileName
) != 0 &&
317 lstrcmpA("..", w32fd
.cFileName
) != 0)
319 lstrcpyA(fname
+ fname_len
, w32fd
.cFileName
);
320 if (DELNODE_recurse_dirtree(fname
, flags
) != S_OK
)
326 FindClose(hFindFile
);
329 /* We're done with this directory, so restore the old path without wildcard */
330 *(fname
+ fname_len
) = '\0';
334 TRACE("%s: directory\n", fname
);
335 if (SetFileAttributesA(fname
, FILE_ATTRIBUTE_NORMAL
) && RemoveDirectoryA(fname
))
343 TRACE("%s: file\n", fname
);
344 if (SetFileAttributesA(fname
, FILE_ATTRIBUTE_NORMAL
) && DeleteFileA(fname
))
353 /***********************************************************************
354 * DelNodeA (ADVPACK.@)
356 * Deletes a file or directory
359 * pszFileOrDirName [I] Name of file or directory to delete
360 * dwFlags [I] Flags; see include/advpub.h
368 * - Native version apparently does a lot of checking to make sure
369 * we're not trying to delete a system directory etc.
371 HRESULT WINAPI
DelNodeA( LPCSTR pszFileOrDirName
, DWORD dwFlags
)
373 CHAR fname
[MAX_PATH
];
374 HRESULT ret
= E_FAIL
;
376 TRACE("(%s, 0x%08lx)\n", debugstr_a(pszFileOrDirName
), dwFlags
);
379 FIXME("Flags ignored!\n");
381 if (pszFileOrDirName
&& *pszFileOrDirName
)
383 lstrcpyA(fname
, pszFileOrDirName
);
385 /* TODO: Should check for system directory deletion etc. here */
387 ret
= DELNODE_recurse_dirtree(fname
, dwFlags
);
393 /* returns the parameter at dwIndex in a list of parameters
394 * separated by the cSeparator character
396 static LPSTR
get_parameter(LPSTR szParameters
, CHAR cSeparator
, DWORD dwIndex
)
398 LPSTR szParam
= NULL
;
401 while (*szParameters
&& i
< dwIndex
)
403 if (*szParameters
== cSeparator
)
412 szParam
= HeapAlloc(GetProcessHeap(), 0, lstrlenA(szParameters
));
413 lstrcpyA(szParam
, szParameters
);
418 /***********************************************************************
419 * DelNodeRunDLL32A (ADVPACK.@)
421 * Deletes a file or directory, WinMain style.
424 * hWnd [I] Handle to the window used for the display.
425 * hInst [I] Instance of the process.
426 * cmdline [I] Contains parameters in the order FileOrDirName,Flags.
427 * show [I] How the window should be shown.
433 HRESULT WINAPI
DelNodeRunDLL32A( HWND hWnd
, HINSTANCE hInst
, LPSTR cmdline
, INT show
)
435 LPSTR szFilename
, szFlags
;
439 TRACE("(%s)\n", debugstr_a(cmdline
));
441 /* get the parameters at indexes 0 and 1 respectively */
442 szFilename
= get_parameter(cmdline
, ',', 0);
443 szFlags
= get_parameter(cmdline
, ',', 1);
445 dwFlags
= atol(szFlags
);
447 res
= DelNodeA(szFilename
, dwFlags
);
449 HeapFree(GetProcessHeap(), 0, szFilename
);
450 HeapFree(GetProcessHeap(), 0, szFlags
);
455 /* The following defintions were copied from dlls/cabinet/cabinet.h */
457 /* EXTRACTdest flags */
458 #define EXTRACT_FILLFILELIST 0x00000001
459 #define EXTRACT_EXTRACTFILES 0x00000002
461 struct ExtractFileList
{
463 struct ExtractFileList
*next
;
464 BOOL unknown
; /* always 1L */
467 /* the first parameter of the function Extract */
469 long result1
; /* 0x000 */
470 long unknown1
[3]; /* 0x004 */
471 struct ExtractFileList
*filelist
; /* 0x010 */
472 long filecount
; /* 0x014 */
473 DWORD flags
; /* 0x018 */
474 char directory
[0x104]; /* 0x01c */
475 char lastfile
[0x20c]; /* 0x120 */
478 static HRESULT (WINAPI
*pExtract
)(EXTRACTdest
*, LPCSTR
);
480 /* removes legal characters before and after file list, and
481 * converts the file list to a NULL-separated list
483 static LPSTR
convert_file_list(LPCSTR FileList
, DWORD
*dwNumFiles
)
486 char *first
= (char *)FileList
;
487 char *last
= (char *)FileList
+ strlen(FileList
) - 1;
488 LPSTR szConvertedList
, temp
;
490 /* any number of these chars before the list is OK */
491 while (first
< last
&& (*first
== ' ' || *first
== '\t' || *first
== ':'))
494 /* any number of these chars after the list is OK */
495 while (last
> first
&& (*last
== ' ' || *last
== '\t' || *last
== ':'))
501 dwLen
= last
- first
+ 3; /* room for double-null termination */
502 szConvertedList
= HeapAlloc(GetProcessHeap(), 0, dwLen
);
503 lstrcpynA(szConvertedList
, first
, dwLen
- 1);
505 szConvertedList
[dwLen
- 1] = '\0';
506 szConvertedList
[dwLen
] = '\0';
509 if (!lstrlenA(szConvertedList
))
514 /* convert the colons to double-null termination */
515 temp
= szConvertedList
;
527 return szConvertedList
;
530 static void free_file_node(struct ExtractFileList
*pNode
)
532 HeapFree(GetProcessHeap(), 0, pNode
->filename
);
533 HeapFree(GetProcessHeap(), 0, pNode
);
536 /* determines whether szFile is in the NULL-separated szFileList */
537 static BOOL
file_in_list(LPSTR szFile
, LPSTR szFileList
)
539 DWORD dwLen
= lstrlenA(szFile
);
544 dwTestLen
= lstrlenA(szFileList
);
546 if (dwTestLen
== dwLen
)
548 if (!lstrcmpiA(szFile
, szFileList
))
552 szFileList
+= dwTestLen
+ 1;
558 /* removes nodes from the linked list that aren't specified in szFileList
559 * returns the number of files that are in both the linked list and szFileList
561 static DWORD
fill_file_list(EXTRACTdest
*extractDest
, LPCSTR szCabName
, LPSTR szFileList
)
563 DWORD dwNumFound
= 0;
564 struct ExtractFileList
*pNode
;
565 struct ExtractFileList
*prev
= NULL
;
567 extractDest
->flags
|= EXTRACT_FILLFILELIST
;
568 if (pExtract(extractDest
, szCabName
))
570 extractDest
->flags
&= ~EXTRACT_FILLFILELIST
;
574 pNode
= extractDest
->filelist
;
577 if (file_in_list(pNode
->filename
, szFileList
))
585 prev
->next
= pNode
->next
;
586 free_file_node(pNode
);
591 extractDest
->filelist
= pNode
->next
;
592 free_file_node(pNode
);
593 pNode
= extractDest
->filelist
;
597 extractDest
->flags
&= ~EXTRACT_FILLFILELIST
;
601 /***********************************************************************
602 * ExtractFilesA (ADVPACK.@)
604 * Extracts the specified files from a cab archive into
605 * a destination directory.
608 * CabName [I] Filename of the cab archive.
609 * ExpandDir [I] Destination directory for the extracted files.
610 * Flags [I] Reserved.
611 * FileList [I] Optional list of files to extract. See NOTES.
612 * LReserved [I] Reserved. Must be NULL.
613 * Reserved [I] Reserved. Must be 0.
620 * FileList is a colon-separated list of filenames. If FileList is
621 * non-NULL, only the files in the list will be extracted from the
622 * cab file, otherwise all files will be extracted. Any number of
623 * spaces, tabs, or colons can be before or after the list, but
624 * the list itself must only be separated by colons.
626 HRESULT WINAPI
ExtractFilesA( LPCSTR CabName
, LPCSTR ExpandDir
, DWORD Flags
,
627 LPCSTR FileList
, LPVOID LReserved
, DWORD Reserved
)
629 EXTRACTdest extractDest
;
632 DWORD dwFileCount
= 0;
633 DWORD dwFilesFound
= 0;
634 LPSTR szConvertedList
= NULL
;
636 TRACE("(%p %p %ld %p %p %ld)\n", CabName
, ExpandDir
, Flags
,
637 FileList
, LReserved
, Reserved
);
639 if (!CabName
|| !ExpandDir
)
642 if (GetFileAttributesA(ExpandDir
) == INVALID_FILE_ATTRIBUTES
)
643 return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
);
645 hCabinet
= LoadLibraryA("cabinet.dll");
649 pExtract
= (void *)GetProcAddress(hCabinet
, "Extract");
656 ZeroMemory(&extractDest
, sizeof(EXTRACTdest
));
657 lstrcpyA(extractDest
.directory
, ExpandDir
);
661 szConvertedList
= convert_file_list(FileList
, &dwFileCount
);
662 if (!szConvertedList
|| dwFileCount
== -1)
668 dwFilesFound
= fill_file_list(&extractDest
, CabName
, szConvertedList
);
669 if (dwFilesFound
!= dwFileCount
)
676 extractDest
.flags
|= EXTRACT_FILLFILELIST
;
678 extractDest
.flags
|= EXTRACT_EXTRACTFILES
;
679 res
= pExtract(&extractDest
, CabName
);
682 FreeLibrary(hCabinet
);
683 HeapFree(GetProcessHeap(), 0, szConvertedList
);
688 /***********************************************************************
689 * FileSaveMarkNotExistA (ADVPACK.@)
691 * Marks the files in the file list as not existing so they won't be
692 * backed up during a save.
695 * pszFileList [I] NULL-separated list of filenames.
696 * pszDir [I] Path of the backup directory.
697 * pszBaseName [I] Basename of the INI file.
703 HRESULT WINAPI
FileSaveMarkNotExistA(LPSTR pszFileList
, LPSTR pszDir
, LPSTR pszBaseName
)
705 TRACE("(%p, %p, %p)\n", pszFileList
, pszDir
, pszBaseName
);
707 return AddDelBackupEntryA(pszFileList
, pszDir
, pszBaseName
, AADBE_DEL_ENTRY
);
710 /***********************************************************************
711 * FileSaveRestoreA (ADVPACK.@)
713 * Saves or restores the files in the specified file list.
716 * hDlg [I] Handle to the dialog used for the display.
717 * pszFileList [I] NULL-separated list of filenames.
718 * pszDir [I] Path of the backup directory.
719 * pszBaseName [I] Basename of the backup files.
720 * dwFlags [I] See advpub.h.
727 * If pszFileList is NULL on restore, all files will be restored.
732 HRESULT WINAPI
FileSaveRestoreA(HWND hDlg
, LPSTR pszFileList
, LPSTR pszDir
,
733 LPSTR pszBaseName
, DWORD dwFlags
)
735 FIXME("(%p, %p, %p, %p, %ld) stub\n", hDlg
, pszFileList
, pszDir
,
736 pszBaseName
, dwFlags
);
741 /***********************************************************************
742 * FileSaveRestoreOnINFA (ADVPACK.@)
746 * hWnd [I] Handle to the window used for the display.
747 * pszTitle [I] Title of the window.
748 * pszINF [I] Fully-qualified INF filename.
749 * pszSection [I] GenInstall INF section name.
750 * pszBackupDir [I] Directory to store the backup file.
751 * pszBaseBackupFile [I] Basename of the backup files.
752 * dwFlags [I] See advpub.h
759 * If pszSection is NULL, the default section will be used.
764 HRESULT WINAPI
FileSaveRestoreOnINFA(HWND hWnd
, LPCSTR pszTitle
, LPCSTR pszINF
,
765 LPCSTR pszSection
, LPCSTR pszBackupDir
,
766 LPCSTR pszBaseBackupFile
, DWORD dwFlags
)
768 FIXME("(%p, %p, %p, %p, %p, %p, %ld) stub\n", hWnd
, pszTitle
, pszINF
,
769 pszSection
, pszBackupDir
, pszBaseBackupFile
, dwFlags
);
774 /***********************************************************************
775 * GetVersionFromFileA (ADVPACK.@)
777 * See GetVersionFromFileEx.
779 HRESULT WINAPI
GetVersionFromFileA(LPCSTR Filename
, LPDWORD MajorVer
,
780 LPDWORD MinorVer
, BOOL Version
)
782 TRACE("(%s, %p, %p, %d)\n", Filename
, MajorVer
, MinorVer
, Version
);
783 return GetVersionFromFileExA(Filename
, MajorVer
, MinorVer
, Version
);
786 /* data for GetVersionFromFileEx */
787 typedef struct tagLANGANDCODEPAGE
793 /***********************************************************************
794 * GetVersionFromFileExA (ADVPACK.@)
796 * Gets the files version or language information.
799 * lpszFilename [I] The file to get the info from.
800 * pdwMSVer [O] Major version.
801 * pdwLSVer [O] Minor version.
802 * bVersion [I] Whether to retrieve version or language info.
805 * Always returns S_OK.
808 * If bVersion is TRUE, version information is retrieved, else
809 * pdwMSVer gets the language ID and pdwLSVer gets the codepage ID.
811 HRESULT WINAPI
GetVersionFromFileExA(LPCSTR lpszFilename
, LPDWORD pdwMSVer
,
812 LPDWORD pdwLSVer
, BOOL bVersion
)
814 VS_FIXEDFILEINFO
*pFixedVersionInfo
;
815 LANGANDCODEPAGE
*pLangAndCodePage
;
816 DWORD dwHandle
, dwInfoSize
;
817 CHAR szWinDir
[MAX_PATH
];
818 CHAR szFile
[MAX_PATH
];
819 LPVOID pVersionInfo
= NULL
;
820 BOOL bFileCopied
= FALSE
;
823 TRACE("(%s, %p, %p, %d)\n", lpszFilename
, pdwMSVer
, pdwLSVer
, bVersion
);
828 lstrcpynA(szFile
, lpszFilename
, MAX_PATH
);
830 dwInfoSize
= GetFileVersionInfoSizeA(szFile
, &dwHandle
);
833 /* check that the file exists */
834 if (GetFileAttributesA(szFile
) == INVALID_FILE_ATTRIBUTES
)
837 /* file exists, but won't be found by GetFileVersionInfoSize,
838 * so copy it to the temp dir where it will be found.
840 GetWindowsDirectoryA(szWinDir
, MAX_PATH
);
841 GetTempFileNameA(szWinDir
, NULL
, 0, szFile
);
842 CopyFileA(lpszFilename
, szFile
, FALSE
);
845 dwInfoSize
= GetFileVersionInfoSizeA(szFile
, &dwHandle
);
850 pVersionInfo
= HeapAlloc(GetProcessHeap(), 0, dwInfoSize
);
854 if (!GetFileVersionInfoA(szFile
, dwHandle
, dwInfoSize
, pVersionInfo
))
859 if (!VerQueryValueA(pVersionInfo
, "\\",
860 (LPVOID
*)&pFixedVersionInfo
, &uValueLen
))
866 *pdwMSVer
= pFixedVersionInfo
->dwFileVersionMS
;
867 *pdwLSVer
= pFixedVersionInfo
->dwFileVersionLS
;
871 if (!VerQueryValueA(pVersionInfo
, "\\VarFileInfo\\Translation",
872 (LPVOID
*)&pLangAndCodePage
, &uValueLen
))
878 *pdwMSVer
= pLangAndCodePage
->wLanguage
;
879 *pdwLSVer
= pLangAndCodePage
->wCodePage
;
883 HeapFree(GetProcessHeap(), 0, pVersionInfo
);