Skip to content

Commit 0f9de3d

Browse files
committed
fix installers #3
1 parent 37cd50b commit 0f9de3d

File tree

4 files changed

+35
-86
lines changed

4 files changed

+35
-86
lines changed

.github/workflows/build-macos-arm-installer.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,6 @@ jobs:
187187
# Create config directory in user's Application Support
188188
mkdir -p "$HOME/Library/Application Support/Cleanuparr"
189189
190-
# Create sample configuration if it doesn't exist
191-
if [ ! -f "$HOME/Library/Application Support/Cleanuparr/cleanuparr.json" ]; then
192-
cp "/Applications/Cleanuparr.app/Contents/Resources/cleanuparr.json" "$HOME/Library/Application Support/Cleanuparr/"
193-
fi
194-
195190
# Set permissions
196191
chmod -R 755 "$HOME/Library/Application Support/Cleanuparr"
197192

.github/workflows/build-macos-intel-installer.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,6 @@ jobs:
187187
# Create config directory in user's Application Support
188188
mkdir -p "$HOME/Library/Application Support/Cleanuparr"
189189
190-
# Create sample configuration if it doesn't exist
191-
if [ ! -f "$HOME/Library/Application Support/Cleanuparr/cleanuparr.json" ]; then
192-
cp "/Applications/Cleanuparr.app/Contents/Resources/config/cleanuparr.json" "$HOME/Library/Application Support/Cleanuparr/"
193-
fi
194-
195190
# Set permissions
196191
chmod -R 755 "$HOME/Library/Application Support/Cleanuparr"
197192

code/backend/Cleanuparr.Api/Cleanuparr.Api.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
<TargetFramework>net9.0</TargetFramework>
77
<Nullable>enable</Nullable>
88
<ImplicitUsings>enable</ImplicitUsings>
9+
<PublishReadyToRun>true</PublishReadyToRun>
10+
<EnableMacOSCodeSign>false</EnableMacOSCodeSign>
911
</PropertyGroup>
1012

1113
<ItemGroup>

installers/windows/cleanuparr-installer.iss

Lines changed: 33 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ Name: "installservice"; Description: "Install as Windows Service (Recommended)";
4242
[Files]
4343
Source: "dist\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
4444
Source: "Logo\favicon.ico"; DestDir: "{app}"; Flags: ignoreversion
45-
; Note: Application will create its own configuration files
4645

4746
[Dirs]
4847
Name: "{app}\config"; Permissions: everyone-full
@@ -53,18 +52,14 @@ Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
5352
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename: "{app}\favicon.ico"; Tasks: desktopicon
5453

