Implement resource auto-updates.
This commit is contained in:
parent
e01dc377a7
commit
3d8dc5cdf2
5 changed files with 42 additions and 16 deletions
BIN
resources.tgz
BIN
resources.tgz
Binary file not shown.
1
resources/.version
Normal file
1
resources/.version
Normal file
|
|
@ -0,0 +1 @@
|
|||
0.0.1
|
||||
5
src/lib/constants.nim
Normal file
5
src/lib/constants.nim
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# vim: set et sta sw=4 ts=4 :
|
||||
|
||||
# Don't forget to update resources/.version to match this!
|
||||
const VERSION* = "0.0.1"
|
||||
|
||||
|
|
@ -9,13 +9,16 @@ import
|
|||
std/files,
|
||||
std/paths,
|
||||
std/strformat,
|
||||
std/strutils,
|
||||
std/tempfiles
|
||||
|
||||
import
|
||||
constants
|
||||
|
||||
type
|
||||
EmbeddedFS* = object
|
||||
EmbeddedFSError* = object of CatchableError
|
||||
|
||||
let embeddedFs* = EmbeddedFS()
|
||||
|
||||
when not defined( emscripten ):
|
||||
import zippy/tarballs
|
||||
|
|
@ -33,6 +36,7 @@ else:
|
|||
let confFile* = confDir / Path("config.ini")
|
||||
|
||||
|
||||
|
||||
proc path*( data: EmbeddedFS, path: string ): Path =
|
||||
## Returns the path of an embedded file.
|
||||
return dataDir / Path( path )
|
||||
|
|
@ -48,23 +52,38 @@ proc `[]`*( data: EmbeddedFS, path: string ): string =
|
|||
return f.readAll
|
||||
|
||||
|
||||
# TODO: version check, extract over old stuff
|
||||
# no-op if versions match
|
||||
#
|
||||
proc update*( e: EmbeddedFS ) =
|
||||
when not defined( emscripten ):
|
||||
proc newEmbeddedFS(): EmbeddedFS =
|
||||
## Initialize the embedded filesystem.
|
||||
##
|
||||
## If the current runtime version is different than the binary version,
|
||||
## re-extract the embedded filesystem to disk.
|
||||
|
||||
result = EmbeddedFS()
|
||||
when defined( emscripten ): return
|
||||
|
||||
try:
|
||||
var fsVersion = readFile( $result.path(".version") )
|
||||
fsVersion.removeSuffix
|
||||
if fsVersion == VERSION: return
|
||||
except:
|
||||
discard
|
||||
|
||||
echo "Extracting embedded resources for v{VERSION}".fmt
|
||||
|
||||
createDir( getDataDir() )
|
||||
createDir( $confDir )
|
||||
|
||||
# check existing path / version
|
||||
|
||||
let ( tarball, path ) = createTempFile( "{appname}_resources_".fmt, ".tgz" )
|
||||
tarball.write( RESOURCES )
|
||||
tarball.close
|
||||
|
||||
removeDir( $dataDir )
|
||||
extractAll( path, $dataDir )
|
||||
removeFile( path )
|
||||
|
||||
let source = dataDir / Path( "config.ini" )
|
||||
if not fileExists( confFile ): moveFile( source, confFile )
|
||||
if not fileExists( confFile ): copyFile( $source, $confFile )
|
||||
|
||||
|
||||
let embeddedFs* = newEmbeddedFS()
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import reasings
|
|||
import raylib
|
||||
|
||||
import
|
||||
lib/constants,
|
||||
lib/configuration,
|
||||
lib/embeddedfs
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue