8
8
"golang.org/x/term"
9
9
"os"
10
10
"os/exec"
11
+ "path/filepath"
11
12
"runtime"
12
13
"strconv"
13
14
"strings"
@@ -61,16 +62,25 @@ func runCommand(command string, args ...string) error {
61
62
}
62
63
63
64
func main () {
64
- var tibulaCommand = "./tibula"
65
+ var cwd = filepath .Dir (os .Args [0 ])
66
+ var tibulaCommand = filepath .Join (cwd , "tibula" )
67
+ var tibulaJson = filepath .Join (cwd , "tibula.json" )
68
+ var tibulaDb = filepath .Join (cwd , "tibula.db" )
69
+
65
70
if osType () == "windows" {
66
- tibulaCommand = ".\t ibula.exe"
71
+ tibulaCommand += ".exe"
72
+ }
73
+
74
+ if _ , err := os .Stat (tibulaCommand ); err != nil {
75
+ fmt .Println ("Cannot find tibula on the current folder, please copy it here and try again." )
76
+ exit ()
67
77
}
68
78
69
79
sys .Configure ()
70
- if _ , err := os .Stat ("tibula.json" ); err == nil {
80
+ if _ , err := os .Stat (tibulaJson ); err == nil {
71
81
start := prompt ("A configuration file already exists. Do you want to start Tibula instead? (Y/n)" )
72
82
if strings .ToLower (start ) != "n" {
73
- if err := sys .ConfigRead ("tibula.json" ); err != nil {
83
+ if err := sys .ConfigRead (tibulaJson ); err != nil {
74
84
fmt .Println (err )
75
85
exit ()
76
86
}
@@ -79,7 +89,7 @@ func main() {
79
89
} else {
80
90
openBrowser (fmt .Sprintf ("http://%s:%d" , sys .Options .WebHost , sys .Options .WebPort ))
81
91
}
82
- runCommand (tibulaCommand , "--config" , "tibula.json" , "--start" )
92
+ runCommand (tibulaCommand , "--config" , tibulaJson , "--start" )
83
93
exit ()
84
94
}
85
95
}
@@ -132,8 +142,10 @@ func main() {
132
142
}
133
143
} else {
134
144
sys .Options .DbPort = 0
135
- dbName := prompt ("Database file name (tibula.db)" )
136
- if dbName != "" {
145
+ dbName := prompt (fmt .Sprintf ("Database file name (%s)" , tibulaDb ))
146
+ if dbName == "" {
147
+ sys .Options .DbName = tibulaDb
148
+ } else {
137
149
sys .Options .DbName = dbName
138
150
}
139
151
}
@@ -146,9 +158,9 @@ func main() {
146
158
if logLevel != "" {
147
159
sys .Options .LogLevel , _ = strconv .Atoi (logLevel )
148
160
}
149
- jsonFile := prompt ("Config file (tibula.json)" )
161
+ jsonFile := prompt (fmt . Sprintf ( "Config file (%s)" , tibulaJson ) )
150
162
if jsonFile == "" {
151
- jsonFile = "tibula.json"
163
+ jsonFile = tibulaJson
152
164
}
153
165
154
166
//setup
0 commit comments