create save dir before running

This commit is contained in:
giongto35 2019-09-06 03:57:24 +08:00
parent 018c0c413b
commit 6a2ff3b4e2
2 changed files with 14 additions and 10 deletions

View file

@ -75,15 +75,6 @@ func GetSavePath(roomID string) string {
return savePath(roomID)
}
// GetSRAMPath returns SRAM location of game based on roomID
func GetSRAMPath(hash string) string {
return homeDir + "/.nes/sram/" + hash + ".dat"
}
func sramPath(hash string) string {
return homeDir + "/.nes/sram/" + hash + ".dat"
}
func savePath(hash string) string {
return homeDir + "/.nes/save/" + hash + ".dat"
return homeDir + "/.cr/save/" + hash + ".dat"
}

View file

@ -2,8 +2,11 @@ package worker
import (
"log"
"os"
"path"
"time"
"github.com/giongto35/cloud-game/util"
"github.com/giongto35/cloud-game/webrtc"
storage "github.com/giongto35/cloud-game/worker/cloud-storage"
"github.com/giongto35/cloud-game/worker/room"
@ -35,6 +38,10 @@ type Handler struct {
// NewHandler returns a new server
func NewHandler(overlordHost string) *Handler {
// Create offline storage folder
createOfflineStorage()
// Init online storage
onlineStorage := storage.NewInitClient()
return &Handler{
@ -159,3 +166,9 @@ func (h *Handler) Close() {
room.Close()
}
}
func createOfflineStorage() {
dir, _ := path.Split(util.GetSavePath("dummy"))
if err := os.MkdirAll(dir, 0755); err != nil {
log.Println("Failed to create offline storage, err: ", err)
}
}