Play-/Source/ui_ios/CollectionView.m
Jean-Philip Desjardins bf293a69b7 Start scanning from the user's Documents directory instead of its home directory on iOS.
Should fix issues where scanning for disc images can take a long time.
2016-05-01 16:58:55 -04:00

68 lines
1.8 KiB
Objective-C

//
// ViewOrientation.m
// Play
//
// Created by Lounge Katt on 8/15/15.
// Copyright (c) 2015 Jean-Philip Desjardins. All rights reserved.
//
#import "CollectionView.h"
#import "IosUtils.h"
#import "DiskUtils.h"
@implementation CollectionView
@synthesize diskImages;
static CollectionView *instance = nil;
+ (CollectionView *) getInstance
{
@synchronized(self)
{
if (instance == nil)
{
instance = [CollectionView new];
}
}
return instance;
}
- (NSArray *) buildCollection
{
NSString* path = [@"~/Documents" stringByExpandingTildeInPath];
NSFileManager* localFileManager = [[NSFileManager alloc] init];
NSDirectoryEnumerator* dirEnum = [localFileManager enumeratorAtPath: path];
NSMutableArray* images = [[NSMutableArray alloc] init];
NSString* file = nil;
while(file = [dirEnum nextObject])
{
std::string diskId;
if(
IosUtils::IsLoadableExecutableFileName(file) ||
(IosUtils::IsLoadableDiskImageFileName(file) &&
DiskUtils::TryGetDiskId([[NSString stringWithFormat:@"%@/%@", path, file] UTF8String], &diskId))
)
{
NSMutableDictionary *disk = [[NSMutableDictionary alloc] init];
[disk setValue:[NSString stringWithUTF8String:diskId.c_str()] forKey:@"serial"];
[disk setValue:file forKey:@"file"];
[images addObject: disk];
NSLog(@"%@: %s", file, diskId.c_str());
}
}
self.diskImages = [images sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
NSString *first = [[a objectForKey:@"file"] lastPathComponent];
NSString *second = [[b objectForKey:@"file"] lastPathComponent];
return [first caseInsensitiveCompare:second];
}];
return self.diskImages;
}
@end