Added GameCollection model object
This commit is contained in:
parent
43a692bece
commit
3dcf6b9df0
@ -186,7 +186,17 @@ class DatabaseManager
|
|||||||
game.name = URL.URLByDeletingPathExtension?.lastPathComponent ?? NSLocalizedString("Game", comment: "")
|
game.name = URL.URLByDeletingPathExtension?.lastPathComponent ?? NSLocalizedString("Game", comment: "")
|
||||||
game.identifier = identifier
|
game.identifier = identifier
|
||||||
game.filename = filename
|
game.filename = filename
|
||||||
game.typeIdentifier = Game.typeIdentifierForURL(URL) ?? kUTTypeDeltaGame as String
|
|
||||||
|
if let pathExtension = URL.pathExtension,
|
||||||
|
gameCollection = GameCollection.gameSystemCollectionForPathExtension(pathExtension, inManagedObjectContext: managedObjectContext)
|
||||||
|
{
|
||||||
|
game.typeIdentifier = gameCollection.identifier
|
||||||
|
game.gameCollections.insert(gameCollection)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
game.typeIdentifier = kUTTypeDeltaGame as String
|
||||||
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|||||||
@ -19,6 +19,8 @@ enum GameAttributes: String
|
|||||||
case identifier
|
case identifier
|
||||||
case name
|
case name
|
||||||
case typeIdentifier
|
case typeIdentifier
|
||||||
|
|
||||||
|
case gameCollections
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Game
|
extension Game
|
||||||
@ -28,4 +30,6 @@ extension Game
|
|||||||
@NSManaged var identifier: String
|
@NSManaged var identifier: String
|
||||||
@NSManaged var name: String
|
@NSManaged var name: String
|
||||||
@NSManaged var typeIdentifier: String
|
@NSManaged var typeIdentifier: String
|
||||||
|
|
||||||
|
@NSManaged var gameCollections: Set<GameCollection>
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,20 +23,6 @@ class Game: NSManagedObject, GameType
|
|||||||
|
|
||||||
extension Game
|
extension Game
|
||||||
{
|
{
|
||||||
class func typeIdentifierForURL(URL: NSURL) -> String?
|
|
||||||
{
|
|
||||||
guard let pathExtension = URL.pathExtension else { return nil }
|
|
||||||
|
|
||||||
switch pathExtension
|
|
||||||
{
|
|
||||||
case "smc": fallthrough
|
|
||||||
case "sfc": fallthrough
|
|
||||||
case "fig": return kUTTypeSNESGame as String
|
|
||||||
|
|
||||||
default: return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class func supportedTypeIdentifiers() -> Set<String>
|
class func supportedTypeIdentifiers() -> Set<String>
|
||||||
{
|
{
|
||||||
return [kUTTypeSNESGame as String]
|
return [kUTTypeSNESGame as String]
|
||||||
|
|||||||
@ -0,0 +1,31 @@
|
|||||||
|
//
|
||||||
|
// GameCollection+CoreDataProperties.swift
|
||||||
|
// Delta
|
||||||
|
//
|
||||||
|
// Created by Riley Testut on 11/1/15.
|
||||||
|
// Copyright © 2015 Riley Testut. All rights reserved.
|
||||||
|
//
|
||||||
|
// Choose "Create NSManagedObject Subclass…" from the Core Data editor menu
|
||||||
|
// to delete and recreate this implementation file for your updated model.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import CoreData
|
||||||
|
|
||||||
|
enum GameCollectionAttributes: String
|
||||||
|
{
|
||||||
|
case name
|
||||||
|
case identifier
|
||||||
|
case shortName
|
||||||
|
|
||||||
|
case games
|
||||||
|
}
|
||||||
|
|
||||||
|
extension GameCollection {
|
||||||
|
|
||||||
|
@NSManaged var name: String
|
||||||
|
@NSManaged var identifier: String
|
||||||
|
@NSManaged var shortName: String?
|
||||||
|
|
||||||
|
@NSManaged var games: Set<Game>
|
||||||
|
}
|
||||||
52
Common/Database/Model/GameCollection.swift
Normal file
52
Common/Database/Model/GameCollection.swift
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
//
|
||||||
|
// GameCollection.swift
|
||||||
|
// Delta
|
||||||
|
//
|
||||||
|
// Created by Riley Testut on 11/1/15.
|
||||||
|
// Copyright © 2015 Riley Testut. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import CoreData
|
||||||
|
|
||||||
|
import SNESDeltaCore
|
||||||
|
|
||||||
|
@objc(GameCollection)
|
||||||
|
class GameCollection: NSManagedObject
|
||||||
|
{
|
||||||
|
class func gameSystemCollectionForPathExtension(pathExtension: String?, inManagedObjectContext managedObjectContext: NSManagedObjectContext) -> GameCollection?
|
||||||
|
{
|
||||||
|
guard let pathExtension = pathExtension else { return nil }
|
||||||
|
|
||||||
|
let identifier: String
|
||||||
|
let name: String
|
||||||
|
let shortName: String
|
||||||
|
|
||||||
|
switch pathExtension
|
||||||
|
{
|
||||||
|
case "smc": fallthrough
|
||||||
|
case "sfc": fallthrough
|
||||||
|
case "fig":
|
||||||
|
identifier = kUTTypeSNESGame as String
|
||||||
|
name = "Super Nintendo Entertainment System"
|
||||||
|
shortName = "SNES"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
default: return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let predicate = NSPredicate(format: "%K == %@", GameCollectionAttributes.identifier.rawValue, identifier)
|
||||||
|
|
||||||
|
var gameCollection = GameCollection.instancesWithPredicate(predicate, inManagedObjectContext: managedObjectContext, type: GameCollection.self).first
|
||||||
|
if gameCollection == nil
|
||||||
|
{
|
||||||
|
gameCollection = GameCollection.insertIntoManagedObjectContext(managedObjectContext)
|
||||||
|
gameCollection?.identifier = identifier
|
||||||
|
gameCollection?.name = name
|
||||||
|
gameCollection?.shortName = shortName
|
||||||
|
}
|
||||||
|
|
||||||
|
return gameCollection
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -14,6 +14,18 @@
|
|||||||
<attribute name="identifier" attributeType="String" syncable="YES"/>
|
<attribute name="identifier" attributeType="String" syncable="YES"/>
|
||||||
<attribute name="name" attributeType="String" syncable="YES"/>
|
<attribute name="name" attributeType="String" syncable="YES"/>
|
||||||
<attribute name="typeIdentifier" attributeType="String" syncable="YES"/>
|
<attribute name="typeIdentifier" attributeType="String" syncable="YES"/>
|
||||||
|
<relationship name="gameCollections" toMany="YES" deletionRule="Nullify" destinationEntity="GameCollection" inverseName="games" inverseEntity="GameCollection" syncable="YES"/>
|
||||||
|
<uniquenessConstraints>
|
||||||
|
<uniquenessConstraint>
|
||||||
|
<constraint value="identifier"/>
|
||||||
|
</uniquenessConstraint>
|
||||||
|
</uniquenessConstraints>
|
||||||
|
</entity>
|
||||||
|
<entity name="GameCollection" representedClassName="GameCollection" syncable="YES">
|
||||||
|
<attribute name="identifier" attributeType="String" syncable="YES"/>
|
||||||
|
<attribute name="name" attributeType="String" syncable="YES"/>
|
||||||
|
<attribute name="shortName" optional="YES" attributeType="String" syncable="YES"/>
|
||||||
|
<relationship name="games" toMany="YES" deletionRule="Nullify" destinationEntity="Game" inverseName="gameCollections" inverseEntity="Game" syncable="YES"/>
|
||||||
<uniquenessConstraints>
|
<uniquenessConstraints>
|
||||||
<uniquenessConstraint>
|
<uniquenessConstraint>
|
||||||
<constraint value="identifier"/>
|
<constraint value="identifier"/>
|
||||||
@ -21,6 +33,7 @@
|
|||||||
</uniquenessConstraints>
|
</uniquenessConstraints>
|
||||||
</entity>
|
</entity>
|
||||||
<elements>
|
<elements>
|
||||||
<element name="Game" positionX="-198" positionY="9" width="128" height="120"/>
|
<element name="Game" positionX="-200" positionY="9" width="128" height="133"/>
|
||||||
|
<element name="GameCollection" positionX="-198" positionY="-207" width="128" height="103"/>
|
||||||
</elements>
|
</elements>
|
||||||
</model>
|
</model>
|
||||||
@ -57,8 +57,11 @@ class GamePickerController: NSObject
|
|||||||
{
|
{
|
||||||
let contents = try NSFileManager.defaultManager().contentsOfDirectoryAtURL(documentsDirectoryURL!, includingPropertiesForKeys: nil, options: .SkipsHiddenFiles)
|
let contents = try NSFileManager.defaultManager().contentsOfDirectoryAtURL(documentsDirectoryURL!, includingPropertiesForKeys: nil, options: .SkipsHiddenFiles)
|
||||||
|
|
||||||
let gameURLs = contents.filter({ Game.typeIdentifierForURL($0) != nil })
|
let managedObjectContext = DatabaseManager.sharedManager.backgroundManagedObjectContext()
|
||||||
self.importGamesAtURLs(gameURLs)
|
managedObjectContext.performBlock() {
|
||||||
|
let gameURLs = contents.filter({ GameCollection.gameSystemCollectionForPathExtension($0.pathExtension, inManagedObjectContext: managedObjectContext) != nil })
|
||||||
|
self.importGamesAtURLs(gameURLs)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch let error as NSError
|
catch let error as NSError
|
||||||
|
|||||||
@ -52,6 +52,10 @@
|
|||||||
BFB141191BE46934004FBF46 /* GameCollectionViewDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFB141171BE46934004FBF46 /* GameCollectionViewDataSource.swift */; };
|
BFB141191BE46934004FBF46 /* GameCollectionViewDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFB141171BE46934004FBF46 /* GameCollectionViewDataSource.swift */; };
|
||||||
BFC134E11AAD82460087AD7B /* SNESDeltaCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BFC134E01AAD82460087AD7B /* SNESDeltaCore.framework */; };
|
BFC134E11AAD82460087AD7B /* SNESDeltaCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BFC134E01AAD82460087AD7B /* SNESDeltaCore.framework */; };
|
||||||
BFC134E21AAD82470087AD7B /* SNESDeltaCore.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BFC134E01AAD82460087AD7B /* SNESDeltaCore.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
BFC134E21AAD82470087AD7B /* SNESDeltaCore.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BFC134E01AAD82460087AD7B /* SNESDeltaCore.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||||
|
BFC273181BE6152200D22B05 /* GameCollection+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFC273161BE6152200D22B05 /* GameCollection+CoreDataProperties.swift */; };
|
||||||
|
BFC273191BE6152200D22B05 /* GameCollection+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFC273161BE6152200D22B05 /* GameCollection+CoreDataProperties.swift */; };
|
||||||
|
BFC2731A1BE6152200D22B05 /* GameCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFC273171BE6152200D22B05 /* GameCollection.swift */; };
|
||||||
|
BFC2731B1BE6152200D22B05 /* GameCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFC273171BE6152200D22B05 /* GameCollection.swift */; };
|
||||||
BFDB28451BC9DA7B001D0C83 /* GamePickerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFDB28441BC9DA7B001D0C83 /* GamePickerController.swift */; };
|
BFDB28451BC9DA7B001D0C83 /* GamePickerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFDB28441BC9DA7B001D0C83 /* GamePickerController.swift */; };
|
||||||
BFDE393A1BC0CEDF003F72E8 /* Game+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFDE39381BC0CEDF003F72E8 /* Game+CoreDataProperties.swift */; };
|
BFDE393A1BC0CEDF003F72E8 /* Game+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFDE39381BC0CEDF003F72E8 /* Game+CoreDataProperties.swift */; };
|
||||||
BFDE393B1BC0CEDF003F72E8 /* Game+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFDE39381BC0CEDF003F72E8 /* Game+CoreDataProperties.swift */; };
|
BFDE393B1BC0CEDF003F72E8 /* Game+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFDE39381BC0CEDF003F72E8 /* Game+CoreDataProperties.swift */; };
|
||||||
@ -133,6 +137,8 @@
|
|||||||
BFAA1FF31B8AD7F900495943 /* ControllersSettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ControllersSettingsViewController.swift; sourceTree = "<group>"; };
|
BFAA1FF31B8AD7F900495943 /* ControllersSettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ControllersSettingsViewController.swift; sourceTree = "<group>"; };
|
||||||
BFB141171BE46934004FBF46 /* GameCollectionViewDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = GameCollectionViewDataSource.swift; path = "Collection View/GameCollectionViewDataSource.swift"; sourceTree = "<group>"; };
|
BFB141171BE46934004FBF46 /* GameCollectionViewDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = GameCollectionViewDataSource.swift; path = "Collection View/GameCollectionViewDataSource.swift"; sourceTree = "<group>"; };
|
||||||
BFC134E01AAD82460087AD7B /* SNESDeltaCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SNESDeltaCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
BFC134E01AAD82460087AD7B /* SNESDeltaCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SNESDeltaCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
|
BFC273161BE6152200D22B05 /* GameCollection+CoreDataProperties.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "GameCollection+CoreDataProperties.swift"; sourceTree = "<group>"; };
|
||||||
|
BFC273171BE6152200D22B05 /* GameCollection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GameCollection.swift; sourceTree = "<group>"; };
|
||||||
BFDB28441BC9DA7B001D0C83 /* GamePickerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GamePickerController.swift; sourceTree = "<group>"; };
|
BFDB28441BC9DA7B001D0C83 /* GamePickerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GamePickerController.swift; sourceTree = "<group>"; };
|
||||||
BFDE39381BC0CEDF003F72E8 /* Game+CoreDataProperties.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Game+CoreDataProperties.swift"; sourceTree = "<group>"; };
|
BFDE39381BC0CEDF003F72E8 /* Game+CoreDataProperties.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Game+CoreDataProperties.swift"; sourceTree = "<group>"; };
|
||||||
BFDE39391BC0CEDF003F72E8 /* Game.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Game.swift; sourceTree = "<group>"; };
|
BFDE39391BC0CEDF003F72E8 /* Game.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Game.swift; sourceTree = "<group>"; };
|
||||||
@ -198,6 +204,7 @@
|
|||||||
BF4566E31BC09026007BFA1A /* Common */ = {
|
BF4566E31BC09026007BFA1A /* Common */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
BFC273151BE612CE00D22B05 /* Model */,
|
||||||
BFF1E55F1BE04BF6000E9EF6 /* Components */,
|
BFF1E55F1BE04BF6000E9EF6 /* Components */,
|
||||||
BF9257571BD8244800B109DA /* Collection View */,
|
BF9257571BD8244800B109DA /* Collection View */,
|
||||||
BF4566E41BC0902E007BFA1A /* Database */,
|
BF4566E41BC0902E007BFA1A /* Database */,
|
||||||
@ -219,9 +226,11 @@
|
|||||||
BF4566E51BC09033007BFA1A /* Model */ = {
|
BF4566E51BC09033007BFA1A /* Model */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
BFDE39381BC0CEDF003F72E8 /* Game+CoreDataProperties.swift */,
|
|
||||||
BFDE39391BC0CEDF003F72E8 /* Game.swift */,
|
|
||||||
BF4566E61BC090B6007BFA1A /* Model.xcdatamodeld */,
|
BF4566E61BC090B6007BFA1A /* Model.xcdatamodeld */,
|
||||||
|
BFDE39391BC0CEDF003F72E8 /* Game.swift */,
|
||||||
|
BFDE39381BC0CEDF003F72E8 /* Game+CoreDataProperties.swift */,
|
||||||
|
BFC273171BE6152200D22B05 /* GameCollection.swift */,
|
||||||
|
BFC273161BE6152200D22B05 /* GameCollection+CoreDataProperties.swift */,
|
||||||
);
|
);
|
||||||
path = Model;
|
path = Model;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -299,6 +308,13 @@
|
|||||||
path = Settings;
|
path = Settings;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
BFC273151BE612CE00D22B05 /* Model */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
);
|
||||||
|
name = Model;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
BFDB28431BC9D9D1001D0C83 /* Importing */ = {
|
BFDB28431BC9D9D1001D0C83 /* Importing */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
@ -594,9 +610,11 @@
|
|||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
BFF4EA021BE1B2420056AAA4 /* GameCollectionViewLayoutAttributes.swift in Sources */,
|
BFF4EA021BE1B2420056AAA4 /* GameCollectionViewLayoutAttributes.swift in Sources */,
|
||||||
|
BFC273191BE6152200D22B05 /* GameCollection+CoreDataProperties.swift in Sources */,
|
||||||
BF6BB2411BB73FE800CCF94A /* GameSelectionViewController.swift in Sources */,
|
BF6BB2411BB73FE800CCF94A /* GameSelectionViewController.swift in Sources */,
|
||||||
BF27CC8F1BCA010200A20D89 /* GamePickerController.swift in Sources */,
|
BF27CC8F1BCA010200A20D89 /* GamePickerController.swift in Sources */,
|
||||||
BFDE393D1BC0CEDF003F72E8 /* Game.swift in Sources */,
|
BFDE393D1BC0CEDF003F72E8 /* Game.swift in Sources */,
|
||||||
|
BFC2731B1BE6152200D22B05 /* GameCollection.swift in Sources */,
|
||||||
BF762E9F1BC19D31002C8866 /* DatabaseManager.swift in Sources */,
|
BF762E9F1BC19D31002C8866 /* DatabaseManager.swift in Sources */,
|
||||||
BFDE393B1BC0CEDF003F72E8 /* Game+CoreDataProperties.swift in Sources */,
|
BFDE393B1BC0CEDF003F72E8 /* Game+CoreDataProperties.swift in Sources */,
|
||||||
BF27CC911BCB156200A20D89 /* EmulationViewController.swift in Sources */,
|
BF27CC911BCB156200A20D89 /* EmulationViewController.swift in Sources */,
|
||||||
@ -625,6 +643,8 @@
|
|||||||
BFFA71DD1AAC406100EE9DD1 /* AppDelegate.swift in Sources */,
|
BFFA71DD1AAC406100EE9DD1 /* AppDelegate.swift in Sources */,
|
||||||
BF4566E81BC090B6007BFA1A /* Model.xcdatamodeld in Sources */,
|
BF4566E81BC090B6007BFA1A /* Model.xcdatamodeld in Sources */,
|
||||||
BFDE393C1BC0CEDF003F72E8 /* Game.swift in Sources */,
|
BFDE393C1BC0CEDF003F72E8 /* Game.swift in Sources */,
|
||||||
|
BFC273181BE6152200D22B05 /* GameCollection+CoreDataProperties.swift in Sources */,
|
||||||
|
BFC2731A1BE6152200D22B05 /* GameCollection.swift in Sources */,
|
||||||
BFF1E5641BE04CAF000E9EF6 /* BoxArtImageView.swift in Sources */,
|
BFF1E5641BE04CAF000E9EF6 /* BoxArtImageView.swift in Sources */,
|
||||||
BF762EAB1BC1B076002C8866 /* NSManagedObject+Conveniences.swift in Sources */,
|
BF762EAB1BC1B076002C8866 /* NSManagedObject+Conveniences.swift in Sources */,
|
||||||
BFA5342A1BDC6B520088F1BE /* GameCollectionViewLayout.swift in Sources */,
|
BFA5342A1BDC6B520088F1BE /* GameCollectionViewLayout.swift in Sources */,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user