[Setup]
AppName=科技之星
AppVersion=2.0
DefaultDirName={pf}\YourAppName

[Code]
const
  OldVersionRegPath = 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{#SetupSetting("AppId")}_is1';
  OldVersionInstallLocationKey = 'InstallLocation';

function GetOldVersionInstallPath: string;
var
  RegValue: string;
begin
  if not RegQueryStringValue(HKLM, OldVersionRegPath, OldVersionInstallLocationKey, RegValue) then
    RegQueryStringValue(HKCU, OldVersionRegPath, OldVersionInstallLocationKey, RegValue);

  Result := RegValue;
end;

procedure CurStepChanged(CurStep: TSetupStep);
var
  OldInstallPath: string;
begin
  if CurStep = ssInstall then
  begin
    OldInstallPath := GetOldVersionInstallPath;

    if DirExists(OldInstallPath) then
    begin
      // 复制新的文件替换旧版本
      FileCopy('NewFiles\*', OldInstallPath, False, True);
    end;
  end;
end;