Skip to content

Commit

Permalink
Red Text Warnings
Browse files Browse the repository at this point in the history
Red text is hard to ignore.
  • Loading branch information
ZenithVal committed Jul 3, 2023
1 parent 3cb8f03 commit ba43401
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 37 deletions.
4 changes: 2 additions & 2 deletions Bluetooth/BleScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static async void OnDeviceUpdate(DeviceWatcher sender, DeviceInformation
}
}
catch (Exception e) {
Console.WriteLine("Failed on deiscovery " + e);
Console.WriteLine("Failed on discovery " + e);
}
}

Expand Down Expand Up @@ -118,7 +118,7 @@ private static async void OnDeviceDiscovered(DeviceWatcher sender, DeviceInforma
}
}
catch (Exception e) {
Console.WriteLine("Failed on deiscovery " + e);
Console.WriteLine("Failed on discovery " + e);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion Configs/ConfigManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Threading;
using FluentColorConsole;
using Tomlet;
using Tomlet.Models;

Expand Down Expand Up @@ -44,7 +45,7 @@ private static void InitConfig() {
ApplicationConfig = TomletMain.To<MainConfig>(lastDocument);
}
catch (Exception e) {
Console.WriteLine("FAILED TO READ CONFIG FILE!" + e, e);
ColorConsole.WithRedText.WriteLine("FAILED TO READ CONFIG FILE!" + e, e);
Thread.Sleep(5000);
}

Expand Down
3 changes: 2 additions & 1 deletion Encryption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using FluentColorConsole;
using OSCLock.Logic;

//This is mostly just fun security theater. Strings are not protected in memory, and you have access to the source code anyway.
Expand Down Expand Up @@ -33,7 +34,7 @@ public static void Write(string filePath, string data, string encryptionKey)
}
catch (Exception e)
{
Console.WriteLine("Failed to write encrypted file" + e.Message);
ColorConsole.WithRedText.WriteLine("Failed to write encrypted file" + e.Message);
}
}

Expand Down
Binary file added Heart.ico
Binary file not shown.
33 changes: 18 additions & 15 deletions Logic/OSCTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq.Expressions;
using System.Threading.Tasks;
using System.Timers;
using FluentColorConsole;
using OSCLock.Configs;
using SharpOSC;
using Windows.Devices.Printers;
Expand Down Expand Up @@ -168,7 +169,7 @@ public static void Setup() {
}
else {
Program.isAllowedToUnlock = false;
Console.WriteLine("Failed to restore timer.\nEncryption prevents timer file tampering.");
Console.WriteLine("Failed to restore timer.\nEncryption prevents timer tampering.");
}
}
}
Expand All @@ -189,7 +190,7 @@ public static void Setup() {
}
}
catch (Exception e) {
Console.WriteLine($"Timer config load failed: {e.Message}\n\nPlease check your config file and reboot.");
ColorConsole.WithRedText.WriteLine($"Timer config load failed: {e.Message}\n\nPlease check your config file and reboot.");
Task.Delay(5000).Wait();
Environment.Exit(0);
}
Expand Down Expand Up @@ -232,7 +233,7 @@ public static void AddTime(double timeToAdd) {

}
catch (Exception e) {
Console.WriteLine("Failed to update endtime file" + e.Message);
ColorConsole.WithRedText.WriteLine("Failed to update endtime file" + e.Message);
}
}

Expand Down Expand Up @@ -290,9 +291,10 @@ public static async Task Start() {

_timer.Stop();

Console.WriteLine("You are about to start a new timer.");
Console.WriteLine("Unlock will be disabled until the timer reaches 0.");
if (Program.isEncrypted) Console.WriteLine("Your backup decrypt key can be used as a failsafe.\n");
ColorConsole.WithRedText.WriteLine("You are about to start a new timer.");
ColorConsole.WithRedText.WriteLine("Unlock will be disabled until the timer reaches 0.\n");

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

//Random disclaimer
var TimerConfig = ConfigManager.ApplicationConfig.TimerConfig;
Expand All @@ -302,13 +304,14 @@ public static async Task Start() {


if (starting_time < 0) {
Console.WriteLine($"The time is set to random between {random_min} and {random_max} minutes.");
ColorConsole.WithYellowText.WriteLine($"The time is set to random between {random_min} and {random_max} minutes.");
}

if (absolute_min > 0) {
Console.WriteLine("There is a minimum time of " + absolute_min + " minutes set.");
ColorConsole.WithYellowText.WriteLine("There is a minimum time of " + absolute_min + " minutes set.");
}



Console.Write("Press 'y', to proceed or any other key to quit");
var key = Console.ReadKey().Key;
if (key != ConsoleKey.Y) {
Expand All @@ -331,18 +334,18 @@ public static async Task Start() {
//Minimum check
if (starting_time < absolute_min && absolute_min > 0) {
starting_time = absolute_min;
Console.Write("capped by minimum time to ");
ColorConsole.WithYellowText.Write("capped by minimum time to ");
}
//Maximum check
else if (starting_time > maxAccumulated && maxAccumulated > 0) {
starting_time = maxAccumulated;

Console.Write("capped by maxtime to ");
ColorConsole.WithYellowText.Write("capped by maxtime to ");
}
//Absolute max check. This should never really happen... but just in case someone really fumbles the config:
else if (starting_time > absolute_max && absolute_max > 0) {
starting_time = absolute_max;
Console.Write("capped by maxtime to ");
ColorConsole.WithYellowText.Write("capped by maxtime to ");
}
else Console.Write("of ");

Expand Down Expand Up @@ -374,7 +377,7 @@ public static async Task Start() {

private static async void CheckIfUnlockable(object sender, ElapsedEventArgs elapsedEventArgs) {
if (HasTimeElapsed()) {
Console.WriteLine("\nTime is up, Marking as unlockable and stopping timer");
ColorConsole.WithGreenText.WriteLine("\nTime is up, Marking as unlockable and stopping timer");

_timer.Stop();

Expand All @@ -392,7 +395,7 @@ private static async void CheckIfUnlockable(object sender, ElapsedEventArgs elap
public static async Task ForceEnd()
{
Console.Clear();
Console.WriteLine("Ending Timer.");
ColorConsole.WithGreenText.WriteLine("Ending Timer.");

_timer.Stop();
EndTime = DateTime.Now;
Expand Down Expand Up @@ -492,7 +495,7 @@ private static async void OnProgress(object sender, ElapsedEventArgs elapsedEven
}
catch (Exception e)
{
Console.WriteLine("Failed to write vrchat readout parameter" + e.Message);
ColorConsole.WithRedText.WriteLine("Failed to write vrchat readout parameter" + e.Message);
}
}
}
Expand Down
21 changes: 12 additions & 9 deletions OSCLock.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
<ApplicationIcon>Heart.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="FluentColorConsole, Version=2.0.0.1, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\FluentColorConsole.2.0.1\lib\netstandard2.0\FluentColorConsole.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
<HintPath>packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
Expand All @@ -57,12 +60,14 @@
<HintPath>packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll</HintPath>
<Reference Include="System.Runtime, Version=4.1.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Runtime.4.3.1\lib\net462\System.Runtime.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Security.Cryptography.Algorithms, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net463\System.Security.Cryptography.Algorithms.dll</HintPath>
<Reference Include="System.Security.Cryptography.Algorithms, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Security.Cryptography.Algorithms.4.3.1\lib\net463\System.Security.Cryptography.Algorithms.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Security.Cryptography.Encoding, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
Expand All @@ -73,8 +78,9 @@
<HintPath>packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Security.Cryptography.X509Certificates, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll</HintPath>
<Reference Include="System.Security.Cryptography.X509Certificates, Version=4.1.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Security.Cryptography.X509Certificates.4.3.2\lib\net461\System.Security.Cryptography.X509Certificates.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Windows" />
Expand Down Expand Up @@ -125,9 +131,6 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="packages\System.Runtime.WindowsRuntime.5.0.0-preview.5.20278.1\build\net461\System.Runtime.WindowsRuntime.targets" Condition="Exists('packages\System.Runtime.WindowsRuntime.5.0.0-preview.5.20278.1\build\net461\System.Runtime.WindowsRuntime.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\System.Runtime.WindowsRuntime.5.0.0-preview.5.20278.1\build\net461\System.Runtime.WindowsRuntime.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\System.Runtime.WindowsRuntime.5.0.0-preview.5.20278.1\build\net461\System.Runtime.WindowsRuntime.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
12 changes: 8 additions & 4 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using OSCLock.Configs;
using OSCLock.Logic;
using System.IO;
using FluentColorConsole;

namespace OSCLock {
internal class Program {
Expand Down Expand Up @@ -41,8 +42,11 @@ public static async Task PrintHelp() {
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("{ -- Encrypts Config & Timer files\n");
else Console.WriteLine("} -- Decrypts Config & Timer files\n");
if (isEncrypted) Console.WriteLine("} -- Decrypts Config & Timer files\n");

//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");
}

private static async Task PrintStatus() {
Expand Down Expand Up @@ -95,14 +99,14 @@ public static async Task UnlockDevice() {
private static async Task StartTimer() {
if (ConfigManager.ApplicationConfig.mode == ApplicationMode.Timer) {
await OSCTimer.Start();
} else Console.WriteLine("Not operating in timer mode, change mode in config and restart");
} else ColorConsole.WithYellowText.WriteLine("Not operating in timer mode, change mode in config and restart");
}

private static async Task EncryptApp() {

//if OSCTimer.HasTimeElapsed is false, don't allow encryption
if (!OSCTimer.HasTimeElapsed()) {
Console.WriteLine("A timer is already running, you need to finish that before attempting encryption.\n");
ColorConsole.WithYellowText.WriteLine("A timer is already running, you need to finish that before attempting encryption.\n");
await PrintHelp();
return;
}
Expand Down
7 changes: 5 additions & 2 deletions VRChatConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using FluentColorConsole;
using OSCLock.Configs;
using OSCLock.Logic;
using SharpOSC;
Expand Down Expand Up @@ -54,7 +55,7 @@ public static void Start() {
Console.WriteLine($"debugging: {debugging}");
}
catch (Exception e) {
Console.WriteLine($"Connector config load failed: {e.Message}\n\nPlease check your config file and reboot.");
ColorConsole.WithRedText.WriteLine($"Connector config load failed: {e.Message}\n\nPlease check your config file and reboot.");
Task.Delay(5000).Wait();
Environment.Exit(0);
}
Expand All @@ -67,7 +68,9 @@ public static void Start() {
}
//90% of the time this will fail because the port they attempted to use is already occupied.
catch (Exception e) {
Console.WriteLine($"\nUDPListener failed: {e.Message}\n\nMake sure you're not attempting to run two apps on the same port.");
Console.WriteLine($"\nUDPListener failed: {e.Message}\n\n");
ColorConsole.WithRedText.WriteLine("Make sure you're not attempting to run two apps on the same port.");

Task.Delay(5000).Wait();
Environment.Exit(0);
}
Expand Down
7 changes: 4 additions & 3 deletions packages.config
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FluentColorConsole" version="2.0.1" targetFramework="net48" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
<package id="Samboy063.Tomlet" version="5.1.3" targetFramework="net48" />
<package id="System.IO" version="4.3.0" targetFramework="net48" />
<package id="System.Net.Http" version="4.3.4" targetFramework="net48" />
<package id="System.Runtime" version="4.3.0" targetFramework="net48" />
<package id="System.Runtime" version="4.3.1" targetFramework="net48" />
<package id="System.Runtime.WindowsRuntime" version="5.0.0-preview.5.20278.1" targetFramework="net48" />
<package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net48" />
<package id="System.Security.Cryptography.Algorithms" version="4.3.1" targetFramework="net48" />
<package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net48" />
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net48" />
<package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net48" />
<package id="System.Security.Cryptography.X509Certificates" version="4.3.2" targetFramework="net48" />
</packages>

0 comments on commit ba43401

Please sign in to comment.