Reset preferences option, switch to POJAV_HOME

This commit is contained in:
Adam Tunnic committed 2021-12-08 21:43:02 -05:00
1 parent b056e5ed95
commit d11e113ec4
2 files changed
+45 -3

No files matched your search

+4 -1
View File
@@ -292,6 +292,9 @@ void environmentFailsafes(char *argv[]) {
int launchJVM(int argc, char *argv[]) {
if (0 != [[NSFileManager defaultManager] fileExistsAtPath:@"/var/mobile/Documents/.pojavlauncher"] && 0 == [[NSFileManager defaultManager] fileExistsAtPath:@"/var/mobile/Documents/.pojavlauncher/migration_complete"]) {
NSString *newDir = @"/usr/share/pojavlauncher";
if([[[UIDevice currentDevice] systemVersion] containsString:@"15."]) {
newDir = @"/private/preboot/procursus/usr/share/pojavlauncher";
}
NSString *oldDir = @"/var/mobile/Documents/.pojavlauncher";
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *files = [fm contentsOfDirectoryAtPath:oldDir error:nil];
@@ -301,7 +304,7 @@ int launchJVM(int argc, char *argv[]) {
[fm removeItemAtPath:oldDir error:nil];
symlink([newDir cStringUsingEncoding:NSUTF8StringEncoding], [oldDir cStringUsingEncoding:NSUTF8StringEncoding]);
FILE* file_ptr = fopen("/var/mobile/Documents/.pojavlauncher/migration_complete", "w");
fprintf(file_ptr, "#README - The PojavLauncher data directory is now /usr/share/pojavlauncher. All of your existing data has been moved to the new location.");
fprintf(file_ptr, "#README - The PojavLauncher data directory is now %s. All of your existing data has been moved to the new location.", [newDir cStringUsingEncoding:NSUTF8StringEncoding]);
fclose(file_ptr);
}
+41 -2
View File
@@ -21,6 +21,7 @@
#define SLIDEHOTBAR 13
#define SAFEAREA 14
#define HOMESYM 15
#define ERASEPREF 16
#define TAG_BTNSCALE 98
#define TAG_RESOLUTION 99
@@ -54,6 +55,8 @@
#define TAG_HOMESYM 114
#define TAG_ERASEPREF 115
@interface LauncherPreferencesViewController () <UIPickerViewDataSource, UIPickerViewDelegate, UIPopoverPresentationControllerDelegate> {
}
@@ -481,6 +484,18 @@ int tempIndex;
[homesymSwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
[tableView addSubview:homesymSwitch];
UILabel *erasePrefTextView = [[UILabel alloc] initWithFrame:CGRectMake(16.0, currY+=44.0, 0.0, 0.0)];
erasePrefTextView.text = @"Reset all settings";
erasePrefTextView.numberOfLines = 0;
[erasePrefTextView sizeToFit];
[tableView addSubview:erasePrefTextView];
UISwitch *erasePrefSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(width - 62.0, currY - 5.0, 50.0, 30)];
erasePrefSwitch.tag = TAG_ERASEPREF;
[erasePrefSwitch setOn:NO animated:NO];
[erasePrefSwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
[tableView addSubview:erasePrefSwitch];
CGRect frame = tableView.frame;
frame.size.height = currY+=44;
tableView.frame = frame;
@@ -521,6 +536,8 @@ int tempIndex;
handler:^(__kindof UIAction * _Nonnull action) {[self helpAlertOpt:DEBUGLOG];}],
[UIAction actionWithTitle:@"Home symlink" image:[[UIImage systemImageNamed:@"link"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] identifier:nil
handler:^(__kindof UIAction * _Nonnull action) {[self helpAlertOpt:HOMESYM];}],
[UIAction actionWithTitle:@"Reset preferences" image:[[UIImage systemImageNamed:@"trash"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] identifier:nil
handler:^(__kindof UIAction * _Nonnull action) {[self helpAlertOpt:ERASEPREF];}],
]];
self.navigationItem.rightBarButtonItem.action = nil;
self.navigationItem.rightBarButtonItem.primaryAction = nil;
@@ -791,6 +808,7 @@ int tempIndex;
UIAlertAction *typesel = [UIAlertAction actionWithTitle:@"Type switches" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self helpAlertOpt:TYPESEL];}];
UIAlertAction *debuglog = [UIAlertAction actionWithTitle:@"Debug logging" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self helpAlertOpt:DEBUGLOG];}];
UIAlertAction *homesym = [UIAlertAction actionWithTitle:@"Home symlink" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self helpAlertOpt:HOMESYM];}];
UIAlertAction *erasepref = [UIAlertAction actionWithTitle:@"Reset preferences" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self helpAlertOpt:ERASEPREF];}];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[self setPopoverProperties:helpAlert.popoverPresentationController sender:(UIButton *)self.navigationItem.rightBarButtonItem];
[self presentViewController:helpAlert animated:YES completion:nil];
@@ -938,7 +956,8 @@ int tempIndex;
case TAG_HOMESYM:
setPreference(@"disable_home_symlink", @(sender.isOn));
if([getPreference(@"disable_home_symlink") boolValue] == YES){
UIAlertController *homesymWarn = [UIAlertController alertControllerWithTitle:@"Are you sure?" message:@"This will remove the link at /var/mobile/Documents/.pojavlauncher. The new directory is /usr/share/pojavlauncher." preferredStyle:UIAlertControllerStyleActionSheet];
NSString *message = [NSString stringWithFormat:@"This will remove the link at /var/mobile/Documents/.pojavlauncher. The new directory is %s.", getenv("POJAV_HOME")];
UIAlertController *homesymWarn = [UIAlertController alertControllerWithTitle:@"Are you sure?" message:message preferredStyle:UIAlertControllerStyleActionSheet];
[self setPopoverProperties:homesymWarn.popoverPresentationController sender:(UIButton *)sender];
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"Continue" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[[NSFileManager defaultManager] removeItemAtPath:@"/var/mobile/Documents/.pojavlauncher" error:nil];}];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
@@ -946,7 +965,8 @@ int tempIndex;
[homesymWarn addAction:cancel];
[homesymWarn addAction:ok];
} else {
UIAlertController *homesymWarn = [UIAlertController alertControllerWithTitle:@"Are you sure?" message:@"This will create a link to /usr/share/pojavlauncher in /var/mobile/Documents/.pojavlauncher." preferredStyle:UIAlertControllerStyleActionSheet];
NSString *message = [NSString stringWithFormat:@"This will create a link to %s at /var/mobile/Documents/.pojavlauncher. This option will be removed in a future release.", getenv("POJAV_HOME")];
UIAlertController *homesymWarn = [UIAlertController alertControllerWithTitle:@"Are you sure?" message:message preferredStyle:UIAlertControllerStyleActionSheet];
[self setPopoverProperties:homesymWarn.popoverPresentationController sender:(UIButton *)sender];
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"Continue" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {symlink("/usr/share/pojavlauncher", "/var/mobile/Documents/.pojavlauncher");}];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
@@ -955,6 +975,25 @@ int tempIndex;
[homesymWarn addAction:ok];
}
break;
case TAG_ERASEPREF:
{
NSString *prefFile = [NSString stringWithFormat:@"%s/launcher_preferences.plist", getenv("POJAV_HOME")];
UIAlertController *eraseprefWarn = [UIAlertController alertControllerWithTitle:@"Are you sure?" message:@"This will remove all of your custom preferences, including resolution, button size, and Java arguments." preferredStyle:UIAlertControllerStyleActionSheet];
[self setPopoverProperties:eraseprefWarn.popoverPresentationController sender:(UIButton *)sender];
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"Continue" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[NSFileManager defaultManager] removeItemAtPath:prefFile error:nil];
UIAlertController *eraseprefPost = [UIAlertController alertControllerWithTitle:@"Preferences reset" message:@"The next time you open PojavLauncher, all of the default settings will be restored." preferredStyle:UIAlertControllerStyleActionSheet];
[self setPopoverProperties:eraseprefWarn.popoverPresentationController sender:(UIButton *)sender];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil];
[self presentViewController:eraseprefPost animated:YES completion:nil];
[eraseprefPost addAction:cancel];
}];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[self presentViewController:eraseprefWarn animated:YES completion:nil];
[eraseprefWarn addAction:cancel];
[eraseprefWarn addAction:ok];
}
break;
default:
NSLog(@"what does switch %ld for? implement me!", sender.tag);
break;