From 4590b0ce7a16abb0b1822e8a5328c07b8cfcf44b Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Thu, 2 Jan 2025 17:38:10 +0000 Subject: [PATCH] update process for windows --- norg/utils/update.nim | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/norg/utils/update.nim b/norg/utils/update.nim index 6b4903a..a730b84 100644 --- a/norg/utils/update.nim +++ b/norg/utils/update.nim @@ -11,12 +11,18 @@ import os import ../model/log_type import version -const sh = """ +const SH = """ #!/usr/bin/env sh mv {new} {old} {old} --version rm -r tmp """ +const BAT = """ +move {new} {old} +{old} --version +rmdir /s tmp +""" + proc extractUpdate(name, file: string) = var client = newHttpClient() try: @@ -24,22 +30,19 @@ proc extractUpdate(name, file: string) = client.downloadFile(file,fmt"tmp/{name}") let cwd = getAppDir() let cwf = getAppFilename() - case hostOS - of "linux": - let ok = osproc.execCmd(fmt"tar xf tmp/{name} -C tmp/") - if ok == 0: - copyFile(cwf,fmt"{cwd}/norg_backup") - let content = sh.replace("{new}", "tmp/norg").replace("{old}", cwf) + let ok = osproc.execCmd(fmt"tar xf tmp/{name} -C tmp/") + copyFile(cwf,fmt"{cwd}/norg_backup") + if ok == 0: + case hostOS + of "linux","freebsd": + let content = SH.replace("{new}", "tmp/norg").replace("{old}", cwf) writeFile("tmp/norg_update", content) discard osproc.execCmd("sh tmp/norg_update") quit(0) - of "windows": - let ok = osproc.execCmd(fmt"decompress tmp/{name} -C tmp/") - if ok == 0: - copyFile(cwf,fmt"{cwd}/norg_backup") - let content = sh.replace("{new}", "tmp/norg").replace("{old}", cwf) + of "windows": + let content = BAT.replace("{new}", "tmp/norg").replace("{old}", cwf) writeFile("tmp/norg_update", content) - discard osproc.execCmd("sh tmp/norg_update") + discard osproc.execCmd("tmp/norg_update") quit(0) except: error getCurrentExceptionMsg()