Skip to content

Commit

Permalink
Cleanup & Console text beautify
Browse files Browse the repository at this point in the history
We love colored text!
  • Loading branch information
ZenithVal committed Jul 3, 2023
1 parent ddc40f5 commit 1d2abf3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Configs/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static void Save() {
InitConfig();
Console.WriteLine("SUCCESS");
} catch (Exception w) {
Console.WriteLine("FAILED!!" + e, e);
Console.WriteLine("FAILED!!" + w, w);
}
}
}
Expand Down
9 changes: 0 additions & 9 deletions Encryption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,11 @@ public static void EncryptApp()
string appPassPath = "app.pass";
Encryption.Write(appPassPath, password, "7b7079bb6379001dce"); //Really secret, I know.

//Old Expanded version
//string encryptedAppPass = Encrypt(password, "7b7079bb6379001dce");
//File.WriteAllText(appPassPath, encryptedAppPass);

//Encrypt the config.toml file with the password
string configPath = "config.toml";
string configData = File.ReadAllText(configPath);
Encryption.Write(configPath, configData, password);

//Old Expanded version
//string encryptedConfig = Encrypt(configData, password);
//File.WriteAllText(configPath, encryptedConfig);


//Encrypt the existing timer.end and timer.start files, IF THEY EXIST.
var timersExist = File.Exists("timer.start") && File.Exists("timer.end");
if (timersExist)
Expand Down
31 changes: 17 additions & 14 deletions Logic/OSCTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static async Task OnIncParam(OscMessage message) {
lastAdded = DateTime.Now.AddMilliseconds(input_delay);
}
else {
Console.WriteLine($"Restricted by input delay until: " + lastAdded);
ColorConsole.WithYellowText.WriteLine($"Restricted by input delay until: " + lastAdded);
}
}
else if (shouldAdd) {
Expand Down Expand Up @@ -165,11 +165,11 @@ public static void Setup() {
//If the app is encrypted, require the user to start a new timer to enable unlocking again.
if (!Program.isEncrypted) {
Program.isAllowedToUnlock = true;
Console.WriteLine("Failed to restore timer.\n");
ColorConsole.WithYellowText.WriteLine("Failed to restore timer.\n");
}
else {
Program.isAllowedToUnlock = false;
Console.WriteLine("Failed to restore timer.\nEncryption prevents timer tampering.");
ColorConsole.WithRedText.WriteLine("Failed to restore timer.\nEncryption prevents timer tampering.");
}
}
}
Expand All @@ -185,12 +185,13 @@ public static void Setup() {
}
else {
Program.isAllowedToUnlock = false;
Console.WriteLine("No timer files found.\nEncryption prevents timer file tampering.");
ColorConsole.WithRedText.WriteLine("No timer files found.\nEncryption prevents timer file tampering.");
}
}
}
catch (Exception e) {
ColorConsole.WithRedText.WriteLine($"Timer config load failed: {e.Message}\n\nPlease check your config file and reboot.");
ColorConsole.WithRedText.WriteLine($"Timer config load failed: {e.Message}");
Console.WriteLine("\n\nPlease check your config file and reboot.");
Task.Delay(5000).Wait();
Environment.Exit(0);
}
Expand All @@ -204,7 +205,7 @@ public static void AddTime(double timeToAdd) {
var newTimeSpan = (int)(EndTime.AddSeconds(timeToAdd) - DateTime.Now).TotalMinutes;

if (newTimeSpan > maxTime) {
Console.WriteLine("Reached timer device cap");
ColorConsole.WithYellowText.WriteLine("Reached timer device cap");
//If the new time span is greater than the max time, we need to remove the difference from the minutes to add
timeToAdd -= (newTimeSpan - maxTime);
}
Expand All @@ -215,7 +216,7 @@ public static void AddTime(double timeToAdd) {
//Checking if going past absolute max
if (newEndTime > AbsoluteEndTime) {
newEndTime = AbsoluteEndTime;
Console.WriteLine("Reached overall maximum time limit");
ColorConsole.WithYellowText.WriteLine("Reached overall maximum time limit");
}
}

Expand Down Expand Up @@ -244,17 +245,17 @@ public static Double GetTimeLeftTotal() {

if (absolute_min > 0 && EarlietEndTime > currentTime)
{ //Endtime in past, but minimum time has not passed
Console.WriteLine("Absolute minimum time has not yet elapsed, ");
ColorConsole.WithYellowText.WriteLine("Absolute minimum time has not yet elapsed, ");

//Going to use ceiling instead of floor to prevent the timer from having to fire minimum warning twice in rare cases.
var timeDiff = Math.Ceiling((EarlietEndTime - currentTime).TotalSeconds);
var timeDiffMinutes = Math.Round(timeDiff / 60.0);

if (timeDiff < 60) {
Console.WriteLine($"atleast {timeDiff} more seconds must pass, ");
ColorConsole.WithYellowText.WriteLine($"atleast {timeDiff} more seconds must pass, ");
}
else {
Console.WriteLine($"atleast {timeDiffMinutes} more minute(s) must pass, ");
ColorConsole.WithYellowText.WriteLine($"atleast {timeDiffMinutes} more minute(s) must pass, ");
}

//Makes sure we don't go past the max accumulated time.
Expand Down Expand Up @@ -285,14 +286,16 @@ public static bool HasTimeElapsed() {

public static async Task Start() {
if (!HasTimeElapsed()) {
Console.WriteLine("Cannot start a new timer, you still have " + (int) GetTimeLeftTotal() + " minutes left of current timer.");
ColorConsole.WithRedText.WriteLine("Cannot start a new timer, you still have " + (int) GetTimeLeftTotal() + " minutes left of current timer.");
return;
}

_timer.Stop();

ColorConsole.WithRedText.WriteLine("You are about to start a new timer.");
ColorConsole.WithRedText.WriteLine("Unlock will be disabled until the timer reaches 0.\n");
ColorConsole.WithRedText.WriteLine("■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■");
ColorConsole.WithRedText.WriteLine(" You are about to start a new timer");
ColorConsole.WithRedText.WriteLine(" Unlock will be disabled until the timer reaches 0");
ColorConsole.WithRedText.WriteLine("■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■\n");

if (Program.isEncrypted) Console.WriteLine("Your decrypt key can be used as a failsafe to end the timer.\n");

Expand All @@ -312,7 +315,7 @@ public static async Task Start() {
}


Console.Write("Press 'y', to proceed or any other key to quit");
Console.Write(" Press 'y', to proceed or any other key to quit");
var key = Console.ReadKey().Key;
if (key != ConsoleKey.Y) {
Console.Clear();
Expand Down
38 changes: 23 additions & 15 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class Program {

public static async Task Main(string[] args) {

Console.WriteLine("OSCLock Version v1.0 - 7/1/23\n");
Console.WriteLine("OSCLock Version v1.0\n");

if (File.Exists("app.pass"))
{
Expand All @@ -29,24 +29,32 @@ public static async Task Main(string[] args) {

VRChatConnector.Start();
//Console.WriteLine("Going to home screen...");
Thread.Sleep(2000);

//Thread.Sleep(500);

//Delay for reading the config readout if in debug mode.
if (VRChatConnector.debugging) Thread.Sleep(1500);

await CmdPrompt();
}


public static async Task PrintHelp() {
Console.WriteLine("=== HELP SCREEN ===");
Console.WriteLine("H -- prints this menu");
Console.WriteLine("T -- starts a new timer");
Console.WriteLine("S -- prints status of the app and lock");
Console.WriteLine("U -- Unlock device");
Console.WriteLine("Q -- Quits the application");
if (isEncrypted) Console.WriteLine("} -- Decrypts Config & Timer files\n");
Console.WriteLine("■■■■■■■ HELP SCREEN ■■■■■■■");


Console.WriteLine(" H -- Prints this menu");
Console.WriteLine(" T -- Starts a new timer");
Console.WriteLine(" S -- Status of app & lock");
Console.WriteLine(" U -- Unlock device");
Console.WriteLine(" Q -- Quits the app");
if (isEncrypted) Console.WriteLine("} -- Decrypts Config & Timer files");

//Decided to not inform the user about accessing encryption, since it's documented in the readme.
//if (!isEncrypted) Console.WriteLine("{ -- Encrypts Config & Timer files\n");
//else Console.WriteLine("} -- Decrypts Config & Timer files\n");

//Bumper
Console.WriteLine("");
}

private static async Task PrintStatus() {
Expand All @@ -65,10 +73,10 @@ private static async Task PrintStatus() {
private static ESmartLock connectedLock;
public static async Task UnlockDevice() {
if (!isAllowedToUnlock) {
Console.WriteLine("You are not allowed to unlock yet!\n");
ColorConsole.WithYellowText.WriteLine("You are not allowed to unlock yet!\n");

if (isEncrypted && OSCTimer.HasTimeElapsed()) {
Console.WriteLine("Encryption requires a complete timer to allow unlocking.");
ColorConsole.WithYellowText.WriteLine("Encryption requires a complete timer to allow unlocking.");
Thread.Sleep(1500);
Console.Clear();
await PrintHelp();
Expand Down Expand Up @@ -113,7 +121,7 @@ private static async Task EncryptApp() {

if (isEncrypted)
{
Console.WriteLine("Application is already encrypted!\n");
ColorConsole.WithYellowText.WriteLine("Application is already encrypted!\n");
await PrintHelp();
return;
}
Expand All @@ -128,7 +136,7 @@ private static async Task DecryptApp()
{
if (!isEncrypted)
{
Console.WriteLine("Application is already decrypted!\n");
ColorConsole.WithYellowText.WriteLine("Application is already decrypted!\n");
await PrintHelp();
return;
}
Expand Down Expand Up @@ -174,7 +182,7 @@ private static async Task CmdPrompt() {
await DecryptApp();
break;
default:
Console.WriteLine($"Unknown command {Key}");
ColorConsole.WithRedText.WriteLine($"Unknown command {Key}");
await PrintHelp();
break;
}
Expand Down
2 changes: 1 addition & 1 deletion VRChatConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class VRChatConnector {

private static UDPListener oscListener;
private static UDPSender oscSender;
private static bool debugging;
public static bool debugging;
private static int listener_port;
private static int write_port;
private static string ipAddress;
Expand Down

0 comments on commit 1d2abf3

Please sign in to comment.