Skip to content

Commit

Permalink
Handle 32bit to 64bit updates in Windows installer
Browse files Browse the repository at this point in the history
Inno Setup uses separate AppIDs for 32bit and 64bit versions, so we need
to do extra work to transparently perform the update: we need to
uninstall the old version first, then install the new one, instead of
doing in-place update.

This is further complicated by a) async nature of the uninstaller (it
spawns a helper process to remove its own executable, so it is not
sufficient to wait until the process) and b) unfortunate behavior of
Poedit's uninstaller, which removes even HKCU user settings. This was
fixed recently (see 2c1e41c), but it still needs to be handled for
old installs.

Handle both of these complications with a small helper DLL that launches
the uninstaller in a safe manner.
  • Loading branch information
vslavik committed Jan 17, 2024
1 parent e9b3062 commit 94204f7
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ xcuserdata

/packages/
/win32/distrib-*
/win32/uninst-helper.dll

/*.snap
/poedit_source.tar.bz2
Expand Down
2 changes: 2 additions & 0 deletions Poedit.vcxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="packages\Tools.InnoSetup.6.2.2\build\Tools.InnoSetup.props" Condition="Exists('packages\Tools.InnoSetup.6.2.2\build\Tools.InnoSetup.props')" />
<Import Project="packages\Gettext.Tools.0.22.3\build\Gettext.Tools.props" Condition="Exists('packages\Gettext.Tools.0.22.3\build\Gettext.Tools.props')" />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
Expand Down Expand Up @@ -357,5 +358,6 @@
<Error Condition="!Exists('packages\MSBuildTasks.1.5.0.196\build\MSBuildTasks.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\MSBuildTasks.1.5.0.196\build\MSBuildTasks.targets'))" />
<Error Condition="!Exists('packages\WinSparkle.0.8.0\build\native\WinSparkle.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\WinSparkle.0.8.0\build\native\WinSparkle.targets'))" />
<Error Condition="!Exists('packages\Gettext.Tools.0.22.3\build\Gettext.Tools.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Gettext.Tools.0.22.3\build\Gettext.Tools.props'))" />
<Error Condition="!Exists('packages\Tools.InnoSetup.6.2.2\build\Tools.InnoSetup.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Tools.InnoSetup.6.2.2\build\Tools.InnoSetup.props'))" />
</Target>
</Project>
1 change: 1 addition & 0 deletions packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<package id="Gettext.Tools" version="0.22.3" targetFramework="native" />
<package id="Microsoft.Web.WebView2" version="1.0.1661.34" targetFramework="native" />
<package id="MSBuildTasks" version="1.5.0.196" targetFramework="native" developmentDependency="true" />
<package id="Tools.InnoSetup" version="6.2.2" targetFramework="native" />
<package id="WinSparkle" version="0.8.0" targetFramework="native" />
</packages>
73 changes: 73 additions & 0 deletions win32/distrib.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
ToolsVersion="4.0"
InitialTargets="SetupOutputDir"
DefaultTargets="Distrib">

<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Common.props" />

<Import Project="version.props" />

<PropertyGroup>
<MSBuildCommunityTasksPath>$(MSBuildProjectDirectory)\..\packages\MSBuildTasks.1.5.0.235\tools</MSBuildCommunityTasksPath>
</PropertyGroup>
<Import Project="$(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.targets"/>

<PropertyGroup>
<BinDir>../x64/$(Configuration)</BinDir>
<MsvcToolsX86>"$(VCToolsInstallDir)\bin\HostX64\x86"</MsvcToolsX86>
<MsvcLibpathX86>"$(VCToolsInstallDir)\lib\x86"</MsvcLibpathX86>
<InnoCC>..\packages\Tools.InnoSetup.6.2.2\tools\ISCC.exe</InnoCC>
<InnoFlags>/dCONFIG=$(Configuration)</InnoFlags>
</PropertyGroup>

<ItemGroup>
<PdbFiles Include="$(BinDir)/*.pdb" Exclude="$(BinDir)/vc1*.pdb" />
</ItemGroup>

<Target Name="SetupOutputDir" BeforeTargets="PDBs;Distrib;Installer">
<GitCommits>
<Output TaskParameter="CommitsCount" PropertyName="GitBuildNumber" />
</GitCommits>
<CreateProperty Value="distrib-$(Configuration)-$(PoeditVersion).$(GitBuildNumber)">
<Output TaskParameter="Value" PropertyName="OutputDir"/>
</CreateProperty>
</Target>

<Target Name="Distrib" DependsOnTargets="$(BuildDependsOn);Build;Installer;PDBs">
<Message Importance="High" Text="Copying debug symbols..." />
</Target>

<Target Name="Installer" DependsOnTargets="Build;UninstHelper">
<Message Importance="High" Text="Creating InnoSetup installer..." />
<Exec Command="$(InnoCC) /O$(OutputDir) $(InnoFlags) poedit.iss " />
</Target>

<Target Name="Build">
<MSBuild
Projects="..\Poedit.sln"
Properties="Configuration=$(Configuration)"
/>
</Target>

<Target Name="UninstHelper" Inputs="uninst-helper.c" Outputs="uninst-helper.dll">
<!-- the helper needs to be compiled as 32bit: -->
<PropertyGroup>
<HelperCompileCmd>
call "$(VCINSTALLDIR)\Auxiliary\Build\vcvarsall.bat" x64_x86 || exit /b 666
cl /LD /O1 /MT /W3 uninst-helper.c || exit /b 666
</HelperCompileCmd>
</PropertyGroup>
<WriteLinesToFile File="uninst-helper.bat" Lines="$(HelperCompileCmd)" Overwrite="true" />
<Exec Command="uninst-helper.bat" />
<Delete Files="uninst-helper.bat;uninst-helper.exp;uninst-helper.lib;uninst-helper.obj" />
</Target>

<Target Name="PDBs" DependsOnTargets="Build">
<Message Importance="High" Text="Copying debug symbols..." />
<MakeDir Directories="$(OutputDir)\pdb" />
<Copy SourceFiles="@(PdbFiles)" DestinationFolder="$(OutputDir)\pdb" SkipUnchangedFiles="true" />
</Target>

</Project>
51 changes: 50 additions & 1 deletion win32/poedit.iss
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#define VERSION "3.4.2"
#define VERSION_WIN VERSION + "." + Str(POEDIT_GIT_BUILD_NUMBER)

#define APP_ID "{68EB2C37-083A-4303-B5D8-41FA67E50B8F}"

#ifndef CRT_REDIST
#define CRT_REDIST GetEnv("VCToolsRedistDir") + "\x64\Microsoft.VC143.CRT"
#endif
Expand Down Expand Up @@ -70,7 +72,7 @@ ShowLanguageDialog=no
DisableWelcomePage=true
AllowUNCPath=true
InternalCompressLevel=ultra
AppID={{68EB2C37-083A-4303-B5D8-41FA67E50B8F}
AppID={{#APP_ID}
VersionInfoVersion={#VERSION_WIN}
VersionInfoTextVersion={#VERSION}
AppCopyright=Copyright © 1999-2023 Vaclav Slavik
Expand Down Expand Up @@ -99,6 +101,7 @@ VersionInfoProductTextVersion={#VERSION}
DisableDirPage=auto

[Files]
Source: win32\uninst-helper.dll; Flags: dontcopy
Source: {#BINDIR}\Poedit.exe; DestDir: {app}; Flags: ignoreversion
Source: {#BINDIR}\*.dll; DestDir: {app}; Flags: ignoreversion
Source: {#BINDIR}\icudt*.dat; DestDir: {app}
Expand Down Expand Up @@ -209,6 +212,7 @@ Name: "ukrainian"; MessagesFile: "compiler:Languages\Ukrainian.isl"

[CustomMessages]
OpenAfterInstall=Open Poedit after installation
Uninstall32bit=Uninstalling 32-bit version of Poedit...
brazilianportuguese.OpenAfterInstall=Abrir o Poedit após a instalação
catalan.OpenAfterInstall=Obre el Poedit després de la instal·lació
corsican.OpenAfterInstall=Apre Poedit dopu à l'installazione
Expand All @@ -229,3 +233,48 @@ slovenian.OpenAfterInstall=Odpri Poedit po namestitvi
spanish.OpenAfterInstall=Abrir Poedit tras la instalación
turkish.OpenAfterInstall=Kurulumdan sonra Poedit'i aç
ukrainian.OpenAfterInstall=Відкрити Poedit після встановлення

[Code]
const UninstallKey = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#APP_ID}_is1';
function SafelyUninstall32BitVersion(uninstallerExe: String): Integer;
external 'SafelyUninstall32BitVersion@files:uninst-helper.dll cdecl setuponly';
function Find32bitUninstallerPath(): String;
var
uninst: String;
begin
if (not RegKeyExists(HKCU64, UninstallKey)) and (not RegKeyExists(HKLM64, UninstallKey)) and RegKeyExists(HKLM32, UninstallKey) then
begin
RegQueryStringValue(HKLM32, UninstallKey, 'UninstallString', uninst);
Result := RemoveQuotes(uninst);
end
else
Result := '';
end;
procedure Uninstall32bitVersionIfPresent;
var
uninstaller: String;
begin
uninstaller := Find32bitUninstallerPath();
if (uninstaller <> '') then
begin
Log('Migrating from 32bit install, uninstalling via ' + uninstaller);
WizardForm.StatusLabel.Caption := CustomMessage('Uninstall32bit');
SafelyUninstall32BitVersion(uninstaller);
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if (CurStep = ssInstall) then
begin
Uninstall32bitVersionIfPresent();
end;
end;
Binary file added win32/uninst-helper.c
Binary file not shown.

0 comments on commit 94204f7

Please sign in to comment.