-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathauto-update.lisp
More file actions
182 lines (163 loc) · 7.84 KB
/
auto-update.lisp
File metadata and controls
182 lines (163 loc) · 7.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
;;;; -------------------------------
;;;; Copyright (c) Corman Technologies Inc.
;;;; See LICENSE.txt for license information.
;;;; -------------------------------
;;;;
;;;; File: auto-update.lisp
;;;; Contents: Corman Lisp miscellaneous features.
;;;; History: 08/21/06 RGC Created.
;;;;
(in-package :ccl)
(export '(
*cormanlisp-patch-level*
auto-update
patch-rollback
*auto-update-enabled*
*patch-root-directory*
*patch-server*
compile-cormanlisp-image
load-default-image
*auto-update-level*))
(defparameter *cormanlisp-patch-level* (cormanlisp-patch-level))
(defparameter *patches-available* nil)
(defparameter *patches-installed* nil)
(defparameter *patch-server* "www.cormanlisp.com")
(defparameter *patch-root-directory* "/CormanLisp/patches/3_01f1/")
(defparameter *auto-update-enabled* nil) ; disabled by default
(defparameter *auto-update-level* 1) ;; version of auto-update
(defparameter *patch* nil)
(defstruct cormanlisp-patch
level ;; int
pathname
install-func
uninstall-func) ;; relative file name
(defun make-patch (filename)
(make-cormanlisp-patch :level (ccl::get-patch-level-from-name filename) :pathname filename))
(defun define-patch (level filename)
(push (make-cormanlisp-patch :level level :pathname filename) *patches-available*))
(defun local-patches-directory ()
(merge-pathnames "patches/" *cormanlisp-directory*))
(defun local-patches-backup-directory (patch-level)
(merge-pathnames (format nil "patches/backup/3_01/~d/" patch-level)
*cormanlisp-directory*))
(defun get-patch-level-from-name (pathname)
(let ((filename (pathname-name pathname)))
(values (parse-integer filename :start (+ (position #\_ filename :from-end t) 1)
:junk-allowed t))))
(defun update-patch-index ()
(ensure-directories-exist (local-patches-directory))
(sockets:get-http-file
*patch-server*
(concatenate 'string *patch-root-directory* "CormanLisp_3_01_patch_index.lisp")
(merge-pathnames "CormanLisp_3_01_patch_index.lisp"
(local-patches-directory))))
(defun download-patch (patch)
(sockets:get-http-file
*patch-server*
(format nil "~A~D" *patch-root-directory* (cormanlisp-patch-pathname patch))
(merge-pathnames (cormanlisp-patch-pathname patch)
(local-patches-directory))))
(defun compile-cormanlisp-image ()
(format *terminal-io* "Building CormanLisp.img file...~%")
(win:shell-execute (namestring (merge-pathnames "clconsole.exe" *cormanlisp-directory*))
(format nil " -image \"\" -execute \"~a\""
(namestring (merge-pathnames "sys\\compile-sys.lisp" *cormanlisp-directory*))))
;;(win:shell-execute (namestring (merge-pathnames "makeimg.bat" *cormanlisp-directory*)) "")
(win:message-box-ok "A console process has been launched which is recompiling the CormanLisp.img file." "Information")
t)
;; utility function to load default image
;; (handy for reloading default Corman Lisp image after rebuilding)
(defun load-default-image ()
"Load default Corman Lisp image"
(load-image (concatenate 'string
*cormanlisp-directory*
"CormanLisp.img")))
(defun install-patch (patch)
(ensure-directories-exist (local-patches-backup-directory (cormanlisp-patch-level patch)))
(let ((filename (download-patch patch)))
(unless filename
(format *terminal-io* "Could not load patch: ~A~%" (cormanlisp-patch-pathname patch))
(return-from install-patch nil))
(format *terminal-io* "Loading patch level ~D...~%" (cormanlisp-patch-level patch))
(let ((*patch* patch))
(load filename)
(if (cormanlisp-patch-install-func patch)
(funcall (cormanlisp-patch-install-func patch))))
(format *terminal-io* "Finished loading patch level ~D.~%"
(cormanlisp-patch-level patch))))
(defun patch-upgrade-confirm (new-level)
(let ((result (eq
(win:message-box-yes-no
(format nil
(concatenate 'string
"Your patch level is currently ~D. There are new patches available which will "
"bring you up to patch level ~D.~%"
"Would you like to have the new patches installed now?")
ccl:*cormanlisp-patch-level*
new-level)
"Install New Updates")
'win:IDYES)))
(unless result
(win:message-box-ok
(concatenate 'string
"If you wish to disable automatic update notification, you can "
"set the special variable ccl:*AUTO-UPDATE-ENABLED* to NIL "
"in the 'init.lisp' file.")
"Information"))
result))
(defun patch-rollback-confirm (new-level)
(let ((result (eq
(win:message-box-yes-no
(format nil
(concatenate 'string
"Your patch level is currently ~D. Your patch level will "
"be rolled back to level ~D.~%"
"Do you wish to continue with the rollback?")
ccl:*cormanlisp-patch-level*
new-level)
"Remove Patches")
'win:IDYES)))
result))
(defun auto-update ()
(let ((local-index (update-patch-index))
(save-patch-level ccl:*cormanlisp-patch-level*))
(unless local-index
(format *terminal-io*
(concatenate 'string
";; Could not load auto-update index file. "
"This may be because you are not connected to the internet, or because you "
"need to configure proxy server settings (see the 'init.lisp' file)~%"))
(return-from auto-update nil))
(load local-index)
;; if the patch level was upgraded, recompile the image
(when (> ccl:*cormanlisp-patch-level* save-patch-level)
(compile-cormanlisp-image))))
;;;
;;; You can rollback to any patch level from 0 to ccl:*cormanlisp-patch-level*
;;;
(defun patch-rollback (level)
(let ((save-patch-level ccl:*cormanlisp-patch-level*))
(unless (and (>= level 0)
(< level ccl:*cormanlisp-patch-level*)
(patch-rollback-confirm level))
(return-from patch-rollback))
(dolist (patch ccl::*patches-installed*)
(if (> (cormanlisp-patch-level patch) level)
(progn
(if (cormanlisp-patch-uninstall-func patch)
(funcall (cormanlisp-patch-uninstall-func patch)))
(delete-file (cormanlisp-patch-pathname patch))
(pop ccl::*patches-installed*)
(decf *cormanlisp-patch-level*))))
;; if the patch level was downgraded, recompile the image
(when (< ccl:*cormanlisp-patch-level* save-patch-level)
(compile-cormanlisp-image)
(win:message-box-ok
(format nil "The new patch level is ~D" ccl:*cormanlisp-patch-level*)
"Information"))))
(defmacro defpatch (level &key (install-func nil) (uninstall-func nil))
`(progn
(setf (ccl::cormanlisp-patch-install-func ccl::*patch*) ',install-func)
(setf (ccl::cormanlisp-patch-uninstall-func ccl::*patch*) ',uninstall-func)
(setf ccl::*cormanlisp-patch-level* ,level)
(push ccl::*patch* ccl::*patches-installed*)))