The launcher now works as a standalone and as a nimble package.
Folder structure:
websitecreator.nim <-- Launcher
websitecreator_main.nim <-- Main executable
Code (websitecreator.nim):
import osproc, os, sequtils
proc checkCompileOptions(): string =
# Checking for known compile options
# and returning them as a space separated string.
# See README.md for explation of the options.
result = ""
when defined(newdb):
result.add(" -d:newdb")
when defined(newuser):
result.add(" -d:newuser")
when defined(insertdata):
result.add(" -d:insertdata")
when defined(nginx):
result.add(" -d:nginx")
when defined(adminnotify):
result.add(" -d:adminnotify")
when defined(dev):
result.add(" -d:dev")
when defined(devemailon):
result.add(" -d:devemailon")
when defined(demo):
result.add(" -d:demo")
let compileOptions = checkCompileOptions()
# User specified args
template addArgs(inExec = false): string =
let args = foldl(commandLineParams(), a & (b & " "), "")
if inExec:
" --run " & args
else:
" " & args
proc launcherActivated() =
# 1) Executing the main-program in a loop.
# 2) Each time the main-program quits, there's a check
# for a new version
echo "Launcher initialized"
while true:
if fileExists(getAppDir() & "/websitecreator_main_new"):
moveFile(getAppDir() & "/websitecreator_main_new", getAppDir() &
"/websitecreator_main")
echo execProcess(getAppDir() & "/websitecreator_main" & addArgs(true))
echo "Quitted"
# Checking if the main-program file exists. If not it will
# be compiled with args and compiler options (compiler
# options should be specified in the *.nim.pkg)
if not fileExists(getAppDir() & "/websitecreator_main") or compileOptions
!= "":
echo "Compiling"
echo " - Using params:" & addArgs()
echo " - Using compile options in *.nim.cfg"
echo " "
echo " .. please wait while compiling"
let output = execCmd("nim c " & compileOptions & " " & getAppDir() &
"/websitecreator_main.nim")
if output == 1:
echo "\nAn error occured"
else:
echo "\nCompiling done. Starting:"
launcherActivated()
else:
launcherActivated()