Skip to content

Commit 048d688

Browse files
committed
fixed filepath bug in windows
1 parent 1926523 commit 048d688

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

main.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log"
88
"net/http"
99
"os"
10+
"path/filepath"
1011
)
1112

1213
type Config struct {
@@ -40,7 +41,7 @@ func failOnError(err error, msg string) {
4041

4142
// Loads server configuration files
4243
// JSON config file contains default values,
43-
// any provided flags to the binary will overwrite values in config file.
44+
// config file will overwrite any provided flags
4445
func loadServerConfig(f string) {
4546
file, err := os.Open(f)
4647
failOnError(err, "Error loading config file.")
@@ -64,11 +65,11 @@ func parseFlags() {
6465
config.FactorioDir = *factorioDir
6566
config.ServerIP = *factorioIP
6667
config.ServerPort = *factorioPort
67-
config.FactorioSavesDir = config.FactorioDir + "/saves"
68-
config.FactorioModsDir = config.FactorioDir + "/mods"
69-
config.FactorioConfigFile = config.FactorioDir + "/" + *factorioConfigFile
70-
config.FactorioBinary = config.FactorioDir + "/" + *factorioBinary
71-
config.FactorioLog = config.FactorioDir + "/factorio-current.log"
68+
config.FactorioSavesDir = filepath.Join(config.FactorioDir, "saves")
69+
config.FactorioModsDir = filepath.Join(config.FactorioDir, "/mods")
70+
config.FactorioConfigFile = filepath.Join(config.FactorioDir, *factorioConfigFile)
71+
config.FactorioBinary = filepath.Join(config.FactorioDir, *factorioBinary)
72+
config.FactorioLog = filepath.Join(config.FactorioDir, "/factorio-current.log")
7273
config.MaxUploadSize = *factorioMaxUpload
7374
}
7475

mods.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io/ioutil"
88
"log"
99
"os"
10+
"path/filepath"
1011
"strings"
1112
)
1213

@@ -38,6 +39,7 @@ func listInstalledMods(modDir string) ([]string, error) {
3839
return result, nil
3940
}
4041

42+
// Delete mod by provided filename
4143
func rmMod(modName string) error {
4244
removed := false
4345
if modName == "" {
@@ -72,11 +74,21 @@ func rmMod(modName string) error {
7274
return nil
7375
}
7476

77+
func createModPackDir() error {
78+
err := os.Mkdir(config.FactorioDir+"/modpacks", 0775)
79+
if err != nil {
80+
log.Printf("Could not create modpacks directory: %s", err)
81+
return err
82+
}
83+
84+
return nil
85+
}
86+
7587
// Parses mod-list.json file in factorio/mods
7688
// returns ModList struct
7789
func parseModList() (ModList, error) {
7890
var mods ModList
79-
modListFile := config.FactorioModsDir + "/mod-list.json"
91+
modListFile := filepath.Join(config.FactorioModsDir, "/mod-list.json")
8092

8193
modList, err := ioutil.ReadFile(modListFile)
8294
if err != nil {
@@ -125,7 +137,7 @@ func (m *ModList) toggleMod(name string) error {
125137
// Saves ModList object to mod-list.json file
126138
// Overwrites old file
127139
func (m ModList) save() error {
128-
modListFile := config.FactorioModsDir + "/mod-list.json"
140+
modListFile := filepath.Join(config.FactorioModsDir, "/mod-list.json")
129141
b, _ := json.MarshalIndent(m, "", " ")
130142

131143
err := ioutil.WriteFile(modListFile, b, 0644)

0 commit comments

Comments
 (0)