Commit e18f8abe authored by Mike McCormack's avatar Mike McCormack Committed by Alexandre Julliard

- build a standard Wine list of files instead of using an array

- use file pointers instead of array indexes
parent 625d872b
......@@ -93,6 +93,7 @@ typedef struct tagMSIFOLDER
typedef struct tagMSIFILE
{
struct list entry;
LPWSTR File;
MSICOMPONENT *Component;
LPWSTR FileName;
......@@ -237,8 +238,8 @@ LPWSTR load_dynamic_property(MSIPACKAGE *package, LPCWSTR prop, UINT* rc);
LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name, BOOL source,
BOOL set_prop, MSIFOLDER **folder);
MSICOMPONENT *get_loaded_component( MSIPACKAGE* package, LPCWSTR Component );
MSIFEATURE *get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature );
int get_loaded_file(MSIPACKAGE* package, LPCWSTR file);
MSIFEATURE *get_loaded_feature( MSIPACKAGE* package, LPCWSTR Feature );
MSIFILE *get_loaded_file( MSIPACKAGE* package, LPCWSTR file );
int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path);
UINT schedule_action(MSIPACKAGE *package, UINT script, LPCWSTR action);
UINT build_icon_path(MSIPACKAGE *, LPCWSTR, LPWSTR *);
......
......@@ -918,7 +918,7 @@ UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
for (i = 0; i < package->loaded_classes; i++)
{
MSICOMPONENT *comp;
INT index;
MSIFILE *file;
DWORD size, sz;
LPWSTR argument;
MSIFEATURE *feature;
......@@ -959,7 +959,7 @@ UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
Description)+1)*sizeof(WCHAR));
RegCreateKeyW(hkey2,package->classes[i].Context,&hkey3);
index = get_loaded_file( package, comp->KeyPath );
file = get_loaded_file( package, comp->KeyPath );
/* the context server is a short path name
......@@ -968,7 +968,7 @@ UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
if (strcmpiW(package->classes[i].Context,szInprocServer32)!=0)
{
sz = 0;
sz = GetShortPathNameW(package->files[index].TargetPath, NULL, 0);
sz = GetShortPathNameW( file->TargetPath, NULL, 0 );
if (sz == 0)
{
ERR("Unable to find short path for CLSID COM Server\n");
......@@ -986,8 +986,7 @@ UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
}
argument = HeapAlloc(GetProcessHeap(), 0, size + sizeof(WCHAR));
GetShortPathNameW(package->files[index].TargetPath, argument,
sz);
GetShortPathNameW( file->TargetPath, argument, sz );
if (package->classes[i].Argument)
{
......@@ -998,7 +997,7 @@ UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
}
else
{
size = lstrlenW(package->files[index].TargetPath) * sizeof(WCHAR);
size = lstrlenW( file->TargetPath ) * sizeof(WCHAR);
if (package->classes[i].Argument)
{
......@@ -1007,7 +1006,7 @@ UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
}
argument = HeapAlloc(GetProcessHeap(), 0, size + sizeof(WCHAR));
strcpyW(argument, package->files[index].TargetPath);
strcpyW( argument, file->TargetPath );
if (package->classes[i].Argument)
{
......
......@@ -586,14 +586,16 @@ static UINT HANDLE_CustomType18(MSIPACKAGE *package, LPCWSTR source,
WCHAR *cmd;
INT len;
static const WCHAR spc[] = {' ',0};
int index;
MSIFILE *file;
UINT prc;
memset(&si,0,sizeof(STARTUPINFOW));
index = get_loaded_file(package,source);
file = get_loaded_file(package,source);
if( !file )
return ERROR_FUNCTION_FAILED;
len = strlenW(package->files[index].TargetPath);
len = lstrlenW( file->TargetPath );
deformat_string(package,target,&deformated);
if (deformated)
......@@ -602,7 +604,7 @@ static UINT HANDLE_CustomType18(MSIPACKAGE *package, LPCWSTR source,
cmd = HeapAlloc(GetProcessHeap(),0,len * sizeof(WCHAR));
strcpyW(cmd, package->files[index].TargetPath);
lstrcpyW( cmd, file->TargetPath);
if (deformated)
{
strcatW(cmd, spc);
......
......@@ -207,23 +207,22 @@ static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
LPWSTR tracknametmp;
static const WCHAR tmpprefix[] = {'C','A','B','T','M','P','_',0};
LPWSTR given_file;
INT index;
MSIRECORD * uirow;
LPWSTR uipath;
MSIFILE *f;
given_file = strdupAtoW(pfdin->psz1);
index = get_loaded_file(data->package, given_file);
f = get_loaded_file(data->package, given_file);
if (index < 0)
if (!f)
{
ERR("Unknown File in Cabinent (%s)\n",debugstr_w(given_file));
HeapFree(GetProcessHeap(),0,given_file);
return 0;
}
if (!((data->package->files[index].State == 1 ||
data->package->files[index].State == 2)))
if (!((f->State == 1 || f->State == 2)))
{
TRACE("Skipping extraction of %s\n",debugstr_w(given_file));
HeapFree(GetProcessHeap(),0,given_file);
......@@ -253,16 +252,16 @@ static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
/* the UI chunk */
uirow=MSI_CreateRecord(9);
MSI_RecordSetStringW(uirow,1,data->package->files[index].File);
uipath = strdupW(data->package->files[index].TargetPath);
MSI_RecordSetStringW( uirow, 1, f->File );
uipath = strdupW( f->TargetPath );
*(strrchrW(uipath,'\\')+1)=0;
MSI_RecordSetStringW(uirow,9,uipath);
MSI_RecordSetInteger(uirow,6,data->package->files[index].FileSize);
MSI_RecordSetInteger( uirow, 6, f->FileSize );
ui_actiondata(data->package,szInstallFiles,uirow);
msiobj_release( &uirow->hdr );
HeapFree(GetProcessHeap(),0,uipath);
ui_progress(data->package,2,data->package->files[index].FileSize,0,0);
ui_progress( data->package, 2, f->FileSize, 0, 0);
return cabinet_open(file, _O_WRONLY | _O_CREAT, 0);
}
......@@ -433,7 +432,7 @@ static UINT ready_volume(MSIPACKAGE* package, LPCWSTR path, LPWSTR last_volume,
return ERROR_SUCCESS;
}
static UINT ready_media_for_file(MSIPACKAGE *package, int fileindex,
static UINT ready_media_for_file(MSIPACKAGE *package, MSIFILE *file,
MSICOMPONENT* comp)
{
UINT rc = ERROR_SUCCESS;
......@@ -451,7 +450,6 @@ static UINT ready_media_for_file(MSIPACKAGE *package, int fileindex,
static UINT last_sequence = 0;
static LPWSTR last_volume = NULL;
static LPWSTR last_path = NULL;
MSIFILE* file = NULL;
UINT type;
LPCWSTR prompt;
static DWORD count = 0;
......@@ -469,8 +467,6 @@ static UINT ready_media_for_file(MSIPACKAGE *package, int fileindex,
return ERROR_SUCCESS;
}
file = &package->files[fileindex];
if (file->Sequence <= last_sequence)
{
set_file_source(package,file,comp,last_path);
......@@ -581,8 +577,6 @@ static UINT ready_media_for_file(MSIPACKAGE *package, int fileindex,
}
}
rc = !extract_cabinet_file(package, source, last_path);
/* reaquire file ptr */
file = &package->files[fileindex];
}
else
{
......@@ -615,21 +609,21 @@ static UINT ready_media_for_file(MSIPACKAGE *package, int fileindex,
return rc;
}
inline static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
LPWSTR* file_source)
{
DWORD index;
MSIFILE *file;
if (!package)
return ERROR_INVALID_HANDLE;
for (index = 0; index < package->loaded_files; index ++)
LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
{
if (strcmpW(file_key,package->files[index].File)==0)
if (lstrcmpW( file_key, file->File )==0)
{
if (package->files[index].State >= 2)
if (file->State >= 2)
{
*file_source = strdupW(package->files[index].TargetPath);
*file_source = strdupW( file->TargetPath );
return ERROR_SUCCESS;
}
else
......@@ -650,8 +644,8 @@ inline static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
UINT ACTION_InstallFiles(MSIPACKAGE *package)
{
UINT rc = ERROR_SUCCESS;
DWORD index;
LPWSTR ptr;
MSIFILE *file;
if (!package)
return ERROR_INVALID_HANDLE;
......@@ -672,13 +666,10 @@ UINT ACTION_InstallFiles(MSIPACKAGE *package)
FIXME("Write DiskPrompt\n");
/* Pass 1 */
for (index = 0; index < package->loaded_files; index++)
LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
{
MSIFILE *file;
MSICOMPONENT* comp = NULL;
file = &package->files[index];
if (file->Temporary)
continue;
......@@ -719,12 +710,8 @@ UINT ACTION_InstallFiles(MSIPACKAGE *package)
}
/* Pass 2 */
for (index = 0; index < package->loaded_files; index++)
LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
{
MSIFILE *file;
file = &package->files[index];
if (file->Temporary)
continue;
......@@ -732,7 +719,7 @@ UINT ACTION_InstallFiles(MSIPACKAGE *package)
{
TRACE("Pass 2: %s\n",debugstr_w(file->File));
rc = ready_media_for_file( package, index, file->Component );
rc = ready_media_for_file( package, file, file->Component );
if (rc != ERROR_SUCCESS)
{
ERR("Unable to ready media\n");
......@@ -740,13 +727,6 @@ UINT ACTION_InstallFiles(MSIPACKAGE *package)
break;
}
/*
* WARNING!
* our file table could change here because a new temp file
* may have been created. So reaquire our ptr.
*/
file = &package->files[index];
TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
debugstr_w(file->TargetPath));
......@@ -791,7 +771,7 @@ UINT ACTION_InstallFiles(MSIPACKAGE *package)
}
/* cleanup */
ready_media_for_file(NULL, 0, NULL);
ready_media_for_file(NULL, NULL, NULL);
return rc;
}
......
......@@ -100,38 +100,37 @@ static LPWSTR deformat_file(MSIPACKAGE* package, LPCWSTR key, DWORD* sz,
BOOL shortname)
{
LPWSTR value = NULL;
INT index;
MSIFILE *file;
*sz = 0;
if (!package)
return NULL;
index = get_loaded_file(package,key);
if (index >=0)
file = get_loaded_file( package, key );
if (file)
{
if (!shortname)
{
value = strdupW(package->files[index].TargetPath);
value = strdupW( file->TargetPath );
*sz = (strlenW(value)) * sizeof(WCHAR);
}
else
{
DWORD size = 0;
size = GetShortPathNameW(package->files[index].TargetPath, NULL, 0);
size = GetShortPathNameW( file->TargetPath, NULL, 0 );
if (size > 0)
{
*sz = (size-1) * sizeof (WCHAR);
size ++;
value = HeapAlloc(GetProcessHeap(),0,size * sizeof(WCHAR));
GetShortPathNameW(package->files[index].TargetPath, value,
size);
GetShortPathNameW( file->TargetPath, value, size );
}
else
{
ERR("Unable to get ShortPath size (%s)\n",
debugstr_w(package->files[index].TargetPath));
ERR("Unable to get ShortPath size (%s)\n",
debugstr_w( file->TargetPath) );
value = NULL;
*sz = 0;
}
......
......@@ -169,7 +169,7 @@ LPWSTR load_dynamic_property(MSIPACKAGE *package, LPCWSTR prop, UINT* rc)
MSICOMPONENT* get_loaded_component( MSIPACKAGE* package, LPCWSTR Component )
{
MSICOMPONENT *comp = NULL;
MSICOMPONENT *comp;
LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
{
......@@ -181,7 +181,7 @@ MSICOMPONENT* get_loaded_component( MSIPACKAGE* package, LPCWSTR Component )
MSIFEATURE* get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature )
{
MSIFEATURE *feature = NULL;
MSIFEATURE *feature;
LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
{
......@@ -191,49 +191,36 @@ MSIFEATURE* get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature )
return NULL;
}
int get_loaded_file(MSIPACKAGE* package, LPCWSTR file)
MSIFILE* get_loaded_file( MSIPACKAGE* package, LPCWSTR key )
{
int rc = -1;
DWORD i;
MSIFILE *file;
for (i = 0; i < package->loaded_files; i++)
LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
{
if (strcmpW(file,package->files[i].File)==0)
{
rc = i;
break;
}
if (lstrcmpW( key, file->File )==0)
return file;
}
return rc;
return NULL;
}
int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path)
int track_tempfile( MSIPACKAGE *package, LPCWSTR name, LPCWSTR path )
{
DWORD i;
DWORD index;
MSIFILE *file;
if (!package)
return -2;
for (i=0; i < package->loaded_files; i++)
if (strcmpW(package->files[i].File,name)==0)
return -1;
index = package->loaded_files;
package->loaded_files++;
if (package->loaded_files== 1)
package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
else
package->files = HeapReAlloc(GetProcessHeap(),0,
package->files , package->loaded_files * sizeof(MSIFILE));
file = get_loaded_file( package, name );
if (file)
return -1;
memset(&package->files[index],0,sizeof(MSIFILE));
file = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof (MSIFILE) );
package->files[index].File = strdupW(name);
package->files[index].TargetPath = strdupW(path);
package->files[index].Temporary = TRUE;
file->File = strdupW( name );
file->TargetPath = strdupW( path );
file->Temporary = TRUE;
TRACE("Tracking tempfile (%s)\n",debugstr_w(package->files[index].File));
TRACE("Tracking tempfile (%s)\n", debugstr_w( file->File ));
return 0;
}
......@@ -429,19 +416,18 @@ UINT schedule_action(MSIPACKAGE *package, UINT script, LPCWSTR action)
static void remove_tracked_tempfiles(MSIPACKAGE* package)
{
DWORD i;
MSIFILE *file;
if (!package)
return;
for (i = 0; i < package->loaded_files; i++)
LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
{
if (package->files[i].Temporary)
if (file->Temporary)
{
TRACE("Cleaning up %s\n",debugstr_w(package->files[i].TargetPath));
DeleteFileW(package->files[i].TargetPath);
TRACE("Cleaning up %s\n", debugstr_w( file->TargetPath ));
DeleteFileW( file->TargetPath );
}
}
}
......@@ -497,19 +483,20 @@ void ACTION_free_package_structures( MSIPACKAGE* package)
HeapFree( GetProcessHeap(), 0, comp );
}
for (i = 0; i < package->loaded_files; i++)
LIST_FOR_EACH_SAFE( item, cursor, &package->files )
{
HeapFree(GetProcessHeap(),0,package->files[i].File);
HeapFree(GetProcessHeap(),0,package->files[i].FileName);
HeapFree(GetProcessHeap(),0,package->files[i].ShortName);
HeapFree(GetProcessHeap(),0,package->files[i].Version);
HeapFree(GetProcessHeap(),0,package->files[i].Language);
HeapFree(GetProcessHeap(),0,package->files[i].SourcePath);
HeapFree(GetProcessHeap(),0,package->files[i].TargetPath);
}
MSIFILE *file = LIST_ENTRY( item, MSIFILE, entry );
if (package->files && package->loaded_files > 0)
HeapFree(GetProcessHeap(),0,package->files);
list_remove( &file->entry );
HeapFree( GetProcessHeap(), 0, file->File );
HeapFree( GetProcessHeap(), 0, file->FileName );
HeapFree( GetProcessHeap(), 0, file->ShortName );
HeapFree( GetProcessHeap(), 0, file->Version );
HeapFree( GetProcessHeap(), 0, file->Language );
HeapFree( GetProcessHeap(), 0, file->SourcePath );
HeapFree( GetProcessHeap(), 0, file->TargetPath );
HeapFree( GetProcessHeap(), 0, file );
}
/* clean up extension, progid, class and verb structures */
for (i = 0; i < package->loaded_classes; i++)
......
......@@ -190,8 +190,7 @@ typedef struct tagMSIPACKAGE
UINT loaded_folders;
struct list components;
struct list features;
struct tagMSIFILE *files;
UINT loaded_files;
struct list files;
LPWSTR ActionFormat;
LPWSTR LastAction;
......
......@@ -380,9 +380,8 @@ MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db )
list_init( &package->features );
package->folders = NULL;
list_init( &package->components );
package->files = NULL;
list_init( &package->files );
package->loaded_folders = 0;
package->loaded_files = 0;
package->ActionFormat = NULL;
package->LastAction = NULL;
package->dialog = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment