Nethack Launcher
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

59 lines
2.1 KiB

package main
import (
"fmt"
"os"
"os/exec"
)
func createInitialFiles() {
// create necessary directories if they dont exist
if _, err := os.Stat(config.NethackLauncher.HackDir); os.IsNotExist(err) {
os.Mkdir(config.NethackLauncher.HackDir, os.ModeDir)
}
// move in nhdat file if it does not exist
if _, err := os.Stat(fmt.Sprintf("%s/nhdat", config.NethackLauncher.HackDir)); os.IsNotExist(err) {
fmt.Printf("%s\n", err)
println("moving in initial nhdat file")
out, err := exec.Command("cp", config.NethackLauncher.NhdatLocation, fmt.Sprintf("%s/nhdat", config.NethackLauncher.HackDir)).Output()
if err != nil {
fmt.Printf("%s\n", err)
}
fmt.Printf("%s\n", out)
}
// move in sysconf file if it does not exist
if _, err := os.Stat(fmt.Sprintf("%s/sysconf", config.NethackLauncher.HackDir)); os.IsNotExist(err) {
exec.Command("cp", config.NethackLauncher.SysconfLocation, config.NethackLauncher.HackDir).Run()
}
// make sure record file exists
if _, err := os.Stat(fmt.Sprintf("%s/record", config.NethackLauncher.HackDir)); os.IsNotExist(err) {
os.OpenFile(fmt.Sprintf("%s/record", config.NethackLauncher.HackDir), os.O_RDONLY|os.O_CREATE, 0666)
}
// make sure initial rcfile exists
hackRCLoc := fmt.Sprintf("%s/.nethackrc", config.NethackLauncher.HackDir)
if _, err := os.Stat(hackRCLoc); os.IsNotExist(err) {
fmt.Printf("initial config file not found at: %s\n", hackRCLoc)
fmt.Printf("%s\n", err)
// check root and move in if applicable
if _, err := os.Stat("/.nethackrc"); os.IsNotExist(err) {
fmt.Printf("initial config file not found at root\n")
fmt.Printf("%s\n", err)
os.Exit(1)
} else {
// move nethackrc file to proper location
println("moving in initial config file")
exec.Command("cp", "/.nethackrc", config.NethackLauncher.HackDir).Run()
}
}
// make sure initial sotw scores file exists
if _, err := os.Stat(fmt.Sprintf("%s/scores.dat", config.NethackLauncher.HackDir)); os.IsNotExist(err) {
exec.Command("cp", fmt.Sprintf("%s/scores.dat", config.NethackLauncher.SotwRoot), config.NethackLauncher.HackDir).Run()
}
}