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

Alexandre Julliard julliard at winehq.org
Wed May 16 17:30:27 CDT 2018


Module: wine
Branch: master
Commit: 75aa132b521f426fa670c05774a50c87247e9834
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=75aa132b521f426fa670c05774a50c87247e9834

Author: Zebediah Figura <z.figura12 at gmail.com>
Date:   Tue May 15 23:03:33 2018 -0500

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

Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
Signed-off-by: Hans Leidekker <hans at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/msi/format.c       | 59 ++++++++++++++++++++++++++-----------------------
 dlls/msi/install.c      | 23 +++++++++++++++++++
 dlls/msi/msipriv.h      |  1 +
 dlls/msi/tests/custom.c |  8 +++----
 4 files changed, 59 insertions(+), 32 deletions(-)

diff --git a/dlls/msi/format.c b/dlls/msi/format.c
index 0533cc0..d34fb2b 100644
--- a/dlls/msi/format.c
+++ b/dlls/msi/format.c
@@ -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);
-
-    if (szResult && len > *sz)
-    {
-        if (*sz) szResult[*sz - 1] = '\0';
-        r = ERROR_MORE_DATA;
-    }
+    r = MSI_FormatRecordW(package, rec, value, &len);
+    if (!r)
+        r = msi_strncpyWtoA(value, len, buf, sz, FALSE);
 
-    *sz = save - 1;
-
-done:
     msi_free(value);
+done:
+    msiobj_release(&rec->hdr);
+    if (package) msiobj_release(&package->hdr);
     return r;
 }
 
diff --git a/dlls/msi/install.c b/dlls/msi/install.c
index 45c5537..ca277d3 100644
--- a/dlls/msi/install.c
+++ b/dlls/msi/install.c
@@ -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 );
diff --git a/dlls/msi/msipriv.h b/dlls/msi/msipriv.h
index 46cbb43..5c6cd40 100644
--- a/dlls/msi/msipriv.h
+++ b/dlls/msi/msipriv.h
@@ -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 */
 
diff --git a/dlls/msi/tests/custom.c b/dlls/msi/tests/custom.c
index 04946d9..320aa6f 100644
--- a/dlls/msi/tests/custom.c
+++ b/dlls/msi/tests/custom.c
@@ -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");




More information about the wine-cvs mailing list