-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (50 loc) · 1.55 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* main.go © Penguin_Spy 2024
*
* 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, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package main
import (
"io"
"log"
"os"
"path/filepath"
"strings"
)
var appDataPath string
func main() {
// saves the absolute path to the platform-specific app data directory
// or the current directory if running from "go run ."
if strings.Contains(filepath.Dir(os.Args[0]), "go-build") {
appDataPath = "."
} else {
userConfigDir, err := os.UserConfigDir()
if err != nil {
log.Printf("[main] failed to load app data directory! - %v\n", err)
return
}
appDataPath = filepath.Join(userConfigDir, "pylon-launcher")
if err := os.MkdirAll(userConfigDir, os.ModeDir); err != nil {
log.Printf("[main] failed to create app data directory! - %v\n", err)
return
}
}
// save the old log (ignoring any errors, the file might not exist and that's fine)
os.Rename(filepath.Join(appDataPath, "launcher-current.log"), filepath.Join(appDataPath, "launcher-previous.log"))
// and open the new log file
logFile, err := os.Create(filepath.Join(appDataPath, "launcher-current.log"))
if err != nil {
log.Printf("[main] failed to open log file (continuing anyways) - %v\n", err)
}
defer logFile.Close()
mw := io.MultiWriter(os.Stdout, logFile)
log.SetOutput(mw)
log.Printf("[main] using data path %q\n", appDataPath)
// start the program
go func() {
loadAllPlugins()
}()
GUI_start()
closeAllPlugins()
}