tags:

views:

970

answers:

2

I have this in my installer and I need to change the name of the ini file.

[INI]
Filename: {app}\bin\old.ini; Section: Data; Key: key; String: Value;

If I just change the filename it will create another ini file and I'll lose the data.

Is there some easy way to rename this ini file in the installer?

+2  A: 

I think you should use RenameFile() in [CODE] section instead, since you know where the ini file is.

PhiLho
+1  A: 

Just being more verbose about PhiLho's answer:

In the [INI] section of the installer, just change everything to the new .ini file, then in the code rename the old file in the ssInstall step like this:

procedure CurStepChanged(CurStep: TSetupStep);
var
  OldFile: string;
begin
  if CurStep = ssInstall then
  begin
    OldFile := ExpandConstant('{app}\old.ini');
    if FileExists(OldFile) then
      RenameFile(OldFile, ExpandConstant('{app}\new.ini'));
  end;
end;

It works as expected because the ssInstall occurs before the [INI] section, so when the installer tries to create the new .ini file the old one will be already renamed and it will just update any entries if necessary.

Fabio Gomes