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/files,
|
||||||
std/paths,
|
std/paths,
|
||||||
std/strformat,
|
std/strformat,
|
||||||
|
std/strutils,
|
||||||
std/tempfiles
|
std/tempfiles
|
||||||
|
|
||||||
|
import
|
||||||
|
constants
|
||||||
|
|
||||||
type
|
type
|
||||||
EmbeddedFS* = object
|
EmbeddedFS* = object
|
||||||
EmbeddedFSError* = object of CatchableError
|
EmbeddedFSError* = object of CatchableError
|
||||||
|
|
||||||
let embeddedFs* = EmbeddedFS()
|
|
||||||
|
|
||||||
when not defined( emscripten ):
|
when not defined( emscripten ):
|
||||||
import zippy/tarballs
|
import zippy/tarballs
|
||||||
|
|
@ -33,6 +36,7 @@ else:
|
||||||
let confFile* = confDir / Path("config.ini")
|
let confFile* = confDir / Path("config.ini")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
proc path*( data: EmbeddedFS, path: string ): Path =
|
proc path*( data: EmbeddedFS, path: string ): Path =
|
||||||
## Returns the path of an embedded file.
|
## Returns the path of an embedded file.
|
||||||
return dataDir / Path( path )
|
return dataDir / Path( path )
|
||||||
|
|
@ -48,23 +52,38 @@ proc `[]`*( data: EmbeddedFS, path: string ): string =
|
||||||
return f.readAll
|
return f.readAll
|
||||||
|
|
||||||
|
|
||||||
# TODO: version check, extract over old stuff
|
proc newEmbeddedFS(): EmbeddedFS =
|
||||||
# no-op if versions match
|
## Initialize the embedded filesystem.
|
||||||
#
|
##
|
||||||
proc update*( e: EmbeddedFS ) =
|
## If the current runtime version is different than the binary version,
|
||||||
when not defined( emscripten ):
|
## 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( getDataDir() )
|
||||||
createDir( $confDir )
|
createDir( $confDir )
|
||||||
|
|
||||||
# check existing path / version
|
|
||||||
|
|
||||||
let ( tarball, path ) = createTempFile( "{appname}_resources_".fmt, ".tgz" )
|
let ( tarball, path ) = createTempFile( "{appname}_resources_".fmt, ".tgz" )
|
||||||
tarball.write( RESOURCES )
|
tarball.write( RESOURCES )
|
||||||
tarball.close
|
tarball.close
|
||||||
|
|
||||||
|
removeDir( $dataDir )
|
||||||
extractAll( path, $dataDir )
|
extractAll( path, $dataDir )
|
||||||
removeFile( path )
|
removeFile( path )
|
||||||
|
|
||||||
let source = dataDir / Path( "config.ini" )
|
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 raylib
|
||||||
|
|
||||||
import
|
import
|
||||||
|
lib/constants,
|
||||||
lib/configuration,
|
lib/configuration,
|
||||||
lib/embeddedfs
|
lib/embeddedfs
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue