2021-09-09 19:09:17 +00:00
|
|
|
import os, sequtils, strutils
|
|
|
|
|
|
|
|
import # vendor libs
|
|
|
|
confutils
|
|
|
|
|
2022-04-07 09:08:44 +00:00
|
|
|
const sep* = when defined(windows): "\\" else: "/"
|
2021-09-09 19:09:17 +00:00
|
|
|
|
2022-04-08 10:44:50 +00:00
|
|
|
proc defaultDataDir*(): string =
|
2021-09-09 19:09:17 +00:00
|
|
|
let homeDir = getHomeDir()
|
|
|
|
let parentDir =
|
|
|
|
if defined(development):
|
|
|
|
parentDir(getAppDir())
|
|
|
|
elif homeDir == "":
|
|
|
|
getCurrentDir()
|
|
|
|
elif defined(macosx):
|
|
|
|
joinPath(homeDir, "Library", "Application Support")
|
|
|
|
elif defined(windows):
|
|
|
|
let targetDir = getEnv("LOCALAPPDATA").string
|
|
|
|
if targetDir == "":
|
|
|
|
joinPath(homeDir, "AppData", "Local")
|
|
|
|
else:
|
|
|
|
targetDir
|
|
|
|
else:
|
|
|
|
let targetDir = getEnv("XDG_CONFIG_HOME").string
|
|
|
|
if targetDir == "":
|
|
|
|
joinPath(homeDir, ".config")
|
|
|
|
else:
|
|
|
|
targetDir
|
|
|
|
absolutePath(joinPath(parentDir, "Status"))
|
|
|
|
|
|
|
|
type StatusDesktopConfig = object
|
|
|
|
dataDir* {.
|
|
|
|
defaultValue: defaultDataDir()
|
|
|
|
desc: "Status Desktop data directory"
|
|
|
|
abbr: "d" .}: string
|
2021-09-09 21:31:56 +00:00
|
|
|
uri* {.
|
|
|
|
defaultValue: ""
|
|
|
|
desc: "status-im:// URI to open a chat or other"
|
|
|
|
name: "uri" .}: string
|
|
|
|
|
|
|
|
|
2021-09-09 19:09:17 +00:00
|
|
|
# On macOS the first time when a user gets the "App downloaded from the
|
|
|
|
# internet" warning, and clicks the Open button, the OS passes a unique process
|
|
|
|
# serial number (PSN) as -psn_... command-line argument, which we remove before
|
|
|
|
# processing the arguments with nim-confutils.
|
|
|
|
# Credit: https://github.com/bitcoin/bitcoin/blame/b6e34afe9735faf97d6be7a90fafd33ec18c0cbb/src/util/system.cpp#L383-L389
|
|
|
|
|
|
|
|
var cliParams = commandLineParams()
|
|
|
|
if defined(macosx):
|
|
|
|
cliParams.keepIf(proc(p: string): bool = not p.startsWith("-psn_"))
|
|
|
|
|
|
|
|
let desktopConfig = StatusDesktopConfig.load(cliParams)
|
|
|
|
|
|
|
|
let
|
|
|
|
baseDir = absolutePath(expandTilde(desktopConfig.dataDir))
|
2021-09-09 21:31:56 +00:00
|
|
|
OPENURI* = desktopConfig.uri
|
2021-09-09 19:09:17 +00:00
|
|
|
DATADIR* = baseDir & sep
|
|
|
|
STATUSGODIR* = joinPath(baseDir, "data") & sep
|
2022-05-05 13:43:29 +00:00
|
|
|
ROOTKEYSTOREDIR* = joinPath(baseDir, "data", "keystore")
|
2021-09-09 19:09:17 +00:00
|
|
|
TMPDIR* = joinPath(baseDir, "tmp") & sep
|
|
|
|
LOGDIR* = joinPath(baseDir, "logs") & sep
|
|
|
|
|
|
|
|
proc ensureDirectories*(dataDir, tmpDir, logDir: string) =
|
|
|
|
createDir(dataDir)
|
|
|
|
createDir(tmpDir)
|
2022-02-09 09:43:23 +00:00
|
|
|
createDir(logDir)
|
2022-03-24 11:51:24 +00:00
|
|
|
|
|
|
|
# This is changed during compilation by reading the VERSION file
|
|
|
|
const DESKTOP_VERSION* {.strdefine.} = "0.0.0"
|
|
|
|
# This is changed during compilation by executing git command
|
|
|
|
const GIT_COMMIT* {.strdefine.} = ""
|