Skip to content

Commit cfa17e7

Browse files
committed
fix(installer): Best-effort attempt to keep autostart settings on initial v2 migration
The v1 uninstaller tries to remove autostart entries, but the appdata restore doesn't restore those entries. While restoring all is infeasible, do a best effort to restore the autostart setting of the current user performing the upgrade.
1 parent 0b4bf1c commit cfa17e7

1 file changed

Lines changed: 63 additions & 2 deletions

File tree

installer/common.iss

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,67 @@ var
8282
OldUninstString : string;
8383
OldInstallDir : string;
8484
BackupDir : string;
85+
BackupAutostartValue: string;
86+
BackupAutostartExists: Boolean;
8587
8688
InfoPage : TWizardPage;
8789
PgLabel : TNewStaticText;
8890
PgCheckbox : TNewCheckBox;
8991
92+
// -------------------------------------------------------------------
93+
// AUTOSTART REGISTRY BACKUP ----------------------------------------
94+
// -------------------------------------------------------------------
95+
function BackupAutostartRegistry(): Boolean;
96+
var
97+
RegValue: string;
98+
begin
99+
Result := False;
100+
BackupAutostartExists := False;
101+
BackupAutostartValue := '';
102+
103+
if RegQueryStringValue(HKEY_CURRENT_USER, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run', 'SyncTrayzor', RegValue) then
104+
begin
105+
BackupAutostartExists := True;
106+
BackupAutostartValue := RegValue;
107+
Result := True;
108+
Log('Backed up autostart registry: ' + RegValue);
109+
end
110+
else
111+
begin
112+
Log('No autostart registry entry found to backup');
113+
end;
114+
end;
115+
116+
procedure RestoreAutostartRegistry();
117+
var
118+
NewValue: string;
119+
HasMinimized: Boolean;
120+
begin
121+
if not BackupAutostartExists then
122+
begin
123+
Log('No autostart registry to restore');
124+
Exit;
125+
end;
126+
127+
// Check if the old value contained -minimized
128+
HasMinimized := Pos('-minimized', BackupAutostartValue) > 0;
129+
130+
// Build new registry value with current install path
131+
NewValue := '"' + ExpandConstant('{app}\{#AppExeName}') + '"';
132+
if HasMinimized then
133+
NewValue := NewValue + ' -minimized';
134+
135+
// Write the new autostart registry entry
136+
if RegWriteStringValue(HKEY_CURRENT_USER, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run', 'SyncTrayzor', NewValue) then
137+
begin
138+
Log('Restored autostart registry: ' + NewValue);
139+
end
140+
else
141+
begin
142+
Log('Failed to restore autostart registry');
143+
end;
144+
end;
145+
90146
procedure BumpInstallCount;
91147
var
92148
FileContents: AnsiString;
@@ -145,6 +201,8 @@ begin
145201
end
146202
else if CurStep = ssPostInstall then
147203
begin
204+
if OldVersionDetected then
205+
RestoreAutostartRegistry();
148206
ExeConfig := ExpandConstant('{param:SyncTrayzorExeConfig}');
149207
if ExeConfig <> '' then
150208
begin
@@ -367,7 +425,10 @@ begin
367425
begin
368426
// 1) Backup
369427
if not PgCheckbox.Checked then
428+
begin
370429
BackupAppData();
430+
BackupAutostartRegistry();
431+
end;
371432
372433
// 2) Run uninstaller
373434
if (Exec('>', OldUninstString, '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode)) then
@@ -379,8 +440,8 @@ begin
379440
else
380441
begin
381442
MsgBox('Could not launch the previous uninstaller (' +
382-
OldUninstString + '): ' + SysErrorMessage(ResultCode) + '.'#13#10'Setup cannot continue.',
383-
mbError, MB_OK);
443+
OldUninstString + '): ' + SysErrorMessage(ResultCode) + '.'#13#10'Setup cannot continue.',
444+
mbError, MB_OK);
384445
Result := False; // stay on page
385446
end;
386447
end;

0 commit comments

Comments
 (0)