2017-10-31 07:35:57 -04:00
|
|
|
|
#import <SDWebImage/UIImageView+WebCache.h>
|
2015-08-15 03:08:32 -04:00
|
|
|
|
#import "CoverViewController.h"
|
|
|
|
|
#import "EmulatorViewController.h"
|
2017-10-31 07:35:57 -04:00
|
|
|
|
#import "../ui_shared/BootablesProcesses.h"
|
|
|
|
|
#import "../ui_shared/BootablesDbClient.h"
|
|
|
|
|
#import "PathUtils.h"
|
2015-08-17 12:48:29 -04:00
|
|
|
|
#import "BackgroundLayer.h"
|
2015-08-31 14:59:13 -04:00
|
|
|
|
#import "CoverViewCell.h"
|
2015-08-15 03:08:32 -04:00
|
|
|
|
|
|
|
|
|
@interface CoverViewController ()
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation CoverViewController
|
|
|
|
|
|
2017-10-31 07:35:57 -04:00
|
|
|
|
static NSString* const reuseIdentifier = @"coverCell";
|
2015-08-15 03:08:32 -04:00
|
|
|
|
|
2017-10-31 07:35:57 -04:00
|
|
|
|
-(void)awakeFromNib
|
2015-08-15 03:08:32 -04:00
|
|
|
|
{
|
2017-10-31 07:35:57 -04:00
|
|
|
|
[super awakeFromNib];
|
|
|
|
|
|
|
|
|
|
ScanBootables(Framework::PathUtils::GetPersonalDataPath());
|
|
|
|
|
PurgeInexistingFiles();
|
|
|
|
|
FetchGameTitles();
|
2015-08-15 03:08:32 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-31 07:35:57 -04:00
|
|
|
|
-(void)viewDidLoad
|
|
|
|
|
{
|
|
|
|
|
[super viewDidLoad];
|
2015-08-17 12:48:29 -04:00
|
|
|
|
|
2017-10-31 07:35:57 -04:00
|
|
|
|
assert(_bootables == nullptr);
|
|
|
|
|
_bootables = new BootableArray(BootablesDb::CClient::GetInstance().GetBootables());
|
|
|
|
|
|
|
|
|
|
CAGradientLayer* bgLayer = [BackgroundLayer blueGradient];
|
2015-08-17 12:48:29 -04:00
|
|
|
|
bgLayer.frame = self.view.bounds;
|
2017-10-31 07:35:57 -04:00
|
|
|
|
[self.view.layer insertSublayer: bgLayer atIndex: 0];
|
2015-08-15 03:08:32 -04:00
|
|
|
|
|
2017-10-31 07:35:57 -04:00
|
|
|
|
self.collectionView.allowsMultipleSelection = NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(void)viewDidUnload
|
|
|
|
|
{
|
|
|
|
|
assert(_bootables != nullptr);
|
|
|
|
|
delete _bootables;
|
2015-08-31 14:59:13 -04:00
|
|
|
|
|
2017-10-31 07:35:57 -04:00
|
|
|
|
[super viewDidUnload];
|
2015-08-15 03:08:32 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-31 07:35:57 -04:00
|
|
|
|
-(void)willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation duration: (NSTimeInterval)duration
|
2015-08-17 12:48:29 -04:00
|
|
|
|
{
|
|
|
|
|
// resize your layers based on the view’s new bounds
|
2017-10-31 07:35:57 -04:00
|
|
|
|
[[[self.view.layer sublayers] objectAtIndex: 0] setFrame: self.view.bounds];
|
2015-08-17 12:48:29 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-31 07:35:57 -04:00
|
|
|
|
-(BOOL)shouldAutorotate
|
|
|
|
|
{
|
|
|
|
|
if([self isViewLoaded] && self.view.window)
|
|
|
|
|
{
|
2015-08-17 12:48:29 -04:00
|
|
|
|
return YES;
|
2017-10-31 07:35:57 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-08-17 12:48:29 -04:00
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-15 03:08:32 -04:00
|
|
|
|
#pragma mark <UICollectionViewDataSource>
|
|
|
|
|
|
2017-10-31 07:35:57 -04:00
|
|
|
|
-(NSInteger)numberOfSectionsInCollectionView: (UICollectionView*)collectionView
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
2015-08-15 03:08:32 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-31 07:35:57 -04:00
|
|
|
|
-(NSString*)collectionView: (UICollectionView*)collectionView titleForHeaderInSection: (NSInteger)section
|
2015-08-15 12:44:56 -04:00
|
|
|
|
{
|
2017-10-31 07:35:57 -04:00
|
|
|
|
return @"";
|
2015-08-15 12:44:56 -04:00
|
|
|
|
}
|
2015-08-15 03:08:32 -04:00
|
|
|
|
|
2017-10-31 07:35:57 -04:00
|
|
|
|
-(NSInteger)collectionView: (UICollectionView*)collectionView numberOfItemsInSection: (NSInteger)section
|
|
|
|
|
{
|
|
|
|
|
return _bootables->size();
|
2015-08-15 03:08:32 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-31 07:35:57 -04:00
|
|
|
|
-(UICollectionViewCell*)collectionView: (UICollectionView*)collectionView cellForItemAtIndexPath: (NSIndexPath*)indexPath
|
|
|
|
|
{
|
|
|
|
|
CoverViewCell* cell = (CoverViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier: reuseIdentifier forIndexPath: indexPath];
|
|
|
|
|
|
|
|
|
|
auto bootable = (*_bootables)[indexPath.row];
|
|
|
|
|
UIImage* placeholder = [UIImage imageNamed: @"boxart.png"];
|
|
|
|
|
cell.nameLabel.text = [NSString stringWithUTF8String: bootable.title.c_str()];
|
|
|
|
|
cell.backgroundView = [[UIImageView alloc] initWithImage: placeholder];
|
|
|
|
|
|
|
|
|
|
if(!bootable.coverUrl.empty())
|
|
|
|
|
{
|
|
|
|
|
NSString* coverUrl = [NSString stringWithUTF8String: bootable.coverUrl.c_str()];
|
|
|
|
|
[(UIImageView*)cell.backgroundView sd_setImageWithURL: [NSURL URLWithString: coverUrl] placeholderImage: placeholder];
|
2015-08-31 14:59:13 -04:00
|
|
|
|
}
|
2017-10-31 07:35:57 -04:00
|
|
|
|
|
|
|
|
|
return cell;
|
2015-08-15 03:08:32 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark <UICollectionViewDelegate>
|
|
|
|
|
|
2015-08-15 04:06:15 -04:00
|
|
|
|
-(void)prepareForSegue: (UIStoryboardSegue*)segue sender: (id)sender
|
|
|
|
|
{
|
2017-10-31 07:35:57 -04:00
|
|
|
|
if([segue.identifier isEqualToString: @"showEmulator"])
|
|
|
|
|
{
|
|
|
|
|
NSIndexPath* indexPath = [[self.collectionView indexPathsForSelectedItems] objectAtIndex: 0];
|
|
|
|
|
auto bootable = (*_bootables)[indexPath.row];
|
|
|
|
|
BootablesDb::CClient::GetInstance().SetLastBootedTime(bootable.path, time(nullptr));
|
|
|
|
|
EmulatorViewController* emulatorViewController = segue.destinationViewController;
|
2017-11-01 09:46:23 -04:00
|
|
|
|
emulatorViewController.bootablePath = [NSString stringWithUTF8String: bootable.path.native().c_str()];
|
2017-10-31 07:35:57 -04:00
|
|
|
|
[self.collectionView deselectItemAtIndexPath: indexPath animated: NO];
|
|
|
|
|
}
|
2015-08-15 03:08:32 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-26 08:14:14 -04:00
|
|
|
|
-(IBAction)onExit: (id)sender
|
|
|
|
|
{
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-15 03:08:32 -04:00
|
|
|
|
@end
|