diff --git a/GUI/Debugging.cs b/GUI/Debugging.cs new file mode 100644 index 000000000..653e898ff --- /dev/null +++ b/GUI/Debugging.cs @@ -0,0 +1,35 @@ +/* + _ _ _ ____ _ _____ + / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ + / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ + / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | +/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| + + 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. + +*/ + +namespace GUI { + internal static class Debugging { +#if DEBUG + internal static readonly bool IsDebugBuild = true; +#else + internal static readonly bool IsDebugBuild = false; +#endif + + internal static bool IsReleaseBuild => !IsDebugBuild; + } +} diff --git a/GUI/Form1.cs b/GUI/Form1.cs index db3af0aac..90b06579e 100644 --- a/GUI/Form1.cs +++ b/GUI/Form1.cs @@ -8,6 +8,9 @@ Copyright 2015-2016 Florian "KlappPC" Lang Contact: ichhoeremusik@gmx.net + 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 @@ -23,9 +26,9 @@ */ using System; -using System.Drawing; using System.Windows.Forms; using System.ServiceModel; +using System.IO; namespace GUI { @@ -43,11 +46,16 @@ namespace GUI { InitializeComponent(); // So either the ASF.exe is in the same directory, or we assume development environment. - if (System.IO.File.Exists("ASF.exe")) { - proc = new ServerProcess("ASF.exe", "--server", textBox2); - } else { - proc = new ServerProcess("../../../ArchiSteamFarm/bin/Release/ArchiSteamFarm.exe", "--server", textBox2); + string ASF = "ASF.exE"; + if (!File.Exists(ASF)) { + ASF = "../../../ArchiSteamFarm/bin/" + (Debugging.IsDebugBuild ? "Debug" : "Release") + "/ArchiSteamFarm.exe2"; + if (!File.Exists(ASF)) { + Logging.LogGenericError("ASF binary could not be found!"); + Environment.Exit(1); + } } + + proc = new ServerProcess(ASF, "--server", textBox2); proc.Start(); } diff --git a/GUI/GUI.csproj b/GUI/GUI.csproj index f4d724bcb..011d01aca 100644 --- a/GUI/GUI.csproj +++ b/GUI/GUI.csproj @@ -63,6 +63,7 @@ + Form @@ -75,6 +76,7 @@ Form2.cs + diff --git a/GUI/Logging.cs b/GUI/Logging.cs new file mode 100644 index 000000000..e910236e6 --- /dev/null +++ b/GUI/Logging.cs @@ -0,0 +1,93 @@ +/* + _ _ _ ____ _ _____ + / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ + / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ + / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | +/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| + + 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.Runtime.CompilerServices; +using System.Windows.Forms; + +namespace GUI { + internal static class Logging { + internal static void LogGenericInfo(string message) { + if (string.IsNullOrEmpty(message)) { + return; + } + + MessageBox.Show(message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + internal static void LogGenericWTF(string message, [CallerMemberName] string previousMethodName = "") { + if (string.IsNullOrEmpty(message)) { + return; + } + + MessageBox.Show(previousMethodName + "() " + message, "WTF", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + internal static void LogGenericError(string message, [CallerMemberName] string previousMethodName = "") { + if (string.IsNullOrEmpty(message)) { + return; + } + + MessageBox.Show(previousMethodName + "() " + message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + internal static void LogGenericException(Exception exception, [CallerMemberName] string previousMethodName = "") { + if (exception == null) { + return; + } + + MessageBox.Show(previousMethodName + "() " + exception.Message + Environment.NewLine + exception.StackTrace, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); + + if (exception.InnerException != null) { + LogGenericException(exception.InnerException, previousMethodName); + } + } + + internal static void LogGenericWarning(string message, [CallerMemberName] string previousMethodName = "") { + if (string.IsNullOrEmpty(message)) { + return; + } + + MessageBox.Show(previousMethodName + "() " + message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + + internal static void LogNullError(string nullObjectName, [CallerMemberName] string previousMethodName = "") { + if (string.IsNullOrEmpty(nullObjectName)) { + return; + } + + LogGenericError(nullObjectName + " is null!", previousMethodName); + } + + [Conditional("DEBUG")] + internal static void LogGenericDebug(string message, [CallerMemberName] string previousMethodName = "") { + if (string.IsNullOrEmpty(message)) { + return; + } + + MessageBox.Show(previousMethodName + "() " + message, "Debug", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } +}