Starts looking good

This commit is contained in:
JustArchi 2016-03-20 06:41:12 +01:00
parent 4bd48c399a
commit 6de721089c
13 changed files with 6458 additions and 88 deletions

View file

@ -21,6 +21,7 @@
"AcceptConfirmationsPeriod": 0,
"CustomGamePlayedWhileIdle": null,
"GamesPlayedWhileIdle": [
0,
0
]
}

View file

@ -1,5 +1,26 @@
{
"Enabled": false,
"StartOnLaunch": true,
"SteamLogin": null,
"SteamPassword": null
"SteamPassword": null,
"SteamParentalPIN": "0",
"SteamApiKey": null,
"SteamMasterID": 0,
"SteamMasterClanID": 0,
"CardDropsRestricted": false,
"DismissInventoryNotifications": true,
"FarmOffline": false,
"HandleOfflineMessages": false,
"ForwardKeysToOtherBots": false,
"DistributeKeys": false,
"UseAsfAsMobileAuthenticator": false,
"ShutdownOnFarmingFinished": false,
"SendOnFarmingFinished": false,
"SteamTradeToken": null,
"SendTradePeriod": 0,
"AcceptConfirmationsPeriod": 0,
"CustomGamePlayedWhileIdle": null,
"GamesPlayedWhileIdle": [
0
]
}

View file

@ -0,0 +1,30 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
namespace ConfigGenerator {
internal class ASFConfig {
internal static List<ASFConfig> ASFConfigs = new List<ASFConfig>();
internal string FilePath { get; set; }
protected ASFConfig() {
ASFConfigs.Add(this);
}
protected ASFConfig(string filePath) : base() {
FilePath = filePath;
}
internal virtual void Save() {
lock (FilePath) {
try {
File.WriteAllText(FilePath, JsonConvert.SerializeObject(this, Formatting.Indented));
} catch (Exception e) {
Logging.LogGenericException(e);
}
}
}
}
}

View file

