Commit f3e7ed44 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

msi: Open the log file once per package.

parent 29ee6540
...@@ -1766,24 +1766,26 @@ UINT WINAPI MsiEnableLogA(DWORD dwLogMode, LPCSTR szLogFile, DWORD attributes) ...@@ -1766,24 +1766,26 @@ UINT WINAPI MsiEnableLogA(DWORD dwLogMode, LPCSTR szLogFile, DWORD attributes)
UINT WINAPI MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD attributes) UINT WINAPI MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD attributes)
{ {
HANDLE file = INVALID_HANDLE_VALUE;
TRACE("%08x %s %08x\n", dwLogMode, debugstr_w(szLogFile), attributes); TRACE("%08x %s %08x\n", dwLogMode, debugstr_w(szLogFile), attributes);
msi_free(gszLogFile);
gszLogFile = NULL;
if (szLogFile) if (szLogFile)
{ {
lstrcpyW(gszLogFile,szLogFile); HANDLE file;
if (!(attributes & INSTALLLOGATTRIBUTES_APPEND)) if (!(attributes & INSTALLLOGATTRIBUTES_APPEND))
DeleteFileW(szLogFile); DeleteFileW(szLogFile);
file = CreateFileW(szLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, file = CreateFileW(szLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL); FILE_ATTRIBUTE_NORMAL, NULL);
if (file != INVALID_HANDLE_VALUE) if (file != INVALID_HANDLE_VALUE)
{
gszLogFile = strdupW(szLogFile);
CloseHandle(file); CloseHandle(file);
}
else else
ERR("Unable to enable log %s (%u)\n", debugstr_w(szLogFile), GetLastError()); ERR("Unable to enable log %s (%u)\n", debugstr_w(szLogFile), GetLastError());
} }
else
gszLogFile[0] = '\0';
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
......
...@@ -44,7 +44,7 @@ INSTALLUI_HANDLERW gUIHandlerW = NULL; ...@@ -44,7 +44,7 @@ INSTALLUI_HANDLERW gUIHandlerW = NULL;
INSTALLUI_HANDLER_RECORD gUIHandlerRecord = NULL; INSTALLUI_HANDLER_RECORD gUIHandlerRecord = NULL;
DWORD gUIFilter = 0; DWORD gUIFilter = 0;
LPVOID gUIContext = NULL; LPVOID gUIContext = NULL;
WCHAR gszLogFile[MAX_PATH]; WCHAR *gszLogFile = NULL;
HINSTANCE msi_hInstance; HINSTANCE msi_hInstance;
static WCHAR msi_path[MAX_PATH]; static WCHAR msi_path[MAX_PATH];
...@@ -78,6 +78,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) ...@@ -78,6 +78,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
if (msi_typelib) ITypeLib_Release( msi_typelib ); if (msi_typelib) ITypeLib_Release( msi_typelib );
msi_dialog_unregister_class(); msi_dialog_unregister_class();
msi_free_handle_table(); msi_free_handle_table();
msi_free( gszLogFile );
break; break;
} }
return TRUE; return TRUE;
......
...@@ -331,6 +331,7 @@ typedef struct tagMSIPACKAGE ...@@ -331,6 +331,7 @@ typedef struct tagMSIPACKAGE
struct list folders; struct list folders;
LPWSTR ActionFormat; LPWSTR ActionFormat;
LPWSTR LastAction; LPWSTR LastAction;
HANDLE log_file;
struct list classes; struct list classes;
struct list extensions; struct list extensions;
...@@ -879,7 +880,7 @@ extern INSTALLUI_HANDLERW gUIHandlerW; ...@@ -879,7 +880,7 @@ extern INSTALLUI_HANDLERW gUIHandlerW;
extern INSTALLUI_HANDLER_RECORD gUIHandlerRecord; extern INSTALLUI_HANDLER_RECORD gUIHandlerRecord;
extern DWORD gUIFilter; extern DWORD gUIFilter;
extern LPVOID gUIContext; extern LPVOID gUIContext;
extern WCHAR gszLogFile[MAX_PATH]; extern WCHAR *gszLogFile;
extern HINSTANCE msi_hInstance; extern HINSTANCE msi_hInstance;
/* action related functions */ /* action related functions */
......
...@@ -295,6 +295,7 @@ static void MSI_FreePackage( MSIOBJECTHDR *arg) ...@@ -295,6 +295,7 @@ static void MSI_FreePackage( MSIOBJECTHDR *arg)
msiobj_release( &package->db->hdr ); msiobj_release( &package->db->hdr );
free_package_structures(package); free_package_structures(package);
CloseHandle( package->log_file );
} }
static UINT create_temp_property_table(MSIPACKAGE *package) static UINT create_temp_property_table(MSIPACKAGE *package)
...@@ -1121,6 +1122,8 @@ MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPCWSTR base_url ) ...@@ -1121,6 +1122,8 @@ MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPCWSTR base_url )
if (package->WordCount & msidbSumInfoSourceTypeAdminImage) if (package->WordCount & msidbSumInfoSourceTypeAdminImage)
msi_load_admin_properties( package ); msi_load_admin_properties( package );
package->log_file = INVALID_HANDLE_VALUE;
} }
return package; return package;
...@@ -1551,6 +1554,10 @@ UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage) ...@@ -1551,6 +1554,10 @@ UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
msi_adjust_privilege_properties( package ); msi_adjust_privilege_properties( package );
} }
if (gszLogFile)
package->log_file = CreateFileW( gszLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
*pPackage = package; *pPackage = package;
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
...@@ -1657,17 +1664,13 @@ INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType, ...@@ -1657,17 +1664,13 @@ INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType,
{'S','e','t','P','r','o','g','r','e','s','s',0}; {'S','e','t','P','r','o','g','r','e','s','s',0};
static const WCHAR szActionText[] = static const WCHAR szActionText[] =
{'A','c','t','i','o','n','T','e','x','t',0}; {'A','c','t','i','o','n','T','e','x','t',0};
DWORD log_type = 0;
LPWSTR message; LPWSTR message;
DWORD sz; DWORD sz, total_size = 0, log_type = 0;
DWORD total_size = 0; INT i, rc = 0;
INT i;
INT rc;
char *msg; char *msg;
int len; int len;
TRACE("%x\n", eMessageType); TRACE("%x\n", eMessageType);
rc = 0;
if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR) if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
log_type |= INSTALLLOGMODE_ERROR; log_type |= INSTALLLOGMODE_ERROR;
...@@ -1773,19 +1776,12 @@ INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType, ...@@ -1773,19 +1776,12 @@ INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType,
MsiCloseHandle( rec ); MsiCloseHandle( rec );
} }
if (!rc && gszLogFile[0] && (eMessageType & 0xff000000) != INSTALLMESSAGE_PROGRESS) if (!rc && package->log_file != INVALID_HANDLE_VALUE &&
(eMessageType & 0xff000000) != INSTALLMESSAGE_PROGRESS)
{ {
DWORD write; DWORD written;
HANDLE log_file = CreateFileW(gszLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, WriteFile( package->log_file, msg, len - 1, &written, NULL );
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); WriteFile( package->log_file, "\n", 1, &written, NULL );
if (log_file != INVALID_HANDLE_VALUE)
{
SetFilePointer(log_file,0, NULL, FILE_END);
WriteFile(log_file,msg,strlen(msg),&write,NULL);
WriteFile(log_file,"\n",1,&write,NULL);
CloseHandle(log_file);
}
} }
msi_free( msg ); msi_free( msg );
msi_free( message ); msi_free( message );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment