fix some logging stuff so it's easier to read

This commit is contained in:
Carson McManus 2018-03-27 19:16:15 -04:00
parent 704b1c8f44
commit 8f9cbda78e
2 changed files with 20 additions and 18 deletions

View file

@ -64,7 +64,7 @@ namespace SteamGuard
// If there's no manifest, create it // If there's no manifest, create it
if (!File.Exists(maFile)) if (!File.Exists(maFile))
{ {
if (Program.Verbose) Console.WriteLine("warn: No manifest file found at {0}", maFile); Utils.Verbose("warn: No manifest file found at {0}", maFile);
bool? createNewManifest = Program.SteamGuardPath == bool? createNewManifest = Program.SteamGuardPath ==
Program.defaultSteamGuardPath.Replace("~", Environment.GetEnvironmentVariable("HOME")) ? true : (bool?) null; Program.defaultSteamGuardPath.Replace("~", Environment.GetEnvironmentVariable("HOME")) ? true : (bool?) null;
while (createNewManifest == null) while (createNewManifest == null)
@ -95,6 +95,7 @@ namespace SteamGuard
_manifest.RecomputeExistingEntries(); _manifest.RecomputeExistingEntries();
Utils.Verbose($"{_manifest.Entries.Count} accounts loaded");
return _manifest; return _manifest;
} }
catch (Exception ex) catch (Exception ex)
@ -106,7 +107,7 @@ namespace SteamGuard
private static Manifest _generateNewManifest(bool scanDir = false) private static Manifest _generateNewManifest(bool scanDir = false)
{ {
if (Program.Verbose) Console.WriteLine("Generating new manifest..."); Utils.Verbose("Generating new manifest...");
// No directory means no manifest file anyways. // No directory means no manifest file anyways.
Manifest newManifest = new Manifest(); Manifest newManifest = new Manifest();
@ -143,7 +144,7 @@ namespace SteamGuard
} }
catch (Exception ex) catch (Exception ex)
{ {
if (Program.Verbose) Console.WriteLine("warn: {0}", ex.Message); Utils.Verbose("warn: {0}", ex.Message);
} }
} }
@ -249,9 +250,10 @@ namespace SteamGuard
Stream stream = null; Stream stream = null;
RijndaelManaged aes256; RijndaelManaged aes256;
string filename = Path.Combine(Program.SteamGuardPath, entry.Filename);
if (this.Encrypted) if (this.Encrypted)
{ {
MemoryStream ms = new MemoryStream(Convert.FromBase64String(File.ReadAllText(Path.Combine(Program.SteamGuardPath, entry.Filename)))); MemoryStream ms = new MemoryStream(Convert.FromBase64String(File.ReadAllText(filename)));
byte[] key = GetEncryptionKey(passKey, entry.Salt); byte[] key = GetEncryptionKey(passKey, entry.Salt);
aes256 = new RijndaelManaged aes256 = new RijndaelManaged
@ -264,14 +266,14 @@ namespace SteamGuard
ICryptoTransform decryptor = aes256.CreateDecryptor(aes256.Key, aes256.IV); ICryptoTransform decryptor = aes256.CreateDecryptor(aes256.Key, aes256.IV);
stream = new CryptoStream(ms, decryptor, CryptoStreamMode.Read); stream = new CryptoStream(ms, decryptor, CryptoStreamMode.Read);
Utils.Verbose($"Decrypting {filename}...");
} }
else else
{ {
FileStream fileStream = File.OpenRead(Path.Combine(Program.SteamGuardPath, entry.Filename)); FileStream fileStream = File.OpenRead(filename);
stream = fileStream; stream = fileStream;
} }
if (Program.Verbose) Console.WriteLine("Decrypting...");
using (StreamReader reader = new StreamReader(stream)) using (StreamReader reader = new StreamReader(stream))
{ {
fileText = reader.ReadToEnd(); fileText = reader.ReadToEnd();
@ -325,7 +327,7 @@ namespace SteamGuard
string jsonAccount = JsonConvert.SerializeObject(account); string jsonAccount = JsonConvert.SerializeObject(account);
string filename = account.Session.SteamID.ToString() + ".maFile"; string filename = account.Session.SteamID.ToString() + ".maFile";
if (Program.Verbose) Console.WriteLine($"Saving account {account.AccountName} to {filename}..."); Utils.Verbose($"Saving account {account.AccountName} to {filename}...");
ManifestEntry newEntry = new ManifestEntry() ManifestEntry newEntry = new ManifestEntry()
{ {
@ -406,7 +408,7 @@ namespace SteamGuard
} }
catch (Exception ex) catch (Exception ex)
{ {
if (Program.Verbose) Console.WriteLine("error: {0}", ex.ToString()); Utils.Verbose("error: {0}", ex.ToString());
return false; return false;
} }
} }
@ -418,12 +420,12 @@ namespace SteamGuard
{ {
try try
{ {
if (Program.Verbose) Console.WriteLine("Creating {0}", Program.SteamGuardPath); Utils.Verbose("Creating {0}", Program.SteamGuardPath);
Directory.CreateDirectory(Program.SteamGuardPath); Directory.CreateDirectory(Program.SteamGuardPath);
} }
catch (Exception ex) catch (Exception ex)
{ {
if (Program.Verbose) Console.WriteLine($"error: {ex.Message}"); Utils.Verbose($"error: {ex.Message}");
return false; return false;
} }
} }
@ -436,7 +438,7 @@ namespace SteamGuard
} }
catch (Exception ex) catch (Exception ex)
{ {
if (Program.Verbose) Console.WriteLine($"error: {ex.Message}"); Utils.Verbose($"error: {ex.Message}");
return false; return false;
} }
} }

View file

@ -137,13 +137,13 @@ namespace SteamGuard
} }
} }
if (Verbose) Utils.Verbose($"Action: {action}");
if (user.Length > 0)
{ {
Console.WriteLine($"Action: {action}"); Utils.Verbose($"User: {user}");
Console.WriteLine($"User: {user}");
Console.WriteLine($"Passkey: {passkey}");
Console.WriteLine($"maFiles path: {SteamGuardPath}");
} }
Utils.Verbose($"Passkey: {passkey.Length > 0 ? "[specified]" : "[not specified]" }");
Utils.Verbose($"maFiles path: {SteamGuardPath}");
// Perform desired action // Perform desired action
switch (action) switch (action)
@ -273,14 +273,14 @@ namespace SteamGuard
{ {
if (account.AccountName.ToLower() == user.ToLower()) if (account.AccountName.ToLower() == user.ToLower())
{ {
Utils.Verbose("Generating Code..."); Utils.Verbose("Generating code for {0}...", account.AccountName);
code = account.GenerateSteamGuardCode(); code = account.GenerateSteamGuardCode();
break; break;
} }
} }
else else
{ {
Utils.Verbose("Generating Code for {0}...", account.AccountName); Utils.Verbose("Generating code for {0}...", account.AccountName);
code = account.GenerateSteamGuardCode(); code = account.GenerateSteamGuardCode();
break; break;
} }