From d97ff3d9b6ac4e551b956d69f697a0f49fd7b889 Mon Sep 17 00:00:00 2001 From: CapCreeperGR Date: Sun, 5 May 2024 22:14:59 +0300 Subject: [PATCH] Stormfetch can now use ascii art from both the global and user ascii directory simultaneously --- main.go | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index ae16720..15d48b6 100644 --- a/main.go +++ b/main.go @@ -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 }