diff --git a/src/api-client.lisp b/src/api-client.lisp index bdfcf76..1f0b90b 100644 --- a/src/api-client.lisp +++ b/src/api-client.lisp @@ -26,9 +26,12 @@ (defparameter *client-lock* (make-lock) "The Lock for prevent race conditions when accessing the mastodon server") -(define-constant +credentials-filename+ "client" :test #'string= - :documentation "The name of the file where - credentials are stored") +(defun credentials-filename () + "The name of the file where credentials are stored." + (text-utils:strcat (swconf:current-username) + "@" + (swconf:current-server-name) + ".credentials")) (define-constant +protocol-scheme+ "https://" :test #'string= :documentation "The scheme of the protocol that the @@ -70,14 +73,14 @@ initform." (defun dump-credentials () "Serialize `*credential*' to disk" - (let ((resource-file (res:get-data-file +credentials-filename+))) + (let ((resource-file (res:get-data-file (credentials-filename)))) (fs:dump-sequence-to-file (serialize *credentials*) resource-file))) (defun forget-credentials () "Remove credentials data file" (conditions:with-default-on-error (nil) - (let ((resource-file (res:get-data-file +credentials-filename+))) + (let ((resource-file (res:get-data-file (credentials-filename)))) (fs:delete-file-if-exists resource-file)))) (defun credentials-complete-p () @@ -201,7 +204,7 @@ Returns nil if the user did not provided a server in the configuration file" (ui:error-dialog-immediate (format nil (_ "Credential invalid. Try to remove ~a and restart the software to authenticate again") - (res:get-data-file +credentials-filename+)))))) + (res:get-data-file (credentials-filename))))))) (multiple-value-bind (server-socket server-port) (open-catch-code-socket) (setf *client* (make-default-client)) @@ -964,7 +967,7 @@ and day is current time)" (lambda (e) (declare (ignore e)) (invoke-restart 'res:return-home-filename)))) - (res:get-data-file +credentials-filename+)))) + (res:get-data-file (credentials-filename))))) (let ((resource-file (credentials-filename))) (if (not (fs:file-exists-p resource-file)) (progn diff --git a/src/constants.lisp b/src/constants.lisp index 196af9b..4111878 100644 --- a/src/constants.lisp +++ b/src/constants.lisp @@ -122,8 +122,8 @@ General Public License for more details." (define-constant +mime-type-text+ "text/plain" :test #'string=) -(define-constant +db-file+ "db.sqlite3" :test #'string= - :documentation "the filename of the database") +(define-constant +db-file-extension+ "sqlite3" :test #'string= + :documentation "the extension filename of the databases") (define-constant +json-true+ "true" :test #'string=) diff --git a/src/db-utils.lisp b/src/db-utils.lisp index 36e0348..d183e33 100644 --- a/src/db-utils.lisp +++ b/src/db-utils.lisp @@ -227,11 +227,25 @@ example: (from table))))) :ct)) +(defun db-current-file-name () + (concatenate 'string + (swconf:current-username) + "@" + (swconf:current-server-name) + "." + +db-file-extension+)) + (defun db-path () (uiop:unix-namestring (concatenate 'string (res:home-datadir) "/" - +db-file+))) + (db-current-file-name)))) + +(defun db-path* () + (uiop:unix-namestring (concatenate 'string + (res:home-datadir) + "/" + "db.sqlite3"))) (defun db-file-exists-p () (fs:file-exists-p (db-path))) diff --git a/src/main.lisp b/src/main.lisp index 8a4f0b1..5af710c 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -259,28 +259,29 @@ etc.) happened" (defun main () "The entry point function of the program" - (let ((first-time-starting (not (db-utils:db-file-exists-p)))) - (init-i18n) - (res:init) - (command-line:manage-opts) - (cond - (command-line:*start-dummy-server* - (gemini-dummy-server:start)) - (command-line:*rpc-server-mode* - (db-utils:with-ready-database (:connect nil) - (rpc-server-init))) - (command-line:*rpc-client-mode* - (rpc-client-init) - (json-rpc-communication::start-client) - (client-main-window:init-main-window command-line:*net-address*)) - (command-line:*print-lisp-dependencies* - (misc:all-program-dependencies t)) - (command-line:*script-file* - (load-script-file)) - (t - (let ((croatoan::*debugger-hook* #'(lambda (c h) - (declare (ignore h)) - (c:end-screen) - (print c)))) - (tui-init) - (run first-time-starting)))))) + (init-i18n) + (res:init) + (command-line:manage-opts) + (cond + (command-line:*start-dummy-server* + (gemini-dummy-server:start)) + (command-line:*rpc-server-mode* + (db-utils:with-ready-database (:connect nil) + (rpc-server-init))) + (command-line:*rpc-client-mode* + (rpc-client-init) + (json-rpc-communication::start-client) + (client-main-window:init-main-window command-line:*net-address*)) + (command-line:*print-lisp-dependencies* + (misc:all-program-dependencies t)) + (command-line:*script-file* + (load-script-file)) + (t + (let ((croatoan::*debugger-hook* #'(lambda (c h) + (declare (ignore h)) + (c:end-screen) + (print c)))) + + (tui-init) + (let ((first-time-starting (not (db-utils:db-file-exists-p)))) + (run first-time-starting)))))) diff --git a/src/package.lisp b/src/package.lisp index 1c7241a..ecd6ea5 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -55,7 +55,7 @@ :+mime-type-png+ :+mime-type-html+ :+mime-type-text+ - :+db-file+ + :+db-file-extension+ :+fps+ :+command-window-height+ :+starting-init-file+