生产工具打包脚本,覆盖安装更改为卸载安装

This commit is contained in:
yangjiaxuan 2024-01-08 09:54:12 +08:00
parent 3a259fe837
commit d8ab54234b
1 changed files with 114 additions and 3 deletions

View File

@ -30,7 +30,15 @@ PrivilegesRequired=admin
DisableWelcomePage=no
[Languages]
Name: "zn"; MessagesFile: "compiler:Languages/ChineseSimp.isl"
Name: "chinese_simp"; MessagesFile: "compiler:Languages/ChineseSimp.isl"; LicenseFile:HGProductionTool_App_License.txt
[CustomMessages]
chinese_simp.MyAppName=华高生产工具
chinese_simp.MyAppPublisher=宁波华高信息科技有限公司
chinese_simp.MyStr1=软件已安装,是否卸载原版本?
chinese_simp.MyStr2=请先关闭旧版软件!
chinese_simp.MyStr3=卸载旧版软件失败,停止安装!
chinese_simp.MyStr4=请先关闭软件!
[Files]
@ -64,17 +72,102 @@ Source: "..\..\usb\huagao\hgscannerusball.cat"; DestDir: "{app}\driver\"; Flags
Source: "..\..\x86\Release\DPInst32.exe"; DestDir: "{app}\"; Flags: ignoreversion recursesubdirs; Check: not IsWin64
Source: "..\..\x64\Release\DPInst64.exe"; DestDir: "{app}\"; Flags: ignoreversion recursesubdirs; Check: IsWin64
; 临时使用
Source: "..\..\x86\Release\RemoveOldApp.exe"; DestDir: "{tmp}\"; Flags: ignoreversion
Source: "..\..\x86\Release\CheckNewApp.exe"; DestDir: "{app}\"; Flags: ignoreversion; Check: not Is64BitInstallMode
Source: "..\..\x64\Release\CheckNewApp.exe"; DestDir: "{app}\"; Flags: ignoreversion; Check: Is64BitInstallMode
[INI]
[Icons]
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\ProductionTool.exe"
Name: "{group}\{#MyAppName}"; Filename: "{app}\ProductionTool.exe"
Name: "{group}\{cm:UninstallProgram, {#MyAppName}}"; Filename: "{uninstallexe}";
Name: "{group}\卸载 {cm:UninstallProgram, {#MyAppName}}"; Filename: "{uninstallexe}";
[Registry]
Root: HKLM; Subkey: "Software\ProductionTool"; ValueType: string; ValueName: "AppDirectory"; ValueData: "{app}"; Flags: uninsdeletekey
Root: HKLM; Subkey: "Software\ProductionTool"; ValueType: string; ValueName: "Application"; ValueData: "{app}\ProductionTool.exe"; Flags: uninsdeletekey
Root: HKLM; Subkey: "Software\ProductionTool"; ValueType: string; ValueName: "AppVersion"; ValueData: "{#MyAppVersion}"; Flags: uninsdeletekey
Root: HKLM; Subkey: "Software\ProductionTool"; ValueType: string; ValueName: "DriverPath"; ValueData: "{app}"; Flags: uninsdeletekey; Check: not Is64BitInstallMode
[Code]
function SetUninstallIcon(iconPath:string): Boolean;
var
globalInstallPath: String;
procedure InitializeWizard;
begin
WizardForm.DirEdit.Text := globalInstallPath;
end;
function GetInstallString(): String;
var
InstallPath: String;
begin
InstallPath := ExpandConstant('{pf}\{#MyAppDefSetupDir}');
if RegValueExists(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{52021EA6-BCE5-4E07-8766-B6DC7C61FB51}_is1', 'Inno Setup: App Path') then
begin
RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{52021EA6-BCE5-4E07-8766-B6DC7C61FB51}_is1', 'Inno Setup: App Path', InstallPath)
end
result := InstallPath;
end;
function InitializeSetup(): boolean;
var
ErrorCode: Integer;
ResultCode: Integer;
ResultStr: String;
UninstallContinue: Boolean;
CmdStr: String;
begin
Result := false;
globalInstallPath := GetInstallString();
CmdStr := GetCmdTail();
ExtractTemporaryFile('RemoveOldApp.exe');
if Exec(ExpandConstant('{tmp}\RemoveOldApp.exe'), '', '', SW_HIDE, ewWaitUntilTerminated, ErrorCode) then
begin
if 0 = ErrorCode then
begin
if RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{52021EA6-BCE5-4E07-8766-B6DC7C61FB51}_is1', 'UninstallString', ResultStr) then
begin
UninstallContinue := true;
if Pos('/verysilent', CmdStr) = 0 then
begin
if MsgBox(ExpandConstant('{cm:MyStr1}'), mbConfirmation, MB_YESNO) <> IDYES then
begin
UninstallContinue := false;
end
end
if UninstallContinue then
begin
ResultStr := RemoveQuotes(ResultStr);
if Exec(ResultStr, '/verysilent', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
begin
if 0 = ResultCode then
begin
Sleep(1000)
Result := true;
end
end
end
end
else
begin
Result := true;
end
end
else if 2 = ErrorCode then
begin
MsgBox(ExpandConstant('{cm:MyStr2}'), mbInformation, MB_OK);
end
else
begin
MsgBox(ExpandConstant('{cm:MyStr3}'), mbInformation, MB_OK);
end
end
end;
function SetUninstallIcon(iconPath:string): Boolean;
var
InstalledVersion,SubKeyName: String;
begin
@ -82,6 +175,24 @@ begin
RegWriteStringValue(HKLM,SubKeyName,'DisplayIcon',iconPath);
end;
function InitializeUninstall(): Boolean;
var
ErrorCode: Integer;
begin
Result := false;
if Exec(ExpandConstant('{app}\CheckNewApp.exe'), '', '', SW_HIDE, ewWaitUntilTerminated, ErrorCode) then
begin
if 0 = ErrorCode then
begin
Result := true;
end
else
begin
MsgBox(ExpandConstant('{cm:MyStr4}'), mbInformation, MB_OK);
end
end
end;
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpFinished then