winwix.mc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. % # Source code for the Puzzles installer.
  2. % #
  3. % # The installer is built using WiX, but this file itself is not valid
  4. % # XML input to WiX's candle.exe; instead, this is a template intended
  5. % # to be processed through the standalone 'mason.pl' script provided
  6. % # with Perl's Mason module.
  7. <%class>
  8. has 'version' => (required => 1);
  9. has 'descfile' => (required => 1);
  10. </%class>
  11. <?xml version="1.0" encoding="utf-8"?>
  12. <?if $(var.Win64) = yes ?>
  13. <?define PlatformProgramFilesFolder = "ProgramFiles64Folder" ?>
  14. <?else ?>
  15. <?define PlatformProgramFilesFolder = "ProgramFilesFolder" ?>
  16. <?endif ?>
  17. <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  18. % # Product tag. The Id component is set to "*", which causes WiX to
  19. % # make up a new GUID every time it's run, whereas UpgradeCode is set
  20. % # to a fixed GUID. This combination allows Windows to
  21. % # recognise each new installer as different (because of Id)
  22. % # versions of the same underlying thing (because of the common
  23. % # UpgradeCode).
  24. <Product
  25. Name="Simon Tatham's Portable Puzzle Collection"
  26. Manufacturer="Simon Tatham"
  27. Id="*"
  28. UpgradeCode="<% invent_guid('upgradecode') %>"
  29. Language="1033" Codepage="1252" Version="<% $winver %>">
  30. % # We force the install scope to perMachine, largely because I
  31. % # don't really understand how to make it usefully switchable
  32. % # between the two. If anyone is a WiX expert and does want to
  33. % # install Puzzles locally in a user account, I hope they'll send a
  34. % # well explained patch!
  35. <Package Id="*" Keywords="Installer"
  36. Description="Simon Tatham's Portable Puzzle Collection installer, version <% $.version %>"
  37. Manufacturer="Simon Tatham"
  38. InstallerVersion="100" Languages="1033"
  39. Compressed="yes" SummaryCodepage="1252"
  40. InstallScope="perMachine" />
  41. % # Permit installing an arbitrary one of these installers
  42. % # over the top of an existing one, whether it's an upgrade or a
  43. % # downgrade.
  44. % #
  45. % # Setting the REINSTALLMODE property to "amus" (from its default
  46. % # of "omus") forces every component replaced by a different
  47. % # version of the installer to be _actually_ reinstalled; the 'o'
  48. % # flag in the default setting breaks the downgrade case by
  49. % # causing Windows to disallow installation of an older version
  50. % # over the top of a newer one - and to do so _silently_, so the
  51. % # installer claims to have worked fine but the files that would have
  52. % # been downgraded aren't there.
  53. <MajorUpgrade AllowDowngrades="yes" MigrateFeatures="yes" />
  54. <Property Id="REINSTALLMODE" Value="amus"/>
  55. % # Boilerplate
  56. <Media Id="1" Cabinet="puzzles.cab" EmbedCab="yes" />
  57. % # The actual directory structure and list of 'components'
  58. % # (individual files or shortcuts or additions to PATH) that are
  59. % # installed.
  60. <Directory Id="TARGETDIR" Name="SourceDir">
  61. <Directory Id="$(var.PlatformProgramFilesFolder)" Name="PFiles">
  62. <Directory Id="INSTALLDIR" Name="Simon Tatham's Portable Puzzle Collection">
  63. % # The following components all install things in the main
  64. % # install directory (implicitly, by being nested where
  65. % # they are in the XML structure). Most of them also put a
  66. % # shortcut in a subdir of the Start menu, though some of
  67. % # the more obscure things like LICENCE are just there for
  68. % # the sake of being _somewhere_ and don't rate a shortcut.
  69. <%method file_component ($prefix, $filename, $shortcutname)>
  70. % my $filename_id = file_component_name($filename);
  71. <Component Id="File_Component_<% $filename_id %>"
  72. Guid="<% invent_guid('file:' . $filename) %>">
  73. <File Id="File_<% $filename_id %>"
  74. Source="<% $prefix %><% $filename %>" KeyPath="yes">
  75. % if (defined $shortcutname) {
  76. <Shortcut Id="startmenu_<% $filename_id %>"
  77. Directory="ProgramMenuDir" WorkingDirectory="INSTALLDIR"
  78. Name="<% $shortcutname %>" Advertise="no" />
  79. % }
  80. </File>
  81. </Component>
  82. </%method>
  83. % for my $exe (@exes) {
  84. <% $.file_component('$(var.Bindir)', $exe, $names{$exe}) %>
  85. % }
  86. <% $.file_component('', "puzzles.chm", "Puzzles Manual") %>
  87. <% $.file_component('', "website.url", "Puzzles Web Site") %>
  88. <% $.file_component('', "LICENCE") %>
  89. </Directory>
  90. </Directory>
  91. % # This component doesn't actually install anything, but it
  92. % # arranges for the Start Menu _directory_ to be removed again
  93. % # on uninstall. All the actual shortcuts inside the directory
  94. % # are placed by code above here.
  95. <Directory Id="ProgramMenuFolder" Name="Programs">
  96. <Directory Id="ProgramMenuDir" Name="Simon Tatham's Portable Puzzle Collection">
  97. <Component Id="ProgramMenuDir"
  98. Guid="<% invent_guid('programmenudir') %>">
  99. <RemoveFolder Id="ProgramMenuDir" On="uninstall" />
  100. <RegistryValue Root="HKLM"
  101. Key="Software\SimonTatham\Puzzles\StartMenu"
  102. Type="string" Value="" KeyPath="yes" />
  103. </Component>
  104. </Directory>
  105. </Directory>
  106. </Directory>
  107. % # Detect an installation of Puzzles made by the old Inno Setup
  108. % # installer, and refuse to run if we find one. I don't know what
  109. % # would happen if you tried anyway, but since they install files
  110. % # at the same pathnames, it surely wouldn't end well.
  111. % #
  112. % # It could be argued that a better approach would be to actually
  113. % # _launch_ the Inno Setup uninstaller automatically at this
  114. % # point (prompting the user first, of course), but I'm not
  115. % # nearly skilled enough with WiX to know how, or even if it's
  116. % # feasible.
  117. <Property Id="LEGACYINNOSETUPINSTALLERNATIVE32PROPERTY">
  118. <RegistrySearch
  119. Id="LegacyInnoSetupInstallerNative32RegSearch"
  120. Root="HKLM"
  121. Key="SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Simon Tatham's Portable Puzzle Collection_is1"
  122. Name="QuietUninstallString" Type="raw" />
  123. </Property>
  124. <Property Id="LEGACYINNOSETUPINSTALLER32ON64PROPERTY">
  125. <RegistrySearch
  126. Id="LegacyInnoSetupInstaller32On64RegSearch"
  127. Root="HKLM"
  128. Key="SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Simon Tatham's Portable Puzzle Collection_is1"
  129. Name="QuietUninstallString" Type="raw" />
  130. </Property>
  131. <Condition Message="A version of this software is already installed on this system using its old Inno Setup installer. Please uninstall that before running the new installer.">
  132. <![CDATA[Installed OR
  133. (LEGACYINNOSETUPINSTALLERNATIVE32PROPERTY = "" AND
  134. LEGACYINNOSETUPINSTALLER32ON64PROPERTY = "")]]>
  135. </Condition>
  136. % # Separate the installation into 'features', which are parts of
  137. % # the install that can be chosen separately. Trivial: there is only
  138. % # one feature here.
  139. <Feature Id="FilesFeature" Level="1" Absent="disallow" AllowAdvertise="no"
  140. Title="Install puzzle games">
  141. % for my $exe (@exes) {
  142. <ComponentRef Id="File_Component_<% file_component_name($exe) %>" />
  143. % }
  144. <ComponentRef Id="File_Component_<% file_component_name("puzzles.chm") %>" />
  145. <ComponentRef Id="File_Component_<% file_component_name("website.url") %>" />
  146. <ComponentRef Id="File_Component_<% file_component_name("LICENCE") %>" />
  147. <ComponentRef Id="ProgramMenuDir" />
  148. </Feature>
  149. % # Installer user interface.
  150. % #
  151. % # Basically like WixUI_InstallDir, only I've ripped out the EULA.
  152. <UIRef Id="WixUI_Common" />
  153. <UI>
  154. <TextStyle Id="WixUI_Font_Normal" FaceName="Tahoma" Size="8" />
  155. <TextStyle Id="WixUI_Font_Bigger" FaceName="Tahoma" Size="12" />
  156. <TextStyle Id="WixUI_Font_Title" FaceName="Tahoma" Size="9" Bold="yes" />
  157. <Property Id="DefaultUIFont" Value="WixUI_Font_Normal" />
  158. <Property Id="WixUI_Mode" Value="InstallDir" />
  159. <DialogRef Id="BrowseDlg" />
  160. <DialogRef Id="DiskCostDlg" />
  161. <DialogRef Id="ErrorDlg" />
  162. <DialogRef Id="FatalError" />
  163. <DialogRef Id="FilesInUse" />
  164. <DialogRef Id="MsiRMFilesInUse" />
  165. <DialogRef Id="PrepareDlg" />
  166. <DialogRef Id="ProgressDlg" />
  167. <DialogRef Id="ResumeDlg" />
  168. <DialogRef Id="UserExit" />
  169. <Publish Dialog="BrowseDlg" Control="OK" Event="DoAction" Value="WixUIValidatePath" Order="3">1</Publish>
  170. <Publish Dialog="BrowseDlg" Control="OK" Event="SpawnDialog" Value="InvalidDirDlg" Order="4"><![CDATA[NOT WIXUI_DONTVALIDATEPATH AND WIXUI_INSTALLDIR_VALID<>"1"]]></Publish>
  171. <Publish Dialog="ExitDialog" Control="Finish" Event="EndDialog" Value="Return" Order="999">1</Publish>
  172. <Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="InstallDirDlg">NOT Installed</Publish>
  173. <Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg">Installed</Publish>
  174. <Publish Dialog="InstallDirDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg">1</Publish>
  175. <Publish Dialog="InstallDirDlg" Control="Next" Event="SetTargetPath" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
  176. <Publish Dialog="InstallDirDlg" Control="Next" Event="DoAction" Value="WixUIValidatePath" Order="2">NOT WIXUI_DONTVALIDATEPATH</Publish>
  177. <Publish Dialog="InstallDirDlg" Control="Next" Event="SpawnDialog" Value="InvalidDirDlg" Order="3"><![CDATA[NOT WIXUI_DONTVALIDATEPATH AND WIXUI_INSTALLDIR_VALID<>"1"]]></Publish>
  178. <Publish Dialog="InstallDirDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="4">WIXUI_DONTVALIDATEPATH OR WIXUI_INSTALLDIR_VALID="1"</Publish>
  179. <Publish Dialog="InstallDirDlg" Control="ChangeFolder" Property="_BrowseProperty" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
  180. <Publish Dialog="InstallDirDlg" Control="ChangeFolder" Event="SpawnDialog" Value="BrowseDlg" Order="2">1</Publish>
  181. <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="InstallDirDlg" Order="1">NOT Installed</Publish>
  182. <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="MaintenanceTypeDlg" Order="2">Installed AND NOT PATCH</Publish>
  183. <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="2">Installed AND PATCH</Publish>
  184. <Publish Dialog="MaintenanceWelcomeDlg" Control="Next" Event="NewDialog" Value="MaintenanceTypeDlg">1</Publish>
  185. <Publish Dialog="MaintenanceTypeDlg" Control="RepairButton" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
  186. <Publish Dialog="MaintenanceTypeDlg" Control="RemoveButton" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
  187. <Publish Dialog="MaintenanceTypeDlg" Control="Back" Event="NewDialog" Value="MaintenanceWelcomeDlg">1</Publish>
  188. % # This ARPNOMODIFY flag prohibits changing the set of
  189. % # installed features, because we don't have any.
  190. <Property Id="ARPNOMODIFY" Value="1" />
  191. </UI>
  192. % # Glue: tell the install dir part of the UI what id my actual
  193. % # install dir is known by. Otherwise the former won't know how
  194. % # to alter the setting of the latter.
  195. <Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR" />
  196. % # Include my custom installer artwork, created in Buildscr. FIXME:
  197. % # create some!
  198. % # <WixVariable Id="WixUIDialogBmp" Value="msidialog.bmp" />
  199. % # <WixVariable Id="WixUIBannerBmp" Value="msibanner.bmp" />
  200. </Product>
  201. </Wix>
  202. <%init>
  203. use Digest::SHA qw(sha512_hex);
  204. use Time::Local;
  205. die "bad date format" if $.version !~ /^(\d{4})(\d{2})(\d{2})/;
  206. my $date = timegm(0,0,0,$3,$2-1,$1);
  207. my $integer_date = int($date / 86400) - 6000;
  208. my $winver = sprintf "0.0.%d.0", $integer_date;
  209. my @exes;
  210. my %names;
  211. {
  212. open my $descfh, "<", $.descfile or die "$.descfile: open: $!\n";
  213. while (<$descfh>) {
  214. chomp;
  215. my @fields = split /:/;
  216. push @exes, $fields[1];
  217. $names{$fields[1]} = $fields[2];
  218. }
  219. close $descfh;
  220. }
  221. sub file_component_name($) {
  222. my ($id) = @_;
  223. $id =~ s!.*\\!!;
  224. $id =~ y!A-Za-z0-9!_!cs;
  225. return $id;
  226. }
  227. sub invent_guid($) {
  228. my ($name) = @_;
  229. # Invent a GUID. We'll need a lot of these in this installer - one
  230. # per puzzle game and a few standard ones - and we'd like to
  231. # arrange for them to be stable between versions of the installer,
  232. # while not having to _manually_ invent one every time.
  233. #
  234. # So we generate our GUIDs by hashing a pile of fixed (but
  235. # originally randomly generated) data with an identifying string
  236. # that acts as source for the particular GUID. For example,
  237. # hashing (fixed_random_data || "upgradecode") produces the GUID
  238. # used as the upgrade code, and (fixed_random_data ||
  239. # "installfile:" || filename) gives the GUID for an MSI component
  240. # that installs a specific file.
  241. #
  242. # Hashing _just_ the id strings would clearly be cheating (it's
  243. # quite conceivable that someone might hash the same string for
  244. # another reason and so generate a colliding GUID), but hashing a
  245. # whole SHA-512 data block of random gibberish as well should make
  246. # these GUIDs pseudo-random enough to not collide with anyone
  247. # else's.
  248. my $randdata = pack "N*",
  249. 0xCCAA8D31,0x42931BD9,0xA9D9878A,0x72E4FB9C,0xEA9B11DE,0x4FF17AEC,
  250. 0x1AFA2DEC,0xB662640A,0x780143F5,0xBFFFF0FC,0x01CB46CF,0x832AE842,
  251. 0xBCCDDA12,0x4DB24889,0xEC7A9BCD,0xBCCF70ED,0x85800659,0x8ABA9524,
  252. 0xE484F8D6,0x5CBE55B3,0x95AD9B3D,0x0555F432,0x46737F89,0xE981471C,
  253. 0x4B3419AD,0xD4E49DF4,0xB3EF69DE,0x2A7E391E,0xF3C3D370,0x3EA5E9FC,
  254. 0xB35A57ED,0x52B21099,0x9BD99092,0x7B5097AE,0x4DBE59BD,0x2FCC709B,
  255. 0xC555A779,0x4AE2E5AB,0xB7C74314,0x7F9194CF,0x8FFBCA88,0x46263306,
  256. 0x4C714DF7,0x07FE8CEE,0x28974885,0x0869865D,0xBB5B0EA4,0x4064A928,
  257. 0x28C41910,0x07030758,0x19E66319,0x050C9D4E,0xD79A37FB,0xF232D98B,
  258. 0x0C3E4C25,0xC94F865B,0xB6D86BED,0x87DB718D,0xC65D4C43,0x7C8BBF6A,
  259. 0x9DFDD26A,0x8C478976,0x53E47640,0x263E04AA,0xDD7C5456,0x766BDF50,
  260. 0x86946E34,0xE80D8DE3,0xFB92949E,0x691FDAD0,0x96AB210D,0xB278D60B,
  261. 0x71C7DC6B,0xD49846FC,0x38953F66,0x39777D72,0x4A0F80E5,0xFE1DD1A4,
  262. 0xDA9D191A,0xA32844AD,0x171BFBCC,0xA7D556F6,0xF9F6D944,0xF9687060,
  263. 0xDDDB81D0,0xE9AF4F2F,0xEF84685A,0x8A172492,0x50615EFC,0x20817881,
  264. 0xC3E507E5,0x33189771,0xB9E2EBBD,0x2AAE34A3,0x8D3E7486,0x0A448F13,
  265. 0x94F92A81,0x5150A34F,0x5ED50563,0xAD801A42,0xD0617AFA,0xB78F85F7,
  266. 0x0019D384,0xF0F1C06F,0x6EF8D5B3,0x38092D09,0xC87CD4B3,0xE9D8C84F,
  267. 0xE036648C,0xF2500BD9,0xCF069B5C,0x835326BA,0xCD107B6A,0x64F152B3,
  268. 0xA9663E24,0x33ED5E08,0xC3B24F7E,0xA83205C8,0xA0560F30,0xDFF1226E,
  269. 0xF1A404B7,0x9C2B4EF2,0x62802F88,0xE393A05F,0xC7F72F7B,0x1CD989BD,
  270. 0x725AB516,0xA84F7E39,0xACC3572A,0x820ACB2D,0xAFF5BF06,0x476A2405,
  271. 0x90953482,0x8E8035E1,0x1FB95F6E,0x01FD6766,0x1E63D78E,0xD7D42220,
  272. 0x188D23E4,0x1941BCC5,0xEE1E6487,0x6E197F82,0x32772265,0x9B79D0C8,
  273. 0xB4B617A1,0xCD2475B4,0xDE0F410B,0xE9CF69E4,0x831AC9A4,0xD549A00E,
  274. 0x12ECC561,0x3D636A43,0x1FFFC99A,0xF79401C5,0xAA1D8251,0x84D29609,
  275. 0x5464CB71,0xB28AAE5A,0x4AD934FC,0x347E8A5D,0xC87BCBA0,0x67172E33,
  276. 0xEC70E245,0x4289A9EF,0xA8AF6BA5,0x1528FE0C,0xA87CBFF8,0x79AE1554,
  277. 0xBD59DB9E,0xF1879F94,0x14D7E9F6,0x85196447,0xC4363A67,0x7E02A325,
  278. 0x54051E05,0xABAFE646,0x65D5DF96,0xD3F8173B,0x09D475E7,0x9BF7BD0C,
  279. 0x2DAF371A,0x793D063C,0xA68FD47B,0xBE2500A7,0x0D5071C4,0x08384AC8,
  280. 0xF6CFE74E,0x124A5086,0x03475917,0x47267765,0x56F7DF31,0xE5696381,
  281. 0xEB2B4668,0x78345B5B,0x6E2AFC0F,0x3AD0D43B,0x5C3C2BC9,0x833AB4A0,
  282. 0x1DE2CDBF,0x4DDDCF58,0xEA25D69B,0x36E9B3B0,0xC8B11465,0x066A997E,
  283. 0x9D51C7CD,0x8C6AE686,0xAFB06CE6,0xCC3F3017,0x6E4E4CC0,0x85A34875,
  284. 0x498FE759,0xC24B6332,0xEBCD2257,0xE70FC659,0x439EC788,0xB47F2A06,
  285. 0x696EE8A7,0xF70A31B8,0xECD840F7,0x80AE5E7A,0xC6EDF8AE,0x8165EAFD,
  286. 0x5DAE5ADE,0x9FFD39CE,0xFC6B4C23,0x02BCA024,0xC1497A68,0xD18153EF,
  287. 0xD787EA51,0x91386720,0xBF6E2200,0x98638391,0x144B9148,0x9A554DE1,
  288. 0xA940DC7F,0x37C08265,0x7B782C60,0xC081FDD7,0x62B47201,0x43427563,
  289. 0x1B66E983,0x3DAC0305,0x21E9DEA8,0xA9490EE0,0xE2EFD37D,0x3501F306,
  290. 0x16361BD5,0x668B219D,0x17177844,0x3861A9A4,0x222403B2,0xB29F6714,
  291. 0x7A2A938A,0xBC797418,0x3B241624,0x9163C3F2;
  292. my $digest = sha512_hex($name . "\0" . $randdata);
  293. return sprintf("%s-%s-%04x-%04x-%s",
  294. substr($digest,0,8),
  295. substr($digest,8,4),
  296. 0x4000 | (0xFFF & hex(substr($digest,12,4))),
  297. 0x8000 | (0x3FFF & hex(substr($digest,16,4))),
  298. substr($digest,20,12));
  299. }
  300. </%init>