1
0
mirror of https://codeberg.org/cage/tinmop/ synced 2025-02-19 08:30:35 +01:00

- create an empty config file if the user did not provided oopne, instread of printing an error and exit.

This commit is contained in:
cage 2021-01-13 17:28:23 +01:00
parent 72254f981a
commit 382c61818d
4 changed files with 47 additions and 36 deletions

View File

@ -31,7 +31,7 @@
(defun setup-bindings () (defun setup-bindings ()
"This is where an UI event is bound to a function the event nil is "This is where an UI event is bound to a function the event nil is
the event that is fired wnen no input from user (key pressed mouse the event that is fired when no input from user (key pressed mouse
etc.) happened" etc.) happened"
(windows:with-croatoan-window (croatoan-window specials:*main-window*) (windows:with-croatoan-window (croatoan-window specials:*main-window*)
(bind croatoan-window (bind croatoan-window
@ -101,14 +101,25 @@ etc.) happened"
(program-events:push-event event))) (program-events:push-event event)))
(defun load-configuration-files () (defun load-configuration-files ()
(swconf:load-config-file swconf:+shared-conf-filename+) (handler-case
(swconf:load-config-file swconf:+conf-filename+)) (swconf:load-config-file swconf:+shared-conf-filename+)
(error (e)
(format *error-output* "~a~%" e)
(os-utils:exit-program 1)))
(handler-bind ((error
#'(lambda (e)
(format *error-output*
(_ "Non fatal error~%~a~%Tinmop will add an empty file for you. This file will be enough to use the program as a gemini client but to connect to pleroma the file must be properly filled.~%Consult the manpage ~a(1) for more details")
e
+program-name+)
(invoke-restart 'res:create-empty-in-home))))
(swconf:load-config-file swconf:+conf-filename+)))
(defun init () (defun init ()
"Initialize the program" "Initialize the program"
(res:init) ;; (res:init)
(load-configuration-files) ;; (load-configuration-files)
(init-db) ;; (init-db)
(gemini-client:init-default-gemini-theme) (gemini-client:init-default-gemini-theme)
(db-utils:with-ready-database (:connect nil) (db-utils:with-ready-database (:connect nil)
(complete:initialize-complete-username-cache) (complete:initialize-complete-username-cache)
@ -171,6 +182,9 @@ etc.) happened"
(defun main () (defun main ()
"The entry point function of the program" "The entry point function of the program"
(init-i18n) (init-i18n)
(res:init)
(load-configuration-files)
(init-db)
(command-line:manage-opts) (command-line:manage-opts)
(if command-line:*script-file* (if command-line:*script-file*
(load-script-file) (load-script-file)

View File

@ -411,6 +411,7 @@
:home-confdir :home-confdir
:return-home-filename :return-home-filename
:return-system-filename :return-system-filename
:create-empty-in-home
:get-config-file :get-config-file
:get-sys-config-file :get-sys-config-file
:get-data-file)) :get-data-file))

View File

@ -52,15 +52,16 @@
((fs:file-exists-p system-file) ((fs:file-exists-p system-file)
system-file) system-file)
(t (t
(let ((msg (_ "Unrecoverable error: cannot find ~s in either ~s or ~s."))) (let ((msg (_ "Cannot find ~s in either ~s or ~s.")))
(restart-case (restart-case
(error (format nil msg path system-file home-file)) (error (format nil msg path system-file home-file))
(return-home-filename (e) (return-home-filename ()
(declare (ignore e))
home-file) home-file)
(return-system-filename (e) (return-system-filename ()
(declare (ignore e)) system-file)
system-file))))))) (create-empty-in-home ()
(fs:create-file home-file :skip-if-exists t)
(get-resource-file system-dir home-dir path))))))))
(defun get-config-file (path) (defun get-config-file (path)
(get-resource-file +sys-conf-dir+ (home-confdir) path)) (get-resource-file +sys-conf-dir+ (home-confdir) path))

View File

@ -413,30 +413,25 @@
purge-cache-days-offset) purge-cache-days-offset)
(defun load-config-file (&optional (virtual-filepath +conf-filename+)) (defun load-config-file (&optional (virtual-filepath +conf-filename+))
(handler-case (let* ((file (res:get-config-file virtual-filepath))
(progn (tree (parse-config (fs:namestring->pathname file))))
(let* ((file (res:get-config-file virtual-filepath)) (loop for entry in tree do
(tree (parse-config (fs:namestring->pathname file)))) (let ((key (first entry))
(loop for entry in tree do (value (second entry)))
(let ((key (first entry)) (cond
(value (second entry))) ((or (eq +key-color-re+ key)
(cond (eq +key-ignore-user-re+ key))
((or (eq +key-color-re+ key) (setf (access:accesses *software-configuration* key)
(eq +key-ignore-user-re+ key)) (append (access:accesses *software-configuration* key)
(setf (access:accesses *software-configuration* key) (list value))))
(append (access:accesses *software-configuration* key) ((keywordp key)
(list value)))) (setf (access:accesses *software-configuration* key) value))
((keywordp key) (t
(setf (access:accesses *software-configuration* key) value)) (multiple-value-bind (rest all)
(t (apply #'access:set-accesses value *software-configuration* key)
(multiple-value-bind (rest all) (declare (ignore rest))
(apply #'access:set-accesses value *software-configuration* key) (setf *software-configuration* all))))))
(declare (ignore rest)) *software-configuration*))
(setf *software-configuration* all))))))
*software-configuration*))
(error (e)
(format *error-output* "~a~%" e)
(os-utils:exit-program 1))))
;;;; end of parser ;;;; end of parser