web-dev-qa-db-ja.com

古いバージョンが既にインストールされている場合に更新を実行するインストーラーを作成する

私のソフトウェア(これはC#ソフトウェアです)のInnoセットアップを構成しようとしています。ソフトウェアの多くのバージョンをリリースする予定です。アプリケーションの古いバージョンがすでにコンピューターにインストールされている場合は、Innoセットアップインストーラーインターフェイスを変更したいと思います。この場合、ユーザーはインストールディレクトリを変更できません。

4つのケースがあります。

最初のケース:これは私の製品の最初のインストールです。Innoセットアップは通常どおり続行されます。

2番目のケース:製品はすでにインストールされており、インストーラーには新しいバージョンが含まれています。ユーザーは宛先フォルダーを選択できません。彼はアップデートを実行できます。

3番目のケース:インストーラーにインストールされているバージョンより古いバージョンが含まれている場合、更新は無効になり、メッセージが表示されます。

4番目のケース:インストーラーのバージョンは、インストールされているバージョンと同じです。ユーザーは必要に応じて実際のバージョンを修復できます。

InnoSetupでそれを行うことは可能ですか?

19
Ben

ユーザーにフィードバックを提供したい場合は、そのようなことを試すことができます。まず、アップデートにはメインアプリと同じAppIdの名前を付ける必要があります。次に、いくつかのチェックを設定できます。これにより、状態をユーザーに通知するメッセージが表示されます。

#define MyAppVersion "1.2.2.7570"
#define MyAppName "MyApp Update"

[Setup]
AppId=MyApp
AppName={#MyAppName}
AppVersion={#MyAppVersion}
DefaultDirName={reg:HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1,InstallLocation}
DisableDirPage=True

[CustomMessages]
MyAppOld=The Setup detected application version 
MyAppRequired=The installation of {#MyAppName} requires MyApp to be installed.%nInstall MyApp before installing this update.%n%n
MyAppTerminated=The setup of update will be terminated.

[Code]
var
InstallLocation: String;

function GetInstallString(): String;
var
InstPath: String;
InstallString: String;
begin
InstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1');
InstallString := '';
if not RegQueryStringValue(HKLM, InstPath, 'InstallLocation', InstallString) then
RegQueryStringValue(HKCU, InstPath, 'InstallLocation', InstallString);
Result := InstallString;
InstallLocation := InstallString;
end;

function InitializeSetup: Boolean;
var
V: Integer;
sUnInstallString: String;
Version: String;
begin
    if RegValueExists(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1', 'UninstallString') then begin
      RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1', 'DisplayVersion', Version);
      if Version =< ExpandConstant('{#MyAppVersion}') then begin 
          Result := True;
          GetInstallString();
       end
       else begin
MsgBox(ExpandConstant('{cm:MyAppOld}'+Version+'.'+#13#10#13#10+'{cm:MyAppRequired}'+'{cm:MyAppTerminated}'), mbInformation, MB_OK);
         Result := False;
  end;
end
else begin
  MsgBox(ExpandConstant('{cm:MyAppRequired}'+'{cm:MyAppTerminated}'), mbInformation, MB_OK);
  Result := False;
end;
end;
9
RobeN

Inno Setupは、AppIDがアプリケーションの存続期間中同じに保たれている場合、すでにケース1、2、および4を自動的に処理します。
次の_[Setup]_ディレクティブを使用して、ディレクトリおよびグループのページを非表示にすることもできます:

_DisableDirPage=auto
DisableGroupPage=auto
_

詳細はこちら ISXKB記事 を参照してください。

ケース3の場合、ファイルが正しくバージョン管理されていれば、Innoは何もダウングレードしませんが、実際にはユーザーに警告しません。これを行うには、これをチェックするコードを追加する必要があります。これは、おそらくInitializeSetup()イベント関数にあります。

7
Deanna