From faadb6081b52e7a1b4320d5ce39fcc778da0af5f Mon Sep 17 00:00:00 2001 From: khanhduytran0 Date: Thu, 15 Feb 2024 05:42:18 +0700 Subject: [PATCH] Fix json error parsing --- Natives/MinecraftResourceDownloadTask.m | 8 ++++---- Natives/PLProfiles.m | 2 +- Natives/authenticator/BaseAuthenticator.m | 4 ++-- Natives/customcontrols/ControlLayout.m | 4 ++-- Natives/utils.m | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Natives/MinecraftResourceDownloadTask.m b/Natives/MinecraftResourceDownloadTask.m index a49588b8aa..7580aca841 100644 --- a/Natives/MinecraftResourceDownloadTask.m +++ b/Natives/MinecraftResourceDownloadTask.m @@ -86,8 +86,8 @@ - (void)downloadVersionMetadata:(NSDictionary *)version success:(void (^)())succ void(^completionBlock)(void) = ^{ self.metadata = parseJSONFromFile(path); - if (self.metadata[@"NSErrorDescription"]) { - [self finishDownloadWithErrorString:self.metadata[@"NSErrorDescription"]]; + if (self.metadata[@"NSErrorObject"]) { + [self finishDownloadWithErrorString:[self.metadata[@"NSErrorObject"] localizedDescription]]; return; } if (self.metadata[@"inheritsFrom"]) { @@ -104,8 +104,8 @@ - (void)downloadVersionMetadata:(NSDictionary *)version success:(void (^)())succ if (!version) { // This is likely local version, check if json exists and has inheritsFrom NSMutableDictionary *json = parseJSONFromFile(path); - if (json[@"NSErrorDescription"]) { - [self finishDownloadWithErrorString:json[@"NSErrorDescription"]]; + if (json[@"NSErrorObject"]) { + [self finishDownloadWithErrorString:[json[@"NSErrorObject"] localizedDescription]]; return; } else if (json[@"inheritsFrom"]) { version = (id)[MinecraftResourceUtils findVersion:json[@"inheritsFrom"] inList:remoteVersionList]; diff --git a/Natives/PLProfiles.m b/Natives/PLProfiles.m index 5dfe958f1d..e4e63c7dbc 100644 --- a/Natives/PLProfiles.m +++ b/Natives/PLProfiles.m @@ -64,7 +64,7 @@ - (id)initWithCurrentInstance { self = [super init]; self.profilePath = [@(getenv("POJAV_GAME_DIR")) stringByAppendingPathComponent:@"launcher_profiles.json"]; self.profileDict = parseJSONFromFile(self.profilePath); - if (self.profileDict[@"NSErrorDescription"]) { + if (self.profileDict[@"NSErrorObject"]) { self.profileDict = PLProfiles.defaultProfiles; [self save]; } diff --git a/Natives/authenticator/BaseAuthenticator.m b/Natives/authenticator/BaseAuthenticator.m index 6253be311d..4cbf388831 100644 --- a/Natives/authenticator/BaseAuthenticator.m +++ b/Natives/authenticator/BaseAuthenticator.m @@ -20,8 +20,8 @@ + (void)setCurrent:(BaseAuthenticator *)auth { + (id)loadSavedName:(NSString *)name { NSMutableDictionary *authData = parseJSONFromFile([NSString stringWithFormat:@"%s/accounts/%@.json", getenv("POJAV_HOME"), name]); - if (authData[@"error"] != nil) { - NSError *error = ((NSError *)authData[@"error"]); + if (authData[@"NSErrorObject"] != nil) { + NSError *error = ((NSError *)authData[@"NSErrorObject"]); if (error.code != NSFileReadNoSuchFileError) { showDialog(localize(@"Error", nil), error.localizedDescription); } diff --git a/Natives/customcontrols/ControlLayout.m b/Natives/customcontrols/ControlLayout.m index dc55159356..661545b50d 100644 --- a/Natives/customcontrols/ControlLayout.m +++ b/Natives/customcontrols/ControlLayout.m @@ -27,8 +27,8 @@ - (void)loadControlFile:(NSString *)name { NSString *controlFilePath = [NSString stringWithFormat:@"%s/controlmap/%@", getenv("POJAV_HOME"), name]; self.layoutDictionary = parseJSONFromFile(controlFilePath); - if (self.layoutDictionary[@"error"] != nil) { - showDialog(localize(@"Error", nil), [NSString stringWithFormat:@"Could not open %@: %@", controlFilePath, [self.layoutDictionary[@"error"] localizedDescription]]); + if (self.layoutDictionary[@"NSErrorObject"] != nil) { + showDialog(localize(@"Error", nil), [NSString stringWithFormat:@"Could not open %@: %@", controlFilePath, [self.layoutDictionary[@"NSErrorObject"] localizedDescription]]); return; } [self loadControlLayout:self.layoutDictionary]; diff --git a/Natives/utils.m b/Natives/utils.m index 021f3336a8..dfe51c573a 100644 --- a/Natives/utils.m +++ b/Natives/utils.m @@ -68,14 +68,14 @@ void openLink(UIViewController* sender, NSURL* link) { NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error]; if (content == nil) { NSLog(@"[ParseJSON] Error: could not read %@: %@", path, error.localizedDescription); - return @{@"NSErrorDescription": error.localizedDescription}.mutableCopy; + return @{@"NSErrorObject": error}.mutableCopy; } NSData* data = [content dataUsingEncoding:NSUTF8StringEncoding]; NSMutableDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error]; if (error) { NSLog(@"[ParseJSON] Error: could not parse JSON: %@", error.localizedDescription); - return [@{@"error": error} mutableCopy]; + return @{@"NSErrorObject": error}.mutableCopy; } return dict; }