Skip to content

Commit

Permalink
Console works again (though the console is very likely to change in t…
Browse files Browse the repository at this point in the history
…he future)
  • Loading branch information
TauAkiou committed Mar 10, 2022
1 parent 94f0181 commit 42f34ec
Show file tree
Hide file tree
Showing 13 changed files with 251 additions and 353 deletions.
4 changes: 4 additions & 0 deletions AUCapture-GTK/AUCapture-GTK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@
</Compile>
</ItemGroup>

<ItemGroup>
<Folder Include="PangoText" />
</ItemGroup>

</Project>
8 changes: 0 additions & 8 deletions AUCapture-GTK/ConsoleTypes/NlogGTKConsoleTarget.cs

This file was deleted.

29 changes: 0 additions & 29 deletions AUCapture-GTK/ConsoleTypes/NormalConsole.cs

This file was deleted.

35 changes: 35 additions & 0 deletions AUCapture-GTK/GtkSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.IO;
using Config.Net;
using Gtk;

namespace AmongUsCapture_GTK
{
public static class GtkSettings
{
public static string StorageLocation = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "AmongUsCapture");

public static ConsoleInterface conInterface;

public static void WriteLineToConsole(string time, string module, string severity, string message)
{
if (conInterface != null)
{

}
}

//Global persistent settings that are saved to a json file. Limited Types
public static IGtkPersistentSettings PersistentSettings = new ConfigurationBuilder<IGtkPersistentSettings>().UseJsonFile(Path.Join(StorageLocation, "GtkSettings.json")).Build();
}


public interface IGtkPersistentSettings
{
//Types allowed: bool, double, int, long, string, TimeSpan, DateTime, Uri, Guid
//DateTime is always converted to UTC
bool skipHandlerInstall { get; set; }

}

}
14 changes: 7 additions & 7 deletions AUCapture-GTK/IPC/DBus/IPCAdapterDBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public override URIStartResult HandleURIStart(string[] args)
var wasURIStart = args.Length > 0 && args[0].StartsWith(UriScheme + "://");
var result = URIStartResult.CONTINUE;

