function IsOldVersionInstalled: Boolean;
begin
Result := FileExists(ExpandConstant('{pf}')+'\old program dir\oldexename.exe');
end;
function InitializeSetup: Boolean;
begin
Result := True;
if IsOldVersionInstalled then
begin
MsgBox('You must uninstall the previous version before installing.', mbError, MB_OK);
Result := False;
Exit;
end;
end;
function PrepareToInstall(var NeedsRestart: Boolean): String;
begin
{ do we need to rename dir/files }
if DirExists(expandconstant('{commonappdata}')+'\oldname') and not DirExists(expandconstant('{commonappdata}')+'\newname') then
begin
if not RenameFile(expandconstant('{commonappdata}')+'\oldname', expandconstant('{commonappdata}')+'\newname') then
begin
Result := 'Unable to rename old programdata directory.';
Exit;
end;
end;
{try to rename oldname.log}
if FileExists(expandconstant('{commonappdata}')+'\newname\oldname.log') and not FileExists(expandconstant('{commonappdata}')+'\newname\newname.log') then
begin
if not RenameFile(expandconstant('{commonappdata}')+'\newname\oldname.log', expandconstant('{commonappdata}')+'\newname\newname.log') then
begin
Result := 'Unable to rename oldname.log.';
Exit;
end;
end;
end;