winscpsetup.iss 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492
  1. #define AppId "winscp3"
  2. #define AppMutex "WinSCP"
  3. #define ParentRegistryKey "Software\Martin Prikryl"
  4. #define RegistryKey ParentRegistryKey+"\WinSCP 2"
  5. #define DefaultLang "en"
  6. #define WebRoot "http://winscp.net/"
  7. #define WebForum WebRoot+"forum/"
  8. #define WebDocumentation WebRoot+"eng/docs/"
  9. #define WebReport WebRoot+"install.php"
  10. #define WebPuTTY "http://www.chiark.greenend.org.uk/~sgtatham/putty/"
  11. #define Year 2016
  12. #define EnglishLang "English"
  13. #define SetupTypeData "SetupType"
  14. #define InnoSetupReg "Software\Microsoft\Windows\CurrentVersion\Uninstall\" + AppId + "_is1"
  15. #define InnoSetupAppPathReg "Inno Setup: App Path"
  16. #ifndef CompletenessThreshold
  17. #define CompletenessThreshold 100
  18. #else
  19. #define CompletenessThreshold Int(CompletenessThreshold)
  20. #endif
  21. #ifndef PuttySourceDir
  22. #define PuttySourceDir "c:\Program Files\PuTTY"
  23. #endif
  24. #ifndef Status
  25. #define Status "unofficial"
  26. #endif
  27. #ifndef SourceDir
  28. #define SourceDir "..\source"
  29. #endif
  30. #ifndef BinariesDir
  31. #define BinariesDir SourceDir + "\Win32\Release"
  32. #endif
  33. #ifndef BinariesDir64
  34. #define BinariesDir64 SourceDir + "\Win64\Release"
  35. #endif
  36. #ifndef AllTranslations
  37. #define AllTranslations
  38. #endif
  39. #define TranslationDir "translations"
  40. #define ImagesDir "images"
  41. #define OutputDir "."
  42. #define TranslationFileMask "WinSCP.???"
  43. #define MainFileName "WinSCP.exe"
  44. #define MainFileSource BinariesDir+"\"+MainFileName
  45. #define ShellExtFileName "DragExt.dll"
  46. #define ShellExtFileSource BinariesDir+"\"+ShellExtFileName
  47. #define ShellExt64FileName "DragExt64.dll"
  48. #define ShellExt64FileSource BinariesDir64+"\"+ShellExt64FileName
  49. #define ConsoleFileSource BinariesDir+"\WinSCP.com"
  50. #define MapFileSource BinariesDir+"\WinSCP.map"
  51. #ifdef Donations
  52. #define PayPalCardImage "PayPalCard.bmp"
  53. #endif
  54. #define Major
  55. #define Minor
  56. #define Rev
  57. #define Build
  58. #expr ParseVersion(MainFileSource, Major, Minor, Rev, Build)
  59. #define VersionOnly Str(Major)+"."+Str(Minor)+(Rev > 0 ? "."+Str(Rev) : "")
  60. #define Version VersionOnly+(Status != "" ? " "+Status : "")
  61. #define FTag VersionOnly+(Status != "" ? "."+Status : "")
  62. #define WebArguments "ver=" +VersionOnly + "&lang={language}&utm_source=winscp&utm_medium=setup&utm_campaign=" + VersionOnly
  63. #define WebGettingStarted WebRoot + "eng/installed.php?" + WebArguments + "&prevver="
  64. #define MessagesPath(L) TranslationDir + "\" + "WinSCP." + L + ".islu"
  65. #define ExplorerFileBase "Explorer"
  66. #define CommanderFileBase "Commander"
  67. #define WizardImageFileBase "Tall"
  68. #define WizardSmallImageFileBase "Square"
  69. #define SelectDirFileBase "Opened bookmark folder-stored session folder"
  70. [Setup]
  71. AppId={#AppId}
  72. AppName=WinSCP
  73. AppPublisher=Martin Prikryl
  74. AppPublisherURL={#WebRoot}
  75. AppSupportURL={#WebForum}
  76. AppUpdatesURL={#WebRoot}eng/download.php
  77. VersionInfoCompany=Martin Prikryl
  78. VersionInfoDescription=Setup for WinSCP {#Version} (SFTP, FTP, WebDAV and SCP client)
  79. VersionInfoVersion={#Major}.{#Minor}.{#Rev}.{#Build}
  80. VersionInfoTextVersion={#Version}
  81. VersionInfoCopyright=(c) 2000-{#Year} Martin Prikryl
  82. DefaultDirName={pf}\WinSCP
  83. LicenseFile=license.setup.txt
  84. UninstallDisplayIcon={app}\WinSCP.exe
  85. OutputDir={#OutputDir}
  86. DisableStartupPrompt=yes
  87. AppVersion={#Version}
  88. AppVerName=WinSCP {#Version}
  89. OutputBaseFilename=WinSCP-{#FTag}-Setup
  90. SolidCompression=yes
  91. WizardImageFile={#ImagesDir}\{#WizardImageFileBase} 100.bmp
  92. WizardSmallImageFile={#ImagesDir}\{#WizardSmallImageFileBase} 100.bmp
  93. ShowTasksTreeLines=yes
  94. PrivilegesRequired=none
  95. UsePreviousLanguage=yes
  96. DisableProgramGroupPage=yes
  97. MinVersion=0,5.1
  98. SetupIconFile=winscpsetup.ico
  99. DisableDirPage=no
  100. #ifdef Sign
  101. SignTool=sign $f "WinSCP Installer" http://winscp.net/eng/docs/installation
  102. #endif
  103. [Languages]
  104. ; English has to be first so that it is pre-selected
  105. ; on Setup Select Language window, when no translation matching
  106. ; Windows UI locale is available
  107. Name: {#DefaultLang}; MessagesFile: {#MessagesPath(DefaultLang)}
  108. #define FindHandle
  109. #dim Languages[200]
  110. #define LanguageCount 0
  111. #define AnyLanguageComplete 0
  112. #define LangI
  113. #sub ProcessTranslationFile
  114. #define FileName FindGetFileName(FindHandle)
  115. #define Lang Copy(FileName, Pos(".", FileName)+1)
  116. #define LangNameFull ReadIni(MessagesPath(Lang), "LangOptions", "LanguageName")
  117. #define Sep Pos(" -", LangNameFull)
  118. #if Sep > 0
  119. #define LangName Copy(LangNameFull, 1, Sep - 1)
  120. #else
  121. #define LangName LangNameFull
  122. #endif
  123. #define LangID ReadIni(MessagesPath(Lang), "LangOptions", "LanguageID")
  124. #define LangCompleteness Int(ReadIni(MessagesPath(Lang), "CustomOptions", "TranslationCompleteness"))
  125. #expr Languages[LanguageCount*4] = Lang
  126. #expr Languages[LanguageCount*4+1] = LangName
  127. #expr Languages[LanguageCount*4+2] = LangID
  128. #expr Languages[LanguageCount*4+3] = LangCompleteness
  129. #expr LanguageCount++
  130. #if LangCompleteness > CompletenessThreshold
  131. Name: {#Lang}; MessagesFile: {#MessagesPath(Lang)}
  132. #expr AnyLanguageComplete = 1
  133. #endif
  134. #endsub /* sub ProcessTranslationFile */
  135. #if FindHandle = FindFirst(TranslationDir + "\" + TranslationFileMask, 0)
  136. #define FResult 1
  137. #for {0; FResult; FResult = FindNext(FindHandle)} ProcessTranslationFile
  138. #expr FindClose(FindHandle)
  139. #endif
  140. ; Types are not used anymore, they are preserved only to let setup
  141. ; detect previous installation type and decide between typical/custom setup
  142. [Types]
  143. Name: full; Description: "full"
  144. Name: compact; Description: "compact"
  145. Name: custom; Description: "custom"; Flags: iscustom
  146. [Components]
  147. Name: main; Description: {cm:ApplicationComponent}; \
  148. Types: full custom compact; Flags: fixed
  149. Name: shellext; Description: {cm:ShellExtComponent}; \
  150. Types: full compact
  151. Name: pageant; Description: {cm:PageantComponent}; \
  152. Types: full
  153. Name: puttygen; Description: {cm:PuTTYgenComponent}; \
  154. Types: full
  155. #if AnyLanguageComplete == 1
  156. Name: transl; Description: {cm:TranslationsComponent}; \
  157. Types: full
  158. #endif
  159. [Tasks]
  160. Name: enableupdates; Description: {cm:EnableUpdates}
  161. Name: enableupdates\enablecollectusage; Description: {cm:EnableCollectUsage}
  162. ; Windows integration
  163. Name: desktopicon; Description: {cm:DesktopIconTask}
  164. Name: desktopicon\user; Description: {cm:DesktopIconUserTask}; \
  165. Flags: exclusive unchecked
  166. Name: desktopicon\common; Description: {cm:DesktopIconCommonTask}; \
  167. Flags: exclusive
  168. ; No Quick Launch on Win7
  169. Name: quicklaunchicon; Description: {cm:QuickLaunchIconTask}; \
  170. Flags: unchecked; OnlyBelowVersion: 6.1.7600
  171. Name: sendtohook; Description: {cm:SendToHookTask}
  172. Name: urlhandler; Description: {cm:RegisterAsUrlHandlers}
  173. Name: searchpath; Description: {cm:AddSearchPath}; \
  174. Flags: unchecked; Check: IsAdminLoggedOn
  175. [Icons]
  176. Name: "{commonprograms}\WinSCP"; Filename: "{app}\WinSCP.exe"; Components: main; \
  177. Comment: "{cm:ProgramComment2}"
  178. ; This is created when desktopicon task is selected
  179. Name: "{userdesktop}\WinSCP"; Filename: "{app}\WinSCP.exe"; \
  180. Tasks: desktopicon\user; Comment: "{cm:ProgramComment2}"
  181. Name: "{commondesktop}\WinSCP"; Filename: "{app}\WinSCP.exe"; \
  182. Tasks: desktopicon\common; Comment: "{cm:ProgramComment2}"
  183. ; This is created when quicklaunchicon task is selected
  184. Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\WinSCP"; \
  185. Filename: "{app}\WinSCP.exe"; Tasks: quicklaunchicon
  186. ; This is created when sendtohook task is selected
  187. Name: "{sendto}\{cm:SendToHookNew}"; Filename: "{app}\WinSCP.exe"; \
  188. Parameters: "/upload"; Tasks: sendtohook
  189. [InstallDelete]
  190. ; Remove pre-524 licence file (without .txt extension)
  191. Type: files; Name: "{app}\license"
  192. ; Remove pre-520 start menu folders
  193. Type: filesandordirs; Name: "{commonprograms}\WinSCP"
  194. Type: filesandordirs; Name: "{userprograms}\WinSCP"
  195. [Run]
  196. Filename: "{app}\WinSCP.exe"; Parameters: "/RegisterForDefaultProtocols"; \
  197. StatusMsg: {cm:RegisteringAsUrlHandlers}; Tasks: urlhandler
  198. Filename: "{app}\WinSCP.exe"; Parameters: "/AddSearchPath"; \
  199. StatusMsg: {cm:AddingSearchPath}; Tasks: searchpath
  200. Filename: "{app}\WinSCP.exe"; Parameters: "/ImportSitesIfAny"; \
  201. StatusMsg: {cm:ImportSites}; Flags: skipifsilent
  202. [UninstallDelete]
  203. ; These additional files are created by application
  204. Type: files; Name: "{app}\WinSCP.ini"
  205. Type: files; Name: "{app}\WinSCP.cgl"
  206. [Files]
  207. ; Put these to the top as we extract them on demand and
  208. ; that can take long with solid compression enabled
  209. Source: "{#ImagesDir}\{#ExplorerFileBase} *.bmp"; Flags: dontcopy
  210. Source: "{#ImagesDir}\{#CommanderFileBase} *.bmp"; Flags: dontcopy
  211. ; We do not need 100% images here, they are embedded already automatically
  212. ; by WizardImageFile and WizardSmallImageFile
  213. Source: "{#ImagesDir}\{#WizardImageFileBase} *.bmp"; Excludes: "* 100.bmp"; \
  214. Flags: dontcopy
  215. Source: "{#ImagesDir}\{#WizardSmallImageFileBase} *.bmp"; Excludes: "* 100.bmp"; \
  216. Flags: dontcopy
  217. Source: "{#ImagesDir}\{#SelectDirFileBase} *.bmp"; Flags: dontcopy
  218. #ifdef Donations
  219. Source: "{#ImagesDir}\{#PayPalCardImage}"; Flags: dontcopy
  220. #endif
  221. Source: "{#MainFileSource}"; DestDir: "{app}"; \
  222. Components: main; Flags: ignoreversion
  223. Source: "{#ConsoleFileSource}"; DestDir: "{app}"; \
  224. Components: main; Flags: ignoreversion
  225. Source: "{#MapFileSource}"; DestDir: "{app}"; \
  226. Components: main; Flags: ignoreversion
  227. Source: "license.txt"; DestDir: "{app}"; \
  228. Components: main; Flags: ignoreversion
  229. Source: "{#ShellExtFileSource}"; DestDir: "{app}"; \
  230. Components: shellext; \
  231. Flags: regserver restartreplace uninsrestartdelete; \
  232. Check: not IsWin64 and IsShellExtNewer(ExpandConstant('{app}\{#ShellExtFileName}'), '{#GetFileVersion(ShellExtFileSource)}')
  233. Source: "{#ShellExt64FileSource}"; DestDir: "{app}"; \
  234. Components: shellext; \
  235. Flags: regserver restartreplace uninsrestartdelete; \
  236. Check: IsWin64 and IsShellExtNewer(ExpandConstant('{app}\{#ShellExt64FileName}'), '{#GetFileVersion(ShellExt64FileSource)}')
  237. Source: "{#PuttySourceDir}\LICENCE"; DestDir: "{app}\PuTTY"; \
  238. Components: pageant puttygen; Flags: ignoreversion
  239. Source: "{#PuttySourceDir}\putty.hlp"; DestDir: "{app}\PuTTY"; \
  240. Components: pageant puttygen; Flags: ignoreversion
  241. Source: "{#PuttySourceDir}\pageant.exe"; DestDir: "{app}\PuTTY"; \
  242. Components: pageant; Flags: ignoreversion
  243. Source: "{#PuttySourceDir}\puttygen.exe"; DestDir: "{app}\PuTTY"; \
  244. Components: puttygen; Flags: ignoreversion
  245. [Registry]
  246. Root: HKCU; Subkey: "{#ParentRegistryKey}"; Flags: uninsdeletekeyifempty
  247. Root: HKCU; Subkey: "{#RegistryKey}"; Flags: uninsdeletekeyifempty
  248. ; Norton Commander interface
  249. Root: HKCU; SubKey: "{#RegistryKey}\Configuration\Interface"; ValueType: dword; \
  250. ValueName: "Interface"; ValueData: 0; Check: UserSettings(1)
  251. Root: HKLM; SubKey: "{#RegistryKey}"; ValueType: dword; \
  252. ValueName: "DefaultInterfaceInterface"; ValueData: 0; \
  253. Check: UserSettings(1); Flags: noerror
  254. ; Explorer-like interface
  255. Root: HKCU; SubKey: "{#RegistryKey}\Configuration\Interface"; ValueType: dword; \
  256. ValueName: "Interface"; ValueData: 1; Check: not UserSettings(1)
  257. Root: HKLM; SubKey: "{#RegistryKey}"; ValueType: dword; \
  258. ValueName: "DefaultInterfaceInterface"; ValueData: 1; \
  259. Check: not UserSettings(1); Flags: noerror
  260. ; If installer enabled ddext, let it reset the settings on uninstall,
  261. ; so the default is used on the next run
  262. Root: HKCU; SubKey: "{#RegistryKey}\Configuration\Interface"; ValueType: dword; \
  263. ValueName: "DDExtEnabled"; ValueData: 1; Components: shellext; \
  264. Flags: uninsdeletevalue
  265. ; Updates
  266. Root: HKCU; SubKey: "{#RegistryKey}\Configuration\Interface\Updates"; \
  267. ValueType: dword; ValueName: "Period"; ValueData: 7; \
  268. Tasks: enableupdates; Check: not UpdatesEnabled
  269. Root: HKLM; SubKey: "{#RegistryKey}"; \
  270. ValueType: dword; ValueName: "DefaultUpdatesPeriod"; ValueData: 7; \
  271. Tasks: enableupdates; Flags: noerror
  272. Root: HKLM; SubKey: "{#RegistryKey}"; \
  273. ValueType: dword; ValueName: "DefaultCollectUsage"; ValueData: 1; \
  274. Tasks: enableupdates\enablecollectusage; Flags: noerror
  275. #if AnyLanguageComplete == 1
  276. [Components]
  277. Name: transl\eng; Description: {#EnglishLang}; Types: full custom compact; \
  278. Flags: fixed
  279. #endif
  280. #sub EmitLang
  281. #if Languages[LangI*4+3] > CompletenessThreshold
  282. [Components]
  283. Name: transl\{#Languages[LangI*4]}; Description: {#Languages[LangI*4+1]}; \
  284. Types: full compact custom; Check: IsLang('{#Languages[LangI*4]}')
  285. Name: transl\{#Languages[LangI*4]}; Description: {#Languages[LangI*4+1]}; \
  286. Check: not IsLang('{#Languages[LangI*4]}')
  287. [Files]
  288. Source: "{#TranslationDir}\WinSCP.{#Languages[LangI*4]}"; DestDir: "{app}"; \
  289. Components: transl\{#Languages[LangI*4]}; Flags: ignoreversion
  290. [Registry]
  291. ; set program default language to setup language, but only if user installs it
  292. Root: HKCU; SubKey: "{#RegistryKey}\Configuration\Interface"; \
  293. ValueType: dword; ValueName: "LocaleSafe"; ValueData: {#Languages[LangI*4+2]}; \
  294. Components: transl\{#Languages[LangI*4]}; Languages: {#Languages[LangI*4]}
  295. #endif
  296. #endsub /* sub EmitLang */
  297. #for {LangI = 0; LangI < LanguageCount; LangI++} EmitLang
  298. [UninstallRun]
  299. ; Make sure no later uninstall task recreate the configuration
  300. Filename: "{app}\WinSCP.exe"; Parameters: "/UninstallCleanup"; \
  301. RunOnceId: "UninstallCleanup"
  302. Filename: "{app}\WinSCP.exe"; Parameters: "/RemoveSearchPath"; \
  303. RunOnceId: "RemoveSearchPath"
  304. Filename: "{app}\WinSCP.exe"; Parameters: "/UnregisterForProtocols"; \
  305. RunOnceId: "UnregisterForProtocols"
  306. [Code]
  307. const
  308. wpSetupType = 100;
  309. wpInterface = 101;
  310. NewLine = #13#10;
  311. var
  312. TypicalTypeButton: TRadioButton;
  313. CustomTypeButton: TRadioButton;
  314. CommanderRadioButton: TRadioButton;
  315. ExplorerRadioButton: TRadioButton;
  316. LaunchCheckbox: TCheckbox;
  317. OpenGettingStartedCheckbox: TCheckbox;
  318. AreUpdatesEnabled: Boolean;
  319. AutomaticUpdate: Boolean;
  320. Upgrade: Boolean;
  321. MissingTranslations: string;
  322. PrevVersion: string;
  323. ShellExtNewerCacheFileName: string;
  324. ShellExtNewerCacheResult: Boolean;
  325. #ifdef Donations
  326. DonationPanel: TPanel;
  327. AboutDonationCaption: TLabel;
  328. #endif
  329. InstallationDone: Boolean;
  330. LicenseAccepted: Boolean;
  331. InitDir: string;
  332. InitComponents: string;
  333. InitTasks: string;
  334. InitInterface: Integer;
  335. Donated: Boolean;
  336. procedure ShowMessage(Text: string);
  337. begin
  338. MsgBox(Text, mbInformation, MB_OK);
  339. end;
  340. function IsLang(Lang: string): Boolean;
  341. begin
  342. Result := (Lang = ActiveLanguage);
  343. end;
  344. function IsWin8: Boolean;
  345. var
  346. Version: TWindowsVersion;
  347. begin
  348. GetWindowsVersionEx(Version);
  349. Result :=
  350. (Version.Major > 6) or
  351. ((Version.Major = 6) and (Version.Minor >= 2));
  352. end;
  353. procedure CutVersionPart(var VersionString: string; var VersionPart: Word);
  354. var
  355. P: Integer;
  356. begin
  357. P := Pos('.', VersionString);
  358. if P > 0 then
  359. begin
  360. VersionPart := StrToIntDef(Copy(VersionString, 1, P - 1), 0);
  361. Delete(VersionString, 1, P);
  362. end
  363. else
  364. begin
  365. VersionPart := StrToIntDef(VersionString, 0);
  366. VersionString := '';
  367. end;
  368. end;
  369. function IsShellExtNewer(FileName: string; InstalledVersion: string): Boolean;
  370. var
  371. ExistingMS, ExistingLS: Cardinal;
  372. ExistingMajor, ExistingMinor, ExistingRev, ExistingBuild: Cardinal;
  373. InstalledMajor, InstalledMinor, InstalledRev, InstalledBuild: Word;
  374. begin
  375. if ShellExtNewerCacheFileName = FileName then
  376. begin
  377. if ShellExtNewerCacheResult then
  378. begin
  379. Log(Format('Allowing installation of shell extension %s as already decided', [FileName]));
  380. Result := True;
  381. end
  382. else
  383. begin
  384. Log(Format('Skipping installation of shell extension %s as already decided', [FileName]));
  385. Result := False;
  386. end;
  387. end
  388. else
  389. if not FileExists(FileName) then
  390. begin
  391. Log(Format('Shell extension %s does not exist yet, allowing installation', [FileName]));
  392. Result := True;
  393. end
  394. else
  395. if not GetVersionNumbers(FileName, ExistingMS, ExistingLS) then
  396. begin
  397. Log(Format('Cannot retrieve version of existing shell extension %s, allowing installation', [FileName]));
  398. Result := True;
  399. end
  400. else
  401. begin
  402. ExistingMajor := ExistingMS shr 16;
  403. ExistingMinor := ExistingMS and $FFFF;
  404. ExistingRev := ExistingLS shr 16;
  405. ExistingBuild := ExistingLS and $FFFF;
  406. Log(Format('Existing shell extension %s version: %d.%d.%d[.%d]', [FileName, ExistingMajor, ExistingMinor, ExistingRev, ExistingBuild]));
  407. Log(Format('Installed extension version string: %s', [InstalledVersion]));
  408. CutVersionPart(InstalledVersion, InstalledMajor);
  409. CutVersionPart(InstalledVersion, InstalledMinor);
  410. CutVersionPart(InstalledVersion, InstalledRev);
  411. CutVersionPart(InstalledVersion, InstalledBuild);
  412. Log(Format('Installed extension version: %d.%d.%d[.%d]', [InstalledMajor, InstalledMinor, InstalledRev, InstalledBuild]));
  413. if ((InstalledMajor > ExistingMajor)) or
  414. ((InstalledMajor = ExistingMajor) and (InstalledMinor > ExistingMinor)) or
  415. ((InstalledMajor = ExistingMajor) and (InstalledMinor = ExistingMinor) and (InstalledRev > ExistingRev)) then
  416. begin
  417. Log('Installed extension is newer than existing extension, allowing installation');
  418. Result := True;
  419. end
  420. else
  421. begin
  422. Log('Installed extension is same or older than existing extension, skipping installation');
  423. Result := False;
  424. end;
  425. end;
  426. ShellExtNewerCacheFileName := FileName;
  427. ShellExtNewerCacheResult := Result;
  428. end;
  429. function UpdatesEnabled: Boolean;
  430. begin
  431. Result := AreUpdatesEnabled;
  432. end;
  433. function UserSettings(Settings: Integer): Boolean;
  434. begin
  435. case Settings of
  436. 1: Result := CommanderRadioButton.Checked;
  437. else Result := False;
  438. end;
  439. end;
  440. function LanguageName(Lang: string; Unknown: string): string;
  441. begin
  442. #sub EmitLang2
  443. if Lang = '{#Languages[LangI*4]}' then Result := '{#Languages[LangI*4+1]}'
  444. else
  445. #endsub /* sub EmitLang2 */
  446. #for {LangI = 0; LangI < LanguageCount; LangI++} EmitLang2
  447. Result := Unknown;
  448. end;
  449. function ContainsLanguage(Lang: string): Boolean;
  450. begin
  451. #sub EmitLang3
  452. #if Languages[LangI*4+3] > CompletenessThreshold
  453. if (Lang = '{#Languages[LangI*4]}') then Result := True
  454. else
  455. #endif
  456. #endsub /* sub EmitLang3 */
  457. #for {LangI = 0; LangI < LanguageCount; LangI++} EmitLang3
  458. Result := False;
  459. end;
  460. function LanguageCompleteness(Lang: string): Integer;
  461. begin
  462. #sub EmitLang4
  463. if (Lang = '{#Languages[LangI*4]}') then
  464. begin
  465. Result := {#Languages[LangI*4+3]};
  466. end
  467. else
  468. #endsub /* sub EmitLang4 */
  469. #for {LangI = 0; LangI < LanguageCount; LangI++} EmitLang4
  470. // used also for the default language
  471. Result := 100;
  472. end;
  473. procedure OpenBrowser(Url: string);
  474. var
  475. ErrorCode: Integer;
  476. begin
  477. ShellExec('open', Url, '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
  478. end;
  479. procedure OpenHelp;
  480. begin
  481. OpenBrowser('{#WebDocumentation}installation?page=' + IntToStr(WizardForm.CurPageID) + '&' + ExpandConstant('{#WebArguments}'));
  482. end;
  483. procedure HelpButtonClick(Sender: TObject);
  484. begin
  485. OpenHelp;
  486. end;
  487. procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  488. begin
  489. if Key = 112 { VK_F1 } then
  490. begin
  491. OpenHelp;
  492. Key := 0;
  493. end;
  494. end;
  495. procedure CaptionClick(Sender: TObject);
  496. begin
  497. WizardForm.ActiveControl := TLabel(Sender).FocusControl;
  498. end;
  499. procedure ImageClick(Sender: TObject);
  500. begin
  501. WizardForm.ActiveControl := TWinControl(TControl(Sender).Tag);
  502. end;
  503. type
  504. TProcessTranslationEvent = procedure(Lang: string; FileName: string);
  505. procedure CollectNames(Lang: string; FileName: string);
  506. begin
  507. if Length(MissingTranslations) > 0 then
  508. MissingTranslations := MissingTranslations + ', ';
  509. MissingTranslations := MissingTranslations + LanguageName(Lang, Lang);
  510. end;
  511. procedure DeleteTranslation(Lang: string; FileName: string);
  512. begin
  513. DeleteFile(FileName);
  514. end;
  515. procedure ProcessMissingTranslations(OnProcessTranslation: TProcessTranslationEvent);
  516. var
  517. Path: string;
  518. FindRec: TFindRec;
  519. Ext: string;
  520. LExt: string;
  521. begin
  522. Path := AddBackslash(WizardDirValue);
  523. if FindFirst(Path + '{#TranslationFileMask}', FindRec) then
  524. begin
  525. try
  526. repeat
  527. if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then
  528. begin
  529. Ext := Uppercase(ExtractFileExt(FindRec.Name));
  530. if Pos('.', Ext) = 1 then
  531. begin
  532. Ext := Uppercase(Copy(Ext, 2, Length(Ext) - 1));
  533. LExt := Lowercase(Ext);
  534. if (Pos('-' + Ext + '-', '-{#AllTranslations}-') > 0) and
  535. not ContainsLanguage(LExt) then
  536. OnProcessTranslation(LExt, Path + FindRec.Name);
  537. end;
  538. end;
  539. until not FindNext(FindRec);
  540. finally
  541. FindClose(FindRec);
  542. end;
  543. end;
  544. end;
  545. function WillRestart: Boolean;
  546. begin
  547. Result := WizardForm.YesRadio.Visible and WizardForm.YesRadio.Checked;
  548. end;
  549. procedure UpdatePostInstallRunCheckboxes(Sender: TObject);
  550. begin
  551. LaunchCheckbox.Enabled := not WillRestart;
  552. OpenGettingStartedCheckbox.Enabled :=
  553. LaunchCheckbox.Enabled
  554. end;
  555. procedure LinkLabel(Control: TLabel);
  556. begin
  557. Control.ParentFont := True;
  558. Control.Font.Style := Control.Font.Style + [fsUnderline];
  559. Control.Font.Color := clBlue;
  560. Control.Cursor := crHand;
  561. end;
  562. function IsTypicalInstallation: Boolean;
  563. begin
  564. Result := TypicalTypeButton.Checked;
  565. end;
  566. #ifdef Donations
  567. procedure AboutDonationsLinkClick(Sender: TObject);
  568. begin
  569. OpenBrowser('{#WebRoot}eng/donate.php?' + ExpandConstant('{#WebArguments}'));
  570. Donated := true;
  571. end;
  572. procedure DonateLinkClick(Sender: TObject);
  573. var
  574. Control: TControl;
  575. begin
  576. Control := TControl(Sender);
  577. OpenBrowser('{#WebRoot}eng/donate.php?amount=' + IntToStr(Control.Tag) + '&currency=' + CustomMessage('Currency') + '&' + ExpandConstant('{#WebArguments}'));
  578. Donated := true;
  579. end;
  580. procedure CreateDonateLink(Amount: Integer; Row: Integer; Top: Integer);
  581. var
  582. Caption: TLabel;
  583. begin
  584. Caption := TLabel.Create(DonationPanel);
  585. Caption.Left := 0;
  586. Caption.Top := Top + Row * ScaleY(16);
  587. Caption.Tag := Amount;
  588. Caption.Parent := DonationPanel;
  589. Caption.Caption := Format(CustomMessage('Donate'), ['$' + IntToStr(Amount)]);
  590. Caption.OnClick := @DonateLinkClick;
  591. LinkLabel(Caption);
  592. end;
  593. #endif
  594. const
  595. fsSurface = 0;
  596. procedure LoadEmbededBitmap(Image: TBitmapImage; Name: string; BackgroundColor: TColor);
  597. var
  598. FileName: string;
  599. Bitmap: TAlphaBitmap;
  600. begin
  601. ExtractTemporaryFile(Name);
  602. Bitmap := TAlphaBitmap.Create();
  603. Bitmap.AlphaFormat := afDefined;
  604. FileName := ExpandConstant('{tmp}\' + Name);
  605. Bitmap.LoadFromFile(FileName);
  606. // we won't need this anymore
  607. DeleteFile(FileName);
  608. Image.Bitmap := Bitmap;
  609. Bitmap.Free;
  610. Image.BackColor := BackgroundColor;
  611. end;
  612. function GetScalingFactor: Integer;
  613. begin
  614. if WizardForm.Font.PixelsPerInch >= 192 then Result := 200
  615. else
  616. if WizardForm.Font.PixelsPerInch >= 144 then Result := 150
  617. else
  618. if WizardForm.Font.PixelsPerInch >= 120 then Result := 125
  619. else Result := 100;
  620. end;
  621. procedure LoadEmbededScaledBitmap(Image: TBitmapImage; NameBase: string; SizeBase: Integer; BackgroundColor: TColor);
  622. var
  623. Name: String;
  624. begin
  625. Name := Format('%s %d.bmp', [NameBase, SizeBase * GetScalingFactor div 100]);
  626. LoadEmbededBitmap(Image, Name, BackgroundColor);
  627. end;
  628. procedure LoadEmbededScaledIcon(Image: TBitmapImage; NameBase: string; SizeBase: Integer; BackgroundColor: TColor);
  629. begin
  630. LoadEmbededScaledBitmap(Image, NameBase, SizeBase, BackgroundColor);
  631. Image.AutoSize := True;
  632. end;
  633. // WORKAROUND
  634. // Checkboxes and Radio buttons created on runtime do
  635. // not scale their height automatically
  636. procedure ScaleFixedHeightControl(Control: TButtonControl);
  637. begin
  638. Control.Height := ScaleY(Control.Height);
  639. end;
  640. function GetBottom(Control: TControl): Integer;
  641. begin
  642. Result := Control.Top + Control.Height;
  643. end;
  644. function CmdLineParamExists(const Value: string): Boolean;
  645. var
  646. I: Integer;
  647. begin
  648. Result := False;
  649. for I := 1 to ParamCount do
  650. begin
  651. if CompareText(ParamStr(I), Value) = 0 then
  652. begin
  653. Result := True;
  654. Exit;
  655. end;
  656. end;
  657. end;
  658. function InitializeSetup: Boolean;
  659. var
  660. WaitInterval: Integer;
  661. Wait: Integer;
  662. begin
  663. AutomaticUpdate := CmdLineParamExists('/AutomaticUpdate');
  664. if AutomaticUpdate then
  665. begin
  666. Log('Automatic update');
  667. Wait := 10000;
  668. end
  669. else
  670. begin
  671. Wait := 0;
  672. end;
  673. WaitInterval := 250;
  674. while (Wait > 0) and CheckForMutexes('{#AppMutex}') do
  675. begin
  676. Log('Application is still running, waiting');
  677. Sleep(WaitInterval);
  678. Wait := Wait - WaitInterval;
  679. end;
  680. while CheckForMutexes('{#AppMutex}') do
  681. begin
  682. if MsgBox(
  683. FmtMessage(SetupMessage(msgSetupAppRunningError), ['WinSCP']),
  684. mbError, MB_OKCANCEL) <> IDOK then
  685. begin
  686. Abort;
  687. end;
  688. end;
  689. Result := True;
  690. end;
  691. procedure InitializeWizard;
  692. var
  693. DefaultLang: Boolean;
  694. UserInterface: Cardinal;
  695. UpdatesPeriod: Cardinal;
  696. InterfacePage: TWizardPage;
  697. SetupTypePage: TWizardPage;
  698. Caption: TLabel;
  699. Image: TBitmapImage;
  700. HelpButton: TButton;
  701. P: Integer;
  702. S: string;
  703. Completeness: Integer;
  704. begin
  705. InstallationDone := False;
  706. LicenseAccepted := False;
  707. InitInterface := -1;
  708. DefaultLang := (ActiveLanguage = '{#DefaultLang}');
  709. Upgrade :=
  710. RegQueryStringValue(HKLM, '{#InnoSetupReg}', '{#InnoSetupAppPathReg}', S) or
  711. RegQueryStringValue(HKCU, '{#InnoSetupReg}', '{#InnoSetupAppPathReg}', S)
  712. if Upgrade and GetVersionNumbersString(AddBackslash(WizardDirValue) + '{#MainFileName}', PrevVersion) and
  713. (PrevVersion[2] = '.') and (PrevVersion[4] = '.') and (PrevVersion[6] = '.') then
  714. begin
  715. PrevVersion := Copy(PrevVersion, 1, 5);
  716. end;
  717. Completeness := LanguageCompleteness(ActiveLanguage);
  718. if Completeness < 100 then
  719. begin
  720. ShowMessage(FmtMessage(CustomMessage('IncompleteTranslation'), [IntToStr(Completeness)]));
  721. end;
  722. ProcessMissingTranslations(@CollectNames);
  723. WizardForm.KeyPreview := True;
  724. WizardForm.OnKeyDown := @FormKeyDown;
  725. // to accomodate one more task
  726. WizardForm.TasksList.Height := WizardForm.TasksList.Height + ScaleY(8);
  727. // allow installation without requiring user to accept license
  728. WizardForm.LicenseAcceptedRadio.Checked := True;
  729. WizardForm.LicenseAcceptedRadio.Visible := False;
  730. WizardForm.LicenseNotAcceptedRadio.Visible := False;
  731. WizardForm.LicenseMemo.Height :=
  732. GetBottom(WizardForm.LicenseNotAcceptedRadio) -
  733. WizardForm.LicenseMemo.Top - 5;
  734. // hide installation types combo
  735. WizardForm.TypesCombo.Visible := False;
  736. WizardForm.ComponentsList.Height :=
  737. GetBottom(WizardForm.ComponentsList) -
  738. WizardForm.TypesCombo.Top;
  739. WizardForm.ComponentsList.Top := WizardForm.TypesCombo.Top;
  740. // add help button
  741. HelpButton := TButton.Create(WizardForm);
  742. HelpButton.Parent := WizardForm;
  743. HelpButton.Left :=
  744. WizardForm.ClientWidth -
  745. (WizardForm.CancelButton.Left + WizardForm.CancelButton.Width);
  746. HelpButton.Top := WizardForm.CancelButton.Top;
  747. HelpButton.Width := WizardForm.CancelButton.Width;
  748. HelpButton.Height := WizardForm.CancelButton.Height;
  749. HelpButton.Caption := CustomMessage('HelpButton');
  750. HelpButton.OnClick := @HelpButtonClick;
  751. // installation type page
  752. SetupTypePage := CreateCustomPage(wpLicense,
  753. CustomMessage('SetupTypeTitle'),
  754. CustomMessage('SetupTypePrompt'));
  755. TypicalTypeButton := TRadioButton.Create(SetupTypePage);
  756. if not Upgrade then
  757. S := CustomMessage('TypicalType')
  758. else
  759. S := CustomMessage('TypicalUpgradeType');
  760. TypicalTypeButton.Caption :=
  761. FmtMessage(CustomMessage('Recommended'), [S]);
  762. // check typical install, if typical install was installed before or
  763. // when version without setup type support was installed with
  764. // "full" installation or when there were no installation before
  765. // ("full" installation is default)
  766. TypicalTypeButton.Checked :=
  767. ((GetPreviousData('{#SetupTypeData}', '') = 'typical')) or
  768. ((GetPreviousData('{#SetupTypeData}', '') = '') and
  769. (WizardSetupType(False) = 'full'));
  770. TypicalTypeButton.Left := ScaleX(4);
  771. TypicalTypeButton.Width := SetupTypePage.SurfaceWidth -
  772. TypicalTypeButton.Left;
  773. ScaleFixedHeightControl(TypicalTypeButton);
  774. TypicalTypeButton.Parent := SetupTypePage.Surface;
  775. Caption := TLabel.Create(SetupTypePage);
  776. Caption.WordWrap := True;
  777. if not Upgrade then
  778. begin
  779. if DefaultLang then
  780. S := CustomMessage('TypicalType2Eng')
  781. else
  782. S := FmtMessage(CustomMessage('TypicalType2Intl'), [CustomMessage('LocalLanguageName')]);
  783. Caption.Caption :=
  784. CustomMessage('TypicalType1') + NewLine +
  785. S + NewLine +
  786. CustomMessage('TypicalType3');
  787. end
  788. else
  789. begin
  790. if Length(MissingTranslations) > 0 then
  791. begin
  792. #if AnyLanguageComplete
  793. S := FmtMessage(CustomMessage('TypicalUpgradeTypeMissingTransl'), [MissingTranslations]);
  794. #else
  795. S := CustomMessage('TypicalUpgradeTypeNoTransl');
  796. #endif
  797. S := NewLine + S;
  798. end
  799. else S := '';
  800. Caption.Caption :=
  801. CustomMessage('TypicalUpgradeType1') + S;
  802. end;
  803. Caption.Left := ScaleX(4) + ScaleX(20);
  804. Caption.Width := SetupTypePage.SurfaceWidth - Caption.Left;
  805. Caption.Top := GetBottom(TypicalTypeButton) + ScaleY(6);
  806. Caption.Parent := SetupTypePage.Surface;
  807. Caption.FocusControl := TypicalTypeButton;
  808. Caption.OnClick := @CaptionClick;
  809. CustomTypeButton := TRadioButton.Create(SetupTypePage);
  810. if not Upgrade then
  811. CustomTypeButton.Caption := CustomMessage('CustomType')
  812. else
  813. CustomTypeButton.Caption := CustomMessage('CustomUpgradeType');
  814. CustomTypeButton.Checked := (not TypicalTypeButton.Checked);
  815. CustomTypeButton.Left := ScaleX(4);
  816. CustomTypeButton.Width := SetupTypePage.SurfaceWidth -
  817. CustomTypeButton.Left;
  818. CustomTypeButton.Top := GetBottom(Caption) + ScaleY(10);
  819. ScaleFixedHeightControl(CustomTypeButton);
  820. CustomTypeButton.Parent := SetupTypePage.Surface;
  821. Caption := TLabel.Create(SetupTypePage);
  822. Caption.WordWrap := True;
  823. if not Upgrade then
  824. begin
  825. Caption.Caption :=
  826. CustomMessage('CustomType1');
  827. end
  828. else
  829. begin
  830. Caption.Caption :=
  831. CustomMessage('CustomUpgradeType1') + NewLine +
  832. CustomMessage('CustomUpgradeType2');
  833. end;
  834. Caption.Left := ScaleX(4) + ScaleX(20);
  835. Caption.Width := SetupTypePage.SurfaceWidth - Caption.Left;
  836. Caption.Top := GetBottom(CustomTypeButton) + ScaleY(6);
  837. Caption.Parent := SetupTypePage.Surface;
  838. Caption.FocusControl := CustomTypeButton;
  839. Caption.OnClick := @CaptionClick;
  840. // interface page
  841. InterfacePage := CreateCustomPage(wpSelectTasks,
  842. CustomMessage('UserSettingsTitle'),
  843. CustomMessage('UserSettingsPrompt'));
  844. UpdatesPeriod := 0;
  845. RegQueryDWordValue(HKCU, '{#RegistryKey}\Configuration\Interface\Updates',
  846. 'Period', UpdatesPeriod);
  847. AreUpdatesEnabled := (UpdatesPeriod <> 0);
  848. UserInterface := 0; { default is commander }
  849. RegQueryDWordValue(HKCU, '{#RegistryKey}\Configuration\Interface',
  850. 'Interface', UserInterface);
  851. Caption := TLabel.Create(InterfacePage);
  852. Caption.Caption := CustomMessage('UserInterfaceStyle');
  853. Caption.Width := InterfacePage.SurfaceWidth;
  854. Caption.Parent := InterfacePage.Surface;
  855. CommanderRadioButton := TRadioButton.Create(InterfacePage);
  856. CommanderRadioButton.Caption := CustomMessage('NortonCommanderInterfaceC');
  857. CommanderRadioButton.Checked := (UserInterface = 0);
  858. CommanderRadioButton.Left := ScaleX(4);
  859. CommanderRadioButton.Width := ScaleX(116);
  860. CommanderRadioButton.Top := GetBottom(Caption) + ScaleY(6);
  861. ScaleFixedHeightControl(CommanderRadioButton);
  862. CommanderRadioButton.Parent := InterfacePage.Surface;
  863. Image := TBitmapImage.Create(InterfacePage);
  864. Image.Top := GetBottom(CommanderRadioButton) + ScaleY(6);
  865. Image.Left := CommanderRadioButton.Left + ScaleX(45);
  866. Image.Parent := InterfacePage.Surface;
  867. LoadEmbededScaledIcon(Image, '{#CommanderFileBase}', 32, InterfacePage.Surface.Color);
  868. Image.OnClick := @ImageClick;
  869. Image.Tag := Integer(CommanderRadioButton);
  870. Caption := TLabel.Create(InterfacePage);
  871. Caption.WordWrap := True;
  872. Caption.Caption :=
  873. CustomMessage('NortonCommanderInterface1') + NewLine +
  874. CustomMessage('NortonCommanderInterface2') + NewLine +
  875. CustomMessage('NortonCommanderInterface3');
  876. Caption.Left := CommanderRadioButton.Left + CommanderRadioButton.Width;
  877. Caption.Width := InterfacePage.SurfaceWidth - Caption.Left;
  878. Caption.Top := CommanderRadioButton.Top;
  879. Caption.Parent := InterfacePage.Surface;
  880. Caption.FocusControl := CommanderRadioButton;
  881. Caption.OnClick := @CaptionClick;
  882. ExplorerRadioButton := TRadioButton.Create(InterfacePage);
  883. ExplorerRadioButton.Caption := CustomMessage('ExplorerInterfaceC');
  884. ExplorerRadioButton.Checked := (UserInterface <> 0);
  885. ExplorerRadioButton.Left := ScaleX(4);
  886. ExplorerRadioButton.Width := CommanderRadioButton.Width;
  887. ExplorerRadioButton.Top := GetBottom(Caption) + ScaleY(10);
  888. ScaleFixedHeightControl(ExplorerRadioButton);
  889. ExplorerRadioButton.Parent := InterfacePage.Surface;
  890. Image := TBitmapImage.Create(InterfacePage);
  891. Image.Top := GetBottom(ExplorerRadioButton) + ScaleY(6);
  892. Image.Left := ExplorerRadioButton.Left + ScaleX(45);
  893. Image.Parent := InterfacePage.Surface;
  894. LoadEmbededScaledIcon(Image, '{#ExplorerFileBase}', 32, InterfacePage.Surface.Color);
  895. Image.OnClick := @ImageClick;
  896. Image.Tag := Integer(ExplorerRadioButton);
  897. Caption := TLabel.Create(InterfacePage);
  898. Caption.WordWrap := True;
  899. Caption.Caption :=
  900. CustomMessage('ExplorerInterface1') + NewLine +
  901. CustomMessage('ExplorerInterface2') + NewLine +
  902. CustomMessage('ExplorerInterface3');
  903. Caption.Left := ExplorerRadioButton.Left + ExplorerRadioButton.Width;
  904. Caption.Width := InterfacePage.SurfaceWidth - Caption.Left;
  905. Caption.Top := ExplorerRadioButton.Top;
  906. Caption.Parent := InterfacePage.Surface;
  907. Caption.FocusControl := ExplorerRadioButton;
  908. Caption.OnClick := @CaptionClick;
  909. // run checkbox
  910. LaunchCheckbox := TCheckbox.Create(WizardForm.FinishedPage);
  911. LaunchCheckbox.Caption := CustomMessage('Launch');
  912. LaunchCheckbox.Checked := True;
  913. LaunchCheckbox.Left := WizardForm.YesRadio.Left;
  914. LaunchCheckbox.Width := WizardForm.YesRadio.Width;
  915. ScaleFixedHeightControl(LaunchCheckbox);
  916. LaunchCheckbox.Parent := WizardForm.FinishedPage;
  917. OpenGettingStartedCheckbox := TCheckbox.Create(WizardForm.FinishedPage);
  918. OpenGettingStartedCheckbox.Caption := CustomMessage('OpenGettingStarted');
  919. OpenGettingStartedCheckbox.Checked := True;
  920. OpenGettingStartedCheckbox.Left := WizardForm.YesRadio.Left;
  921. OpenGettingStartedCheckbox.Width := WizardForm.YesRadio.Width;
  922. ScaleFixedHeightControl(OpenGettingStartedCheckbox);
  923. OpenGettingStartedCheckbox.Parent := WizardForm.FinishedPage;
  924. #ifdef Donations
  925. DonationPanel := TPanel.Create(WizardForm.FinishedPage);
  926. DonationPanel.Left := WizardForm.YesRadio.Left;
  927. DonationPanel.Width := WizardForm.YesRadio.Width;
  928. DonationPanel.Parent := WizardForm.FinishedPage;
  929. DonationPanel.BevelInner := bvNone;
  930. DonationPanel.BevelOuter := bvNone;
  931. DonationPanel.Color := WizardForm.FinishedPage.Color;
  932. Caption := TLabel.Create(DonationPanel);
  933. Caption.WordWrap := True;
  934. Caption.Caption := CustomMessage('PleaseDonate');
  935. Caption.Left := 0;
  936. Caption.Top := 0;
  937. Caption.Width := DonationPanel.Width;
  938. Caption.Parent := DonationPanel;
  939. P := GetBottom(Caption) + ScaleY(12);
  940. CreateDonateLink( 9, 0, P);
  941. CreateDonateLink(19, 1, P);
  942. CreateDonateLink(29, 2, P);
  943. CreateDonateLink(49, 3, P);
  944. AboutDonationCaption := TLabel.Create(DonationPanel);
  945. AboutDonationCaption.Left := 0;
  946. AboutDonationCaption.Top := P + 3 * ScaleY(16) + ScaleY(24);
  947. AboutDonationCaption.Parent := DonationPanel;
  948. AboutDonationCaption.Caption := CustomMessage('AboutDonations');
  949. AboutDonationCaption.OnClick := @AboutDonationsLinkClick;
  950. LinkLabel(AboutDonationCaption);
  951. Image := TBitmapImage.Create(DonationPanel);
  952. LoadEmbededBitmap(Image, '{#PayPalCardImage}', DonationPanel.Color);
  953. Image.AutoSize := True;
  954. Image.Cursor := crHand;
  955. Image.Parent := DonationPanel;
  956. Image.Left := ScaleX(100);
  957. Image.Top := P + ScaleX(8);
  958. Image.Hint := CustomMessage('AboutDonations');
  959. Image.ShowHint := True;
  960. Image.OnClick := @AboutDonationsLinkClick;
  961. DonationPanel.Height := GetBottom(AboutDonationCaption);
  962. #endif
  963. WizardForm.YesRadio.OnClick := @UpdatePostInstallRunCheckboxes;
  964. WizardForm.NoRadio.OnClick := @UpdatePostInstallRunCheckboxes;
  965. UpdatePostInstallRunCheckboxes(nil);
  966. if IsWin8 then
  967. begin
  968. WizardForm.NoIconsCheck.Checked := True;
  969. end;
  970. // 100% images are automatically loaded by
  971. // WizardImageFile and WizardSmallImageFile
  972. if GetScalingFactor > 100 then
  973. begin
  974. LoadEmbededScaledBitmap(WizardForm.WizardBitmapImage, '{#WizardImageFileBase}', 100, 0);
  975. LoadEmbededScaledBitmap(WizardForm.WizardBitmapImage2, '{#WizardImageFileBase}', 100, 0);
  976. LoadEmbededScaledBitmap(WizardForm.WizardSmallBitmapImage, '{#WizardSmallImageFileBase}', 100, 0);
  977. end;
  978. // Text does not scale as quick as with DPI,
  979. // so the icon may overlap the labels. Shift them.
  980. P := WizardForm.SelectDirBitmapImage.Width;
  981. LoadEmbededScaledIcon(WizardForm.SelectDirBitmapImage, '{#SelectDirFileBase}', 32, WizardForm.SelectDirPage.Color);
  982. P := (WizardForm.SelectDirBitmapImage.Width - P);
  983. // Vertical change should be the same as horizontal
  984. WizardForm.SelectDirLabel.Left := WizardForm.SelectDirLabel.Left + P;
  985. WizardForm.SelectDirBrowseLabel.Top := WizardForm.SelectDirBrowseLabel.Top + P;
  986. WizardForm.DirEdit.Top := WizardForm.DirEdit.Top + P;
  987. WizardForm.DirBrowseButton.Top := WizardForm.DirBrowseButton.Top + P;
  988. end;
  989. procedure RegisterPreviousData(PreviousDataKey: Integer);
  990. var
  991. S: string;
  992. begin
  993. if IsTypicalInstallation then S := 'typical'
  994. else S := 'custom';
  995. SetPreviousData(PreviousDataKey, '{#SetupTypeData}', S);
  996. end;
  997. function SaveCheckListBoxState(ListBox: TNewCheckListBox): string;
  998. var
  999. I: Integer;
  1000. begin
  1001. for I := 0 to ListBox.Items.Count - 1 do
  1002. begin
  1003. Result := Result + IntToStr(Integer(ListBox.State[I]));
  1004. end;
  1005. end;
  1006. procedure CurPageChanged(CurPageID: Integer);
  1007. var
  1008. Delta: Integer;
  1009. LineHeight: Integer;
  1010. LaunchCheckboxTop: Integer;
  1011. begin
  1012. if CurPageID = wpLicense then
  1013. begin
  1014. WizardForm.NextButton.Caption := CustomMessage('AcceptButton')
  1015. end;
  1016. if CurPageID = wpSelectDir then
  1017. begin
  1018. if InitDir = '' then
  1019. InitDir := WizardForm.DirEdit.Text;
  1020. end
  1021. else
  1022. if CurPageID = wpSelectComponents then
  1023. begin
  1024. if InitComponents = '' then
  1025. InitComponents := SaveCheckListBoxState(WizardForm.ComponentsList);
  1026. end
  1027. else
  1028. if CurPageID = wpSelectTasks then
  1029. begin
  1030. if InitTasks = '' then
  1031. InitTasks := SaveCheckListBoxState(WizardForm.TasksList);
  1032. end
  1033. else
  1034. if CurPageID = wpInterface then
  1035. begin
  1036. if InitInterface < 0 then
  1037. InitInterface := Integer(CommanderRadioButton.Checked);
  1038. end
  1039. else
  1040. if CurPageID = wpFinished then
  1041. begin
  1042. LineHeight := (WizardForm.NoRadio.Top - WizardForm.YesRadio.Top);
  1043. // Are we at the "Restart?" screen
  1044. if WizardForm.YesRadio.Visible then
  1045. begin
  1046. WizardForm.FinishedLabel.Caption :=
  1047. CustomMessage('FinishedRestartDragExtLabel') + NewLine;
  1048. Delta := WizardForm.AdjustLabelHeight(WizardForm.FinishedLabel);
  1049. WizardForm.YesRadio.Top := WizardForm.YesRadio.Top + Delta;
  1050. WizardForm.NoRadio.Top := WizardForm.NoRadio.Top + Delta;
  1051. LaunchCheckboxTop := WizardForm.NoRadio.Top + LineHeight;
  1052. #ifdef Donations
  1053. DonationPanel.Visible := False;
  1054. #endif
  1055. end
  1056. else
  1057. begin
  1058. LaunchCheckboxTop := WizardForm.RunList.Top;
  1059. end;
  1060. LaunchCheckbox.Top := LaunchCheckboxTop;
  1061. OpenGettingStartedCheckbox.Top := LaunchCheckbox.Top + LineHeight;
  1062. UpdatePostInstallRunCheckboxes(nil);
  1063. #ifdef Donations
  1064. if DonationPanel.Visible then
  1065. begin
  1066. DonationPanel.Top := GetBottom(OpenGettingStartedCheckbox) + ScaleY(12);
  1067. // Hide "about donations" if it does not fit nicely
  1068. // (happens on "long" languages, as German)
  1069. if (DonationPanel.Top + GetBottom(AboutDonationCaption)) >
  1070. (WizardForm.FinishedPage.Height - ScaleY(8)) then
  1071. begin
  1072. AboutDonationCaption.Visible := False;
  1073. end;
  1074. end;
  1075. #endif
  1076. end
  1077. else
  1078. if CurPageID = wpSetupType then
  1079. begin
  1080. Log('License accepted');
  1081. LicenseAccepted := True;
  1082. end
  1083. else
  1084. if CurPageID = wpPreparing then
  1085. begin
  1086. // Are we at the "Restart applications?" screen
  1087. if WizardForm.PreparingLabel.Visible then
  1088. begin
  1089. WizardForm.PreparingLabel.Caption :=
  1090. CustomMessage('ApplicationsFoundDragExt');
  1091. WizardForm.IncTopDecHeight(WizardForm.PreparingMemo,
  1092. WizardForm.AdjustLabelHeight(WizardForm.PreparingLabel));
  1093. end;
  1094. end;
  1095. end;
  1096. function AskedRestart: Boolean;
  1097. begin
  1098. Result := WizardForm.YesRadio.Visible;
  1099. end;
  1100. procedure DeinitializeSetup;
  1101. var
  1102. WinHttpReq: Variant;
  1103. ReportUrl: string;
  1104. ReportData: string;
  1105. begin
  1106. // cannot send report, unless user already accepted license
  1107. // (with privacy policy)
  1108. if LicenseAccepted then
  1109. begin
  1110. Log('Preparing intallation report');
  1111. ReportData := Format(
  1112. 'installed=%d&silent=%d&ver=%s&lang=%s&prevver=%s&', [
  1113. Integer(InstallationDone), Integer(WizardSilent),
  1114. '{#VersionOnly}', ActiveLanguage,
  1115. PrevVersion]);
  1116. try
  1117. ReportUrl := '{#WebReport}?' + ReportData;
  1118. Log('Sending installation report: ' + ReportUrl);
  1119. WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
  1120. WinHttpReq.Open('GET', ReportUrl, False);
  1121. WinHttpReq.Send('');
  1122. Log('Installation report send result: ' + IntToStr(WinHttpReq.Status) + ' ' + WinHttpReq.StatusText);
  1123. except
  1124. Log('Error sending installation report: ' + GetExceptionMessage);
  1125. end;
  1126. end;
  1127. end;
  1128. procedure ExecApp(Params: string; ShowCmd: Integer; Wait: TExecWait);
  1129. var
  1130. Path: string;
  1131. ErrorCode: Integer;
  1132. begin
  1133. Path := ExpandConstant('{app}\{#MainFileName}');
  1134. ExecAsOriginalUser(Path, Params, '', ShowCmd, Wait, ErrorCode)
  1135. end;
  1136. procedure OpenBrowserGettingStarted;
  1137. var
  1138. WebGettingStarted: string;
  1139. begin
  1140. WebGettingStarted :=
  1141. ExpandConstant('{#WebGettingStarted}') + PrevVersion +
  1142. '&automatic=' + IntToStr(Integer(AutomaticUpdate));
  1143. Log('Opening getting started page: ' + WebGettingStarted);
  1144. OpenBrowser(WebGettingStarted);
  1145. end;
  1146. procedure CurStepChanged(CurStep: TSetupStep);
  1147. var
  1148. ShowCmd: Integer;
  1149. OpenGettingStarted: Boolean;
  1150. UsageData: string;
  1151. CanPostInstallRuns: Boolean;
  1152. begin
  1153. if CurStep = ssPostInstall then
  1154. begin
  1155. Log('Post install');
  1156. if Length(MissingTranslations) > 0 then
  1157. begin
  1158. Log('Removing obsolete translations');
  1159. WizardForm.StatusLabel.Caption :=
  1160. CustomMessage('RemovingObsoleteTranslations');
  1161. ProcessMissingTranslations(@DeleteTranslation);
  1162. end;
  1163. InstallationDone := True;
  1164. end
  1165. else
  1166. if CurStep = ssDone then
  1167. begin
  1168. Log('Done');
  1169. // bug in InnoSetup causes it using ssDone even when
  1170. // setup failed because machine was not restarted to complete previous
  1171. // installation. double check that ssPostInstall was called
  1172. if InstallationDone then
  1173. begin
  1174. CanPostInstallRuns := (not WizardSilent) and (not WillRestart);
  1175. OpenGettingStarted :=
  1176. OpenGettingStartedCheckbox.Enabled and
  1177. OpenGettingStartedCheckbox.Checked;
  1178. UsageData := '/Usage=';
  1179. // old style counter
  1180. UsageData := UsageData + Format('TypicalInstallation:%d,', [Integer(IsTypicalInstallation)]);
  1181. // new style counters
  1182. if not Upgrade then
  1183. begin
  1184. if IsTypicalInstallation then
  1185. UsageData := UsageData + 'InstallationsFirstTypical+,'
  1186. else
  1187. UsageData := UsageData + 'InstallationsFirstCustom+,';
  1188. end
  1189. else
  1190. begin
  1191. if AutomaticUpdate then
  1192. UsageData := UsageData + 'InstallationsUpgradeAutomatic+,'
  1193. else if IsTypicalInstallation then
  1194. UsageData := UsageData + 'InstallationsUpgradeTypical+,'
  1195. else
  1196. UsageData := UsageData + 'InstallationsUpgradeCustom+,';
  1197. end;
  1198. if (InitDir <> '') and (InitDir <> WizardForm.DirEdit.Text) then
  1199. UsageData := UsageData + 'InstallationsCustomDir+,';
  1200. if (InitComponents <> '') and (InitComponents <> SaveCheckListBoxState(WizardForm.ComponentsList)) then
  1201. UsageData := UsageData + 'InstallationsCustomComponents+,';
  1202. if (InitTasks <> '') and (InitTasks <> SaveCheckListBoxState(WizardForm.TasksList)) then
  1203. UsageData := UsageData + 'InstallationsCustomTasks+,';
  1204. if (InitInterface >= 0) and (InitInterface <> Integer(CommanderRadioButton.Checked)) then
  1205. UsageData := UsageData + 'InstallationsCustomInterface+,';
  1206. if CanPostInstallRuns and OpenGettingStarted then
  1207. UsageData := UsageData + 'InstallationsGettingStarted+,';
  1208. if CanPostInstallRuns and LaunchCheckbox.Checked then
  1209. UsageData := UsageData + 'InstallationsLaunch+,';
  1210. if WizardSilent then
  1211. UsageData := UsageData + 'InstallationsSilent+,';
  1212. if AskedRestart then
  1213. UsageData := UsageData + 'InstallationsNeedRestart+,';
  1214. if WillRestart then
  1215. UsageData := UsageData + 'InstallationsRestart+,';
  1216. if Donated then
  1217. UsageData := UsageData + 'InstallationsDonate+,';
  1218. // have to do this before running WinSCP GUI instance below,
  1219. // otherwise it loads the empty/previous counters and overwrites our changes,
  1220. // when it's closed
  1221. Log('Recording installer usage statistics: ' + UsageData);
  1222. // make sure we write the counters using the "normal" account
  1223. // (the account that will be used to report the counters)
  1224. ExecApp(UsageData, SW_HIDE, ewWaitUntilTerminated);
  1225. if AutomaticUpdate then
  1226. begin
  1227. Log('Launching WinSCP after automatic update');
  1228. ExecApp('', SW_SHOWNORMAL, ewNoWait);
  1229. if CmdLineParamExists('/OpenGettingStarted') then
  1230. begin
  1231. OpenBrowserGettingStarted;
  1232. end;
  1233. end
  1234. else
  1235. if CanPostInstallRuns then
  1236. begin
  1237. if OpenGettingStarted then
  1238. begin
  1239. OpenBrowserGettingStarted;
  1240. end;
  1241. if LaunchCheckbox.Checked then
  1242. begin
  1243. if OpenGettingStarted then
  1244. begin
  1245. Log('Will launch WinSCP minimized');
  1246. ShowCmd := SW_SHOWMINIMIZED
  1247. end
  1248. else
  1249. begin
  1250. ShowCmd := SW_SHOWNORMAL;
  1251. end;
  1252. Log('Launching WinSCP');
  1253. ExecApp('', ShowCmd, ewNoWait);
  1254. end;
  1255. end;
  1256. end;
  1257. end;
  1258. end;
  1259. function ShouldSkipPage(PageID: Integer): Boolean;
  1260. begin
  1261. Result :=
  1262. { Hide most pages during typical installation }
  1263. IsTypicalInstallation and
  1264. ((PageID = wpSelectDir) or (PageID = wpSelectComponents) or
  1265. (PageID = wpSelectTasks) or
  1266. { Hide Interface page for upgrades only, show for fresh installs }
  1267. ((PageID = wpInterface) and Upgrade));
  1268. end;
  1269. function UpdateReadyMemo(Space, NewLine, MemoUserInfoInfo, MemoDirInfo,
  1270. MemoTypeInfo, MemoComponentsInfo, MemoGroupInfo, MemoTasksInfo: string): string;
  1271. var
  1272. S: string;
  1273. S2: string;
  1274. begin
  1275. S := '';
  1276. S := S + MemoDirInfo + NewLine + NewLine;
  1277. if not Upgrade then
  1278. begin
  1279. if IsTypicalInstallation then S2 := CustomMessage('TypicalType')
  1280. else S2 := CustomMessage('CustomType');
  1281. end
  1282. else
  1283. begin
  1284. if IsTypicalInstallation then S2 := CustomMessage('TypicalUpgradeType')
  1285. else S2 := CustomMessage('CustomUpgradeType');
  1286. end;
  1287. StringChange(S2, '&', '');
  1288. S := S + SetupMessage(msgReadyMemoType) + NewLine + Space + S2 + NewLine + NewLine;
  1289. S := S + MemoComponentsInfo + NewLine + NewLine;
  1290. if Length(MemoGroupInfo) > 0 then
  1291. S := S + MemoGroupInfo + NewLine + NewLine;
  1292. if Length(MemoTasksInfo) > 0 then
  1293. S := S + MemoTasksInfo + NewLine + NewLine;
  1294. S := S + CustomMessage('UserSettingsOverview') + NewLine;
  1295. S := S + Space;
  1296. if CommanderRadioButton.Checked then S2 := CustomMessage('NortonCommanderInterfaceC')
  1297. else S2 := CustomMessage('ExplorerInterfaceC');
  1298. StringChange(S2, '&', '');
  1299. S := S + S2;
  1300. S := S + NewLine;
  1301. Result := S;
  1302. end;
  1303. function InitializeUninstall: Boolean;
  1304. begin
  1305. // let application know that we are running silent uninstall,
  1306. // this turns UninstallCleanup to noop
  1307. if UninstallSilent then
  1308. CreateMutex('WinSCPSilentUninstall');
  1309. Result := True;
  1310. end;
  1311. #expr SaveToFile(AddBackslash(SourcePath) + "Preprocessed.iss")