Added extract command (extracts resources to the current working directory).
This commit is contained in:
parent
b68107b74a
commit
093cef549c
37
cmd/tins2020/extract.go
Normal file
37
cmd/tins2020/extract.go
Normal file
@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
rice "github.com/GeertJohan/go.rice"
|
||||
)
|
||||
|
||||
func copyFile(path string, file *rice.File) error {
|
||||
dir := filepath.Dir(path)
|
||||
os.MkdirAll(dir, 0777)
|
||||
dst, err := os.Create(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer dst.Close()
|
||||
_, err = io.Copy(dst, file)
|
||||
return err
|
||||
}
|
||||
|
||||
func copyBoxToDisk(box *rice.Box) error {
|
||||
return box.Walk("", func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
src, err := box.Open(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return copyFile(filepath.Join(box.Name(), path), src)
|
||||
})
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
|
||||
rice "github.com/GeertJohan/go.rice"
|
||||
@ -26,6 +27,20 @@ func logSDLVersion() {
|
||||
}
|
||||
|
||||
func run() error {
|
||||
var extract bool
|
||||
flag.BoolVar(&extract, "extract-resources", false, "extracts all resources to the current working directory")
|
||||
flag.Parse()
|
||||
|
||||
ctx, err := tins2020.NewContext(rice.MustFindBox("res"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer ctx.Destroy()
|
||||
|
||||
if extract {
|
||||
return copyBoxToDisk(ctx.Resources.Box())
|
||||
}
|
||||
|
||||
if err := sdl.Init(sdl.INIT_EVERYTHING); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -38,12 +53,6 @@ func run() error {
|
||||
}
|
||||
defer ttf.Quit()
|
||||
|
||||
ctx, err := tins2020.NewContext(rice.MustFindBox("res"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer ctx.Destroy()
|
||||
|
||||
if ctx.Settings.Window.Location == nil {
|
||||
ctx.Settings.Window.Location = tins2020.PtPtr(sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED)
|
||||
}
|
||||
|
@ -13,6 +13,10 @@ type Resources struct {
|
||||
copy vfs.CopyDir
|
||||
}
|
||||
|
||||
func (r *Resources) Box() *rice.Box {
|
||||
return r.box
|
||||
}
|
||||
|
||||
func (r *Resources) Destroy() {
|
||||
r.copy.Destroy()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user