2021-09-29 23:57:09 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path"
|
|
|
|
path2 "path"
|
|
|
|
"path/filepath"
|
2021-11-11 03:00:38 +00:00
|
|
|
"pikapika/main/config"
|
2021-09-29 23:57:09 +00:00
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
applicationDir, err := os.UserHomeDir()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "windows":
|
|
|
|
// applicationDir = path.Join(applicationDir, "AppData", "Roaming")
|
|
|
|
file, err := exec.LookPath(os.Args[0])
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
path, err := filepath.Abs(file)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
i := strings.LastIndex(path, "/")
|
|
|
|
if i < 0 {
|
|
|
|
i = strings.LastIndex(path, "\\")
|
|
|
|
}
|
|
|
|
if i < 0 {
|
|
|
|
panic(errors.New(" can't find \"/\" or \"\\\""))
|
|
|
|
}
|
2021-11-11 03:00:38 +00:00
|
|
|
applicationDir = path2.Join(path[0:i+1], "data")
|
2021-09-29 23:57:09 +00:00
|
|
|
case "darwin":
|
2021-11-11 03:00:38 +00:00
|
|
|
applicationDir = path.Join(applicationDir, "Library", "Application Support", "pikapika")
|
2021-09-29 23:57:09 +00:00
|
|
|
case "linux":
|
2021-11-11 03:00:38 +00:00
|
|
|
applicationDir = path.Join(applicationDir, ".pikapika")
|
2021-09-29 23:57:09 +00:00
|
|
|
default:
|
|
|
|
panic(errors.New("not supported system"))
|
|
|
|
}
|
|
|
|
if _, err = os.Stat(applicationDir); err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
err = os.MkdirAll(applicationDir, os.FileMode(0700))
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
config.InitApplication(applicationDir)
|
|
|
|
}
|