(version string, spotifyBasePath string, extractedAppsPath string, flags Flag)
| 81 | } |
| 82 | |
| 83 | func Start(version string, spotifyBasePath string, extractedAppsPath string, flags Flag) { |
| 84 | appPath := filepath.Join(extractedAppsPath, "xpui") |
| 85 | var cssTranslationMap = make(map[string]string) |
| 86 | |
| 87 | if version != "Dev" { |
| 88 | fetchSpinner, _ := utils.Spinner.Start("Fetching remote CSS map") |
| 89 | tag, err := FetchLatestTagMatchingOrMain(version) |
| 90 | if err != nil { |
| 91 | fetchSpinner.Warning("Failed to fetch remote CSS map") |
| 92 | utils.PrintWarning(err.Error()) |
| 93 | tag = version |
| 94 | } |
| 95 | if readRemoteCssMap(tag, &cssTranslationMap) != nil { |
| 96 | fetchSpinner.Warning("Failed to fetch remote CSS map") |
| 97 | utils.PrintInfo("Using local CSS map instead") |
| 98 | readLocalCssMap(&cssTranslationMap) |
| 99 | } else { |
| 100 | fetchSpinner.Success("Fetched remote CSS map") |
| 101 | } |
| 102 | } else { |
| 103 | utils.PrintInfo("Using local CSS map; in development environment") |
| 104 | readLocalCssMap(&cssTranslationMap) |
| 105 | } |
| 106 | |
| 107 | cssMapPairs := make([]string, 0, len(cssTranslationMap)*4) |
| 108 | for k, v := range cssTranslationMap { |
| 109 | cssMapPairs = append(cssMapPairs, k+":", `"`+v+`":`) |
| 110 | cssMapPairs = append(cssMapPairs, k, v) |
| 111 | } |
| 112 | cssMapJSReplacer := strings.NewReplacer(cssMapPairs...) |
| 113 | cssMapBareKeySpaceRe := regexp.MustCompile(`\b[a-zA-Z0-9_]{16,21}[ \t]+:`) |
| 114 | |
| 115 | verParts := strings.Split(flags.SpotifyVer, ".") |
| 116 | spotifyMajor, spotifyMinor, spotifyPatch := 0, 0, 0 |
| 117 | if len(verParts) > 0 { |
| 118 | spotifyMajor, _ = strconv.Atoi(verParts[0]) |
| 119 | } |
| 120 | if len(verParts) > 1 { |
| 121 | spotifyMinor, _ = strconv.Atoi(verParts[1]) |
| 122 | } |
| 123 | if len(verParts) > 2 { |
| 124 | spotifyPatch, _ = strconv.Atoi(verParts[2]) |
| 125 | } |
| 126 | |
| 127 | var spotifyBinaryPath string |
| 128 | switch runtime.GOOS { |
| 129 | case "windows": |
| 130 | dllPath := filepath.Join(spotifyBasePath, "spotify.dll") |
| 131 | exePath := filepath.Join(spotifyBasePath, "spotify.exe") |
| 132 | |
| 133 | if _, err := os.Stat(dllPath); err == nil { |
| 134 | spotifyBinaryPath = dllPath |
| 135 | } else if _, err := os.Stat(exePath); err == nil { |
| 136 | spotifyBinaryPath = exePath |
| 137 | } else { |
| 138 | utils.PrintError("Could not find spotify.dll or spotify.exe in Spotify installation directory") |
| 139 | utils.Fatal(errors.New("aborting the patching process due to missing Spotify binaries")) |
| 140 | } |
no test coverage detected