MSI: move round and rename some functions

Mike McCormack mike at codeweavers.com
Wed Dec 22 04:24:52 CST 2004


ChangeLog:
<aric at codeweavers.com>
* move round and rename some functions
-------------- next part --------------
diff -ur dlls/msi.old/action.c dlls/msi/action.c
--- dlls/msi.old/action.c	2004-12-22 19:00:44.000000000 +0900
+++ dlls/msi/action.c	2004-12-22 19:16:27.000000000 +0900
@@ -122,7 +122,7 @@
        /* 2 = present but replace */
        /* 3 = present do not replace */
        /* 4 = Installed */
-    WCHAR   SourcePath[MAX_PATH];
+    LPWSTR  SourcePath;
     LPWSTR  TargetPath;
     BOOL    Temporary; 
 }MSIFILE;
@@ -252,6 +252,15 @@
     return ret;
 }
 
+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;
+}
+
 inline static WCHAR *load_dynamic_stringW(MSIRECORD *row, INT index)
 {
     UINT rc;
@@ -259,22 +268,33 @@
     LPWSTR ret;
    
     sz = 0; 
-    rc = MSI_RecordGetStringW(row,index,NULL,&sz);
-    if (sz <= 0)
+    if (MSI_RecordIsNull(row,index))
         return NULL;
 
+    rc = MSI_RecordGetStringW(row,index,NULL,&sz);
+
+    /* having an empty string is different than NULL */
+    if (sz == 0)
+    {
+        ret = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR));
+        ret[0] = 0;
+        return ret;
+    }
+
     sz ++;
     ret = HeapAlloc(GetProcessHeap(),0,sz * sizeof (WCHAR));
     rc = MSI_RecordGetStringW(row,index,ret,&sz);
     if (rc!=ERROR_SUCCESS)
     {
+        ERR("Unable to load dynamic string\n");
         HeapFree(GetProcessHeap(), 0, ret);
         ret = NULL;
     }
     return ret;
 }
 
-static LPWSTR PACKAGE_GetProperty(MSIPACKAGE *package, LPCWSTR prop)
+inline static LPWSTR load_dynamic_property(MSIPACKAGE *package, LPCWSTR prop,
+                                           UINT* rc)
 {
     DWORD sz = 0;
     LPWSTR str;
@@ -282,7 +302,11 @@
 
     r = MSI_GetPropertyW(package, prop, NULL, &sz);
     if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
+    {
+        if (rc)
+            *rc = r;
         return NULL;
+    }
     sz++;
     str = HeapAlloc(GetProcessHeap(),0,sz*sizeof(WCHAR));
     r = MSI_GetPropertyW(package, prop, str, &sz);
@@ -291,6 +315,8 @@
         HeapFree(GetProcessHeap(),0,str);
         str = NULL;
     }
+    if (rc)
+        *rc = r;
     return str;
 }
 
@@ -342,14 +368,6 @@
     return rc;
 }
 
-static LPWSTR PACKAGE_dupstrW(LPCWSTR src)
-{
-    LPWSTR dest;
-    if (!src) return NULL;
-    dest = HeapAlloc(GetProcessHeap(), 0, (strlenW(src)+1)*sizeof(WCHAR));
-    strcpyW(dest, src);
-    return dest;
-}
 
 static int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path)
 {
@@ -373,10 +391,8 @@
 
     memset(&package->files[index],0,sizeof(MSIFILE));
 
-    package->files[index].File = PACKAGE_dupstrW(name);
-    if (package->files[index].TargetPath)
-        HeapFree(GetProcessHeap(),0,package->files[index].TargetPath);
-    package->files[index].TargetPath = PACKAGE_dupstrW(path);
+    package->files[index].File = dupstrW(name);
+    package->files[index].TargetPath = dupstrW(path);
     package->files[index].Temporary = TRUE;
 
     TRACE("Tracking tempfile (%s)\n",debugstr_w(package->files[index].File));  
@@ -399,19 +415,6 @@
     }
 }
 
