Optimized unneccesary try-catch block
This commit is contained in:
@@ -20,53 +20,42 @@ namespace Password_Manager
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
try
|
||||
if (File.Exists(CONFIGPATH))
|
||||
{
|
||||
StreamReader sr = new StreamReader(CONFIGPATH);
|
||||
string? path = null, recipient = null;
|
||||
if (sr != null)
|
||||
string? path = null, recipient = null;
|
||||
while (!sr.EndOfStream)
|
||||
{
|
||||
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];
|
||||
}
|
||||
}
|
||||
else //probably an empty line or something
|
||||
{
|
||||
continue;
|
||||
path = fields[1];
|
||||
}
|
||||
else if (fields[0] == RECIPIENT)
|
||||
{
|
||||
recipient = fields[1];
|
||||
}
|
||||
}
|
||||
else //probably an empty line or something
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (path != null && recipient != null)
|
||||
{
|
||||
Configuration = new Config(path, recipient);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidConfigurationException("One or more required fileds were missing from the configuration file.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
if (path != null && recipient != null)
|
||||
{
|
||||
Configuration = new Config(path, recipient);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidConfigurationException("One or more required fileds were missing from the configuration file.");
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
else
|
||||
{
|
||||
CreateDefaultConfig();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
MessageBox.Show(e.ToString(), "IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user