From 90d249450bcb83f03d52356828834f8bd9cfedfa Mon Sep 17 00:00:00 2001 From: PhiZero Date: Sun, 12 Jun 2022 05:45:26 +0200 Subject: [PATCH] Catch Profile.json parse to prevent crash on launch --- .../Account/Acc/AccountSaveDataManager.cs | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Ryujinx.HLE/HOS/Services/Account/Acc/AccountSaveDataManager.cs b/Ryujinx.HLE/HOS/Services/Account/Acc/AccountSaveDataManager.cs index 44ef3f335..52fc460d8 100644 --- a/Ryujinx.HLE/HOS/Services/Account/Acc/AccountSaveDataManager.cs +++ b/Ryujinx.HLE/HOS/Services/Account/Acc/AccountSaveDataManager.cs @@ -1,5 +1,7 @@ using Ryujinx.Common.Configuration; using Ryujinx.Common.Utilities; +using Ryujinx.Common.Logging; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; @@ -43,16 +45,24 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc if (File.Exists(_profilesJsonPath)) { - ProfilesJson profilesJson = JsonHelper.DeserializeFromFile(_profilesJsonPath); - - foreach (var profile in profilesJson.Profiles) + try { - UserProfile addedProfile = new UserProfile(new UserId(profile.UserId), profile.Name, profile.Image, profile.LastModifiedTimestamp); + ProfilesJson profilesJson = JsonHelper.DeserializeFromFile(_profilesJsonPath); - profiles.AddOrUpdate(profile.UserId, addedProfile, (key, old) => addedProfile); + foreach (var profile in profilesJson.Profiles) + { + UserProfile addedProfile = new UserProfile(new UserId(profile.UserId), profile.Name, profile.Image, profile.LastModifiedTimestamp); + + profiles.AddOrUpdate(profile.UserId, addedProfile, (key, old) => addedProfile); + } + + LastOpened = new UserId(profilesJson.LastOpened); + } + catch (Exception e) + { + Logger.Error?.Print(LogClass.Application, $"Failed to parse {_profilesJsonPath}: {e.Message} Loading default profile!"); + LastOpened = AccountManager.DefaultUserId; } - - LastOpened = new UserId(profilesJson.LastOpened); } else {