-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle 32bit to 64bit updates in Windows installer
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
Showing
6 changed files
with
220 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ xcuserdata | |
|
||
/packages/ | ||
/win32/distrib-* | ||
/win32/uninst-helper.dll | ||
|
||
/*.snap | ||
/poedit_source.tar.bz2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* This file is part of Poedit (https://poedit.net) | ||
* | ||
* Copyright (C) 2024 Vaclav Slavik | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
#ifndef _M_IX86 | ||
#error This file must be compiled for 32bit x86 target | ||
#endif | ||
|
||
// This DLL is used by the uninstaller to remove Poedit's 32bit version during upgrades. | ||
// | ||
// Inno Setup treats 64bit and 32bit versions as separate applications, so it can't | ||
// upgrade existing install seamlessly; we need to remove the old version first. | ||
// | ||
// Unfortunately, the installer for older versions of Poedit uninstalled HKCU registry | ||
// keys, i.e. deleted user settings; that wouldn't be good during a simple upgrade. | ||
// Hence this DLL: it is loaded by the uninstaller and it removes the old version, | ||
// while taking care to preserve user settings. | ||
|
||
#define UNICODE | ||
#include <windows.h> | ||
#pragma comment(lib, "advapi32.lib") | ||
|
||
|
||
__declspec(dllexport) int SafelyUninstall32BitVersion(LPCWSTR uninstallerExe) | ||
{ | ||
// check if the uninstaller file exists: | ||
if (GetFileAttributesW(uninstallerExe) == INVALID_FILE_ATTRIBUTES) | ||
return 0; | ||
|
||
// rename the HKCU\Software\Vaclav Slavik\Poedit key to *.backup: | ||
HKEY key = 0; | ||
if (SUCCEEDED(RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Vaclav Slavik\\Poedit", 0, KEY_ALL_ACCESS, &key))) | ||
{ | ||
if (FAILED(RegRenameKey(key, NULL, L"Poedit.backup"))) | ||
{ | ||
RegCloseKey(key); | ||
key = 0; | ||
} | ||
} | ||
|
||
// run the uninstaller: | ||
wchar_t cmdline[10240]; | ||
wcscpy_s(cmdline, 10240, uninstallerExe); | ||
wcscat_s(cmdline, 10240, L" /VERYSILENT /SUPPRESSMSGBOXES /NORESTART"); | ||
|
||
STARTUPINFOW si = { sizeof(si) }; | ||
PROCESS_INFORMATION pi; | ||
if (CreateProcessW(uninstallerExe, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) | ||
{ | ||
WaitForSingleObject(pi.hProcess, INFINITE); | ||
CloseHandle(pi.hProcess); | ||
CloseHandle(pi.hThread); | ||
} | ||
|
||
// Inno Setup's uninstaller spawns a subprocess in order to be able to delete itself, so wait until | ||
// the uninstaller is removed (or 60 seconds pass, whichever comes first): | ||
for (int i = 0; i < 600; i++) | ||
{ | ||
if (GetFileAttributesW(uninstallerExe) == INVALID_FILE_ATTRIBUTES) | ||
break; | ||
Sleep(100); | ||
} | ||
|
||
// rename the backup key back: | ||
if (key) | ||
{ | ||
RegRenameKey(key, NULL, L"Poedit"); | ||
RegCloseKey(key); | ||
} | ||
|
||
return 1; | ||
} |