Пример #1
0
        /// <summary>
        /// Reads the LibraryFolders.vdf file to get all steam lib folders (if user has multiple folder (like one on SSD, multiple on HDD))
        /// </summary>
        private IEnumerable <string> DiscoverLibFolders(string steamAppsFolder)
        {
            List <string> folders = new List <string>();

            folders.Add(steamAppsFolder);
            var libFolders = Path.Combine(steamAppsFolder, Settings.LibraryFolderFileName);

            using (StreamReader reader = new StreamReader(libFolders))
            {
                var serial = new VdfSerializer();

                dynamic file  = serial.Deserialize(reader);
                var     token = file.Value as VObject;
                for (int i = 1; i < 100; ++i)
                {
                    VProperty vprop;
                    if (token.TryGetValue(i.ToString(), out vprop) == false)
                    {
                        break;
                    }
                    var folder = vprop.Value.ToString().Replace("\\\\", "\\");
                    if (Directory.Exists(folder))
                    {
                        folders.Add(Path.Combine(folder, Settings.SteamAppsFolder)); // concats /steamapps/ to the library folders
                    }
                    else
                    {
                        // Debug.WriteLine($"Folder [{folder}] does not exist");
                    }
                }
            }

            return(folders);
        }
Пример #2
0
        /// <summary>
        /// ACF file parsing method, deserializes the file into an object, return the right properties
        /// </summary>
        /// <param name="reader">the acf file reader</param>
        /// <returns>
        /// name: the ACF AppState.name property
        /// installDir: the ACF AppState.installdir property
        /// </returns>
        private (string name, string installDir) ReadFile(StreamReader reader)
        {
            var serial = new VdfSerializer();
            var file   = serial.Deserialize(reader);

            var f = file.Value as VObject;

            (var found, var vprop) = f.GetValue(Settings.GameNameKeyName);
            if (!found)
            {
                throw new InvalidOperationException($"Could not find property {Settings.GameNameKeyName}");
            }

            var name = vprop.Value.ToString();

            (found, vprop) = f.GetValue(Settings.InstallDirKeyName);
            if (!found)
            {
                throw new InvalidOperationException($"Could not find property {Settings.InstallDirKeyName}");
            }

            var installDir = vprop.Value.ToString();

            return(name, installDir);
        }