-static void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
-{
-    MSIRECORD * row;
-
-    row = MSI_CreateRecord(4);
-    MSI_RecordSetInteger(row,1,a);
-    MSI_RecordSetInteger(row,2,b);
-    MSI_RecordSetInteger(row,3,c);
-    MSI_RecordSetInteger(row,4,d);
-    MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
-    msiobj_release(&row->hdr);
-}
-
 static UINT ACTION_OpenQuery( MSIDATABASE *db, MSIQUERY **view, LPCWSTR fmt, ... )
 {
     LPWSTR szQuery;
@@ -459,6 +462,19 @@
     return rc;
 }
 
+static void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
+{
+    MSIRECORD * row;
+
+    row = MSI_CreateRecord(4);
+    MSI_RecordSetInteger(row,1,a);
+    MSI_RecordSetInteger(row,2,b);
+    MSI_RecordSetInteger(row,3,c);
+    MSI_RecordSetInteger(row,4,d);
+    MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
+    msiobj_release(&row->hdr);
+}
+
 static void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
 {
     static const WCHAR Query_t[] = 
@@ -504,8 +520,8 @@
         package->ActionFormat = load_dynamic_stringW(row,3);
 
         if (package->LastAction)
-            HeapFree(GetProcessHeap(),0,package->ActionFormat);
-        package->LastAction = PACKAGE_dupstrW(action);
+            HeapFree(GetProcessHeap(),0,package->LastAction);
+        package->LastAction = dupstrW(action);
 
         msiobj_release(&row->hdr);
         MSI_ViewClose(view);
@@ -633,6 +649,58 @@
     msiobj_release(&row->hdr);
 }
 
+/*
+ *  build_directory_name()
+ *
+ *  This function is to save messing round with directory names
+ *  It handles adding backslashes between path segments, 
+ *   and can add \ at the end of the directory name if told to.
+ *
+ *  It takes a variable number of arguments.
+ *  It always allocates a new string for the result, so make sure
+ *   to free the return value when finished with it.
+ *
+ *  The first arg is the number of path segments that follow.
+ *  The arguments following count are a list of path segments.
+ *  A path segment may be NULL.
+ *
+ *  Path segments will be added with a \ seperating them.
+ *  A \ will not be added after the last segment, however if the
+ *    last segment is NULL, then the last character will be a \
+ * 
+ */
+static LPWSTR build_directory_name(DWORD count, ...)
+{
+    DWORD sz = 1, i;
+    LPWSTR dir;
+    va_list va;
+
+    va_start(va,count);
+    for(i=0; i<count; i++)
+    {
+        LPCWSTR str = va_arg(va,LPCWSTR);
+        if (str)
+            sz += strlenW(str) + 1;
+    }
+    va_end(va);
+
+    dir = HeapAlloc(GetProcessHeap(), 0, sz*sizeof(WCHAR));
+    dir[0]=0;
+
+    va_start(va,count);
+    for(i=0; i<count; i++)
+    {
+        LPCWSTR str = va_arg(va,LPCWSTR);
+        if (!str)
+            continue;
+        strcatW(dir, str);
+        if( ((i+1)!=count) && dir[strlenW(dir)-1]!='\\')
+            strcatW(dir, cszbs);
+    }
+    return dir;
+}
+
+
 /****************************************************
  * TOP level entry points 
  *****************************************************/
@@ -649,7 +717,7 @@
     {
         LPWSTR p, check, path;
  
-        path = PACKAGE_dupstrW(szPackagePath);
+        path = dupstrW(szPackagePath);
         p = strrchrW(path,'\\');    
         if (p)
         {
@@ -657,12 +725,12 @@
             *p=0;
         }
 
-        check = PACKAGE_GetProperty(package, cszSourceDir);
+        check = load_dynamic_property(package, cszSourceDir,NULL);
         if (!check)
-        {
             MSI_SetPropertyW(package, cszSourceDir, path);
+        else
             HeapFree(GetProcessHeap(), 0, check);
-        }
+
         HeapFree(GetProcessHeap(), 0, path);
     }
 
@@ -708,7 +776,8 @@
 
                 if (strlenW(prop) > 0)
                 {
-                    TRACE("Found commandline property (%s) = (%s)\n", debugstr_w(prop), debugstr_w(val));
+                    TRACE("Found commandline property (%s) = (%s)\n", 
+                                       debugstr_w(prop), debugstr_w(val));
                     MSI_SetPropertyW(package,prop,val);
                 }
             }
