Skip to content

Commit

Permalink
Add more debugging for SK2
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Mar 13, 2016
1 parent 06778c9 commit 7587ff0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
6 changes: 1 addition & 5 deletions ArchiSteamFarm/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,8 @@ internal Bot(string botName) {
// Initialize
SteamClient = new SteamClient();

if (Program.GlobalConfig.Debug && !Debugging.NetHookAlreadyInitialized) {
if (Program.GlobalConfig.Debug && !Debugging.NetHookAlreadyInitialized && Directory.Exists(Program.DebugDirectory)) {
try {
if (Directory.Exists(Program.DebugDirectory)) {
Directory.Delete(Program.DebugDirectory, true);
}
Directory.CreateDirectory(Program.DebugDirectory);
SteamClient.DebugNetworkListener = new NetHookNetworkListener(Program.DebugDirectory);
Debugging.NetHookAlreadyInitialized = true;
} catch (Exception e) {
Expand Down
26 changes: 26 additions & 0 deletions ArchiSteamFarm/Debugging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ limitations under the License.
*/

using SteamKit2;
using System;
using System.IO;

namespace ArchiSteamFarm {
internal static class Debugging {
#if DEBUG
Expand All @@ -33,5 +37,27 @@ internal static class Debugging {
internal static bool IsReleaseBuild => !IsDebugBuild;

internal static bool NetHookAlreadyInitialized { get; set; } = false;

internal sealed class DebugListener : IDebugListener {
private readonly string FilePath;

internal DebugListener(string filePath) {
if (string.IsNullOrEmpty(filePath)) {
return;
}

FilePath = filePath;
}

public void WriteLine(string category, string msg) {
lock (FilePath) {
try {
File.AppendAllText(FilePath, category + " | " + msg + Environment.NewLine);
} catch (Exception e) {
Logging.LogGenericException(e);
}
}
}
}
}
}
12 changes: 12 additions & 0 deletions ArchiSteamFarm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,18 @@ private static void Main(string[] args) {
}
}

// If debugging is on, we prepare debug directory prior to running
if (GlobalConfig.Debug) {
if (Directory.Exists(Program.DebugDirectory)) {
Directory.Delete(Program.DebugDirectory, true);
Thread.Sleep(1000); // Dirty workaround giving Windows some time to sync
}
Directory.CreateDirectory(Program.DebugDirectory);

SteamKit2.DebugLog.AddListener(new Debugging.DebugListener(Path.Combine(Program.DebugDirectory, "debug.txt")));
SteamKit2.DebugLog.Enabled = true;
}

// Parse args
ParseArgs(args);

Expand Down

0 comments on commit 7587ff0

Please sign in to comment.