1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-09-01 01:29:03 +00:00
CLK/OSBindings/Mac/Clock Signal/Machine/CSROMFetcher.mm

55 lines
1.7 KiB
Plaintext
Raw Normal View History

2018-01-01 21:04:13 +00:00
//
// CSROMFetcher.m
// Clock Signal
//
// Created by Thomas Harte on 01/01/2018.
// Copyright 2018 Thomas Harte. All rights reserved.
2018-01-01 21:04:13 +00:00
//
#import <Foundation/Foundation.h>
#include "CSROMFetcher.hpp"
#import "NSBundle+DataResource.h"
#import "NSData+StdVector.h"
#include <string>
ROMMachine::ROMFetcher CSROMFetcher(ROM::Request *missing) {
return [missing] (const ROM::Request &roms) -> ROM::Map {
NSArray<NSURL *> *const supportURLs = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask];
ROM::Map results;
for(const auto &description: roms.all_descriptions()) {
for(const auto &file_name: description.file_names) {
NSData *fileData;
NSString *const subdirectory = [@"ROMImages/" stringByAppendingString:[NSString stringWithUTF8String:description.machine_name.c_str()]];
// Check for this file first within the application support directories.
for(NSURL *supportURL in supportURLs) {
NSURL *const fullURL = [[supportURL URLByAppendingPathComponent:subdirectory]
URLByAppendingPathComponent:[NSString stringWithUTF8String:file_name.c_str()]];
fileData = [NSData dataWithContentsOfURL:fullURL];
if(fileData) break;
}
2018-01-01 21:04:13 +00:00
// Failing that, check inside the application bundle.
if(!fileData) {
fileData = [[NSBundle mainBundle]
dataForResource:[NSString stringWithUTF8String:file_name.c_str()]
withExtension:nil
subdirectory:subdirectory];
}
// Store an appropriate result.
if(fileData) {
results[description.name] = fileData.stdVector8;
}
}
2018-01-01 21:04:13 +00:00
}
// TODO: sever all found ROMs from roms and store to missing, if provided.
2018-01-01 21:04:13 +00:00
return results;
};
2018-01-01 21:04:13 +00:00
}