Files
PojavLauncher_iOS/Natives/AccountListViewController.m
T
khanhduytran0 0041edcc87 Bundle AFNetworking into the main executable
Trying to fix the following crash:

Exception type: EXC_BAD_ACCESS (SIGBUS)
Exception subtype: KERN_PROTECTION_FAILURE: 0x100fe76e8
Exception codes: 0x0000000000000002, 0x0000000100fe76e8
Culprit: Unknown
VM Protection: ---

Triggered by thread: 0
Thread name: Dispatch queue: com.apple.main-thread
Call stack:
0   AFNetworking                  	0x0000000100fe76e8 0x100fc8000 + 128744     	// +[_AFURLSessionTaskSwizzling load]
1   libobjc.A.dylib               	0x00000001a1b9321c 0x1a1b82000 + 70172      	// load_images
2   dyld                          	0x00000001012ee320 0x1012ec000 + 8992       	// dyld::notifySingle(dyld_image_states, ImageLoader const*, ImageLoader::InitializerTimingList*)
3   dyld                          	0x0000000101300c4c 0x1012ec000 + 85068      	// ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&)
4   dyld                          	0x0000000101300bb0 0x1012ec000 + 84912      	// ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&)
5   dyld                          	0x00000001012febb8 0x1012ec000 + 76728      	// ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&)
6   dyld                          	0x00000001012fec84 0x1012ec000 + 76932      	// ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&)
7   dyld                          	0x00000001012ee7f4 0x1012ec000 + 10228      	// dyld::initializeMainExecutable()
8   dyld                          	0x00000001012f3d88 0x1012ec000 + 32136      	// dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*)
9   dyld                          	0x00000001012ed258 0x1012ec000 + 4696       	// dyldbootstrap::start(dyld3::MachOLoaded const*, int, char const**, dyld3::MachOLoaded const*, unsigned long*)
10  dyld                          	0x00000001012ed038 0x1012ec000 + 4152       	// _dyld_start
2022-06-30 14:28:41 +07:00

101 lines
3.5 KiB
Objective-C

#import "AccountListViewController.h"
#import "AFNetworking.h"
#import "utils.h"
#import "UIImageView+AFNetworking.h"
@interface ATableViewCell : UITableViewCell
@end
@implementation ATableViewCell
@end
@interface AccountListViewController()
@property(nonatomic, strong) NSMutableArray *accountList;
@end
@implementation AccountListViewController
- (void)viewDidLoad {
[super viewDidLoad];
if (self.accountList == nil) {
self.accountList = [NSMutableArray array];
} else {
[self.accountList removeAllObjects];
}
// List accounts
NSString *listPath = [NSString stringWithFormat:@"%s/accounts", getenv("POJAV_HOME")];
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *files = [fm contentsOfDirectoryAtPath:listPath error:nil];
for(NSString *file in files) {
NSString *path = [listPath stringByAppendingPathComponent:file];
BOOL isDir = NO;
[fm fileExistsAtPath:path isDirectory:(&isDir)];
if(!isDir && [file hasSuffix:@".json"]) {
[self.accountList addObject:parseJSONFromFile(path)];
}
}
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.accountList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
}
NSDictionary *selected = self.accountList[indexPath.row];
cell.textLabel.text = selected[@"username"];
if ([selected[@"username"] hasPrefix:@"Demo."]) {
cell.textLabel.text = [selected[@"username"] substringFromIndex:5];
cell.detailTextLabel.text = NSLocalizedString(@"login.option.demo", nil);
} else if (selected[@"xboxGamertag"] == nil) {
cell.detailTextLabel.text = NSLocalizedString(@"login.option.local", nil);
} else {
// Display the Xbox gamertag for online accounts
cell.detailTextLabel.text = selected[@"xboxGamertag"];
}
cell.imageView.contentMode = UIViewContentModeCenter;
[cell.imageView setImageWithURL:[NSURL URLWithString:[selected[@"profilePicURL"] stringByReplacingOccurrencesOfString:@"\\/" withString:@"/"]] placeholderImage:[UIImage imageNamed:@"default_account_pfp"]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self dismissViewControllerAnimated:YES completion:nil];
self.whenItemSelected(self.accountList[indexPath.row][@"username"]);
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// TODO: invalidate token
NSString *str = [self.accountList objectAtIndex:indexPath.row][@"username"];
NSFileManager *fm = [NSFileManager defaultManager];
NSString *path = [NSString stringWithFormat:@"%s/accounts/%@.json", getenv("POJAV_HOME"), str];
if (self.whenDelete != nil) {
self.whenDelete(path);
}
[fm removeItemAtPath:path error:nil];
[self.accountList removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
@end