示例#1
0
文件: save.go 项目: btfidelis/gync
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
}
示例#2
0
文件: save.go 项目: btfidelis/gync
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)
}
示例#3
0
文件: save.go 项目: btfidelis/gync
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)
}
示例#4
0
文件: config.go 项目: btfidelis/gync
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
}
示例#5
0
文件: save.go 项目: btfidelis/gync
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)
		}
	}
}
示例#6
0
文件: save.go 项目: btfidelis/gync
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()}
}