| 1 |
(use file.util) |
| 2 |
(use gauche.parseopt) |
| 3 |
(use gauche.process) |
| 4 |
(use srfi.13) |
| 5 |
(use sxml.serializer) |
| 6 |
(use sxml.ssax) |
| 7 |
(use sxml.sxpath) |
| 8 |
(use sxml.tools) |
| 9 |
(use sxml.tree-trans) |
| 10 |
(use util.match) |
| 11 |
|
| 12 |
(define *wix-ns* "http://schemas.microsoft.com/wix/2006/wi") |
| 13 |
(define *program-files-folder* "ProgramFilesFolder") |
| 14 |
|
| 15 |
(define (wix-template version file-tree) |
| 16 |
`(Wix |
| 17 |
(@ (xmlns ,*wix-ns*)) |
| 18 |
;; |
| 19 |
;; Main product description |
| 20 |
;; |
| 21 |
(Product |
| 22 |
(@ (Id "*") |
| 23 |
(Name "Gauche") |
| 24 |
(Language "1033") |
| 25 |
(Version ,version) |
| 26 |
(Manufacturer "Shiro Kawai") |
| 27 |
(UpgradeCode "79ee0cec-691c-4945-b47a-10b9f53b5859")) |
| 28 |
(Package |
| 29 |
(@ (Description "Gauche Scheme Script Engine") |
| 30 |
(Comments "Script-friendly R7RS-conformant Scheme Implementation") |
| 31 |
(Manufacturer "Shiro Kawai") |
| 32 |
(InstallerVersion "200") |
| 33 |
(Compressed "yes"))) |
| 34 |
|
| 35 |
(UIRef (@ (Id "WixUI_InstallDirCustom"))) |
| 36 |
(Property (@ (Id "WIXUI_INSTALLDIR") (Value "INSTALLDIR"))) |
| 37 |
(Property (@ (Id "CUSTOM_DESCTOPSHORTCUT") (Value "1"))) |
| 38 |
(Property (@ (Id "CUSTOM_ASSOCIATEEXTENSION") (Value "1"))) |
| 39 |
(WixVariable (@ (Id "WixUILicenseRtf") (Value "Gauche\\COPYING.rtf"))) |
| 40 |
(Media (@ (Id "1") (Cabinet "gauche.cab") (EmbedCab "yes"))) |
| 41 |
(Icon (@ (Id "AppIcon.ico") (SourceFile "gauche-logo.ico"))) |
| 42 |
(Property (@ (Id "ARPPRODUCTICON") (Value "AppIcon.ico"))) |
| 43 |
|
| 44 |
;; |
| 45 |
;; The 'meat' of the installed components |
| 46 |
;; |
| 47 |
(Directory |
| 48 |
(@ (Id "TARGETDIR") (Name "SourceDir")) |
| 49 |
(Directory |
| 50 |
(@ (Id ,*program-files-folder*)) |
| 51 |
;; Files under Gauche/ directory tree |
| 52 |
(Directory |
| 53 |
(@ (Id "INSTALLDIR") (Name "Gauche")) |
| 54 |
,@(sxml:content file-tree))) |
| 55 |
;; Add PATH environment variables |
| 56 |
(Component |
| 57 |
(@ (Id "SetEnvPath") (Guid "ca07df2e-9e51-493a-bfe6-d7e0d861b5c9")) |
| 58 |
(Environment (@ (Id "UpdatePath") |
| 59 |
(Name "PATH") |
| 60 |
(Action "set") |
| 61 |
(Part "last") |
| 62 |
(Permanent "no") |
| 63 |
(System "yes") |
| 64 |
(Value "[INSTALLDIR]bin")))) |
| 65 |
;; Set up registries |
| 66 |
(Component |
| 67 |
(@ (Id "RegistryEntries") (Guid "aad33726-68ed-46c6-91cb-a88d9ad47c01")) |
| 68 |
,(regkey 'HKLM "Software\\Scheme Arts\\Gauche" |
| 69 |
'("InstallDir" "[INSTALLDIR]"))) |
| 70 |
(Component |
| 71 |
(@ (Id "RegistryEntries_AssociateExtension") |
| 72 |
(Guid "8bc70ca0-e3ff-11e3-b171-d31eca574265")) |
| 73 |
(Condition "CUSTOM_ASSOCIATEEXTENSION") |
| 74 |
,(regkey 'HKCR ".scm" "Scheme.script") |
| 75 |
,(regkey 'HKCR "Scheme.script" "Scheme Script") |
| 76 |
,(regkey 'HKCR "Scheme.script\\shell" "open") |
| 77 |
,(regkey 'HKCR "Scheme.script\\DefaultIcon" |
| 78 |
"[INSTALLDIR]gauche-logo.ico") |
| 79 |
,(regkey 'HKCR "Scheme.script\\shell\\open\\command" |
| 80 |
"[INSTALLDIR]bin\\gosh-noconsole.exe \"%1\"")) |
| 81 |
;; Shortcuts in the start menu |
| 82 |
(Directory |
| 83 |
(@ (Id "ProgramMenuFolder")) |
| 84 |
(Directory |
| 85 |
(@ (Id "ApplicationProgramsFolder") (Name "Gauche")) |
| 86 |
(Component |
| 87 |
(@ (Id "ApplicationShortcut") |
| 88 |
(Guid "505cd733-bb8b-443c-9637-988d74a87c3a")) |
| 89 |
(Shortcut (@ (Id "ApplicationStartMenuShortcut") |
| 90 |
(Name "Gauche") |
| 91 |
(Description "Gauche REPL") |
| 92 |
(Target "[INSTALLDIR]bin\\gosh.exe") |
| 93 |
(Icon "AppIcon.ico") |
| 94 |
(WorkingDirectory "INSTALLDIR"))) |
| 95 |
(Shortcut (@ (Id "UninstallProduct") |
| 96 |
(Name "Uninstall Gauche") |
| 97 |
(Target "[SystemFolder]msiexec.exe") |
| 98 |
(Arguments "/x [ProductCode]") |
| 99 |
(Description "Uninstall Gauche"))) |
| 100 |
(RemoveFolder (@ (Id "ApplicationProgramsFolder") (On "uninstall"))) |
| 101 |
(RegistryValue (@ (Root "HKCU") |
| 102 |
(Key "Software\\Scheme Arts\\Gauche\\StartMenu") |
| 103 |
(Name "installed") (Type "integer") |
| 104 |
(Value "1") (KeyPath "yes"))) |
| 105 |
))) |
| 106 |
;; Shortcut in Desktop |
| 107 |
(Directory |
| 108 |
(@ (Id "DesktopFolder") (Name "Desktop"))) |
| 109 |
(Component |
| 110 |
(@ (Id "DesktopShortcut") |
| 111 |
(Guid "197997bb-369e-4797-9ea6-e98287592d7d")) |
| 112 |
(Condition "CUSTOM_DESCTOPSHORTCUT") |
| 113 |
(Shortcut (@ (Id "desktopGauche") (Directory "DesktopFolder") |
| 114 |
(Name "Gauche") (WorkingDirectory "INSTALLDIR") |
| 115 |
(Icon "AppIcon.ico") (IconIndex "0") |
| 116 |
(Target "[INSTALLDIR]bin\\gosh.exe"))) |
| 117 |
(RegistryValue (@ (Root "HKCU") |
| 118 |
(Key "Software\\Scheme Arts\\Gauche\\DesktopIcon") |
| 119 |
(Name "installed") (Type "integer") |
| 120 |
(Value "1") (KeyPath "yes"))) |
| 121 |
)) |
| 122 |
|
| 123 |
;; |
| 124 |
;; Do the work |
| 125 |
;; |
| 126 |
(Feature (@ (Id "Complete") (Title "Gauche") (Display "expand") |
| 127 |
(Description "The complete package") (Level "1") |
| 128 |
(ConfigurableDirectory "INSTALLDIR")) |
| 129 |
,@(map (^i `(ComponentRef (@ (Id ,i)))) |
| 130 |
((sxpath '(// Component @ Id *text*)) file-tree)) |
| 131 |
(ComponentRef (@ (Id "ApplicationShortcut"))) |
| 132 |
(ComponentRef (@ (Id "SetEnvPath"))) |
| 133 |
(ComponentRef (@ (Id "RegistryEntries"))) |
| 134 |
(ComponentRef (@ (Id "RegistryEntries_AssociateExtension"))) |
| 135 |
(ComponentRef (@ (Id "DesktopShortcut"))) |
| 136 |
) |
| 137 |
|
| 138 |
(MajorUpgrade |
| 139 |
(@ (DowngradeErrorMessage "Newer version of Gauche is already installed.") |
| 140 |
(AllowSameVersionUpgrades "yes"))) |
| 141 |
) |
| 142 |
;; |
| 143 |
;; Custom UI component |
| 144 |
;; |
| 145 |
(Fragment |
| 146 |
(UI |
| 147 |
(Dialog |
| 148 |
(@ (Id "InstallDirDlg_Custom") |
| 149 |
(Width "370") (Height "270") (Title "!(loc.InstallDirDlg_Title)")) |
| 150 |
(Control (@ (Id "Next") (Type "PushButton") |
| 151 |
(X "236") (Y "243") (Width "56") (Height "17") |
| 152 |
(Default "yes") (Text "!(loc.WixUINext)"))) |
| 153 |
(Control (@ (Id "Back") (Type "PushButton") |
| 154 |
(X "180") (Y "243") (Width "56") (Height "17") |
| 155 |
(Text "!(loc.WixUIBack)"))) |
| 156 |
(Control (@ (Id "Cancel") (Type "PushButton") |
| 157 |
(X "304") (Y "243") (Width "56") (Height "17") |
| 158 |
(Cancel "yes") (Text "!(loc.WixUICancel)")) |
| 159 |
(Publish (@ (Event "SpawnDialog") (Value "CancelDlg")) 1)) |
| 160 |
(Control (@ (Id "Description") (Type "Text") |
| 161 |
(X "25") (Y "23") (Width "280") (Height "15") |
| 162 |
(Transparent "yes") (NoPrefix "yes") |
| 163 |
(Text "!(loc.InstallDirDlgDescription)"))) |
| 164 |
(Control (@ (Id "Title") (Type "Text") |
| 165 |
(X "15") (Y "6") (Width "200") (Height "15") |
| 166 |
(Transparent "yes") (NoPrefix "yes") |
| 167 |
(Text "!(loc.InstallDirDlgTitle)"))) |
| 168 |
(Control (@ (Id "BannerBitmap") (Type "Bitmap") |
| 169 |
(X "0") (Y "0") (Width "370") (Height "44") (TabSkip "no") |
| 170 |
(Text "!(loc.InstallDirDlgBannerBitmap)"))) |
| 171 |
(Control (@ (Id "BannerLine") (Type "Line") |
| 172 |
(X "0") (Y "0") (Width "370") (Height "0"))) |
| 173 |
(Control (@ (Id "BottomLine") (Type "Line") |
| 174 |
(X "0") (Y "234") (Width "370") (Height "0"))) |
| 175 |
(Control (@ (Id "FolderLabel") (Type "Text") |
| 176 |
(X "20") (Y "60") (Width "290") (Height "30") |
| 177 |
(NoPrefix "yes") (Text "!(loc.InstallDirDlgFolderLabel)"))) |
| 178 |
(Control (@ (Id "Folder") (Type "PathEdit") |
| 179 |
(X "20") (Y "100") (Width "320") (Height "18") |
| 180 |
(Property "WIXUI_INSTALLDIR") (Indirect "yes"))) |
| 181 |
(Control (@ (Id "ChangeFolder") (Type "PushButton") |
| 182 |
(X "20") (Y "120") (Width "56") (Height "17") |
| 183 |
(Text "!(loc.InstallDirDlgChange)"))) |
| 184 |
(Control (@ (Id "DesktopShortcutCheckBox") (Type "CheckBox") |
| 185 |
(X "20") (Y "160") (Width "290") (Height "17") |
| 186 |
(Property "CUSTOM_DESCTOPSHORTCUT") |
| 187 |
(CheckBoxValue "1") |
| 188 |
(Text "Create a shortcut on the desktop."))) |
| 189 |
(Control (@ (Id "AssociateExtensionCheckBox") (Type "CheckBox") |
| 190 |
(X "20") (Y "185") (Width "290") (Height "17") |
| 191 |
(Property "CUSTOM_ASSOCIATEEXTENSION") |
| 192 |
(CheckBoxValue "1") |
| 193 |
(Text "Associate 'scm' extension to Gauche."))) |
| 194 |
))) |
| 195 |
(Fragment |
| 196 |
(UI |
| 197 |
(@ (Id "WixUI_InstallDirCustom")) |
| 198 |
(TextStyle (@ (Id "WixUI_Font_Normal") (FaceName "Tahoma") (Size "8"))) |
| 199 |
(TextStyle (@ (Id "WixUI_Font_Bigger") (FaceName "Tahoma") (Size "12"))) |
| 200 |
(TextStyle (@ (Id "WixUI_Font_Title") (FaceName "Tahoma") (Size "9") (Bold "yes"))) |
| 201 |
(Property (@ (Id "DefaultUIFont") (Value "WixUI_Font_Normal"))) |
| 202 |
(Property (@ (Id "WixUI_Mode") (Value "InstallDir"))) |
| 203 |
(Property (@ (Id "ARPNOMODIFY") (Value "1"))) |
| 204 |
,@($ append-map gen-dialog |
| 205 |
'((BrowseDlg |
| 206 |
(OK DoAction WixUIValidatePath 3 1) |
| 207 |
(OK SpawnDialog InvalidDirDlg 4 "WIXUI_INSTALLDIR_VALID<>\"1\"")) |
| 208 |
(DiskCostDlg) |
| 209 |
(.ExitDialog |
| 210 |
(Finish EndDialog Return 999 1)) |
| 211 |
(.WelcomeDlg |
| 212 |
(Next NewDialog LicenseAgreementDlg #f "NOT Installed") |
| 213 |
(Next NewDialog VerifyReadyDlg #f "Installed AND PATCH")) |
| 214 |
(.LicenseAgreementDlg |
| 215 |
(Back NewDialog WelcomeDlg #f 1) |
| 216 |
(Next NewDialog InstallDirDlg_Custom #f "LicenseAccepted = \"1\"")) |
| 217 |
(.InstallDirDlg_Custom |
| 218 |
(Back NewDialog LicenseAgreementDlg #f 1) |
| 219 |
(Next SetTargetPath "[WIXUI_INSTALLDIR]" 1 1) |
| 220 |
(Next DoAction "WixUIValidatePath" 2 1) |
| 221 |
(Next SpawnDialog "InvalidDirDlg" 3 "WIXUI_INSTALLDIR_VALID <> \"1\"") |
| 222 |
(Next NewDialog VerifyReadyDlg 4 "WIXUI_INSTALLDIR_VALID = \"1\"") |
| 223 |
(ChangeFolder _BrowseProperty "[WIXUI_INSTALLDIR]" 1 1) |
| 224 |
(ChangeFolder SpawnDialog BrowseDlg 2 1)) |
| 225 |
(.VerifyReadyDlg |
| 226 |
(Back NewDialog InstallDirDlg_Custom 1 "NOT Installed") |
| 227 |
(Back NewDialog MaintenanceTypeDlg 2 "Installed AND NOT PATCH") |
| 228 |
(Back NewDialog WelcomeDlg 2 "Installed AND NOT PATCH")) |
| 229 |
(.MaintenanceWelcomeDlg |
| 230 |
(Next NewDialog MaintenanceTypeDlg #f 1)) |
| 231 |
(.MaintenanceTypeDlg |
| 232 |
(RepairButton NewDialog VerifyReadyDlg #f 1) |
| 233 |
(RemoveButton NewDialog VerifyReadyDlg #f 1) |
| 234 |
(Back NewDialog MaintenanceWelcomeDlg #f 1)) |
| 235 |
(ErrorDlg) |
| 236 |
(FatalError) |
| 237 |
(FilesInUse) |
| 238 |
(MsiRMFilesInUse) |
| 239 |
(PrepareDlg) |
| 240 |
(ProgressDlg) |
| 241 |
(ResumeDlg) |
| 242 |
(UserExit)))) |
| 243 |
(UIRef (@ (Id "WixUI_Common")))) |
| 244 |
)) |
| 245 |
|
| 246 |
;; generate DialogRef and/or Publish |
| 247 |
;; from (dialog-name (ctrl event value order content) ...) |
| 248 |
;; if dialog-name begins with '.', we don't emit DialogRef |
| 249 |
(define (gen-dialog spec) |
| 250 |
(match-let1 (dlg . params) spec |
| 251 |
(let* ([s (x->string dlg)] |
| 252 |
[need-ref? (not (string-prefix? "." s))] |
| 253 |
[dlgname (if need-ref? s (string-drop s 1))]) |
| 254 |
`(,@(cond-list [need-ref? `(DialogRef (@ (Id ,dlgname)))]) |
| 255 |
,@(map (^[param] |
| 256 |
(match-let1 (ctrl event value order content) param |
| 257 |
`(Publish (@ (Dialog ,dlgname) |
| 258 |
(Control ,(x->string ctrl)) |
| 259 |
(,(if (eq? event '_BrowseProperty) 'Property 'Event) ,(x->string event)) |
| 260 |
(Value ,(x->string value)) |
| 261 |
,@(cond-list |
| 262 |
[order `(Order ,(x->string order))])) |
| 263 |
,content))) |
| 264 |
params))))) |
| 265 |
|
| 266 |
;; vals :: Val | (name Val) |
| 267 |
(define (regkey root key vals) |
| 268 |
`(RegistryKey |
| 269 |
(@ (Root ,(x->string root)) (Key ,key) |
| 270 |
(ForceDeleteOnUninstall "yes")) |
| 271 |
,(match vals |
| 272 |
[(name val) |
| 273 |
`(RegistryValue (@ (Type "string") (Name ,name) (Value ,val)))] |
| 274 |
[val |
| 275 |
`(RegistryValue (@ (Type "string") (Value ,val)))]))) |
| 276 |
|
| 277 |
;; |
| 278 |
(define (generate version file-tree out-file) |
| 279 |
(call-with-output-file out-file |
| 280 |
(^p (display "<?xml version='1.0' encoding='utf-8'?>\n" p) |
| 281 |
(srl:sxml->xml (wix-template version file-tree) p)))) |
| 282 |
|
| 283 |
(define (get-version) |
| 284 |
(regexp-replace |
| 285 |
#/^(\d+\.\d+(?:\.\d+)).*$/ |
| 286 |
(process-output->string '("Gauche/bin/gauche-config" "-V")) |
| 287 |
"\\1")) |
| 288 |
|
| 289 |
|
| 290 |
;; Generate an XML Directory node of the installation tree. |
| 291 |
;; Currently we rely on the 'heat.exe' that comes with Wix SDK. |
| 292 |
(define (gen-file-tree) |
| 293 |
(let1 tmpfile "file-tree.xml" |
| 294 |
(run-process `("heat" "dir" "Gauche" "-nologo" "-sfrag" "-gg" "-sreg" "-o" ,tmpfile) |
| 295 |
:wait #t) |
| 296 |
(let1 sxml (call-with-input-file tmpfile |
| 297 |
(^p (read-char p) ; skip BOM |
| 298 |
(ssax:xml->sxml p `((#f . ,*wix-ns*))))) |
| 299 |
(begin0 |
| 300 |
(xlate-file-tree |
| 301 |
((if-car-sxpath '(// Fragment DirectoryRef Directory)) sxml)) |
| 302 |
(sys-unlink tmpfile))))) |
| 303 |
|
| 304 |
(define (xlate-file-tree sxml) |
| 305 |
(pre-post-order sxml |
| 306 |
`((File . ,(^(n . cs) |
| 307 |
(let* ([node (cons n cs)] |
| 308 |
[src (sxml:attr node 'Source)] |
| 309 |
[id (sxml:attr node 'Id)]) |
| 310 |
(sxml:change-attrlist |
| 311 |
node |
| 312 |
`((Name ,(sys-basename src)) |
| 313 |
(Id ,id)))))) |
| 314 |
(*text* . ,(^(n c) c)) |
| 315 |
(*default* . ,list)))) |
| 316 |
|
| 317 |
(define (main args) |
| 318 |
(define (usage) (exit 1 #"Usage: ~*program-name* [--arch=x64] <outfile>")) |
| 319 |
(let-args (cdr args) |
| 320 |
([arch "a|arch=s"] |
| 321 |
[else (opt . _) (display #"Unknown option: ~opt\n" (current-error-port)) (usage)] |
| 322 |
. args) |
| 323 |
(match args |
| 324 |
[(outfile) |
| 325 |
(if (equal? arch "x64") |
| 326 |
(set! *program-files-folder* "ProgramFiles64Folder")) |
| 327 |
(generate (get-version) (gen-file-tree) outfile)] |
| 328 |
[_ (usage)]) |
| 329 |
0)) |