Beispiel #1
0
        static void Main()
        {
            if (!File.Exists("settings.json"))
            {
                throw new Exception("settings.json file doesn't exist.");
            }

            settings = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText("settings.json"));

            if (string.IsNullOrWhiteSpace(settings["steamUsername"]) || string.IsNullOrWhiteSpace(settings["steamPassword"]))
            {
                throw new Exception("Please provide your Steam username and password in settings.json.");
            }

            var options = new ChromeOptions();
            options.AddArgument(string.Format("--user-data-dir={0}", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "userdata")));
            options.AddArgument("--enable-file-cookies");
            options.AddArgument("--disable-cache");

            driver = new ChromeDriver(options);

            directoryImgs = Path.Combine(directory, "images");

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            else
            {
                Array.ForEach(Directory.GetFiles(directory, "*.html", SearchOption.TopDirectoryOnly), File.Delete);
                Array.ForEach(Directory.GetFiles(directoryImgs, "*.png", SearchOption.TopDirectoryOnly), File.Delete);
                Array.ForEach(Directory.GetFiles(directoryImgs, "*.jpg", SearchOption.TopDirectoryOnly), File.Delete);
                Array.ForEach(Directory.GetFiles(directoryImgs, "*.gif", SearchOption.TopDirectoryOnly), File.Delete);
            }

            driver.Navigate().GoToUrl("https://partner.steamgames.com/");

            if (driver.ElementIsPresent(By.ClassName("avatar")))
            {
                signedIn = true;
            }
            else
            {
                Login();
            }

            if (signedIn)
            {
                if (settings.Keys.Contains("predefinedDocs"))
                {
                    foreach (string predefined in settings["predefinedDocs"].Split(','))
                    {
                        var key = "https://partner.steamgames.com/documentation/" + predefined;

                        if (string.IsNullOrWhiteSpace(predefined) || documentationLinks.ContainsKey(key))
                        {
                            Console.WriteLine("Invalid or duplicate predefined doc: {0}", predefined);
                            continue;
                        }

                        cleanDocumentationLinks.Add(predefined);
                        documentationLinks.Add(key, false);
                    }
                }

                driver.Navigate().GoToUrl("https://partner.steamgames.com/home/steamworks");

                GetDocumentationLinks();

                AddFromSearchResults();

                FetchLinks();
            }

            driver.Quit();

            settings["predefinedDocs"] = string.Join(",", cleanDocumentationLinks);

            File.WriteAllText("settings.json", JsonConvert.SerializeObject(settings, Formatting.Indented));

            Console.WriteLine("Done.");
            Console.ReadLine();
        }