@ -0,0 +1,129 @@
/*
_ _ _ ____ _ _____
/ \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
/ _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
/ ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
Copyright 2015-2016 Łukasz "JustArchi" Domeradzki
Contact: JustArchi@JustArchi.net
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
namespace ConfigGenerator {
internal sealed class BotConfig : ASFConfig {
[JsonProperty(Required = Required.DisallowNull)]
public bool Enabled { get; set; } = false;
[JsonProperty(Required = Required.DisallowNull)]
public bool StartOnLaunch { get; set; } = true;
[JsonProperty]
public string SteamLogin { get; set; } = null;
[JsonProperty]
public string SteamPassword { get; set; } = null;
[JsonProperty]
public string SteamParentalPIN { get; set; } = "0";
[JsonProperty]
public string SteamApiKey { get; set; } = null;
[JsonProperty(Required = Required.DisallowNull)]
public ulong SteamMasterID { get; set; } = 0;
[JsonProperty(Required = Required.DisallowNull)]
public ulong SteamMasterClanID { get; set; } = 0;
[JsonProperty(Required = Required.DisallowNull)]
public bool CardDropsRestricted { get; set; } = false;
[JsonProperty(Required = Required.DisallowNull)]
public bool DismissInventoryNotifications { get; set; } = true;
[JsonProperty(Required = Required.DisallowNull)]
public bool FarmOffline { get; set; } = false;
[JsonProperty(Required = Required.DisallowNull)]
public bool HandleOfflineMessages { get; set; } = false;
[JsonProperty(Required = Required.DisallowNull)]
public bool ForwardKeysToOtherBots { get; set; } = false;
[JsonProperty(Required = Required.DisallowNull)]
public bool DistributeKeys { get; set; } = false;
[JsonProperty(Required = Required.DisallowNull)]
public bool UseAsfAsMobileAuthenticator { get; set; } = false;
[JsonProperty(Required = Required.DisallowNull)]
public bool ShutdownOnFarmingFinished { get; set; } = false;
[JsonProperty(Required = Required.DisallowNull)]
public bool SendOnFarmingFinished { get; set; } = false;
[JsonProperty]
public string SteamTradeToken { get; set; } = null;
[JsonProperty(Required = Required.DisallowNull)]
public byte SendTradePeriod { get; set; } = 0;
[JsonProperty(Required = Required.DisallowNull)]
public byte AcceptConfirmationsPeriod { get; set; } = 0;
[JsonProperty]
public string CustomGamePlayedWhileIdle { get; set; } = null;
[JsonProperty(Required = Required.DisallowNull)]
public List<uint> GamesPlayedWhileIdle { get; set; } = new List<uint>();
internal static BotConfig Load(string filePath) {
if (string.IsNullOrEmpty(filePath)) {
return null;
}
if (!File.Exists(filePath)) {
return new BotConfig(filePath);
}
BotConfig botConfig;
try {
botConfig = JsonConvert.DeserializeObject<BotConfig>(File.ReadAllText(filePath));
} catch (Exception e) {
Logging.LogGenericException(e);
return new BotConfig(filePath);
}
botConfig.FilePath = filePath;
return botConfig;
}
// This constructor is used only by deserializer
private BotConfig() : base() { }
private BotConfig(string filePath) : base(filePath) {
FilePath = filePath;
GamesPlayedWhileIdle.Add(0);
}
}
}

View file

@ -52,12 +52,14 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ASFConfig.cs" />
<Compile Include="BotConfig.cs" />
<Compile Include="EnhancedPropertyGrid.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Debugging.cs" />
<Compile Include="GlobalConfig.cs" />
<Compile Include="GlobalConfigPage.cs">
<Compile Include="ConfigPage.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Logging.cs" />
@ -69,8 +71,8 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="GlobalConfigPage.resx">
<DependentUpon>GlobalConfigPage.cs</DependentUpon>
<EmbeddedResource Include="ConfigPage.resx">
<DependentUpon>ConfigPage.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>

View file

@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ConfigGenerator {
internal class ConfigPage : TabPage {
private EnhancedPropertyGrid EnhancedPropertyGrid;
private Button LoadButton, SaveButton;
internal ConfigPage(ASFConfig config) : base() {
if (config == null) {
return;
}
Text = Path.GetFileNameWithoutExtension(config.FilePath);
EnhancedPropertyGrid = new EnhancedPropertyGrid(config);
Controls.Add(EnhancedPropertyGrid);
Panel panel = new Panel() {
Height = 20,
Dock = DockStyle.Bottom,
};
LoadButton = new Button() {
Dock = DockStyle.Left,
Text = "Load"
};
panel.Controls.Add(LoadButton);
SaveButton = new Button() {
Dock = DockStyle.Right,
Text = "Save"
};
SaveButton.Click += SaveButton_Click;
panel.Controls.Add(SaveButton);
Controls.Add(panel);
}
private async void SaveButton_Click(object sender, EventArgs e) {
if (sender == null || e == null) {
return;
}
SaveButton.Enabled = false;
List<Task> tasks = new List<Task>(ASFConfig.ASFConfigs.Count);
foreach (ASFConfig config in ASFConfig.ASFConfigs) {
tasks.Add(Task.Run(() => config.Save()));
config.Save();
}
await Task.WhenAll(tasks);
SaveButton.Enabled = true;
}
private void InitializeComponent() {
SuspendLayout();
ResumeLayout(false);
}
}
}

View file

@ -2,15 +2,12 @@
namespace ConfigGenerator {
internal sealed class EnhancedPropertyGrid : PropertyGrid {
private GlobalConfig GlobalConfig;
internal EnhancedPropertyGrid(GlobalConfig globalConfig) : base() {
if (globalConfig == null) {
internal EnhancedPropertyGrid(ASFConfig config) : base() {
if (config == null) {
return;
}
GlobalConfig = globalConfig;
SelectedObject = globalConfig;
SelectedObject = config;
Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
Dock = DockStyle.Fill;
HelpVisible = false;

View file

@ -29,7 +29,7 @@ using System.IO;
using System.Net.Sockets;
namespace ConfigGenerator {
internal sealed class GlobalConfig {
internal sealed class GlobalConfig : ASFConfig {
internal enum EUpdateChannel : byte {
Unknown,
Stable,
@ -97,8 +97,6 @@ namespace ConfigGenerator {
[JsonProperty(Required = Required.DisallowNull)]
public List<uint> Blacklist { get; set; } = new List<uint>();
private string FilePath;
internal static GlobalConfig Load(string filePath) {
if (string.IsNullOrEmpty(filePath)) {
return null;
@ -113,7 +111,7 @@ namespace ConfigGenerator {
globalConfig = JsonConvert.DeserializeObject<GlobalConfig>(File.ReadAllText(filePath));
} catch (Exception e) {
Logging.LogGenericException(e);
return null;
return new GlobalConfig(filePath);
}
globalConfig.FilePath = filePath;
@ -133,20 +131,10 @@ namespace ConfigGenerator {
return globalConfig;
}
internal void Save() {
lock (FilePath) {
try {
File.WriteAllText(FilePath, JsonConvert.SerializeObject(this, Formatting.Indented));
} catch (Exception e) {
Logging.LogGenericException(e);
}
}
}
// This constructor is used only by deserializer
private GlobalConfig() { }
private GlobalConfig() : base() { }
private GlobalConfig(string filePath) {
private GlobalConfig(string filePath) : base(filePath) {
FilePath = filePath;
Blacklist.AddRange(GlobalBlacklist);
}

View file

@ -1,51 +0,0 @@
using System.IO;
using System.Windows.Forms;
namespace ConfigGenerator {
internal sealed class GlobalConfigPage : TabPage {
internal GlobalConfig GlobalConfig { get; private set; }
private EnhancedPropertyGrid EnhancedPropertyGrid;
internal GlobalConfigPage(string filePath) : base() {
if (string.IsNullOrEmpty(filePath)) {
return;
}
GlobalConfig = GlobalConfig.Load(filePath);
if (GlobalConfig == null) {
Logging.LogNullError("GlobalConfig");
return;
}
Text = Path.GetFileNameWithoutExtension(filePath);
EnhancedPropertyGrid = new EnhancedPropertyGrid(GlobalConfig);
Controls.Add(EnhancedPropertyGrid);
Panel panel = new Panel() {
Height = 20,
Dock = DockStyle.Bottom,
};
panel.Controls.Add(new Button() {
Dock = DockStyle.Left,
Text = "Load"
});
panel.Controls.Add(new Button() {
Dock = DockStyle.Right,
Text = "Save"
});
Controls.Add(panel);
}
private void InitializeComponent() {
this.SuspendLayout();
this.ResumeLayout(false);
}
}
}

View file

@ -23,14 +23,15 @@
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.MenuPanel = new System.Windows.Forms.MenuStrip();
this.FileMenu = new System.Windows.Forms.ToolStripMenuItem();
this.FileMenuHelp = new System.Windows.Forms.ToolStripMenuItem();
this.FileMenuExit = new System.Windows.Forms.ToolStripMenuItem();
this.BotMenu = new System.Windows.Forms.ToolStripMenuItem();
this.BotMenuNew = new System.Windows.Forms.ToolStripMenuItem();
this.BotMenuDelete = new System.Windows.Forms.ToolStripMenuItem();
this.MainTab = new System.Windows.Forms.TabControl();
this.FileMenuExit = new System.Windows.Forms.ToolStripMenuItem();
this.MenuPanel.SuspendLayout();
this.SuspendLayout();
//
@ -57,10 +58,17 @@
// FileMenuHelp
//
this.FileMenuHelp.Name = "FileMenuHelp";
this.FileMenuHelp.Size = new System.Drawing.Size(152, 22);
this.FileMenuHelp.Size = new System.Drawing.Size(99, 22);
this.FileMenuHelp.Text = "Help";
this.FileMenuHelp.Click += new System.EventHandler(this.FileMenuHelp_Click);
//
// FileMenuExit
//
this.FileMenuExit.Name = "FileMenuExit";
this.FileMenuExit.Size = new System.Drawing.Size(99, 22);
this.FileMenuExit.Text = "Exit";
this.FileMenuExit.Click += new System.EventHandler(this.FileMenuExit_Click);
//
// BotMenu
//
this.BotMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -95,13 +103,6 @@
this.MainTab.Size = new System.Drawing.Size(760, 522);
this.MainTab.TabIndex = 1;
//
// FileMenuExit
//
this.FileMenuExit.Name = "FileMenuExit";
this.FileMenuExit.Size = new System.Drawing.Size(152, 22);
this.FileMenuExit.Text = "Exit";
this.FileMenuExit.Click += new System.EventHandler(this.FileMenuExit_Click);
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -109,9 +110,10 @@
this.ClientSize = new System.Drawing.Size(784, 561);
this.Controls.Add(this.MainTab);
this.Controls.Add(this.MenuPanel);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MainMenuStrip = this.MenuPanel;
this.Name = "MainForm";
this.Text = "Form1";
this.Text = "ASF Config Generator";
this.Load += new System.EventHandler(this.MainForm_Load);
this.MenuPanel.ResumeLayout(false);
this.MenuPanel.PerformLayout();

View file

@ -46,7 +46,16 @@ namespace ConfigGenerator {
return;
}
MainTab.TabPages.Add(new GlobalConfigPage(Path.Combine(Program.ConfigDirectory, Program.GlobalConfigFile)));
MainTab.TabPages.Add(new ConfigPage(GlobalConfig.Load(Path.Combine(Program.ConfigDirectory, Program.GlobalConfigFile))));
foreach (var configFile in Directory.EnumerateFiles(Program.ConfigDirectory, "*.json")) {
string botName = Path.GetFileNameWithoutExtension(configFile);
if (botName.Equals(Program.ASF)) {
continue;
}
MainTab.TabPages.Add(new ConfigPage(BotConfig.Load(configFile)));
}
}
}
}

File diff suppressed because it is too large Load diff