Skip to content

Commit

Permalink
Accidentally appended the formatted code not replaced
Browse files Browse the repository at this point in the history
  • Loading branch information
UnaTried committed Feb 2, 2025
1 parent fefb851 commit 1730ebe
Showing 1 changed file with 0 additions and 172 deletions.
172 changes: 0 additions & 172 deletions src/utils/path-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) }()
Expand Down

0 comments on commit 1730ebe

Please sign in to comment.