From 1f86353d60db5316663a9f156cfea23bfe44d677 Mon Sep 17 00:00:00 2001 From: Pierre Schweitzer Date: Thu, 13 Aug 2015 09:38:33 +0000 Subject: [PATCH] [SETUPAPI] Partly sync with Wine 1.7.47: - Implement SetupCloseLog(), SetupOpenLog(), SetupLogErrorA(), SetupLogErrorW() CORE-9924 svn path=/trunk/; revision=68705 --- reactos/dll/win32/setupapi/misc.c | 153 ++++++++++++++++++++++- reactos/dll/win32/setupapi/setupapi.spec | 2 +- reactos/dll/win32/setupapi/setupcab.c | 1 + reactos/dll/win32/setupapi/stubs.c | 26 ---- 4 files changed, 154 insertions(+), 28 deletions(-) diff --git a/reactos/dll/win32/setupapi/misc.c b/reactos/dll/win32/setupapi/misc.c index 0b79e43540f..626dc1305ae 100644 --- a/reactos/dll/win32/setupapi/misc.c +++ b/reactos/dll/win32/setupapi/misc.c @@ -28,6 +28,18 @@ static const WCHAR BackSlash[] = {'\\',0}; 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}; +/* Handles and critical sections for the SetupLog API */ +static HANDLE setupact = INVALID_HANDLE_VALUE; +static HANDLE setuperr = INVALID_HANDLE_VALUE; +static CRITICAL_SECTION setupapi_cs; +static CRITICAL_SECTION_DEBUG critsect_debug = +{ + 0, 0, &setupapi_cs, + { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList }, + 0, 0, { (DWORD_PTR)(__FILE__ ": setupapi_cs") } +}; +static CRITICAL_SECTION setupapi_cs = { &critsect_debug, -1, 0, 0, 0, 0 }; + DWORD GetFunctionPointer( IN PWSTR InstallerName, @@ -1964,4 +1976,143 @@ BOOL WINAPI SetupTerminateFileLog(HANDLE FileLogHandle) SetLastError(ERROR_SUCCESS); return TRUE; -} \ No newline at end of file +} + +/*********************************************************************** + * SetupCloseLog(SETUPAPI.@) + */ +void WINAPI SetupCloseLog(void) +{ + EnterCriticalSection(&setupapi_cs); + + CloseHandle(setupact); + setupact = INVALID_HANDLE_VALUE; + + CloseHandle(setuperr); + setuperr = INVALID_HANDLE_VALUE; + + LeaveCriticalSection(&setupapi_cs); +} + +/*********************************************************************** + * SetupOpenLog(SETUPAPI.@) + */ +BOOL WINAPI SetupOpenLog(BOOL reserved) +{ + WCHAR path[MAX_PATH]; + + static const WCHAR setupactlog[] = {'\\','s','e','t','u','p','a','c','t','.','l','o','g',0}; + static const WCHAR setuperrlog[] = {'\\','s','e','t','u','p','e','r','r','.','l','o','g',0}; + + EnterCriticalSection(&setupapi_cs); + + if (setupact != INVALID_HANDLE_VALUE && setuperr != INVALID_HANDLE_VALUE) + { + LeaveCriticalSection(&setupapi_cs); + return TRUE; + } + + GetWindowsDirectoryW(path, MAX_PATH); + lstrcatW(path, setupactlog); + + setupact = CreateFileW(path, FILE_GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, + NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (setupact == INVALID_HANDLE_VALUE) + { + LeaveCriticalSection(&setupapi_cs); + return FALSE; + } + + SetFilePointer(setupact, 0, NULL, FILE_END); + + GetWindowsDirectoryW(path, MAX_PATH); + lstrcatW(path, setuperrlog); + + setuperr = CreateFileW(path, FILE_GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, + NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (setuperr == INVALID_HANDLE_VALUE) + { + CloseHandle(setupact); + setupact = INVALID_HANDLE_VALUE; + LeaveCriticalSection(&setupapi_cs); + return FALSE; + } + + SetFilePointer(setuperr, 0, NULL, FILE_END); + + LeaveCriticalSection(&setupapi_cs); + + return TRUE; +} + +/*********************************************************************** + * SetupLogErrorA(SETUPAPI.@) + */ +BOOL WINAPI SetupLogErrorA(LPCSTR message, LogSeverity severity) +{ + static const char null[] = "(null)"; + BOOL ret; + DWORD written; + DWORD len; + + EnterCriticalSection(&setupapi_cs); + + if (setupact == INVALID_HANDLE_VALUE || setuperr == INVALID_HANDLE_VALUE) + { + SetLastError(ERROR_FILE_INVALID); + ret = FALSE; + goto done; + } + + if (message == NULL) + message = null; + + len = lstrlenA(message); + + ret = WriteFile(setupact, message, len, &written, NULL); + if (!ret) + goto done; + + if (severity >= LogSevMaximum) + { + ret = FALSE; + goto done; + } + + if (severity > LogSevInformation) + ret = WriteFile(setuperr, message, len, &written, NULL); + +done: + LeaveCriticalSection(&setupapi_cs); + return ret; +} + +/*********************************************************************** + * SetupLogErrorW(SETUPAPI.@) + */ +BOOL WINAPI SetupLogErrorW(LPCWSTR message, LogSeverity severity) +{ + LPSTR msg = NULL; + DWORD len; + BOOL ret; + + if (message) + { + len = WideCharToMultiByte(CP_ACP, 0, message, -1, NULL, 0, NULL, NULL); + msg = HeapAlloc(GetProcessHeap(), 0, len); + if (msg == NULL) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return FALSE; + } + WideCharToMultiByte(CP_ACP, 0, message, -1, msg, len, NULL, NULL); + } + + /* This is the normal way to proceed. The log files are ASCII files + * and W is to be converted. + */ + ret = SetupLogErrorA(msg, severity); + + HeapFree(GetProcessHeap(), 0, msg); + return ret; +} diff --git a/reactos/dll/win32/setupapi/setupapi.spec b/reactos/dll/win32/setupapi/setupapi.spec index 9ca79d212ed..0a3dc9c9892 100644 --- a/reactos/dll/win32/setupapi/setupapi.spec +++ b/reactos/dll/win32/setupapi/setupapi.spec @@ -452,7 +452,7 @@ @ stdcall SetupInstallServicesFromInfSectionW(long wstr long) @ stdcall SetupIterateCabinetA(str long ptr ptr) @ stdcall SetupIterateCabinetW(wstr long ptr ptr) -@ stub SetupLogErrorA +@ stdcall SetupLogErrorA(str long) @ stdcall SetupLogErrorW(wstr long) @ stub SetupLogFileA @ stub SetupLogFileW diff --git a/reactos/dll/win32/setupapi/setupcab.c b/reactos/dll/win32/setupapi/setupcab.c index 8bedd5257f3..a52e45a7792 100644 --- a/reactos/dll/win32/setupapi/setupcab.c +++ b/reactos/dll/win32/setupapi/setupcab.c @@ -675,6 +675,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) break; case DLL_PROCESS_DETACH: UnloadCABINETDll(); + SetupCloseLog(); break; } diff --git a/reactos/dll/win32/setupapi/stubs.c b/reactos/dll/win32/setupapi/stubs.c index 47405b331ec..4ec7acef29a 100644 --- a/reactos/dll/win32/setupapi/stubs.c +++ b/reactos/dll/win32/setupapi/stubs.c @@ -29,32 +29,6 @@ BOOL WINAPI pSetupRegistryDelnode(DWORD x, DWORD y) return FALSE; } -/*********************************************************************** - * SetupCloseLog(SETUPAPI.@) - */ -void WINAPI SetupCloseLog(void) -{ - FIXME("() stub\n"); -} - -/*********************************************************************** - * SetupLogErrorW(SETUPAPI.@) - */ -BOOL WINAPI SetupLogErrorW(LPCWSTR MessageString, LogSeverity Severity) -{ - FIXME("(%s, %d) stub\n", debugstr_w(MessageString), Severity); - return TRUE; -} - -/*********************************************************************** - * SetupOpenLog(SETUPAPI.@) - */ -BOOL WINAPI SetupOpenLog(BOOL Reserved) -{ - FIXME("(%d) stub\n", Reserved); - return TRUE; -} - /*********************************************************************** * SetupPromptReboot(SETUPAPI.@) */