From 137a53ef89ea3f73a06a0dab2ebf9b1da495d34d Mon Sep 17 00:00:00 2001 From: JustArchi Date: Thu, 24 Nov 2016 07:46:37 +0100 Subject: [PATCH] Improve readability of some specific segments --- ArchiSteamFarm.sln.DotSettings | 2 +- ArchiSteamFarm/ASF.cs | 4 +- ArchiSteamFarm/ArchiHandler.cs | 12 +++- ArchiSteamFarm/ArchiServiceInstaller.cs | 5 +- ArchiSteamFarm/ArchiWebHandler.cs | 35 +++++++++-- ArchiSteamFarm/Bot.cs | 12 +++- ArchiSteamFarm/GlobalDatabase.cs | 7 ++- ArchiSteamFarm/Logging.cs | 17 +++++- ArchiSteamFarm/WebBrowser.cs | 9 ++- ConfigGenerator/DialogBox.cs | 77 ++++++++++++++++++++++--- GUI/Logging.cs | 20 ++++++- GUI/MainForm.cs | 5 +- 12 files changed, 173 insertions(+), 32 deletions(-) diff --git a/ArchiSteamFarm.sln.DotSettings b/ArchiSteamFarm.sln.DotSettings index 9a21d2744..bb4d3a62c 100644 --- a/ArchiSteamFarm.sln.DotSettings +++ b/ArchiSteamFarm.sln.DotSettings @@ -97,7 +97,7 @@ END_OF_LINE 1 1 - False + True END_OF_LINE False False diff --git a/ArchiSteamFarm/ASF.cs b/ArchiSteamFarm/ASF.cs index b2be71eaf..bf6f01f73 100644 --- a/ArchiSteamFarm/ASF.cs +++ b/ArchiSteamFarm/ASF.cs @@ -233,7 +233,9 @@ namespace ArchiSteamFarm { return; } - FileSystemWatcher = new FileSystemWatcher(SharedInfo.ConfigDirectory, "*.json") { NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite }; + FileSystemWatcher = new FileSystemWatcher(SharedInfo.ConfigDirectory, "*.json") { + NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite + }; FileSystemWatcher.Changed += OnChanged; FileSystemWatcher.Created += OnCreated; diff --git a/ArchiSteamFarm/ArchiHandler.cs b/ArchiSteamFarm/ArchiHandler.cs index fea520c72..0a61d3436 100644 --- a/ArchiSteamFarm/ArchiHandler.cs +++ b/ArchiSteamFarm/ArchiHandler.cs @@ -170,7 +170,9 @@ namespace ArchiSteamFarm { return null; } - ClientMsgProtobuf request = new ClientMsgProtobuf(EMsg.ClientRedeemGuestPass) { SourceJobID = Client.GetNextJobID() }; + ClientMsgProtobuf request = new ClientMsgProtobuf(EMsg.ClientRedeemGuestPass) { + SourceJobID = Client.GetNextJobID() + }; request.Body.guest_pass_id = guestPassID; @@ -194,7 +196,9 @@ namespace ArchiSteamFarm { return null; } - ClientMsgProtobuf request = new ClientMsgProtobuf(EMsg.ClientRegisterKey) { SourceJobID = Client.GetNextJobID() }; + ClientMsgProtobuf request = new ClientMsgProtobuf(EMsg.ClientRegisterKey) { + SourceJobID = Client.GetNextJobID() + }; request.Body.key = key; @@ -303,7 +307,9 @@ namespace ArchiSteamFarm { JobID = jobID; if (msg.count_new_items > 0) { - Notifications = new HashSet { ENotification.Items }; + Notifications = new HashSet { + ENotification.Items + }; } } diff --git a/ArchiSteamFarm/ArchiServiceInstaller.cs b/ArchiSteamFarm/ArchiServiceInstaller.cs index aacbc6497..93c98eb7e 100644 --- a/ArchiSteamFarm/ArchiServiceInstaller.cs +++ b/ArchiSteamFarm/ArchiServiceInstaller.cs @@ -48,7 +48,10 @@ namespace ArchiSteamFarm { serviceInstaller.Installers.Clear(); - EventLogInstaller logInstaller = new EventLogInstaller { Log = SharedInfo.EventLog, Source = SharedInfo.EventLogSource }; + EventLogInstaller logInstaller = new EventLogInstaller { + Log = SharedInfo.EventLog, + Source = SharedInfo.EventLogSource + }; Installers.Add(serviceInstaller); Installers.Add(serviceProcessInstaller); diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index 8f5897fce..1f4978d5b 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -86,7 +86,11 @@ namespace ArchiSteamFarm { string referer = SteamCommunityURL + "/tradeoffer/" + tradeID; string request = referer + "/accept"; - Dictionary data = new Dictionary(3) { { "sessionid", sessionID }, { "serverid", "1" }, { "tradeofferid", tradeID.ToString() } }; + Dictionary data = new Dictionary(3) { + { "sessionid", sessionID }, + { "serverid", "1" }, + { "tradeofferid", tradeID.ToString() } + }; await WebBrowser.UrlPostRetry(request, data, referer).ConfigureAwait(false); } @@ -108,7 +112,11 @@ namespace ArchiSteamFarm { } string request = SteamStoreURL + "/checkout/addfreelicense"; - Dictionary data = new Dictionary(3) { { "sessionid", sessionID }, { "subid", subID.ToString() }, { "action", "add_to_cart" } }; + Dictionary data = new Dictionary(3) { + { "sessionid", sessionID }, + { "subid", subID.ToString() }, + { "action", "add_to_cart" } + }; HtmlDocument htmlDocument = await WebBrowser.UrlPostToHtmlDocumentRetry(request, data).ConfigureAwait(false); return htmlDocument?.DocumentNode.SelectSingleNode("//div[@class='add_free_content_success_area']") != null; @@ -635,7 +643,15 @@ namespace ArchiSteamFarm { string request = SteamCommunityURL + "/mobileconf/multiajaxop"; - List> data = new List>(7 + confirmations.Count*2) { new KeyValuePair("op", accept ? "allow" : "cancel"), new KeyValuePair("p", deviceID), new KeyValuePair("a", SteamID.ToString()), new KeyValuePair("k", confirmationHash), new KeyValuePair("t", time.ToString()), new KeyValuePair("m", "android"), new KeyValuePair("tag", "conf") }; + List> data = new List>(7 + confirmations.Count*2) { + new KeyValuePair("op", accept ? "allow" : "cancel"), + new KeyValuePair("p", deviceID), + new KeyValuePair("a", SteamID.ToString()), + new KeyValuePair("k", confirmationHash), + new KeyValuePair("t", time.ToString()), + new KeyValuePair("m", "android"), + new KeyValuePair("tag", "conf") + }; foreach (MobileAuthenticator.Confirmation confirmation in confirmations) { data.Add(new KeyValuePair("cid[]", confirmation.ID.ToString())); @@ -750,7 +766,10 @@ namespace ArchiSteamFarm { } string request = SteamCommunityURL + "/gid/" + groupID; - Dictionary data = new Dictionary(2) { { "sessionID", sessionID }, { "action", "join" } }; + Dictionary data = new Dictionary(2) { + { "sessionID", sessionID }, + { "action", "join" } + }; return await WebBrowser.UrlPostRetry(request, data).ConfigureAwait(false); } @@ -777,7 +796,9 @@ namespace ArchiSteamFarm { } string request = SteamStoreURL + "/account/validatewalletcode"; - Dictionary data = new Dictionary(1) { { "wallet_code", key } }; + Dictionary data = new Dictionary(1) { + { "wallet_code", key } + }; Steam.RedeemWalletResponse response = await WebBrowser.UrlPostToJsonResultRetry(request, data).ConfigureAwait(false); return response?.PurchaseResult ?? ArchiHandler.PurchaseResponseCallback.EPurchaseResult.Timeout; @@ -966,7 +987,9 @@ namespace ArchiSteamFarm { Bot.ArchiLogger.LogGenericInfo("Unlocking parental account..."); string request = SteamCommunityURL + "/parental/ajaxunlock"; - Dictionary data = new Dictionary(1) { { "pin", parentalPin } }; + Dictionary data = new Dictionary(1) { + { "pin", parentalPin } + }; bool result = await WebBrowser.UrlPostRetry(request, data, SteamCommunityURL).ConfigureAwait(false); if (!result) { diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 876f1b36c..a9a1e50f9 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -906,7 +906,17 @@ namespace ArchiSteamFarm { loginKey = CryptoHelper.Decrypt(BotConfig.PasswordFormat, loginKey); } - SteamUser.LogOnDetails logOnDetails = new SteamUser.LogOnDetails { Username = BotConfig.SteamLogin, Password = password, AuthCode = AuthCode, CellID = Program.GlobalDatabase.CellID, LoginID = LoginID, LoginKey = loginKey, TwoFactorCode = TwoFactorCode, SentryFileHash = sentryFileHash, ShouldRememberPassword = true }; + SteamUser.LogOnDetails logOnDetails = new SteamUser.LogOnDetails { + Username = BotConfig.SteamLogin, + Password = password, + AuthCode = AuthCode, + CellID = Program.GlobalDatabase.CellID, + LoginID = LoginID, + LoginKey = loginKey, + TwoFactorCode = TwoFactorCode, + SentryFileHash = sentryFileHash, + ShouldRememberPassword = true + }; try { SteamUser.LogOn(logOnDetails); diff --git a/ArchiSteamFarm/GlobalDatabase.cs b/ArchiSteamFarm/GlobalDatabase.cs index 80fe654fd..6b5f65abe 100644 --- a/ArchiSteamFarm/GlobalDatabase.cs +++ b/ArchiSteamFarm/GlobalDatabase.cs @@ -30,7 +30,12 @@ using Newtonsoft.Json; namespace ArchiSteamFarm { internal sealed class GlobalDatabase : IDisposable { - private static readonly JsonSerializerSettings CustomSerializerSettings = new JsonSerializerSettings { Converters = new List(2) { new IPAddressConverter(), new IPEndPointConverter() } }; + private static readonly JsonSerializerSettings CustomSerializerSettings = new JsonSerializerSettings { + Converters = new List(2) { + new IPAddressConverter(), + new IPEndPointConverter() + } + }; [JsonProperty(Required = Required.DisallowNull)] internal readonly InMemoryServerListProvider ServerListProvider = new InMemoryServerListProvider(); diff --git a/ArchiSteamFarm/Logging.cs b/ArchiSteamFarm/Logging.cs index 4edf0742a..1cf35858a 100644 --- a/ArchiSteamFarm/Logging.cs +++ b/ArchiSteamFarm/Logging.cs @@ -47,18 +47,29 @@ namespace ArchiSteamFarm { LoggingConfiguration config = new LoggingConfiguration(); - ColoredConsoleTarget coloredConsoleTarget = new ColoredConsoleTarget("ColoredConsole") { DetectConsoleAvailable = false, Layout = GeneralLayout }; + ColoredConsoleTarget coloredConsoleTarget = new ColoredConsoleTarget("ColoredConsole") { + DetectConsoleAvailable = false, + Layout = GeneralLayout + }; config.AddTarget(coloredConsoleTarget); config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, coloredConsoleTarget)); if (Program.IsRunningAsService) { - EventLogTarget eventLogTarget = new EventLogTarget("EventLog") { Layout = EventLogLayout, Log = SharedInfo.EventLog, Source = SharedInfo.EventLogSource }; + EventLogTarget eventLogTarget = new EventLogTarget("EventLog") { + Layout = EventLogLayout, + Log = SharedInfo.EventLog, + Source = SharedInfo.EventLogSource + }; config.AddTarget(eventLogTarget); config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, eventLogTarget)); } else if (!Program.Mode.HasFlag(Program.EMode.Client) || Program.Mode.HasFlag(Program.EMode.Server)) { - FileTarget fileTarget = new FileTarget("File") { DeleteOldFileOnStartup = true, FileName = SharedInfo.LogFile, Layout = GeneralLayout }; + FileTarget fileTarget = new FileTarget("File") { + DeleteOldFileOnStartup = true, + FileName = SharedInfo.LogFile, + Layout = GeneralLayout + }; config.AddTarget(fileTarget); config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, fileTarget)); diff --git a/ArchiSteamFarm/WebBrowser.cs b/ArchiSteamFarm/WebBrowser.cs index eb627d216..9d949fb77 100644 --- a/ArchiSteamFarm/WebBrowser.cs +++ b/ArchiSteamFarm/WebBrowser.cs @@ -51,9 +51,14 @@ namespace ArchiSteamFarm { ArchiLogger = archiLogger; - HttpClientHandler httpClientHandler = new HttpClientHandler { AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip, CookieContainer = CookieContainer }; + HttpClientHandler httpClientHandler = new HttpClientHandler { + AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip, + CookieContainer = CookieContainer + }; - HttpClient = new HttpClient(httpClientHandler) { Timeout = TimeSpan.FromSeconds(Program.GlobalConfig.HttpTimeout) }; + HttpClient = new HttpClient(httpClientHandler) { + Timeout = TimeSpan.FromSeconds(Program.GlobalConfig.HttpTimeout) + }; // Most web services expect that UserAgent is set, so we declare it globally HttpClient.DefaultRequestHeaders.UserAgent.ParseAdd("ArchiSteamFarm/" + SharedInfo.Version); diff --git a/ConfigGenerator/DialogBox.cs b/ConfigGenerator/DialogBox.cs index 5e249d761..071f45712 100644 --- a/ConfigGenerator/DialogBox.cs +++ b/ConfigGenerator/DialogBox.cs @@ -36,11 +36,43 @@ namespace ConfigGenerator { return DialogResult.Abort; } - TextBox textBox = new TextBox { Anchor = AnchorStyles.Right, Bounds = new Rectangle(12, 36, 372, 20), Width = 1000 }; - Button buttonOk = new Button { Anchor = AnchorStyles.Bottom | AnchorStyles.Right, Bounds = new Rectangle(228, 72, 75, 23), DialogResult = DialogResult.OK, Text = Resources.OK }; - Button buttonCancel = new Button { Anchor = AnchorStyles.Bottom | AnchorStyles.Right, Bounds = new Rectangle(309, 72, 75, 23), DialogResult = DialogResult.Cancel, Text = Resources.Cancel }; - Label label = new Label { AutoSize = true, Bounds = new Rectangle(9, 20, 372, 13), Text = promptText }; - Form form = new Form { AcceptButton = buttonOk, CancelButton = buttonCancel, ClientSize = new Size(Math.Max(300, label.Right + 10), 107), Controls = { label, textBox, buttonOk, buttonCancel }, FormBorderStyle = FormBorderStyle.FixedDialog, MinimizeBox = false, MaximizeBox = false, StartPosition = FormStartPosition.CenterScreen, Text = title }; + TextBox textBox = new TextBox { + Anchor = AnchorStyles.Right, + Bounds = new Rectangle(12, 36, 372, 20), + Width = 1000 + }; + + Button buttonOk = new Button { + Anchor = AnchorStyles.Bottom | AnchorStyles.Right, + Bounds = new Rectangle(228, 72, 75, 23), + DialogResult = DialogResult.OK, + Text = Resources.OK + }; + + Button buttonCancel = new Button { + Anchor = AnchorStyles.Bottom | AnchorStyles.Right, + Bounds = new Rectangle(309, 72, 75, 23), + DialogResult = DialogResult.Cancel, + Text = Resources.Cancel + }; + + Label label = new Label { + AutoSize = true, + Bounds = new Rectangle(9, 20, 372, 13), + Text = promptText + }; + + Form form = new Form { + AcceptButton = buttonOk, + CancelButton = buttonCancel, + ClientSize = new Size(Math.Max(300, label.Right + 10), 107), + Controls = { label, textBox, buttonOk, buttonCancel }, + FormBorderStyle = FormBorderStyle.FixedDialog, + MinimizeBox = false, + MaximizeBox = false, + StartPosition = FormStartPosition.CenterScreen, + Text = title + }; DialogResult dialogResult = form.ShowDialog(); value = textBox.Text; @@ -53,10 +85,37 @@ namespace ConfigGenerator { return DialogResult.Abort; } - Button buttonYes = new Button { Anchor = AnchorStyles.Bottom | AnchorStyles.Right, Bounds = new Rectangle(228, 72, 75, 23), DialogResult = DialogResult.Yes, Text = Resources.Yes }; - Button buttonNo = new Button { Anchor = AnchorStyles.Bottom | AnchorStyles.Right, Bounds = new Rectangle(309, 72, 75, 23), DialogResult = DialogResult.No, Text = Resources.No }; - Label label = new Label { AutoSize = true, Bounds = new Rectangle(9, 20, 372, 13), Text = promptText }; - Form form = new Form { AcceptButton = buttonYes, CancelButton = buttonNo, ClientSize = new Size(Math.Max(300, label.Right + 10), 107), Controls = { label, buttonYes, buttonNo }, FormBorderStyle = FormBorderStyle.FixedDialog, MinimizeBox = false, MaximizeBox = false, StartPosition = FormStartPosition.CenterScreen, Text = title }; + Button buttonYes = new Button { + Anchor = AnchorStyles.Bottom | AnchorStyles.Right, + Bounds = new Rectangle(228, 72, 75, 23), + DialogResult = DialogResult.Yes, + Text = Resources.Yes + }; + + Button buttonNo = new Button { + Anchor = AnchorStyles.Bottom | AnchorStyles.Right, + Bounds = new Rectangle(309, 72, 75, 23), + DialogResult = DialogResult.No, + Text = Resources.No + }; + + Label label = new Label { + AutoSize = true, + Bounds = new Rectangle(9, 20, 372, 13), + Text = promptText + }; + + Form form = new Form { + AcceptButton = buttonYes, + CancelButton = buttonNo, + ClientSize = new Size(Math.Max(300, label.Right + 10), 107), + Controls = { label, buttonYes, buttonNo }, + FormBorderStyle = FormBorderStyle.FixedDialog, + MinimizeBox = false, + MaximizeBox = false, + StartPosition = FormStartPosition.CenterScreen, + Text = title + }; DialogResult dialogResult = form.ShowDialog(); return dialogResult; diff --git a/GUI/Logging.cs b/GUI/Logging.cs index 7a3af88eb..d3b9a746e 100644 --- a/GUI/Logging.cs +++ b/GUI/Logging.cs @@ -47,7 +47,10 @@ namespace ArchiSteamFarm { } } - MessageBoxTarget messageBoxTarget = new MessageBoxTarget { Name = "MessageBox", Layout = GeneralLayout }; + MessageBoxTarget messageBoxTarget = new MessageBoxTarget { + Name = "MessageBox", + Layout = GeneralLayout + }; LogManager.Configuration.AddTarget(messageBoxTarget); LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Fatal, messageBoxTarget)); @@ -59,7 +62,11 @@ namespace ArchiSteamFarm { return; } - FileTarget fileTarget = new FileTarget("File") { DeleteOldFileOnStartup = true, FileName = SharedInfo.LogFile, Layout = GeneralLayout }; + FileTarget fileTarget = new FileTarget("File") { + DeleteOldFileOnStartup = true, + FileName = SharedInfo.LogFile, + Layout = GeneralLayout + }; LogManager.Configuration.AddTarget(fileTarget); LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, fileTarget)); @@ -68,7 +75,14 @@ namespace ArchiSteamFarm { } internal static void InitFormLogger() { - RichTextBoxTarget formControlTarget = new RichTextBoxTarget { AutoScroll = true, ControlName = "LogTextBox", FormName = "MainForm", Layout = GeneralLayout, MaxLines = byte.MaxValue, Name = "RichTextBox" }; + RichTextBoxTarget formControlTarget = new RichTextBoxTarget { + AutoScroll = true, + ControlName = "LogTextBox", + FormName = "MainForm", + Layout = GeneralLayout, + MaxLines = byte.MaxValue, + Name = "RichTextBox" + }; formControlTarget.RowColoringRules.Add(new RichTextBoxRowColoringRule("level >= LogLevel.Error", "Red", "Black")); formControlTarget.RowColoringRules.Add(new RichTextBoxRowColoringRule("level >= LogLevel.Warn", "Yellow", "Black")); diff --git a/GUI/MainForm.cs b/GUI/MainForm.cs index 319d5a20f..5f4c99278 100644 --- a/GUI/MainForm.cs +++ b/GUI/MainForm.cs @@ -100,7 +100,10 @@ namespace GUI { botStatusForm.TopLevel = false; BotStatusPanel.Controls.Add(botStatusForm); - ListViewItem botListViewItem = new ListViewItem { ImageIndex = BotIndexes[botName], Text = botName }; + ListViewItem botListViewItem = new ListViewItem { + ImageIndex = BotIndexes[botName], + Text = botName + }; BotListView.Items.Add(botListViewItem); }