@@ -1192,7 +1261,6 @@
     return ERROR_SUCCESS;
 }
 
-
 typedef UINT __stdcall CustomEntry(MSIHANDLE);
 typedef struct 
 {
@@ -1312,28 +1380,38 @@
 static UINT HANDLE_CustomType2(MSIPACKAGE *package, const LPWSTR source, 
                                 const LPWSTR target, const INT type)
 {
-    WCHAR tmp_file[MAX_PATH*2];
+    WCHAR tmp_file[MAX_PATH];
     STARTUPINFOW si;
     PROCESS_INFORMATION info;
     BOOL rc;
+    INT len;
     WCHAR *deformated;
+    WCHAR *cmd;
     static const WCHAR spc[] = {' ',0};
 
     memset(&si,0,sizeof(STARTUPINFOW));
 
     store_binary_to_temp(package, source, tmp_file);
 
-    strcatW(tmp_file,spc);
     deformat_string(package,target,&deformated);
-    strcatW(tmp_file,deformated);
+
+    len = strlenW(tmp_file) + strlenW(deformated) + 2;
+   
+    cmd = (WCHAR*)HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*len);
+
+    strcpyW(cmd,tmp_file);
+    strcatW(cmd,spc);
+    strcatW(cmd,deformated);
 
     HeapFree(GetProcessHeap(),0,deformated);
 
-    TRACE("executing exe %s \n",debugstr_w(tmp_file));
+    TRACE("executing exe %s \n",debugstr_w(cmd));
 
-    rc = CreateProcessW(NULL, tmp_file, NULL, NULL, FALSE, 0, NULL,
+    rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
                   c_collen, &si, &info);
 
+    HeapFree(GetProcessHeap(),0,cmd);
+
     if ( !rc )
     {
         ERR("Unable to execute command\n");
@@ -1351,30 +1429,40 @@
 static UINT HANDLE_CustomType18(MSIPACKAGE *package, const LPWSTR source, 
                                 const LPWSTR target, const INT type)
 {
-    WCHAR filename[MAX_PATH*2];
     STARTUPINFOW si;
     PROCESS_INFORMATION info;
     BOOL rc;
     WCHAR *deformated;
+    WCHAR *cmd;
+    INT len;
     static const WCHAR spc[] = {' ',0};
     int index;
 
     memset(&si,0,sizeof(STARTUPINFOW));
 
     index = get_loaded_file(package,source);
-    strcpyW(filename,package->files[index].TargetPath);
 
-    strcatW(filename,spc);
+    len = strlenW(package->files[index].TargetPath);
+
     deformat_string(package,target,&deformated);
-    strcatW(filename,deformated);
+    len += strlenW(deformated);
+    len += 2;
+
+    cmd = (WCHAR*)HeapAlloc(GetProcessHeap(),0,len * sizeof(WCHAR));
+
+    strcpyW(cmd, package->files[index].TargetPath);
+    strcatW(cmd, spc);
+    strcatW(cmd, deformated);
 
     HeapFree(GetProcessHeap(),0,deformated);
 
-    TRACE("executing exe %s \n",debugstr_w(filename));
+    TRACE("executing exe %s \n",debugstr_w(cmd));
 
-    rc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
+    rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
                   c_collen, &si, &info);
 
+    HeapFree(GetProcessHeap(),0,cmd);
+    
     if ( !rc )
     {
         ERR("Unable to execute command\n");
@@ -1392,31 +1480,40 @@
 static UINT HANDLE_CustomType50(MSIPACKAGE *package, const LPWSTR source, 
                                 const LPWSTR target, const INT type)
 {
-    WCHAR filename[MAX_PATH*2];
     STARTUPINFOW si;
     PROCESS_INFORMATION info;
+    WCHAR *prop;
     BOOL rc;
     WCHAR *deformated;
+    WCHAR *cmd;
+    INT len;
+    UINT prc;
     static const WCHAR spc[] = {' ',0};
-    DWORD sz;
 
     memset(&si,0,sizeof(STARTUPINFOW));
+    memset(&info,0,sizeof(PROCESS_INFORMATION));
 
-    sz = MAX_PATH*2;
-    if (MSI_GetPropertyW(package,source,filename,&sz) != ERROR_SUCCESS)
-        return ERROR_FUNCTION_FAILED;
+    prop = load_dynamic_property(package,source,&prc);
+    if (!prop)
+        return prc;
 
-    strcatW(filename,spc);
     deformat_string(package,target,&deformated);
-    strcatW(filename,deformated);
+    len = strlenW(prop) + strlenW(deformated) + 2;
+    cmd = (WCHAR*)HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*len);
+
+    strcpyW(cmd,prop);
+    strcatW(cmd,spc);
+    strcatW(cmd,deformated);
 
     HeapFree(GetProcessHeap(),0,deformated);
 
-    TRACE("executing exe %s \n",debugstr_w(filename));
+    TRACE("executing exe %s \n",debugstr_w(cmd));
 
-    rc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
+    rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
                   c_collen, &si, &info);
 
+    HeapFree(GetProcessHeap(),0,cmd);
+    
     if ( !rc )
     {
         ERR("Unable to execute command\n");
@@ -1442,6 +1539,7 @@
     memset(&si,0,sizeof(STARTUPINFOW));
 
     filename = resolve_folder(package, source, FALSE, FALSE, NULL);
+
     if (!filename)
         return ERROR_FUNCTION_FAILED;
 
@@ -1484,7 +1582,8 @@
     WCHAR *new_path;
 
     new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) *
-sizeof(WCHAR));
+                                              sizeof(WCHAR));
+
     strcpyW(new_path, path);
 
     while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
