~reesmichael1/roman

ref: 3784df6eb213fc0ccd683ed396d42645e1bca718 roman/src/romanpkg/paths.nim -rw-r--r-- 1.1 KiB
3784df6eMichael Rees Fix crash when displaying very long link in post 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os

import errors


proc getConfigFilePath*(): string {.raises: [].} =
  joinPath(getConfigDir(), "roman", "config")


proc getSubsFilePath*(): string {.raises: [].} =
  joinPath(getConfigDir(), "roman", "subscriptions")


proc initConfigDir*() {.raises: [RomanError].} =
  let configDir = joinPath(getConfigDir(), "roman")
  try:
    if not existsOrCreateDir(configDir):
      let config = getConfigFilePath()
      let subs = getSubsFilePath()
      writeFile(config, "")
      writeFile(subs, "")
  except IOError, OSError:
    raise newException(RomanError, getCurrentExceptionMsg())


proc getShareDir*(): string {.raises: [].} =
  # TODO: support non-Linux OSes
  let defaultShare = expandTilde("~/.local/share/")
  let shareRoot = getEnv("XDG_SHARE_HOME", defaultShare)
  let shareDir = joinPath(shareRoot, "roman")
  return shareDir


proc getPostReadFile*(): string {.raises: [RomanError].} =
  result = joinPath(getShareDir(), "read-posts")
  if not existsFile(result):
    var f: File
    if not f.open(result, mode = fmWrite):
      raise newException(RomanError, "could not create read-posts file")
    f.close()