changeset 235:5f6d3511ef79

did: replace zippy with "standard" nim zip, compiled from source, fix some errors
author Sam <sam@basx.dev>
date Sat, 20 May 2023 17:44:55 +0700
parents 3918e42bf26e
children 4a7b8cd88e0e
files config.nims semicongine.nimble src/semicongine/resources.nim tests/test_resources.nim
diffstat 4 files changed, 21 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/config.nims	Sat May 20 16:35:23 2023 +0700
+++ b/config.nims	Sat May 20 17:44:55 2023 +0700
@@ -16,6 +16,7 @@
   switch("mm", "orc")
   switch("experimental", "strictEffects")
   switch("threads", "on")
+  switch("d", "useLibzipSrc")
   var buildType = DEBUG
   var platformDir = ""
   if defined(linux):
--- a/semicongine.nimble	Sat May 20 16:35:23 2023 +0700
+++ b/semicongine.nimble	Sat May 20 17:44:55 2023 +0700
@@ -12,4 +12,4 @@
 requires "nim >= 1.6.10"
 requires "winim"
 requires "xlib"
-requires "zippy"
+requires "zip"
--- a/src/semicongine/resources.nim	Sat May 20 16:35:23 2023 +0700
+++ b/src/semicongine/resources.nim	Sat May 20 17:44:55 2023 +0700
@@ -40,12 +40,12 @@
         result.add file
 
   iterator walkResources_intern(): string =
-    for i in walkDir(modRoot(), relative=true):
-      yield i.path
+    for file in walkDirRec(modRoot(), relative=true):
+      yield file
 
 elif thebundletype == Zip:
 
-  import zippy/ziparchives
+  import zip/zipfiles
 
   proc resourceRoot(): string =
     joinPath(absolutePath(getAppDir()), RESOURCEROOT)
@@ -53,9 +53,12 @@
     joinPath(resourceRoot(), selectedMod)
 
   proc loadResource_intern(path: string): Stream =
-    let reader = openZipArchive(modRoot() & ".zip")
-    result = newStringStream(reader.extractFile(path))
-    reader.close()
+    var archive: ZipArchive
+    if not archive.open(modRoot() & ".zip", fmRead):
+      raise newException(Exception, "Unable to open file " & path)
+    # read all here so we can close the stream
+    result = newStringStream(archive.getStream(path).readAll())
+    archive.close()
 
   proc modList_intern(): seq[string] =
     for kind, file in walkDir(resourceRoot(), relative=true):
@@ -63,10 +66,14 @@
         result.add file[0 ..< ^4]
 
   iterator walkResources_intern(): string =
-    let reader = openZipArchive(modRoot() & ".zip")
-    for i in reader.walkFiles:
-      yield i.splitPath().tail
-    reader.close()
+    var archive: ZipArchive
+    if not archive.open(modRoot() & ".zip", fmRead):
+      raise newException(Exception, "Unable to open file " & modRoot() & ".zip")
+
+    for i in archive.walkFiles:
+      if i[^1] != '/':
+        yield i
+    archive.close()
 
 elif thebundletype == Exe:
 
--- a/tests/test_resources.nim	Sat May 20 16:35:23 2023 +0700
+++ b/tests/test_resources.nim	Sat May 20 17:44:55 2023 +0700
@@ -1,4 +1,4 @@
-import std/times
+import std/streams
 
 import semicongine
 
@@ -8,7 +8,7 @@
     echo modName, ":"
     selectedMod = modName
     for i in walkResources():
-      echo "  ", i, ": ", loadResource(i)[]
+      echo "  ", i, ": ", loadResource(i).readAll().len
 
 when isMainModule:
   main()