From 6a2ff3b4e2e7d514ba50572fb63469733d8bd752 Mon Sep 17 00:00:00 2001 From: giongto35 Date: Fri, 6 Sep 2019 03:57:24 +0800 Subject: [PATCH] create save dir before running --- util/util.go | 11 +---------- worker/handlers.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/util/util.go b/util/util.go index 5f4cbcfa..f83dda6d 100644 --- a/util/util.go +++ b/util/util.go @@ -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" } diff --git a/worker/handlers.go b/worker/handlers.go index cfba5709..81fba6f9 100644 --- a/worker/handlers.go +++ b/worker/handlers.go @@ -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) + } +}