-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstalled.go
More file actions
107 lines (90 loc) · 2.56 KB
/
installed.go
File metadata and controls
107 lines (90 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
"fmt"
"os"
"path/filepath"
"regexp"
"runtime"
tea "github.com/charmbracelet/bubbletea"
)
// loadInstalledMods scans the mods directory for installed mods
func loadInstalledMods(modsPath string) tea.Cmd {
return func() tea.Msg {
var installed []InstalledMod
// Validate path
if modsPath == "" {
return installedModsLoadedMsg{mods: installed}
}
// Check if path exists
if _, err := os.Stat(modsPath); os.IsNotExist(err) {
return installedModsLoadedMsg{mods: installed}
}
// Read directory
entries, err := os.ReadDir(modsPath)
if err != nil {
return installedModsLoadedMsg{mods: installed}
}
// Process each entry
for _, entry := range entries {
if !entry.IsDir() {
continue
}
mod := parseModFolder(modsPath, entry.Name())
installed = append(installed, mod)
}
return installedModsLoadedMsg{mods: installed}
}
}
// parseModFolder creates an InstalledMod from a folder
func parseModFolder(basePath, folderName string) InstalledMod {
modPath := filepath.Join(basePath, folderName)
// Check if folder name is a Steam Workshop ID (all digits)
isWorkshopID := regexp.MustCompile(`^\d+$`).MatchString(folderName)
if isWorkshopID {
return InstalledMod{
ID: folderName,
Title: fmt.Sprintf("Workshop Mod #%s", folderName),
Path: modPath,
}
}
// Regular mod folder
return InstalledMod{
ID: "",
Title: folderName,
Path: modPath,
}
}
// getDefaultModsPath returns the default Kenshi mods path for the current platform
func getDefaultModsPath() string {
switch runtime := runtime.GOOS; runtime {
case "windows":
// Common Steam locations on Windows
paths := []string{
`C:\Program Files (x86)\Steam\steamapps\workshop\content\233860`,
`C:\Program Files\Steam\steamapps\workshop\content\233860`,
}
for _, path := range paths {
if _, err := os.Stat(path); err == nil {
return path
}
}
return `C:\Steam\steamapps\workshop\content\233860`
case "linux":
home := os.Getenv("HOME")
paths := []string{
filepath.Join(home, ".steam", "steam", "steamapps", "workshop", "content", "233860"),
filepath.Join(home, ".local", "share", "Steam", "steamapps", "workshop", "content", "233860"),
}
for _, path := range paths {
if _, err := os.Stat(path); err == nil {
return path
}
}
return filepath.Join(home, ".steam", "steam", "steamapps", "workshop", "content", "233860")
case "darwin":
home := os.Getenv("HOME")
return filepath.Join(home, "Library", "Application Support", "Steam", "steamapps", "workshop", "content", "233860")
default:
return ""
}
}