1+ ; Script generated by the Inno Setup Script Wizard.
2+ ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
3+
4+ #define NSSM " nssm.exe"
5+ #define AmonServiceName " AmonAgent"
6+ #define AmonApp " amon-agent.exe"
7+
8+
9+ [Setup]
10+ ; NOTE: The value of AppId uniquely identifies this application.
11+ ; Do not use the same AppId value in installers for other applications.
12+ ; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
13+ AppId = {{33541FBB-1B7C-4C64-8902 -420ACE513DF9}
14+ AppName = amon-agent
15+ AppVersion = 1.1
16+ ;AppVerName=amon-agent 1.0
17+ AppPublisher = Simplistic LLC
18+ AppPublisherURL = https://amon.cx
19+ AppSupportURL = https://amon.cx
20+ AppUpdatesURL = https://amon.cx
21+ DefaultDirName = {pf} \AmonAgent
22+ DefaultGroupName = amon-agent
23+ OutputBaseFilename = amon-agent-1.1
24+ Compression = lzma
25+ SolidCompression = yes
26+ WizardImageFile = welcome.bmp
27+ DisableDirPage = auto
28+ DisableProgramGroupPage = yes
29+ CloseApplications = yes
30+ RestartApplications = yes
31+ AlwaysRestart = no
32+ UninstallDisplayIcon = {app} \amon-agent.exe
33+ PrivilegesRequired = admin
34+
35+ [Languages]
36+ Name : " english" ; MessagesFile : " compiler:Default.isl"
37+
38+ [Files]
39+ Source : " dist\amon-agent.exe" ; DestDir : " {app} " ; Flags : ignoreversion restartreplace ;
40+ ; NOTE: Don't use "Flags: ignoreversion" on any shared system files
41+ Source : " nssm.exe" ; DestDir : " {app} "
42+ Source : " amon-agent.ini" ; DestDir : " {app} " ; Permissions: everyone-full ;
43+
44+ [INI]
45+ Filename : {app} \amon-agent.ini; Section: Main ; Key: amon_url; String : {code:GetAmonUrl}
46+ Filename : {app} \amon-agent.ini; Section: Main ; Key: server_key; String : {code:GetKey}
47+
48+ [Icons]
49+ Name : " {group} \amon-agent" ; Filename : " {app} \amon-agent.exe"
50+
51+
52+
53+ [Run]
54+ ; post-install
55+ Filename : " {sys} \msiexec.exe" ; Parameters : " /package " " {app} \{#AmonApp}" " /qn /norestart /nocloseapplications /passive" ; Flags : shellexec waituntilterminated ;
56+ Filename : " {sys} \netsh.exe" ; Parameters : " advfirewall firewall add rule name=" " AmonAgent Out" " program=" " {app} \{#AmonApp}" " dir=out action=allow enable=yes" ; Flags : runhidden ;
57+ Filename : " {app} \{#NSSM}" ; Parameters : " install {#AmonServiceName} " " {app} \{#AmonApp}" " " ; Flags : runhidden ;
58+ Filename : " {app} \{#NSSM}" ; Parameters : " set {#AmonServiceName} AppDirectory {app} " ; Flags : runhidden ;
59+ Filename : " {app} \{#NSSM}" ; Parameters : " set {#AmonServiceName} AppStdout {userappdata}\Amon\amon.log" ; Flags : runhidden ;
60+ Filename : " {app} \{#NSSM}" ; Parameters : " set {#AmonServiceName} AppStderr {userappdata}\Amon\amon.log" ; Flags : runhidden ;
61+ Filename : " {app} \{#NSSM}" ; Parameters : " start {#AmonServiceName}" ; Flags : runhidden ;
62+
63+
64+ [UninstallDelete]
65+ Type : filesandordirs ; Name : " {app} "
66+
67+
68+ [UninstallRun]
69+ ; pre-uninstall
70+ Filename : " {app} \{#NSSM}" ; Parameters : " stop {#AmonServiceName}" ; Flags : runhidden ;
71+ Filename : " {app} \{#NSSM}" ; Parameters : " remove {#AmonServiceName} confirm" ; Flags : runhidden ;
72+
73+ [InstallDelete]
74+ Type : files ; Name : " {app} \amon-agent.exe"
75+
76+ [Code]
77+ var
78+ UserPage: TInputQueryWizardPage;
79+
80+ procedure InitializeWizard ;
81+ begin
82+ { Create the pages }
83+ UserPage := CreateInputQueryPage(wpWelcome,
84+ ' Amon Information' , ' ' ,
85+ ' Please specify the URL where your Amon instance is running and the agent server key, then click Next.' );
86+ UserPage.Add(' Amon URL:' , False);
87+ UserPage.Add(' Server Key:' , False);
88+
89+ UserPage.Values[0 ] := GetIniString(' Main' , ' amon_url' , ' ' , WizardDirValue + ' \amon-agent.ini' );
90+ UserPage.Values[1 ] := GetIniString(' Main' , ' server_key' , ' ' , WizardDirValue + ' \amon-agent.ini' );
91+ end ;
92+
93+ function GetAmonUrl (Param: String): string;
94+ begin
95+ result := UserPage.Values[0 ];
96+ end ;
97+
98+ function GetKey (Param: String): string;
99+ begin
100+ result := UserPage.Values[1 ];
101+ end ;
102+
103+
104+ function GetUninstallString : string;
105+ var
106+ sUnInstPath: string;
107+ sUnInstallString: String;
108+ begin
109+ Result := ' ' ;
110+ sUnInstPath := ExpandConstant(' Software\Microsoft\Windows\CurrentVersion\Uninstall\33541FBB-1B7C-4C64-8902-420ACE513DF9_is1' ); // Your App GUID/ID
111+ sUnInstallString := ' ' ;
112+ if not RegQueryStringValue(HKLM, sUnInstPath, ' UninstallString' , sUnInstallString) then
113+ RegQueryStringValue(HKCU, sUnInstPath, ' UninstallString' , sUnInstallString);
114+ Result := sUnInstallString;
115+ end ;
116+
117+ function IsUpgrade : Boolean;
118+ begin
119+ Result := (GetUninstallString() <> ' ' );
120+ end ;
121+
122+ function InitializeSetup : Boolean;
123+ var
124+ V: Integer;
125+ iResultCode: Integer;
126+ sUnInstallString: string;
127+ begin
128+ Result := True; // in case when no previous version is found
129+ if RegValueExists(HKEY_LOCAL_MACHINE,' Software\Microsoft\Windows\CurrentVersion\Uninstall\33541FBB-1B7C-4C64-8902-420ACE513DF9_is1' , ' UninstallString' ) then // Your App GUID/ID
130+ begin
131+ V := MsgBox(ExpandConstant(' An old version of the Amon Agent was detected. Do you want to uninstall it?' ), mbInformation, MB_YESNO); // Custom Message if App installed
132+ if V = IDYES then
133+ begin
134+ sUnInstallString := GetUninstallString();
135+ sUnInstallString := RemoveQuotes(sUnInstallString);
136+ Exec(ExpandConstant(sUnInstallString), ' ' , ' ' , SW_SHOW, ewWaitUntilTerminated, iResultCode);
137+ Result := True; // if you want to proceed after uninstall
138+ // Exit; //if you want to quit after uninstall
139+ end
140+ else
141+ Result := False; // when older version present and not uninstalled
142+ end ;
143+ end ;
0 commit comments