common.iss 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. #define AppExeName "SyncTrayzor.exe"
  2. #define AppRoot "..\.."
  3. #define AppSrc AppRoot + "\src\SyncTrayzor"
  4. #define AppBin AppRoot +"\bin\" + Arch + "\Release"
  5. #define AppExe AppBin + "\SyncTrayzor.exe"
  6. #define AppName GetStringFileInfo(AppExe, "ProductName")
  7. #define AppVersion GetVersionNumbersString(AppExe)
  8. #define AppPublisher "SyncTrayzor"
  9. #define AppURL "https://github.com/canton7/SyncTrayzor"
  10. #define AppDataFolder "SyncTrayzor"
  11. #define RunRegKey "Software\Microsoft\Windows\CurrentVersion\Run"
  12. #define DotNetInstallerExe "dotNet472Setup.exe"
  13. #define DonateUrl "https://synctrayzor.antonymale.co.uk/donate"
  14. [Setup]
  15. AppId={{#AppId}
  16. AppName={#AppName} ({#Arch})
  17. AppVersion={#AppVersion}
  18. VersionInfoVersion={#AppVersion}
  19. ;AppVerName={#AppName} {#AppVersion}
  20. AppPublisher={#AppPublisher}
  21. AppPublisherURL={#AppURL}
  22. AppSupportURL={#AppURL}
  23. AppUpdatesURL={#AppURL}
  24. DefaultDirName={commonpf}\{#AppName}
  25. DefaultGroupName={#AppName}
  26. AllowNoIcons=yes
  27. LicenseFile={#AppRoot}\LICENSE.txt
  28. OutputDir="."
  29. OutputBaseFilename={#AppName}Setup-{#Arch}
  30. SetupIconFile={#AppSrc}\Icons\default.ico
  31. WizardSmallImageFile=..\icon.bmp
  32. Compression=lzma2/max
  33. ;Compression=None
  34. SolidCompression=yes
  35. PrivilegesRequired=admin
  36. CloseApplications=yes
  37. RestartApplications=no
  38. ; If we try and close CefSharp.BrowserSubprocess.exe we'll fail - it doesn't respond well
  39. ; However if we close *just* SyncTrayzor, that will take care of shutting down CefSharp and syncthing
  40. CloseApplicationsFilter=SyncTrayzor.exe
  41. TouchDate=current
  42. #if "x64" == Arch
  43. ArchitecturesInstallIn64BitMode=x64
  44. ArchitecturesAllowed=x64
  45. #endif
  46. [Languages]
  47. Name: "english"; MessagesFile: "compiler:Default.isl"
  48. [CustomMessages]
  49. InstallingDotNetFramework=Installing .NET Framework. This might take a few minutes...
  50. DotNetFrameworkFailedToLaunch=Failed to launch .NET Framework Installer with error "%1". Please fix the error then run this installer again.
  51. DotNetFrameworkFailed1602=.NET Framework installation was cancelled. This installation can continue, but be aware that this application may not run unless the .NET Framework installation is completed successfully.
  52. DotNetFrameworkFailed1603=A fatal error occurred while installing the .NET Framework. Please fix the error, then run the installer again.
  53. DotNetFrameworkFailed5100=Your computer does not meet the requirements of the .NET Framework. Please consult the documentation.
  54. DotNetFrameworkFailedOther=The .NET Framework installer exited with an unexpected status code "%1". Please review any other messages shown by the installer to determine whether the installation completed successfully, and abort this installation and fix the problem if it did not.
  55. [Tasks]
  56. Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
  57. [Dirs]
  58. Name: "{userappdata}\{#AppDataFolder}"
  59. [Files]
  60. ; Near the beginning, as it's extracted first and this makes it cheaper
  61. Source: "..\{#DotNetInstallerExe}"; DestDir: {tmp}; Flags: dontcopy nocompression noencryption
  62. Source: "{#AppBin}\*"; DestDir: "{app}"; Excludes: "*.xml,*.vshost.*,*.config,*.log,FluentValidation.resources.dll,System.Windows.Interactivity.resources.dll,syncthing.exe,data,logs,cef_extensions.pak,d3dcompiler_47.dll,libEGL.dll,libGLESv2.dll,swiftshader/libEGL.dll,swiftshader/libGLESv2.dll"; Flags: ignoreversion recursesubdirs
  63. Source: "{#AppBin}\SyncTrayzor.exe.Installer.config"; DestDir: "{app}"; DestName: "SyncTrayzor.exe.config"; Flags: ignoreversion
  64. Source: "{#AppSrc}\Icons\default.ico"; DestDir: "{app}"; Flags: ignoreversion
  65. Source: "{#AppRoot}\*.md"; DestDir: "{app}"; Flags: ignoreversion
  66. Source: "{#AppRoot}\*.txt"; DestDir: "{app}"; Flags: ignoreversion
  67. Source: "ucrt\*.dll"; DestDir: "{app}"; Flags: ignoreversion; OnlyBelowVersion: 10.0
  68. Source: "syncthing.exe"; DestDir: "{app}"; DestName: "syncthing.exe"; Flags: ignoreversion
  69. [Icons]
  70. Name: "{group}\{#AppName}"; Filename: "{app}\{#AppExeName}"
  71. Name: "{group}\{cm:UninstallProgram,{#AppName}}"; Filename: "{uninstallexe}"
  72. Name: "{commondesktop}\{#AppName}"; Filename: "{app}\{#AppExeName}"; Tasks: desktopicon
  73. [Run]
  74. Filename: "{app}\{#AppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(AppName, '&', '&&')}}"; Flags: nowait postinstall; Parameters: {code:SyncTrayzorStartFlags}; Check: ShouldStartSyncTrayzor
  75. [Code]
  76. var
  77. GlobalRestartRequired: boolean;
  78. function DotNetIsMissing(): Boolean;
  79. var
  80. Exists: Boolean;
  81. Release: Cardinal;
  82. begin
  83. // https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed#minimum-version
  84. Exists := RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full', 'Release', Release);
  85. Result := not Exists or (Release < 461808);
  86. end;
  87. // Adapted from https://blogs.msdn.microsoft.com/davidrickard/2015/07/17/installing-net-framework-4-5-automatically-with-inno-setup/
  88. function InstallDotNet(): String;
  89. var
  90. StatusText: string;
  91. ResultCode: Integer;
  92. begin
  93. StatusText := WizardForm.StatusLabel.Caption;
  94. WizardForm.StatusLabel.Caption := CustomMessage('InstallingDotNetFramework');
  95. WizardForm.ProgressGauge.Style := npbstMarquee;
  96. try
  97. ExtractTemporaryFile('{#DotNetInstallerExe}');
  98. if not Exec(ExpandConstant('{tmp}\{#DotNetInstallerExe}'), '/passive /norestart /showrmui /showfinalerror', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
  99. begin
  100. Result := FmtMessage(CustomMessage('DotNetFrameworkFailedToLaunch'), [SysErrorMessage(ResultCode)]);
  101. end
  102. else
  103. begin
  104. // See https://msdn.microsoft.com/en-us/library/ee942965(v=vs.110).aspx#return_codes
  105. case resultCode of
  106. 0: begin
  107. // Successful
  108. end;
  109. 1602 : begin
  110. MsgBox(CustomMessage('DotNetFrameworkFailed1602'), mbInformation, MB_OK);
  111. end;
  112. 1603: begin
  113. Result := CustomMessage('DotNetFrameworkFailed1603');
  114. end;
  115. 1641: begin
  116. GlobalRestartRequired := True;
  117. end;
  118. 3010: begin
  119. GlobalRestartRequired := True;
  120. end;
  121. 5100: begin
  122. Result := CustomMessage('DotNetFrameworkFailed5100');
  123. end;
  124. else begin
  125. MsgBox(FmtMessage(CustomMessage('DotNetFrameworkFailedOther'), [IntToStr(ResultCode)]), mbError, MB_OK);
  126. end;
  127. end;
  128. end;
  129. finally
  130. WizardForm.StatusLabel.Caption := StatusText;
  131. WizardForm.ProgressGauge.Style := npbstNormal;
  132. end;
  133. end;
  134. procedure BumpInstallCount;
  135. var
  136. FileContents: AnsiString;
  137. InstallCount: integer;
  138. begin
  139. { Increment the install count in InstallCount.txt if it exists, or create it with the contents '1' if it doesn't }
  140. if LoadStringFromFile(ExpandConstant('{app}\InstallCount.txt'), FileContents) then
  141. begin
  142. InstallCount := StrTointDef(Trim(string(FileContents)), 0) + 1;
  143. end
  144. else
  145. begin
  146. InstallCount := 1;
  147. end;
  148. SaveStringToFile(ExpandConstant('{app}\InstallCount.txt'), IntToStr(InstallCount), False);
  149. end;
  150. procedure URLLabelOnClick(Sender: TObject);
  151. var
  152. ErrorCode: Integer;
  153. begin
  154. ShellExec('open', '{#DonateUrl}', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
  155. end;
  156. procedure InitializeWizard;
  157. var
  158. URLLabel: TNewStaticText;
  159. begin
  160. URLLabel := TNewStaticText.Create(WizardForm);
  161. URLLabel.Caption := 'Donate';
  162. URLLabel.Cursor := crHand;
  163. URLLabel.Parent := WizardForm;
  164. URLLabel.Font.Style := URLLabel.Font.Style + [fsUnderline];
  165. URLLabel.Font.Color := clBlue;
  166. URLLabel.Top := WizardForm.ClientHeight - URLLabel.Height - 15;
  167. URLLabel.Left := ScaleX(10)
  168. URLLabel.OnClick := @URLLabelOnClick;
  169. end;
  170. procedure CurStepChanged(CurStep: TSetupStep);
  171. var
  172. FindRec: TFindRec;
  173. FolderPath: String;
  174. FilePath: String;
  175. ExeConfig: String;
  176. begin
  177. if CurStep = ssInstall then
  178. begin
  179. BumpInstallCount();
  180. { We might be being run from ProcessRunner.exe, *and* we might be trying to update it. Funsies. Let's rename it (which Windows lets us do) }
  181. DeleteFile(ExpandConstant('{app}\ProcessRunner.exe.old'));
  182. RenameFile(ExpandConstant('{app}\ProcessRunner.exe'), ExpandConstant('{app}\ProcessRunner.exe.old'));
  183. Log(ExpandConstant('Looking for resource files in {app}\*'));
  184. { Remove resource files. This means that out-of-date languages will be removed, which (as a last-ditch resore) will alert maintainers that something's wrong }
  185. if FindFirst(ExpandConstant('{app}\*'), FindRec) then
  186. begin
  187. try
  188. repeat
  189. if (FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY <> 0) and (FindRec.Name <> '.') and (FindRec.Name <> '..') then
  190. begin
  191. FolderPath := ExpandConstant('{app}\') + FindRec.Name;
  192. FilePath := FolderPath + '\SyncTrayzor.resources.dll';
  193. if DeleteFile(FilePath) then
  194. begin
  195. Log('Deleted ' + FilePath);
  196. if DelTree(FolderPath, True, False, False) then
  197. Log('Deleted ' + FolderPath);
  198. end;
  199. end;
  200. until not FindNext(FindRec);
  201. finally
  202. FindClose(FindRec);
  203. end;
  204. end;
  205. end
  206. else if CurStep = ssPostInstall then
  207. begin
  208. ExeConfig := ExpandConstant('{param:SyncTrayzorExeConfig}');
  209. if ExeConfig <> '' then
  210. begin
  211. if FileExists(ExeConfig) then
  212. begin
  213. FileCopy(ExeConfig, ExpandConstant('{app}\SyncTrayzor.exe.config'), false);
  214. end
  215. else
  216. begin
  217. MsgBox('Could not find SyncTrayzorExeConfig file: ' + ExeConfig + '. Using default.', mbError, MB_OK);
  218. end
  219. end
  220. end
  221. end;
  222. function PrepareToInstall(var NeedsRestart: Boolean): String;
  223. begin
  224. // 'NeedsRestart' only has an effect if we return a non-empty string, thus aborting the installation.
  225. // If the installers indicate that they want a restart, this should be done at the end of installation.
  226. // Therefore we set the global 'restartRequired' if a restart is needed, and return this from NeedRestart()
  227. if DotNetIsMissing() then
  228. begin
  229. Result := InstallDotNet();
  230. end;
  231. end;
  232. function NeedRestart(): Boolean;
  233. begin
  234. Result := GlobalRestartRequired;
  235. end;
  236. function ShouldStartSyncTrayzor(): Boolean;
  237. var
  238. flagPassed: Boolean;
  239. i: Integer;
  240. begin
  241. // Can't use {param}, as it doesn't match flags with no value
  242. flagPassed := False;
  243. for i := 0 to ParamCount do begin
  244. if ParamStr(i) = '/StartSyncTrayzor' then begin
  245. flagPassed := True;
  246. break;
  247. end;
  248. end;
  249. Result := (not WizardSilent()) or flagPassed;
  250. end;
  251. function SyncTrayzorStartFlags(param: String): String;
  252. begin
  253. if WizardSilent() then begin
  254. Result := '-minimized'
  255. end else begin
  256. Result := ''
  257. end;
  258. end;
  259. [UninstallDelete]
  260. Type: files; Name: "{app}\ProcessRunner.exe.old"
  261. Type: files; Name: "{app}\InstallCount.txt"
  262. Type: filesandordirs; Name: "{userappdata}\{#AppDataFolder}"
  263. Type: filesandordirs; Name: "{localappdata}\{#AppDataFolder}"