Code review

This commit is contained in:
JustArchi
2016-04-12 19:12:45 +02:00
parent e9d8f271a2
commit 4a36345635
16 changed files with 68 additions and 24 deletions

View File

@@ -36,7 +36,7 @@ namespace ArchiSteamFarm {
internal ArchiHandler(Bot bot) {
if (bot == null) {
return;
throw new ArgumentNullException("bot");
}
Bot = bot;

View File

@@ -56,7 +56,7 @@ namespace ArchiSteamFarm {
internal ArchiWebHandler(Bot bot) {
if (bot == null) {
return;
throw new ArgumentNullException("bot");
}
Bot = bot;

View File

@@ -107,7 +107,7 @@ namespace ArchiSteamFarm {
internal Bot(string botName) {
if (string.IsNullOrEmpty(botName)) {
return;
throw new ArgumentNullException("botName");
}
BotName = botName;

View File

@@ -92,6 +92,10 @@ namespace ArchiSteamFarm {
// This constructor is used when creating new database
private BotDatabase(string filePath) {
if (string.IsNullOrEmpty(filePath)) {
throw new ArgumentNullException("filePath");
}
FilePath = filePath;
Save();
}

View File

@@ -48,7 +48,7 @@ namespace ArchiSteamFarm {
internal CardsFarmer(Bot bot) {
if (bot == null) {
return;
throw new ArgumentNullException("bot");
}
Bot = bot;

View File

@@ -107,8 +107,11 @@ namespace ArchiSteamFarm {
[JsonProperty(Required = Required.DisallowNull)]
internal HashSet<uint> Blacklist { get; private set; } = new HashSet<uint>(GlobalBlacklist);
internal static GlobalConfig Load() {
string filePath = Path.Combine(Program.ConfigDirectory, Program.GlobalConfigFile);
internal static GlobalConfig Load(string filePath) {
if (string.IsNullOrEmpty(filePath)) {
return null;
}
if (!File.Exists(filePath)) {
return null;
}

View File

@@ -28,8 +28,6 @@ using System.IO;
namespace ArchiSteamFarm {
internal sealed class GlobalDatabase {
private static readonly string FilePath = Path.Combine(Program.ConfigDirectory, Program.GlobalDatabaseFile);
internal uint CellID {
get {
return _CellID;
@@ -47,22 +45,43 @@ namespace ArchiSteamFarm {
[JsonProperty(Required = Required.DisallowNull)]
private uint _CellID;
internal static GlobalDatabase Load() {
if (!File.Exists(FilePath)) {
return new GlobalDatabase();
private string FilePath;
internal static GlobalDatabase Load(string filePath) {
if (string.IsNullOrEmpty(filePath)) {
return null;
}
if (!File.Exists(filePath)) {
return new GlobalDatabase(filePath);
}
GlobalDatabase globalDatabase;
try {
globalDatabase = JsonConvert.DeserializeObject<GlobalDatabase>(File.ReadAllText(FilePath));
globalDatabase = JsonConvert.DeserializeObject<GlobalDatabase>(File.ReadAllText(filePath));
} catch (Exception e) {
Logging.LogGenericException(e);
return null;
}
if (globalDatabase == null) {
return null;
}
globalDatabase.FilePath = filePath;
return globalDatabase;
}
// This constructor is used when creating new database
private GlobalDatabase(string filePath) {
if (string.IsNullOrEmpty(filePath)) {
throw new ArgumentNullException("filePath");
}
FilePath = filePath;
Save();
}
// This constructor is used only by deserializer
private GlobalDatabase() { }

View File

@@ -353,14 +353,14 @@ namespace ArchiSteamFarm {
}
private static void InitServices() {
GlobalConfig = GlobalConfig.Load();
GlobalConfig = GlobalConfig.Load(Path.Combine(ConfigDirectory, GlobalConfigFile));
if (GlobalConfig == null) {
Logging.LogGenericError("Global config could not be loaded, please make sure that ASF.json exists and is valid!");
Thread.Sleep(5000);
Exit(1);
}
GlobalDatabase = GlobalDatabase.Load();
GlobalDatabase = GlobalDatabase.Load(Path.Combine(ConfigDirectory, GlobalDatabaseFile));
if (GlobalDatabase == null) {
Logging.LogGenericError("Global database could not be loaded!");
Thread.Sleep(5000);

View File

@@ -23,6 +23,7 @@
*/
using SteamAuth;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@@ -49,7 +50,7 @@ namespace ArchiSteamFarm {
internal Trading(Bot bot) {
if (bot == null) {
return;
throw new ArgumentNullException("bot");
}
Bot = bot;

View File

@@ -65,7 +65,7 @@ namespace ArchiSteamFarm {
internal WebBrowser(string identifier) {
if (string.IsNullOrEmpty(identifier)) {
return;
throw new ArgumentNullException("identifier");
}
Identifier = identifier;

View File

@@ -38,6 +38,10 @@ namespace ConfigGenerator {
}
protected ASFConfig(string filePath) : this() {
if (string.IsNullOrEmpty(filePath)) {
throw new ArgumentNullException("filePath");
}
FilePath = filePath;
}

View File

@@ -128,7 +128,10 @@ namespace ConfigGenerator {
private BotConfig() { }
private BotConfig(string filePath) : base(filePath) {
FilePath = filePath;
if (string.IsNullOrEmpty(filePath)) {
throw new ArgumentNullException("filePath");
}
GamesPlayedWhileIdle.Add(0);
Save();
}

View File

@@ -31,7 +31,7 @@ namespace ConfigGenerator {
internal EnhancedPropertyGrid(ASFConfig config) {
if (config == null) {
return;
throw new ArgumentNullException("config");
}
ASFConfig = config;

View File

@@ -170,7 +170,10 @@ namespace ConfigGenerator {
private GlobalConfig() { }
private GlobalConfig(string filePath) : base(filePath) {
FilePath = filePath;
if (string.IsNullOrEmpty(filePath)) {
throw new ArgumentNullException("filePath");
}
Blacklist.AddRange(GlobalBlacklist);
Save();
}

View File

@@ -26,6 +26,7 @@ using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace ConfigGenerator {
@@ -121,6 +122,9 @@ namespace ConfigGenerator {
return;
}
// Get rid of any potential whitespaces in bot name
input = Regex.Replace(input, @"\s+", "");
configPage.ASFConfig.Rename(input);
configPage.RefreshText();
} else if (e.TabPage == NewTab) {
@@ -144,6 +148,9 @@ namespace ConfigGenerator {
return;
}
// Get rid of any potential whitespaces in bot name
input = Regex.Replace(input, @"\s+", "");
foreach (ASFConfig config in ASFConfig.ASFConfigs) {
if (Path.GetFileNameWithoutExtension(config.FilePath).Equals(input)) {
Logging.LogGenericError("Bot with such name exists already!");

View File

@@ -35,7 +35,7 @@ namespace ConfigGenerator {
BotEnabled,
BotReady,
GlobalConfigOpened,
GlobalConfigReady,
GlobalConfigReady
}
internal static bool Enabled { get; set; } = true;
@@ -61,20 +61,20 @@ namespace ConfigGenerator {
Logging.LogGenericInfo("Please click the help button to continue.");
break;
case EPhase.Help:
Logging.LogGenericInfo("That's right! On ASF wiki you can find detailed help about every config property you're going to configure in a moment.");
Logging.LogGenericInfo("Well done! On ASF wiki you can find detailed help about every config property you're going to configure in a moment.");
break;
case EPhase.HelpFinished:
Logging.LogGenericInfo("Alright, let's start configuring our ASF. Click on the plus [+] button to add your first steam account to ASF!");
break;
case EPhase.BotNickname:
Logging.LogGenericInfo("That's right! You'll be asked for your bot name now. A good example would be a nickname that you're using for the steam account you're configuring right now, or any other name of your choice which will be easy for you to connect with bot instance that is being configured.");
Logging.LogGenericInfo("Good job! You'll be asked for your bot name now. A good example would be a nickname that you're using for the steam account you're configuring right now, or any other name of your choice which will be easy for you to connect with bot instance that is being configured. Please don't use spaces in the name.");
break;
case EPhase.BotNicknameFinished:
Logging.LogGenericInfo("As you can see your bot config is now ready to configure!");
Logging.LogGenericInfo("First thing that you want to do is switching \"Enabled\" property from False to True, try it!");
break;
case EPhase.BotEnabled:
Logging.LogGenericInfo("That's right! Now your bot instance is enabled. You need to configure at least 2 more config properties - \"SteamLogin\" and \"SteamPassword\". The tutorial will continue after you're done with it. Remember to visit ASF wiki by clicking the help icon if you're unsure how given property should be configured!");
Logging.LogGenericInfo("Excellent! Now your bot instance is enabled. You need to configure at least 2 more config properties - \"SteamLogin\" and \"SteamPassword\". The tutorial will continue after you're done with it. Remember to visit ASF wiki by clicking the help icon if you're unsure how given property should be configured!");
break;
case EPhase.BotReady:
Logging.LogGenericInfo("If the data you put is proper, then your bot is ready to run! We need to do only one more thing now. Visit global ASF config, which is labelled as \"ASF\" on your config tab.");
@@ -86,7 +86,7 @@ namespace ConfigGenerator {
case EPhase.GlobalConfigReady:
Logging.LogGenericInfo("Your ASF is now ready! Simply launch ASF process by double-clicking ASF.exe binary and if you did everything properly, you should now notice that ASF logs in on your account and starts farming. If you have SteamGuard or 2FA authorization enabled, ASF will ask you for that once");
Logging.LogGenericInfo("Congratulations! You've done everything that is needed in order to make ASF \"work\". I highly recommend reading the wiki now, as ASF offers some really neat features for you to configure, such as offline farming or deciding upon most efficient cards farming algorithm.");
Logging.LogGenericInfo("If you'd like to add another steam account for farming, simply click the plus [+] button and add another instance. You can also rename bots and remove them with 2 other buttons. Good luck!");
Logging.LogGenericInfo("If you'd like to add another steam account for farming, simply click the plus [+] button and add another instance. You can also rename bots [~] and remove them [-]. Good luck!");
Enabled = false;
break;
}