84 lines
2.5 KiB
Nim
84 lines
2.5 KiB
Nim
# src/handlers/initialRunHandler.nim
|
|
|
|
import os, osproc
|
|
import ../lib/styledOut
|
|
|
|
# Path of the default dashinit config
|
|
const dashinitConfig = staticRead("../resources/config/config.toml")
|
|
|
|
let roamingAppData = getEnv("APPDATA")
|
|
let localAppData = getEnv("LOCALAPPDATA")
|
|
let homeDir = os.getHomeDir()
|
|
|
|
# Base directory containing templates and other files
|
|
let dashinitBaseDir* = if hostOS == "windows":
|
|
roamingAppData / "dashinit"
|
|
else:
|
|
homeDir / ".local" / "share" / "dashinit"
|
|
|
|
# Dashinit config directory containing the config files
|
|
let confBaseDir* = if hostOs == "windows":
|
|
roamingAppData / "dashinit"
|
|
else:
|
|
homeDir / ".config" / "dashinit"
|
|
|
|
# Cache directory containing donwloaded templates used as cache
|
|
let cacheBaseDir* = if hostOs == "windows":
|
|
localAppData / "dashinit"
|
|
else:
|
|
homeDir / ".cache" / "dashinit"
|
|
|
|
# Get the template directory path based on the OS
|
|
let templateBaseDir* = dashinitBaseDir / "templates"
|
|
|
|
# Get the config file path based on the OS
|
|
let configPath* = confBaseDir / "config.toml"
|
|
|
|
let contentsConf = execProcess("ls -l " & $confBaseDir)
|
|
let contentsLocal = execProcess("ls -l " & $dashinitBaseDir)
|
|
|
|
styledPrint("Contents of config path: " & $contentsConf, debug)
|
|
styledPrint("Contents of local path: " & $contentsLocal, debug)
|
|
|
|
# Ensure the templates directory exists
|
|
proc ensureTemplatesDirExists() =
|
|
if not dirExists(templateBaseDir):
|
|
try:
|
|
os.createDir(templateBaseDir)
|
|
except:
|
|
styledPrint("Failed to create templates directory at " & $templateBaseDir, error)
|
|
|
|
# Ensure the config file exists
|
|
proc ensureConfigFileExists() =
|
|
|
|
# Create the directory if it doesn't exist
|
|
let dir = confBaseDir
|
|
if not dir.dirExists():
|
|
try:
|
|
dir.createDir()
|
|
except:
|
|
styledPrint("Failed to create config directory at " & $confBaseDir, error)
|
|
|
|
# Write the template config to the determined path
|
|
if not configPath.fileExists():
|
|
try:
|
|
writeFile(configPath, dashinitConfig)
|
|
except:
|
|
styledPrint("Failed to create config file at " & $configPath, error)
|
|
|
|
# Ensure the cache directory exists
|
|
proc ensureCacheDirExists() =
|
|
# Create the directory if it doesn't exist
|
|
let dir = cacheBaseDir
|
|
if not dir.dirExists():
|
|
try:
|
|
dir.createDir()
|
|
except:
|
|
styledPrint("Failed to create cache directory at " & $cacheBaseDir, error)
|
|
|
|
# Ensure all initial directories and files are set up
|
|
proc initialSetup*() =
|
|
ensureTemplatesDirExists()
|
|
ensureConfigFileExists()
|
|
ensureCacheDirExists()
|