Beispiel #1
0
func GetSaveCollection() SaveCollection {
	io := core.NewIOManager(GetSaveLocal())
	var saveCol SaveCollection
	saves := io.LoadFile()

	err := json.Unmarshal(saves, &saveCol)

	if err != nil {
		log.Fatal(err)
	}

	return saveCol
}
Beispiel #2
0
func (save *Save) Save() {
	io := core.NewIOManager(GetSaveLocal())
	saveCol := GetSaveCollection()

	saveCol.Saves = append(saveCol.Saves, *save)

	saves, err := json.Marshal(saveCol)

	if err != nil {
		log.Fatal(err)
	}

	io.SaveObj(saves)
}
Beispiel #3
0
func (saveCol *SaveCollection) Remove(id int) {
	io := core.NewIOManager(GetSaveLocal())

	if id != -1 {
		saveCol.Saves = append(saveCol.Saves[:id], saveCol.Saves[id+1:]...)
	}

	saves, err := json.Marshal(saveCol)

	if err != nil {
		log.Fatal("On Delete:", err)
	}

	io.SaveObj(saves)
}
Beispiel #4
0
func GetConfig() Config {
	_, file, _, _ := runtime.Caller(1)
	configPath := path.Join(path.Dir(file), CONFIG_FILE)
	io := core.NewIOManager(configPath)
	configStruct := Config{}

	config := io.LoadFile()

	err := json.Unmarshal(config, &configStruct)

	if err != nil {
		log.Fatal("Config loading: ", err)
	}

	return configStruct
}
Beispiel #5
0
func CheckSaveFile() {
	_, err := os.Stat(GetSaveLocal())

	if os.IsNotExist(err) {
		io := core.NewIOManager(path.Dir(GetSaveLocal()))
		err := io.InitDirectory()

		if err != nil {
			log.Fatal("Failed initializing:", err)
		}

		io.Path = GetSaveLocal()

		err = io.PutEmptyJson()

		if err != nil {
			log.Fatal("Failed initializing:", err)
		}
	}
}
Beispiel #6
0
func NewSave(name string, local string) *Save {
	errName := validateName(name)
	file, errPath := os.Stat(local)

	if errName != nil {
		fmt.Println(errName)
		return nil
	}

	if errPath != nil {
		fmt.Println("The path provided does not exist")
		return nil
	}

	conf := GetConfig()

	io := core.NewIOManager(path.Join(conf.BackupPath, name))
	io.InitDirectory()
	core.CopyDirContents(local, path.Join(conf.BackupPath, name))

	return &Save{name, local, file.IsDir()}
}