msi [3/5]: Forward MsiFormatRecordA to MsiFormatRecordW

James Hawkins truiken at gmail.com
Thu Jul 5 19:52:07 CDT 2007


Hi,

I know we should use the length returned from WideCharToMultiByte
instead of the character length returned from the W calls, but
MsiFormatRecord is more complicated than that (as shown by the tests)
and sometimes returns the length of a temporary (to the formatting
process) string instead of the length of the string returned.  What
really happens is that MsiFormatRecord needs to be rewritten
completely, but this works in the meantime.

Changelog:
* Forward MsiFormatRecordA to MsiFormatRecordW.

 dlls/msi/format.c  |   93 +++++++++++++++++-----------------------------------
 dlls/msi/msipriv.h |    1 -
 2 files changed, 30 insertions(+), 64 deletions(-)

-- 
James Hawkins
-------------- next part --------------
diff --git a/dlls/msi/format.c b/dlls/msi/format.c
index 147ae56..8dc99b8 100644
--- a/dlls/msi/format.c
+++ b/dlls/msi/format.c
@@ -657,57 +657,6 @@ UINT MSI_FormatRecordW( MSIPACKAGE* pack
     return rc;
 }
 
-UINT MSI_FormatRecordA( MSIPACKAGE* package, MSIRECORD* record, LPSTR buffer,
-                        DWORD *size )
-{
-    LPWSTR deformated;
-    LPWSTR rec;
-    DWORD len,lenA;
-    UINT rc = ERROR_INVALID_PARAMETER;
-
-    TRACE("%p %p %p %i\n", package, record ,buffer, *size);
-
-    rec = msi_dup_record_field(record,0);
-    if (!rec)
-        rec = build_default_format(record);
-
-    TRACE("(%s)\n",debugstr_w(rec));
-
-    len = deformat_string_internal(package,rec,&deformated,strlenW(rec),
-                                   record, NULL);
-    /* If len is zero then WideCharToMultiByte will return 0 indicating 
-     * failure, but that will do just as well since we are ignoring
-     * possible errors.
-     */
-    lenA = WideCharToMultiByte(CP_ACP,0,deformated,len,NULL,0,NULL,NULL);
-
-    if (buffer)
-    {
-        /* Ditto above */
-        WideCharToMultiByte(CP_ACP,0,deformated,len,buffer,*size,NULL, NULL);
-        if (*size>lenA)
-        {
-            rc = ERROR_SUCCESS;
-            buffer[lenA] = 0;
-        }
-        else
-        {
-            rc = ERROR_MORE_DATA;
-            if (*size)
-                buffer[(*size)-1] = 0;
-        }
-    }
-    else
-        rc = ERROR_SUCCESS;
-
-    *size = lenA;
-
-    msi_free(rec);
-    msi_free(deformated);
-    return rc;
-}
-
-
 UINT WINAPI MsiFormatRecordW( MSIHANDLE hInstall, MSIHANDLE hRecord, 
                               LPWSTR szResult, DWORD *sz )
 {
@@ -791,30 +740,48 @@ done:
 UINT WINAPI MsiFormatRecordA( MSIHANDLE hInstall, MSIHANDLE hRecord,
                               LPSTR szResult, DWORD *sz )
 {
-    UINT r = ERROR_INVALID_HANDLE;
-    MSIPACKAGE *package = NULL;
-    MSIRECORD *record = NULL;
+    UINT r;
+    DWORD len, save;
+    LPWSTR value;
 
     TRACE("%ld %ld %p %p\n", hInstall, hRecord, szResult, sz);
 
-    record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
-
-    if (!record)
+    if (!hRecord)
         return ERROR_INVALID_HANDLE;
+
     if (!sz)
     {
-        msiobj_release( &record->hdr );
         if (szResult)
             return ERROR_INVALID_PARAMETER;
         else
             return ERROR_SUCCESS;
     }
 
-    package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
+    r = MsiFormatRecordW( hInstall, hRecord, NULL, &len );
+    if (r != ERROR_SUCCESS)
+        return r;
 
-    r = MSI_FormatRecordA( package, record, szResult, sz );
-    msiobj_release( &record->hdr );
-    if (package)
-        msiobj_release( &package->hdr );
+    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, -1, NULL, 0, NULL, NULL);
+    WideCharToMultiByte(CP_ACP, 0, value, -1, szResult, *sz, NULL, NULL);
+
+    if (szResult && len > *sz)
+    {
+        if (*sz) szResult[*sz - 1] = '\0';
+        r = ERROR_MORE_DATA;
+    }
+
+    *sz = save - 1;
+
+done:
+    msi_free(value);
     return r;
 }
diff --git a/dlls/msi/msipriv.h b/dlls/msi/msipriv.h
index bb85e9a..79bda64 100644
--- a/dlls/msi/msipriv.h
+++ b/dlls/msi/msipriv.h
@@ -691,7 +691,6 @@ extern UINT msi_package_add_media_disk(M
 
 /* for deformating */
 extern UINT MSI_FormatRecordW( MSIPACKAGE *, MSIRECORD *, LPWSTR, DWORD * );
-extern UINT MSI_FormatRecordA( MSIPACKAGE *, MSIRECORD *, LPSTR, DWORD * );
 
 /* registry data encoding/decoding functions */
 extern BOOL unsquash_guid(LPCWSTR in, LPWSTR out);
-- 
1.4.1


More information about the wine-patches mailing list