Skip to content

Commit

Permalink
create save dir before running
Browse files Browse the repository at this point in the history
  • Loading branch information
giongto35 committed Sep 5, 2019
1 parent 845d229 commit 7f0e1d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
11 changes: 1 addition & 10 deletions util/util.go
Expand Up @@ -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"
}
13 changes: 13 additions & 0 deletions worker/handlers.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 7f0e1d3

Please sign in to comment.