Work on GUI

There is still a long way till it's done...
This commit is contained in:
JustArchi
2016-08-02 08:50:31 +02:00
parent 97224aafaf
commit 612abef327
15 changed files with 13727 additions and 66 deletions

34
GUI/Form1.Designer.cs generated
View File

@@ -1,34 +0,0 @@
namespace GUI {
partial class Form1 {
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Text = "Form1";
}
#endregion
}
}

View File

@@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GUI {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
}
}

View File

@@ -48,6 +48,10 @@
<HintPath>..\packages\NLog.4.4.0-betaV15\lib\net45\NLog.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NLog.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.Windows.Forms.4.2.3\lib\net35\NLog.Windows.Forms.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="protobuf-net, Version=2.0.0.668, Culture=neutral, PublicKeyToken=257b51d87d2e4d67, processorArchitecture=MSIL">
<HintPath>..\packages\protobuf-net.2.0.0.668\lib\net40\protobuf-net.dll</HintPath>
<Private>True</Private>
@@ -129,9 +133,6 @@
<Compile Include="..\ArchiSteamFarm\JSON\Steam.cs">
<Link>JSON\Steam.cs</Link>
</Compile>
<Compile Include="..\ArchiSteamFarm\Logging.cs">
<Link>Logging.cs</Link>
</Compile>
<Compile Include="..\ArchiSteamFarm\MobileAuthenticator.cs">
<Link>MobileAuthenticator.cs</Link>
</Compile>
@@ -147,20 +148,21 @@
<Compile Include="..\ArchiSteamFarm\Utilities.cs">
<Link>Utilities.cs</Link>
</Compile>
<Compile Include="..\ArchiSteamFarm\WCF.cs">
<Link>WCF.cs</Link>
</Compile>
<Compile Include="..\ArchiSteamFarm\WebBrowser.cs">
<Link>WebBrowser.cs</Link>
</Compile>
<Compile Include="Form1.cs">
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
<Compile Include="MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="Logging.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>

187
GUI/Logging.cs Normal file
View File

