New default config values

This commit is contained in:
2023-03-31 11:01:31 +02:00
parent 7ab3a64d56
commit 4652442794

View File

@@ -24,45 +24,45 @@ namespace Password_Manager
while (!success) while (!success)
{ {
if (File.Exists(CONFIGPATH)) if (File.Exists(CONFIGPATH))
{
StreamReader sr = new StreamReader(CONFIGPATH);
string? path = null, recipient = null;
while (!sr.EndOfStream)
{ {
string[]? fields = sr.ReadLine().Split(DELIMETER); StreamReader sr = new StreamReader(CONFIGPATH);
if (fields != null) 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.");
} }
} }
else
if (path != null && recipient != null) {
{ CreateDefaultConfig();
Configuration = new Config(path, recipient); }
success = true;
}
else
{
throw new InvalidConfigurationException("One or more required fileds were missing from the configuration file.");
}
} }
else
{
CreateDefaultConfig();
}
}
} }
public static string GetPath() public static string GetPath()
@@ -79,9 +79,10 @@ namespace Password_Manager
{ {
try try
{ {
string user = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
StreamWriter sw = new StreamWriter(CONFIGPATH); StreamWriter sw = new StreamWriter(CONFIGPATH);
sw.WriteLine(RECIPIENT + DELIMETER + "typo"); sw.WriteLine(RECIPIENT + DELIMETER + user);
sw.WriteLine(PATH + DELIMETER + @"C:\Users\Typo\pass"); sw.WriteLine(PATH + DELIMETER + SpecialDirectories.CurrentUserApplicationData);
sw.Close(); sw.Close();
} }
catch (Exception e) catch (Exception e)