Skip to content

Commit 6efb07e

Browse files
committed
Properly detect dev environment
1 parent 2b28f01 commit 6efb07e

File tree

4 files changed

+143
-5
lines changed

4 files changed

+143
-5
lines changed

GUI/Debugging.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
_ _ _ ____ _ _____
3+
/ \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
4+
/ _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
5+
/ ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
6+
/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
7+
8+
Copyright 2015-2016 Łukasz "JustArchi" Domeradzki
9+
10+
11+
Licensed under the Apache License, Version 2.0 (the "License");
12+
you may not use this file except in compliance with the License.
13+
You may obtain a copy of the License at
14+
15+
http://www.apache.org/licenses/LICENSE-2.0
16+
17+
Unless required by applicable law or agreed to in writing, software
18+
distributed under the License is distributed on an "AS IS" BASIS,
19+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20+
See the License for the specific language governing permissions and
21+
limitations under the License.
22+
23+
*/
24+
25+
namespace GUI {
26+
internal static class Debugging {
27+
#if DEBUG
28+
internal static readonly bool IsDebugBuild = true;
29+
#else
30+
internal static readonly bool IsDebugBuild = false;
31+
#endif
32+
33+
internal static bool IsReleaseBuild => !IsDebugBuild;
34+
}
35+
}

GUI/Form1.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ _ _ _ ____ _ _____
88
Copyright 2015-2016 Florian "KlappPC" Lang
99
1010
11+
Copyright 2015-2016 Łukasz "JustArchi" Domeradzki
12+
13+
1114
Licensed under the Apache License, Version 2.0 (the "License");
1215
you may not use this file except in compliance with the License.
1316
You may obtain a copy of the License at
@@ -23,9 +26,9 @@ limitations under the License.
2326
*/
2427

2528
using System;
26-
using System.Drawing;
2729
using System.Windows.Forms;
2830
using System.ServiceModel;
31+
using System.IO;
2932

3033
namespace GUI {
3134

@@ -43,11 +46,16 @@ public Form1() {
4346
InitializeComponent();
4447

4548
// So either the ASF.exe is in the same directory, or we assume development environment.
46-
if (System.IO.File.Exists("ASF.exe")) {
47-
proc = new ServerProcess("ASF.exe", "--server", textBox2);
48-
} else {
49-
proc = new ServerProcess("../../../ArchiSteamFarm/bin/Release/ArchiSteamFarm.exe", "--server", textBox2);
49+
string ASF = "ASF.exE";
50+
if (!File.Exists(ASF)) {
51+
ASF = "../../../ArchiSteamFarm/bin/" + (Debugging.IsDebugBuild ? "Debug" : "Release") + "/ArchiSteamFarm.exe2";
52+
if (!File.Exists(ASF)) {
53+
Logging.LogGenericError("ASF binary could not be found!");
54+
Environment.Exit(1);
55+
}
5056
}
57+
58+
proc = new ServerProcess(ASF, "--server", textBox2);
5159
proc.Start();
5260
}
5361

GUI/GUI.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
<Reference Include="System.Windows.Forms" />
6464
</ItemGroup>
6565
<ItemGroup>
66+
<Compile Include="Debugging.cs" />
6667
<Compile Include="Form1.cs">
6768
<SubType>Form</SubType>
6869
</Compile>
@@ -75,6 +76,7 @@
7576
<Compile Include="Form2.Designer.cs">
7677
<DependentUpon>Form2.cs</DependentUpon>
7778
</Compile>
79+
<Compile Include="Logging.cs" />
7880
<Compile Include="Program.cs" />
7981
<Compile Include="Properties\AssemblyInfo.cs" />
8082
<Compile Include="ServerProcess.cs" />

GUI/Logging.cs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
_ _ _ ____ _ _____
3+
/ \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
4+
/ _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
5+
/ ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
6+
/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
7+
8+
Copyright 2015-2016 Łukasz "JustArchi" Domeradzki
9+
10+
11+
Licensed under the Apache License, Version 2.0 (the "License");
12+
you may not use this file except in compliance with the License.
13+
You may obtain a copy of the License at
14+
15+
http://www.apache.org/licenses/LICENSE-2.0
16+
17+
Unless required by applicable law or agreed to in writing, software
18+
distributed under the License is distributed on an "AS IS" BASIS,
19+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20+
See the License for the specific language governing permissions and
21+
limitations under the License.
22+
23+
*/
24+
25+
using System;
26+
using System.Diagnostics;
27+
using System.Runtime.CompilerServices;
28+
using System.Windows.Forms;
29+
30+
namespace GUI {
31+
internal static class Logging {
32+
internal static void LogGenericInfo(string message) {
33+
if (string.IsNullOrEmpty(message)) {
34+
return;
35+
}
36+
37+
MessageBox.Show(message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
38+
}
39+
40+
internal static void LogGenericWTF(string message, [CallerMemberName] string previousMethodName = "") {
41+
if (string.IsNullOrEmpty(message)) {
42+
return;
43+
}
44+
45+
MessageBox.Show(previousMethodName + "() " + message, "WTF", MessageBoxButtons.OK, MessageBoxIcon.Error);
46+
}
47+
48+
internal static void LogGenericError(string message, [CallerMemberName] string previousMethodName = "") {
49+
if (string.IsNullOrEmpty(message)) {
50+
return;
51+
}
52+
53+
MessageBox.Show(previousMethodName + "() " + message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
54+
}
55+
56+
internal static void LogGenericException(Exception exception, [CallerMemberName] string previousMethodName = "") {
57+
if (exception == null) {
58+
return;
59+
}
60+
61+
MessageBox.Show(previousMethodName + "() " + exception.Message + Environment.NewLine + exception.StackTrace, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
62+
63+
if (exception.InnerException != null) {
64+
LogGenericException(exception.InnerException, previousMethodName);
65+
}
66+
}
67+
68+
internal static void LogGenericWarning(string message, [CallerMemberName] string previousMethodName = "") {
69+
if (string.IsNullOrEmpty(message)) {
70+
return;
71+
}
72+
73+
MessageBox.Show(previousMethodName + "() " + message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
74+
}
75+
76+
internal static void LogNullError(string nullObjectName, [CallerMemberName] string previousMethodName = "") {
77+
if (string.IsNullOrEmpty(nullObjectName)) {
78+
return;
79+
}
80+
81+
LogGenericError(nullObjectName + " is null!", previousMethodName);
82+
}
83+
84+
[Conditional("DEBUG")]
85+
internal static void LogGenericDebug(string message, [CallerMemberName] string previousMethodName = "") {
86+
if (string.IsNullOrEmpty(message)) {
87+
return;
88+
}
89+
90+
MessageBox.Show(previousMethodName + "() " + message, "Debug", MessageBoxButtons.OK, MessageBoxIcon.Information);
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)