2016-10-04 15:42:36 +05:00
|
|
|
// URTator - Urban Terror server browser and game launcher, written in
|
|
|
|
// Go.
|
|
|
|
//
|
|
|
|
// Copyright (c) 2016, Stanslav N. a.k.a pztrn (or p0z1tr0n)
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under Terms and Conditions of GNU General Public License
|
|
|
|
// version 3 or any higher.
|
|
|
|
// ToDo: put full text of license here.
|
|
|
|
package configuration
|
|
|
|
|
|
|
|
import (
|
2018-11-10 20:58:15 +05:00
|
|
|
// stdlib
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"runtime"
|
2016-10-04 15:42:36 +05:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2018-11-10 20:58:15 +05:00
|
|
|
// Configuration from database.
|
|
|
|
Cfg map[string]string
|
|
|
|
// Temporary (or runtime) configuration things.
|
|
|
|
TEMP map[string]string
|
2016-10-04 15:42:36 +05:00
|
|
|
}
|
|
|
|
|
2016-10-04 18:32:50 +05:00
|
|
|
func (c *Config) initializePathsMac() {
|
2018-11-10 20:58:15 +05:00
|
|
|
fmt.Println("Initializing configuration paths...")
|
|
|
|
home_path := os.Getenv("HOME")
|
|
|
|
data_path := path.Join(home_path, "Library", "Application Support", "URTrator")
|
|
|
|
fmt.Println("Will use data path: " + data_path)
|
|
|
|
c.TEMP["DATA"] = data_path
|
2016-10-04 18:32:50 +05:00
|
|
|
|
2018-11-10 20:58:15 +05:00
|
|
|
profile_path := path.Join(home_path, "Library", "Application Support", "Quake3", "q3ut4")
|
|
|
|
c.TEMP["DEFAULT_PROFILE_PATH"] = profile_path
|
2017-05-08 23:38:54 +05:00
|
|
|
|
2018-11-10 20:58:15 +05:00
|
|
|
if _, err := os.Stat(data_path); os.IsNotExist(err) {
|
|
|
|
os.MkdirAll(data_path, 0755)
|
|
|
|
}
|
2016-10-04 18:32:50 +05:00
|
|
|
}
|
|
|
|
|
2016-10-04 15:42:36 +05:00
|
|
|
func (c *Config) initializePathsNix() {
|
2018-11-10 20:58:15 +05:00
|
|
|
fmt.Println("Initializing configuration paths...")
|
2016-10-04 15:42:36 +05:00
|
|
|
|
2018-11-10 20:58:15 +05:00
|
|
|
// Get storage path. By default we will use ~/.config/urtrator
|
|
|
|
// directory.
|
|
|
|
home_path := os.Getenv("HOME")
|
|
|
|
data_path := path.Join(home_path, ".config", "urtrator")
|
|
|
|
fmt.Println("Will use data path: " + data_path)
|
|
|
|
c.TEMP["DATA"] = data_path
|
2016-10-04 15:42:36 +05:00
|
|
|
|
2018-11-10 20:58:15 +05:00
|
|
|
profile_path := path.Join(home_path, ".q3a", "q3ut4")
|
|
|
|
c.TEMP["DEFAULT_PROFILE_PATH"] = profile_path
|
2017-05-08 23:38:54 +05:00
|
|
|
|
2018-11-10 20:58:15 +05:00
|
|
|
if _, err := os.Stat(data_path); os.IsNotExist(err) {
|
|
|
|
os.MkdirAll(data_path, 0755)
|
|
|
|
}
|
2016-10-04 15:42:36 +05:00
|
|
|
}
|
|
|
|
|
2016-10-05 14:05:37 +05:00
|
|
|
func (c *Config) initializePathsWin() {
|
2018-11-10 20:58:15 +05:00
|
|
|
fmt.Println("Initializing configuration paths...")
|
|
|
|
homepath_without_drive := os.Getenv("HOMEPATH")
|
|
|
|
homedrive := os.Getenv("HOMEDRIVE")
|
|
|
|
data_path := path.Join(homedrive, homepath_without_drive, "AppData", "Roaming", "URTrator")
|
|
|
|
c.TEMP["DATA"] = data_path
|
2016-10-05 14:05:37 +05:00
|
|
|
|
2018-11-10 20:58:15 +05:00
|
|
|
// Verify it!
|
|
|
|
profile_path := path.Join(homedrive, homepath_without_drive, "AppData", "UrbanTerror43", "q3ut4")
|
|
|
|
c.TEMP["DEFAULT_PROFILE_PATH"] = profile_path
|
2017-05-08 23:38:54 +05:00
|
|
|
|
2018-11-10 20:58:15 +05:00
|
|
|
if _, err := os.Stat(data_path); os.IsNotExist(err) {
|
|
|
|
os.MkdirAll(data_path, 0755)
|
|
|
|
}
|
2016-10-05 14:05:37 +05:00
|
|
|
}
|
|
|
|
|
2016-10-04 15:42:36 +05:00
|
|
|
func (c *Config) initializeStorages() {
|
2018-11-10 20:58:15 +05:00
|
|
|
c.TEMP = make(map[string]string)
|
|
|
|
c.Cfg = make(map[string]string)
|
2016-10-04 15:42:36 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) Initialize() {
|
2018-11-10 20:58:15 +05:00
|
|
|
fmt.Println("Initializing configuration storage...")
|
|
|
|
c.initializeStorages()
|
2016-10-04 15:42:36 +05:00
|
|
|
|
2018-11-10 20:58:15 +05:00
|
|
|
if runtime.GOOS == "linux" {
|
|
|
|
c.initializePathsNix()
|
|
|
|
} else if runtime.GOOS == "darwin" {
|
|
|
|
c.initializePathsMac()
|
|
|
|
} else if runtime.GOOS == "windows" {
|
|
|
|
c.initializePathsWin()
|
|
|
|
} else {
|
|
|
|
panic("We're not ready for other OSes yet!")
|
|
|
|
}
|
2016-10-04 15:42:36 +05:00
|
|
|
}
|