-
Notifications
You must be signed in to change notification settings - Fork 8
/
settings.go
52 lines (43 loc) · 1.15 KB
/
settings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"encoding/json"
"os"
)
type Settings struct {
UseSavedPosition bool `json:"use_saved_position"`
PositionX int `json:"position_x"`
PositionY int `json:"position_y"`
Resolution int32 `json:"resolution"`
Shaders int32 `json:"shaders"`
Encoder int32 `json:"encoder"`
Crf int32 `json:"crf"`
OutputFormat int32 `json:"output_format"`
CompatibilityMode bool `json:"compatibility_mode"`
DebugMode bool `json:"debug_mode"`
Version string `json:"version"`
}
func saveSettings() {
os.Remove("settings.json") // Ignore error as file may not exist
file, err := os.Create("settings.json")
check(err)
marshalled, err := json.Marshal(settings)
if err != nil {
return
}
_, err = file.Write(marshalled)
check(err)
}
func loadSettings() bool {
bytes, err := os.ReadFile("settings.json")
if err != nil {
return false
}
loadedSettings := Settings{}
err = json.Unmarshal(bytes, &loadedSettings)
if err != nil || loadedSettings.Version != version {
os.Remove("settings.json")
return false
}
settings = loadedSettings
return true
}