5554
[Run]
56-
; For fresh installs only - create and start service
55+
; Create service only if it doesn't exist (fresh install)
5756
Filename: "{sys}\sc.exe"; Parameters: "create ""{#MyServiceName}"" binPath= ""\""{app}\{#MyAppExeName}\"""" DisplayName= ""{#MyAppName}"" start= auto"; Tasks: installservice; Flags: runhidden; Check: not ServiceExists('{#MyServiceName}')
5857
Filename: "{sys}\sc.exe"; Parameters: "description ""{#MyServiceName}"" ""Cleanuparr download management service"""; Tasks: installservice; Flags: runhidden; Check: not ServiceExists('{#MyServiceName}')
5958

60-
; For updates - stop service if running, wait for complete shutdown, then restart
61-
Filename: "{sys}\sc.exe"; Parameters: "stop ""{#MyServiceName}"""; Flags: runhidden; Check: ServiceExists('{#MyServiceName}') and IsServiceRunning('{#MyServiceName}') and IsTaskSelected('installservice')
62-
Filename: "{sys}\sc.exe"; Parameters: "start ""{#MyServiceName}"""; Tasks: installservice; Flags: runhidden; Check: ServiceExists('{#MyServiceName}') and ServiceExistedBefore
59+
; Start service (both fresh install and update)
60+
Filename: "{sys}\sc.exe"; Parameters: "start ""{#MyServiceName}"""; Tasks: installservice; Flags: runhidden
6361

64-
; For fresh installs - start the newly created service
65-
Filename: "{sys}\sc.exe"; Parameters: "start ""{#MyServiceName}"""; Tasks: installservice; Flags: runhidden; Check: not ServiceExistedBefore
66-
67-
; Open web interface (only if service is selected)
62+
; Open web interface
6863
Filename: "http://localhost:11011"; Description: "Open Cleanuparr Web Interface"; Flags: postinstall shellexec nowait; Check: IsTaskSelected('installservice')
6964

7065
; Run directly (if not installed as service)
@@ -76,15 +71,6 @@ Filename: "{sys}\timeout.exe"; Parameters: "/t 5"; Flags: runhidden; Check: Serv
7671
Filename: "{sys}\sc.exe"; Parameters: "delete ""{#MyServiceName}"""; Flags: runhidden; Check: ServiceExists('{#MyServiceName}')
7772

7873
[Code]
79-
var
80-
ServiceExistedBefore: Boolean;
81-
82-
procedure CreateConfigDirs;
83-
begin
84-
// Create config directory - application will create its own config files
85-
ForceDirectories(ExpandConstant('{app}\config'));
86-
end;
87-
8874
function ServiceExists(ServiceName: string): Boolean;
8975
var
9076
ResultCode: Integer;
@@ -95,119 +81,90 @@ end;
9581
function IsServiceRunning(ServiceName: string): Boolean;
9682
var
9783
ResultCode: Integer;
98-
Output: AnsiString;
99-
OutputFile: string;
84+
TempFile: string;
85+
StatusOutput: AnsiString;
10086
begin
10187
Result := False;
102-
OutputFile := ExpandConstant('{tmp}\service_status.txt');
88+
TempFile := ExpandConstant('{tmp}\service_status.txt');
10389
104-
// Query service status and capture output
105-
if Exec(ExpandConstant('{sys}\sc.exe'), 'query "' + ServiceName + '"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) and (ResultCode = 0) then
90+
// Use PowerShell to get service status
91+
if Exec(ExpandConstant('{sys}\WindowsPowerShell\v1.0\powershell.exe'),
92+
'-Command "try { (Get-Service -Name ''' + ServiceName + ''' -ErrorAction Stop).Status } catch { ''NotFound'' }" > "' + TempFile + '"',
93+
'', SW_HIDE, ewWaitUntilTerminated, ResultCode) and (ResultCode = 0) then
10694
begin
107-
// Use PowerShell to get service status more reliably
108-
if Exec(ExpandConstant('{sys}\WindowsPowerShell\v1.0\powershell.exe'),
109-
'-Command "& {(Get-Service -Name ''' + ServiceName + ''' -ErrorAction SilentlyContinue).Status}"',
110-
'', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
95+
if LoadStringFromFile(TempFile, StatusOutput) then
11196
begin
112-
// If we can't determine status precisely, assume it might be running to be safe
113-
Result := True;
97+
Result := (Pos('Running', StatusOutput) > 0);
11498
end;
99+
DeleteFile(TempFile);
115100
end;
116101
end;
117102
118-
function WaitForServiceStop(ServiceName: string): Boolean;
103+
function WaitForServiceStop(ServiceName: string; TimeoutSeconds: Integer): Boolean;
119104
var
120105
Counter: Integer;
121-
ResultCode: Integer;
122-
StatusOutput: AnsiString;
123-
TempFile: string;
124106
begin
125107
Result := True;
126108
Counter := 0;
127-
TempFile := ExpandConstant('{tmp}\service_check.txt');
128109
129-
// Wait up to 30 seconds for service to stop
130-
while Counter < 30 do
110+
while Counter < TimeoutSeconds do
131111
begin
132-
// Check service status using PowerShell for more reliable output
133-
if Exec(ExpandConstant('{sys}\WindowsPowerShell\v1.0\powershell.exe'),
134-
'-Command "& {try { $s = Get-Service -Name ''' + ServiceName + ''' -ErrorAction Stop; $s.Status } catch { ''NotFound'' }}" > "' + TempFile + '"',
135-
'', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
136-
begin
137-
if LoadStringFromFile(TempFile, StatusOutput) then
138-
begin
139-
// If service is stopped or not found, we're good
140-
if (Pos('Stopped', StatusOutput) > 0) or (Pos('NotFound', StatusOutput) > 0) then
141-
begin
142-
DeleteFile(TempFile);
143-
Exit;
144-
end;
145-
end;
146-
end;
147-
112+
if not IsServiceRunning(ServiceName) then
113+
Exit;
148114
Sleep(1000);
149115
Counter := Counter + 1;
150116
end;
151117
152-
// Cleanup temp file
153-
DeleteFile(TempFile);
154-
155-
// If we get here, service didn't stop in time
156-
if Counter >= 30 then
157-
begin
158-
MsgBox('Warning: Service took longer than expected to stop. Installation will continue but the service may need to be restarted manually.',
159-
mbInformation, MB_OK);
160-
Result := False;
161-
end;
118+
Result := False;
162119
end;
163120
164121
function InitializeSetup(): Boolean;
165122
var
166123
ResultCode: Integer;
167124
begin
168-
// Remember if service existed before installation
169-
ServiceExistedBefore := ServiceExists('{#MyServiceName}');
125+
Result := True;
170126
171-
// Only stop service if it exists and is running
172-
if ServiceExistedBefore and IsServiceRunning('{#MyServiceName}') then
127+
// If service exists and is running, stop it for the update
128+
if ServiceExists('{#MyServiceName}') and IsServiceRunning('{#MyServiceName}') then
173129
begin
174130
if MsgBox('Cleanuparr service is currently running and needs to be stopped for the installation. Continue?',
175131
mbConfirmation, MB_YESNO) = IDYES then
176132
begin
177133
Exec(ExpandConstant('{sys}\sc.exe'), 'stop "{#MyServiceName}"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
178-
if not WaitForServiceStop('{#MyServiceName}') then
134+
135+
if not WaitForServiceStop('{#MyServiceName}', 30) then
179136
begin
180-
// Service didn't stop properly, but continue anyway
181-
Log('Warning: Service did not stop cleanly, continuing with installation');
137+
MsgBox('Warning: Service took longer than expected to stop. Installation will continue but you may need to restart the service manually.',
138+
mbInformation, MB_OK);
182139
end;
183140
end
184141
else
185142
begin
186143
Result := False;
187-
Exit;
188144
end;
189145
end;
190-
191-
Result := True;
192146
end;
193147
194148
function InitializeUninstall(): Boolean;
195149
var
196150
ResultCode: Integer;
197151
begin
152+
Result := True;
153+
198154
if ServiceExists('{#MyServiceName}') then
199155
begin
200156
if MsgBox('Cleanuparr service will be stopped and removed. Continue with uninstallation?',
201157
mbConfirmation, MB_YESNO) = IDYES then
202158
begin
203-
Exec(ExpandConstant('{sys}\sc.exe'), 'stop "{#MyServiceName}"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
204-
WaitForServiceStop('{#MyServiceName}');
159+
if IsServiceRunning('{#MyServiceName}') then
160+
begin
161+
Exec(ExpandConstant('{sys}\sc.exe'), 'stop "{#MyServiceName}"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
162+
WaitForServiceStop('{#MyServiceName}', 30);
163+
end;
205164
end
206165
else
207166
begin
208167
Result := False;
209-
Exit;
210168
end;
211169
end;
212-
Result := True;
213170
end;

0 commit comments

Comments
 (0)