Deleted everything profile related and started semi-fresh

This commit is contained in:
2023-03-27 10:24:40 +02:00
parent 60c6982663
commit 6dd08d15b5
17 changed files with 118 additions and 687 deletions

View File

@@ -0,0 +1,75 @@
using Microsoft.VisualBasic.FileIO;
namespace Password_Manager
{
static class ConfigFileManager
{
private static string configPath = SpecialDirectories.CurrentUserApplicationData + "\\config.cfg";
#region Config flags
/*Configuration: (format: fieldname=value)
pwdStorePath: path to the folder which contains the .gpg files
recipient: whose public key to use for encryption when a new password is created
*/
private const char DELIMETER = '=';
private const string RECIPIENT = "recipient";
private const string PATH = "pwdStorePath";
#endregion
public static string GetPath()
{
try
{
StreamReader sr = new StreamReader(configPath);
if (sr != null)
{
while (!sr.EndOfStream)
{
string[]? fields = sr.ReadLine().Split(DELIMETER);
if (fields != null)
{
if (fields[0] == PATH)
{
return fields[1];
}
}
else
{
continue;
}
}
}
else
{
throw new FileNotFoundException();
}
}
catch (FileNotFoundException)
{
CreateDefaultConfig();
}
catch (IOException e)
{
MessageBox.Show(e.ToString(), "IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return @"C:\Users\Typo\pass"; //TODO: temporary default value
}
private static void CreateDefaultConfig()
{
try
{
StreamWriter sw = new StreamWriter(configPath);
sw.WriteLine(RECIPIENT + DELIMETER + "typo");
sw.WriteLine(PATH + DELIMETER + @"C:\Users\Typo\pass");
sw.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}