Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/PojavLauncher_iOS
Path: blob/main/Natives/FileListViewController.m
589 views
1
#import "FileListViewController.h"
2
3
@interface FileListViewController () {
4
}
5
6
@property(nonatomic) NSMutableArray *fileList;
7
8
@end
9
10
@implementation FileListViewController
11
12
- (void)viewDidLoad {
13
[super viewDidLoad];
14
15
if (self.fileList == nil) {
16
self.fileList = [NSMutableArray array];
17
} else {
18
[self.fileList removeAllObjects];
19
}
20
21
// List files
22
NSFileManager *fm = [NSFileManager defaultManager];
23
NSArray *files = [fm contentsOfDirectoryAtPath:self.listPath error:nil];
24
for(NSString *file in files) {
25
NSString *path = [self.listPath stringByAppendingPathComponent:file];
26
BOOL isDir = NO;
27
[fm fileExistsAtPath:path isDirectory:(&isDir)];
28
if(!isDir && [file hasSuffix:@".json"]) {
29
[self.fileList addObject:[file stringByDeletingPathExtension]];
30
}
31
}
32
33
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
34
}
35
36
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
37
{
38
return self.fileList.count;
39
}
40
41
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
42
{
43
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
44
45
if (cell == nil) {
46
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
47
}
48
49
cell.textLabel.text = [self.fileList objectAtIndex:indexPath.row];
50
return cell;
51
}
52
53
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
54
[self dismissViewControllerAnimated:YES completion:nil];
55
56
self.whenItemSelected(self.fileList [indexPath.row]);
57
}
58
59
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
60
if (editingStyle == UITableViewCellEditingStyleDelete) {
61
NSString *str = [self.fileList objectAtIndex:indexPath.row];
62
NSFileManager *fm = [NSFileManager defaultManager];
63
NSString *path = [NSString stringWithFormat:@"%@/%@.json", self.listPath, str];
64
if (self.whenDelete != nil) {
65
self.whenDelete(path);
66
}
67
[fm removeItemAtPath:path error:nil];
68
[self.fileList removeObjectAtIndex:indexPath.row];
69
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
70
}
71
}
72
73
@end
74
75