コード例 #1
0
        public static string GetSteamUsername(string steamApiKey, string steamId32Bit)
        {
            string steamId64Bit = SteamUtil.ConvertSteamId32BitTo64Bit(steamId32Bit);

            string apiUrl = string.Format("{0}/ISteamUser/GetPlayerSummaries/v0002/?key={1}&steamids={2}", steamBaseApiUrl, steamApiKey, steamId64Bit);

            try
            {
                WebClient webClient  = new WebClient();
                string    jsonString = webClient.DownloadString(apiUrl);

                dynamic dynamicJsonObject = JsonConvert.DeserializeObject(jsonString);

                return(dynamicJsonObject.response.players[0].personaname);
            }
            catch
            {
                return(null);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: MrGraversen/SteamShots.NET
        static void Main(string[] args)
        {
            Console.Title = "SteamShots.NET";

            PrintWelcome();
            if (!FileUtil.ApiKeyFileExists())
            {
                string apiKeyFileName = FileUtil.CreateApiKeyFile();

                PrintHiglightError("You must supply a valid Steam Web API key!");
                Console.WriteLine(string.Format("Please insert your API key in the {0} file", apiKeyFileName));
                WaitForInput();
                Environment.Exit(0);
            }

            FileUtil.CreateSteamShotsDirectory();

            string steamInstallPath = RegistryUtil.GetSteamInstallPath();

            if (steamInstallPath == null)
            {
                PrintHiglightError("Steam does not appear to be installed!");
                WaitForInput();
                Environment.Exit(0);
            }

            PrintHiglightInfo("Discovered Steam: ", steamInstallPath);

            IEnumerable <string> steamUserIds = SteamUtil.GetUserProfiles();

            if (steamUserIds == null || !steamUserIds.Any())
            {
                PrintHiglightError("No Steam screenshots discovered!");
                WaitForInput();
                Environment.Exit(0);
            }

            PrintHiglightInfo("Discovered users with IDs: ", "{ " + string.Join(", ", steamUserIds.ToArray <string>()) + " }");

            foreach (string steamUserId in steamUserIds)
            {
                string steamUsername = SteamApiUtil.GetSteamUsername(FileUtil.ReadApiKey(), steamUserId);

                if (steamUsername != null)
                {
                    PrintHiglightSuccess(string.Format("Resolved Steam user ID {0}: ", steamUserId), steamUsername);

                    IEnumerable <string> gameIds = SteamUtil.GetGamesWithScreenshots(steamUserId);

                    if (gameIds == null || !gameIds.Any())
                    {
                        PrintInlineHighlight("Discovered ", gameIds.Count().ToString(), " games");
                        PrintHiglightWarning("The following user has no game screenshots: ", steamUsername);
                    }
                    else
                    {
                        PrintHiglightInfo("Discovered games with SteamApp IDs: ", "{ " + string.Join(", ", gameIds.ToArray <string>()) + " }");

                        foreach (string gameId in gameIds)
                        {
                            string gameName = SteamApiUtil.GetSteamGameName(gameId);

                            if (gameName != null)
                            {
                                PrintHiglightSuccess(string.Format("Resolved game SteamApp ID {0}: ", gameId), gameName);
                                int screenshotCopyCount = FileUtil.CopyContentsToSteamShots(SteamUtil.GetGameScreenshotsFullPath(steamUserId, gameId), steamUsername, gameName);
                                PrintInlineHighlight("Copied ", screenshotCopyCount.ToString(), " screensots!");
                            }
                            else
                            {
                                PrintHiglightWarning("The following SteamApp ID couldn't resolve: ", gameId);
                            }
                        }

                        Console.WriteLine();
                    }
                }
                else
                {
                    PrintHiglightWarning("The following Steam ID couldn't resolve: ", steamUserId);
                }
            }

            PrintFinished();
            WaitForInput();
        }