2022-08-23 09:57:42 +00:00
|
|
|
#lang racket/base
|
2022-08-24 08:59:11 +00:00
|
|
|
(require racket/runtime-path
|
|
|
|
ini)
|
2022-08-23 09:57:42 +00:00
|
|
|
|
|
|
|
(provide
|
2022-08-24 08:59:11 +00:00
|
|
|
config-true?
|
2022-08-23 09:57:42 +00:00
|
|
|
config-get)
|
|
|
|
|
2022-08-24 08:59:11 +00:00
|
|
|
(define-runtime-path path-config "../config.ini")
|
|
|
|
|
|
|
|
(define (config-true? key)
|
|
|
|
(not (member (hash-ref config key) '("" "false"))))
|
2022-08-24 01:23:46 +00:00
|
|
|
|
2022-08-23 09:57:42 +00:00
|
|
|
(define (config-get key)
|
|
|
|
(hash-ref config key))
|
|
|
|
|
|
|
|
(define default-config
|
2022-08-24 08:59:11 +00:00
|
|
|
'((port . "10416")
|
|
|
|
(debug . "false")
|
|
|
|
(instance-is-official . "false") ; please don't turn this on, or you will make me very upset
|
2022-08-23 09:57:42 +00:00
|
|
|
(application-name . "BreezeWiki")))
|
|
|
|
|
|
|
|
(define config
|
|
|
|
(make-hasheq
|
|
|
|
(append
|
|
|
|
default-config
|
2022-08-24 08:59:11 +00:00
|
|
|
(with-handlers ([exn:fail:filesystem:errno?
|
|
|
|
(λ (exn)
|
|
|
|
(begin0
|
|
|
|
'()
|
|
|
|
(displayln "note: config file not detected, using defaults")))]
|
|
|
|
[exn:fail:contract?
|
|
|
|
(λ (exn)
|
|
|
|
(begin0
|
|
|
|
'()
|
|
|
|
(displayln "note: config file empty or missing [] section, using defaults")))])
|
|
|
|
(let ([l (hash->list
|
|
|
|
(hash-ref
|
|
|
|
(ini->hash
|
|
|
|
(call-with-input-file path-config
|
|
|
|
(λ (in)
|
|
|
|
(read-ini in))))
|
|
|
|
'||))])
|
|
|
|
(begin0
|
|
|
|
l
|
|
|
|
(printf "note: ~a items loaded from config file~n" (length l))))))))
|
|
|
|
|
|
|
|
(when (config-true? 'debug)
|
|
|
|
(printf "config: ~v~n" config))
|