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
This commit is contained in:
JustArchi
2016-12-23 18:49:52 +01:00
parent 4219107d2b
commit 30c69cf57c
23 changed files with 192 additions and 190 deletions

View File

@@ -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<Bot, DateTime> LastWriteTimes = new ConcurrentDictionary<Bot, DateTime>();
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<GitHub.ReleaseResponse>(releaseURL).ConfigureAwait(false);
if (releaseResponse == null) {
ArchiLogger.LogGenericWarning("Could not check latest version!");
Program.ArchiLogger.LogGenericWarning("Could not check latest version!");
return;
}
} else {
List<GitHub.ReleaseResponse> releases = await Program.WebBrowser.UrlGetToJsonResultRetry<List<GitHub.ReleaseResponse>>(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();
}

View File

@@ -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;
}

View File

@@ -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<ulong, Tuple<uint, Steam.Item.EType>> descriptions, List<KeyValue> input, HashSet<Steam.Item> 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;
}

View File

@@ -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<string> 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<string> 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<string> 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<string> 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<string> 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<string> 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<string> 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<string> 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<string> 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<string> 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<string> 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<string> ResponseUpdate(ulong steamID) {
if (steamID == 0) {
ASF.ArchiLogger.LogNullError(nameof(steamID));
Program.ArchiLogger.LogNullError(nameof(steamID));
return null;
}

View File

@@ -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<BotConfig>(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<uint> validGames = new HashSet<uint>(botConfig.GamesPlayedWhileIdle.Take(CardsFarmer.MaxGamesPlayedConcurrently));
botConfig.GamesPlayedWhileIdle.IntersectWith(validGames);

View File

@@ -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<BotDatabase>(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);

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}
}

View File

@@ -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();
}

View File

@@ -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<GlobalConfig>(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;
}

View File

@@ -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<GlobalDatabase>(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);

View File

@@ -39,7 +39,7 @@ namespace ArchiSteamFarm {
public Task UpdateServerListAsync(IEnumerable<IPEndPoint> endPoints) {
if (endPoints == null) {
ASF.ArchiLogger.LogNullError(nameof(endPoints));
Program.ArchiLogger.LogNullError(nameof(endPoints));
return Task.Delay(0);
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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<string> 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<string> 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]

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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);
}
/// <summary>
@@ -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);
}
}
}