@@ -1795,7 +1894,6 @@
 {
     MSIQUERY * view;
     MSIRECORD * row;
-    DWORD sz;
     UINT rc;
     static const WCHAR Query_all[] = {
        'S','E','L','E','C','T',' ','*',' ',
@@ -1807,7 +1905,6 @@
     MSI_SetPropertyW(package, szCosting, szZero);
     MSI_SetPropertyW(package, cszRootDrive , c_collen);
 
-    sz = 0x100;
     rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
     if (rc != ERROR_SUCCESS)
         return rc;
@@ -1964,7 +2061,7 @@
 
     memset(&package->folders[index],0,sizeof(MSIFOLDER));
 
-    package->folders[index].Directory = PACKAGE_dupstrW(dir);
+    package->folders[index].Directory = dupstrW(dir);
 
     rc = ACTION_OpenQuery(package->db, &view, Query, dir);
     if (rc != ERROR_SUCCESS)
@@ -2022,14 +2119,15 @@
     if (targetdir)
     {
         TRACE("   TargetDefault = %s\n",debugstr_w(targetdir));
-        HeapFree(GetProcessHeap(), 0, package->folders[index].TargetDefault);
-        package->folders[index].TargetDefault = PACKAGE_dupstrW(targetdir);
+        if (package->folders[index].TargetDefault)
+            HeapFree(GetProcessHeap(),0, package->folders[index].TargetDefault);
+        package->folders[index].TargetDefault = dupstrW(targetdir);
     }
 
     if (srcdir)
-       package->folders[index].SourceDefault = PACKAGE_dupstrW(srcdir);
+       package->folders[index].SourceDefault = dupstrW(srcdir);
     else if (targetdir)
-        package->folders[index].SourceDefault = PACKAGE_dupstrW(targetdir);
+        package->folders[index].SourceDefault = dupstrW(targetdir);
     HeapFree(GetProcessHeap(), 0, targetdir);
 
     parent = load_dynamic_stringW(row,2);
@@ -2046,7 +2144,7 @@
         package->folders[index].ParentIndex = -2;
     HeapFree(GetProcessHeap(), 0, parent);
 
-    package->folders[index].Property = PACKAGE_GetProperty(package, dir);
+    package->folders[index].Property = load_dynamic_property(package, dir,NULL);
 
     msiobj_release(&row->hdr);
     MSI_ViewClose(view);
@@ -2055,56 +2153,6 @@
     return index;
 }
 
-/*
- *  build_directory_name()
- *
- *  This function is to save messing round with directory names
- *  It handles adding backslashes between path segments, 
- *   and can add \ at the end of the directory name if told to.
- *
- *  It takes a variable number of arguments.
- *  It always allocates a new string for the result, so make sure
- *   to free the return value when finished with it.
- *
- *  The first arg is the number of path segments that follow.
- *  The arguments following count are a list of path segments.
- *  A path segment may be NULL.
- *
- *  Path segments will be added with a \ seperating them.
- *  A \ will not be added after the last segment, however if the
- *    last segment is NULL, then the last character will be a \
- * 
- */
-static LPWSTR build_directory_name(DWORD count, ...)
-{
-    DWORD sz = 1, i;
-    LPWSTR dir;
-    va_list va;
-
-    va_start(va,count);
-    for(i=0; i<count; i++)
-    {
-        LPCWSTR str = va_arg(va,LPCWSTR);
-        if (str)
-            sz += strlenW(str) + 1;
-    }
-    va_end(va);
-
-    dir = HeapAlloc(GetProcessHeap(), 0, sz*sizeof(WCHAR));
-    dir[0]=0;
-
-    va_start(va,count);
-    for(i=0; i<count; i++)
-    {
-        LPCWSTR str = va_arg(va,LPCWSTR);
-        if (!str)
-            continue;
-        strcatW(dir, str);
-        if( ((i+1)!=count) && dir[strlenW(dir)-1]!='\\')
-            strcatW(dir, cszbs);
-    }
-    return dir;
-}
 
 static LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name,
                            BOOL source, BOOL set_prop, MSIFOLDER **folder)
