View Full Version : Trouble writing installer to upgrade to same directory

04-11-2003, 04:54 PM
Hmm. I think that this should be a relatively common and simple thing to do, but I have spent a couple of days, and can't seem to find a way to do it.
What I want to do:

1) Move all files and directories from a previous installation of my product into a secondary directory.
2) If any files in the original directory cannot be moved (because they are in use, and the operating system won't let me move or delete them), I want to move the files back to their previous location, tell the user to close any open applications, and cancel the installation without producing an uninstall record. (Note: For Windows XP logo certification, rebooting to allow moving of in-use files is not acceptable in this situation. Instead, the install should tell the user to fix the problem, and fail.)
3) Otherwise, overwrite the original directory with a new set of files, and if that is successful, delete the old files.

Some problems I am running into:
A) The "Move Directory" bean doesn't give me any indication that some files couldn't be moved. It silently fails.
B) I can't figure out how to halt an installation from within a product bean, in such a manner that previously installed components will be uninstalled. So if I did manage to detect that the move directory bean had failed, I'm not sure what I could possibly do about the situation.
C) Even if I DID allow a reboot in this situation, after the entire product installation occurred, it appears from other reports in the installshield forums that any "new" file that was copied over a deleted "old" file would be deleted again post-reboot, resulting in incorrect contents of the original directory.
D) Even if I don't try to save the old files, I am still stuck with the problem of what to do if the attempt to delete the old files fails.

Any help on this would be appreciated. I'm surprised to be having these difficulties, since this seems like it would be a very common thing to have to do.

04-11-2003, 04:56 PM
As a note to the above, I should mention that when I say "I can't find any way to halt the installation", that what I mean is that I can't find any methods in the InstallShield API for writing custom actions that would allow me to do this.

04-16-2003, 04:04 PM
I had a similar problem. I needed to backup existing files for a Service Pack. (The original install was not done in multiplatform).

Basically I extend the files bean, then I overrode the

protected boolean canCopyFile(java.io.File file, int replaceOption, ArchiveIndexAccessor accessor, int accessorIndex, ProductActionSupport support)
throws ServiceException, java.io.IOException

so that I check first whether the file already exists. If it does...I back it up (using move). Then I call super.canCopyFile(....

On the uninstall side I overrode
protected boolean deleteWithFile(java.io.File fileToDelete)

first I call the super. protected boolean deleteWithFile(java.io.File fileToDelete)
then move the backed up files back to their original directory.

I would include my code but it has backup directories conventions and more debug code than usable code...basically too much work....

I hope this helps