| @@ -20,17 +20,19 @@ type CurdConfig struct { |
| 20 | StoragePath string `config:"StoragePath"` |
20 | StoragePath string `config:"StoragePath"` |
| 21 | AnimeNameLanguage string `config:"AnimeNameLanguage"` |
21 | AnimeNameLanguage string `config:"AnimeNameLanguage"` |
| 22 | PercentageToMarkComplete int `config:"PercentageToMarkComplete"` |
22 | PercentageToMarkComplete int `config:"PercentageToMarkComplete"` |
| 23 | NextEpisodePrompt bool `config:"NextEpisodePrompt"` |
23 | NextEpisodePrompt bool `config:"NextEpisodePrompt"` |
| 24 | SkipOp bool `config:"SkipOp"` |
24 | SkipOp bool `config:"SkipOp"` |
| 25 | SkipEd bool `config:"SkipEd"` |
25 | SkipEd bool `config:"SkipEd"` |
| 26 | SkipFiller bool `config:"SkipFiller"` |
26 | SkipFiller bool `config:"SkipFiller"` |
| 27 | ImagePreview bool `config:"ImagePreview"` |
27 | ImagePreview bool `config:"ImagePreview"` |
| 28 | SkipRecap bool `config:"SkipRecap"` |
28 | SkipRecap bool `config:"SkipRecap"` |
| 29 | RofiSelection bool `config:"RofiSelection"` |
29 | RofiSelection bool `config:"RofiSelection"` |
| 30 | CurrentCategory bool `config:"CurrentCategory"` |
30 | CurrentCategory bool `config:"CurrentCategory"` |
| 31 | ScoreOnCompletion bool `config:"ScoreOnCompletion"` |
31 | ScoreOnCompletion bool `config:"ScoreOnCompletion"` |
| 32 | SaveMpvSpeed bool `config:"SaveMpvSpeed"` |
32 | SaveMpvSpeed bool `config:"SaveMpvSpeed"` |
| 33 | DiscordPresence bool `config:"DiscordPresence"` |
33 | AddMissingOptions bool `config:"AddMissingOptions"` |
| |
34 | AlternateScreen bool `config:"AlternateScreen"` |
| |
35 | DiscordPresence bool `config:"DiscordPresence"` |
| 34 | } |
36 | } |
| 35 | |
37 | |
| 36 | // Default configuration values as a map |
38 | // Default configuration values as a map |
| @@ -42,16 +44,18 @@ func defaultConfigMap() map[string]string { |
| 42 | "SubsLanguage": "english", |
44 | "SubsLanguage": "english", |
| 43 | "SubOrDub": "sub", |
45 | "SubOrDub": "sub", |
| 44 | "PercentageToMarkComplete": "85", |
46 | "PercentageToMarkComplete": "85", |
| 45 | "NextEpisodePrompt": "false", |
47 | "NextEpisodePrompt": "false", |
| 46 | "SkipOp": "true", |
48 | "SkipOp": "true", |
| 47 | "SkipEd": "true", |
49 | "SkipEd": "true", |
| 48 | "SkipFiller": "true", |
50 | "SkipFiller": "true", |
| 49 | "SkipRecap": "true", |
51 | "SkipRecap": "true", |
| 50 | "RofiSelection": "false", |
52 | "RofiSelection": "false", |
| 51 | "ImagePreview": "false", |
53 | "ImagePreview": "false", |
| 52 | "ScoreOnCompletion": "true", |
54 | "ScoreOnCompletion": "true", |
| 53 | "SaveMpvSpeed": "true", |
55 | "SaveMpvSpeed": "true", |
| 54 | "DiscordPresence": "true", |
56 | "AddMissingOptions": "true", |
| |
57 | "AlternateScreen": "true", |
| |
58 | "DiscordPresence": "true", |
| 55 | } |
59 | } |
| 56 | } |
60 | } |
| 57 | |
61 | |
| @@ -65,7 +69,6 @@ func GetGlobalConfig() *CurdConfig { |
| 65 | return globalConfig |
69 | return globalConfig |
| 66 | } |
70 | } |
| 67 | |
71 | |
| 68 | |
| |
| 69 | // LoadConfig reads or creates the config file, adds missing fields, and returns the populated CurdConfig struct |
72 | // LoadConfig reads or creates the config file, adds missing fields, and returns the populated CurdConfig struct |
| 70 | func LoadConfig(configPath string) (CurdConfig, error) { |
73 | func LoadConfig(configPath string) (CurdConfig, error) { |
| 71 | configPath = os.ExpandEnv(configPath) // Substitute environment variables like $HOME |
74 | configPath = os.ExpandEnv(configPath) // Substitute environment variables like $HOME |
| @@ -85,6 +88,12 @@ func LoadConfig(configPath string) (CurdConfig, error) { |
| 85 | return CurdConfig{}, fmt.Errorf("error loading config file: %v", err) |
88 | return CurdConfig{}, fmt.Errorf("error loading config file: %v", err) |
| 86 | } |
89 | } |
| 87 | |
90 | |
| |
91 | // Check AddMissingOptions setting first |
| |
92 | addMissing := true |
| |
93 | if val, exists := configMap["AddMissingOptions"]; exists { |
| |
94 | addMissing, _ = strconv.ParseBool(val) |
| |
95 | } |
| |
96 | |
| 88 | // Add missing fields to the config map |
97 | // Add missing fields to the config map |
| 89 | updated := false |
98 | updated := false |
| 90 | defaultConfigMap := defaultConfigMap() |
99 | defaultConfigMap := defaultConfigMap() |
| @@ -95,8 +104,8 @@ func LoadConfig(configPath string) (CurdConfig, error) { |
| 95 | } |
104 | } |
| 96 | } |
105 | } |
| 97 | |
106 | |
| 98 | // Write updated config back to file if there were any missing fields |
107 | // Write updated config back to file only if AddMissingOptions is true |
| 99 | if updated { |
108 | if addMissing && updated { |
| 100 | if err := saveConfigToFile(configPath, configMap); err != nil { |
109 | if err := saveConfigToFile(configPath, configMap); err != nil { |
| 101 | return CurdConfig{}, fmt.Errorf("error saving updated config file: %v", err) |
110 | return CurdConfig{}, fmt.Errorf("error saving updated config file: %v", err) |
| 102 | } |
111 | } |