2 * Setupapi miscellaneous functions
4 * Copyright 2005 Eric Kohl
5 * Copyright 2007 Hans Leidekker
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "setupapi_private.h"
27 /* Unicode constants */
28 static const WCHAR BackSlash
[] = {'\\',0};
29 static const WCHAR TranslationRegKey
[] = {'\\','V','e','r','F','i','l','e','I','n','f','o','\\','T','r','a','n','s','l','a','t','i','o','n',0};
33 IN PWSTR InstallerName
,
34 OUT HMODULE
* ModulePointer
,
35 OUT PVOID
* FunctionPointer
)
37 HMODULE hModule
= NULL
;
38 LPSTR FunctionNameA
= NULL
;
42 *ModulePointer
= NULL
;
43 *FunctionPointer
= NULL
;
45 Comma
= strchrW(InstallerName
, ',');
48 rc
= ERROR_INVALID_PARAMETER
;
54 hModule
= LoadLibraryW(InstallerName
);
62 /* Skip comma spaces */
63 while (*Comma
== ',' || isspaceW(*Comma
))
66 /* W->A conversion for function name */
67 FunctionNameA
= pSetupUnicodeToMultiByte(Comma
, CP_ACP
);
75 *FunctionPointer
= GetProcAddress(hModule
, FunctionNameA
);
76 if (!*FunctionPointer
)
82 *ModulePointer
= hModule
;
86 if (rc
!= ERROR_SUCCESS
&& hModule
)
88 MyFree(FunctionNameA
);
94 IN HMODULE ModulePointer
,
95 IN PVOID FunctionPointer
)
97 if (ModulePointer
== NULL
)
99 if (FreeLibrary(ModulePointer
))
100 return ERROR_SUCCESS
;
102 return GetLastError();
105 /**************************************************************************
106 * MyFree [SETUPAPI.@]
108 * Frees an allocated memory block from the process heap.
111 * lpMem [I] pointer to memory block which will be freed
116 VOID WINAPI
MyFree(LPVOID lpMem
)
118 TRACE("%p\n", lpMem
);
119 HeapFree(GetProcessHeap(), 0, lpMem
);
123 /**************************************************************************
124 * MyMalloc [SETUPAPI.@]
126 * Allocates memory block from the process heap.
129 * dwSize [I] size of the allocated memory block
132 * Success: pointer to allocated memory block
135 LPVOID WINAPI
MyMalloc(DWORD dwSize
)
137 TRACE("%lu\n", dwSize
);
138 return HeapAlloc(GetProcessHeap(), 0, dwSize
);
142 /**************************************************************************
143 * MyRealloc [SETUPAPI.@]
145 * Changes the size of an allocated memory block or allocates a memory
146 * block from the process heap.
149 * lpSrc [I] pointer to memory block which will be resized
150 * dwSize [I] new size of the memory block
153 * Success: pointer to the resized memory block
157 * If lpSrc is a NULL-pointer, then MyRealloc allocates a memory
158 * block like MyMalloc.
160 LPVOID WINAPI
MyRealloc(LPVOID lpSrc
, DWORD dwSize
)
162 TRACE("%p %lu\n", lpSrc
, dwSize
);
165 return HeapAlloc(GetProcessHeap(), 0, dwSize
);
167 return HeapReAlloc(GetProcessHeap(), 0, lpSrc
, dwSize
);
171 /**************************************************************************
172 * pSetupDuplicateString [SETUPAPI.@]
174 * Duplicates a unicode string.
177 * lpSrc [I] pointer to the unicode string that will be duplicated
180 * Success: pointer to the duplicated unicode string
184 * Call MyFree() to release the duplicated string.
186 LPWSTR WINAPI
pSetupDuplicateString(LPCWSTR lpSrc
)
190 TRACE("%s\n", debugstr_w(lpSrc
));
192 lpDst
= MyMalloc((lstrlenW(lpSrc
) + 1) * sizeof(WCHAR
));
196 strcpyW(lpDst
, lpSrc
);
202 /**************************************************************************
203 * QueryRegistryValue [SETUPAPI.@]
205 * Retrieves value data from the registry and allocates memory for the
209 * hKey [I] Handle of the key to query
210 * lpValueName [I] Name of value under hkey to query
211 * lpData [O] Destination for the values contents,
212 * lpType [O] Destination for the value type
213 * lpcbData [O] Destination for the size of data
216 * Success: ERROR_SUCCESS
220 * Use MyFree to release the lpData buffer.
222 LONG WINAPI
QueryRegistryValue(HKEY hKey
,
230 TRACE("%p %s %p %p %p\n",
231 hKey
, debugstr_w(lpValueName
), lpData
, lpType
, lpcbData
);
233 /* Get required buffer size */
235 lError
= RegQueryValueExW(hKey
, lpValueName
, 0, lpType
, NULL
, lpcbData
);
236 if (lError
!= ERROR_SUCCESS
)
239 /* Allocate buffer */
240 *lpData
= MyMalloc(*lpcbData
);
242 return ERROR_NOT_ENOUGH_MEMORY
;
244 /* Query registry value */
245 lError
= RegQueryValueExW(hKey
, lpValueName
, 0, lpType
, *lpData
, lpcbData
);
246 if (lError
!= ERROR_SUCCESS
)
253 /**************************************************************************
254 * pSetupMultiByteToUnicode [SETUPAPI.@]
256 * Converts a multi-byte string to a Unicode string.
259 * lpMultiByteStr [I] Multi-byte string to be converted
260 * uCodePage [I] Code page
263 * Success: pointer to the converted Unicode string
267 * Use MyFree to release the returned Unicode string.
269 LPWSTR WINAPI
pSetupMultiByteToUnicode(LPCSTR lpMultiByteStr
, UINT uCodePage
)
274 TRACE("%s %d\n", debugstr_a(lpMultiByteStr
), uCodePage
);
276 nLength
= MultiByteToWideChar(uCodePage
, 0, lpMultiByteStr
,
281 lpUnicodeStr
= MyMalloc(nLength
* sizeof(WCHAR
));
282 if (lpUnicodeStr
== NULL
)
284 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
288 if (!MultiByteToWideChar(uCodePage
, 0, lpMultiByteStr
,
289 nLength
, lpUnicodeStr
, nLength
))
291 MyFree(lpUnicodeStr
);
299 /**************************************************************************
300 * pSetupUnicodeToMultiByte [SETUPAPI.@]
302 * Converts a Unicode string to a multi-byte string.
305 * lpUnicodeStr [I] Unicode string to be converted
306 * uCodePage [I] Code page
309 * Success: pointer to the converted multi-byte string
313 * Use MyFree to release the returned multi-byte string.
315 LPSTR WINAPI
pSetupUnicodeToMultiByte(LPCWSTR lpUnicodeStr
, UINT uCodePage
)
317 LPSTR lpMultiByteStr
;
320 TRACE("%s %d\n", debugstr_w(lpUnicodeStr
), uCodePage
);
322 nLength
= WideCharToMultiByte(uCodePage
, 0, lpUnicodeStr
, -1,
323 NULL
, 0, NULL
, NULL
);
327 lpMultiByteStr
= MyMalloc(nLength
);
328 if (lpMultiByteStr
== NULL
)
331 if (!WideCharToMultiByte(uCodePage
, 0, lpUnicodeStr
, -1,
332 lpMultiByteStr
, nLength
, NULL
, NULL
))
334 MyFree(lpMultiByteStr
);
338 return lpMultiByteStr
;
342 /**************************************************************************
343 * DoesUserHavePrivilege [SETUPAPI.@]
345 * Check whether the current user has got a given privilege.
348 * lpPrivilegeName [I] Name of the privilege to be checked
354 BOOL WINAPI
DoesUserHavePrivilege(LPCWSTR lpPrivilegeName
)
358 PTOKEN_PRIVILEGES lpPrivileges
;
361 BOOL bResult
= FALSE
;
363 TRACE("%s\n", debugstr_w(lpPrivilegeName
));
365 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &hToken
))
368 if (!GetTokenInformation(hToken
, TokenPrivileges
, NULL
, 0, &dwSize
))
370 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
377 lpPrivileges
= MyMalloc(dwSize
);
378 if (lpPrivileges
== NULL
)
384 if (!GetTokenInformation(hToken
, TokenPrivileges
, lpPrivileges
, dwSize
, &dwSize
))
386 MyFree(lpPrivileges
);
393 if (!LookupPrivilegeValueW(NULL
, lpPrivilegeName
, &PrivilegeLuid
))
395 MyFree(lpPrivileges
);
399 for (i
= 0; i
< lpPrivileges
->PrivilegeCount
; i
++)
401 if (lpPrivileges
->Privileges
[i
].Luid
.HighPart
== PrivilegeLuid
.HighPart
&&
402 lpPrivileges
->Privileges
[i
].Luid
.LowPart
== PrivilegeLuid
.LowPart
)
408 MyFree(lpPrivileges
);
414 /**************************************************************************
415 * pSetupEnablePrivilege [SETUPAPI.@]
417 * Enables or disables one of the current users privileges.
420 * lpPrivilegeName [I] Name of the privilege to be changed
421 * bEnable [I] TRUE: Enables the privilege
422 * FALSE: Disables the privilege
428 BOOL WINAPI
pSetupEnablePrivilege(LPCWSTR lpPrivilegeName
, BOOL bEnable
)
430 TOKEN_PRIVILEGES Privileges
;
434 TRACE("%s %s\n", debugstr_w(lpPrivilegeName
), bEnable
? "TRUE" : "FALSE");
436 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
, &hToken
))
439 Privileges
.PrivilegeCount
= 1;
440 Privileges
.Privileges
[0].Attributes
= (bEnable
) ? SE_PRIVILEGE_ENABLED
: 0;
442 if (!LookupPrivilegeValueW(NULL
, lpPrivilegeName
,
443 &Privileges
.Privileges
[0].Luid
))
449 bResult
= AdjustTokenPrivileges(hToken
, FALSE
, &Privileges
, 0, NULL
, NULL
);
457 /**************************************************************************
458 * DelayedMove [SETUPAPI.@]
460 * Moves a file upon the next reboot.
463 * lpExistingFileName [I] Current file name
464 * lpNewFileName [I] New file name
470 BOOL WINAPI
DelayedMove(LPCWSTR lpExistingFileName
, LPCWSTR lpNewFileName
)
472 return MoveFileExW(lpExistingFileName
, lpNewFileName
,
473 MOVEFILE_REPLACE_EXISTING
| MOVEFILE_DELAY_UNTIL_REBOOT
);
477 /**************************************************************************
478 * FileExists [SETUPAPI.@]
480 * Checks whether a file exists.
483 * lpFileName [I] Name of the file to check
484 * lpNewFileName [O] Optional information about the existing file
490 BOOL WINAPI
FileExists(LPCWSTR lpFileName
, LPWIN32_FIND_DATAW lpFileFindData
)
492 WIN32_FIND_DATAW FindData
;
497 uErrorMode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
499 hFind
= FindFirstFileW(lpFileName
, &FindData
);
500 if (hFind
== INVALID_HANDLE_VALUE
)
502 dwError
= GetLastError();
503 SetErrorMode(uErrorMode
);
504 SetLastError(dwError
);
511 memcpy(lpFileFindData
, &FindData
, sizeof(WIN32_FIND_DATAW
));
513 SetErrorMode(uErrorMode
);
519 /**************************************************************************
520 * CaptureStringArg [SETUPAPI.@]
522 * Captures a UNICODE string.
525 * lpSrc [I] UNICODE string to be captured
526 * lpDst [O] Pointer to the captured UNICODE string
529 * Success: ERROR_SUCCESS
530 * Failure: ERROR_INVALID_PARAMETER
533 * Call MyFree to release the captured UNICODE string.
535 DWORD WINAPI
CaptureStringArg(LPCWSTR pSrc
, LPWSTR
*pDst
)
538 return ERROR_INVALID_PARAMETER
;
540 *pDst
= pSetupDuplicateString(pSrc
);
542 return ERROR_SUCCESS
;
546 /**************************************************************************
547 * pSetupCaptureAndConvertAnsiArg [SETUPAPI.@]
549 * Captures an ANSI string and converts it to a UNICODE string.
552 * lpSrc [I] ANSI string to be captured
553 * lpDst [O] Pointer to the captured UNICODE string
556 * Success: ERROR_SUCCESS
557 * Failure: ERROR_INVALID_PARAMETER
560 * Call MyFree to release the captured UNICODE string.
562 DWORD WINAPI
pSetupCaptureAndConvertAnsiArg(LPCSTR pSrc
, LPWSTR
*pDst
)
565 return ERROR_INVALID_PARAMETER
;
567 *pDst
= pSetupMultiByteToUnicode(pSrc
, CP_ACP
);
569 return ERROR_SUCCESS
;
573 /**************************************************************************
574 * pSetupOpenAndMapFileForRead [SETUPAPI.@]
576 * Open and map a file to a buffer.
579 * lpFileName [I] Name of the file to be opened
580 * lpSize [O] Pointer to the file size
581 * lpFile [0] Pointer to the file handle
582 * lpMapping [0] Pointer to the mapping handle
583 * lpBuffer [0] Pointer to the file buffer
586 * Success: ERROR_SUCCESS
590 * Call UnmapAndCloseFile to release the file.
592 DWORD WINAPI
pSetupOpenAndMapFileForRead(LPCWSTR lpFileName
,
600 TRACE("%s %p %p %p %p\n",
601 debugstr_w(lpFileName
), lpSize
, lpFile
, lpMapping
, lpBuffer
);
603 *lpFile
= CreateFileW(lpFileName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
604 OPEN_EXISTING
, 0, NULL
);
605 if (*lpFile
== INVALID_HANDLE_VALUE
)
606 return GetLastError();
608 *lpSize
= GetFileSize(*lpFile
, NULL
);
609 if (*lpSize
== INVALID_FILE_SIZE
)
611 dwError
= GetLastError();
612 CloseHandle(*lpFile
);
616 *lpMapping
= CreateFileMappingW(*lpFile
, NULL
, PAGE_READONLY
, 0,
618 if (*lpMapping
== NULL
)
620 dwError
= GetLastError();
621 CloseHandle(*lpFile
);
625 *lpBuffer
= MapViewOfFile(*lpMapping
, FILE_MAP_READ
, 0, 0, *lpSize
);
626 if (*lpBuffer
== NULL
)
628 dwError
= GetLastError();
629 CloseHandle(*lpMapping
);
630 CloseHandle(*lpFile
);
634 return ERROR_SUCCESS
;
638 /**************************************************************************
639 * pSetupUnmapAndCloseFile [SETUPAPI.@]
641 * Unmap and close a mapped file.
644 * hFile [I] Handle to the file
645 * hMapping [I] Handle to the file mapping
646 * lpBuffer [I] Pointer to the file buffer
652 BOOL WINAPI
pSetupUnmapAndCloseFile(HANDLE hFile
, HANDLE hMapping
, LPVOID lpBuffer
)
655 hFile
, hMapping
, lpBuffer
);
657 if (!UnmapViewOfFile(lpBuffer
))
660 if (!CloseHandle(hMapping
))
663 if (!CloseHandle(hFile
))
670 /**************************************************************************
671 * StampFileSecurity [SETUPAPI.@]
673 * Assign a new security descriptor to the given file.
676 * lpFileName [I] Name of the file
677 * pSecurityDescriptor [I] New security descriptor
680 * Success: ERROR_SUCCESS
683 DWORD WINAPI
StampFileSecurity(LPCWSTR lpFileName
, PSECURITY_DESCRIPTOR pSecurityDescriptor
)
685 TRACE("%s %p\n", debugstr_w(lpFileName
), pSecurityDescriptor
);
687 if (!SetFileSecurityW(lpFileName
, OWNER_SECURITY_INFORMATION
|
688 GROUP_SECURITY_INFORMATION
| DACL_SECURITY_INFORMATION
,
689 pSecurityDescriptor
))
690 return GetLastError();
692 return ERROR_SUCCESS
;
696 /**************************************************************************
697 * TakeOwnershipOfFile [SETUPAPI.@]
699 * Takes the ownership of the given file.
702 * lpFileName [I] Name of the file
705 * Success: ERROR_SUCCESS
708 DWORD WINAPI
TakeOwnershipOfFile(LPCWSTR lpFileName
)
710 SECURITY_DESCRIPTOR SecDesc
;
711 HANDLE hToken
= NULL
;
712 PTOKEN_OWNER pOwner
= NULL
;
716 TRACE("%s\n", debugstr_w(lpFileName
));
718 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &hToken
))
719 return GetLastError();
721 if (!GetTokenInformation(hToken
, TokenOwner
, NULL
, 0, &dwSize
))
726 pOwner
= (PTOKEN_OWNER
)MyMalloc(dwSize
);
730 return ERROR_NOT_ENOUGH_MEMORY
;
733 if (!GetTokenInformation(hToken
, TokenOwner
, pOwner
, dwSize
, &dwSize
))
738 if (!InitializeSecurityDescriptor(&SecDesc
, SECURITY_DESCRIPTOR_REVISION
))
743 if (!SetSecurityDescriptorOwner(&SecDesc
, pOwner
->Owner
, FALSE
))
748 if (!SetFileSecurityW(lpFileName
, OWNER_SECURITY_INFORMATION
, &SecDesc
))
756 return ERROR_SUCCESS
;
759 dwError
= GetLastError();
770 /**************************************************************************
771 * RetreiveFileSecurity [SETUPAPI.@]
773 * Retrieve the security descriptor that is associated with the given file.
776 * lpFileName [I] Name of the file
779 * Success: ERROR_SUCCESS
782 DWORD WINAPI
RetreiveFileSecurity(LPCWSTR lpFileName
,
783 PSECURITY_DESCRIPTOR
*pSecurityDescriptor
)
785 PSECURITY_DESCRIPTOR SecDesc
;
786 DWORD dwSize
= 0x100;
789 TRACE("%s %p\n", debugstr_w(lpFileName
), pSecurityDescriptor
);
791 SecDesc
= MyMalloc(dwSize
);
793 return ERROR_NOT_ENOUGH_MEMORY
;
795 if (GetFileSecurityW(lpFileName
, OWNER_SECURITY_INFORMATION
|
796 GROUP_SECURITY_INFORMATION
| DACL_SECURITY_INFORMATION
,
797 SecDesc
, dwSize
, &dwSize
))
799 *pSecurityDescriptor
= SecDesc
;
800 return ERROR_SUCCESS
;
803 dwError
= GetLastError();
804 if (dwError
!= ERROR_INSUFFICIENT_BUFFER
)
810 SecDesc
= MyRealloc(SecDesc
, dwSize
);
812 return ERROR_NOT_ENOUGH_MEMORY
;
814 if (GetFileSecurityW(lpFileName
, OWNER_SECURITY_INFORMATION
|
815 GROUP_SECURITY_INFORMATION
| DACL_SECURITY_INFORMATION
,
816 SecDesc
, dwSize
, &dwSize
))
818 *pSecurityDescriptor
= SecDesc
;
819 return ERROR_SUCCESS
;
822 dwError
= GetLastError();
829 static DWORD global_flags
= 0; /* FIXME: what should be in here? */
831 /***********************************************************************
832 * pSetupGetGlobalFlags (SETUPAPI.@)
834 DWORD WINAPI
pSetupGetGlobalFlags(void)
841 /***********************************************************************
842 * pSetupSetGlobalFlags (SETUPAPI.@)
844 void WINAPI
pSetupSetGlobalFlags( DWORD flags
)
846 global_flags
= flags
;
849 /***********************************************************************
850 * AssertFail (SETUPAPI.@)
852 * Shows an assert fail error messagebox
855 * lpFile [I] file where assert failed
856 * uLine [I] line number in file
857 * lpMessage [I] assert message
860 VOID WINAPI
AssertFail(LPSTR lpFile
, UINT uLine
, LPSTR lpMessage
)
862 CHAR szModule
[MAX_PATH
];
867 TRACE("%s %u %s\n", lpFile
, uLine
, lpMessage
);
869 GetModuleFileNameA(hInstance
, szModule
, MAX_PATH
);
870 lpName
= strrchr(szModule
, '\\');
877 "Assertion failure at line %u in file %s: %s\n\nCall DebugBreak()?",
878 uLine
, lpFile
, lpMessage
);
880 if (MessageBoxA(NULL
, szBuffer
, lpName
, MB_SETFOREGROUND
|
881 MB_TASKMODAL
| MB_ICONERROR
| MB_YESNO
) == IDYES
)
886 /**************************************************************************
887 * GetSetFileTimestamp [SETUPAPI.@]
889 * Gets or sets a files timestamp.
892 * lpFileName [I] File name
893 * lpCreationTime [I/O] Creation time
894 * lpLastAccessTime [I/O] Last access time
895 * lpLastWriteTime [I/O] Last write time
896 * bSetFileTime [I] TRUE: Set file times
897 * FALSE: Get file times
900 * Success: ERROR_SUCCESS
903 DWORD WINAPI
GetSetFileTimestamp(LPCWSTR lpFileName
,
904 LPFILETIME lpCreationTime
,
905 LPFILETIME lpLastAccessTime
,
906 LPFILETIME lpLastWriteTime
,
907 BOOLEAN bSetFileTime
)
911 DWORD dwError
= ERROR_SUCCESS
;
913 TRACE("%s %p %p %p %x\n", debugstr_w(lpFileName
), lpCreationTime
,
914 lpLastAccessTime
, lpLastWriteTime
, bSetFileTime
);
916 hFile
= CreateFileW(lpFileName
,
917 bSetFileTime
? GENERIC_WRITE
: GENERIC_READ
,
918 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
924 if (hFile
== INVALID_HANDLE_VALUE
)
925 return GetLastError();
928 bRet
= SetFileTime(hFile
, lpCreationTime
, lpLastAccessTime
, lpLastWriteTime
);
930 bRet
= GetFileTime(hFile
, lpCreationTime
, lpLastAccessTime
, lpLastWriteTime
);
933 dwError
= GetLastError();
941 /**************************************************************************
942 * pSetupGetFileTitle [SETUPAPI.@]
944 * Returns a pointer to the last part of a fully qualified file name.
947 * lpFileName [I] File name
950 * Pointer to a files name.
953 pSetupGetFileTitle(LPCWSTR lpFileName
)
959 TRACE("%s\n", debugstr_w(lpFileName
));
961 ptr
= (LPWSTR
)lpFileName
;
971 if (c
== (WCHAR
)'\\' || c
== (WCHAR
)'/' || c
== (WCHAR
)':')
979 /**************************************************************************
980 * pSetupConcatenatePaths [SETUPAPI.@]
982 * Concatenates two paths.
985 * lpPath [I/O] Path to append path to
986 * lpAppend [I] Path to append
987 * dwBufferSize [I] Size of the path buffer
988 * lpRequiredSize [O] Required size for the concatenated path. Optional
995 pSetupConcatenatePaths(LPWSTR lpPath
,
998 LPDWORD lpRequiredSize
)
1003 BOOL bBackslash
= FALSE
;
1005 TRACE("%s %s %lu %p\n", debugstr_w(lpPath
), debugstr_w(lpAppend
),
1006 dwBufferSize
, lpRequiredSize
);
1008 dwPathSize
= lstrlenW(lpPath
);
1010 /* Ignore trailing backslash */
1011 if (lpPath
[dwPathSize
- 1] == (WCHAR
)'\\')
1014 dwAppendSize
= lstrlenW(lpAppend
);
1016 /* Does the source string have a leading backslash? */
1017 if (lpAppend
[0] == (WCHAR
)'\\')
1023 dwTotalSize
= dwPathSize
+ dwAppendSize
+ 2;
1024 if (lpRequiredSize
!= NULL
)
1025 *lpRequiredSize
= dwTotalSize
;
1027 /* Append a backslash to the destination string */
1028 if (bBackslash
== FALSE
)
1030 if (dwPathSize
< dwBufferSize
)
1032 lpPath
[dwPathSize
- 1] = (WCHAR
)'\\';
1037 if (dwPathSize
+ dwAppendSize
< dwBufferSize
)
1039 lstrcpynW(&lpPath
[dwPathSize
],
1044 if (dwBufferSize
>= dwTotalSize
)
1045 lpPath
[dwTotalSize
- 1] = 0;
1047 return (dwBufferSize
>= dwTotalSize
);
1051 /**************************************************************************
1052 * pSetupCenterWindowRelativeToParent [SETUPAPI.@]
1054 * Centers a window relative to its parent.
1057 * hwnd [I] Window to center.
1063 pSetupCenterWindowRelativeToParent(HWND hwnd
)
1069 INT nWindowWidth
, nWindowHeight
;
1070 INT nOwnerWidth
, nOwnerHeight
;
1073 hwndOwner
= GetWindow(hwnd
, GW_OWNER
);
1074 if (hwndOwner
== NULL
)
1079 ClientToScreen(hwndOwner
, &ptOrigin
);
1081 GetWindowRect(hwnd
, &rcWindow
);
1082 GetClientRect(hwndOwner
, &rcOwner
);
1084 nWindowWidth
= rcWindow
.right
- rcWindow
.left
;
1085 nWindowHeight
= rcWindow
.bottom
- rcWindow
.top
;
1087 nOwnerWidth
= rcOwner
.right
- rcOwner
.left
;
1088 nOwnerHeight
= rcOwner
.bottom
- rcOwner
.top
;
1090 posX
= ((nOwnerWidth
- nWindowWidth
) / 2) + ptOrigin
.x
;
1091 posY
= ((nOwnerHeight
- nWindowHeight
) / 2) + ptOrigin
.y
;
1093 MoveWindow(hwnd
, posX
, posY
, nWindowHeight
, nWindowWidth
, 0);
1097 /**************************************************************************
1098 * pSetupGetVersionInfoFromImage [SETUPAPI.@]
1100 * Retrieves version information for a given file.
1103 * lpFileName [I] File name
1104 * lpFileVersion [O] Pointer to the full file version
1105 * lpVersionVarSize [O] Pointer to the size of the variable version
1113 pSetupGetVersionInfoFromImage(LPWSTR lpFileName
,
1114 PULARGE_INTEGER lpFileVersion
,
1115 LPWORD lpVersionVarSize
)
1121 VS_FIXEDFILEINFO
*lpFixedInfo
;
1124 dwSize
= GetFileVersionInfoSizeW(lpFileName
, &dwHandle
);
1128 lpInfo
= MyMalloc(dwSize
);
1132 if (!GetFileVersionInfoW(lpFileName
, 0, dwSize
, lpInfo
))
1138 if (!VerQueryValueW(lpInfo
, BackSlash
,
1139 (LPVOID
*)&lpFixedInfo
, &uSize
))
1145 lpFileVersion
->LowPart
= lpFixedInfo
->dwFileVersionLS
;
1146 lpFileVersion
->HighPart
= lpFixedInfo
->dwFileVersionMS
;
1148 *lpVersionVarSize
= 0;
1149 if (!VerQueryValueW(lpInfo
, TranslationRegKey
,
1150 (LPVOID
*)&lpVarSize
, &uSize
))
1158 *lpVersionVarSize
= *lpVarSize
;
1166 /***********************************************************************
1167 * SetupUninstallOEMInfW (SETUPAPI.@)
1169 BOOL WINAPI
SetupUninstallOEMInfW( PCWSTR inf_file
, DWORD flags
, PVOID reserved
)
1171 static const WCHAR infW
[] = {'\\','i','n','f','\\',0};
1172 WCHAR target
[MAX_PATH
];
1174 TRACE("%s, 0x%08x, %p\n", debugstr_w(inf_file
), flags
, reserved
);
1178 SetLastError(ERROR_INVALID_PARAMETER
);
1182 if (!GetWindowsDirectoryW( target
, sizeof(target
)/sizeof(WCHAR
) )) return FALSE
;
1184 strcatW( target
, infW
);
1185 strcatW( target
, inf_file
);
1187 if (flags
& SUOI_FORCEDELETE
)
1188 return DeleteFileW(target
);
1190 FIXME("not deleting %s\n", debugstr_w(target
));
1195 /***********************************************************************
1196 * SetupUninstallOEMInfA (SETUPAPI.@)
1198 BOOL WINAPI
SetupUninstallOEMInfA( PCSTR inf_file
, DWORD flags
, PVOID reserved
)
1201 WCHAR
*inf_fileW
= NULL
;
1203 TRACE("%s, 0x%08x, %p\n", debugstr_a(inf_file
), flags
, reserved
);
1205 if (inf_file
&& !(inf_fileW
= strdupAtoW( inf_file
))) return FALSE
;
1206 ret
= SetupUninstallOEMInfW( inf_fileW
, flags
, reserved
);
1207 HeapFree( GetProcessHeap(), 0, inf_fileW
);
1211 /***********************************************************************
1212 * InstallCatalog (SETUPAPI.@)
1214 DWORD WINAPI
InstallCatalog( LPCSTR catalog
, LPCSTR basename
, LPSTR fullname
)
1216 FIXME("%s, %s, %p\n", debugstr_a(catalog
), debugstr_a(basename
), fullname
);
1220 /***********************************************************************
1221 * pSetupInstallCatalog (SETUPAPI.@)
1223 DWORD WINAPI
pSetupInstallCatalog( LPCWSTR catalog
, LPCWSTR basename
, LPWSTR fullname
)
1228 TRACE ("%s, %s, %p\n", debugstr_w(catalog
), debugstr_w(basename
), fullname
);
1230 if (!CryptCATAdminAcquireContext(&admin
,NULL
,0))
1231 return GetLastError();
1233 if (!(cat
= CryptCATAdminAddCatalog( admin
, (PWSTR
)catalog
, (PWSTR
)basename
, 0 )))
1235 DWORD rc
= GetLastError();
1236 CryptCATAdminReleaseContext(admin
, 0);
1239 CryptCATAdminReleaseCatalogContext(admin
, cat
, 0);
1240 CryptCATAdminReleaseContext(admin
,0);
1243 FIXME("not returning full installed catalog path\n");
1248 static UINT
detect_compression_type( LPCWSTR file
)
1252 UINT type
= FILE_COMPRESSION_NONE
;
1253 static const BYTE LZ_MAGIC
[] = { 0x53, 0x5a, 0x44, 0x44, 0x88, 0xf0, 0x27, 0x33 };
1254 static const BYTE MSZIP_MAGIC
[] = { 0x4b, 0x57, 0x41, 0x4a };
1255 static const BYTE NTCAB_MAGIC
[] = { 0x4d, 0x53, 0x43, 0x46 };
1258 handle
= CreateFileW( file
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
1259 if (handle
== INVALID_HANDLE_VALUE
)
1261 ERR("cannot open file %s\n", debugstr_w(file
));
1262 return FILE_COMPRESSION_NONE
;
1264 if (!ReadFile( handle
, buffer
, sizeof(buffer
), &size
, NULL
) || size
!= sizeof(buffer
))
1266 CloseHandle( handle
);
1267 return FILE_COMPRESSION_NONE
;
1269 if (!memcmp( buffer
, LZ_MAGIC
, sizeof(LZ_MAGIC
) )) type
= FILE_COMPRESSION_WINLZA
;
1270 else if (!memcmp( buffer
, MSZIP_MAGIC
, sizeof(MSZIP_MAGIC
) )) type
= FILE_COMPRESSION_MSZIP
;
1271 else if (!memcmp( buffer
, NTCAB_MAGIC
, sizeof(NTCAB_MAGIC
) )) type
= FILE_COMPRESSION_MSZIP
; /* not a typo */
1273 CloseHandle( handle
);
1277 static BOOL
get_file_size( LPCWSTR file
, DWORD
*size
)
1281 handle
= CreateFileW( file
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
1282 if (handle
== INVALID_HANDLE_VALUE
)
1284 ERR("cannot open file %s\n", debugstr_w(file
));
1287 *size
= GetFileSize( handle
, NULL
);
1288 CloseHandle( handle
);
1292 static BOOL
get_file_sizes_none( LPCWSTR source
, DWORD
*source_size
, DWORD
*target_size
)
1296 if (!get_file_size( source
, &size
)) return FALSE
;
1297 if (source_size
) *source_size
= size
;
1298 if (target_size
) *target_size
= size
;
1302 static BOOL
get_file_sizes_lz( LPCWSTR source
, DWORD
*source_size
, DWORD
*target_size
)
1309 if (!get_file_size( source
, &size
)) ret
= FALSE
;
1310 else *source_size
= size
;
1317 if ((file
= LZOpenFileW( (LPWSTR
)source
, &of
, OF_READ
)) < 0)
1319 ERR("cannot open source file for reading\n");
1322 *target_size
= LZSeek( file
, 0, 2 );
1328 static UINT CALLBACK
file_compression_info_callback( PVOID context
, UINT notification
, UINT_PTR param1
, UINT_PTR param2
)
1330 DWORD
*size
= context
;
1331 FILE_IN_CABINET_INFO_W
*info
= (FILE_IN_CABINET_INFO_W
*)param1
;
1333 switch (notification
)
1335 case SPFILENOTIFY_FILEINCABINET
:
1337 *size
= info
->FileSize
;
1340 default: return NO_ERROR
;
1344 static BOOL
get_file_sizes_cab( LPCWSTR source
, DWORD
*source_size
, DWORD
*target_size
)
1351 if (!get_file_size( source
, &size
)) ret
= FALSE
;
1352 else *source_size
= size
;
1356 ret
= SetupIterateCabinetW( source
, 0, file_compression_info_callback
, target_size
);
1361 /***********************************************************************
1362 * SetupGetFileCompressionInfoExA (SETUPAPI.@)
1364 * See SetupGetFileCompressionInfoExW.
1366 BOOL WINAPI
SetupGetFileCompressionInfoExA( PCSTR source
, PSTR name
, DWORD len
, PDWORD required
,
1367 PDWORD source_size
, PDWORD target_size
, PUINT type
)
1370 WCHAR
*nameW
= NULL
, *sourceW
= NULL
;
1374 TRACE("%s, %p, %d, %p, %p, %p, %p\n", debugstr_a(source
), name
, len
, required
,
1375 source_size
, target_size
, type
);
1377 if (!source
|| !(sourceW
= pSetupMultiByteToUnicode( source
, CP_ACP
))) return FALSE
;
1381 ret
= SetupGetFileCompressionInfoExW( sourceW
, NULL
, 0, &nb_chars
, NULL
, NULL
, NULL
);
1382 if (!(nameW
= HeapAlloc( GetProcessHeap(), 0, nb_chars
* sizeof(WCHAR
) )))
1388 ret
= SetupGetFileCompressionInfoExW( sourceW
, nameW
, nb_chars
, &nb_chars
, source_size
, target_size
, type
);
1391 if ((nameA
= pSetupUnicodeToMultiByte( nameW
, CP_ACP
)))
1393 if (name
&& len
>= nb_chars
) lstrcpyA( name
, nameA
);
1396 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1402 if (required
) *required
= nb_chars
;
1403 HeapFree( GetProcessHeap(), 0, nameW
);
1409 /***********************************************************************
1410 * SetupGetFileCompressionInfoExW (SETUPAPI.@)
1412 * Get compression type and compressed/uncompressed sizes of a given file.
1415 * source [I] File to examine.
1416 * name [O] Actual filename used.
1417 * len [I] Length in characters of 'name' buffer.
1418 * required [O] Number of characters written to 'name'.
1419 * source_size [O] Size of compressed file.
1420 * target_size [O] Size of uncompressed file.
1421 * type [O] Compression type.
1427 BOOL WINAPI
SetupGetFileCompressionInfoExW( PCWSTR source
, PWSTR name
, DWORD len
, PDWORD required
,
1428 PDWORD source_size
, PDWORD target_size
, PUINT type
)
1434 TRACE("%s, %p, %d, %p, %p, %p, %p\n", debugstr_w(source
), name
, len
, required
,
1435 source_size
, target_size
, type
);
1437 if (!source
) return FALSE
;
1439 source_len
= lstrlenW( source
) + 1;
1440 if (required
) *required
= source_len
;
1441 if (name
&& len
>= source_len
)
1443 lstrcpyW( name
, source
);
1448 comp
= detect_compression_type( source
);
1449 if (type
) *type
= comp
;
1453 case FILE_COMPRESSION_MSZIP
:
1454 case FILE_COMPRESSION_NTCAB
: ret
= get_file_sizes_cab( source
, source_size
, target_size
); break;
1455 case FILE_COMPRESSION_NONE
: ret
= get_file_sizes_none( source
, source_size
, target_size
); break;
1456 case FILE_COMPRESSION_WINLZA
: ret
= get_file_sizes_lz( source
, source_size
, target_size
); break;
1462 /***********************************************************************
1463 * SetupGetFileCompressionInfoA (SETUPAPI.@)
1465 * See SetupGetFileCompressionInfoW.
1467 DWORD WINAPI
SetupGetFileCompressionInfoA( PCSTR source
, PSTR
*name
, PDWORD source_size
,
1468 PDWORD target_size
, PUINT type
)
1471 DWORD error
, required
;
1474 TRACE("%s, %p, %p, %p, %p\n", debugstr_a(source
), name
, source_size
, target_size
, type
);
1476 if (!source
|| !name
|| !source_size
|| !target_size
|| !type
)
1477 return ERROR_INVALID_PARAMETER
;
1479 ret
= SetupGetFileCompressionInfoExA( source
, NULL
, 0, &required
, NULL
, NULL
, NULL
);
1480 if (!(actual_name
= MyMalloc( required
))) return ERROR_NOT_ENOUGH_MEMORY
;
1482 ret
= SetupGetFileCompressionInfoExA( source
, actual_name
, required
, &required
,
1483 source_size
, target_size
, type
);
1486 error
= GetLastError();
1487 MyFree( actual_name
);
1490 *name
= actual_name
;
1491 return ERROR_SUCCESS
;
1494 /***********************************************************************
1495 * SetupGetFileCompressionInfoW (SETUPAPI.@)
1497 * Get compression type and compressed/uncompressed sizes of a given file.
1500 * source [I] File to examine.
1501 * name [O] Actual filename used.
1502 * source_size [O] Size of compressed file.
1503 * target_size [O] Size of uncompressed file.
1504 * type [O] Compression type.
1507 * Success: ERROR_SUCCESS
1508 * Failure: Win32 error code.
1510 DWORD WINAPI
SetupGetFileCompressionInfoW( PCWSTR source
, PWSTR
*name
, PDWORD source_size
,
1511 PDWORD target_size
, PUINT type
)
1514 DWORD error
, required
;
1517 TRACE("%s, %p, %p, %p, %p\n", debugstr_w(source
), name
, source_size
, target_size
, type
);
1519 if (!source
|| !name
|| !source_size
|| !target_size
|| !type
)
1520 return ERROR_INVALID_PARAMETER
;
1522 ret
= SetupGetFileCompressionInfoExW( source
, NULL
, 0, &required
, NULL
, NULL
, NULL
);
1523 if (!(actual_name
= MyMalloc( required
*sizeof(WCHAR
) ))) return ERROR_NOT_ENOUGH_MEMORY
;
1525 ret
= SetupGetFileCompressionInfoExW( source
, actual_name
, required
, &required
,
1526 source_size
, target_size
, type
);
1529 error
= GetLastError();
1530 MyFree( actual_name
);
1533 *name
= actual_name
;
1534 return ERROR_SUCCESS
;
1537 static DWORD
decompress_file_lz( LPCWSTR source
, LPCWSTR target
)
1544 if ((src
= LZOpenFileW( (LPWSTR
)source
, &sof
, OF_READ
)) < 0)
1546 ERR("cannot open source file for reading\n");
1547 return ERROR_FILE_NOT_FOUND
;
1549 if ((dst
= LZOpenFileW( (LPWSTR
)target
, &dof
, OF_CREATE
)) < 0)
1551 ERR("cannot open target file for writing\n");
1553 return ERROR_FILE_NOT_FOUND
;
1555 if ((error
= LZCopy( src
, dst
)) >= 0) ret
= ERROR_SUCCESS
;
1558 WARN("failed to decompress file %d\n", error
);
1559 ret
= ERROR_INVALID_DATA
;
1567 struct callback_context
1573 static UINT CALLBACK
decompress_or_copy_callback( PVOID context
, UINT notification
, UINT_PTR param1
, UINT_PTR param2
)
1575 struct callback_context
*context_info
= context
;
1576 FILE_IN_CABINET_INFO_W
*info
= (FILE_IN_CABINET_INFO_W
*)param1
;
1578 switch (notification
)
1580 case SPFILENOTIFY_FILEINCABINET
:
1582 if (context_info
->has_extracted
)
1583 return FILEOP_ABORT
;
1585 TRACE("Requesting extraction of cabinet file %s\n",
1586 wine_dbgstr_w(info
->NameInCabinet
));
1587 strcpyW( info
->FullTargetName
, context_info
->target
);
1588 context_info
->has_extracted
= TRUE
;
1591 default: return NO_ERROR
;
1595 static DWORD
decompress_file_cab( LPCWSTR source
, LPCWSTR target
)
1597 struct callback_context context
= {0, target
};
1600 ret
= SetupIterateCabinetW( source
, 0, decompress_or_copy_callback
, &context
);
1602 if (ret
) return ERROR_SUCCESS
;
1603 else return GetLastError();
1606 /***********************************************************************
1607 * SetupDecompressOrCopyFileA (SETUPAPI.@)
1609 * See SetupDecompressOrCopyFileW.
1611 DWORD WINAPI
SetupDecompressOrCopyFileA( PCSTR source
, PCSTR target
, PUINT type
)
1614 WCHAR
*sourceW
= NULL
, *targetW
= NULL
;
1616 if (source
&& !(sourceW
= pSetupMultiByteToUnicode( source
, CP_ACP
))) return FALSE
;
1617 if (target
&& !(targetW
= pSetupMultiByteToUnicode( target
, CP_ACP
)))
1620 return ERROR_NOT_ENOUGH_MEMORY
;
1623 ret
= SetupDecompressOrCopyFileW( sourceW
, targetW
, type
);
1631 /***********************************************************************
1632 * SetupDecompressOrCopyFileW (SETUPAPI.@)
1634 * Copy a file and decompress it if needed.
1637 * source [I] File to copy.
1638 * target [I] Filename of the copy.
1639 * type [I] Compression type.
1642 * Success: ERROR_SUCCESS
1643 * Failure: Win32 error code.
1645 DWORD WINAPI
SetupDecompressOrCopyFileW( PCWSTR source
, PCWSTR target
, PUINT type
)
1648 DWORD ret
= ERROR_INVALID_PARAMETER
;
1650 if (!source
|| !target
) return ERROR_INVALID_PARAMETER
;
1652 if (!type
) comp
= detect_compression_type( source
);
1657 case FILE_COMPRESSION_NONE
:
1658 if (CopyFileW( source
, target
, FALSE
)) ret
= ERROR_SUCCESS
;
1659 else ret
= GetLastError();
1661 case FILE_COMPRESSION_WINLZA
:
1662 ret
= decompress_file_lz( source
, target
);
1664 case FILE_COMPRESSION_NTCAB
:
1665 case FILE_COMPRESSION_MSZIP
:
1666 ret
= decompress_file_cab( source
, target
);
1669 WARN("unknown compression type %d\n", comp
);
1673 TRACE("%s -> %s %d\n", debugstr_w(source
), debugstr_w(target
), comp
);
1678 * implemented (used by pSetupGuidFromString)
1680 static BOOL
TrimGuidString(PCWSTR szString
, LPWSTR szNewString
)
1685 if (wcslen(szString
) == 38)
1687 if ((szString
[0] == L
'{') && (szString
[37] == L
'}'))
1689 for (Index
= 0; Index
< wcslen(szString
); Index
++)
1690 szBuffer
[Index
] = szString
[Index
+ 1];
1692 szBuffer
[36] = L
'\0';
1693 wcscpy(szNewString
, szBuffer
);
1697 szNewString
[0] = L
'\0';
1706 pSetupGuidFromString(PCWSTR pString
, LPGUID lpGUID
)
1711 if (!TrimGuidString(pString
, szBuffer
))
1713 return RPC_S_INVALID_STRING_UUID
;
1716 Status
= UuidFromStringW(szBuffer
, lpGUID
);
1717 if (Status
!= RPC_S_OK
)
1719 return RPC_S_INVALID_STRING_UUID
;
1730 pSetupStringFromGuid(LPGUID lpGUID
, PWSTR pString
, DWORD dwStringLen
)
1736 if (dwStringLen
< 39)
1738 return ERROR_INSUFFICIENT_BUFFER
;
1741 Status
= UuidToStringW(lpGUID
, &rpcBuffer
);
1742 if (Status
!= RPC_S_OK
)
1747 wcscpy(szBuffer
, L
"{");
1748 wcscat(szBuffer
, rpcBuffer
);
1749 wcscat(szBuffer
, L
"}");
1751 wcscpy(pString
, szBuffer
);
1753 RpcStringFreeW(&rpcBuffer
);
1762 pSetupIsGuidNull(LPGUID lpGUID
)
1764 return IsEqualGUID(lpGUID
, &GUID_NULL
);
1772 pSetupIsUserAdmin(VOID
)
1774 SID_IDENTIFIER_AUTHORITY Authority
= {SECURITY_NT_AUTHORITY
};
1775 BOOL bResult
= FALSE
;
1778 if (!AllocateAndInitializeSid(&Authority
, 2, SECURITY_BUILTIN_DOMAIN_RID
,
1779 DOMAIN_ALIAS_RID_ADMINS
, 0, 0, 0, 0, 0, 0,
1785 if (!CheckTokenMembership(NULL
, lpSid
, &bResult
))
1795 /***********************************************************************
1796 * SetupInitializeFileLogW(SETUPAPI.@)
1798 HSPFILELOG WINAPI
SetupInitializeFileLogW(LPCWSTR LogFileName
, DWORD Flags
)
1800 struct FileLog
* Log
;
1802 WCHAR Windir
[MAX_PATH
];
1805 TRACE("%s, 0x%x\n",debugstr_w(LogFileName
),Flags
);
1807 if (Flags
& SPFILELOG_SYSTEMLOG
)
1809 if (!pSetupIsUserAdmin() && !(Flags
& SPFILELOG_QUERYONLY
))
1811 /* insufficient privileges */
1812 SetLastError(ERROR_ACCESS_DENIED
);
1813 return INVALID_HANDLE_VALUE
;
1816 if (LogFileName
|| (Flags
& SPFILELOG_FORCENEW
))
1818 /* invalid parameter */
1819 SetLastError(ERROR_INVALID_PARAMETER
);
1820 return INVALID_HANDLE_VALUE
;
1823 ret
= GetSystemWindowsDirectoryW(Windir
, MAX_PATH
);
1824 if (!ret
|| ret
>= MAX_PATH
)
1826 /* generic failure */
1827 return INVALID_HANDLE_VALUE
;
1831 wcscat(Windir
, L
"repair\\setup.log");
1837 /* invalid parameter */
1838 SetLastError(ERROR_INVALID_PARAMETER
);
1839 return INVALID_HANDLE_VALUE
;
1842 wcsncpy(Windir
, LogFileName
, MAX_PATH
);
1845 if (FileExists(Windir
, NULL
))
1847 /* take ownership */
1848 ret
= TakeOwnershipOfFile(Windir
);
1850 if (ret
!= ERROR_SUCCESS
)
1854 return INVALID_HANDLE_VALUE
;
1857 if (!SetFileAttributesW(Windir
, FILE_ATTRIBUTE_NORMAL
))
1860 return INVALID_HANDLE_VALUE
;
1863 if ((Flags
& SPFILELOG_FORCENEW
))
1865 if (!DeleteFileW(Windir
))
1868 return INVALID_HANDLE_VALUE
;
1874 hLog
= CreateFileW(Windir
,
1875 (Flags
& SPFILELOG_QUERYONLY
) ? GENERIC_READ
: GENERIC_WRITE
,
1876 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
1879 FILE_ATTRIBUTE_NORMAL
,
1882 if (hLog
== INVALID_HANDLE_VALUE
)
1885 return INVALID_HANDLE_VALUE
;
1888 /* close log handle */
1891 /* allocate file log struct */
1892 Log
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct FileLog
));
1895 /* not enough memory */
1896 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1897 return INVALID_HANDLE_VALUE
;
1900 /* initialize log */
1901 Log
->LogName
= HeapAlloc(GetProcessHeap(), 0, (wcslen(Windir
)+1) * sizeof(WCHAR
));
1904 /* not enough memory */
1905 HeapFree(GetProcessHeap(), 0, Log
);
1906 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1907 return INVALID_HANDLE_VALUE
;
1910 wcscpy(Log
->LogName
, Windir
);
1911 Log
->ReadOnly
= (Flags
& SPFILELOG_QUERYONLY
);
1912 Log
->SystemLog
= (Flags
& SPFILELOG_SYSTEMLOG
);
1914 return (HSPFILELOG
)Log
;
1917 /***********************************************************************
1918 * SetupInitializeFileLogA(SETUPAPI.@)
1920 HSPFILELOG WINAPI
SetupInitializeFileLogA(LPCSTR LogFileName
, DWORD Flags
)
1923 LPWSTR LogFileNameW
= NULL
;
1925 TRACE("%s, 0x%x\n",debugstr_a(LogFileName
),Flags
);
1929 LogFileNameW
= strdupAtoW(LogFileName
);
1933 /* not enough memory */
1934 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1935 return INVALID_HANDLE_VALUE
;
1938 hLog
= SetupInitializeFileLogW(LogFileNameW
, Flags
);
1939 HeapFree(GetProcessHeap(), 0, LogFileNameW
);
1943 hLog
= SetupInitializeFileLogW(NULL
, Flags
);
1949 /***********************************************************************
1950 * SetupTerminateFileLog(SETUPAPI.@)
1952 BOOL WINAPI
SetupTerminateFileLog(HANDLE FileLogHandle
)
1954 struct FileLog
* Log
;
1956 TRACE ("%p\n",FileLogHandle
);
1958 Log
= (struct FileLog
*)FileLogHandle
;
1960 /* free file log handle */
1961 HeapFree(GetProcessHeap(), 0, Log
->LogName
);
1962 HeapFree(GetProcessHeap(), 0, Log
);
1964 SetLastError(ERROR_SUCCESS
);