parent
310ad34a4e
commit
4b87fa68c3
|
@ -12,6 +12,7 @@
|
||||||
FE0A7E9D2393A1FF001E6997 /* FBScanner.mm in Sources */ = {isa = PBXBuildFile; fileRef = FE0A7E9C2393A1FE001E6997 /* FBScanner.mm */; };
|
FE0A7E9D2393A1FF001E6997 /* FBScanner.mm in Sources */ = {isa = PBXBuildFile; fileRef = FE0A7E9C2393A1FE001E6997 /* FBScanner.mm */; };
|
||||||
FE0A7EA12394B87B001E6997 /* FBRomSetStatusAsNSImage.m in Sources */ = {isa = PBXBuildFile; fileRef = FE0A7E9F2394B87B001E6997 /* FBRomSetStatusAsNSImage.m */; };
|
FE0A7EA12394B87B001E6997 /* FBRomSetStatusAsNSImage.m in Sources */ = {isa = PBXBuildFile; fileRef = FE0A7E9F2394B87B001E6997 /* FBRomSetStatusAsNSImage.m */; };
|
||||||
FE0A7EA42394ED91001E6997 /* FBDropFileScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = FE0A7EA32394ED91001E6997 /* FBDropFileScrollView.m */; };
|
FE0A7EA42394ED91001E6997 /* FBDropFileScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = FE0A7EA32394ED91001E6997 /* FBDropFileScrollView.m */; };
|
||||||
|
FE0A7EA7239501FF001E6997 /* FBImporter.m in Sources */ = {isa = PBXBuildFile; fileRef = FE0A7EA5239501FF001E6997 /* FBImporter.m */; };
|
||||||
FE1B1092235615940065200C /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = FE1B1091235615940065200C /* AppDelegate.m */; };
|
FE1B1092235615940065200C /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = FE1B1091235615940065200C /* AppDelegate.m */; };
|
||||||
FE1B1094235615950065200C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FE1B1093235615950065200C /* Assets.xcassets */; };
|
FE1B1094235615950065200C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FE1B1093235615950065200C /* Assets.xcassets */; };
|
||||||
FE1B1097235615950065200C /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = FE1B1095235615950065200C /* MainMenu.xib */; };
|
FE1B1097235615950065200C /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = FE1B1095235615950065200C /* MainMenu.xib */; };
|
||||||
|
@ -1050,6 +1051,8 @@
|
||||||
FE0A7EA02394B87B001E6997 /* FBRomSetStatusAsNSImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBRomSetStatusAsNSImage.h; sourceTree = "<group>"; };
|
FE0A7EA02394B87B001E6997 /* FBRomSetStatusAsNSImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBRomSetStatusAsNSImage.h; sourceTree = "<group>"; };
|
||||||
FE0A7EA22394ED90001E6997 /* FBDropFileScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBDropFileScrollView.h; sourceTree = "<group>"; };
|
FE0A7EA22394ED90001E6997 /* FBDropFileScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBDropFileScrollView.h; sourceTree = "<group>"; };
|
||||||
FE0A7EA32394ED91001E6997 /* FBDropFileScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBDropFileScrollView.m; sourceTree = "<group>"; };
|
FE0A7EA32394ED91001E6997 /* FBDropFileScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBDropFileScrollView.m; sourceTree = "<group>"; };
|
||||||
|
FE0A7EA5239501FF001E6997 /* FBImporter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBImporter.m; sourceTree = "<group>"; };
|
||||||
|
FE0A7EA6239501FF001E6997 /* FBImporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBImporter.h; sourceTree = "<group>"; };
|
||||||
FE1B108D235615940065200C /* FinalBurn Neo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "FinalBurn Neo.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
FE1B108D235615940065200C /* FinalBurn Neo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "FinalBurn Neo.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
FE1B1090235615940065200C /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
|
FE1B1090235615940065200C /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
|
||||||
FE1B1091235615940065200C /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
|
FE1B1091235615940065200C /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
|
||||||
|
@ -4645,6 +4648,8 @@
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
FE1B287F235626280065200C /* burner_macos.h */,
|
FE1B287F235626280065200C /* burner_macos.h */,
|
||||||
|
FE0A7EA6239501FF001E6997 /* FBImporter.h */,
|
||||||
|
FE0A7EA5239501FF001E6997 /* FBImporter.m */,
|
||||||
FEED9E1A235845EE00B7AF83 /* FBMainThread.h */,
|
FEED9E1A235845EE00B7AF83 /* FBMainThread.h */,
|
||||||
FEED9E1B235845EE00B7AF83 /* FBMainThread.mm */,
|
FEED9E1B235845EE00B7AF83 /* FBMainThread.mm */,
|
||||||
FE2BC6CF2362D5BD00B9D150 /* FBMainThread+Etc.mm */,
|
FE2BC6CF2362D5BD00B9D150 /* FBMainThread+Etc.mm */,
|
||||||
|
@ -5626,6 +5631,7 @@
|
||||||
FE1B25C923561A760065200C /* k051316.cpp in Sources */,
|
FE1B25C923561A760065200C /* k051316.cpp in Sources */,
|
||||||
FE1B25AC23561A760065200C /* k056832.cpp in Sources */,
|
FE1B25AC23561A760065200C /* k056832.cpp in Sources */,
|
||||||
FE1B26B623561A770065200C /* d_mrdo.cpp in Sources */,
|
FE1B26B623561A770065200C /* d_mrdo.cpp in Sources */,
|
||||||
|
FE0A7EA7239501FF001E6997 /* FBImporter.m in Sources */,
|
||||||
FE1B27DD23561A790065200C /* mathbox.cpp in Sources */,
|
FE1B27DD23561A790065200C /* mathbox.cpp in Sources */,
|
||||||
FE1B268E23561A770065200C /* d_bionicc.cpp in Sources */,
|
FE1B268E23561A770065200C /* d_bionicc.cpp in Sources */,
|
||||||
FE1B24BF23561A750065200C /* smssystem.cpp in Sources */,
|
FE1B24BF23561A750065200C /* smssystem.cpp in Sources */,
|
||||||
|
@ -6129,7 +6135,7 @@
|
||||||
CODE_SIGN_ENTITLEMENTS = Emulator/FinalBurnNeo.entitlements;
|
CODE_SIGN_ENTITLEMENTS = Emulator/FinalBurnNeo.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 2;
|
CURRENT_PROJECT_VERSION = 3;
|
||||||
FRAMEWORK_SEARCH_PATHS = (
|
FRAMEWORK_SEARCH_PATHS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"$(LOCAL_LIBRARY_DIR)/Frameworks",
|
"$(LOCAL_LIBRARY_DIR)/Frameworks",
|
||||||
|
@ -6142,7 +6148,7 @@
|
||||||
"@executable_path/../Frameworks",
|
"@executable_path/../Frameworks",
|
||||||
);
|
);
|
||||||
MACOSX_DEPLOYMENT_TARGET = 10.13;
|
MACOSX_DEPLOYMENT_TARGET = 10.13;
|
||||||
MARKETING_VERSION = 1.01;
|
MARKETING_VERSION = 1.02;
|
||||||
OTHER_CFLAGS = (
|
OTHER_CFLAGS = (
|
||||||
"-DINLINE=\"static inline\"",
|
"-DINLINE=\"static inline\"",
|
||||||
"-DUSE_SPEEDHACKS",
|
"-DUSE_SPEEDHACKS",
|
||||||
|
@ -6189,7 +6195,7 @@
|
||||||
CODE_SIGN_ENTITLEMENTS = Emulator/FinalBurnNeo.entitlements;
|
CODE_SIGN_ENTITLEMENTS = Emulator/FinalBurnNeo.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 2;
|
CURRENT_PROJECT_VERSION = 3;
|
||||||
FRAMEWORK_SEARCH_PATHS = (
|
FRAMEWORK_SEARCH_PATHS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"$(LOCAL_LIBRARY_DIR)/Frameworks",
|
"$(LOCAL_LIBRARY_DIR)/Frameworks",
|
||||||
|
@ -6202,7 +6208,7 @@
|
||||||
"@executable_path/../Frameworks",
|
"@executable_path/../Frameworks",
|
||||||
);
|
);
|
||||||
MACOSX_DEPLOYMENT_TARGET = 10.13;
|
MACOSX_DEPLOYMENT_TARGET = 10.13;
|
||||||
MARKETING_VERSION = 1.01;
|
MARKETING_VERSION = 1.02;
|
||||||
OTHER_CFLAGS = (
|
OTHER_CFLAGS = (
|
||||||
"-DINLINE=\"static inline\"",
|
"-DINLINE=\"static inline\"",
|
||||||
"-DUSE_SPEEDHACKS",
|
"-DUSE_SPEEDHACKS",
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
#import "FBScanner.h"
|
#import "FBScanner.h"
|
||||||
|
#import "FBImporter.h"
|
||||||
#import "FBDropFileScrollView.h"
|
#import "FBDropFileScrollView.h"
|
||||||
|
|
||||||
@interface FBLauncherItem: NSObject
|
@interface FBLauncherItem: NSObject
|
||||||
|
@ -20,7 +21,7 @@
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface FBLauncherController : NSWindowController<FBScannerDelegate, FBDropFileScrollViewDelegate>
|
@interface FBLauncherController : NSWindowController<FBScannerDelegate, FBImporterDelegate, FBDropFileScrollViewDelegate>
|
||||||
{
|
{
|
||||||
IBOutlet NSPanel *progressPanel;
|
IBOutlet NSPanel *progressPanel;
|
||||||
IBOutlet NSProgressIndicator *progressPanelBar;
|
IBOutlet NSProgressIndicator *progressPanelBar;
|
||||||
|
|
|
@ -33,11 +33,15 @@
|
||||||
- (NSString *) setCachePath;
|
- (NSString *) setCachePath;
|
||||||
- (NSSet<NSString *> *) supportedRomSets;
|
- (NSSet<NSString *> *) supportedRomSets;
|
||||||
|
|
||||||
|
- (void) importFiles:(NSArray<NSString *> *) files;
|
||||||
|
- (void) initiateScan;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation FBLauncherController
|
@implementation FBLauncherController
|
||||||
{
|
{
|
||||||
FBScanner *scanner;
|
FBScanner *scanner;
|
||||||
|
FBImporter *importer;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) init
|
- (id) init
|
||||||
|
@ -54,8 +58,14 @@
|
||||||
if ([NSFileManager.defaultManager fileExistsAtPath:self.setCachePath]) {
|
if ([NSFileManager.defaultManager fileExistsAtPath:self.setCachePath]) {
|
||||||
// Restore from cache
|
// Restore from cache
|
||||||
NSArray<FBROMSet *> *cached = [NSKeyedUnarchiver unarchiveObjectWithFile:self.setCachePath];
|
NSArray<FBROMSet *> *cached = [NSKeyedUnarchiver unarchiveObjectWithFile:self.setCachePath];
|
||||||
if (cached)
|
if (cached) {
|
||||||
[self reloadSets:cached];
|
[self reloadSets:cached];
|
||||||
|
|
||||||
|
// Restore previous selection
|
||||||
|
NSData *data = [NSUserDefaults.standardUserDefaults objectForKey:@"selectedGame"];
|
||||||
|
romSetTreeController.selectionIndexPaths = [NSKeyedUnarchiver unarchiveTopLevelObjectWithData:data
|
||||||
|
error:nil];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_romSets.count == 0)
|
if (_romSets.count == 0)
|
||||||
|
@ -70,9 +80,10 @@
|
||||||
|
|
||||||
- (void) windowWillClose:(NSNotification *) notification
|
- (void) windowWillClose:(NSNotification *) notification
|
||||||
{
|
{
|
||||||
@synchronized (self) {
|
[NSUserDefaults.standardUserDefaults setObject:[NSKeyedArchiver archivedDataWithRootObject:romSetTreeController.selectionIndexPaths]
|
||||||
[scanner cancel];
|
forKey:@"selectedGame"];
|
||||||
}
|
[importer cancel];
|
||||||
|
[scanner cancel];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - FBScannerDelegate
|
#pragma mark - FBScannerDelegate
|
||||||
|
@ -87,16 +98,14 @@
|
||||||
completionHandler:^(NSModalResponse returnCode) { }];
|
completionHandler:^(NSModalResponse returnCode) { }];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) progressDidUpdate:(float) progress
|
- (void) scanDidProgress:(float) progress
|
||||||
{
|
{
|
||||||
progressPanelBar.doubleValue = progress;
|
progressPanelBar.doubleValue = progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) scanDidEnd:(NSArray<FBROMSet *> *) romSets
|
- (void) scanDidEnd:(NSArray<FBROMSet *> *) romSets
|
||||||
{
|
{
|
||||||
@synchronized (self) {
|
scanner = nil;
|
||||||
scanner = nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
[self.window endSheet:progressPanel];
|
[self.window endSheet:progressPanel];
|
||||||
|
|
||||||
|
@ -110,6 +119,37 @@
|
||||||
[self reloadSets:romSets];
|
[self reloadSets:romSets];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - FBImporterDelegate
|
||||||
|
|
||||||
|
- (void) importDidStart
|
||||||
|
{
|
||||||
|
progressPanelBar.doubleValue = 0;
|
||||||
|
progressPanelLabel.stringValue = NSLocalizedString(@"Importing...", nil);
|
||||||
|
progressPanelCancelButton.enabled = YES;
|
||||||
|
|
||||||
|
[self.window beginSheet:progressPanel
|
||||||
|
completionHandler:^(NSModalResponse returnCode) { }];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) importDidProgress:(float) progress
|
||||||
|
{
|
||||||
|
progressPanelBar.doubleValue = progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) importDidEnd:(BOOL) isCancelled
|
||||||
|
filesCopied:(int) count
|
||||||
|
{
|
||||||
|
importer = nil;
|
||||||
|
NSLog(@"Import complete; %d files copied", count);
|
||||||
|
|
||||||
|
[self.window endSheet:progressPanel];
|
||||||
|
|
||||||
|
if (isCancelled || count < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
[self rescanSets:self];
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - FBDropFileScrollView
|
#pragma mark - FBDropFileScrollView
|
||||||
|
|
||||||
- (BOOL) isDropAcceptable:(NSArray<NSString *> *) paths
|
- (BOOL) isDropAcceptable:(NSArray<NSString *> *) paths
|
||||||
|
@ -117,12 +157,16 @@
|
||||||
__block BOOL acceptable = YES;
|
__block BOOL acceptable = YES;
|
||||||
NSSet<NSString *> *supportedFormats = self.appDelegate.supportedFormats;
|
NSSet<NSString *> *supportedFormats = self.appDelegate.supportedFormats;
|
||||||
NSSet<NSString *> *supportedArchives = self.supportedRomSets;
|
NSSet<NSString *> *supportedArchives = self.supportedRomSets;
|
||||||
|
NSString *romPath = self.appDelegate.romPath;
|
||||||
|
|
||||||
[paths enumerateObjectsUsingBlock:^(NSString *path, NSUInteger idx, BOOL *stop) {
|
[paths enumerateObjectsUsingBlock:^(NSString *path, NSUInteger idx, BOOL *stop) {
|
||||||
NSString *filename = path.lastPathComponent;
|
NSString *filename = path.lastPathComponent;
|
||||||
|
NSString *parent = path.stringByDeletingLastPathComponent.stringByResolvingSymlinksInPath;
|
||||||
|
|
||||||
// Check extension && archive name
|
// Check extension && archive name
|
||||||
if (![supportedFormats containsObject:filename.pathExtension]
|
if (![supportedFormats containsObject:filename.pathExtension]
|
||||||
|| ![supportedArchives containsObject:filename.stringByDeletingPathExtension]) {
|
|| ![supportedArchives containsObject:filename.stringByDeletingPathExtension]
|
||||||
|
|| [parent isEqualToString:romPath]) {
|
||||||
acceptable = NO;
|
acceptable = NO;
|
||||||
*stop = YES;
|
*stop = YES;
|
||||||
}
|
}
|
||||||
|
@ -133,21 +177,14 @@
|
||||||
|
|
||||||
- (void) dropDidComplete:(NSArray<NSString *> *) paths
|
- (void) dropDidComplete:(NSArray<NSString *> *) paths
|
||||||
{
|
{
|
||||||
// FIXME
|
[self importFiles:paths];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Actions
|
#pragma mark - Actions
|
||||||
|
|
||||||
- (void) rescanSets:(id) sender
|
- (void) rescanSets:(id) sender
|
||||||
{
|
{
|
||||||
@synchronized (self) {
|
[self initiateScan];
|
||||||
if (!scanner) {
|
|
||||||
scanner = [FBScanner new];
|
|
||||||
scanner.rootPath = AppDelegate.sharedInstance.romPath;
|
|
||||||
scanner.delegate = self;
|
|
||||||
[scanner start];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) cancelProgress:(id) sender
|
- (void) cancelProgress:(id) sender
|
||||||
|
@ -155,9 +192,8 @@
|
||||||
progressPanelCancelButton.enabled = NO;
|
progressPanelCancelButton.enabled = NO;
|
||||||
progressPanelLabel.stringValue = NSLocalizedString(@"Cancelling...", nil);
|
progressPanelLabel.stringValue = NSLocalizedString(@"Cancelling...", nil);
|
||||||
|
|
||||||
@synchronized (self) {
|
[importer cancel];
|
||||||
[scanner cancel];
|
[scanner cancel];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) launchSet:(id) sender
|
- (void) launchSet:(id) sender
|
||||||
|
@ -179,6 +215,9 @@
|
||||||
|
|
||||||
- (void) reloadSets:(NSArray<FBROMSet *> *) romSets
|
- (void) reloadSets:(NSArray<FBROMSet *> *) romSets
|
||||||
{
|
{
|
||||||
|
// Save current selection
|
||||||
|
NSArray<NSIndexPath *> *selection = romSetTreeController.selectionIndexPaths;
|
||||||
|
|
||||||
// Clear the master list
|
// Clear the master list
|
||||||
[(NSMutableArray *) _romSets removeAllObjects];
|
[(NSMutableArray *) _romSets removeAllObjects];
|
||||||
|
|
||||||
|
@ -211,6 +250,9 @@
|
||||||
}];
|
}];
|
||||||
|
|
||||||
[romSetTreeController rearrangeObjects];
|
[romSetTreeController rearrangeObjects];
|
||||||
|
|
||||||
|
// Restore selection
|
||||||
|
romSetTreeController.selectionIndexPaths = selection;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *) setCachePath
|
- (NSString *) setCachePath
|
||||||
|
@ -231,4 +273,29 @@
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) importFiles:(NSArray<NSString *> *) files
|
||||||
|
{
|
||||||
|
if (scanner || importer)
|
||||||
|
return;
|
||||||
|
|
||||||
|
importer = [FBImporter new];
|
||||||
|
importer.destinationPath = AppDelegate.sharedInstance.romPath;
|
||||||
|
importer.sourcePaths = files;
|
||||||
|
importer.delegate = self;
|
||||||
|
|
||||||
|
[importer start];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) initiateScan
|
||||||
|
{
|
||||||
|
if (scanner || importer)
|
||||||
|
return;
|
||||||
|
|
||||||
|
scanner = [FBScanner new];
|
||||||
|
scanner.rootPath = AppDelegate.sharedInstance.romPath;
|
||||||
|
scanner.delegate = self;
|
||||||
|
|
||||||
|
[scanner start];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
//
|
||||||
|
// FBImporter.h
|
||||||
|
// Emulator
|
||||||
|
//
|
||||||
|
// Created by Akop Karapetyan on 12/02/19.
|
||||||
|
// Copyright © 2019 Akop Karapetyan. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
@protocol FBImporterDelegate<NSObject>
|
||||||
|
|
||||||
|
@optional
|
||||||
|
- (void) importDidStart;
|
||||||
|
- (void) importDidProgress:(float) progress;
|
||||||
|
- (void) importDidEnd:(BOOL) isCancelled
|
||||||
|
filesCopied:(int) count;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface FBImporter : NSThread
|
||||||
|
|
||||||
|
@property NSArray<NSString *> *sourcePaths;
|
||||||
|
@property NSString *destinationPath;
|
||||||
|
|
||||||
|
@property (nonatomic, weak) id<FBImporterDelegate> delegate;
|
||||||
|
|
||||||
|
@end
|
|
@ -0,0 +1,74 @@
|
||||||
|
//
|
||||||
|
// FBImporter.m
|
||||||
|
// Emulator
|
||||||
|
//
|
||||||
|
// Created by Akop Karapetyan on 12/02/19.
|
||||||
|
// Copyright © 2019 Akop Karapetyan. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "FBImporter.h"
|
||||||
|
|
||||||
|
#pragma mark - FBImporter
|
||||||
|
|
||||||
|
@implementation FBImporter
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
- (instancetype) init
|
||||||
|
{
|
||||||
|
if (self = [super init]) {
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - NSThread
|
||||||
|
|
||||||
|
- (void) main
|
||||||
|
{
|
||||||
|
NSArray<NSString *> *sourcePaths = [NSArray arrayWithArray:_sourcePaths];
|
||||||
|
NSString *destinationPath = _destinationPath;
|
||||||
|
|
||||||
|
if (!sourcePaths || sourcePaths.count == 0 || !destinationPath)
|
||||||
|
return;
|
||||||
|
|
||||||
|
id<FBImporterDelegate> del = _delegate;
|
||||||
|
if ([del respondsToSelector:@selector(importDidStart)])
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{ [del importDidStart]; });
|
||||||
|
|
||||||
|
__block int filesCopied = 0;
|
||||||
|
[sourcePaths enumerateObjectsUsingBlock:^(NSString *source, NSUInteger idx, BOOL *stop) {
|
||||||
|
NSString *sourceFilename = source.lastPathComponent;
|
||||||
|
NSURL *destinationUrl = [NSURL fileURLWithPath:[destinationPath stringByAppendingPathComponent:sourceFilename]];
|
||||||
|
|
||||||
|
// FIXME...
|
||||||
|
NSError *error = nil;
|
||||||
|
// Trash any existing file
|
||||||
|
[NSFileManager.defaultManager trashItemAtURL:destinationUrl
|
||||||
|
resultingItemURL:nil
|
||||||
|
error:&error];
|
||||||
|
// Copy new file to destination
|
||||||
|
BOOL copyOK = [NSFileManager.defaultManager copyItemAtURL:[NSURL fileURLWithPath:source]
|
||||||
|
toURL:destinationUrl
|
||||||
|
error:&error];
|
||||||
|
|
||||||
|
if (self.isCancelled)
|
||||||
|
*stop = YES;
|
||||||
|
if (copyOK)
|
||||||
|
filesCopied++;
|
||||||
|
|
||||||
|
id<FBImporterDelegate> del = _delegate;
|
||||||
|
if ([del respondsToSelector:@selector(importDidProgress:)])
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[del importDidProgress:(float) idx / sourcePaths.count];
|
||||||
|
});
|
||||||
|
}];
|
||||||
|
|
||||||
|
del = _delegate;
|
||||||
|
if ([del respondsToSelector:@selector(importDidEnd:filesCopied:)])
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[del importDidEnd:self.isCancelled
|
||||||
|
filesCopied:filesCopied];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
@optional
|
@optional
|
||||||
- (void) scanDidStart;
|
- (void) scanDidStart;
|
||||||
- (void) progressDidUpdate:(float) progress;
|
- (void) scanDidProgress:(float) progress;
|
||||||
- (void) scanDidEnd:(NSArray<FBROMSet *> *) romSets;
|
- (void) scanDidEnd:(NSArray<FBROMSet *> *) romSets;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -88,9 +88,9 @@
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
del = _delegate;
|
del = _delegate;
|
||||||
if ([del respondsToSelector:@selector(progressDidUpdate:)])
|
if ([del respondsToSelector:@selector(scanDidProgress:)])
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[del progressDidUpdate:(float)i/nBurnDrvCount];
|
[del scanDidProgress:(float)i/nBurnDrvCount];
|
||||||
});
|
});
|
||||||
|
|
||||||
nBurnDrvActive = i;
|
nBurnDrvActive = i;
|
||||||
|
|
Loading…
Reference in New Issue