MSI: tidy up string manipulation functions

Mike McCormack mike at codeweavers.com
Tue Mar 15 23:40:20 CST 2005


ChangeLog:
* Rename dupstrW to strdupW, and remove duplicate definition
* Move definition of string manipulation functions to msipriv.h

-------------- next part --------------
? dlls/msi/custom.c.1
? dlls/msi/msi.c.1
? dlls/msi/version.res
Index: dlls/msi/action.c
===================================================================
RCS file: /home/wine/wine/dlls/msi/action.c,v
retrieving revision 1.101
diff -u -p -r1.101 action.c
--- dlls/msi/action.c	10 Mar 2005 11:15:40 -0000	1.101
+++ dlls/msi/action.c	16 Mar 2005 05:38:46 -0000
@@ -508,8 +508,8 @@ int track_tempfile(MSIPACKAGE *package, 
 
     memset(&package->files[index],0,sizeof(MSIFILE));
 
-    package->files[index].File = dupstrW(name);
-    package->files[index].TargetPath = dupstrW(path);
+    package->files[index].File = strdupW(name);
+    package->files[index].TargetPath = strdupW(path);
     package->files[index].Temporary = TRUE;
 
     TRACE("Tracking tempfile (%s)\n",debugstr_w(package->files[index].File));  
@@ -677,7 +677,7 @@ static void ui_actiondata(MSIPACKAGE *pa
         package->ActionFormat = load_dynamic_stringW(row,3);
 
         HeapFree(GetProcessHeap(),0,package->LastAction);
-        package->LastAction = dupstrW(action);
+        package->LastAction = strdupW(action);
 
         msiobj_release(&row->hdr);
         MSI_ViewClose(view);
@@ -875,8 +875,8 @@ UINT ACTION_DoTopLevelINSTALL(MSIPACKAGE
     {
         LPWSTR p, check, path;
  
-        package->PackagePath = dupstrW(szPackagePath);
-        path = dupstrW(szPackagePath);
+        package->PackagePath = strdupW(szPackagePath);
+        path = strdupW(szPackagePath);
         p = strrchrW(path,'\\');    
         if (p)
         {
@@ -1921,7 +1921,7 @@ static INT load_folder(MSIPACKAGE *packa
 
     memset(&package->folders[index],0,sizeof(MSIFOLDER));
 
-    package->folders[index].Directory = dupstrW(dir);
+    package->folders[index].Directory = strdupW(dir);
 
     rc = MSI_OpenQuery(package->db, &view, Query, dir);
     if (rc != ERROR_SUCCESS)
@@ -1980,13 +1980,13 @@ static INT load_folder(MSIPACKAGE *packa
     {
         TRACE("   TargetDefault = %s\n",debugstr_w(targetdir));
         HeapFree(GetProcessHeap(),0, package->folders[index].TargetDefault);
-        package->folders[index].TargetDefault = dupstrW(targetdir);
+        package->folders[index].TargetDefault = strdupW(targetdir);
     }
 
     if (srcdir)
-       package->folders[index].SourceDefault = dupstrW(srcdir);
+        package->folders[index].SourceDefault = strdupW(srcdir);
     else if (targetdir)
-        package->folders[index].SourceDefault = dupstrW(targetdir);
+        package->folders[index].SourceDefault = strdupW(targetdir);
     HeapFree(GetProcessHeap(), 0, ptargetdir);
 
     parent = load_dynamic_stringW(row,2);
@@ -2084,13 +2084,13 @@ LPWSTR resolve_folder(MSIPACKAGE *packag
 
     if (!source && package->folders[i].ResolvedTarget)
     {
-        path = dupstrW(package->folders[i].ResolvedTarget);
+        path = strdupW(package->folders[i].ResolvedTarget);
         TRACE("   already resolved to %s\n",debugstr_w(path));
         return path;
     }
     else if (source && package->folders[i].ResolvedSource)
     {
-        path = dupstrW(package->folders[i].ResolvedSource);
+        path = strdupW(package->folders[i].ResolvedSource);
         return path;
     }
     else if (!source && package->folders[i].Property)
@@ -2114,7 +2114,7 @@ LPWSTR resolve_folder(MSIPACKAGE *packag
         {
             TRACE("   TargetDefault = %s\n",debugstr_w(package->folders[i].TargetDefault));
             path = build_directory_name(3, p, package->folders[i].TargetDefault, NULL);
-            package->folders[i].ResolvedTarget = dupstrW(path);
+            package->folders[i].ResolvedTarget = strdupW(path);
             TRACE("   resolved into %s\n",debugstr_w(path));
             if (set_prop)
                 MSI_SetPropertyW(package,name,path);
@@ -2122,7 +2122,7 @@ LPWSTR resolve_folder(MSIPACKAGE *packag
         else 
         {
             path = build_directory_name(3, p, package->folders[i].SourceDefault, NULL);
-            package->folders[i].ResolvedSource = dupstrW(path);
+            package->folders[i].ResolvedSource = strdupW(path);
         }
         HeapFree(GetProcessHeap(),0,p);
     }
@@ -3119,7 +3119,7 @@ inline static UINT get_file_target(MSIPA
         {
             if (package->files[index].State >= 2)
             {
-                *file_source = dupstrW(package->files[index].TargetPath);
+                *file_source = strdupW(package->files[index].TargetPath);
                 return ERROR_SUCCESS;
             }
             else
@@ -3231,7 +3231,7 @@ static UINT ACTION_DuplicateFiles(MSIPAC
         if (MSI_RecordIsNull(row,5))
         {
             LPWSTR p;
-            dest_path = dupstrW(file_source);
+            dest_path = strdupW(file_source);
             p = strrchrW(dest_path,'\\');
             if (p)
                 *p=0;
@@ -3759,7 +3759,7 @@ static LPWSTR resolve_keypath( MSIPACKAG
 
         if (j>=0)
         {
-            LPWSTR p = dupstrW(package->files[j].TargetPath);
+            LPWSTR p = strdupW(package->files[j].TargetPath);
             return p;
         }
     }
@@ -4882,7 +4882,7 @@ static UINT ACTION_CreateShortcuts(MSIPA
         {
             LPWSTR keypath;
             FIXME("poorly handled shortcut format, advertised shortcut\n");
-            keypath = dupstrW(package->components[index].FullKeypath);
+            keypath = strdupW(package->components[index].FullKeypath);
             IShellLinkW_SetPath(sl,keypath);
             HeapFree(GetProcessHeap(),0,keypath);
         }
Index: dlls/msi/action.h
===================================================================
RCS file: /home/wine/wine/dlls/msi/action.h,v
retrieving revision 1.5
diff -u -p -r1.5 action.h
--- dlls/msi/action.h	24 Feb 2005 12:47:43 -0000	1.5
+++ dlls/msi/action.h	16 Mar 2005 05:38:46 -0000
@@ -116,39 +116,3 @@ int get_loaded_component(MSIPACKAGE* pac
 int get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature );
 int get_loaded_file(MSIPACKAGE* package, LPCWSTR file);
 int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path);
-
-
-
-inline static char *strdupWtoA( const WCHAR *str )
-{
-    char *ret = NULL;
-    if (str)
-    {
-        DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL
-);
-        if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
-            WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
-    }
-    return ret;
-}
-
-inline static WCHAR *strdupAtoW( const char *str )
-{
-    WCHAR *ret = NULL;
-    if (str)
-    {
-        DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
-        if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
-            MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
-    }
-    return ret;
-}
-
-inline static LPWSTR dupstrW(LPCWSTR src)
-{
-    LPWSTR dest;
-    if (!src) return NULL;
-    dest = HeapAlloc(GetProcessHeap(), 0, (strlenW(src)+1)*sizeof(WCHAR));
-    strcpyW(dest, src);
-    return dest;
-}
Index: dlls/msi/custom.c
===================================================================
RCS file: /home/wine/wine/dlls/msi/custom.c,v
retrieving revision 1.8
diff -u -p -r1.8 custom.c
--- dlls/msi/custom.c	9 Feb 2005 14:05:24 -0000	1.8
+++ dlls/msi/custom.c	16 Mar 2005 05:38:46 -0000
@@ -145,7 +145,7 @@ UINT ACTION_CustomAction(MSIPACKAGE *pac
                 else
                     newbuf = HeapAlloc(GetProcessHeap(),0, sizeof(LPWSTR));
 
-                newbuf[count] = dupstrW(action);
+                newbuf[count] = strdupW(action);
                 package->CommitAction = newbuf;
             }
             else
@@ -160,7 +160,7 @@ UINT ACTION_CustomAction(MSIPACKAGE *pac
                 else
                     newbuf = HeapAlloc(GetProcessHeap(),0, sizeof(LPWSTR));
 
-                newbuf[count] = dupstrW(action);
+                newbuf[count] = strdupW(action);
                 package->DeferredAction = newbuf;
             }
 
@@ -326,7 +326,7 @@ static void file_running_action(MSIPACKA
 
     newbuf[count].handle = Handle;
     newbuf[count].process = process;
-    newbuf[count].name = dupstrW(name);
+    newbuf[count].name = strdupW(name);
 
     package->RunningAction = newbuf;
 }
@@ -508,8 +508,8 @@ static UINT HANDLE_CustomType1(MSIPACKAG
     info = HeapAlloc( GetProcessHeap(), 0, sizeof(*info) );
     msiobj_addref( &package->hdr );
     info->package = package;
-    info->target = dupstrW(target);
-    info->source = dupstrW(tmp_file);
+    info->target = strdupW(target);
+    info->source = strdupW(tmp_file);
 
     ThreadHandle = CreateThread(NULL,0,DllThread,(LPVOID)info,0,&ThreadId);
 
Index: dlls/msi/dialog.c
===================================================================
RCS file: /home/wine/wine/dlls/msi/dialog.c,v
retrieving revision 1.7
diff -u -p -r1.7 dialog.c
--- dlls/msi/dialog.c	4 Mar 2005 12:32:08 -0000	1.7
+++ dlls/msi/dialog.c	16 Mar 2005 05:38:46 -0000
@@ -309,7 +309,7 @@ static UINT msi_dialog_checkbox_control(
     control->handler = msi_dialog_checkbox_handler;
     prop = MSI_RecordGetString( rec, 9 );
     if( prop )
-        control->property = dupstrW( prop );
+        control->property = strdupW( prop );
     msi_dialog_checkbox_sync_state( dialog, control );
 
     return ERROR_SUCCESS;
@@ -364,7 +364,7 @@ static UINT msi_dialog_edit_control( msi
     control->handler = msi_dialog_edit_handler;
     prop = MSI_RecordGetString( rec, 9 );
     if( prop )
-        control->property = dupstrW( prop );
+        control->property = strdupW( prop );
     val = load_dynamic_property( dialog->package, control->property, NULL );
     SetWindowTextW( control->hwnd, val );
     HeapFree( GetProcessHeap(), 0, val );
@@ -433,7 +433,7 @@ static UINT msi_dialog_create_radiobutto
 
     prop = MSI_RecordGetString( rec, 1 );
     if( prop )
-        control->property = dupstrW( prop );
+        control->property = strdupW( prop );
 
     return ERROR_SUCCESS;
 }
@@ -467,7 +467,7 @@ static UINT msi_dialog_radiogroup_contro
     }
 
     if( prop )
-        control->property = dupstrW( prop );
+        control->property = strdupW( prop );
 
     /* query the Radio Button table for all control in this group */
     r = MSI_OpenQuery( package->db, &view, query, prop );
Index: dlls/msi/format.c
===================================================================
RCS file: /home/wine/wine/dlls/msi/format.c,v
retrieving revision 1.7
diff -u -p -r1.7 format.c
--- dlls/msi/format.c	10 Mar 2005 11:15:40 -0000	1.7
+++ dlls/msi/format.c	16 Mar 2005 05:38:46 -0000
@@ -114,7 +114,7 @@ static LPWSTR deformat_file(MSIPACKAGE* 
     index = get_loaded_file(package,key);
     if (index >=0)
     {
-        value = dupstrW(package->files[index].TargetPath);
+        value = strdupW(package->files[index].TargetPath);
         *sz = (strlenW(value)) * sizeof(WCHAR);
     }
 
Index: dlls/msi/msipriv.h
===================================================================
RCS file: /home/wine/wine/dlls/msi/msipriv.h,v
retrieving revision 1.49
diff -u -p -r1.49 msipriv.h
--- dlls/msi/msipriv.h	10 Mar 2005 17:24:05 -0000	1.49
+++ dlls/msi/msipriv.h	16 Mar 2005 05:38:47 -0000
@@ -29,6 +29,7 @@
 #include "msiquery.h"
 #include "objbase.h"
 #include "objidl.h"
+#include "wine/unicode.h"
 
 #define MSI_DATASIZEMASK 0x00ff
 #define MSITYPE_VALID    0x0100
@@ -385,5 +386,39 @@ extern INSTALLUI_HANDLERW gUIHandlerW;
 extern DWORD gUIFilter;
 extern LPVOID gUIContext;
 extern WCHAR gszLogFile[MAX_PATH];
+
+inline static char *strdupWtoA( LPCWSTR str )
+{
+    LPSTR ret = NULL;
+    if (str)
+    {
+        DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL
+);
+        if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
+            WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
+    }
+    return ret;
+}
+
+inline static LPWSTR strdupAtoW( LPCSTR str )
+{
+    LPWSTR ret = NULL;
+    if (str)
+    {
+        DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
+        if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
+            MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
+    }
+    return ret;
+}
+
+inline static LPWSTR strdupW( LPCWSTR src )
+{
+    LPWSTR dest;
+    if (!src) return NULL;
+    dest = HeapAlloc(GetProcessHeap(), 0, (strlenW(src)+1)*sizeof(WCHAR));
+    strcpyW(dest, src);
+    return dest;
+}
 
 #endif /* __WINE_MSI_PRIVATE__ */
Index: dlls/msi/table.c
===================================================================
RCS file: /home/wine/wine/dlls/msi/table.c,v
retrieving revision 1.31
diff -u -p -r1.31 table.c
--- dlls/msi/table.c	16 Feb 2005 16:06:05 -0000	1.31
+++ dlls/msi/table.c	16 Mar 2005 05:38:47 -0000
@@ -834,15 +834,6 @@ err:
     return ret;
 }
 
-static LPWSTR strdupW( LPCWSTR str )
-{
-    UINT len = lstrlenW( str ) + 1;
-    LPWSTR ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof (WCHAR) );
-    if( ret )
-        lstrcpyW( ret, str );
-    return ret;
-}
-
 /* information for default tables */
 static const WCHAR szTables[]  = { '_','T','a','b','l','e','s',0 };
 static const WCHAR szTable[]  = { 'T','a','b','l','e',0 };


More information about the wine-patches mailing list