From 72edd15dfbffa838fc72f7bfbbcc759b5d84af41 Mon Sep 17 00:00:00 2001 From: Duy Tran Khanh Date: Fri, 7 Jul 2023 17:59:54 +0700 Subject: [PATCH] Fix: potential crashes in profile mgr, wrong debug_logging category --- Natives/LauncherNavigationController.m | 4 ++++ Natives/LauncherProfilesViewController.m | 8 +++++++- Natives/MinecraftResourceUtils.m | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Natives/LauncherNavigationController.m b/Natives/LauncherNavigationController.m index 5b30e867..acd5d35b 100644 --- a/Natives/LauncherNavigationController.m +++ b/Natives/LauncherNavigationController.m @@ -163,6 +163,10 @@ [self.versionPickerView reloadAllComponents]; // Reload selected profile info self.profileSelectedAt = [PLProfiles.current.profiles.allKeys indexOfObject:PLProfiles.current.selectedProfileName]; + if (self.profileSelectedAt == -1) { + // This instance has no profiles? + return; + } [self.versionPickerView selectRow:self.profileSelectedAt inComponent:0 animated:NO]; [self pickerView:self.versionPickerView didSelectRow:self.profileSelectedAt inComponent:0]; } diff --git a/Natives/LauncherProfilesViewController.m b/Natives/LauncherProfilesViewController.m index b7c957ec..d5ba7798 100644 --- a/Natives/LauncherProfilesViewController.m +++ b/Natives/LauncherProfilesViewController.m @@ -203,7 +203,13 @@ confirmAlert.popoverPresentationController.sourceRect = cell.bounds; UIAlertAction *ok = [UIAlertAction actionWithTitle:localize(@"OK", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { [PLProfiles.current.profiles removeObjectForKey:cell.textLabel.text]; - [PLProfiles.current save]; + if ([PLProfiles.current.selectedProfileName isEqualToString:cell.textLabel.text]) { + // The one being deleted is the selected one, switch to the random one now + PLProfiles.current.selectedProfileName = PLProfiles.current.profiles.allKeys[0]; + [self.navigationController performSelector:@selector(reloadProfileList)]; + } else { + [PLProfiles.current save]; + } [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; }]; UIAlertAction *cancel = [UIAlertAction actionWithTitle:localize(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil]; diff --git a/Natives/MinecraftResourceUtils.m b/Natives/MinecraftResourceUtils.m index 883e32eb..b842740f 100644 --- a/Natives/MinecraftResourceUtils.m +++ b/Natives/MinecraftResourceUtils.m @@ -71,7 +71,7 @@ static AFURLSessionManager* manager; } BOOL check = [sha isEqualToString:localSHA]; - if (!check || (getPrefBool(@"debug.debug_logging") && logSuccess)) { + if (!check || (getPrefBool(@"general.debug_logging") && logSuccess)) { NSLog(@"[MCDL] SHA1 %@ for %@%@", (check ? @"passed" : @"failed"), (altName ? altName : path.lastPathComponent),