Skip to content

Commit

Permalink
Implement workaround for broken copyFile (Fixes #11), remove winim re…
Browse files Browse the repository at this point in the history
…s file
  • Loading branch information
chvancooten committed Mar 12, 2023
1 parent bef008f commit fc6bc9c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
4 changes: 1 addition & 3 deletions NimPlant.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ def compile_nim(binary_type, xor_key, debug=False):

# Construct compilation command
if binary_type == "exe" or binary_type == "exe-selfdelete" or binary_type == "dll":
compile_command = (
f"nim c --hints:off --warnings:off -d:xor_key={xor_key} -d:release -d:strip"
)
compile_command = f"nim c --hints:off --warnings:off -d:xor_key={xor_key} -d:release -d:strip -d:noRes"

if debug:
compile_command = compile_command + " -d:verbose"
Expand Down
8 changes: 5 additions & 3 deletions client/commands/cp.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from os import copyDir, copyFile, copyFileToDir, dirExists, splitPath, `/`
from ../util/winUtils import copyDir
from os import dirExists, splitPath, `/`
from strutils import join
from winim/lean import CopyFileA, LPCSTR, FALSE, winstrConverterStringToPtrChar

# Copy files or directories
proc cp*(args : varargs[string]) : string =
Expand All @@ -23,8 +25,8 @@ proc cp*(args : varargs[string]) : string =

# Copying a file
elif dirExists(destination):
copyFileToDir(source, destination)
CopyFileA(source, destination/splitPath(source).tail, FALSE)
else:
copyFile(source, destination)
CopyFileA(source, destination, FALSE)

result = obf("Copied '") & source & obf("' to '") & destination & obf("'.")
3 changes: 2 additions & 1 deletion client/commands/mv.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from os import dirExists, moveFile, moveDir, splitPath, `/`
from os import dirExists, moveFile, splitPath, `/`
from ../util/winUtils import moveDir
from strutils import join

# Move a file or directory
Expand Down
22 changes: 20 additions & 2 deletions client/util/winUtils.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from nativesockets import getHostName, gethostbyname
from os import getCurrentProcessId, splitPath, getAppFilename
import winlean
from os import getCurrentProcessId, splitPath, getAppFilename, createDir, walkDir, splitPath, pcDir, `/`, removeDir
from winim/lean import CopyFileA, FALSE, ULONG, winstrConverterStringToPtrChar
import ../commands/whoami
import strenc

Expand Down Expand Up @@ -37,6 +37,24 @@ proc getWindowsVersion*() : string =
var vInfo = obf("Windows ") & $versionInfo.dwMajorVersion & obf(" build ") & $versionInfo.dwBuildNumber
result = vInfo

# Define copyDir and moveDir functions to override os stdlib
# This fixes a bug where any function with using copyFile does not work with Win11 DLLs
# See: https://github.com/nim-lang/Nim/issues/21504
proc copyDir*(source, dest: string) =
createDir(dest)
for kind, path in walkDir(source):
var
noSource = splitPath(path).tail
dPath = dest / noSource
if kind == pcDir:
copyDir(path, dPath)
else:
CopyFileA(path, dPath, FALSE)

proc moveDir*(source, dest: string) =
copydir(source, dest)
removeDir(source)

# Get the username
proc getUsername*() : string =
result = whoami()
Expand Down

0 comments on commit fc6bc9c

Please sign in to comment.