public void Reset()
 {
     Key     = null;
     Value   = null;
     Comment = null;
     Parent  = null;
 }
 public KeyValuesData(string key, string value, string comment, KeyValues parent)
 {
     Tag     = null;
     Key     = key;
     Value   = value;
     Comment = comment;
     Parent  = parent;
 }
        public List <SteamGame> GetAllSteamGames()
        {
            var steamGames = new List <SteamGame>();

            if (!_steamLibraryFolders.Any())
            {
                return(steamGames);
            }

            foreach (
                var acfFile in
                GetLibraryFolders()
                .Select(libraryFolder => new DirectoryInfo(libraryFolder).GetFiles("appmanifest*.acf"))
                .SelectMany(acfFiles => acfFiles))
            {
                try
                {
                    var kv = new KeyValues.KeyValues("AppState");
                    kv.LoadFromFile(acfFile.FullName);

                    //Empty list of key name values, skip
                    if (!kv.KeyNameValues.Any())
                    {
                        continue;
                    }
                    var appId =
                        kv.KeyNameValues.Single(
                            k => k.Key.Equals("appid", StringComparison.InvariantCultureIgnoreCase)).Value;
                    var gameName = GetGameName(kv);
                    if (gameName == null)
                    {
                        continue;
                    }
                    steamGames.Add(new SteamGame(appId, gameName, acfFile.FullName));
                }
                catch (Exception ex)
                {
                    // get a better stack trace if we do have an exception including the contents of the failed file information
                    var fileContents = "UNKNOWN";
                    try
                    {
                        fileContents = File.ReadAllText(acfFile.FullName);
                    }
                    catch
                    {
                        // ignored
                    }
                    throw new Exception(
                              $@"An issue occured handling Steam acf file {acfFile.FullName} - Contents{"\r\n"}{
                            fileContents}"
                              , ex);
                }
            }
            return(steamGames);
        }
        private static string GetGameName(KeyValues.KeyValues kv)
        {
            while (true)
            {
                var kvp =
                    kv.KeyNameValues.FirstOrDefault(
                        k => k.Key.Equals("name", StringComparison.InvariantCultureIgnoreCase));
                if (kvp != null)
                {
                    return(kvp.Value);
                }

                var userConfigKv =
                    kv.KeyChilds.FirstOrDefault(
                        c => c.Name.Equals("UserConfig", StringComparison.InvariantCultureIgnoreCase));
                if (userConfigKv == null)
                {
                    return(null);
                }
                kv = userConfigKv;
            }
        }
        public List <string> GetLibraryFolders()
        {
            if (_steamLibraryFolders.Count > 0)
            {
                return(_steamLibraryFolders);
            }

            try
            {
                AddLibraryFolder(new FileInfo(GetLibraryFoldersVdf()).Directory?.Parent?.FullName + @"\");
            }
            catch
            {
                // ignored
            }

            var kv = new KeyValues.KeyValues("LibraryFolders");

            kv.LoadFromFile(GetLibraryFoldersVdf());
            foreach (
                var keyValuePair in
                kv.KeyNameValues.Where(keyValuePair => Regex.Match(keyValuePair.Key, @"\d+").Success))
            {
                try
                {
                    var libraryFolder = keyValuePair.Value.Replace(@"\\", @"\") + "\\";
                    AddLibraryFolder(libraryFolder);
                }
                catch (SteamLibraryPathNotFoundException)
                {
                    // ignored
                }
            }

            return(_steamLibraryFolders);
        }