From 30c69cf57c26c03385d6e680ff410c8ff94dfff7 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Fri, 23 Dec 2016 18:49:52 +0100 Subject: [PATCH] Move main ArchiLogger from ASF to Program It makes more sense to put it in ASF class due to sharing potential, but I want to unify ArchiBoT logging and this makes it easier for maintenance --- ArchiSteamFarm/ASF.cs | 66 +++++++++---------- ArchiSteamFarm/ArchiHandler.cs | 6 +- ArchiSteamFarm/ArchiWebHandler.cs | 14 ++-- ArchiSteamFarm/Bot.cs | 56 ++++++++-------- ArchiSteamFarm/BotConfig.cs | 8 +-- ArchiSteamFarm/BotDatabase.cs | 10 +-- .../CMsgs/CMsgClientClanInviteAction.cs | 4 +- ArchiSteamFarm/CryptoHelper.cs | 22 +++---- ArchiSteamFarm/Debugging.cs | 4 +- ArchiSteamFarm/Events.cs | 2 +- ArchiSteamFarm/GlobalConfig.cs | 16 ++--- ArchiSteamFarm/GlobalDatabase.cs | 10 +-- ArchiSteamFarm/InMemoryServerListProvider.cs | 2 +- ArchiSteamFarm/JSON/Steam.cs | 38 +++++------ ArchiSteamFarm/Logging.cs | 2 +- ArchiSteamFarm/Program.cs | 32 ++++----- ArchiSteamFarm/Runtime.cs | 28 ++++---- ArchiSteamFarm/Statistics.cs | 2 +- ArchiSteamFarm/Utilities.cs | 6 +- ArchiSteamFarm/WCF.cs | 24 +++---- GUI/Events.cs | 2 +- GUI/MainForm.cs | 8 +-- GUI/Program.cs | 20 +++--- 23 files changed, 192 insertions(+), 190 deletions(-) diff --git a/ArchiSteamFarm/ASF.cs b/ArchiSteamFarm/ASF.cs index 357a415c1..8313d0f0b 100644 --- a/ArchiSteamFarm/ASF.cs +++ b/ArchiSteamFarm/ASF.cs @@ -34,8 +34,6 @@ using ArchiSteamFarm.JSON; namespace ArchiSteamFarm { internal static class ASF { - internal static readonly ArchiLogger ArchiLogger = new ArchiLogger(SharedInfo.ASF); - private static readonly ConcurrentDictionary LastWriteTimes = new ConcurrentDictionary(); private static Timer AutoUpdatesTimer; @@ -44,7 +42,7 @@ namespace ArchiSteamFarm { internal static async Task CheckForUpdate(bool updateOverride = false) { string exeFile = Assembly.GetEntryAssembly().Location; if (string.IsNullOrEmpty(exeFile)) { - ArchiLogger.LogNullError(nameof(exeFile)); + Program.ArchiLogger.LogNullError(nameof(exeFile)); return; } @@ -58,8 +56,8 @@ namespace ArchiSteamFarm { try { File.Delete(oldExeFile); } catch (Exception e) { - ArchiLogger.LogGenericException(e); - ArchiLogger.LogGenericError("Could not remove old ASF binary, please remove " + oldExeFile + " manually in order for update function to work!"); + Program.ArchiLogger.LogGenericException(e); + Program.ArchiLogger.LogGenericError("Could not remove old ASF binary, please remove " + oldExeFile + " manually in order for update function to work!"); } } @@ -72,7 +70,7 @@ namespace ArchiSteamFarm { TimeSpan.FromDays(1) // Period ); - ArchiLogger.LogGenericInfo("ASF will automatically check for new versions every 24 hours"); + Program.ArchiLogger.LogGenericInfo("ASF will automatically check for new versions every 24 hours"); } string releaseURL = SharedInfo.GithubReleaseURL; @@ -80,20 +78,20 @@ namespace ArchiSteamFarm { releaseURL += "/latest"; } - ArchiLogger.LogGenericInfo("Checking new version..."); + Program.ArchiLogger.LogGenericInfo("Checking new version..."); GitHub.ReleaseResponse releaseResponse; if (Program.GlobalConfig.UpdateChannel == GlobalConfig.EUpdateChannel.Stable) { releaseResponse = await Program.WebBrowser.UrlGetToJsonResultRetry(releaseURL).ConfigureAwait(false); if (releaseResponse == null) { - ArchiLogger.LogGenericWarning("Could not check latest version!"); + Program.ArchiLogger.LogGenericWarning("Could not check latest version!"); return; } } else { List releases = await Program.WebBrowser.UrlGetToJsonResultRetry>(releaseURL).ConfigureAwait(false); if ((releases == null) || (releases.Count == 0)) { - ArchiLogger.LogGenericWarning("Could not check latest version!"); + Program.ArchiLogger.LogGenericWarning("Could not check latest version!"); return; } @@ -101,33 +99,33 @@ namespace ArchiSteamFarm { } if (string.IsNullOrEmpty(releaseResponse.Tag)) { - ArchiLogger.LogGenericWarning("Could not check latest version!"); + Program.ArchiLogger.LogGenericWarning("Could not check latest version!"); return; } Version newVersion = new Version(releaseResponse.Tag); - ArchiLogger.LogGenericInfo("Local version: " + SharedInfo.Version + " | Remote version: " + newVersion); + Program.ArchiLogger.LogGenericInfo("Local version: " + SharedInfo.Version + " | Remote version: " + newVersion); if (SharedInfo.Version.CompareTo(newVersion) >= 0) { // If local version is the same or newer than remote version return; } if (!updateOverride && !Program.GlobalConfig.AutoUpdates) { - ArchiLogger.LogGenericInfo("New version is available!"); - ArchiLogger.LogGenericInfo("Consider updating yourself!"); + Program.ArchiLogger.LogGenericInfo("New version is available!"); + Program.ArchiLogger.LogGenericInfo("Consider updating yourself!"); await Task.Delay(5000).ConfigureAwait(false); return; } if (File.Exists(oldExeFile)) { - ArchiLogger.LogGenericWarning("Refusing to proceed with auto update as old " + oldExeFile + " binary could not be removed, please remove it manually"); + Program.ArchiLogger.LogGenericWarning("Refusing to proceed with auto update as old " + oldExeFile + " binary could not be removed, please remove it manually"); return; } // Auto update logic starts here if (releaseResponse.Assets == null) { - ArchiLogger.LogGenericWarning("Could not proceed with update because that version doesn't include assets!"); + Program.ArchiLogger.LogGenericWarning("Could not proceed with update because that version doesn't include assets!"); return; } @@ -135,17 +133,17 @@ namespace ArchiSteamFarm { GitHub.ReleaseResponse.Asset binaryAsset = releaseResponse.Assets.FirstOrDefault(asset => !string.IsNullOrEmpty(asset.Name) && asset.Name.Equals(exeFileName, StringComparison.OrdinalIgnoreCase)); if (binaryAsset == null) { - ArchiLogger.LogGenericWarning("Could not proceed with update because there is no asset that relates to currently running binary!"); + Program.ArchiLogger.LogGenericWarning("Could not proceed with update because there is no asset that relates to currently running binary!"); return; } if (string.IsNullOrEmpty(binaryAsset.DownloadURL)) { - ArchiLogger.LogGenericWarning("Could not proceed with update because download URL is empty!"); + Program.ArchiLogger.LogGenericWarning("Could not proceed with update because download URL is empty!"); return; } - ArchiLogger.LogGenericInfo("Downloading new version..."); - ArchiLogger.LogGenericInfo("While waiting, consider donating if you appreciate the work being done :)"); + Program.ArchiLogger.LogGenericInfo("Downloading new version..."); + Program.ArchiLogger.LogGenericInfo("While waiting, consider donating if you appreciate the work being done :)"); byte[] result = await Program.WebBrowser.UrlGetToBytesRetry(binaryAsset.DownloadURL).ConfigureAwait(false); if (result == null) { @@ -158,7 +156,7 @@ namespace ArchiSteamFarm { try { File.WriteAllBytes(newExeFile, result); } catch (Exception e) { - ArchiLogger.LogGenericException(e); + Program.ArchiLogger.LogGenericException(e); return; } @@ -166,7 +164,7 @@ namespace ArchiSteamFarm { try { File.Move(exeFile, oldExeFile); } catch (Exception e) { - ArchiLogger.LogGenericException(e); + Program.ArchiLogger.LogGenericException(e); try { // Cleanup File.Delete(newExeFile); @@ -180,7 +178,7 @@ namespace ArchiSteamFarm { try { File.Move(newExeFile, exeFile); } catch (Exception e) { - ArchiLogger.LogGenericException(e); + Program.ArchiLogger.LogGenericException(e); try { // Cleanup File.Move(oldExeFile, exeFile); @@ -191,7 +189,7 @@ namespace ArchiSteamFarm { return; } - ArchiLogger.LogGenericInfo("Update process finished!"); + Program.ArchiLogger.LogGenericInfo("Update process finished!"); await RestartOrExit().ConfigureAwait(false); } @@ -215,7 +213,7 @@ namespace ArchiSteamFarm { } if (Bot.Bots.Count == 0) { - ArchiLogger.LogGenericWarning("No bots are defined, did you forget to configure your ASF?"); + Program.ArchiLogger.LogGenericWarning("No bots are defined, did you forget to configure your ASF?"); } } @@ -238,7 +236,7 @@ namespace ArchiSteamFarm { private static async Task CreateBot(string botName) { if (string.IsNullOrEmpty(botName)) { - ArchiLogger.LogNullError(nameof(botName)); + Program.ArchiLogger.LogNullError(nameof(botName)); return; } @@ -258,7 +256,7 @@ namespace ArchiSteamFarm { private static async void OnChanged(object sender, FileSystemEventArgs e) { if ((sender == null) || (e == null)) { - ArchiLogger.LogNullError(nameof(sender) + " || " + nameof(e)); + Program.ArchiLogger.LogNullError(nameof(sender) + " || " + nameof(e)); return; } @@ -268,7 +266,7 @@ namespace ArchiSteamFarm { } if (botName.Equals(SharedInfo.ASF)) { - ArchiLogger.LogGenericWarning("Global config file has been changed!"); + Program.ArchiLogger.LogGenericWarning("Global config file has been changed!"); await RestartOrExit().ConfigureAwait(false); return; } @@ -310,7 +308,7 @@ namespace ArchiSteamFarm { private static void OnCreated(object sender, FileSystemEventArgs e) { if ((sender == null) || (e == null)) { - ArchiLogger.LogNullError(nameof(sender) + " || " + nameof(e)); + Program.ArchiLogger.LogNullError(nameof(sender) + " || " + nameof(e)); return; } @@ -324,7 +322,7 @@ namespace ArchiSteamFarm { private static void OnDeleted(object sender, FileSystemEventArgs e) { if ((sender == null) || (e == null)) { - ArchiLogger.LogNullError(nameof(sender) + " || " + nameof(e)); + Program.ArchiLogger.LogNullError(nameof(sender) + " || " + nameof(e)); return; } @@ -334,7 +332,7 @@ namespace ArchiSteamFarm { } if (botName.Equals(SharedInfo.ASF)) { - ArchiLogger.LogGenericError("Global config file has been removed, exiting..."); + Program.ArchiLogger.LogGenericError("Global config file has been removed, exiting..."); Program.Exit(1); return; } @@ -347,7 +345,7 @@ namespace ArchiSteamFarm { private static void OnRenamed(object sender, RenamedEventArgs e) { if ((sender == null) || (e == null)) { - ArchiLogger.LogNullError(nameof(sender) + " || " + nameof(e)); + Program.ArchiLogger.LogNullError(nameof(sender) + " || " + nameof(e)); return; } @@ -357,7 +355,7 @@ namespace ArchiSteamFarm { } if (oldBotName.Equals(SharedInfo.ASF)) { - ArchiLogger.LogGenericError("Global config file has been renamed, exiting..."); + Program.ArchiLogger.LogGenericError("Global config file has been renamed, exiting..."); Program.Exit(1); return; } @@ -377,11 +375,11 @@ namespace ArchiSteamFarm { private static async Task RestartOrExit() { if (Program.GlobalConfig.AutoRestart) { - ArchiLogger.LogGenericInfo("Restarting..."); + Program.ArchiLogger.LogGenericInfo("Restarting..."); await Task.Delay(5000).ConfigureAwait(false); Program.Restart(); } else { - ArchiLogger.LogGenericInfo("Exiting..."); + Program.ArchiLogger.LogGenericInfo("Exiting..."); await Task.Delay(5000).ConfigureAwait(false); Program.Exit(); } diff --git a/ArchiSteamFarm/ArchiHandler.cs b/ArchiSteamFarm/ArchiHandler.cs index 5c9843ec2..b1363a257 100644 --- a/ArchiSteamFarm/ArchiHandler.cs +++ b/ArchiSteamFarm/ArchiHandler.cs @@ -395,7 +395,7 @@ namespace ArchiSteamFarm { KeyValue receiptInfo = new KeyValue(); using (MemoryStream ms = new MemoryStream(msg.purchase_receipt_info)) { if (!receiptInfo.TryReadAsBinary(ms)) { - ASF.ArchiLogger.LogNullError(nameof(ms)); + Program.ArchiLogger.LogNullError(nameof(ms)); return; } } @@ -412,14 +412,14 @@ namespace ArchiSteamFarm { // Valid, coupons have PackageID of -1 (don't ask me why) packageID = lineItem["ItemAppID"].AsUnsignedInteger(); if (packageID == 0) { - ASF.ArchiLogger.LogNullError(nameof(packageID)); + Program.ArchiLogger.LogNullError(nameof(packageID)); return; } } string gameName = lineItem["ItemDescription"].Value; if (string.IsNullOrEmpty(gameName)) { - ASF.ArchiLogger.LogNullError(nameof(gameName)); + Program.ArchiLogger.LogNullError(nameof(gameName)); return; } diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index 976d48d8e..da3724aa7 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -950,7 +950,7 @@ namespace ArchiSteamFarm { private static uint GetAppIDFromMarketHashName(string hashName) { if (string.IsNullOrEmpty(hashName)) { - ASF.ArchiLogger.LogNullError(nameof(hashName)); + Program.ArchiLogger.LogNullError(nameof(hashName)); return 0; } @@ -965,7 +965,7 @@ namespace ArchiSteamFarm { private static Steam.Item.EType GetItemType(string name) { if (string.IsNullOrEmpty(name)) { - ASF.ArchiLogger.LogNullError(nameof(name)); + Program.ArchiLogger.LogNullError(nameof(name)); return Steam.Item.EType.Unknown; } @@ -1006,32 +1006,32 @@ namespace ArchiSteamFarm { private static bool ParseItems(Dictionary> descriptions, List input, HashSet output) { if ((descriptions == null) || (input == null) || (input.Count == 0) || (output == null)) { - ASF.ArchiLogger.LogNullError(nameof(descriptions) + " || " + nameof(input) + " || " + nameof(output)); + Program.ArchiLogger.LogNullError(nameof(descriptions) + " || " + nameof(input) + " || " + nameof(output)); return false; } foreach (KeyValue item in input) { uint appID = item["appid"].AsUnsignedInteger(); if (appID == 0) { - ASF.ArchiLogger.LogNullError(nameof(appID)); + Program.ArchiLogger.LogNullError(nameof(appID)); return false; } ulong contextID = item["contextid"].AsUnsignedLong(); if (contextID == 0) { - ASF.ArchiLogger.LogNullError(nameof(contextID)); + Program.ArchiLogger.LogNullError(nameof(contextID)); return false; } ulong classID = item["classid"].AsUnsignedLong(); if (classID == 0) { - ASF.ArchiLogger.LogNullError(nameof(classID)); + Program.ArchiLogger.LogNullError(nameof(classID)); return false; } uint amount = item["amount"].AsUnsignedInteger(); if (amount == 0) { - ASF.ArchiLogger.LogNullError(nameof(amount)); + Program.ArchiLogger.LogNullError(nameof(amount)); return false; } diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 84afe2ec4..2c7068c4b 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -297,14 +297,14 @@ namespace ArchiSteamFarm { try { return JsonConvert.SerializeObject(response); } catch (JsonException e) { - ASF.ArchiLogger.LogGenericException(e); + Program.ArchiLogger.LogGenericException(e); return null; } } internal static void InitializeCMs(uint cellID, IServerListProvider serverListProvider) { if (serverListProvider == null) { - ASF.ArchiLogger.LogNullError(nameof(serverListProvider)); + Program.ArchiLogger.LogNullError(nameof(serverListProvider)); return; } @@ -824,7 +824,7 @@ namespace ArchiSteamFarm { return (steamID == Program.GlobalConfig.SteamOwnerID) || (Debugging.IsDebugBuild && (steamID == SharedInfo.ArchiSteamID)); } - ASF.ArchiLogger.LogNullError(nameof(steamID)); + Program.ArchiLogger.LogNullError(nameof(steamID)); return false; } @@ -833,7 +833,7 @@ namespace ArchiSteamFarm { return Regex.IsMatch(key, @"^[0-9A-Z]{4,7}-[0-9A-Z]{4,7}-[0-9A-Z]{4,7}(?:(?:-[0-9A-Z]{4,7})?(?:-[0-9A-Z]{4,7}))?$", RegexOptions.IgnoreCase); } - ASF.ArchiLogger.LogNullError(nameof(key)); + Program.ArchiLogger.LogNullError(nameof(key)); return false; } @@ -1504,7 +1504,7 @@ namespace ArchiSteamFarm { private static async Task Response2FA(ulong steamID, string botName) { if ((steamID == 0) || string.IsNullOrEmpty(botName)) { - ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); + Program.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); return null; } @@ -1543,7 +1543,7 @@ namespace ArchiSteamFarm { private static async Task Response2FAConfirm(ulong steamID, string botName, bool confirm) { if ((steamID == 0) || string.IsNullOrEmpty(botName)) { - ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); + Program.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); return null; } @@ -1595,7 +1595,7 @@ namespace ArchiSteamFarm { private static async Task ResponseAddLicense(ulong steamID, string botName, string games) { if ((steamID == 0) || string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(games)) { - ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName) + " || " + nameof(games)); + Program.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName) + " || " + nameof(games)); return null; } @@ -1632,13 +1632,13 @@ namespace ArchiSteamFarm { return !IsOwner(steamID) ? null : GetAPIStatus(); } - ASF.ArchiLogger.LogNullError(nameof(steamID)); + Program.ArchiLogger.LogNullError(nameof(steamID)); return null; } private static string ResponseExit(ulong steamID) { if (steamID == 0) { - ASF.ArchiLogger.LogNullError(nameof(steamID)); + Program.ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -1676,7 +1676,7 @@ namespace ArchiSteamFarm { private static async Task ResponseFarm(ulong steamID, string botName) { if ((steamID == 0) || string.IsNullOrEmpty(botName)) { - ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); + Program.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); return null; } @@ -1756,7 +1756,7 @@ namespace ArchiSteamFarm { private static async Task ResponseLoot(ulong steamID, string botName) { if ((steamID == 0) || string.IsNullOrEmpty(botName)) { - ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); + Program.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); return null; } @@ -1774,7 +1774,7 @@ namespace ArchiSteamFarm { private static async Task ResponseLootAll(ulong steamID) { if (steamID == 0) { - ASF.ArchiLogger.LogNullError(nameof(steamID)); + Program.ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -1802,7 +1802,7 @@ namespace ArchiSteamFarm { private static string ResponseLootSwitch(ulong steamID, string botName) { if ((steamID == 0) || string.IsNullOrEmpty(botName)) { - ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); + Program.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); return null; } @@ -1875,7 +1875,7 @@ namespace ArchiSteamFarm { private static async Task ResponseOwns(ulong steamID, string botName, string query) { if ((steamID == 0) || string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(query)) { - ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName) + " || " + nameof(query)); + Program.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName) + " || " + nameof(query)); return null; } @@ -1893,7 +1893,7 @@ namespace ArchiSteamFarm { private static async Task ResponseOwnsAll(ulong steamID, string query) { if ((steamID == 0) || string.IsNullOrEmpty(query)) { - ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(query)); + Program.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(query)); return null; } @@ -1930,7 +1930,7 @@ namespace ArchiSteamFarm { private static string ResponsePassword(ulong steamID, string botName) { if ((steamID == 0) || string.IsNullOrEmpty(botName)) { - ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); + Program.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); return null; } @@ -1976,7 +1976,7 @@ namespace ArchiSteamFarm { private static async Task ResponsePause(ulong steamID, string botName, bool sticky) { if ((steamID == 0) || string.IsNullOrEmpty(botName)) { - ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); + Program.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); return null; } @@ -2016,7 +2016,7 @@ namespace ArchiSteamFarm { private static async Task ResponsePlay(ulong steamID, string botName, string games) { if ((steamID == 0) || string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(games)) { - ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName) + " || " + nameof(games)); + Program.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName) + " || " + nameof(games)); return null; } @@ -2179,7 +2179,7 @@ namespace ArchiSteamFarm { private static async Task ResponseRedeem(ulong steamID, string botName, string message, ERedeemFlags redeemFlags = ERedeemFlags.None) { if ((steamID == 0) || string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(message)) { - ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName) + " || " + nameof(message)); + Program.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName) + " || " + nameof(message)); return null; } @@ -2197,7 +2197,7 @@ namespace ArchiSteamFarm { private static string ResponseRejoinChat(ulong steamID) { if (steamID == 0) { - ASF.ArchiLogger.LogNullError(nameof(steamID)); + Program.ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -2214,7 +2214,7 @@ namespace ArchiSteamFarm { private static string ResponseRestart(ulong steamID) { if (steamID == 0) { - ASF.ArchiLogger.LogNullError(nameof(steamID)); + Program.ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -2256,7 +2256,7 @@ namespace ArchiSteamFarm { private static string ResponseResume(ulong steamID, string botName) { if ((steamID == 0) || string.IsNullOrEmpty(botName)) { - ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); + Program.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); return null; } @@ -2293,7 +2293,7 @@ namespace ArchiSteamFarm { private static string ResponseStart(ulong steamID, string botName) { if ((steamID == 0) || string.IsNullOrEmpty(botName)) { - ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); + Program.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); return null; } @@ -2311,7 +2311,7 @@ namespace ArchiSteamFarm { private static string ResponseStartAll(ulong steamID) { if (steamID == 0) { - ASF.ArchiLogger.LogNullError(nameof(steamID)); + Program.ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -2375,7 +2375,7 @@ namespace ArchiSteamFarm { private static string ResponseStatus(ulong steamID, string botName) { if ((steamID == 0) || string.IsNullOrEmpty(botName)) { - ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); + Program.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); return null; } @@ -2393,7 +2393,7 @@ namespace ArchiSteamFarm { private static string ResponseStatusAll(ulong steamID) { if (steamID == 0) { - ASF.ArchiLogger.LogNullError(nameof(steamID)); + Program.ArchiLogger.LogNullError(nameof(steamID)); return null; } @@ -2427,7 +2427,7 @@ namespace ArchiSteamFarm { private static string ResponseStop(ulong steamID, string botName) { if ((steamID == 0) || string.IsNullOrEmpty(botName)) { - ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); + Program.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botName)); return null; } @@ -2454,7 +2454,7 @@ namespace ArchiSteamFarm { private static async Task ResponseUpdate(ulong steamID) { if (steamID == 0) { - ASF.ArchiLogger.LogNullError(nameof(steamID)); + Program.ArchiLogger.LogNullError(nameof(steamID)); return null; } diff --git a/ArchiSteamFarm/BotConfig.cs b/ArchiSteamFarm/BotConfig.cs index ee8fdee11..d66b46f4f 100644 --- a/ArchiSteamFarm/BotConfig.cs +++ b/ArchiSteamFarm/BotConfig.cs @@ -121,7 +121,7 @@ namespace ArchiSteamFarm { internal static BotConfig Load(string filePath) { if (string.IsNullOrEmpty(filePath)) { - ASF.ArchiLogger.LogNullError(nameof(filePath)); + Program.ArchiLogger.LogNullError(nameof(filePath)); return null; } @@ -134,12 +134,12 @@ namespace ArchiSteamFarm { try { botConfig = JsonConvert.DeserializeObject(File.ReadAllText(filePath)); } catch (Exception e) { - ASF.ArchiLogger.LogGenericException(e); + Program.ArchiLogger.LogGenericException(e); return null; } if (botConfig == null) { - ASF.ArchiLogger.LogNullError(nameof(botConfig)); + Program.ArchiLogger.LogNullError(nameof(botConfig)); return null; } @@ -155,7 +155,7 @@ namespace ArchiSteamFarm { return botConfig; } - ASF.ArchiLogger.LogGenericWarning("Playing more than " + CardsFarmer.MaxGamesPlayedConcurrently + " games concurrently is not possible, only first " + CardsFarmer.MaxGamesPlayedConcurrently + " entries from GamesPlayedWhileIdle will be used"); + Program.ArchiLogger.LogGenericWarning("Playing more than " + CardsFarmer.MaxGamesPlayedConcurrently + " games concurrently is not possible, only first " + CardsFarmer.MaxGamesPlayedConcurrently + " entries from GamesPlayedWhileIdle will be used"); HashSet validGames = new HashSet(botConfig.GamesPlayedWhileIdle.Take(CardsFarmer.MaxGamesPlayedConcurrently)); botConfig.GamesPlayedWhileIdle.IntersectWith(validGames); diff --git a/ArchiSteamFarm/BotDatabase.cs b/ArchiSteamFarm/BotDatabase.cs index 1eec758f4..6bcd091ef 100644 --- a/ArchiSteamFarm/BotDatabase.cs +++ b/ArchiSteamFarm/BotDatabase.cs @@ -82,7 +82,7 @@ namespace ArchiSteamFarm { internal static BotDatabase Load(string filePath) { if (string.IsNullOrEmpty(filePath)) { - ASF.ArchiLogger.LogNullError(nameof(filePath)); + Program.ArchiLogger.LogNullError(nameof(filePath)); return null; } @@ -95,12 +95,12 @@ namespace ArchiSteamFarm { try { botDatabase = JsonConvert.DeserializeObject(File.ReadAllText(filePath)); } catch (Exception e) { - ASF.ArchiLogger.LogGenericException(e); + Program.ArchiLogger.LogGenericException(e); return null; } if (botDatabase == null) { - ASF.ArchiLogger.LogNullError(nameof(botDatabase)); + Program.ArchiLogger.LogNullError(nameof(botDatabase)); return null; } @@ -111,7 +111,7 @@ namespace ArchiSteamFarm { internal void Save() { string json = JsonConvert.SerializeObject(this); if (string.IsNullOrEmpty(json)) { - ASF.ArchiLogger.LogNullError(nameof(json)); + Program.ArchiLogger.LogNullError(nameof(json)); return; } @@ -121,7 +121,7 @@ namespace ArchiSteamFarm { File.WriteAllText(FilePath, json); break; } catch (Exception e) { - ASF.ArchiLogger.LogGenericException(e); + Program.ArchiLogger.LogGenericException(e); } Thread.Sleep(1000); diff --git a/ArchiSteamFarm/CMsgs/CMsgClientClanInviteAction.cs b/ArchiSteamFarm/CMsgs/CMsgClientClanInviteAction.cs index 84b654651..a24bdf533 100644 --- a/ArchiSteamFarm/CMsgs/CMsgClientClanInviteAction.cs +++ b/ArchiSteamFarm/CMsgs/CMsgClientClanInviteAction.cs @@ -33,7 +33,7 @@ namespace ArchiSteamFarm.CMsgs { void ISteamSerializable.Deserialize(Stream stream) { if (stream == null) { - ASF.ArchiLogger.LogNullError(nameof(stream)); + Program.ArchiLogger.LogNullError(nameof(stream)); return; } @@ -46,7 +46,7 @@ namespace ArchiSteamFarm.CMsgs { void ISteamSerializable.Serialize(Stream stream) { if (stream == null) { - ASF.ArchiLogger.LogNullError(nameof(stream)); + Program.ArchiLogger.LogNullError(nameof(stream)); return; } diff --git a/ArchiSteamFarm/CryptoHelper.cs b/ArchiSteamFarm/CryptoHelper.cs index 5a2ca1fb9..b30a9cf03 100644 --- a/ArchiSteamFarm/CryptoHelper.cs +++ b/ArchiSteamFarm/CryptoHelper.cs @@ -32,7 +32,7 @@ namespace ArchiSteamFarm { internal static string Decrypt(ECryptoMethod cryptoMethod, string encrypted) { if (string.IsNullOrEmpty(encrypted)) { - ASF.ArchiLogger.LogNullError(nameof(encrypted)); + Program.ArchiLogger.LogNullError(nameof(encrypted)); return null; } @@ -50,7 +50,7 @@ namespace ArchiSteamFarm { internal static string Encrypt(ECryptoMethod cryptoMethod, string decrypted) { if (string.IsNullOrEmpty(decrypted)) { - ASF.ArchiLogger.LogNullError(nameof(decrypted)); + Program.ArchiLogger.LogNullError(nameof(decrypted)); return null; } @@ -68,7 +68,7 @@ namespace ArchiSteamFarm { internal static void SetEncryptionKey(string key) { if (string.IsNullOrEmpty(key)) { - ASF.ArchiLogger.LogNullError(nameof(key)); + Program.ArchiLogger.LogNullError(nameof(key)); return; } @@ -77,7 +77,7 @@ namespace ArchiSteamFarm { private static string DecryptAES(string encrypted) { if (string.IsNullOrEmpty(encrypted)) { - ASF.ArchiLogger.LogNullError(nameof(encrypted)); + Program.ArchiLogger.LogNullError(nameof(encrypted)); return null; } @@ -91,14 +91,14 @@ namespace ArchiSteamFarm { decryptedData = SteamKit2.CryptoHelper.SymmetricDecrypt(decryptedData, key); return Encoding.UTF8.GetString(decryptedData); } catch (Exception e) { - ASF.ArchiLogger.LogGenericException(e); + Program.ArchiLogger.LogGenericException(e); return null; } } private static string DecryptProtectedDataForCurrentUser(string encrypted) { if (string.IsNullOrEmpty(encrypted)) { - ASF.ArchiLogger.LogNullError(nameof(encrypted)); + Program.ArchiLogger.LogNullError(nameof(encrypted)); return null; } @@ -108,14 +108,14 @@ namespace ArchiSteamFarm { return Encoding.UTF8.GetString(decryptedData); } catch (Exception e) { - ASF.ArchiLogger.LogGenericException(e); + Program.ArchiLogger.LogGenericException(e); return null; } } private static string EncryptAES(string decrypted) { if (string.IsNullOrEmpty(decrypted)) { - ASF.ArchiLogger.LogNullError(nameof(decrypted)); + Program.ArchiLogger.LogNullError(nameof(decrypted)); return null; } @@ -129,14 +129,14 @@ namespace ArchiSteamFarm { encryptedData = SteamKit2.CryptoHelper.SymmetricEncrypt(encryptedData, key); return Convert.ToBase64String(encryptedData); } catch (Exception e) { - ASF.ArchiLogger.LogGenericException(e); + Program.ArchiLogger.LogGenericException(e); return null; } } private static string EncryptProtectedDataForCurrentUser(string decrypted) { if (string.IsNullOrEmpty(decrypted)) { - ASF.ArchiLogger.LogNullError(nameof(decrypted)); + Program.ArchiLogger.LogNullError(nameof(decrypted)); return null; } @@ -146,7 +146,7 @@ namespace ArchiSteamFarm { return Convert.ToBase64String(encryptedData); } catch (Exception e) { - ASF.ArchiLogger.LogGenericException(e); + Program.ArchiLogger.LogGenericException(e); return null; } } diff --git a/ArchiSteamFarm/Debugging.cs b/ArchiSteamFarm/Debugging.cs index 47b06f91d..8dea3abc8 100644 --- a/ArchiSteamFarm/Debugging.cs +++ b/ArchiSteamFarm/Debugging.cs @@ -38,11 +38,11 @@ namespace ArchiSteamFarm { internal sealed class DebugListener : IDebugListener { public void WriteLine(string category, string msg) { if (string.IsNullOrEmpty(category) && string.IsNullOrEmpty(msg)) { - ASF.ArchiLogger.LogNullError(nameof(category) + " && " + nameof(msg)); + Program.ArchiLogger.LogNullError(nameof(category) + " && " + nameof(msg)); return; } - ASF.ArchiLogger.LogGenericDebug(category + " | " + msg); + Program.ArchiLogger.LogGenericDebug(category + " | " + msg); } } } diff --git a/ArchiSteamFarm/Events.cs b/ArchiSteamFarm/Events.cs index 0966611b1..03239f78d 100644 --- a/ArchiSteamFarm/Events.cs +++ b/ArchiSteamFarm/Events.cs @@ -33,7 +33,7 @@ namespace ArchiSteamFarm { return; } - ASF.ArchiLogger.LogGenericInfo("No bots are running, exiting"); + Program.ArchiLogger.LogGenericInfo("No bots are running, exiting"); await Task.Delay(5000).ConfigureAwait(false); Program.Shutdown(); } diff --git a/ArchiSteamFarm/GlobalConfig.cs b/ArchiSteamFarm/GlobalConfig.cs index b8d13e46b..f808c1509 100644 --- a/ArchiSteamFarm/GlobalConfig.cs +++ b/ArchiSteamFarm/GlobalConfig.cs @@ -109,7 +109,7 @@ namespace ArchiSteamFarm { internal static GlobalConfig Load(string filePath) { if (string.IsNullOrEmpty(filePath)) { - ASF.ArchiLogger.LogNullError(nameof(filePath)); + Program.ArchiLogger.LogNullError(nameof(filePath)); return null; } @@ -122,12 +122,12 @@ namespace ArchiSteamFarm { try { globalConfig = JsonConvert.DeserializeObject(File.ReadAllText(filePath)); } catch (Exception e) { - ASF.ArchiLogger.LogGenericException(e); + Program.ArchiLogger.LogGenericException(e); return null; } if (globalConfig == null) { - ASF.ArchiLogger.LogNullError(nameof(globalConfig)); + Program.ArchiLogger.LogNullError(nameof(globalConfig)); return null; } @@ -138,24 +138,24 @@ namespace ArchiSteamFarm { case ProtocolType.Udp: break; default: - ASF.ArchiLogger.LogGenericWarning("Configured SteamProtocol is invalid: " + globalConfig.SteamProtocol); + Program.ArchiLogger.LogGenericWarning("Configured SteamProtocol is invalid: " + globalConfig.SteamProtocol); return null; } // User might not know what he's doing // Ensure that he can't screw core ASF variables if (globalConfig.MaxFarmingTime == 0) { - ASF.ArchiLogger.LogGenericWarning("Configured MaxFarmingTime is invalid: " + globalConfig.MaxFarmingTime); + Program.ArchiLogger.LogGenericWarning("Configured MaxFarmingTime is invalid: " + globalConfig.MaxFarmingTime); return null; } if (globalConfig.FarmingDelay == 0) { - ASF.ArchiLogger.LogGenericWarning("Configured FarmingDelay is invalid: " + globalConfig.FarmingDelay); + Program.ArchiLogger.LogGenericWarning("Configured FarmingDelay is invalid: " + globalConfig.FarmingDelay); return null; } if (globalConfig.HttpTimeout == 0) { - ASF.ArchiLogger.LogGenericWarning("Configured HttpTimeout is invalid: " + globalConfig.HttpTimeout); + Program.ArchiLogger.LogGenericWarning("Configured HttpTimeout is invalid: " + globalConfig.HttpTimeout); return null; } @@ -163,7 +163,7 @@ namespace ArchiSteamFarm { return globalConfig; } - ASF.ArchiLogger.LogGenericWarning("Configured WCFPort is invalid: " + globalConfig.WCFPort); + Program.ArchiLogger.LogGenericWarning("Configured WCFPort is invalid: " + globalConfig.WCFPort); return null; } diff --git a/ArchiSteamFarm/GlobalDatabase.cs b/ArchiSteamFarm/GlobalDatabase.cs index ec85765d3..b6326c8d9 100644 --- a/ArchiSteamFarm/GlobalDatabase.cs +++ b/ArchiSteamFarm/GlobalDatabase.cs @@ -84,7 +84,7 @@ namespace ArchiSteamFarm { internal static GlobalDatabase Load(string filePath) { if (string.IsNullOrEmpty(filePath)) { - ASF.ArchiLogger.LogNullError(nameof(filePath)); + Program.ArchiLogger.LogNullError(nameof(filePath)); return null; } @@ -97,12 +97,12 @@ namespace ArchiSteamFarm { try { globalDatabase = JsonConvert.DeserializeObject(File.ReadAllText(filePath), CustomSerializerSettings); } catch (Exception e) { - ASF.ArchiLogger.LogGenericException(e); + Program.ArchiLogger.LogGenericException(e); return null; } if (globalDatabase == null) { - ASF.ArchiLogger.LogNullError(nameof(globalDatabase)); + Program.ArchiLogger.LogNullError(nameof(globalDatabase)); return null; } @@ -115,7 +115,7 @@ namespace ArchiSteamFarm { private void Save() { string json = JsonConvert.SerializeObject(this, CustomSerializerSettings); if (string.IsNullOrEmpty(json)) { - ASF.ArchiLogger.LogNullError(nameof(json)); + Program.ArchiLogger.LogNullError(nameof(json)); return; } @@ -125,7 +125,7 @@ namespace ArchiSteamFarm { File.WriteAllText(FilePath, json); break; } catch (Exception e) { - ASF.ArchiLogger.LogGenericException(e); + Program.ArchiLogger.LogGenericException(e); } Thread.Sleep(1000); diff --git a/ArchiSteamFarm/InMemoryServerListProvider.cs b/ArchiSteamFarm/InMemoryServerListProvider.cs index ed911d624..7e2c565ab 100644 --- a/ArchiSteamFarm/InMemoryServerListProvider.cs +++ b/ArchiSteamFarm/InMemoryServerListProvider.cs @@ -39,7 +39,7 @@ namespace ArchiSteamFarm { public Task UpdateServerListAsync(IEnumerable endPoints) { if (endPoints == null) { - ASF.ArchiLogger.LogNullError(nameof(endPoints)); + Program.ArchiLogger.LogNullError(nameof(endPoints)); return Task.Delay(0); } diff --git a/ArchiSteamFarm/JSON/Steam.cs b/ArchiSteamFarm/JSON/Steam.cs index bc2631305..9d61924b5 100644 --- a/ArchiSteamFarm/JSON/Steam.cs +++ b/ArchiSteamFarm/JSON/Steam.cs @@ -67,25 +67,25 @@ namespace ArchiSteamFarm.JSON { HtmlNode htmlNode = HtmlDocument.DocumentNode.SelectSingleNode("//div[@class='tradeoffer']"); if (htmlNode == null) { - ASF.ArchiLogger.LogNullError(nameof(htmlNode)); + Program.ArchiLogger.LogNullError(nameof(htmlNode)); return 0; } string id = htmlNode.GetAttributeValue("id", null); if (string.IsNullOrEmpty(id)) { - ASF.ArchiLogger.LogNullError(nameof(id)); + Program.ArchiLogger.LogNullError(nameof(id)); return 0; } int index = id.IndexOf('_'); if (index < 0) { - ASF.ArchiLogger.LogNullError(nameof(index)); + Program.ArchiLogger.LogNullError(nameof(index)); return 0; } index++; if (id.Length <= index) { - ASF.ArchiLogger.LogNullError(nameof(id.Length)); + Program.ArchiLogger.LogNullError(nameof(id.Length)); return 0; } @@ -94,7 +94,7 @@ namespace ArchiSteamFarm.JSON { return _TradeOfferID; } - ASF.ArchiLogger.LogNullError(nameof(_TradeOfferID)); + Program.ArchiLogger.LogNullError(nameof(_TradeOfferID)); return 0; } } @@ -131,13 +131,13 @@ namespace ArchiSteamFarm.JSON { HtmlNode htmlNode = HtmlDocument.DocumentNode.SelectSingleNode("//a/@data-miniprofile"); if (htmlNode == null) { - ASF.ArchiLogger.LogNullError(nameof(htmlNode)); + Program.ArchiLogger.LogNullError(nameof(htmlNode)); return 0; } string miniProfile = htmlNode.GetAttributeValue("data-miniprofile", null); if (string.IsNullOrEmpty(miniProfile)) { - ASF.ArchiLogger.LogNullError(nameof(miniProfile)); + Program.ArchiLogger.LogNullError(nameof(miniProfile)); return 0; } @@ -145,7 +145,7 @@ namespace ArchiSteamFarm.JSON { return _OtherSteamID3; } - ASF.ArchiLogger.LogNullError(nameof(_OtherSteamID3)); + Program.ArchiLogger.LogNullError(nameof(_OtherSteamID3)); return 0; } } @@ -182,7 +182,7 @@ namespace ArchiSteamFarm.JSON { set { if (value == null) { - ASF.ArchiLogger.LogNullError(nameof(value)); + Program.ArchiLogger.LogNullError(nameof(value)); return; } @@ -237,13 +237,13 @@ namespace ArchiSteamFarm.JSON { set { if (string.IsNullOrEmpty(value)) { - ASF.ArchiLogger.LogNullError(nameof(value)); + Program.ArchiLogger.LogNullError(nameof(value)); return; } uint amount; if (!uint.TryParse(value, out amount) || (amount == 0)) { - ASF.ArchiLogger.LogNullError(nameof(amount)); + Program.ArchiLogger.LogNullError(nameof(amount)); return; } @@ -258,13 +258,13 @@ namespace ArchiSteamFarm.JSON { set { if (string.IsNullOrEmpty(value)) { - ASF.ArchiLogger.LogNullError(nameof(value)); + Program.ArchiLogger.LogNullError(nameof(value)); return; } uint appID; if (!uint.TryParse(value, out appID) || (appID == 0)) { - ASF.ArchiLogger.LogNullError(nameof(appID)); + Program.ArchiLogger.LogNullError(nameof(appID)); return; } @@ -278,13 +278,13 @@ namespace ArchiSteamFarm.JSON { set { if (string.IsNullOrEmpty(value)) { - ASF.ArchiLogger.LogNullError(nameof(value)); + Program.ArchiLogger.LogNullError(nameof(value)); return; } ulong assetID; if (!ulong.TryParse(value, out assetID) || (assetID == 0)) { - ASF.ArchiLogger.LogNullError(nameof(assetID)); + Program.ArchiLogger.LogNullError(nameof(assetID)); return; } @@ -299,7 +299,7 @@ namespace ArchiSteamFarm.JSON { set { if (string.IsNullOrEmpty(value)) { - ASF.ArchiLogger.LogNullError(nameof(value)); + Program.ArchiLogger.LogNullError(nameof(value)); return; } @@ -319,13 +319,13 @@ namespace ArchiSteamFarm.JSON { set { if (string.IsNullOrEmpty(value)) { - ASF.ArchiLogger.LogNullError(nameof(value)); + Program.ArchiLogger.LogNullError(nameof(value)); return; } ulong contextID; if (!ulong.TryParse(value, out contextID) || (contextID == 0)) { - ASF.ArchiLogger.LogNullError(nameof(contextID)); + Program.ArchiLogger.LogNullError(nameof(contextID)); return; } @@ -407,7 +407,7 @@ namespace ArchiSteamFarm.JSON { } if (OtherSteamID3 == 0) { - ASF.ArchiLogger.LogNullError(nameof(OtherSteamID3)); + Program.ArchiLogger.LogNullError(nameof(OtherSteamID3)); return 0; } diff --git a/ArchiSteamFarm/Logging.cs b/ArchiSteamFarm/Logging.cs index 1cf35858a..2117df3da 100644 --- a/ArchiSteamFarm/Logging.cs +++ b/ArchiSteamFarm/Logging.cs @@ -116,7 +116,7 @@ namespace ArchiSteamFarm { private static void OnConfigurationChanged(object sender, LoggingConfigurationChangedEventArgs e) { if ((sender == null) || (e == null)) { - ASF.ArchiLogger.LogNullError(nameof(sender) + " || " + nameof(e)); + Program.ArchiLogger.LogNullError(nameof(sender) + " || " + nameof(e)); return; } diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index 601ae6f2f..c84880236 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -35,6 +35,8 @@ using SteamKit2; namespace ArchiSteamFarm { internal static class Program { + internal static readonly ArchiLogger ArchiLogger = new ArchiLogger(SharedInfo.ASF); + internal static bool IsWCFRunning => WCF.IsServerRunning; internal static GlobalConfig GlobalConfig { get; private set; } internal static GlobalDatabase GlobalDatabase { get; private set; } @@ -59,7 +61,7 @@ namespace ArchiSteamFarm { } if (GlobalConfig.Headless || !Runtime.IsUserInteractive) { - ASF.ArchiLogger.LogGenericWarning("Received a request for user input, but process is running in headless mode!"); + ArchiLogger.LogGenericWarning("Received a request for user input, but process is running in headless mode!"); return null; } @@ -123,7 +125,7 @@ namespace ArchiSteamFarm { try { Process.Start(Assembly.GetEntryAssembly().Location, string.Join(" ", Environment.GetCommandLineArgs().Skip(1))); } catch (Exception e) { - ASF.ArchiLogger.LogGenericException(e); + ArchiLogger.LogGenericException(e); } ShutdownResetEvent.Set(); @@ -169,10 +171,10 @@ namespace ArchiSteamFarm { } Logging.InitLoggers(); - ASF.ArchiLogger.LogGenericInfo("ASF V" + SharedInfo.Version); + ArchiLogger.LogGenericInfo("ASF V" + SharedInfo.Version); if (!Runtime.IsRuntimeSupported) { - ASF.ArchiLogger.LogGenericError("ASF detected unsupported runtime version, program might NOT run correctly in current environment. You're running it at your own risk!"); + ArchiLogger.LogGenericError("ASF detected unsupported runtime version, program might NOT run correctly in current environment. You're running it at your own risk!"); Thread.Sleep(10000); } @@ -211,7 +213,7 @@ namespace ArchiSteamFarm { GlobalConfig = GlobalConfig.Load(globalConfigFile); if (GlobalConfig == null) { - ASF.ArchiLogger.LogGenericError("Global config could not be loaded, please make sure that " + globalConfigFile + " exists and is valid! Did you forget to read wiki?"); + ArchiLogger.LogGenericError("Global config could not be loaded, please make sure that " + globalConfigFile + " exists and is valid! Did you forget to read wiki?"); Thread.Sleep(5000); Exit(1); } @@ -220,7 +222,7 @@ namespace ArchiSteamFarm { GlobalDatabase = GlobalDatabase.Load(globalDatabaseFile); if (GlobalDatabase == null) { - ASF.ArchiLogger.LogGenericError("Global database could not be loaded, if issue persists, please remove " + globalDatabaseFile + " in order to recreate database!"); + ArchiLogger.LogGenericError("Global database could not be loaded, if issue persists, please remove " + globalDatabaseFile + " in order to recreate database!"); Thread.Sleep(5000); Exit(1); } @@ -229,7 +231,7 @@ namespace ArchiSteamFarm { WebBrowser.Init(); WCF.Init(); - WebBrowser = new WebBrowser(ASF.ArchiLogger); + WebBrowser = new WebBrowser(ArchiLogger); } private static bool InitShutdownSequence() { @@ -268,7 +270,7 @@ namespace ArchiSteamFarm { private static void ParsePostInitArgs(IEnumerable args) { if (args == null) { - ASF.ArchiLogger.LogNullError(nameof(args)); + ArchiLogger.LogNullError(nameof(args)); return; } @@ -294,11 +296,11 @@ namespace ArchiSteamFarm { } if (!Mode.HasFlag(EMode.Client)) { - ASF.ArchiLogger.LogGenericWarning("Ignoring command because --client wasn't specified: " + arg); + ArchiLogger.LogGenericWarning("Ignoring command because --client wasn't specified: " + arg); break; } - ASF.ArchiLogger.LogGenericInfo("Response received: " + WCF.SendCommand(arg)); + ArchiLogger.LogGenericInfo("Response received: " + WCF.SendCommand(arg)); break; } } @@ -306,7 +308,7 @@ namespace ArchiSteamFarm { private static void ParsePreInitArgs(IEnumerable args) { if (args == null) { - ASF.ArchiLogger.LogNullError(nameof(args)); + ArchiLogger.LogNullError(nameof(args)); return; } @@ -334,20 +336,20 @@ namespace ArchiSteamFarm { private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args) { if (args?.ExceptionObject == null) { - ASF.ArchiLogger.LogNullError(nameof(args) + " || " + nameof(args.ExceptionObject)); + ArchiLogger.LogNullError(nameof(args) + " || " + nameof(args.ExceptionObject)); return; } - ASF.ArchiLogger.LogFatalException((Exception) args.ExceptionObject); + ArchiLogger.LogFatalException((Exception) args.ExceptionObject); } private static void UnobservedTaskExceptionHandler(object sender, UnobservedTaskExceptionEventArgs args) { if (args?.Exception == null) { - ASF.ArchiLogger.LogNullError(nameof(args) + " || " + nameof(args.Exception)); + ArchiLogger.LogNullError(nameof(args) + " || " + nameof(args.Exception)); return; } - ASF.ArchiLogger.LogFatalException(args.Exception); + ArchiLogger.LogFatalException(args.Exception); } [Flags] diff --git a/ArchiSteamFarm/Runtime.cs b/ArchiSteamFarm/Runtime.cs index 22f54bb4d..1c4b24798 100644 --- a/ArchiSteamFarm/Runtime.cs +++ b/ArchiSteamFarm/Runtime.cs @@ -39,38 +39,38 @@ namespace ArchiSteamFarm { if (IsRunningOnMono) { Version monoVersion = GetMonoVersion(); if (monoVersion == null) { - ASF.ArchiLogger.LogNullError(nameof(monoVersion)); + Program.ArchiLogger.LogNullError(nameof(monoVersion)); return false; } Version minMonoVersion = new Version(4, 6); if (monoVersion >= minMonoVersion) { - ASF.ArchiLogger.LogGenericInfo("Your Mono version is OK. Required: " + minMonoVersion + " | Found: " + monoVersion); + Program.ArchiLogger.LogGenericInfo("Your Mono version is OK. Required: " + minMonoVersion + " | Found: " + monoVersion); _IsRuntimeSupported = true; return true; } - ASF.ArchiLogger.LogGenericWarning("Your Mono version is too old. Required: " + minMonoVersion + " | Found: " + monoVersion); + Program.ArchiLogger.LogGenericWarning("Your Mono version is too old. Required: " + minMonoVersion + " | Found: " + monoVersion); _IsRuntimeSupported = false; return false; } Version netVersion = GetNetVersion(); if (netVersion == null) { - ASF.ArchiLogger.LogNullError(nameof(netVersion)); + Program.ArchiLogger.LogNullError(nameof(netVersion)); return false; } Version minNetVersion = new Version(4, 6, 1); if (netVersion >= minNetVersion) { - ASF.ArchiLogger.LogGenericInfo("Your .NET version is OK. Required: " + minNetVersion + " | Found: " + netVersion); + Program.ArchiLogger.LogGenericInfo("Your .NET version is OK. Required: " + minNetVersion + " | Found: " + netVersion); _IsRuntimeSupported = true; return true; } - ASF.ArchiLogger.LogGenericWarning("Your .NET version is too old. Required: " + minNetVersion + " | Found: " + netVersion); + Program.ArchiLogger.LogGenericWarning("Your .NET version is too old. Required: " + minNetVersion + " | Found: " + netVersion); _IsRuntimeSupported = false; return false; } @@ -107,25 +107,25 @@ namespace ArchiSteamFarm { private static Version GetMonoVersion() { if (MonoRuntime == null) { - ASF.ArchiLogger.LogNullError(nameof(MonoRuntime)); + Program.ArchiLogger.LogNullError(nameof(MonoRuntime)); return null; } MethodInfo displayName = MonoRuntime.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static); if (displayName == null) { - ASF.ArchiLogger.LogNullError(nameof(displayName)); + Program.ArchiLogger.LogNullError(nameof(displayName)); return null; } string versionString = (string) displayName.Invoke(null, null); if (string.IsNullOrEmpty(versionString)) { - ASF.ArchiLogger.LogNullError(nameof(versionString)); + Program.ArchiLogger.LogNullError(nameof(versionString)); return null; } int index = versionString.IndexOf(' '); if (index <= 0) { - ASF.ArchiLogger.LogNullError(nameof(index)); + Program.ArchiLogger.LogNullError(nameof(index)); return null; } @@ -136,7 +136,7 @@ namespace ArchiSteamFarm { return version; } - ASF.ArchiLogger.LogNullError(nameof(version)); + Program.ArchiLogger.LogNullError(nameof(version)); return null; } @@ -144,18 +144,18 @@ namespace ArchiSteamFarm { uint release; using (RegistryKey registryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full\\")) { if (registryKey == null) { - ASF.ArchiLogger.LogNullError(nameof(registryKey)); + Program.ArchiLogger.LogNullError(nameof(registryKey)); return null; } object releaseObj = registryKey.GetValue("Release"); if (releaseObj == null) { - ASF.ArchiLogger.LogNullError(nameof(releaseObj)); + Program.ArchiLogger.LogNullError(nameof(releaseObj)); return null; } if (!uint.TryParse(releaseObj.ToString(), out release) || (release == 0)) { - ASF.ArchiLogger.LogNullError(nameof(release)); + Program.ArchiLogger.LogNullError(nameof(release)); return null; } } diff --git a/ArchiSteamFarm/Statistics.cs b/ArchiSteamFarm/Statistics.cs index 06d105790..9ea34011a 100644 --- a/ArchiSteamFarm/Statistics.cs +++ b/ArchiSteamFarm/Statistics.cs @@ -90,7 +90,7 @@ namespace ArchiSteamFarm { internal async Task OnPersonaState(SteamFriends.PersonaStateCallback callback) { if (callback == null) { - ASF.ArchiLogger.LogNullError(nameof(callback)); + Program.ArchiLogger.LogNullError(nameof(callback)); return; } diff --git a/ArchiSteamFarm/Utilities.cs b/ArchiSteamFarm/Utilities.cs index 36480d887..60d1b78a2 100644 --- a/ArchiSteamFarm/Utilities.cs +++ b/ArchiSteamFarm/Utilities.cs @@ -38,7 +38,7 @@ namespace ArchiSteamFarm { internal static string GetCookieValue(this CookieContainer cookieContainer, string url, string name) { if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(name)) { - ASF.ArchiLogger.LogNullError(nameof(url) + " || " + nameof(name)); + Program.ArchiLogger.LogNullError(nameof(url) + " || " + nameof(name)); return null; } @@ -47,7 +47,7 @@ namespace ArchiSteamFarm { try { uri = new Uri(url); } catch (UriFormatException e) { - ASF.ArchiLogger.LogGenericException(e); + Program.ArchiLogger.LogGenericException(e); return null; } @@ -59,7 +59,7 @@ namespace ArchiSteamFarm { internal static int RandomNext(int maxWithout) { if (maxWithout <= 0) { - ASF.ArchiLogger.LogNullError(nameof(maxWithout)); + Program.ArchiLogger.LogNullError(nameof(maxWithout)); return -1; } diff --git a/ArchiSteamFarm/WCF.cs b/ArchiSteamFarm/WCF.cs index 09f352006..5e4536418 100644 --- a/ArchiSteamFarm/WCF.cs +++ b/ArchiSteamFarm/WCF.cs @@ -54,7 +54,7 @@ namespace ArchiSteamFarm { public string HandleCommand(string input) { if (string.IsNullOrEmpty(input)) { - ASF.ArchiLogger.LogNullError(nameof(input)); + Program.ArchiLogger.LogNullError(nameof(input)); return null; } @@ -73,7 +73,7 @@ namespace ArchiSteamFarm { // We must keep it synchronous until either Mono gets fixed, or culprit for freeze located (and corrected) string output = bot.Response(Program.GlobalConfig.SteamOwnerID, command).Result; - ASF.ArchiLogger.LogGenericInfo("Answered to WCF command: " + input + " with: " + output); + Program.ArchiLogger.LogGenericInfo("Answered to WCF command: " + input + " with: " + output); return output; } @@ -90,11 +90,11 @@ namespace ArchiSteamFarm { internal string SendCommand(string input) { if (string.IsNullOrEmpty(input)) { - ASF.ArchiLogger.LogNullError(nameof(input)); + Program.ArchiLogger.LogNullError(nameof(input)); return null; } - ASF.ArchiLogger.LogGenericInfo("Sending command: " + input + " to WCF server on " + URL + "..."); + Program.ArchiLogger.LogGenericInfo("Sending command: " + input + " to WCF server on " + URL + "..."); if (Client == null) { Client = new Client(new NetTcpBinding { Security = { Mode = SecurityMode.None } }, new EndpointAddress(URL)); @@ -108,19 +108,19 @@ namespace ArchiSteamFarm { return; } - ASF.ArchiLogger.LogGenericInfo("Starting WCF server on " + URL + "..."); + Program.ArchiLogger.LogGenericInfo("Starting WCF server on " + URL + "..."); try { ServiceHost = new ServiceHost(typeof(WCF), new Uri(URL)); ServiceHost.AddServiceEndpoint(typeof(IWCF), new NetTcpBinding { Security = { Mode = SecurityMode.None } }, string.Empty); ServiceHost.Open(); - ASF.ArchiLogger.LogGenericInfo("WCF server ready!"); + Program.ArchiLogger.LogGenericInfo("WCF server ready!"); } catch (AddressAccessDeniedException) { - ASF.ArchiLogger.LogGenericError("WCF service could not be started because of AddressAccessDeniedException!"); - ASF.ArchiLogger.LogGenericWarning("If you want to use WCF service provided by ASF, consider starting ASF as administrator, or giving proper permissions!"); + Program.ArchiLogger.LogGenericError("WCF service could not be started because of AddressAccessDeniedException!"); + Program.ArchiLogger.LogGenericWarning("If you want to use WCF service provided by ASF, consider starting ASF as administrator, or giving proper permissions!"); } catch (Exception e) { - ASF.ArchiLogger.LogGenericException(e); + Program.ArchiLogger.LogGenericException(e); } } @@ -133,7 +133,7 @@ namespace ArchiSteamFarm { try { ServiceHost.Close(); } catch (Exception e) { - ASF.ArchiLogger.LogGenericException(e); + Program.ArchiLogger.LogGenericException(e); } } @@ -158,14 +158,14 @@ namespace ArchiSteamFarm { internal string HandleCommand(string input) { if (string.IsNullOrEmpty(input)) { - ASF.ArchiLogger.LogNullError(nameof(input)); + Program.ArchiLogger.LogNullError(nameof(input)); return null; } try { return Channel.HandleCommand(input); } catch (Exception e) { - ASF.ArchiLogger.LogGenericException(e); + Program.ArchiLogger.LogGenericException(e); return null; } } diff --git a/GUI/Events.cs b/GUI/Events.cs index b040b7c50..1e6c8c376 100644 --- a/GUI/Events.cs +++ b/GUI/Events.cs @@ -33,7 +33,7 @@ namespace ArchiSteamFarm { internal static void OnPersonaState(Bot bot, SteamFriends.PersonaStateCallback callback) { if (bot == null) { - ASF.ArchiLogger.LogNullError(nameof(bot)); + Program.ArchiLogger.LogNullError(nameof(bot)); return; } diff --git a/GUI/MainForm.cs b/GUI/MainForm.cs index 5f4c99278..7806b8922 100644 --- a/GUI/MainForm.cs +++ b/GUI/MainForm.cs @@ -23,7 +23,7 @@ namespace GUI { internal static void UpdateBotAvatar(string botName, Image image) { if (string.IsNullOrEmpty(botName) || (image == null)) { - ASF.ArchiLogger.LogNullError(nameof(botName) + " || " + nameof(image)); + Program.ArchiLogger.LogNullError(nameof(botName) + " || " + nameof(image)); return; } @@ -68,10 +68,10 @@ namespace GUI { BotListView.LargeImageList = BotListView.SmallImageList = AvatarImageList; await Task.Run(async () => { - ASF.ArchiLogger.LogGenericInfo("ASF V" + SharedInfo.Version); + Program.ArchiLogger.LogGenericInfo("ASF V" + SharedInfo.Version); if (!Directory.Exists(SharedInfo.ConfigDirectory)) { - ASF.ArchiLogger.LogGenericError("Config directory could not be found!"); + Program.ArchiLogger.LogGenericError("Config directory could not be found!"); Environment.Exit(1); } @@ -133,7 +133,7 @@ namespace GUI { private static Bitmap ResizeImage(Image image, int width, int height) { if ((image == null) || (width <= 0) || (height <= 0)) { - ASF.ArchiLogger.LogNullError(nameof(image) + " || " + nameof(width) + " || " + nameof(height)); + Program.ArchiLogger.LogNullError(nameof(image) + " || " + nameof(width) + " || " + nameof(height)); return null; } diff --git a/GUI/Program.cs b/GUI/Program.cs index 061385432..75d920a32 100644 --- a/GUI/Program.cs +++ b/GUI/Program.cs @@ -13,6 +13,8 @@ using SteamKit2; namespace ArchiSteamFarm { internal static class Program { + internal static readonly ArchiLogger ArchiLogger = new ArchiLogger(SharedInfo.ASF); + internal static GlobalConfig GlobalConfig { get; private set; } internal static GlobalDatabase GlobalDatabase { get; private set; } internal static WebBrowser WebBrowser { get; private set; } @@ -38,7 +40,7 @@ namespace ArchiSteamFarm { try { Process.Start(Assembly.GetEntryAssembly().Location, string.Join(" ", Environment.GetCommandLineArgs().Skip(1))); } catch (Exception e) { - ASF.ArchiLogger.LogGenericException(e); + ArchiLogger.LogGenericException(e); } Environment.Exit(0); @@ -51,7 +53,7 @@ namespace ArchiSteamFarm { Logging.InitCoreLoggers(); if (!Runtime.IsRuntimeSupported) { - ASF.ArchiLogger.LogGenericError("ASF detected unsupported runtime version, program might NOT run correctly in current environment. You're running it at your own risk!"); + ArchiLogger.LogGenericError("ASF detected unsupported runtime version, program might NOT run correctly in current environment. You're running it at your own risk!"); } string homeDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); @@ -101,7 +103,7 @@ namespace ArchiSteamFarm { GlobalConfig = GlobalConfig.Load(globalConfigFile); if (GlobalConfig == null) { - ASF.ArchiLogger.LogGenericError("Global config could not be loaded, please make sure that " + globalConfigFile + " exists and is valid!"); + ArchiLogger.LogGenericError("Global config could not be loaded, please make sure that " + globalConfigFile + " exists and is valid!"); Exit(1); } @@ -109,14 +111,14 @@ namespace ArchiSteamFarm { GlobalDatabase = GlobalDatabase.Load(globalDatabaseFile); if (GlobalDatabase == null) { - ASF.ArchiLogger.LogGenericError("Global database could not be loaded, if issue persists, please remove " + globalDatabaseFile + " in order to recreate database!"); + ArchiLogger.LogGenericError("Global database could not be loaded, if issue persists, please remove " + globalDatabaseFile + " in order to recreate database!"); Exit(1); } ArchiWebHandler.Init(); WebBrowser.Init(); - WebBrowser = new WebBrowser(ASF.ArchiLogger); + WebBrowser = new WebBrowser(ArchiLogger); } /// @@ -132,20 +134,20 @@ namespace ArchiSteamFarm { private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args) { if (args?.ExceptionObject == null) { - ASF.ArchiLogger.LogNullError(nameof(args) + " || " + nameof(args.ExceptionObject)); + ArchiLogger.LogNullError(nameof(args) + " || " + nameof(args.ExceptionObject)); return; } - ASF.ArchiLogger.LogFatalException((Exception) args.ExceptionObject); + ArchiLogger.LogFatalException((Exception) args.ExceptionObject); } private static void UnobservedTaskExceptionHandler(object sender, UnobservedTaskExceptionEventArgs args) { if (args?.Exception == null) { - ASF.ArchiLogger.LogNullError(nameof(args) + " || " + nameof(args.Exception)); + ArchiLogger.LogNullError(nameof(args) + " || " + nameof(args.Exception)); return; } - ASF.ArchiLogger.LogFatalException(args.Exception); + ArchiLogger.LogFatalException(args.Exception); } } } \ No newline at end of file