lynx.iss 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. ; $LynxId: lynx.iss,v 1.12 2014/01/09 00:26:08 tom Exp $
  2. ; vile:ts=2 sw=2 notabinsert
  3. ;
  4. ; This is the BASE script for different flavors of the installer for Lynx.
  5. ; It can be overridden to select different source-executables (and their associated
  6. ; screen library, e.g., pdcurses or slang).
  7. ;
  8. ; The script assumes environment variables have been set, e.g., to point to
  9. ; data which is used by the installer:
  10. ;
  11. ; LYNX_BINDIR - directory containing lynx.exe (or different names)
  12. ; LYNX_DLLSDIR - directory containing curses or slang dlls.
  13. ; LYNX_DOCSDIR - files and subdirectories installed from Unix with "make install-doc"
  14. ; LYNX_HELPDIR - files and subdirectories installed from Unix with "make install-help"
  15. #include "version.iss"
  16. #ifndef MyAppExeName
  17. #define MyAppExeName "lynx.exe"
  18. #endif
  19. #define MySendTo '{sendto}\' + myAppName + '.lnk'
  20. #define MyQuickLaunch '{userappdata}\Microsoft\Internet Explorer\Quick Launch\' + myAppName + '.lnk'
  21. #ifndef SourceExeName
  22. #define SourceExeName "lynx.exe"
  23. #endif
  24. #ifndef NoScreenDll
  25. #ifndef ScreenDllName
  26. #define ScreenDllName "pdcurses.dll"
  27. #endif
  28. #endif
  29. #ifndef BzipDllName
  30. #define BzipDllName "libbz2.dll"
  31. #endif
  32. #ifndef ZlibDllName
  33. #define ZlibDllName "zlib.dll"
  34. #endif
  35. #ifndef BzipExeName
  36. #define BzipExeName "bzip2.exe"
  37. #endif
  38. #ifndef GzipExeName
  39. #define GzipExeName "gzip.exe"
  40. #endif
  41. #ifndef SetupBaseName
  42. #define SetupBaseName "lynx"
  43. #endif
  44. #ifndef BinsSrcDir
  45. #define BinsSrcDir GetEnv("LYNX_BINDIR")
  46. #if BinsSrcDir == ""
  47. #define BinsSrcDir "..\bin"
  48. #endif
  49. #endif
  50. #ifndef DllsSrcDir
  51. #define DllsSrcDir GetEnv("LYNX_DLLSDIR")
  52. #if DllsSrcDir == ""
  53. #define DllsSrcDir "..\dlls"
  54. #endif
  55. #endif
  56. #ifndef DocsSrcDir
  57. #define DocsSrcDir GetEnv("LYNX_DOCSDIR")
  58. #if DocsSrcDir == ""
  59. #define DocsSrcDir "..\docs"
  60. #endif
  61. #endif
  62. #ifndef HelpSrcDir
  63. #define HelpSrcDir GetEnv("LYNX_HELPDIR")
  64. #if HelpSrcDir == ""
  65. #define HelpSrcDir "..\lynx_help"
  66. #endif
  67. #endif
  68. [Setup]
  69. AppName={#MyAppName}
  70. #emit 'AppVersion=' + LYNX_VERSION
  71. #emit 'VersionInfoDescription=Setup for "' + MyAppName + '"'
  72. #define LYNX_TARGET0 StringChange(LYNX_VERSION,LYNX_RELEASE + "rel.",LYNX_RELEASE + ".00")
  73. #define LYNX_TARGET1 StringChange(LYNX_TARGET0,LYNX_TARGETS + "dev.",LYNX_RELEASE + ".10")
  74. #define LYNX_TARGET2 StringChange(LYNX_TARGET1,LYNX_TARGETS + "pre.",LYNX_RELEASE + ".20")
  75. #emit 'VersionInfoVersion=' + LYNX_TARGET2
  76. AppVerName={#MyAppVerName}
  77. AppPublisher={#MyAppPublisher}
  78. AppCopyright=© 1997-2013,2014, Thomas E. Dickey
  79. AppPublisherURL={#MyAppURL}
  80. AppSupportURL={#MyAppURL}
  81. AppUpdatesURL={#MyAppURL}
  82. DefaultDirName={pf}\{#MyAppName}
  83. DefaultGroupName={#MyAppName}
  84. AllowNoIcons=yes
  85. LicenseFile=..\COPYHEADER
  86. InfoBeforeFile=..\README
  87. OutputDir=..\PACKAGE\lynx-setup
  88. #emit 'OutputBaseFilename=' + SetupBaseName + LYNX_VERSION + '-setup'
  89. Compression=lzma
  90. SolidCompression=yes
  91. PrivilegesRequired=none
  92. [Languages]
  93. Name: "english"; MessagesFile: "compiler:Default.isl"
  94. [Components]
  95. Name: main; Description: The Lynx executable; types: full custom compact
  96. Name: explorer; Description: Windows Explorer integration; types: full custom
  97. [Tasks]
  98. Name: for_all_users; Description: Install for all users on this machine; GroupDescription: Configuration Settings; Components: main; Check: isGuru; Flags: unchecked
  99. Name: register_vars; Description: Use registry for environment variables; GroupDescription: Configuration Settings; Components: main; Flags: unchecked
  100. Name: use_sendto; Description: Add Send To Entry; GroupDescription: Windows Explorer; Components: explorer; Flags: unchecked
  101. Name: desktopicon; Description: {cm:CreateDesktopIcon}; GroupDescription: {cm:AdditionalIcons}; Components: main; Flags: unchecked
  102. Name: quicklaunchicon; Description: {cm:CreateQuickLaunchIcon}; GroupDescription: {cm:AdditionalIcons}; Components: main; Flags: unchecked
  103. [Dirs]
  104. Name: "{app}\doc"
  105. Name: "{app}\doc\samples"
  106. Name: "{app}\doc\test"
  107. Name: "{app}\help"
  108. Name: "{app}\help\keystrokes"
  109. Name: "{app}\icon"
  110. Name: "{app}\tmp"
  111. [Files]
  112. #emit 'Source: "' + BinsSrcDir + '\' + SourceExeName + '"; DestDir: "{app}"; DestName: ' + MyAppExeName + '; AfterInstall: myPostExecutable; Flags: ignoreversion'
  113. #ifndef NoScreenDll
  114. #emit 'Source: "' + DllsSrcDir + '\' + ScreenDllName + '"; DestDir: "{app}"; DestName: ' + ScreenDllName + '; Flags: ignoreversion'
  115. #endif
  116. #emit 'Source: "' + DllsSrcDir + '\' + ZlibDllName + '"; DestDir: "{app}"; DestName: ' + ZlibDllName + '; Flags: ignoreversion'
  117. #emit 'Source: "' + DllsSrcDir + '\' + BzipDllName + '"; DestDir: "{app}"; DestName: ' + BzipDllName + '; Flags: ignoreversion'
  118. #emit 'Source: "' + DllsSrcDir + '\' + BzipExeName + '"; DestDir: "{app}"; DestName: ' + BzipExeName + '; Flags: ignoreversion'
  119. #emit 'Source: "' + DllsSrcDir + '\' + GzipExeName + '"; DestDir: "{app}"; DestName: ' + GzipExeName + '; Flags: ignoreversion'
  120. #emit 'Source: "' + DocsSrcDir + '\*.*"; DestDir: "{app}\doc"; Flags: '
  121. #emit 'Source: "' + DocsSrcDir + '\samples\*.*"; DestDir: "{app}\doc\samples"; Flags: '
  122. #emit 'Source: "' + DocsSrcDir + '\test\*.*"; DestDir: "{app}\doc\test"; Flags: '
  123. #emit 'Source: "' + HelpSrcDir + '\*.*"; DestDir: "{app}\help"; Flags: '
  124. #emit 'Source: "' + HelpSrcDir + '\keystrokes\*.*"; DestDir: "{app}\help\keystrokes"; Flags: '
  125. ; some of these data files are from an earlier installer by Claudio Santambrogio
  126. Source: "..\samples\lynx.ico"; DestDir: "{app}\icon"
  127. Source: "..\samples\lynx.bat"; DestDir: "{app}"
  128. Source: "..\samples\jumps.htm"; DestDir: "{app}"
  129. Source: "..\samples\home.htm"; DestDir: "{app}"
  130. Source: "..\samples\lynx_bookmarks.htm"; DestDir: "{app}"
  131. Source: "..\samples\*.lss"; DestDir: "{app}"
  132. Source: "..\samples\lynx.bat"; DestDir: "{app}"
  133. Source: "..\samples\lynx-demo.cfg"; DestDir: "{app}"
  134. Source: "..\lynx.man"; DestDir: "{app}"
  135. Source: "..\lynx.cfg"; DestDir: "{app}" ; AfterInstall: myCustomCfg; Flags: ignoreversion
  136. ; NOTE: Don't use "Flags: ignoreversion" on any shared system files
  137. [Icons]
  138. Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
  139. Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
  140. Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
  141. [Run]
  142. Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#MyAppName}}"; Flags: nowait postinstall skipifsilent
  143. [UninstallDelete]
  144. Type: files; Name: {app}\.lynx_cookies
  145. Type: dirifempty; Name: {app}
  146. #emit 'Type: files; Name: ' + mySendTo
  147. #emit 'Type: files; Name: ' + myQuickLaunch
  148. [Code]
  149. #emit 'const MY_APP_NAME = ''{app}\' + myAppName + '.exe'';'
  150. function isGuru(): Boolean;
  151. begin
  152. Result := isAdminLoggedOn();
  153. end;
  154. function environRootKey(): Integer;
  155. begin
  156. Result := HKEY_CURRENT_USER;
  157. end;
  158. function appKey(): string;
  159. begin
  160. Result := 'Software\Lynx';
  161. end;
  162. function envSubKey(): string;
  163. begin
  164. Result := 'Environment';
  165. end;
  166. function appSubKey(): string;
  167. begin
  168. Result := appKey() + '\' + envSubKey();
  169. end;
  170. function envSysKey(): string;
  171. begin
  172. Result := 'System\CurrentControlSet\Control\Session Manager\Environment';
  173. end;
  174. // Set the environment variable ValueName.
  175. procedure addVarToEnv(const RootKey: Integer; const SubKeyName, ValueName, toAdd: String);
  176. var
  177. Updated : string;
  178. begin
  179. Updated := ExpandConstant(toAdd);
  180. RegWriteStringValue(RootKey, SubKeyName, ValueName, Updated);
  181. Log('Added ' + toAdd + ' to ' + ValueName);
  182. // MsgBox('addVarToEnv: ' #13#13 + ValueName + '="' + Updated + '"', mbInformation, MB_OK)
  183. end;
  184. // Remove the given environment variable ValueName.
  185. function removeVarFromEnv(const RootKey: Integer; const SubKeyName, ValueName: String): Boolean;
  186. var
  187. Current : string;
  188. begin
  189. Result := False;
  190. if RegQueryStringValue(RootKey, SubKeyName, ValueName, Current) then
  191. begin
  192. RegDeleteValue(RootKey, SubKeyName, ValueName);
  193. Result := True;
  194. Log('Removed ' + ValueName);
  195. // MsgBox('removeVarFromEnv: ' #13#13 + ValueName + '="' + Current + '"', mbInformation, MB_OK)
  196. end;
  197. end;
  198. function selectedVarsRootKey(): Integer;
  199. begin
  200. if isTaskSelected('for_all_users') then
  201. Result := HKEY_LOCAL_MACHINE
  202. else
  203. Result := HKEY_CURRENT_USER;
  204. end;
  205. function selectedVarsSubKey(): String;
  206. begin
  207. if isTaskSelected('for_all_users') then
  208. begin
  209. if isTaskSelected('register_vars') then
  210. Result := appSubKey()
  211. else
  212. Result := envSysKey();
  213. end else
  214. begin
  215. if isTaskSelected('register_vars') then
  216. Result := appSubKey()
  217. else
  218. Result := envSubKey();
  219. end;
  220. end;
  221. procedure addAnyVariable(const ValueName, newValue: String);
  222. begin
  223. addVarToEnv(selectedVarsRootKey(), selectedVarsSubKey(), ValueName, NewValue);
  224. end;
  225. // FIXME: should only remove if it matches the installer's value
  226. procedure removeAnyVariable(const ValueName: String);
  227. begin
  228. removeVarFromEnv(HKEY_CURRENT_USER, envSubKey(), ValueName);
  229. removeVarFromEnv(HKEY_CURRENT_USER, appSubKey(), ValueName);
  230. removeVarFromEnv(HKEY_LOCAL_MACHINE, appSubKey(), ValueName);
  231. removeVarFromEnv(HKEY_LOCAL_MACHINE, envSysKey(), ValueName);
  232. end;
  233. // http://www.delphidabbler.com/articles?article=12
  234. procedure AddSendTo();
  235. begin
  236. CreateShellLink(
  237. #emit 'ExpandConstant(''' + MySendTo + '''),'
  238. #emit '''SendTo link for ' + myAppName + ''','
  239. ExpandConstant(MY_APP_NAME), // program
  240. '', // option(s) will be followed by pathname
  241. '', // no target directory
  242. '', // no icon filename
  243. -1, // no icon index
  244. SW_SHOWNORMAL);
  245. end;
  246. procedure AddQuickLaunch();
  247. begin
  248. CreateShellLink(
  249. #emit 'ExpandConstant(''' + MyQuickLaunch + '''),'
  250. #emit '''SendTo link for ' + myAppName + ''','
  251. ExpandConstant(MY_APP_NAME), // program
  252. '', // option(s) will be followed by pathname
  253. '', // no target directory
  254. '', // no icon filename
  255. -1, // no icon index
  256. SW_SHOWNORMAL);
  257. end;
  258. // This is called after installing the executable.
  259. procedure myPostExecutable();
  260. var
  261. Keypath : String;
  262. AppDir : String;
  263. begin
  264. Keypath := appKey();
  265. AppDir := ExpandConstant('{app}');
  266. Log('Setting registry key "' + Keypath + '" to "' + AppDir + '"');
  267. if not RegWriteStringValue(selectedVarsRootKey(), Keypath, '', AppDir) then
  268. Log('Failed to set key');
  269. if isTaskSelected('use_sendto') then
  270. begin
  271. AddSendTo();
  272. Log('** added Send-To link');
  273. end;
  274. if isTaskSelected('quicklaunchicon') then
  275. begin
  276. AddQuickLaunch();
  277. Log('** added Quick-launch link');
  278. end;
  279. end;
  280. // This is called after installing the lynx.cfg file.
  281. procedure myCustomCfg();
  282. var
  283. AppDir : String;
  284. CfgFile : String;
  285. begin
  286. AppDir := ExpandConstant('{app}');
  287. CfgFile := AppDir + '\lynx.cfg';
  288. addAnyVariable('LYNX_CFG', CfgFile);
  289. Log('** set LYNX_CFG=' + CfgFile);
  290. SaveStringToFile(CfgFile, 'HELPFILE:' + AppDir + '/help/Lynx_help_main.html.gz' + #10, True);
  291. SaveStringToFile(CfgFile, 'COLOR_STYLE:' + AppDir + '/opaque.lss' + #10, True);
  292. SaveStringToFile(CfgFile, 'CHMOD_PATH:' + #10, True);
  293. SaveStringToFile(CfgFile, 'COPY_PATH:' + #10, True);
  294. SaveStringToFile(CfgFile, 'MKDIR_PATH:' + #10, True);
  295. SaveStringToFile(CfgFile, 'MV_PATH:' + #10, True);
  296. SaveStringToFile(CfgFile, 'RMDIR_PATH:' + #10, True);
  297. SaveStringToFile(CfgFile, 'RM_PATH:' + #10, True);
  298. SaveStringToFile(CfgFile, 'TOUCH_PATH:' + #10, True);
  299. Log('** customized ' + CfgFile);
  300. if isTaskSelected('use_sendto') then
  301. begin
  302. AddSendTo();
  303. Log('** added Send-To link');
  304. end;
  305. end;
  306. function CleanupMyKey(const theRootKey: Integer): Boolean;
  307. var
  308. Path : String;
  309. Value : String;
  310. begin
  311. Result := False;
  312. if RegQueryStringValue(theRootKey, appKey(), '', Value) then
  313. begin
  314. if Value <> '' then
  315. begin
  316. Result := True;
  317. Log('Deleting value of "' + appKey() + '" = "' + Value + '"');
  318. if not RegDeleteValue(theRootKey, appKey(), '') then
  319. Log('Failed to delete value');
  320. Path := appKey() + '\Environment';
  321. Log('Checking for subkey "' + Path + '"');
  322. if RegValueExists(theRootKey, Path, '') then
  323. begin
  324. if RegDeleteKeyIncludingSubkeys(theRootKey, Path) then
  325. Log('Deleted key "' + Path + '"')
  326. else
  327. Log('Failed to delete key "' + Path + '"');
  328. end;
  329. if RegDeleteKeyIfEmpty(theRootKey, appKey()) then
  330. Log('Deleted key "' + appKey() + '"')
  331. else
  332. Log('Failed to delete key "' + appKey() + '"');
  333. end
  334. end
  335. end;
  336. // On uninstall, we do not know which registry setting was selected during install, so we remove all.
  337. procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
  338. begin
  339. case CurUninstallStep of
  340. usUninstall:
  341. begin
  342. // MsgBox('CurUninstallStepChanged:' #13#13 'Uninstall is about to start.', mbInformation, MB_OK)
  343. // ...insert code to perform pre-uninstall tasks here...
  344. end;
  345. usPostUninstall:
  346. begin
  347. removeAnyVariable('LYNX_CFG');
  348. {
  349. If we don't find the settings in the current user, try the local machine.
  350. The setup program cannot pass the all-users flag to the uninstaller, so we
  351. have to try both.
  352. }
  353. Log('Checking current-user registry key');
  354. if not CleanupMyKey(HKEY_CURRENT_USER) then
  355. begin
  356. Log('Checking local-machine registry key');
  357. CleanupMyKey(HKEY_LOCAL_MACHINE);
  358. end;
  359. // MsgBox('CurUninstallStepChanged:' #13#13 'Uninstall just finished.', mbInformation, MB_OK);
  360. end;
  361. end;
  362. end;