public Credentials Load()
{
Credentials credentials = new Credentials();
using (var reader = new StreamReader(StorageFile.OpenFile(Common.CredentialsFile, FileMode.OpenOrCreate, FileAccess.Read)))
{
bool isEncrypted;
IsolatedStorageSettings.ApplicationSettings.TryGetValue("IsEncrypted", out isEncrypted);
if (reader.Peek() > 0)
{
try
{
credentials.Email = isEncrypted ? _crypto.Decrypt(reader.ReadLine()) : reader.ReadLine();
credentials.Password = isEncrypted ? _crypto.Decrypt(reader.ReadLine()) : reader.ReadLine();
credentials.Game = (SupportedGame) Convert.ToInt32(reader.ReadLine());
credentials.RememberMe = !string.IsNullOrEmpty(credentials.Password) && Convert.ToBoolean(reader.ReadLine());
}
catch (Exception e)
{
// If it's format exception, then user has not saved credentials in new format before
if (!(e is FormatException))
throw;
}
}
}
if (credentials.Email == null || credentials.Password == null || credentials.Password.Length > 20)
return new Credentials();
return credentials;
}