Skip to content

Commit

Permalink
show alert before cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
m1337v committed Feb 27, 2024
1 parent cfdb89c commit 3c03b34
Showing 1 changed file with 53 additions and 39 deletions.
92 changes: 53 additions & 39 deletions RootHide/VarCleanController.m
Original file line number Diff line number Diff line change
Expand Up @@ -218,50 +218,64 @@ - (BOOL)checkFileInList:(NSString *)fileName List:(NSArray*)list {
}

- (void)varClean {
NSLog(@"self.tableData=%@", self.tableData);
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:Localized(@"Confirmation")
message:Localized(@"Are you sure you want to clean selected items?")
preferredStyle:UIAlertControllerStyleAlert];

[self.tableView.refreshControl beginRefreshing];

for(NSDictionary* group in [self.tableData copy]) {
for(NSDictionary* item in [group[@"items"] copy])
{
if(![item[@"checked"] boolValue]) continue;

NSLog(@"clean=%@", item);

/*
NSString* backup = jbroot(@"/var/mobile/Library/RootHide/backup");
NSString* newpath = [backup stringByAppendingPathComponent:item[@"path"]];
NSString* dirpath = [newpath stringByDeletingLastPathComponent];
NSLog(@"newpath=%@, dirpath=%@", newpath, dirpath);
if(![NSFileManager.defaultManager fileExistsAtPath:dirpath])
[NSFileManager.defaultManager createDirectoryAtPath:dirpath
withIntermediateDirectories:YES attributes:nil error:nil];
[NSFileManager.defaultManager copyItemAtPath:item[@"path"] toPath:newpath error:nil];
//*/


NSError* err;
if(![NSFileManager.defaultManager removeItemAtPath:item[@"path"] error:&err]) {
NSLog(@"clean failed=%@", err);
continue;
}
UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:Localized(@"Confirm")
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"Starting clean process");
NSLog(@"self.tableData=%@", self.tableData);

[self.tableView.refreshControl beginRefreshing];

for (NSDictionary* group in [self.tableData copy]) {
for (NSDictionary* item in [group[@"items"] copy]) {
if (![item[@"checked"] boolValue]) continue;

NSLog(@"clean=%@", item);

/*
NSString* backup = jbroot(@"/var/mobile/Library/RootHide/backup");
NSString* newpath = [backup stringByAppendingPathComponent:item[@"path"]];
NSString* dirpath = [newpath stringByDeletingLastPathComponent];
NSLog(@"newpath=%@, dirpath=%@", newpath, dirpath);
if(![NSFileManager.defaultManager fileExistsAtPath:dirpath])
[NSFileManager.defaultManager createDirectoryAtPath:dirpath
withIntermediateDirectories:YES attributes:nil error:nil];
[NSFileManager.defaultManager copyItemAtPath:item[@"path"] toPath:newpath error:nil];
//*/

NSError *err;
if (![NSFileManager.defaultManager removeItemAtPath:item[@"path"] error:&err]) {
NSLog(@"clean failed=%@", err);
continue;
}


NSIndexPath* indexPath = [NSIndexPath indexPathForRow:[group[@"items"] indexOfObject:item]
inSection:[self.tableData indexOfObject:group] ];

[group[@"items"] removeObject:item]; //delete source data first

NSLog(@"indexPath=%@", indexPath);
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[group[@"items"] indexOfObject:item]
inSection:[self.tableData indexOfObject:group]];

[group[@"items"] removeObject:item]; // Delete source data first
NSLog(@"indexPath=%@", indexPath);
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
}
}
}

[self.tableView.refreshControl endRefreshing];
[self updateData];
[self.tableView reloadData];
}];

[self.tableView.refreshControl endRefreshing];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:Localized(@"Cancel")
style:UIAlertActionStyleCancel
handler:nil];

[self updateData];
[self.tableView reloadData];
[alertController addAction:confirmAction];
[alertController addAction:cancelAction];

[self presentViewController:alertController animated:YES completion:nil];
}

#pragma mark - Table view data source
Expand Down

0 comments on commit 3c03b34

Please sign in to comment.