|
20 | 20 | package systray
|
21 | 21 |
|
22 | 22 | import (
|
23 |
| - "fmt" |
24 | 23 | "os"
|
25 | 24 | "os/user"
|
26 |
| - "path/filepath" |
27 | 25 |
|
28 | 26 | log "github.com/sirupsen/logrus"
|
29 | 27 |
|
@@ -185,35 +183,35 @@ type configIni struct {
|
185 | 183 | Location string
|
186 | 184 | }
|
187 | 185 |
|
188 |
| -// getconfigs parses all config files in the executable folder |
| 186 | +// getConfigs parses all config files in the .arduino-create folder |
189 | 187 | func getConfigs() []configIni {
|
190 |
| - // config.ini must be there, so call it Default |
191 |
| - src, _ := os.Executable() // TODO change path |
192 |
| - dest := filepath.Dir(src) |
| 188 | + |
| 189 | + usr, _ := user.Current() |
| 190 | + usrDir := paths.New(usr.HomeDir) // The user folder, on linux/macos /home/<usr>/ |
| 191 | + agentDir := usrDir.Join(".arduino-create") |
193 | 192 |
|
194 | 193 | var configs []configIni
|
195 | 194 |
|
196 |
| - err := filepath.Walk(dest, func(path string, f os.FileInfo, _ error) error { |
197 |
| - if !f.IsDir() { |
198 |
| - if filepath.Ext(path) == ".ini" { |
199 |
| - cfg, err := ini.LoadSources(ini.LoadOptions{IgnoreInlineComment: true, AllowPythonMultilineValues: true}, filepath.Join(dest, f.Name())) |
200 |
| - if err != nil { |
201 |
| - return err |
202 |
| - } |
203 |
| - defaultSection, err := cfg.GetSection("") |
204 |
| - name := defaultSection.Key("name").String() |
205 |
| - if name == "" || err != nil { |
206 |
| - name = "Default config" |
207 |
| - } |
208 |
| - conf := configIni{Name: name, Location: f.Name()} |
209 |
| - configs = append(configs, conf) |
| 195 | + files, err := agentDir.ReadDir() |
| 196 | + if err != nil { |
| 197 | + log.Errorf("cannot read the content of %s", agentDir) |
| 198 | + return nil |
| 199 | + } |
| 200 | + files.FilterOutDirs() |
| 201 | + files.FilterSuffix(".ini") |
| 202 | + for _, file := range files { |
| 203 | + cfg, err := ini.LoadSources(ini.LoadOptions{IgnoreInlineComment: true, AllowPythonMultilineValues: true}, file.String()) |
| 204 | + if err != nil { |
| 205 | + log.Errorf("error walking through executable configuration: %s", err) |
| 206 | + } else { |
| 207 | + defaultSection, err := cfg.GetSection("") |
| 208 | + name := defaultSection.Key("name").String() |
| 209 | + if name == "" || err != nil { |
| 210 | + name = "Default config" |
210 | 211 | }
|
| 212 | + conf := configIni{Name: name, Location: file.String()} |
| 213 | + configs = append(configs, conf) |
211 | 214 | }
|
212 |
| - return nil |
213 |
| - }) |
214 |
| - |
215 |
| - if err != nil { |
216 |
| - fmt.Println("error walking through executable configuration: %w", err) |
217 | 215 | }
|
218 | 216 |
|
219 | 217 | return configs
|
|
0 commit comments