if (!File.Exists(Path.Join(Settings.StorageLocation, ".amonguscapture.pid")))
if (!File.Exists(Path.Join(AmongUsCapture.Settings.StorageLocation, ".amonguscapture.pid")))
{
_isHostInstance = true;
}
else
{
// Open our PID file.
using (var pidfile = File.OpenText(Path.Join(Settings.StorageLocation, ".amonguscapture.pid")))
using (var pidfile = File.OpenText(Path.Join(AmongUsCapture.Settings.StorageLocation, ".amonguscapture.pid")))
{
var pid = pidfile.ReadLine();
if (pid != null)
Expand Down Expand Up @@ -76,7 +76,7 @@ public override URIStartResult HandleURIStart(string[] args)
{
// Process doesn't exist. Clear the file.
Console.WriteLine($"Found stale PID file containing {pid}.");
File.Delete(Path.Join(Settings.StorageLocation, ".amonguscapture.pid"));
File.Delete(Path.Join(AmongUsCapture.Settings.StorageLocation, ".amonguscapture.pid"));
_isHostInstance = true;
}
}
Expand All @@ -86,7 +86,7 @@ public override URIStartResult HandleURIStart(string[] args)

if (_isHostInstance)
{
using (var pidwriter = File.CreateText(Path.Join(Settings.StorageLocation, ".amonguscapture.pid")))
using (var pidwriter = File.CreateText(Path.Join(AmongUsCapture.Settings.StorageLocation, ".amonguscapture.pid")))
{
pidwriter.Write(myProcessId);
}
Expand Down Expand Up @@ -281,13 +281,13 @@ public override async Task<bool> Cancel()
private Task CleanPid()
{
// Make sure the pidfile is cleaned up if we have one.
var pidfile = Path.Join(Settings.StorageLocation, ".amonguscapture.pid");
var pidfile = Path.Join(AmongUsCapture.Settings.StorageLocation, ".amonguscapture.pid");

if (File.Exists(pidfile))
{
int pid;
bool fileread;
using (var pidread = File.OpenText(Path.Join(Settings.StorageLocation, ".amonguscapture.pid")))
using (var pidread = File.OpenText(Path.Join(AmongUsCapture.Settings.StorageLocation, ".amonguscapture.pid")))
{
fileread = Int32.TryParse(pidread.ReadLine(), out pid);
}
Expand All @@ -310,7 +310,7 @@ private Task CleanPid()

private void RespondToDbus(string signalresponse)
{
Settings.conInterface.WriteModuleTextColored("DBus", Color.Silver,
GtkSettings.conInterface.WriteModuleTextColored("DBus", Color.Silver,
$"Received DBus Method Call: \"{signalresponse}\"");

var token = StartToken.FromString(signalresponse);
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ public class FormConsole : ConsoleInterface
public MainGTKWindow form;
private static object locker = new Object();

public FormConsole(MainGTKWindow mainWindow)
private Dictionary<string, Color> ModuleColor = new Dictionary<string, Color>()
{
{ "GameMemReader", Color.Purple }
};

public FormConsole(MainGTKWindow mainWindow)
{
form = mainWindow;
string directoryuri = null;
Expand Down Expand Up @@ -51,16 +56,15 @@ public void WriteModuleTextColored(string ModuleName, Color moduleColor, string
form.WriteConsoleLineFormatted(ModuleName, moduleColor, text);
WriteToLog($"[{ModuleName}]: {text}");
}



public void WriteToLog(string textToLog)
{
WriteLogLine(DateTime.UtcNow, textToLog);
}

private string StripColor(string text)
{
return TextColor.StripColor(text);
return PangoColor.StripColor(text);
}

private void WriteLogLine(DateTime time, string textToLog)
Expand Down
120 changes: 120 additions & 0 deletions AUCapture-GTK/Logging/NlogGTKConsoleTarget.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using System.Drawing;
using AmongUsCapture;
using AmongUsCapture_GTK;
using Castle.Components.DictionaryAdapter;
using Discord.Commands;
using GLib;
using Gtk;
using NLog;
using Target = NLog.Targets.Target;
using NLog.Targets;
using NLog.Config;

namespace AUCapture_GTK.ConsoleTypes;

[Target("AUGTKConsole")]
public sealed class NlogGTKConsoleTarget : TargetWithContext
{
[RequiredParameter]
public MainGTKWindow MainWindow { get; set; }

protected override void Write(LogEventInfo logEvent)
{
string logMessage = this.RenderLogEvent(this.Layout, logEvent);

IDictionary<string, object> logProperties = this.GetAllProperties(logEvent);

writeMessageToGTKWindow(logMessage, logProperties);
}

private void writeMessageToGTKWindow(string message, IDictionary<string, object> logProperties)
{
MainWindow.AppendNewLineToConsole(message);
}


private Color GetColorForLogLevel(LogLevel level)
{
// COME ON, NLOG. YOU COULDN'T HAVE PROVIDED A LIST OF THESE OR SOMETHING?
switch (level.Ordinal)
{
case 0: //
return Color.Black;
case 1:
return Color.Blue;
case 2:
return Color.Gray;
case 3:
return Color.YellowGreen;
case 4:
return Color.Red;
case 5:
return Color.Red;
default:
return Color.White;
}
}

private Color PlayerColorToColorOBJ(PlayerColor pColor) {
var OutputCode = Color.White;
switch (pColor) {
case PlayerColor.Red:
OutputCode = Color.Red;
break;
case PlayerColor.Blue:
OutputCode = Color.RoyalBlue;
break;
case PlayerColor.Green:
OutputCode = Color.Green;
break;
case PlayerColor.Pink:
OutputCode = Color.Magenta;
break;
case PlayerColor.Orange:
OutputCode = Color.Orange;
break;
case PlayerColor.Yellow:
OutputCode = Color.Yellow;
break;
case PlayerColor.Black:
OutputCode = Color.Gray;
break;
case PlayerColor.White:
OutputCode = Color.White;
break;
case PlayerColor.Purple:
OutputCode = Color.MediumPurple;
break;
case PlayerColor.Brown:
OutputCode = Color.SaddleBrown;
break;
case PlayerColor.Cyan:
OutputCode = Color.Cyan;
break;
case PlayerColor.Lime:
OutputCode = Color.Lime;
break;
case PlayerColor.Maroon:
OutputCode = Color.Maroon;
break;
case PlayerColor.Rose:
OutputCode = Color.MistyRose;
break;
case PlayerColor.Banana:
OutputCode = Color.LightGoldenrodYellow;
break;
case PlayerColor.Gray:
OutputCode = Color.Gray;
break;
case PlayerColor.Tan:
OutputCode = Color.Tan;
break;
case PlayerColor.Sunset:
OutputCode = Color.LightSalmon;
break;
}

return OutputCode;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace AmongUsCapture.TextColorLibrary
{
public static class TextColor
public static class PangoColor
{
private static char colorIndicator = '§'; //Represent color codes as §FFFFFF (6 Letters, Hex decode)

Expand Down
Loading

0 comments on commit 42f34ec

Please sign in to comment.