Skip to content

Commit

Permalink
Fix json error parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduytran0 committed Feb 14, 2024
1 parent a0d4fdd commit faadb60
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Natives/MinecraftResourceDownloadTask.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"]) {
Expand All @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion Natives/PLProfiles.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
4 changes: 2 additions & 2 deletions Natives/authenticator/BaseAuthenticator.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions Natives/customcontrols/ControlLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions Natives/utils.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit faadb60

Please sign in to comment.