|
|
@ -35,7 +35,9 @@ |
|
|
|
(def-introspect-struct auto-update-download |
|
|
|
operating-system ([] 32 char) |
|
|
|
architecture ([] 32 char) |
|
|
|
url ([] 1024 char)) |
|
|
|
url ([] 1024 char) |
|
|
|
;; After the update, this file should be used for the latest version (e.g. executable or DLL) |
|
|
|
file-to-use ([] 1024 char)) |
|
|
|
|
|
|
|
(def-introspect-struct auto-update-metadata |
|
|
|
name ([] 64 char) |
|
|
@ -44,20 +46,20 @@ |
|
|
|
|
|
|
|
(def-type-alias-global CURL void) |
|
|
|
|
|
|
|
(defun auto-update-get-current-platform-download-url (update-data (* auto-update-metadata) |
|
|
|
&return (* (const char))) |
|
|
|
(defun auto-update-get-current-platform-download (update-data (* auto-update-metadata) |
|
|
|
&return (* auto-update-download)) |
|
|
|
(each-item-addr-in-dynarray (path update-data > downloads) i download (* auto-update-download) |
|
|
|
(comptime-cond |
|
|
|
('Windows |
|
|
|
(when (and |
|
|
|
(= 0 (strcmp "Windows" (path download > operating-system))) |
|
|
|
(= 0 (strcmp "x64" (path download > architecture)))) |
|
|
|
(return (path download > url)))) |
|
|
|
(return download))) |
|
|
|
('Unix |
|
|
|
(when (and |
|
|
|
(= 0 (strcmp "Linux" (path download > operating-system))) |
|
|
|
(= 0 (strcmp "x64" (path download > architecture)))) |
|
|
|
(return (path download > url)))))) |
|
|
|
(return download))))) |
|
|
|
(return null)) |
|
|
|
|
|
|
|
;; TODO: Add version header |
|
|
@ -116,9 +118,13 @@ |
|
|
|
;; zip Machsearch_Linux-x64.zip machsearch |
|
|
|
;; ./cryptography-cli create-signed-file Machsearch_Linux-x64.zip ~/website/updates/Machsearch/Machsearch_Linux-x64.auto-update |
|
|
|
;; The download will only occur if the latest version is greater than current-application-version. |
|
|
|
;; new-file-to-use-out-buffer will only be set if there was actually a newer file |
|
|
|
(defun auto-update-download (curl (* CURL) public-key (* (unsigned char)) |
|
|
|
update-cakedata-url (* (const char)) |
|
|
|
current-application-version int |
|
|
|
output-directory (* (const char)) |
|
|
|
new-file-to-use-out-buffer (* char) |
|
|
|
new-file-to-use-out-buffer-size size_t |
|
|
|
&return bool) |
|
|
|
(var update-metadata auto-update-metadata (array 0)) |
|
|
|
(unless (auto-update-get-latest-version-metadata |
|
|
@ -129,8 +135,13 @@ |
|
|
|
(free-introspect-struct-fields auto-update-metadata--metadata (addr update-metadata) free) |
|
|
|
(return false)) |
|
|
|
|
|
|
|
(var platform-update-url (* (const char)) |
|
|
|
(auto-update-get-current-platform-download-url (addr update-metadata))) |
|
|
|
(var platform-download (* auto-update-download) |
|
|
|
(auto-update-get-current-platform-download (addr update-metadata))) |
|
|
|
(unless platform-download |
|
|
|
(fprintf stderr "Could not find update for this platform\n") |
|
|
|
(free-introspect-struct-fields auto-update-metadata--metadata (addr update-metadata) free) |
|
|
|
(return false)) |
|
|
|
(var platform-update-url (* (const char)) (path platform-download > url)) |
|
|
|
|
|
|
|
(scope ;; Print results |
|
|
|
(fprintf stderr "Latest version of %s is %d.\nDownloads:\n" |
|
|
@ -144,6 +155,7 @@ |
|
|
|
|
|
|
|
(when (>= current-application-version (field update-metadata latest-version)) |
|
|
|
(fprintf stderr "The application is already up-to-date.\n") |
|
|
|
(set (at 0 new-file-to-use-out-buffer) 0) |
|
|
|
(free-introspect-struct-fields auto-update-metadata--metadata (addr update-metadata) free) |
|
|
|
(return true)) |
|
|
|
|
|
|
@ -155,20 +167,22 @@ |
|
|
|
(free-introspect-struct-fields auto-update-metadata--metadata (addr update-metadata) free) |
|
|
|
(return false)) |
|
|
|
|
|
|
|
(var output-directory ([] 1024 char) (array 0)) |
|
|
|
(sprintf output-directory "v%d" (field update-metadata latest-version)) |
|
|
|
(unless (make-directory output-directory) |
|
|
|
(var version-output-directory ([] 1024 char) (array 0)) |
|
|
|
(sprintf version-output-directory "%s/v%d" output-directory (field update-metadata latest-version)) |
|
|
|
(unless (make-directory version-output-directory) |
|
|
|
(free verified-payload) |
|
|
|
(free-introspect-struct-fields auto-update-metadata--metadata (addr update-metadata) free) |
|
|
|
(return false)) |
|
|
|
(unless (decompress-zip-from-memory-to-files |
|
|
|
verified-payload (type-cast verified-payload-size size_t) |
|
|
|
output-directory) |
|
|
|
version-output-directory) |
|
|
|
(free verified-payload) |
|
|
|
(free-introspect-struct-fields auto-update-metadata--metadata (addr update-metadata) free) |
|
|
|
(return false)) |
|
|
|
(free verified-payload) |
|
|
|
|
|
|
|
(snprintf new-file-to-use-out-buffer new-file-to-use-out-buffer-size "%s/%s" |
|
|
|
version-output-directory (path platform-download > file-to-use)) |
|
|
|
(free-introspect-struct-fields auto-update-metadata--metadata (addr update-metadata) free) |
|
|
|
(return true)) |
|
|
|
|
|
|
@ -188,6 +202,8 @@ |
|
|
|
(var update-cakedata-url (* (const char)) |
|
|
|
"https://localhost:8888/updates/Machsearch/machsearch.cakedata") |
|
|
|
(var current-version int 0) |
|
|
|
(var output-directory (* (const char)) ".") |
|
|
|
(var new-file-to-use ([] 2048 char) (array 0)) |
|
|
|
|
|
|
|
(when (!= (curl_global_init CURL_GLOBAL_DEFAULT) 0) |
|
|
|
(fprintf stderr "error: Failed to initialize curl\n") |
|
|
@ -199,11 +215,14 @@ |
|
|
|
(curl_global_cleanup) |
|
|
|
(return 1)) |
|
|
|
|
|
|
|
(unless (auto-update-download curl macoy-public-key update-cakedata-url current-version) |
|
|
|
(unless (auto-update-download curl macoy-public-key update-cakedata-url current-version |
|
|
|
output-directory new-file-to-use (sizeof new-file-to-use)) |
|
|
|
(curl_easy_cleanup curl) |
|
|
|
(curl_global_cleanup) |
|
|
|
(return 1)) |
|
|
|
|
|
|
|
(fprintf stderr "The update says I should use %s\n" new-file-to-use) |
|
|
|
|
|
|
|
(curl_easy_cleanup curl) |
|
|
|
(curl_global_cleanup) |
|
|
|
(return 0)))) |
|
|
|