-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-> Added a logger for easy debug -> Renamed the rpc file -> Added a ascii art for the start of the app -> Some more debugging helpers -> Added a hooker for PteroConsole LIB
- Loading branch information
Showing
12 changed files
with
235 additions
and
44 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
namespace PteroController.Managers | ||
{ | ||
public enum LogType | ||
{ | ||
Info, | ||
Warning, | ||
Error | ||
} | ||
|
||
public class LoggerManager | ||
{ | ||
private string logFilePath; | ||
|
||
public LoggerManager() | ||
{ | ||
string logDirectory = "logs"; | ||
string logFileName = "log.txt"; | ||
string logDirectoryPath = Path.Combine(Directory.GetCurrentDirectory(), logDirectory); | ||
logFilePath = Path.Combine(logDirectoryPath, logFileName); | ||
Directory.CreateDirectory(logDirectoryPath); | ||
RenameLogFile(); | ||
} | ||
|
||
public void Log(LogType type, string message) | ||
{ | ||
string timestamp = DateTime.Now.ToString("HH:mm:ss"); | ||
string logText = $"[{timestamp}] [{type.ToString()}] {message}"; | ||
|
||
ConsoleColor color = ConsoleColor.White; | ||
switch (type) | ||
{ | ||
case LogType.Info: | ||
color = ConsoleColor.Blue; | ||
break; | ||
case LogType.Warning: | ||
color = ConsoleColor.Yellow; | ||
break; | ||
case LogType.Error: | ||
color = ConsoleColor.Red; | ||
break; | ||
} | ||
Console.ForegroundColor = color; | ||
Console.WriteLine(logText); | ||
Console.ResetColor(); | ||
AppendToFile(logText); | ||
} | ||
|
||
private void AppendToFile(string logText) | ||
{ | ||
try | ||
{ | ||
using StreamWriter writer = File.AppendText(logFilePath); | ||
writer.WriteLine(logText); | ||
} | ||
catch (Exception ex) | ||
{ | ||
string timestamp = DateTime.Now.ToString("HH:mm:ss"); | ||
Console.ForegroundColor = ConsoleColor.Red; | ||
Console.WriteLine($"[{timestamp}] [Error] Error writing to log file: {ex.Message}"); | ||
Console.ResetColor(); | ||
} | ||
} | ||
|
||
private void RenameLogFile() | ||
{ | ||
if (File.Exists(logFilePath)) | ||
{ | ||
string logFileNameWithoutExtension = Path.GetFileNameWithoutExtension(logFilePath); | ||
string logFileExtension = Path.GetExtension(logFilePath); | ||
#pragma warning disable | ||
string logDirectoryPath = Path.GetDirectoryName(logFilePath); | ||
string newLogFileName = GetUniqueLogFileName(logDirectoryPath, logFileNameWithoutExtension, logFileExtension); | ||
#pragma warning restore | ||
string newLogFilePath = Path.Combine(logDirectoryPath, newLogFileName); | ||
File.Move(logFilePath, newLogFilePath); | ||
} | ||
} | ||
|
||
private string GetUniqueLogFileName(string directoryPath, string fileNameWithoutExtension, string fileExtension) | ||
{ | ||
string uniqueFileName = $"{fileNameWithoutExtension}-{DateTime.Now:yyyy-MM-dd}{fileExtension}"; | ||
string uniqueFilePath = Path.Combine(directoryPath, uniqueFileName); | ||
|
||
int counter = 1; | ||
while (File.Exists(uniqueFilePath)) | ||
{ | ||
uniqueFileName = $"{fileNameWithoutExtension}-{counter++}-{DateTime.Now:yyyy-MM-dd}{fileExtension}"; | ||
uniqueFilePath = Path.Combine(directoryPath, uniqueFileName); | ||
} | ||
|
||
return uniqueFileName; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace PteroController.PteroConsoleHook | ||
{ | ||
public class WebsocketData | ||
{ | ||
[JsonProperty("token")] | ||
public string? Token { get; set; } | ||
|
||
[JsonProperty("socket")] | ||
public string? Socket { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace PteroController.PteroConsoleHook | ||
{ | ||
public class WebsocketDataResource | ||
{ | ||
[JsonProperty("data")] | ||
public WebsocketData? Data { get; set; } | ||
} | ||
|
||
} |
Oops, something went wrong.