Пример #1
0
        private static string CheckAppManifest(string steamapps, Game game)
        {
            if (game.SteamID == 0)
            {
                return(null);
            }
            string appManifest = Path.Combine(steamapps,
                                              string.Format(AppManifest, game.SteamID));
            var collection = ParseValveFile(appManifest);

            if (collection == null)
            {
                return(null);
            }
            if (!collection.TryGetValue("AppState/installdir", out string installDir))
            {
                return(null);
            }
            installDir = Path.Combine(steamapps, "common", installDir);
            if (!PathHelper.IsValidDirectory(installDir))
            {
                return(null);
            }
            if (!Directory.Exists(installDir))
            {
                return(null);
            }
            return(installDir);
        }
Пример #2
0
        public static string[] LocateSteamFolders()
        {
            List <string> steamPaths = new List <string>();

            try {
                string primary = (string)Registry.GetValue(SteamKey, "SteamPath", null);
                if (primary != null && PathHelper.IsValidDirectory(primary))
                {
                    primary = Path.Combine(primary, SteamApps).Replace('/', '\\');
                    steamPaths.Add(
                        PathHelper.GetProperDirectoryCapitalization(primary));
                    string libraryFolders = Path.Combine(primary, SteamLibraryFolders);

                    /*if (File.Exists(libraryFolders)) {
                     *      try {
                     *              string text;
                     *              using (Stream stream = File.OpenRead(libraryFolders)) {
                     *                      StreamReader reader = new StreamReader(stream);
                     *                      text = reader.ReadToEnd();
                     *              }
                     *              ReadLibraryFolders(steamPaths, text);
                     *      }
                     *      catch (Exception) { }
                     * }*/
                    var collection = ParseValveFile(libraryFolders);
                    if (collection != null)
                    {
                        int index = 1;
                        while (collection.TryGetValue(
                                   $"LibraryFolders/{index}", out string path))
                        {
                            if (PathHelper.IsValidDirectory(path) &&
                                Directory.Exists(path))
                            {
                                steamPaths.Add(
                                    PathHelper.GetProperDirectoryCapitalization(path));
                            }
                            index++;
                        }
                    }
                }
            }
            catch (Exception) { }
            return(steamPaths.ToArray());
        }
Пример #3
0
        private static void ReadLibraryFolders(List <string> steamPaths, string text)
        {
            int    level     = 0;
            string path      = "";
            string lastToken = "";
            bool   isName    = false;
            bool   isValue   = false;
            bool   building  = false;
            string token     = "";
            bool   escape    = false;

            for (int i = 0; i < text.Length; i++)
            {
                char c = text[i];
                if (!building)
                {
                    if (char.IsWhiteSpace(c))
                    {
                        continue;
                    }
                    else if (c == '{')
                    {
                        if (isName)                           // Was the last token a name?
                        {
                            level++;
                            path   += $"/{lastToken}";
                            isName  = false;
                            isValue = false;
                        }
                        else
                        {
                            // Error
                            return;
                        }
                    }
                    else if (c == '}')
                    {
                        if (level > 0 && !isName)                           // Are we high enough and not defining something?
                        {
                            level--;
                            path    = path.Substring(0, path.LastIndexOf('/'));
                            isName  = false;
                            isValue = false;
                        }
                        else
                        {
                            // Error
                            return;
                        }
                    }
                    else if (c == '"')
                    {
                        if (isName)
                        {
                            isName  = false;
                            isValue = true;
                        }
                        else
                        {
                            isValue = false;
                            isName  = true;
                        }
                        building = true;
                    }
                    else
                    {
                        // Error: Unknown character
                        return;
                    }
                }
                else if (escape)
                {
                    token += c;
                    escape = false;
                }
                else if (c == '\\')
                {
                    escape = true;
                }
                else if (c == '"')
                {
                    if (isValue && path == "/LibraryFolders" &&
                        int.TryParse(lastToken, out _) &&
                        PathHelper.IsValidDirectory(token))
                    {
                        steamPaths.Add(Path.Combine(token, SteamApps));
                    }
                    lastToken = token;
                    token     = "";
                    building  = false;
                }
                else
                {
                    token += c;
                }
            }
            if (building || isName || level != 0)
            {
                // Error: Nothing we can do now
            }
        }