I've got a Custom Action working as a DLL from my console app and it deletes
file on disk. I now want to push the file deletion into the RemoveFiles
table. Given that I have a handle to the MSI file instance, how would I
access/call the RemoveFile function based on the below? Should I use the
WcaInitialize call for logging too? Just some general pointers, I'm not
asking for anyone to write my code for me.
Also, it occurs to me that I might have to push the files into RemoveFiles
in reverse order so that the descendent directory/file entries get deleted
first. Is this correct or do I not need to bother?
As you can see, it is mostly TODO comments for now.
BOOL _stdcall DeleteDirectory(const TCHAR* sPath)
{
HANDLE hFind;
WIN32_FIND_DATA FindFileData;
//fprintf(stdout,"Root directory is %S\n", sPath);
TCHAR DirPath[MAX_PATH];
TCHAR FileName[MAX_PATH];
lstrcpy(DirPath,sPath);
lstrcat(DirPath,TEXT("\\"));
lstrcpy(FileName,sPath);
lstrcat(FileName,TEXT("\\*"));
//fprintf(stdout,"Checking %S in %S, based on %S\n",
FileName,DirPath,sPath);
hFind = FindFirstFile(FileName, &FindFileData); // find the first file
if( hFind != INVALID_HANDLE_VALUE )
{
do
{
if( IsDots(FindFileData.cFileName) )
{
continue;
}
lstrcpy(FileName + lstrlen(DirPath),
FindFileData.cFileName);
if((FindFileData.dwFileAttributes &
FILE_ATTRIBUTE_DIRECTORY))
{
// we have found a directory, recurse
fprintf(stdout,"Deleting folder %S\n", FileName);
// TODO: Bubble up failures.
if( !DeleteDirectory(FileName) )
{
break; // directory couldn't be deleted
}
}
else
{
if(FindFileData.dwFileAttributes &
FILE_ATTRIBUTE_READONLY)
{
SetFileAttributes(FileName,FILE_ATTRIBUTE_NORMAL);
}
fprintf(stdout,"Deleting file %S\n", FileName);
if( !DeleteFile(FileName) )
{
// TODO: Need to flag failure here.
break; // file couldn't be deleted
}
}
} while( FindNextFile(hFind,&FindFileData) );
FindClose(hFind); // closing file handle
}
// TODO: Bubble up above failures if failed.
return RemoveDirectory(sPath); // remove the empty (maybe not)
directory
}
UINT _stdcall NukeFolder(MSIHANDLE hModule)
{
TCHAR szDirectoryToDelete[MAX_PATH];
DWORD dwlen = MAX_PATH;
/* TODO: Enable logging
HRESULT hResult;
hResult = WcaInitialize( hModule, "NukeFolder" ); */
// TODO: Is there a better way to find the parent component directory?
UINT ur = MsiGetProperty(hModule, TEXT("CustomActionData"),
szDirectoryToDelete, &dwlen);
// TODO: Option to turn folder recursion off (on by default).
// TODO: Should we limit the directories that can be deleted (do not
run on root, windir etc)?
// TODO: We could pass the file deletion mask in here via
MsiGetProperty.
// TODO: Accept a flag that defines whether to delete folders, files
or both (default).
// TODO: Accept a flag for deleting read-only files (default).
// TODO: Handle error return.
DeleteDirectory(szDirectoryToDelete);
return ERROR_SUCCESS;
}
From: Bob Arnson [mailto:[EMAIL PROTECTED]
Sent: 17 April 2008 15:31
To: Ryan O'Neill
Cc: wix-users@lists.sourceforge.net
Subject: Re: [WiX-users] Recursive folder deletion
Ryan O'Neill wrote:
OK, so I'm going to give it a shot, may take a while though. Any pointers /
requirements from people such as Bobs usage of RemoveFile (being naive I
would have just deleted the files / dirs)?
Notes;
It won't be 64 bit tested.
It will be based on the sample @
http://www.wixwiki.com/index.php?title=Simple_Custom_Action_Dll
It will use RemoveFile (and RemoveDirectory if there is one) for rollback (I
assume).
I'll post the resultant source on here for critique if that is OK.
Yes, adding temporary rows to the RemoveFile table means that MSI handles
rollback for you. See
http://www.joyofsetup.com/2007/07/01/semi-custom-actions/.
--
sig://boB
http://joyofsetup.com/
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users