Skip to content

Commit

Permalink
Properly detect dev environment
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Apr 13, 2016
1 parent 2b28f01 commit 6efb07e
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 5 deletions.
35 changes: 35 additions & 0 deletions GUI/Debugging.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
_ _ _ ____ _ _____
/ \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
/ _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
/ ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
Copyright 2015-2016 Łukasz "JustArchi" Domeradzki
Contact: [email protected]
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;
}
}
18 changes: 13 additions & 5 deletions GUI/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ _ _ _ ____ _ _____
Copyright 2015-2016 Florian "KlappPC" Lang
Contact: [email protected]
Copyright 2015-2016 Łukasz "JustArchi" Domeradzki
Contact: [email protected]
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
Expand All @@ -23,9 +26,9 @@ limitations under the License.
*/

using System;
using System.Drawing;
using System.Windows.Forms;
using System.ServiceModel;
using System.IO;

namespace GUI {

Expand All @@ -43,11 +46,16 @@ public Form1() {
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();
}

Expand Down
2 changes: 2 additions & 0 deletions GUI/GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="Debugging.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
Expand All @@ -75,6 +76,7 @@
<Compile Include="Form2.Designer.cs">
<DependentUpon>Form2.cs</DependentUpon>
</Compile>
<Compile Include="Logging.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ServerProcess.cs" />
Expand Down
93 changes: 93 additions & 0 deletions GUI/Logging.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
_ _ _ ____ _ _____
/ \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
/ _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
/ ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
Copyright 2015-2016 Łukasz "JustArchi" Domeradzki
Contact: [email protected]
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);
}
}
}

0 comments on commit 6efb07e

Please sign in to comment.