Handle errors in profile files

This commit is contained in:
Flamefire committed 2014-09-07 11:11:16 +02:00
1 parent a5ddeeee95
commit e66d108df0
1 file changed
+10 -7
+10 -7
View File
@@ -84,18 +84,21 @@ namespace VocaluxeLib.Profile
{ {
PlayerName = value; PlayerName = value;
string avatarFileName; string avatarFileName;
xmlReader.TryGetEnumValue("//root/Info/Difficulty", ref Difficulty); bool ok = xmlReader.TryGetEnumValue("//root/Info/Difficulty", ref Difficulty);
xmlReader.GetValue("//root/Info/Avatar", out avatarFileName, String.Empty); ok &= xmlReader.GetValue("//root/Info/Avatar", out avatarFileName);
Avatar = CBase.Profiles.GetAvatarByFilename(avatarFileName); Avatar = CBase.Profiles.GetAvatarByFilename(avatarFileName);
xmlReader.TryGetEnumValue("//root/Info/UserRole", ref UserRole); ok &= Avatar != null;
xmlReader.TryGetEnumValue("//root/Info/Active", ref Active); ok &= xmlReader.TryGetEnumValue("//root/Info/UserRole", ref UserRole);
ok &= xmlReader.TryGetEnumValue("//root/Info/Active", ref Active);
string passwordHash; string passwordHash;
xmlReader.GetValue("//root/Info/PasswordHash", out passwordHash, ""); xmlReader.GetValue("//root/Info/PasswordHash", out passwordHash);
PasswordHash = !string.IsNullOrEmpty(passwordHash) ? Convert.FromBase64String(passwordHash) : null; PasswordHash = !string.IsNullOrEmpty(passwordHash) ? Convert.FromBase64String(passwordHash) : null;
string passwordSalt; string passwordSalt;
xmlReader.GetValue("//root/Info/PasswordSalt", out passwordSalt, ""); xmlReader.GetValue("//root/Info/PasswordSalt", out passwordSalt);
PasswordSalt = !string.IsNullOrEmpty(passwordSalt) ? Convert.FromBase64String(passwordSalt) : null; PasswordSalt = !string.IsNullOrEmpty(passwordSalt) ? Convert.FromBase64String(passwordSalt) : null;
return true; if (!ok)
CBase.Log.LogError("Error loading profile file: " + FileName);
return ok;
} }
CBase.Log.LogError("Can't find PlayerName in Profile File: " + FileName); CBase.Log.LogError("Can't find PlayerName in Profile File: " + FileName);