MCPcopy
hub / github.com/spicetify/cli / InitPaths

Function InitPaths

src/cmd/cmd.go:56–120  ·  view source on GitHub ↗

InitPaths checks various essential paths' availabilities, tries to auto-detect them and stops spicetify when any one of them is invalid.

()

Source from the content-addressed store, hash-verified

54// tries to auto-detect them and stops spicetify when any one
55// of them is invalid.
56func InitPaths() {
57 spotifyPath = settingSection.Key("spotify_path").String()
58 prefsPath = settingSection.Key("prefs_path").String()
59
60 spotifyPath = utils.ReplaceEnvVarsInString(spotifyPath)
61 prefsPath = utils.ReplaceEnvVarsInString(prefsPath)
62 testPath := filepath.Join(spotifyPath, "Apps")
63
64 if _, err := os.Stat(testPath); err != nil {
65 actualSpotifyPath := utils.FindAppPath()
66
67 if len(actualSpotifyPath) == 0 {
68 if len(spotifyPath) != 0 {
69 utils.PrintError(spotifyPath + ` is not a valid path. Please manually set "spotify_path" in config-xpui.ini to correct directory of Spotify.`)
70 os.Exit(1)
71 }
72 utils.PrintError(`Cannot detect Spotify location. Please manually set "spotify_path" in config-xpui.ini`)
73 if runtime.GOOS == "windows" {
74 utils.PrintInfo("Please make sure Spotify is not installed via Microsoft Store. If it is, please uninstall it and install Spotify with their web installer.")
75 }
76 os.Exit(1)
77 }
78
79 spotifyPath = actualSpotifyPath
80 settingSection.Key("spotify_path").SetValue(spotifyPath)
81 if err := cfg.Write(); err != nil {
82 utils.PrintWarning(fmt.Sprintf("Failed to save config: %s", err.Error()))
83 }
84 }
85
86 if _, err := os.Stat(prefsPath); err != nil {
87 actualPrefsPath := utils.FindPrefFilePath()
88
89 if len(actualPrefsPath) == 0 {
90 if len(prefsPath) != 0 {
91 utils.PrintError(prefsPath + ` does not exist or is not a valid path. Please manually set "prefs_path" in config-xpui.ini to correct path of "prefs" file.`)
92 os.Exit(1)
93 }
94 utils.PrintError(`Cannot detect Spotify "prefs" file location. Please manually set "prefs_path" in config-xpui.ini`)
95 os.Exit(1)
96 }
97
98 prefsPath = actualPrefsPath
99 settingSection.Key("prefs_path").SetValue(prefsPath)
100 if err := cfg.Write(); err != nil {
101 utils.PrintWarning(fmt.Sprintf("Failed to save config: %s", err.Error()))
102 }
103 }
104
105 if runtime.GOOS == "windows" {
106 if strings.Contains(spotifyPath, "SpotifyAB.SpotifyMusic") || strings.Contains(prefsPath, "SpotifyAB.SpotifyMusic") {
107 isAppX = true
108 }
109 }
110
111 appPath = filepath.Join(spotifyPath, "Apps")
112
113 if isAppX {

Callers 1

mainFunction · 0.92

Calls 8

ReplaceEnvVarsInStringFunction · 0.92
FindAppPathFunction · 0.92
PrintErrorFunction · 0.92
PrintInfoFunction · 0.92
PrintWarningFunction · 0.92
FindPrefFilePathFunction · 0.92
CheckExistAndCreateFunction · 0.92
WriteMethod · 0.65

Tested by

no test coverage detected