Skip to content

Commit

Permalink
dev: add coppy logic if a default file is found
Browse files Browse the repository at this point in the history
  • Loading branch information
QuintenQVD0 committed Feb 7, 2024
1 parent 02d9dd6 commit 1cfc2e1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*.dll
*.so
*.dylib

*.ini
# Test binary, built with `go test -c`
*.test

Expand All @@ -19,4 +19,4 @@

# Go workspace file
go.work
Pal/
Pal/
33 changes: 29 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,31 @@ func main() {

// Get the absolute path to the INI file
iniFilePath, err := filepath.Abs(fmt.Sprintf("Pal/Saved/Config/%s/PalWorldSettings.ini", osFolder))
if err != nil {
if err != nil {
fmt.Printf("Error getting absolute path: %v\n", err)
return
}

// Check if the INI file exists
// Check if PalWorldSettings.ini exists
if _, err := os.Stat(iniFilePath); os.IsNotExist(err) {
fmt.Printf("Error: INI file not found. Exiting. %v\n", err)
return
// PalWorldSettings.ini does not exist
// Check if DefaultPalWorldSettings.ini exists in the current directory
defaultIniPath := "DefaultPalWorldSettings.ini"
if _, err := os.Stat(defaultIniPath); !os.IsNotExist(err) {
// DefaultPalWorldSettings.ini exists, so move it to the desired location
newIniPath := fmt.Sprintf("Pal/Saved/Config/%s/PalWorldSettings.ini", osFolder)
err := copyFile(defaultIniPath, iniFilePath)
if err != nil {
fmt.Printf("Error copying file: %v\n", err)
return
}
fmt.Println("DefaultPalWorldSettings.ini copied to:", newIniPath)
} else {
fmt.Println("PalWorldSettings.ini not found and DefaultPalWorldSettings.ini does not exist in the current directory.")
return // No need to continue if PalWorldSettings.ini doesn't exist and DefaultPalWorldSettings.ini isn't found
}
} else {
fmt.Println("PalWorldSettings.ini found at:", iniFilePath)
}

// Read the contents of the original INI file
Expand Down Expand Up @@ -178,3 +194,12 @@ func setINIValue(content *[]byte, key, value string, addQuotes bool) {
*content = append((*content)[:start], append([]byte(value), (*content)[end:]...)...)
}


// copyFile copies a file from src to dst
func copyFile(src, dst string) error {
data, err := ioutil.ReadFile(src)
if err != nil {
return err
}
return ioutil.WriteFile(dst, data, 0644)
}

0 comments on commit 1cfc2e1

Please sign in to comment.