diff --git a/JavaApp/src/main/java/net/kdt/pojavlaunch/PLaunchApp.java b/JavaApp/src/main/java/net/kdt/pojavlaunch/PLaunchApp.java index 0f3ffd59..0ecf0c6a 100644 --- a/JavaApp/src/main/java/net/kdt/pojavlaunch/PLaunchApp.java +++ b/JavaApp/src/main/java/net/kdt/pojavlaunch/PLaunchApp.java @@ -24,6 +24,8 @@ public class PLaunchApp { try { File mcDir = new File("/var/mobile/Documents/minecraft"); mcDir.mkdirs(); + File pojavDir = new File("/var/mobile/Documents/.pojavlauncher/accounts"); + pojavDir.mkdirs(); if (!new File(mcDir, "config_ver.txt").exists()) { Tools.write(mcDir.getAbsolutePath() + "/config_ver.txt", "1.16.5"); } @@ -92,10 +94,16 @@ public class PLaunchApp { JAssets assets = null; UIKit.updateProgressSafe(0, "Downloading version list"); - mVersionList = Tools.GLOBAL_GSON.fromJson(DownloadUtils.downloadString("https://launchermeta.mojang.com/mc/game/version_manifest.json"), JMinecraftVersionList.class); + try { + mVersionList = Tools.GLOBAL_GSON.fromJson(DownloadUtils.downloadString("https://launchermeta.mojang.com/mc/game/version_manifest.json"), JMinecraftVersionList.class); + } catch (IOException e) { + UIKit.updateProgressSafe(0, "Error: " + e.getMessage()); + e.printStackTrace(); + } verInfo = findVersion(mcver); - if (verInfo.url != null && !new File(verJsonDir).exists()) { + if (verInfo.url != null && !new File(verJsonDir).exists() && mVersionList != null) { + // mVersionList != null is for checking if user have network connection UIKit.updateProgressSafe(0, "Downloading " + mcver + ".json"); Tools.downloadFile(verInfo.url, verJsonDir); } diff --git a/Natives/LoginViewController.h b/Natives/LoginViewController.h index dca5c0ab..2e475e9a 100644 --- a/Natives/LoginViewController.h +++ b/Natives/LoginViewController.h @@ -4,7 +4,7 @@ @end -@interface LoginListViewController : UIViewController +@interface LoginListViewController : UITableViewController @end diff --git a/Natives/LoginViewController.m b/Natives/LoginViewController.m index 335fd93e..7b65ed98 100644 --- a/Natives/LoginViewController.m +++ b/Natives/LoginViewController.m @@ -1,3 +1,6 @@ +#include +#include + #import "LauncherViewController.h" #import "LoginViewController.h" @@ -109,8 +112,8 @@ alertTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 300, 300)]; [alertTableView setAllowsSelection:YES]; */ - LoginListViewController *controller = [[LoginListViewController alloc] init]; - [self presentViewController:controller animated:YES completion:nil]; + LoginListViewController *vc = [[LoginListViewController alloc] init]; + [self.navigationController pushViewController:vc animated:YES]; } - (void)enterLauncher { @@ -132,29 +135,43 @@ NSMutableArray *accountList; - (void)viewDidLoad { [super viewDidLoad]; + [self setTitle:@"Select account"]; + if (accountList == nil) { accountList = [NSMutableArray array]; } else { [accountList removeAllObjects]; } - [accountList addObject:@"mojangacc1"]; - [accountList addObject:@"themsacc"]; - [accountList addObject:@"offlineme"]; + DIR *d; + struct dirent *dir; + d = opendir("/var/mobile/Documents/.pojavlauncher/accounts"); + if (d) { + int i = 0; + while ((dir = readdir(d)) != NULL) { + // Skip "." and ".." + if (i < 2) { + i++; + continue; + } else if ([@(dir->d_name) hasSuffix:@".json"]) { + NSString *trimmedName= [@(dir->d_name) substringToIndex:((int)[@(dir->d_name) length] - 5)]; + [accountList addObject:trimmedName]; + } + } + closedir(d); + } CGRect screenBounds = [[UIScreen mainScreen] bounds]; int width = (int) roundf(screenBounds.size.width); int height = (int) roundf(screenBounds.size.height) - self.navigationController.navigationBar.frame.size.height; - self.view.frame = CGRectMake(width / 6, height / 6, width - width / 3, height); + // self.view.frame = CGRectMake(width / 6, height / 6, width - width / 3, height); - UITableView *tableView = [[UITableView alloc]initWithFrame:self.view.frame]; - tableView.delegate = self; - tableView.dataSource = self; - tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero]; - [tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine]; - [self.view addSubview:tableView]; + // UITableView *tableView = [[UITableView alloc]initWithFrame:self.view.frame]; + // tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero]; + [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine]; + // [self.view addSubview:tableView]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section @@ -164,8 +181,7 @@ NSMutableArray *accountList; - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - NSString *simpleTableIdentifier = @"SimpleTableCell"; - + NSString *simpleTableIdentifier = @"cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; if (cell == nil) { @@ -176,4 +192,15 @@ NSMutableArray *accountList; return cell; } +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + NSInteger rowNo = indexPath.row; + [self.navigationController popViewControllerAnimated:YES]; +} + +- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { + if (editingStyle == UITableViewCellEditingStyleDelete) { + // delete + } +} + @end diff --git a/Natives/login_bridge.m b/Natives/login_bridge.m index a056a376..d0231feb 100644 --- a/Natives/login_bridge.m +++ b/Natives/login_bridge.m @@ -1,3 +1,4 @@ +#include "jni.h" #include "login_bridge.h" diff --git a/build_package.sh b/build_package.sh index fe506c2e..792e5554 100644 --- a/build_package.sh +++ b/build_package.sh @@ -2,7 +2,7 @@ set -e -mkdir -p packages/pojavlauncher_iphoneos-arm/{DEBIAN,Applications,var/mobile/Documents/minecraft} +mkdir -p packages/pojavlauncher_iphoneos-arm/{DEBIAN,Applications,var/mobile/Documents/minecraft,var/mobile/Documents/.pojavlauncher} cp -R Natives/build/Release-iphoneos/PojavLauncher.app packages/pojavlauncher_iphoneos-arm/Applications cp control packages/pojavlauncher_iphoneos-arm/DEBIAN