Converting to file-scoped namespaces
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
using Microsoft.VisualBasic.FileIO;
|
||||
|
||||
namespace Common
|
||||
namespace Common;
|
||||
|
||||
static class ConfigFileManager
|
||||
{
|
||||
static class ConfigFileManager
|
||||
{
|
||||
#region Config flags
|
||||
/*Configuration: (format: fieldname=value)
|
||||
|
||||
@@ -20,75 +20,74 @@ namespace Common
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
bool success = false;
|
||||
bool success = false;
|
||||
|
||||
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)
|
||||
{
|
||||
StreamReader sr = new StreamReader(CONFIGPATH);
|
||||
string? path = null, recipient = null;
|
||||
while (!sr.EndOfStream)
|
||||
string[]? fields = sr.ReadLine().Split(DELIMETER);
|
||||
if (fields != null)
|
||||
{
|
||||
string[]? fields = sr.ReadLine().Split(DELIMETER);
|
||||
if (fields != null)
|
||||
if (fields[0] == PATH)
|
||||
{
|
||||
if (fields[0] == PATH)
|
||||
{
|
||||
path = fields[1];
|
||||
}
|
||||
else if (fields[0] == RECIPIENT)
|
||||
{
|
||||
recipient = fields[1];
|
||||
}
|
||||
path = fields[1];
|
||||
}
|
||||
else //probably an empty line or something
|
||||
else if (fields[0] == RECIPIENT)
|
||||
{
|
||||
continue;
|
||||
recipient = fields[1];
|
||||
}
|
||||
}
|
||||
else //probably an empty line or something
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
if (path != null && recipient != null)
|
||||
{
|
||||
Configuration = new Config(path, recipient);
|
||||
success = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateDefaultConfig();
|
||||
throw new InvalidConfigurationException("One or more required fileds were missing from the configuration file.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateDefaultConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetPath()
|
||||
{
|
||||
public static string GetPath()
|
||||
{
|
||||
return Configuration.PasswordStorePath;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetRecipient()
|
||||
{
|
||||
return Configuration.Recipient;
|
||||
}
|
||||
|
||||
private static void CreateDefaultConfig()
|
||||
private static void CreateDefaultConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
string user = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
|
||||
StreamWriter sw = new StreamWriter(CONFIGPATH);
|
||||
sw.WriteLine(RECIPIENT + DELIMETER + user);
|
||||
sw.WriteLine(PATH + DELIMETER + SpecialDirectories.CurrentUserApplicationData);
|
||||
sw.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
string user = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
|
||||
StreamWriter sw = new StreamWriter(CONFIGPATH);
|
||||
sw.WriteLine(RECIPIENT + DELIMETER + user);
|
||||
sw.WriteLine(PATH + DELIMETER + SpecialDirectories.CurrentUserApplicationData);
|
||||
sw.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user