What to do to get nice, full filename from the code below:
;bugfixes
Source: "Bugfixes\CombatGameConstants.json"; DestDir: "{code:battletechDataDir}\constants";\
Flags: uninsneveruninstall; Components: DataBugfixes; BeforeInstall: BackupFile()
and the BackupFile()
procedure:
procedure BackupFile();
var fileToBackup : String;
begin
{ if backup file already exists skip creation, otherwise rename the file to file.backup }
fileToBackup := CurrentFilename(); { get destination file name }
if not FileExists(fileToBackup + '.backup') then
begin
if not RenameFile(fileToBackup, fileToBackup + '.backup') then
MsgBox('Creation backup file for ' + fileToBackup + ' failed!', mbInformation, MB_OK);
end;
end;
This does not convert {code:battletechDataDir}
into full path – CurrentFileName()
returns me {code:battletechDataDir}\constants\{code:battletechDataDir}\constants
. So either how to convert that {code:battletechDataDir}
into directory, or backup given file other way?
You can use ExpandConstant
function:
fileToBackup := ExpandConstant(CurrentFilename()); { get destination file name }
Though CurrentFilename
is intended for use with wildcard source. With a fixed file name, you might as well refer to the file explicitly:
fileToBackup := battletechDataDir('') + '\constants\CombatGameConstants.json';