示例#1
0
        public static string GetSteamIdFromConfig(string userName)
        {
            dynamic steamId = null;

            try
            {
                string steamPath = new IniFile(SAMSettings.FILE_NAME).Read(SAMSettings.STEAM_PATH, SAMSettings.SECTION_STEAM);

                // Attempt to find Steam Id from steam config.
                dynamic config   = VdfConvert.Deserialize(File.ReadAllText(steamPath + "config\\config.vdf"));
                dynamic accounts = config.Value.Software.Valve.Steam.Accounts;

                VObject accountsObj = accounts;
                VToken  value;

                accountsObj.TryGetValue(userName, out value);

                dynamic user   = value;
                VValue  userId = user.SteamID;
                steamId = userId.Value.ToString();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(Convert.ToString(steamId));
        }
 public static VToken GetValue(this VObject vdf, string key)
 {
     if (vdf.TryGetValue(key, out var value))
     {
         return(value.Value);
     }
     return(null);
 }
示例#3
0
        public static async Task <dynamic> GetUserInfoFromConfigAndWebApi(string userName)
        {
            dynamic userJson = null;
            dynamic steamId  = null;

            try
            {
                string steamPath = new IniFile("SAMSettings.ini").Read("Steam", "Settings");

                // Attempt to find Steam Id from steam config.
                dynamic config   = VdfConvert.Deserialize(File.ReadAllText(steamPath + "config\\config.vdf"));
                dynamic accounts = config.Value.Software.Valve.steam.Accounts;

                VObject accountsObj = accounts;
                VToken  value;

                accountsObj.TryGetValue(userName, out value);

                dynamic user   = value;
                VValue  userId = user.SteamID;
                steamId = userId.Value.ToString();
            }
            catch (Exception ex)
            {
                // Attempt to find Steam Id from web api.
                Uri vanityUri = new Uri("http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/?key=" + apiKey + "&vanityurl=" + userName);

                using (WebClient client = new WebClient())
                {
                    string vanityJson = await client.DownloadStringTaskAsync(vanityUri);

                    dynamic vanityValue = JValue.Parse(vanityJson);

                    steamId = vanityValue.response.steamid;
                }
            }

            if (steamId != null)
            {
                using (WebClient client = new WebClient())
                {
                    userJson = await GetUserInfoFromWebApiBySteamId(Convert.ToString(steamId));
                }
            }

            return(userJson);
        }
        /// <summary>
        ///  Finds the collection of Steam library folders
        /// </summary>
        /// <param name="steamPath">The located path to the Steam installation folder.</param>
        /// <returns>The collection of Steam library folders.</returns>
        ///
        /// <exception cref="ArgumentNullException">
        ///  <paramref name="steamPath"/> is null.
        /// </exception>
        /// <exception cref="SteamException">
        ///  An error occurred while reading the Steam folders.
        /// </exception>
        public static SteamLibraryFolders FindLibrariesFromSteamPath(string steamPath)
        {
            if (steamPath == null)
            {
                throw new ArgumentNullException(nameof(steamPath));
            }

            List <string> folders = new List <string>();

            steamPath = PrettifyDir(steamPath);
            string steamApps = Path.Combine(steamPath, SteamApps);

            if (!PathUtils.IsValidDirectory(steamPath) || !Directory.Exists(steamApps))
            {
                throw new SteamException($"Steam installation path does not have a \"{SteamApps}\" folder!");
            }
            folders.Add(steamPath);

            string libraryFolders         = Path.Combine(steamApps, LibraryFolders);
            string libraryFoldersRelative = Path.Combine(SteamApps, LibraryFolders);             // Relative for exceptions

            if (!File.Exists(libraryFolders))
            {
                throw new SteamException($"Steam installation path does not have a \"{libraryFoldersRelative}\" file!");
            }
            try {
                VProperty vlibsRoot = VdfConvert.Deserialize(File.ReadAllText(libraryFolders));
                VObject   vlibs     = vlibsRoot.Value as VObject;
                int       index     = 1;
                while (vlibs.TryGetValue((index++).ToString(), out VToken vlibToken))
                {
                    string folder = vlibToken.Value <string>();
                    if (PathUtils.IsValidDirectory(folder) && Directory.Exists(folder))
                    {
                        folders.Add(PrettifyDir(folder));
                    }
                }
            } catch (Exception ex) {
                throw new SteamException($"An error occurred while trying to load the " +
                                         $"\"{libraryFoldersRelative}\" file!", ex);
            }

            return(new SteamLibraryFolders(steamPath, folders));
        }
        /// <summary>
        ///  Attempts to locate the installed Steam game with the specified Id in any existing library folders.
        /// </summary>
        /// <param name="folders">The loaded library folders for Steam.</param>
        /// <param name="steamId">The Steam game app Id.</param>
        /// <returns>The path to the installed game if found, otherwise null.</returns>
        ///
        /// <exception cref="ArgumentNullException">
        ///  <paramref name="folders"/> is null.
        /// </exception>
        public static string LocateGame(SteamLibraryFolders folders, uint steamId)
        {
            if (folders == null)
            {
                throw new ArgumentNullException(nameof(folders));
            }

            if (steamId == 0)
            {
                return(null);
            }
            foreach (string folder in folders)
            {
                string appManifest = Path.Combine(folder, SteamApps, GetAppManifestFileName(steamId));
                // Is not present in this library folder
                if (!File.Exists(appManifest))
                {
                    continue;
                }

                VProperty vappRoot = VdfConvert.Deserialize(File.ReadAllText(appManifest));
                VObject   vapp     = vappRoot.Value as VObject;
                if (!vapp.TryGetValue(InstallDirVdfKey, out VToken vappToken))
                {
                    continue;
                }
                string installDir = vappToken.Value <string>();
                installDir = Path.Combine(folder, SteamApps, Common, installDir);
                if (!PathUtils.IsValidDirectory(installDir) || !Directory.Exists(installDir))
                {
                    continue;
                }

                return(PrettifyDir(installDir));
            }
            return(null);
        }