@@ -2119,10 +2167,10 @@
     {
         if (!source)
         {
-            path = PACKAGE_GetProperty(package,cszTargetDir);
+            path = load_dynamic_property(package,cszTargetDir,NULL);
             if (!path)
             {
-                path = PACKAGE_GetProperty(package,cszRootDrive);
+                path = load_dynamic_property(package,cszRootDrive,NULL);
                 if (set_prop)
                     MSI_SetPropertyW(package,cszTargetDir,path);
             }
@@ -2132,10 +2180,10 @@
         }
         else
         {
-            path = PACKAGE_GetProperty(package,cszSourceDir);
+            path = load_dynamic_property(package,cszSourceDir,NULL);
             if (!path)
             {
-                path = PACKAGE_GetProperty(package,cszDatabase);
+                path = load_dynamic_property(package,cszDatabase,NULL);
                 if (path)
                 {
                     p = strrchrW(path,'\\');
@@ -2163,18 +2211,18 @@
 
     if (!source && package->folders[i].ResolvedTarget)
     {
-        path = PACKAGE_dupstrW(package->folders[i].ResolvedTarget);
+        path = dupstrW(package->folders[i].ResolvedTarget);
         TRACE("   already resolved to %s\n",debugstr_w(path));
         return path;
     }
     else if (source && package->folders[i].ResolvedSource)
     {
-        path = PACKAGE_dupstrW(package->folders[i].ResolvedSource);
+        path = dupstrW(package->folders[i].ResolvedSource);
         return path;
     }
     else if (!source && package->folders[i].Property)
     {
-        path = PACKAGE_dupstrW(package->folders[i].Property);
+        path = dupstrW(package->folders[i].Property);
         TRACE("   internally set to %s\n",debugstr_w(path));
         if (set_prop)
             MSI_SetPropertyW(package,name,path);
@@ -2192,7 +2240,7 @@
         {
             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 = PACKAGE_dupstrW(path);
+            package->folders[i].ResolvedTarget = dupstrW(path);
             TRACE("   resolved into %s\n",debugstr_w(path));
             if (set_prop)
                 MSI_SetPropertyW(package,name,path);
@@ -2200,7 +2248,7 @@
         else 
         {
             path = build_directory_name(3, p, package->folders[i].SourceDefault, NULL);
-            package->folders[i].ResolvedSource = PACKAGE_dupstrW(path);
+            package->folders[i].ResolvedSource = dupstrW(path);
         }
         HeapFree(GetProcessHeap(),0,p);
     }
@@ -2282,17 +2330,29 @@
         if (file->ComponentIndex >= 0)
             comp = &package->components[file->ComponentIndex];
 
+        if (file->Temporary == TRUE)
+            continue;
+
         if (comp)
         {
             LPWSTR p;
 
             /* calculate target */
             p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
+
+            if (file->TargetPath)
+                HeapFree(GetProcessHeap(),0,file->TargetPath);
+
+            TRACE("file %s is named %s\n",
+                   debugstr_w(file->File),debugstr_w(file->FileName));       
+
             file->TargetPath = build_directory_name(2, p, file->FileName);
 
+            HeapFree(GetProcessHeap(),0,p);
+
             TRACE("file %s resolves to %s\n",
                    debugstr_w(file->File),debugstr_w(file->TargetPath));       
- 
+
             if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
             {
                 file->State = 1;
@@ -2819,7 +2879,7 @@
 }
 
 inline static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key, 
-                                   LPWSTR file_source)
+                                   LPWSTR* file_source)
 {
     DWORD index;
 
@@ -2832,7 +2892,7 @@
         {
             if (package->files[index].State >= 3)
             {
-                strcpyW(file_source,package->files[index].TargetPath);
+                *file_source = dupstrW(package->files[index].TargetPath);
                 return ERROR_SUCCESS;
             }
             else
@@ -2870,7 +2930,7 @@
     while (1)
     {
         WCHAR file_key[0x100];
-        WCHAR file_source[MAX_PATH];
+        WCHAR *file_source = NULL;
         WCHAR dest_name[0x100];
         LPWSTR dest_path, dest;
         WCHAR component[0x100];
@@ -2912,12 +2972,14 @@
             break;
         }
 
-        rc = get_file_target(package,file_key,file_source);
+        rc = get_file_target(package,file_key,&file_source);
 
         if (rc != ERROR_SUCCESS)
         {
             ERR("Original file unknown %s\n",debugstr_w(file_key));
             msiobj_release(&row->hdr);
+            if (file_source)
+                HeapFree(GetProcessHeap(),0,file_source);
             break;
         }
 
@@ -2935,7 +2997,7 @@
         if (MSI_RecordIsNull(row,5))
         {
             LPWSTR p;
-            dest_path = PACKAGE_dupstrW(file_source);
+            dest_path = dupstrW(file_source);
             p = strrchrW(dest_path,'\\');
             if (p)
                 *p=0;
@@ -2951,6 +3013,8 @@
             {
                 ERR("Unable to get destination folder\n");
                 msiobj_release(&row->hdr);
+                if (file_source)
+                    HeapFree(GetProcessHeap(),0,file_source);
                 break;
             }
         }
@@ -2959,10 +3023,10 @@
         HeapFree(GetProcessHeap(), 0, dest_path);
            
         TRACE("Duplicating file %s to %s\n",debugstr_w(file_source),
-              debugstr_w(dest_path)); 
+              debugstr_w(dest)); 
         
-        if (strcmpW(file_source,dest_path))
-            rc = !CopyFileW(file_source,dest_path,TRUE);
+        if (strcmpW(file_source,dest))
+            rc = !CopyFileW(file_source,dest,TRUE);
         else
             rc = ERROR_SUCCESS;
         
@@ -2972,11 +3036,12 @@
         FIXME("We should track these duplicate files as well\n");   
  
         msiobj_release(&row->hdr);
+        HeapFree(GetProcessHeap(),0,dest);
+        HeapFree(GetProcessHeap(),0,file_source);
     }
     MSI_ViewClose(view);
     msiobj_release(&view->hdr);
     return rc;
-
 }
 
 
@@ -3326,7 +3391,7 @@
 
     TRACE("Checking Install Level\n");
 
-    level = PACKAGE_GetProperty(package,szlevel);
+    level = load_dynamic_property(package,szlevel,NULL);
     if (level)
     {
         install_level = atoiW(level);
@@ -3335,7 +3400,7 @@
     else
         install_level = 1;
 
-    override = PACKAGE_GetProperty(package,szAddLocal);
+    override = load_dynamic_property(package,szAddLocal,NULL);
    
     /*
      * Components FeatureState defaults to FALSE. The idea is we want to 
@@ -3469,22 +3534,20 @@
     return rc;
 }
 
-static void resolve_keypath( MSIPACKAGE* package, INT
-                            component_index, WCHAR *keypath)
+static LPWSTR resolve_keypath( MSIPACKAGE* package, INT
+                            component_index)
 {
     MSICOMPONENT* cmp = &package->components[component_index];
 
     if (cmp->KeyPath[0]==0)
     {
         LPWSTR p = resolve_folder(package,cmp->Directory,FALSE,FALSE,NULL);
-        strcpyW(keypath,p);
-        HeapFree(GetProcessHeap(),0,p);
-        return;
+        return p;
     }
     if ((cmp->Attributes & 0x4) || (cmp->Attributes & 0x20))
     {
         FIXME("UNIMPLEMENTED keypath as Registry or ODBC Source\n");
-        keypath[0]=0;
+        return NULL;
     }
     else
     {
@@ -3492,8 +3555,12 @@
         j = get_loaded_file(package,cmp->KeyPath);
 
         if (j>=0)
-            strcpyW(keypath,package->files[j].TargetPath);
+        {
+            LPWSTR p = dupstrW(package->files[j].TargetPath);
+            return p;
+        }
     }
+    return NULL;
 }
 
 /*
@@ -3528,9 +3595,9 @@
         return ERROR_INVALID_HANDLE;
 
     /* writes the Component and Features values to the registry */
-    productcode = PACKAGE_GetProperty(package,szProductCode);
+    productcode = load_dynamic_property(package,szProductCode,&rc);
     if (!productcode)
-        return ERROR_SUCCESS;
+        return rc;
 
     squash_guid(productcode,squished_pc);
     rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller,&hkey);
@@ -3587,7 +3654,7 @@
     {
         if (package->components[i].ComponentId[0]!=0)
         {
-            WCHAR keypath[0x1000];
+            WCHAR *keypath = NULL;
             MSIRECORD * uirow;
 
             squash_guid(package->components[i].ComponentId,squished_cc);
@@ -3595,19 +3662,23 @@
             if (rc != ERROR_SUCCESS)
                 continue;
            
-            resolve_keypath(package,i,keypath);
-
-            RegSetValueExW(hkey3,squished_pc,0,REG_SZ,(LPVOID)keypath,
+            keypath = resolve_keypath(package,i);
+            if (keypath)
+            {
+                RegSetValueExW(hkey3,squished_pc,0,REG_SZ,(LPVOID)keypath,
                             (strlenW(keypath)+1)*sizeof(WCHAR));
-            RegCloseKey(hkey3);
+                RegCloseKey(hkey3);
         
-            /* UI stuff */
-            uirow = MSI_CreateRecord(3);
-            MSI_RecordSetStringW(uirow,1,productcode);
-            MSI_RecordSetStringW(uirow,2,package->components[i].ComponentId);
-            MSI_RecordSetStringW(uirow,3,keypath);
-            ui_actiondata(package,szProcessComponents,uirow);
-            msiobj_release( &uirow->hdr );
+                /* UI stuff */
+                uirow = MSI_CreateRecord(3);
+                MSI_RecordSetStringW(uirow,1,productcode);
+                MSI_RecordSetStringW(uirow,2,package->components[i].
+                                                        ComponentId);
+                MSI_RecordSetStringW(uirow,3,keypath);
+                ui_actiondata(package,szProcessComponents,uirow);
+                msiobj_release( &uirow->hdr );
+                HeapFree(GetProcessHeap(),0,keypath);
+            }
         }
     } 
 end:
@@ -4186,10 +4257,13 @@
 }
 
 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name, 
-                            LPWSTR FilePath)
+                            LPWSTR *FilePath)
 {
     LPWSTR ProductCode;
     LPWSTR SystemFolder;
+    LPWSTR dest;
+    UINT rc;
+
     static const WCHAR szInstaller[] = 
         {'I','n','s','t','a','l','l','e','r','\\',0};
     static const WCHAR szProductCode[] =
@@ -4197,21 +4271,21 @@
     static const WCHAR szFolder[] =
         {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
 
-    ProductCode = PACKAGE_GetProperty(package,szProductCode);
+    ProductCode = load_dynamic_property(package,szProductCode,&rc);
     if (!ProductCode)
-        return ERROR_FUNCTION_FAILED;
+        return rc;
 
-    SystemFolder = PACKAGE_GetProperty(package,szFolder);
+    SystemFolder = load_dynamic_property(package,szFolder,NULL);
+
+    dest = build_directory_name(3, SystemFolder, szInstaller, ProductCode);
+
+    create_full_pathW(dest);
+
+    *FilePath = build_directory_name(2, dest, icon_name);
 
-    strcatW(SystemFolder,szInstaller); 
-    strcatW(SystemFolder,ProductCode);
-    create_full_pathW(SystemFolder);
-
-    strcpyW(FilePath,SystemFolder);
-    strcatW(FilePath,cszbs);
-    strcatW(FilePath,icon_name);
     HeapFree(GetProcessHeap(),0,SystemFolder);
     HeapFree(GetProcessHeap(),0,ProductCode);
+    HeapFree(GetProcessHeap(),0,dest);
     return ERROR_SUCCESS;
 }
 
@@ -4356,16 +4430,17 @@
 
         if (!MSI_RecordIsNull(row,9))
         {
-            WCHAR Path[MAX_PATH];
+            WCHAR *Path = NULL;
             INT index; 
 
             sz = 0x100;
             MSI_RecordGetStringW(row,9,buffer,&sz);
 
-            build_icon_path(package,buffer,Path);
+            build_icon_path(package,buffer,&Path);
             index = MSI_RecordGetInteger(row,10);
 
             IShellLinkW_SetIconLocation(sl,Path,index);
+            HeapFree(GetProcessHeap(),0,Path);
         }
 
         if (!MSI_RecordIsNull(row,11))
@@ -4383,7 +4458,9 @@
 
         TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
         IPersistFile_Save(pf,target_file,FALSE);
-        
+    
+        HeapFree(GetProcessHeap(),0,target_file);    
+
         IPersistFile_Release( pf );
         IShellLinkW_Release( sl );
 
@@ -4433,8 +4510,8 @@
     while (1)
     {
         HANDLE the_file;
-        WCHAR FilePath[MAX_PATH];
-        WCHAR FileName[MAX_PATH];
+        WCHAR *FilePath=NULL;
+        WCHAR *FileName=NULL;
         CHAR buffer[1024];
 
         rc = MSI_ViewFetch(view,&row);
@@ -4444,16 +4521,17 @@
             break;
         }
     
-        sz = MAX_PATH;
-        MSI_RecordGetStringW(row,1,FileName,&sz);
-        if (sz == 0)
+        FileName = load_dynamic_stringW(row,1);
+        if (!FileName)
         {
             ERR("Unable to get FileName\n");
             msiobj_release(&row->hdr);
             continue;
         }
 
-        build_icon_path(package,FileName,FilePath);
+        build_icon_path(package,FileName,&FilePath);
+
+        HeapFree(GetProcessHeap(),0,FileName);
 
         TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
         
@@ -4464,6 +4542,7 @@
         {
             ERR("Unable to create file %s\n",debugstr_w(FilePath));
             msiobj_release(&row->hdr);
+            HeapFree(GetProcessHeap(),0,FilePath);
             continue;
         }
 
@@ -4482,6 +4561,8 @@
             WriteFile(the_file,buffer,sz,&write,NULL);
         } while (sz == 1024);
 
+        HeapFree(GetProcessHeap(),0,FilePath);
+
         CloseHandle(the_file);
         msiobj_release(&row->hdr);
     }
@@ -4583,11 +4664,12 @@
         *pcchPathBuf = strlenW(path)+1;
         rc = ERROR_MORE_DATA;
     }
-    else if (rc == ERROR_SUCCESS)
+    else if (path)
     {
         *pcchPathBuf = strlenW(path)+1;
         strcpyW(szPathBuf,path);
         TRACE("Returning Path %s\n",debugstr_w(path));
+        rc = ERROR_SUCCESS;
     }
     HeapFree(GetProcessHeap(),0,path);
     
@@ -4644,14 +4726,16 @@
     if (path && strlenW(path) > *pcchPathBuf)
     {
         *pcchPathBuf = strlenW(path)+1;
-        return ERROR_MORE_DATA;
+        rc = ERROR_MORE_DATA;
     }
-    else if (rc == ERROR_SUCCESS)
+    else if (path)
     {
         *pcchPathBuf = strlenW(path)+1;
         strcpyW(szPathBuf,path);
         TRACE("Returning Path %s\n",debugstr_w(path));
+        rc = ERROR_SUCCESS;
     }
+    HeapFree(GetProcessHeap(),0,path);
     
     return rc;
 }


More information about the wine-patches mailing list