Exemple #1
0
        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;
        }
Exemple #2
0
        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;
        }