#lang scheme/base
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; FLEXER.plt - FLEX integration with SHP 
;; Bonzai Lab, LLC.  All rights reserved.
;; Licensed under LGPL.
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; - performing additional processing during the installation
;; yc 8/21/2009 - first version 
(require scheme/system
         (planet bzlib/file)

;; post-installer
;; test to see if there is java > v1.4 available.
;; if not - throw an error.
(define (post-installer (collect-path (current-directory)) (package-path (current-directory)))
  (define (satisfy-version? out (match 3))
    (let ((ver (regexp-match #px"(\\d+\\.\\d+).*" out)))
      (cond ((not ver) (values ver #f))
            ((>= (string->number (cadr ver)) match) 
             (values (cadr ver) #t))
            (else (values ver #f)))))
  (define (helper cout) 
    (let-values (((ver match?)
                  (satisfy-version? cout)))
      (if match?
          (display (format "You have FLEX SDK (version = ~a) installed. Your package should work correctly.\n" ver))
          (error 'wrong-verion "Your FLEX SDK (version = ~a) does not meet requirement - please upgrade to version > 3." ver))))
  (let-values (((res code cout cerr)
                (sys/call "mxmlc" "-version")))
    (if (not res)
        (error 'not-java-installed "We cannot find your FLEX SDK installation via shell.  Please make sure it is installed (version >= 3)")
        (helper (bytes->string/utf-8 cout)))))

(provide post-installer)