示例#1
0
 public AppState(SteamLibrary lib, VDFFile vdf)
 {
     Library      = lib;
     AppId        = int.Parse(vdf["AppState"]["appid"].Value);
     Name         = vdf["AppState"]["name"].Value;
     SubDirectory = vdf["AppState"]["installdir"].Value;
 }
示例#2
0
        public SteamManager()
        {
            InstallPath = (string)Registry.GetValue(REG_PATH, REG_KEY, null);
            if (string.IsNullOrEmpty(InstallPath))
            {
                throw new Exception("Could not find Steam installation");
            }
            Logger.Log("Found steam installation");

            var dir = Path.Combine(InstallPath, "steamapps");

            if (!Directory.Exists(dir))
            {
                throw new Exception($"\"{dir}\" does not exist");
            }

            var dirs = new List <SteamLibrary>();

            dirs.Add(new SteamLibrary(0, InstallPath));

            var vdf = Path.Combine(dir, "libraryfolders.vdf");

            if (File.Exists(vdf))
            {
                var libs = new VDFFile(vdf);
                if (libs.RootElements.Count > 0 && libs.RootElements.Any(x => x.Name == "LibraryFolders"))
                {
                    foreach (var e in libs["LibraryFolders"].Children)
                    {
                        int id = 0;
                        if (int.TryParse(e.Name, out id))
                        {
                            dirs.Add(new SteamLibrary(id, e.Value.Replace(@"\\", @"\")));
                        }
                    }
                }
            }
            SteamLibraries = dirs.ToArray();
        }
示例#3
0
            // I know this is not how you read .vdf files. But it works for files that I need to read.
            public static VDFFile ReadVDF(string filePath)
            {
                var      file         = new VDFFile();
                string   buffer       = "";
                VDFArray mainArray    = null;
                VDFArray lastArray    = null;
                VDFArray currentArray = null;

                VDFElement element = null;

                using (var textReader = File.OpenText(filePath))
                {
                    while (textReader.Peek() != -1)
                    {
                        string line = textReader.ReadLine();
                        bool   startReadingString = false;
                        for (int i = 0; i < line.Length; ++i)
                        {
                            // Read String
                            if (startReadingString)
                            {
                                if (line[i] == '\"')
                                {
                                    startReadingString = false;
                                    if (element != null)
                                    {
                                        element.Value = buffer;
                                        buffer        = "";
                                        currentArray.Elements.Add(element.Name, element);
                                        element = null;
                                    }
                                    continue;
                                }
                                buffer += line[i];
                                continue;
                            }

                            switch (line[i])
                            {
                            case '\"':
                                if (buffer.Length != 0)
                                {
                                    if (element == null)
                                    {
                                        element      = new VDFElement();
                                        element.Name = buffer;
                                        buffer       = "";
                                    }
                                }
                                startReadingString = true;
                                break;

                            case '{':
                                if (mainArray == null)
                                {
                                    mainArray    = new VDFArray(buffer);
                                    currentArray = mainArray;
                                    buffer       = "";
                                    break;
                                }
                                var array = new VDFArray(buffer);
                                lastArray = currentArray;
                                currentArray.Elements.Add(array.Name, array);
                                currentArray = array;
                                buffer       = "";
                                break;

                            case '}':
                                currentArray = lastArray;
                                lastArray    = mainArray;
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
                file.Array = mainArray;
                return(file);
            }