Stormfetch can now use ascii art from both the global and user ascii directory simultaneously

This commit is contained in:
CapCreeperGR 2024-05-05 22:14:59 +03:00
parent 0dcb6320af
commit d97ff3d9b6

31
main.go
View File

@ -10,7 +10,6 @@ import (
"strings"
)
var asciiPath string = ""
var configPath string = ""
var config StormfetchConfig = StormfetchConfig{}
@ -41,14 +40,6 @@ func readConfig() {
} else {
log.Fatalf("Config file not found: %s", err.Error())
}
// Find valid ascii directory
if stat, err := os.Stat(path.Join(homedir, "stormfetch/ascii/")); err == nil && stat.IsDir() {
asciiPath = path.Join(homedir, "stormfetch/ascii/")
} else if stat, err := os.Stat("/etc/stormfetch/ascii/"); err == nil && stat.IsDir() {
asciiPath = "/etc/stormfetch/ascii/"
} else {
log.Fatal("Ascii directory not found")
}
// Parse config
bytes, err := os.ReadFile(configPath)
if err != nil {
@ -189,8 +180,26 @@ func getDistroAscii() string {
} else {
id = config.Ascii
}
if _, err := os.Stat(path.Join(asciiPath, id)); err == nil {
bytes, err := os.ReadFile(path.Join(asciiPath, id))
userConfDir, err := os.UserConfigDir()
if err != nil {
if _, err := os.Stat(path.Join("/etc/stormfetch/ascii/", id)); err == nil {
bytes, err := os.ReadFile(path.Join("/etc/stormfetch/ascii/", id))
if err != nil {
return defaultAscii
}
return string(bytes)
} else {
return defaultAscii
}
}
if _, err := os.Stat(path.Join(userConfDir, "stormfetch/ascii/", id)); err == nil {
bytes, err := os.ReadFile(path.Join(userConfDir, "stormfetch/ascii/", id))
if err != nil {
return defaultAscii
}
return string(bytes)
} else if _, err := os.Stat(path.Join("/etc/stormfetch/ascii/", id)); err == nil {
bytes, err := os.ReadFile(path.Join("/etc/stormfetch/ascii/", id))
if err != nil {
return defaultAscii
}