PDA

View Full Version : Backup file location


sabarnett
10-08-2007, 05:54 AM
I have a line in the OnPreInstall event that sets my backup file location as follows:

-- Set the location of backup files
_BackupFolder = SessionVar.Expand("%AppFolder%\\sufBackup");

That works fine and the files listed in the archive are backed up to this folder when the approriate option is ticked. I also have the following code in the On Post Install event:

local result = File.Install(appPath .. sourceFile,
appPath .. destFile,
FILE_INSTALL_SAMEOLDER,
true,
false,
nil,
nil);
File.Delete(appPath .. sourceFile, false, false, false, nil);

This installs a file with a new name, so allowing me to effectively rename a file during the install. In the options to File.Install I have requested that the file be backed up before the copy. This gives me two issues:


The backup is placed in the same folder as the file, NOT the backup folder I requested.
The backup is of the SOURCE file, not the one I'm overwriting. That seems a little pointless as, surely, the file to be backed up should be the one you're about to overwrite.


Any way I can change this behaviour?

Thanks
Steve

Adam
10-10-2007, 01:25 PM
Just to update everyone on this because we have been dealing with it through support. The File.Install() is backing up the target file properly but because the source and target are using different names it is backing up the target file but giving it the source files name.

Adam Kapilik

sabarnett
10-11-2007, 02:30 AM
To add a little context. Our file naming standards require that updated modules include the version number in the file name. So, for example, version 3.6.23 of the ipmeuk.dll file would be called ipmeuk_3623.dll. This is the file that gets included in the install.

SUF does not allow me to install the file with a different name, so I have to rename it after the install. File.Install() seemed to do this for me, but I hit two problems; the name of the backup file is taken from the source file and the backup is not written to the same location as the automatic backup files - it goes to the same folder as the target file.

To get round this, I have developed the following script. It's not 100% in that it assumes that the user will never delete some of their backup files; they either leave them alone or they delete them all. I could add more sophisticated code to determine the next backup file name, but I'm doing an evaluation, so my scripting skills are very much 'new' and time is of the essence if I'm going to test everything I need to.

Still, the code may prove useful to someone else:

-- Function to rename a file - install it with the new name and
-- then delete the source file.
function RenameAppFile(appPath, sourceFile, destFile)
-- appPath = The folder containing the source and target files
-- sourceFile = The name of the file to rename
-- destFile = The name of the file to create

SetupData.WriteToLogFile("Renaming " .. sourceFile .. " to " .. destFile .. "\r\n", true);

local backupFiles = File.Find(_BackupFolder, destFile .. ".b*", false, false);
if backupFiles ~= nil then
backupName = _BackupFolder .. destFile .. ".bk" .. Table.Count(backupFiles);
else
backupName = _BackupFolder .. destFile .. ".bak";
end

-- Backup the file.
File.Copy(appPath .. destFile, backupName, false, true);
SetupData.WriteToLogFile("Backup file created: " .. backupName .. "\r\n", true);

local result = File.Install(appPath .. sourceFile,
appPath .. destFile,
FILE_INSTALL_SAMEOLDER,
false,
false,
nil,
nil);

-- Delete the installed file - we no longer need it.
File.Delete(appPath .. sourceFile, false, false, false, nil);

-- Setup for th e uninstall process, so we restore the backup file.
ItemData = {
Filename = appPath .. destFile,
DecrementUsageCount = true,
UnregisterCOM = false,
UnregisterFont = false,
BackupFile = backupName
}
UninstallData.AddItem(UNINDATA_FILES, ItemData);

return;
end


You would call this function as follows:

-- The install file is called ipmeuk_3623.dll. The runtime file is
-- called ipmeuk.dll so we need to rename it.
RenameAppFile(appFolder, "\\ipmeuk_3623.dll", "\\ipmeuk.dll");

HTH
Steve