msi: Handle the remote case directly in MsiFormatRecordA().

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2018-05-15 23:03:33 -05:00 committed by Alexandre Julliard
parent 9321aa40f5
commit 75aa132b52
4 changed files with 59 additions and 32 deletions

View File

@ -952,52 +952,55 @@ UINT WINAPI MsiFormatRecordW( MSIHANDLE hInstall, MSIHANDLE hRecord,
return r;
}
UINT WINAPI MsiFormatRecordA( MSIHANDLE hInstall, MSIHANDLE hRecord,
LPSTR szResult, LPDWORD sz )
UINT WINAPI MsiFormatRecordA(MSIHANDLE hinst, MSIHANDLE hrec, char *buf, DWORD *sz)
{
UINT r;
DWORD len, save;
MSIPACKAGE *package;
MSIRECORD *rec;
LPWSTR value;
DWORD len;
UINT r;
TRACE("%d %d %p %p\n", hInstall, hRecord, szResult, sz);
TRACE("%d %d %p %p\n", hinst, hrec, buf, sz);
if (!hRecord)
rec = msihandle2msiinfo(hrec, MSIHANDLETYPE_RECORD);
if (!rec)
return ERROR_INVALID_HANDLE;
if (!sz)
package = msihandle2msiinfo(hinst, MSIHANDLETYPE_PACKAGE);
if (!package)
{
if (szResult)
return ERROR_INVALID_PARAMETER;
else
return ERROR_SUCCESS;
LPWSTR value = NULL;
MSIHANDLE remote;
if ((remote = msi_get_remote(hinst)))
{
r = remote_FormatRecord(remote, (struct wire_record *)&rec->count, &value);
if (!r)
r = msi_strncpyWtoA(value, -1, buf, sz, TRUE);
midl_user_free(value);
msiobj_release(&rec->hdr);
return r;
}
}
r = MsiFormatRecordW( hInstall, hRecord, NULL, &len );
r = MSI_FormatRecordW(package, rec, NULL, &len);
if (r != ERROR_SUCCESS)
return r;
value = msi_alloc(++len * sizeof(WCHAR));
if (!value)
return ERROR_OUTOFMEMORY;
r = MsiFormatRecordW( hInstall, hRecord, value, &len );
if (r != ERROR_SUCCESS)
goto done;
save = len + 1;
len = WideCharToMultiByte(CP_ACP, 0, value, len + 1, NULL, 0, NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, value, len, szResult, *sz, NULL, NULL);
r = MSI_FormatRecordW(package, rec, value, &len);
if (!r)
r = msi_strncpyWtoA(value, len, buf, sz, FALSE);
if (szResult && len > *sz)
{
if (*sz) szResult[*sz - 1] = '\0';
r = ERROR_MORE_DATA;
}
*sz = save - 1;
done:
msi_free(value);
done:
msiobj_release(&rec->hdr);
if (package) msiobj_release(&package->hdr);
return r;
}

View File

@ -168,6 +168,29 @@ UINT msi_strcpy_to_awstring( const WCHAR *str, int len, awstring *awbuf, DWORD *
return r;
}
UINT msi_strncpyWtoA(const WCHAR *str, int lenW, char *buf, DWORD *sz, BOOL remote)
{
UINT r = ERROR_SUCCESS;
DWORD lenA;
if (!sz)
return buf ? ERROR_INVALID_PARAMETER : ERROR_SUCCESS;
if (lenW < 0) lenW = strlenW(str);
lenA = WideCharToMultiByte(CP_ACP, 0, str, lenW + 1, NULL, 0, NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, str, lenW + 1, buf, *sz, NULL, NULL);
lenA--;
if (buf && lenA >= *sz)
{
if (*sz) buf[*sz - 1] = 0;
r = ERROR_MORE_DATA;
}
if (remote && lenA >= *sz)
lenA *= 2;
*sz = lenA;
return r;
}
const WCHAR *msi_get_target_folder( MSIPACKAGE *package, const WCHAR *name )
{
MSIFOLDER *folder = msi_get_loaded_folder( package, name );

View File

@ -1045,6 +1045,7 @@ extern WCHAR *msi_font_version_from_file(const WCHAR *) DECLSPEC_HIDDEN;
extern WCHAR **msi_split_string(const WCHAR *, WCHAR) DECLSPEC_HIDDEN;
extern UINT msi_set_original_database_property(MSIDATABASE *, const WCHAR *) DECLSPEC_HIDDEN;
extern WCHAR *msi_get_error_message(MSIDATABASE *, int) DECLSPEC_HIDDEN;
extern UINT msi_strncpyWtoA(const WCHAR *str, int len, char *buf, DWORD *sz, BOOL remote) DECLSPEC_HIDDEN;
/* media */

View File

@ -785,28 +785,28 @@ static void test_format_record(MSIHANDLE hinst)
sz = 0;
r = MsiFormatRecordA(hinst, rec, NULL, &sz);
ok(hinst, !r, "got %u\n", r);
todo_wine_ok(hinst, sz == 14, "got size %u\n", sz);
ok(hinst, sz == 14, "got size %u\n", sz);
sz = 0;
strcpy(buffer,"q");
r = MsiFormatRecordA(hinst, rec, buffer, &sz);
ok(hinst, r == ERROR_MORE_DATA, "got %u\n", r);
ok(hinst, !strcmp(buffer, "q"), "got \"%s\"\n", buffer);
todo_wine_ok(hinst, sz == 14, "got size %u\n", sz);
ok(hinst, sz == 14, "got size %u\n", sz);
sz = 1;
strcpy(buffer,"x");
r = MsiFormatRecordA(hinst, rec, buffer, &sz);
ok(hinst, r == ERROR_MORE_DATA, "got %u\n", r);
ok(hinst, !buffer[0], "got \"%s\"\n", buffer);
todo_wine_ok(hinst, sz == 14, "got size %u\n", sz);
ok(hinst, sz == 14, "got size %u\n", sz);
sz = 7;
strcpy(buffer,"x");
r = MsiFormatRecordA(hinst, rec, buffer, &sz);
ok(hinst, r == ERROR_MORE_DATA, "got %u\n", r);
ok(hinst, !strcmp(buffer, "foo 12"), "got \"%s\"\n", buffer);
todo_wine_ok(hinst, sz == 14, "got size %u\n", sz);
ok(hinst, sz == 14, "got size %u\n", sz);
sz = 8;
strcpy(buffer,"x");