Fix json error parsing

This commit is contained in:
khanhduytran0 committed 2024-02-15 05:42:18 +07:00
1 parent a0d4fdd9ec
commit faadb6081b
5 files changed
+11 -11

No files matched your search

+4 -4
View File
@@ -86,8 +86,8 @@
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 @@
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];
+1 -1
View File
@@ -64,7 +64,7 @@ static PLProfiles* current;
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];
}
+2 -2
View File
@@ -20,8 +20,8 @@ static BaseAuthenticator *current = nil;
+ (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);
}
+2 -2
View File
@@ -27,8 +27,8 @@
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];
+2 -2
View File
@@ -68,14 +68,14 @@ NSMutableDictionary* parseJSONFromFile(NSString *path) {
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;
}