|
| 1 | +// Copyright 2023 Arduino SA |
| 2 | +// |
| 3 | +// This program is free software: you can redistribute it and/or modify |
| 4 | +// it under the terms of the GNU Affero General Public License as published |
| 5 | +// by the Free Software Foundation, either version 3 of the License, or |
| 6 | +// (at your option) any later version. |
| 7 | +// |
| 8 | +// This program is distributed in the hope that it will be useful, |
| 9 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | +// GNU Affero General Public License for more details. |
| 12 | +// |
| 13 | +// You should have received a copy of the GNU Affero General Public License |
| 14 | +// along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 15 | + |
| 16 | +package main |
| 17 | + |
| 18 | +import ( |
| 19 | + "fmt" |
| 20 | + "os" |
| 21 | + "runtime" |
| 22 | + |
| 23 | + "github.com/arduino/go-paths-helper" |
| 24 | + "github.com/arduino/go-win32-utils" |
| 25 | +) |
| 26 | + |
| 27 | +// getDefaultArduinoCreateDataDir returns the full path to the default arduino create agent data directory |
| 28 | +func getDefaultArduinoCreateDataDir() (*paths.Path, error) { |
| 29 | + userHomeDir, err := os.UserHomeDir() |
| 30 | + if err != nil { |
| 31 | + return nil, err |
| 32 | + } |
| 33 | + |
| 34 | + switch runtime.GOOS { |
| 35 | + case "linux": |
| 36 | + return paths.New(userHomeDir, ".arduino-create-agent"), nil |
| 37 | + case "darwin": |
| 38 | + return paths.New(userHomeDir, "Library", "ArduinoCreateAgent"), nil |
| 39 | + case "windows": |
| 40 | + localAppDataPath, err := win32.GetLocalAppDataFolder() |
| 41 | + if err != nil { |
| 42 | + return nil, fmt.Errorf("unable to get Local App Data Folder: %w", err) |
| 43 | + } |
| 44 | + return paths.New(localAppDataPath, "ArduinoCreateAgent"), nil |
| 45 | + default: |
| 46 | + log.Panicf("unsupported OS: %s", runtime.GOOS) |
| 47 | + return nil, nil // unreachable |
| 48 | + } |
| 49 | +} |
0 commit comments