diff --git a/Password Manager/ConfigFileManager.cs b/Password Manager/ConfigFileManager.cs index 68df59f..65c248e 100644 --- a/Password Manager/ConfigFileManager.cs +++ b/Password Manager/ConfigFileManager.cs @@ -24,45 +24,45 @@ namespace Password_Manager while (!success) { - if (File.Exists(CONFIGPATH)) - { - StreamReader sr = new StreamReader(CONFIGPATH); - string? path = null, recipient = null; - while (!sr.EndOfStream) + if (File.Exists(CONFIGPATH)) { - string[]? fields = sr.ReadLine().Split(DELIMETER); - if (fields != null) + StreamReader sr = new StreamReader(CONFIGPATH); + string? path = null, recipient = null; + while (!sr.EndOfStream) { - if (fields[0] == PATH) + string[]? fields = sr.ReadLine().Split(DELIMETER); + if (fields != null) { - path = fields[1]; + if (fields[0] == PATH) + { + path = fields[1]; + } + else if (fields[0] == RECIPIENT) + { + recipient = fields[1]; + } + } + else //probably an empty line or something + { + continue; } - else if (fields[0] == RECIPIENT) - { - recipient = fields[1]; - } } - else //probably an empty line or something + + if (path != null && recipient != null) { - continue; + Configuration = new Config(path, recipient); + success = true; + } + else + { + throw new InvalidConfigurationException("One or more required fileds were missing from the configuration file."); } } - - if (path != null && recipient != null) - { - Configuration = new Config(path, recipient); - success = true; - } - else - { - throw new InvalidConfigurationException("One or more required fileds were missing from the configuration file."); - } + else + { + CreateDefaultConfig(); + } } - else - { - CreateDefaultConfig(); - } - } } public static string GetPath() @@ -79,9 +79,10 @@ namespace Password_Manager { try { + string user = System.Security.Principal.WindowsIdentity.GetCurrent().Name; StreamWriter sw = new StreamWriter(CONFIGPATH); - sw.WriteLine(RECIPIENT + DELIMETER + "typo"); - sw.WriteLine(PATH + DELIMETER + @"C:\Users\Typo\pass"); + sw.WriteLine(RECIPIENT + DELIMETER + user); + sw.WriteLine(PATH + DELIMETER + SpecialDirectories.CurrentUserApplicationData); sw.Close(); } catch (Exception e)