@@ -0,0 +1,187 @@
/*
_ _ _ ____ _ _____
/ \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
/ _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
/ ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
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 System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using NLog;
using NLog.Config;
using NLog.Targets;
using NLog.Windows.Forms;
// ReSharper disable once CheckNamespace
namespace ArchiSteamFarm {
internal static class Logging {
private const string LayoutMessage = @"${message}${onexception:inner= ${exception:format=toString,Data}}";
private const string GeneralLayout = @"${date:format=yyyy-MM-dd HH\:mm\:ss}|${level:uppercase=true}|" + LayoutMessage;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private static bool IsUsingCustomConfiguration;
internal static void InitCoreLoggers() {
if (LogManager.Configuration == null) {
LogManager.Configuration = new LoggingConfiguration();
} else {
// User provided custom NLog config, but we still need to define our own logger
IsUsingCustomConfiguration = true;
if (LogManager.Configuration.AllTargets.Any(target => target is MessageBoxTarget)) {
return;
}
}
MessageBoxTarget messageBoxTarget = new MessageBoxTarget {
Name = "MessageBox",
Layout = GeneralLayout
};
LogManager.Configuration.AddTarget(messageBoxTarget);
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Fatal, messageBoxTarget));
LogManager.ReconfigExistingLoggers();
}
internal static void InitEnhancedLoggers() {
if (IsUsingCustomConfiguration) {
return;
}
FileTarget fileTarget = new FileTarget("File") {
DeleteOldFileOnStartup = true,
FileName = SharedInfo.LogFile,
Layout = GeneralLayout
};
LogManager.Configuration.AddTarget(fileTarget);
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, fileTarget));
LogManager.ReconfigExistingLoggers();
}
internal static void InitFormLogger() {
RichTextBoxTarget formControlTarget = new RichTextBoxTarget {
AutoScroll = true,
ControlName = "LogTextBox",
FormName = "MainForm",
Layout = GeneralLayout,
MaxLines = byte.MaxValue,
Name = "RichTextBox"
};
formControlTarget.RowColoringRules.Add(new RichTextBoxRowColoringRule("level >= LogLevel.Error", "Red", "Black"));
formControlTarget.RowColoringRules.Add(new RichTextBoxRowColoringRule("level >= LogLevel.Warn", "Yellow", "Black"));
LogManager.Configuration.AddTarget(formControlTarget);
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, formControlTarget));
LogManager.ReconfigExistingLoggers();
}
internal static void LogGenericError(string message, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) {
if (string.IsNullOrEmpty(message)) {
LogNullError(nameof(message), botName);
return;
}
Logger.Error($"{botName}|{previousMethodName}() {message}");
}
internal static void LogGenericException(Exception exception, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) {
if (exception == null) {
LogNullError(nameof(exception), botName);
return;
}
Logger.Error(exception, $"{botName}|{previousMethodName}()");
}
internal static void LogFatalException(Exception exception, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) {
if (exception == null) {
LogNullError(nameof(exception), botName);
return;
}
Logger.Fatal(exception, $"{botName}|{previousMethodName}()");
// If LogManager has been initialized already, don't do anything else
if (LogManager.Configuration != null) {
return;
}
// Otherwise, if we run into fatal exception before logging module is even initialized, write exception to classic log file
File.WriteAllText(SharedInfo.LogFile, DateTime.Now + " ASF V" + SharedInfo.Version + " has run into fatal exception before core logging module was even able to initialize!" + Environment.NewLine);
while (true) {
File.AppendAllText(SharedInfo.LogFile, "[!] EXCEPTION: " + previousMethodName + "() " + exception.Message + Environment.NewLine + "StackTrace:" + Environment.NewLine + exception.StackTrace);
if (exception.InnerException != null) {
exception = exception.InnerException;
continue;
}
break;
}
}
internal static void LogGenericWarning(string message, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) {
if (string.IsNullOrEmpty(message)) {
LogNullError(nameof(message), botName);
return;
}
Logger.Warn($"{botName}|{previousMethodName}() {message}");
}
internal static void LogGenericInfo(string message, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) {
if (string.IsNullOrEmpty(message)) {
LogNullError(nameof(message), botName);
return;
}
Logger.Info($"{botName}|{previousMethodName}() {message}");
}
[SuppressMessage("ReSharper", "ExplicitCallerInfoArgument")]
internal static void LogNullError(string nullObjectName, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) {
if (string.IsNullOrEmpty(nullObjectName)) {
return;
}
LogGenericError(nullObjectName + " is null!", botName, previousMethodName);
}
[Conditional("DEBUG")]
[SuppressMessage("ReSharper", "UnusedMember.Global")]
internal static void LogGenericDebug(string message, string botName = SharedInfo.ASF, [CallerMemberName] string previousMethodName = null) {
if (string.IsNullOrEmpty(message)) {
LogNullError(nameof(message), botName);
return;
}
Logger.Debug($"{botName}|{previousMethodName}() {message}");
}
}
}

106
GUI/MainForm.Designer.cs generated Normal file
View File

@@ -0,0 +1,106 @@
namespace GUI {
internal sealed partial class MainForm {
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.BotListView = new System.Windows.Forms.ListView();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.MinimizeIcon = new System.Windows.Forms.NotifyIcon(this.components);
this.LogTextBox = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// BotListView
//
this.BotListView.Dock = System.Windows.Forms.DockStyle.Left;
this.BotListView.GridLines = true;
this.BotListView.Location = new System.Drawing.Point(0, 24);
this.BotListView.MultiSelect = false;
this.BotListView.Name = "BotListView";
this.BotListView.ShowGroups = false;
this.BotListView.Size = new System.Drawing.Size(150, 705);
this.BotListView.TabIndex = 0;
this.BotListView.UseCompatibleStateImageBehavior = false;
//
// menuStrip1
//
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(1008, 24);
this.menuStrip1.TabIndex = 1;
this.menuStrip1.Text = "menuStrip1";
//
// MinimizeIcon
//
this.MinimizeIcon.BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info;
this.MinimizeIcon.BalloonTipText = "ASF will keep working in the background...";
this.MinimizeIcon.BalloonTipTitle = "ASF";
this.MinimizeIcon.Icon = ((System.Drawing.Icon)(resources.GetObject("MinimizeIcon.Icon")));
this.MinimizeIcon.Text = "MinimizeIcon";
this.MinimizeIcon.Visible = true;
this.MinimizeIcon.DoubleClick += new System.EventHandler(this.MinimizeIcon_DoubleClick);
//
// LogTextBox
//
this.LogTextBox.BackColor = System.Drawing.Color.Black;
this.LogTextBox.CausesValidation = false;
this.LogTextBox.Dock = System.Windows.Forms.DockStyle.Bottom;
this.LogTextBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
this.LogTextBox.ForeColor = System.Drawing.Color.White;
this.LogTextBox.Location = new System.Drawing.Point(150, 529);
this.LogTextBox.Name = "LogTextBox";
this.LogTextBox.ReadOnly = true;
this.LogTextBox.Size = new System.Drawing.Size(858, 200);
this.LogTextBox.TabIndex = 2;
this.LogTextBox.Text = "";
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1008, 729);
this.Controls.Add(this.LogTextBox);
this.Controls.Add(this.BotListView);
this.Controls.Add(this.menuStrip1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MainMenuStrip = this.menuStrip1;
this.Name = "MainForm";
this.Text = "ArchiSteamFarm";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.MainForm_FormClosed);
this.Load += new System.EventHandler(this.MainForm_Load);
this.Resize += new System.EventHandler(this.MainForm_Resize);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ListView BotListView;
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.NotifyIcon MinimizeIcon;
private System.Windows.Forms.RichTextBox LogTextBox;
}
}

57
GUI/MainForm.cs Normal file
View File

@@ -0,0 +1,57 @@
using System;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using ArchiSteamFarm;
namespace GUI {
internal sealed partial class MainForm : Form {
internal MainForm() {
InitializeComponent();
}
private void MainForm_Resize(object sender, EventArgs e) {
switch (WindowState) {
case FormWindowState.Minimized:
MinimizeIcon.Visible = true;
MinimizeIcon.ShowBalloonTip(5000);
break;
case FormWindowState.Normal:
MinimizeIcon.Visible = false;
break;
}
}
private void MainForm_Load(object sender, EventArgs e) {
Logging.InitFormLogger();
if (!Directory.Exists(SharedInfo.ConfigDirectory)) {
Logging.LogGenericError("Config directory could not be found!");
Environment.Exit(1);
}
ASF.CheckForUpdate().Wait();
// Before attempting to connect, initialize our list of CMs
Bot.InitializeCMs(Program.GlobalDatabase.CellID, Program.GlobalDatabase.ServerListProvider);
foreach (string botName in Directory.EnumerateFiles(SharedInfo.ConfigDirectory, "*.json").Select(Path.GetFileNameWithoutExtension)) {
switch (botName) {
case SharedInfo.ASF:
case "example":
case "minimal":
continue;
}
Bot bot = new Bot(botName);
}
}
private void MinimizeIcon_DoubleClick(object sender, EventArgs e) {
Show();
WindowState = FormWindowState.Normal;
}
private void MainForm_FormClosed(object sender, FormClosedEventArgs e) => Program.InitShutdownSequence();
}
}

12474
GUI/MainForm.resx Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,10 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using GUI;
@@ -15,26 +21,135 @@ namespace ArchiSteamFarm {
return null;
}
internal static void Exit() {
internal static void Exit(int exitCode = 0) {
InitShutdownSequence();
Environment.Exit(exitCode);
}
internal static void Restart() {
InitShutdownSequence();
try {
Process.Start(Assembly.GetEntryAssembly().Location, string.Join(" ", Environment.GetCommandLineArgs().Skip(1)));
} catch (Exception e) {
Logging.LogGenericException(e);
}
Environment.Exit(0);
}
internal static void OnBotShutdown() {
}
internal static void InitShutdownSequence() {
foreach (Bot bot in Bot.Bots.Values.Where(bot => bot.KeepRunning)) {
bot.Stop();
}
}
private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args) {
if (args?.ExceptionObject == null) {
Logging.LogNullError(nameof(args) + " || " + nameof(args.ExceptionObject));
return;
}
Logging.LogFatalException((Exception) args.ExceptionObject);
}
private static void UnobservedTaskExceptionHandler(object sender, UnobservedTaskExceptionEventArgs args) {
if (args?.Exception == null) {
Logging.LogNullError(nameof(args) + " || " + nameof(args.Exception));
return;
}
Logging.LogFatalException(args.Exception);
}
private static void InitServices() {
string globalConfigFile = Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalConfigFileName);
GlobalConfig = GlobalConfig.Load(globalConfigFile);
if (GlobalConfig == null) {
Logging.LogGenericError("Global config could not be loaded, please make sure that " + globalConfigFile + " exists and is valid!");
Exit(1);
}
string globalDatabaseFile = Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalDatabaseFileName);
GlobalDatabase = GlobalDatabase.Load(globalDatabaseFile);
if (GlobalDatabase == null) {
Logging.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(SharedInfo.ASF);
}
private static void Init() {
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;
TaskScheduler.UnobservedTaskException += UnobservedTaskExceptionHandler;
Logging.InitCoreLoggers();
if (!Runtime.IsRuntimeSupported()) {
Logging.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);
if (!string.IsNullOrEmpty(homeDirectory)) {
Directory.SetCurrentDirectory(homeDirectory);
// Allow loading configs from source tree if it's a debug build
if (Debugging.IsDebugBuild) {
// Common structure is bin/(x64/)Debug/ArchiSteamFarm.exe, so we allow up to 4 directories up
for (byte i = 0; i < 4; i++) {
Directory.SetCurrentDirectory("..");
if (!Directory.Exists(SharedInfo.ASFDirectory)) {
continue;
}
Directory.SetCurrentDirectory(SharedInfo.ASFDirectory);
break;
}
// If config directory doesn't exist after our adjustment, abort all of that
if (!Directory.Exists(SharedInfo.ConfigDirectory)) {
Directory.SetCurrentDirectory(homeDirectory);
}
}
}
InitServices();
// If debugging is on, we prepare debug directory prior to running
if (GlobalConfig.Debug) {
if (Directory.Exists(SharedInfo.DebugDirectory)) {
Directory.Delete(SharedInfo.DebugDirectory, true);
Thread.Sleep(1000); // Dirty workaround giving Windows some time to sync
}
Directory.CreateDirectory(SharedInfo.DebugDirectory);
SteamKit2.DebugLog.AddListener(new Debugging.DebugListener(Path.Combine(SharedInfo.DebugDirectory, "debug.txt")));
SteamKit2.DebugLog.Enabled = true;
}
Logging.InitEnhancedLoggers();
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
private static void Main() {
Init();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Application.Run(new MainForm());
}
}
}

View File

@@ -3,6 +3,7 @@
<package id="HtmlAgilityPack" version="1.4.9.5" targetFramework="net461" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net461" />
<package id="NLog" version="4.4.0-betaV15" targetFramework="net461" />
<package id="NLog.Windows.Forms" version="4.2.3" targetFramework="net461" />
<package id="protobuf-net" version="2.0.0.668" targetFramework="net461" />
<package id="SteamKit2" version="1.8.0" targetFramework="net461" />
</packages>