# HG changeset patch # User Sam # Date 1684579495 -25200 # Node ID 5f6d3511ef7980e45a257b523b91711d305c9a46 # Parent 3918e42bf26ef4cb58ebcfb419adb2cb7cbb3d00 did: replace zippy with "standard" nim zip, compiled from source, fix some errors diff -r 3918e42bf26e -r 5f6d3511ef79 config.nims --- 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): diff -r 3918e42bf26e -r 5f6d3511ef79 semicongine.nimble --- 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" diff -r 3918e42bf26e -r 5f6d3511ef79 src/semicongine/resources.nim --- 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: diff -r 3918e42bf26e -r 5f6d3511ef79 tests/test_resources.nim --- 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()