Commit 5f83069b authored by Mike McCormack's avatar Mike McCormack Committed by Alexandre Julliard

msi: Split code to create a random package name into a separate function.

parent 00fdc6cb
...@@ -3487,31 +3487,24 @@ end: ...@@ -3487,31 +3487,24 @@ end:
return rc; return rc;
} }
static UINT msi_make_package_local( MSIPACKAGE *package, HKEY hkey ) static UINT msi_get_local_package_name( LPWSTR path )
{ {
static const WCHAR installerPathFmt[] = { static const WCHAR szInstaller[] = {
'%','s','\\','I','n','s','t','a','l','l','e','r','\\',0}; '\\','I','n','s','t','a','l','l','e','r','\\',0};
static const WCHAR fmt[] = { static const WCHAR fmt[] = { '%','x','.','m','s','i',0};
'%','s','\\', DWORD time, len, i;
'I','n','s','t','a','l','l','e','r','\\', HANDLE handle;
'%','x','.','m','s','i',0};
static const WCHAR szOriginalDatabase[] = time = GetTickCount();
{'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0}; GetWindowsDirectoryW( path, MAX_PATH );
WCHAR windir[MAX_PATH], path[MAX_PATH], packagefile[MAX_PATH]; lstrcatW( path, szInstaller );
INT num, start; CreateDirectoryW( path, NULL );
LPWSTR msiFilePath;
BOOL r; len = lstrlenW(path);
for (i=0; i<0x10000; i++)
/* copy the package locally */
num = GetTickCount() & 0xffff;
if (!num)
num = 1;
start = num;
GetWindowsDirectoryW( windir, MAX_PATH );
snprintfW( packagefile, MAX_PATH, fmt, windir, num );
do
{ {
HANDLE handle = CreateFileW(packagefile,GENERIC_WRITE, 0, NULL, snprintfW( &path[len], MAX_PATH - len, fmt, (time+i)&0xffff );
handle = CreateFileW( path, GENERIC_WRITE, 0, NULL,
CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 ); CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
if (handle != INVALID_HANDLE_VALUE) if (handle != INVALID_HANDLE_VALUE)
{ {
...@@ -3520,13 +3513,23 @@ static UINT msi_make_package_local( MSIPACKAGE *package, HKEY hkey ) ...@@ -3520,13 +3513,23 @@ static UINT msi_make_package_local( MSIPACKAGE *package, HKEY hkey )
} }
if (GetLastError() != ERROR_FILE_EXISTS && if (GetLastError() != ERROR_FILE_EXISTS &&
GetLastError() != ERROR_SHARING_VIOLATION) GetLastError() != ERROR_SHARING_VIOLATION)
break; return ERROR_FUNCTION_FAILED;
if (!(++num & 0xffff)) num = 1; }
sprintfW(packagefile,fmt,num);
} while (num != start);
snprintfW( path, MAX_PATH, installerPathFmt, windir ); return ERROR_SUCCESS;
create_full_pathW(path); }
static UINT msi_make_package_local( MSIPACKAGE *package, HKEY hkey )
{
static const WCHAR szOriginalDatabase[] =
{'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
WCHAR packagefile[MAX_PATH];
LPWSTR msiFilePath;
UINT r;
r = msi_get_local_package_name( packagefile );
if (r != ERROR_SUCCESS)
return r;
TRACE("Copying to local package %s\n",debugstr_w(packagefile)); TRACE("Copying to local package %s\n",debugstr_w(packagefile));
......
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