2015-10-23 19:02:38 +00:00
|
|
|
// Copyright (C) 2015 The Syncthing Authors.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
2017-02-09 06:52:18 +00:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2015-10-23 19:02:38 +00:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
|
|
|
|
2017-08-19 14:36:56 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/fs"
|
2015-10-23 19:02:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func nulString(bs []byte) string {
|
|
|
|
for i := range bs {
|
|
|
|
if bs[i] == 0 {
|
|
|
|
return string(bs[:i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return string(bs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func defaultConfigDir() string {
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "windows":
|
|
|
|
if p := os.Getenv("LocalAppData"); p != "" {
|
|
|
|
return filepath.Join(p, "Syncthing")
|
|
|
|
}
|
|
|
|
return filepath.Join(os.Getenv("AppData"), "Syncthing")
|
|
|
|
|
|
|
|
case "darwin":
|
2017-08-19 14:36:56 +00:00
|
|
|
dir, err := fs.ExpandTilde("~/Library/Application Support/Syncthing")
|
2015-10-23 19:02:38 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
return dir
|
|
|
|
|
|
|
|
default:
|
|
|
|
if xdgCfg := os.Getenv("XDG_CONFIG_HOME"); xdgCfg != "" {
|
|
|
|
return filepath.Join(xdgCfg, "syncthing")
|
|
|
|
}
|
2017-08-19 14:36:56 +00:00
|
|
|
dir, err := fs.ExpandTilde("~/.config/syncthing")
|
2015-10-23 19:02:38 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
return dir
|
|
|
|
}
|
|
|
|
}
|