From c688c30ab8bfdf32988df22509638dd2bd74f4ac Mon Sep 17 00:00:00 2001 From: UnaTried <103455203+UnaTried@users.noreply.github.com> Date: Sun, 26 Jan 2025 19:10:21 +0100 Subject: [PATCH 1/8] Update path-utils.go --- src/utils/path-utils.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/utils/path-utils.go b/src/utils/path-utils.go index 2105396367..51c2827bc9 100644 --- a/src/utils/path-utils.go +++ b/src/utils/path-utils.go @@ -65,6 +65,23 @@ func GetSpicetifyFolder() string { return result } +func GetStateFolder() string { + if runtime.GOOS == "linux" { + result, isAvailable := os.LookupEnv("SPICETIFY_CONFIG") + defer func() { CheckExistAndCreate(result) }() + + parent, isAvailable := os.LookupEnv("XDG_STATE_HOME") + + if !isAvailable || len(parent) == 0 { + parent = filepath.Join(os.Getenv("HOME"), ".local", "state") + CheckExistAndCreate(parent) + } + + result = filepath.Join(parent, "spicetify") + } + return result +} + // getUserFolder checks if folder `name` is available in spicetifyFolder, // else creates then returns the path. func GetUserFolder(name string) string { From 4cf4806035586446614362c115c6c763f2718af4 Mon Sep 17 00:00:00 2001 From: UnaTried <103455203+UnaTried@users.noreply.github.com> Date: Sun, 26 Jan 2025 19:13:38 +0100 Subject: [PATCH 2/8] Update cmd.go --- src/cmd/cmd.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/cmd.go b/src/cmd/cmd.go index 377d6a858d..4f5e95febb 100644 --- a/src/cmd/cmd.go +++ b/src/cmd/cmd.go @@ -15,7 +15,7 @@ import ( var ( spicetifyFolder = utils.GetSpicetifyFolder() rawFolder, themedFolder = getExtractFolder() - backupFolder = utils.GetUserFolder("Backup") + backupFolder = utils.GetStateFolder("Backup") userThemesFolder = utils.GetUserFolder("Themes") quiet bool isAppX = false @@ -205,7 +205,7 @@ func GetSpotifyPath() string { } func getExtractFolder() (string, string) { - dir := utils.GetUserFolder("Extracted") + dir := utils.GetStateFolder("Extracted") raw := filepath.Join(dir, "Raw") utils.CheckExistAndCreate(raw) From d8cc635496bfed7a69a9c102b654e8bfbdfdf7a5 Mon Sep 17 00:00:00 2001 From: UnaTried <103455203+UnaTried@users.noreply.github.com> Date: Sun, 26 Jan 2025 20:33:12 +0100 Subject: [PATCH 3/8] It should work, I don't know how to test it --- src/utils/path-utils.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/utils/path-utils.go b/src/utils/path-utils.go index 51c2827bc9..4980e76b6d 100644 --- a/src/utils/path-utils.go +++ b/src/utils/path-utils.go @@ -65,11 +65,19 @@ func GetSpicetifyFolder() string { return result } -func GetStateFolder() string { - if runtime.GOOS == "linux" { - result, isAvailable := os.LookupEnv("SPICETIFY_CONFIG") - defer func() { CheckExistAndCreate(result) }() +func GetStateFolder(name string) string { + result, isAvailable := os.LookupEnv("SPICETIFY_STATE") + defer func() { CheckExistAndCreate(result) }() + if isAvailable && len(result) > 0 { + return result + } + + if runtime.GOOS == "windows" { + parent := os.Getenv("APPDATA") + + result = filepath.Join(parent, "spicetify") + } else if runtime.GOOS == "linux" { parent, isAvailable := os.LookupEnv("XDG_STATE_HOME") if !isAvailable || len(parent) == 0 { @@ -77,6 +85,11 @@ func GetStateFolder() string { CheckExistAndCreate(parent) } + result = filepath.Join(parent, "spicetify") + } else if runtime.GOOS == "darwin" { + parent := filepath.Join(os.Getenv("HOME"), ".local", "state") + CheckExistAndCreate(parent) + result = filepath.Join(parent, "spicetify") } return result From d542d4e9115f5154f41ed39cae9b89049759e229 Mon Sep 17 00:00:00 2001 From: UnaTried <103455203+UnaTried@users.noreply.github.com> Date: Sun, 26 Jan 2025 20:33:54 +0100 Subject: [PATCH 4/8] This should work, I don't know how to test it From d12ff998073c556b835af227a8970584029ea7f1 Mon Sep 17 00:00:00 2001 From: UnaTried <103455203+UnaTried@users.noreply.github.com> Date: Sun, 26 Jan 2025 20:51:54 +0100 Subject: [PATCH 5/8] Update path-utils.go --- src/utils/path-utils.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/utils/path-utils.go b/src/utils/path-utils.go index 4980e76b6d..48f4e997c4 100644 --- a/src/utils/path-utils.go +++ b/src/utils/path-utils.go @@ -68,16 +68,12 @@ func GetSpicetifyFolder() string { func GetStateFolder(name string) string { result, isAvailable := os.LookupEnv("SPICETIFY_STATE") defer func() { CheckExistAndCreate(result) }() - + if isAvailable && len(result) > 0 { return result } - if runtime.GOOS == "windows" { - parent := os.Getenv("APPDATA") - - result = filepath.Join(parent, "spicetify") - } else if runtime.GOOS == "linux" { + if runtime.GOOS == "linux" { parent, isAvailable := os.LookupEnv("XDG_STATE_HOME") if !isAvailable || len(parent) == 0 { @@ -85,11 +81,6 @@ func GetStateFolder(name string) string { CheckExistAndCreate(parent) } - result = filepath.Join(parent, "spicetify") - } else if runtime.GOOS == "darwin" { - parent := filepath.Join(os.Getenv("HOME"), ".local", "state") - CheckExistAndCreate(parent) - result = filepath.Join(parent, "spicetify") } return result From ccc208a9aa09c9b8ce90753413527bbf236baa12 Mon Sep 17 00:00:00 2001 From: UnaTried <103455203+UnaTried@users.noreply.github.com> Date: Sun, 2 Feb 2025 00:58:47 +0000 Subject: [PATCH 6/8] Reverted commit --- src/utils/path-utils.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/utils/path-utils.go b/src/utils/path-utils.go index 48f4e997c4..4980e76b6d 100644 --- a/src/utils/path-utils.go +++ b/src/utils/path-utils.go @@ -68,12 +68,16 @@ func GetSpicetifyFolder() string { func GetStateFolder(name string) string { result, isAvailable := os.LookupEnv("SPICETIFY_STATE") defer func() { CheckExistAndCreate(result) }() - + if isAvailable && len(result) > 0 { return result } - if runtime.GOOS == "linux" { + if runtime.GOOS == "windows" { + parent := os.Getenv("APPDATA") + + result = filepath.Join(parent, "spicetify") + } else if runtime.GOOS == "linux" { parent, isAvailable := os.LookupEnv("XDG_STATE_HOME") if !isAvailable || len(parent) == 0 { @@ -81,6 +85,11 @@ func GetStateFolder(name string) string { CheckExistAndCreate(parent) } + result = filepath.Join(parent, "spicetify") + } else if runtime.GOOS == "darwin" { + parent := filepath.Join(os.Getenv("HOME"), ".local", "state") + CheckExistAndCreate(parent) + result = filepath.Join(parent, "spicetify") } return result From fefb85166ff0a66d59da66cb99a3b90297c860a5 Mon Sep 17 00:00:00 2001 From: UnaTried <103455203+UnaTried@users.noreply.github.com> Date: Sun, 2 Feb 2025 01:01:07 +0000 Subject: [PATCH 7/8] Fixed Formatting --- src/utils/path-utils.go | 172 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) diff --git a/src/utils/path-utils.go b/src/utils/path-utils.go index 4980e76b6d..449d53cf44 100644 --- a/src/utils/path-utils.go +++ b/src/utils/path-utils.go @@ -170,3 +170,175 @@ func GetExtensionPath(name string) (string, error) { return "", errors.New("extension not found") } +package utils + +import ( + "errors" + "os" + "path/filepath" + "runtime" + "strings" +) + +func MigrateConfigFolder() { + if runtime.GOOS == "windows" { + source := filepath.Join(os.Getenv("USERPROFILE"), ".spicetify") + if _, err := os.Stat(source); err == nil { + PrintBold("Migrating spicetify config folder") + destination := GetSpicetifyFolder() + err := Copy(source, destination, true, nil) + if err != nil { + Fatal(err) + } + os.RemoveAll(source) + PrintGreen("OK") + } + } +} + +func ReplaceEnvVarsInString(input string) string { + var replacements []string + for _, v := range os.Environ() { + pair := strings.SplitN(v, "=", 2) + replacements = append(replacements, "$"+pair[0], pair[1]) + } + replacer := strings.NewReplacer(replacements...) + return replacer.Replace(input) +} + +func GetSpicetifyFolder() string { + result, isAvailable := os.LookupEnv("SPICETIFY_CONFIG") + defer func() { CheckExistAndCreate(result) }() + + if isAvailable && len(result) > 0 { + return result + } + + if runtime.GOOS == "windows" { + parent := os.Getenv("APPDATA") + + result = filepath.Join(parent, "spicetify") + } else if runtime.GOOS == "linux" { + parent, isAvailable := os.LookupEnv("XDG_CONFIG_HOME") + + if !isAvailable || len(parent) == 0 { + parent = filepath.Join(os.Getenv("HOME"), ".config") + CheckExistAndCreate(parent) + } + + result = filepath.Join(parent, "spicetify") + } else if runtime.GOOS == "darwin" { + parent := filepath.Join(os.Getenv("HOME"), ".config") + CheckExistAndCreate(parent) + + result = filepath.Join(parent, "spicetify") + } + + return result +} + +func GetStateFolder(name string) string { + result, isAvailable := os.LookupEnv("SPICETIFY_STATE") + defer func() { CheckExistAndCreate(result) }() + + if isAvailable && len(result) > 0 { + return result + } + + if runtime.GOOS == "windows" { + parent := os.Getenv("APPDATA") + + result = filepath.Join(parent, "spicetify") + } else if runtime.GOOS == "linux" { + parent, isAvailable := os.LookupEnv("XDG_STATE_HOME") + + if !isAvailable || len(parent) == 0 { + parent = filepath.Join(os.Getenv("HOME"), ".local", "state") + CheckExistAndCreate(parent) + } + + result = filepath.Join(parent, "spicetify") + } else if runtime.GOOS == "darwin" { + parent := filepath.Join(os.Getenv("HOME"), ".local", "state") + CheckExistAndCreate(parent) + + result = filepath.Join(parent, "spicetify") + } + return result +} + +// getUserFolder checks if folder `name` is available in spicetifyFolder, +// else creates then returns the path. +func GetUserFolder(name string) string { + dir := filepath.Join(GetSpicetifyFolder(), name) + CheckExistAndCreate(dir) + + return dir +} + +var userAppsFolder = GetUserFolder("CustomApps") +var userExtensionsFolder = GetUserFolder("Extensions") + +func GetCustomAppSubfolderPath(folderPath string) string { + entries, err := os.ReadDir(folderPath) + if err != nil { + return "" + } + + for _, entry := range entries { + if entry.IsDir() { + subfolderPath := filepath.Join(folderPath, entry.Name()) + indexPath := filepath.Join(subfolderPath, "index.js") + + if _, err := os.Stat(indexPath); err == nil { + return subfolderPath + } + + if subfolderPath := GetCustomAppSubfolderPath(subfolderPath); subfolderPath != "" { + return subfolderPath + } + } + } + + return "" +} + +func GetCustomAppPath(name string) (string, error) { + customAppFolderPath := filepath.Join(userAppsFolder, name) + + if _, err := os.Stat(customAppFolderPath); err == nil { + customAppActualFolderPath := GetCustomAppSubfolderPath(customAppFolderPath) + if customAppActualFolderPath != "" { + return customAppActualFolderPath, nil + } + return customAppFolderPath, nil + } + + customAppFolderPath = filepath.Join(GetExecutableDir(), "CustomApps", name) + + if _, err := os.Stat(customAppFolderPath); err == nil { + customAppActualFolderPath := GetCustomAppSubfolderPath(customAppFolderPath) + if customAppActualFolderPath != "" { + return customAppActualFolderPath, nil + } + return customAppFolderPath, nil + } + + return "", errors.New("custom app not found") +} + +func GetExtensionPath(name string) (string, error) { + extFilePath := filepath.Join(userExtensionsFolder, name) + + if _, err := os.Stat(extFilePath); err == nil { + return extFilePath, nil + } + + extFilePath = filepath.Join(GetExecutableDir(), "Extensions", name) + + if _, err := os.Stat(extFilePath); err == nil { + return extFilePath, nil + } + + return "", errors.New("extension not found") +} From 1730ebe6c71fc8b8d576a7963a18b3c27d344caa Mon Sep 17 00:00:00 2001 From: UnaTried <103455203+UnaTried@users.noreply.github.com> Date: Sun, 2 Feb 2025 01:13:39 +0000 Subject: [PATCH 8/8] Accidentally appended the formatted code not replaced --- src/utils/path-utils.go | 172 ---------------------------------------- 1 file changed, 172 deletions(-) diff --git a/src/utils/path-utils.go b/src/utils/path-utils.go index 449d53cf44..f070d6c00e 100644 --- a/src/utils/path-utils.go +++ b/src/utils/path-utils.go @@ -65,178 +65,6 @@ func GetSpicetifyFolder() string { return result } -func GetStateFolder(name string) string { - result, isAvailable := os.LookupEnv("SPICETIFY_STATE") - defer func() { CheckExistAndCreate(result) }() - - if isAvailable && len(result) > 0 { - return result - } - - if runtime.GOOS == "windows" { - parent := os.Getenv("APPDATA") - - result = filepath.Join(parent, "spicetify") - } else if runtime.GOOS == "linux" { - parent, isAvailable := os.LookupEnv("XDG_STATE_HOME") - - if !isAvailable || len(parent) == 0 { - parent = filepath.Join(os.Getenv("HOME"), ".local", "state") - CheckExistAndCreate(parent) - } - - result = filepath.Join(parent, "spicetify") - } else if runtime.GOOS == "darwin" { - parent := filepath.Join(os.Getenv("HOME"), ".local", "state") - CheckExistAndCreate(parent) - - result = filepath.Join(parent, "spicetify") - } - return result -} - -// getUserFolder checks if folder `name` is available in spicetifyFolder, -// else creates then returns the path. -func GetUserFolder(name string) string { - dir := filepath.Join(GetSpicetifyFolder(), name) - CheckExistAndCreate(dir) - - return dir -} - -var userAppsFolder = GetUserFolder("CustomApps") -var userExtensionsFolder = GetUserFolder("Extensions") - -func GetCustomAppSubfolderPath(folderPath string) string { - entries, err := os.ReadDir(folderPath) - if err != nil { - return "" - } - - for _, entry := range entries { - if entry.IsDir() { - subfolderPath := filepath.Join(folderPath, entry.Name()) - indexPath := filepath.Join(subfolderPath, "index.js") - - if _, err := os.Stat(indexPath); err == nil { - return subfolderPath - } - - if subfolderPath := GetCustomAppSubfolderPath(subfolderPath); subfolderPath != "" { - return subfolderPath - } - } - } - - return "" -} - -func GetCustomAppPath(name string) (string, error) { - customAppFolderPath := filepath.Join(userAppsFolder, name) - - if _, err := os.Stat(customAppFolderPath); err == nil { - customAppActualFolderPath := GetCustomAppSubfolderPath(customAppFolderPath) - if customAppActualFolderPath != "" { - return customAppActualFolderPath, nil - } - return customAppFolderPath, nil - } - - customAppFolderPath = filepath.Join(GetExecutableDir(), "CustomApps", name) - - if _, err := os.Stat(customAppFolderPath); err == nil { - customAppActualFolderPath := GetCustomAppSubfolderPath(customAppFolderPath) - if customAppActualFolderPath != "" { - return customAppActualFolderPath, nil - } - return customAppFolderPath, nil - } - - return "", errors.New("custom app not found") -} - -func GetExtensionPath(name string) (string, error) { - extFilePath := filepath.Join(userExtensionsFolder, name) - - if _, err := os.Stat(extFilePath); err == nil { - return extFilePath, nil - } - - extFilePath = filepath.Join(GetExecutableDir(), "Extensions", name) - - if _, err := os.Stat(extFilePath); err == nil { - return extFilePath, nil - } - - return "", errors.New("extension not found") -} -package utils - -import ( - "errors" - "os" - "path/filepath" - "runtime" - "strings" -) - -func MigrateConfigFolder() { - if runtime.GOOS == "windows" { - source := filepath.Join(os.Getenv("USERPROFILE"), ".spicetify") - if _, err := os.Stat(source); err == nil { - PrintBold("Migrating spicetify config folder") - destination := GetSpicetifyFolder() - err := Copy(source, destination, true, nil) - if err != nil { - Fatal(err) - } - os.RemoveAll(source) - PrintGreen("OK") - } - } -} - -func ReplaceEnvVarsInString(input string) string { - var replacements []string - for _, v := range os.Environ() { - pair := strings.SplitN(v, "=", 2) - replacements = append(replacements, "$"+pair[0], pair[1]) - } - replacer := strings.NewReplacer(replacements...) - return replacer.Replace(input) -} - -func GetSpicetifyFolder() string { - result, isAvailable := os.LookupEnv("SPICETIFY_CONFIG") - defer func() { CheckExistAndCreate(result) }() - - if isAvailable && len(result) > 0 { - return result - } - - if runtime.GOOS == "windows" { - parent := os.Getenv("APPDATA") - - result = filepath.Join(parent, "spicetify") - } else if runtime.GOOS == "linux" { - parent, isAvailable := os.LookupEnv("XDG_CONFIG_HOME") - - if !isAvailable || len(parent) == 0 { - parent = filepath.Join(os.Getenv("HOME"), ".config") - CheckExistAndCreate(parent) - } - - result = filepath.Join(parent, "spicetify") - } else if runtime.GOOS == "darwin" { - parent := filepath.Join(os.Getenv("HOME"), ".config") - CheckExistAndCreate(parent) - - result = filepath.Join(parent, "spicetify") - } - - return result -} - func GetStateFolder(name string) string { result, isAvailable := os.LookupEnv("SPICETIFY_STATE") defer func() { CheckExistAndCreate(result) }()