static KeyValue LoadFromFile(string path, bool asBinary)
{
if (File.Exists(path) == false)
{
return(null);
}
try
{
using (var input = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
var kv = new KeyValue(null, null);
if (asBinary)
{
if (kv.ReadAsBinary(input) == false)
{
return(null);
}
}
else
{
if (kv.ReadAsText(input) == false)
{
return(null);
}
}
return(kv);
}
}
catch (Exception)
{
return(null);
}
}