Skip to content

Commit

Permalink
Fix an issue where the home folder would sometimes be set to OneDrive…
Browse files Browse the repository at this point in the history
… on Windows
  • Loading branch information
jeandeaual committed Nov 11, 2020
1 parent b8f9123 commit 3faafae
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tts/chest.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"runtime"
"strings"

"github.com/jeandeaual/tts-deckconverter/log"
)
Expand All @@ -16,12 +17,14 @@ func FindChestPath() (string, error) {

home, err := os.UserHomeDir()
if err != nil {
return chestPath, err
return "", err
}

switch runtime.GOOS {
case "windows":
chestPath = filepath.Join(home, "/Documents/My Games/Tabletop Simulator/Saves/Saved Objects")
// On some Windows machines `os.UserHomeDir()` seems to return the OneDrive folder
home = strings.TrimSuffix(home, `\OneDrive`)
chestPath = filepath.Join(home, `\Documents\My Games\Tabletop Simulator\Saves\Saved Objects`)
case "darwin":
chestPath = filepath.Join(home, "/Library/Tabletop Simulator/Saves/Saved Objects")
default:
Expand All @@ -31,11 +34,11 @@ func FindChestPath() (string, error) {
log.Debugf("Chest path: \"%s\"", chestPath)

if stat, err := os.Stat(chestPath); os.IsNotExist(err) {
return chestPath, fmt.Errorf("chest path \"%s\" doesn't exist", chestPath)
return "", fmt.Errorf("chest path \"%s\" doesn't exist", chestPath)
} else if err != nil {
return chestPath, err
return "", err
} else if !stat.IsDir() {
return chestPath, fmt.Errorf("chest path \"%s\" is not a directory", chestPath)
return "", fmt.Errorf("chest path \"%s\" is not a directory", chestPath)
}

return chestPath, nil
Expand Down

0 comments on commit 3faafae

Please sign in to comment.