Compare commits

...

280 Commits

Author SHA1 Message Date
忆海16
7399e8cd5c xibme 2024-05-29 14:55:03 +08:00
忆海16
8161aa6d8c 第一次提交 2024-05-27 11:54:20 +08:00
忆海16
18c51d8d1b 第一次提交 2024-05-27 11:53:32 +08:00
Riley Testut
af01b97faf Fixes N64 games crashing when compiled with Xcode 15
# Conflicts:
#	Delta.xcodeproj/project.pbxproj
2023-09-18 16:27:22 -05:00
Riley Testut
62ebf05a8f Updates wording of “Database Repaired” alert to mention conflicts.txt 2023-08-11 21:52:01 -05:00
Riley Testut
452e3dab06 Writes text file of possibly corrupted save files to Files apps instead of actually conflicting them
In practice, the number of conflicts was far too high for the number of save files that actually matter.
2023-08-11 21:51:32 -05:00
Riley Testut
43fedf6fcc Fixes compiling with Xcode 14 2023-08-11 21:37:21 -05:00
Riley Testut
9ab8cf29b6 Updates app version to 1.5b4 2023-08-11 18:57:28 -05:00
Riley Testut
e6cd5475e9 Replaces Logger.debug() usage with Logger.notice()
Debug logs aren’t exported from release builds, so we now use `notice` level instead.
2023-08-11 18:57:28 -05:00
Riley Testut
9c31b8a864 Updates wording of “Database Repaired” alert 2023-08-11 18:57:28 -05:00
Riley Testut
5c7e3cc5b9 [ExpFeat] Adds filter button to change RepairSaveStatesViewController’s date range
* Recent (Last month)
* All
2023-08-11 18:57:28 -05:00
Riley Testut
d5f910ff00 Adds missing throws to SaveState.awakeFromSync() 2023-08-11 18:57:28 -05:00
Riley Testut
d1643dbc8f Throws SyncValidationError when downloading corrupted versions of “verified” SaveStates
After reviewing save states upon first launch, Delta will upload the verified game ID as metadata to ensure other devices don’t download remote versions with incorrect relationships.
2023-08-11 18:57:27 -05:00
Riley Testut
dc3a5b479c [Contributors] Credits Chris Rittenhouse for Alternate App Icons 2023-08-11 15:58:43 -05:00
Riley Testut
b3d8dbc554 [ExpFeat] Fixes Controller Skin alternate app icon filename 2023-08-11 15:57:39 -05:00
Riley Testut
f3534e4415 [ExpFeat] Alternate App Icons (#259)
commit 34ed9726034adbb439515ccb3d576311603bfe2b
Author: Chris Rittenhouse <dev@litritt.com>
Date:   Thu Aug 3 15:31:47 2023 -0400

    Removes `experimentalFeatures` property from `Settings`

commit 4e31d22d56d68439a340707d2fdbac3763df1e3a
Author: Chris Rittenhouse <dev@litritt.com>
Date:   Thu Aug 3 15:17:47 2023 -0400

    Reorder icons

commit 7509eaa29946b622ce0ad920a740f0212db5e771
Author: Chris Rittenhouse <dev@litritt.com>
Date:   Thu Aug 3 15:17:24 2023 -0400

    Moves icon changing code to `AlternateAppIcons`

commit 84821ef99ded74c066563041618aec3c4acb30d7
Author: Chris Rittenhouse <dev@litritt.com>
Date:   Thu Aug 3 14:33:15 2023 -0400

    Fixes icon authors

commit 0b821830f09b434fa375c37a2504c21ee5f90bdb
Author: Chris Rittenhouse <dev@litritt.com>
Date:   Fri Jul 21 01:44:00 2023 -0400

    Adds comments for functional alternate app icon code

commit e8dd6165619bc143f13dde51e5160af2695ef17e
Author: Chris Rittenhouse <dev@litritt.com>
Date:   Fri Jul 21 01:30:03 2023 -0400

    Adds implementation for changing app icon

commit 1e07483d18d1e865804ae34d6011844b63cb33cc
Author: Chris Rittenhouse <dev@litritt.com>
Date:   Fri Jul 21 01:28:24 2023 -0400

    Adds Alternate App Icon experimental feature and options

commit 46ed2ce3ae9593d4cc95f29d6caa09f33f2ce62d
Author: Chris Rittenhouse <dev@litritt.com>
Date:   Fri Jul 21 01:26:51 2023 -0400

    Adds extension to handle retrieving app icon images

commit 9dddb5f98f4523e7877f97c66a5ae95e6513cc09
Author: Chris Rittenhouse <dev@litritt.com>
Date:   Fri Jul 21 01:24:19 2023 -0400

    Adds experimental features as a property of `Settings`

commit d74038fd418a0e6fcd45942cb67e722904fc3e24
Author: Chris Rittenhouse <dev@litritt.com>
Date:   Fri Jul 21 01:23:02 2023 -0400

    Adds alternate icon assets

Co-authored-by: Chris Rittenhouse <dev@litritt.com>
2023-08-10 19:46:08 -05:00
Riley Testut
061f5abd3e Allows explicitly downloading corrupted record versions from RecordVersionsViewController 2023-08-10 19:33:27 -05:00
Riley Testut
be047b28a6 Fixes crash when restoring remote record without local version 2023-08-10 19:33:27 -05:00
Riley Testut
fcdd3c7840 Throws SyncValidationError when downloading corrupted Game or GameSave record 2023-08-10 19:33:27 -05:00
Riley Testut
ca8c2cb8c5 [ExpFeat] Adds “Review Save States” to fix save states associated with wrong game 2023-08-10 19:33:27 -05:00
Riley Testut
a9f15144ed Repairs corrupted Game, GameSave, and SaveState relationships on initial launch
Automatically fixes Game and GameSaves, but requires user to manually review + fix all recent SaveStates.
2023-08-10 19:33:27 -05:00
Riley Testut
a80ac04650 Fixes corrupted Harmony database relationships after heavyweight migration 2023-08-10 19:33:26 -05:00
Riley Testut
25e237cfcb [Delta Sync] Uses local modification date when uploading changes
Previously we used the server’s modification dates, which could be confusing when comparing against local modification dates since the same version may have different dates.
2023-07-10 19:00:39 -05:00
Riley Testut
3227ee4c49 Migrates Core Data model from v6 to v7 2023-07-10 16:09:07 -05:00
Riley Testut
45ed97c255 Actually fixes crash loading save states on iOS 17
The underlying issue causing the crash is that we were returning cached *supplementary view* layout attributes by accident from layoutAttributesForItem(at:).

Now, we only cache layout attributes for cells.
2023-07-10 15:39:31 -05:00
Riley Testut
31578e2e34 Updated mogenerator target to use Homebrew version 2023-07-07 18:22:33 -05:00
Riley Testut
e33a7c662f [Delta Sync] Delays sync until after interactive Settings dismissal has completed
Avoids false-positives when user scrolls to top of a Settings screen.
2023-07-07 18:22:33 -05:00
Riley Testut
8ea40a4728 [Delta Sync] Fixes queued syncs sometimes fetching outdated changes
Rare, but more common when performing initial sync.
2023-07-07 18:22:32 -05:00
Riley Testut
29f152fcb3 [Delta Sync] Repairs references to remote files when signing out then back in
Fixes redundant uploads and potentially ophaned remote files, the latter due to no remote files being deleted if LocalRecord.remoteFiles is empty.
2023-07-07 18:22:26 -05:00
Riley Testut
5779927831 [Delta Sync] Delays seeding Harmony database until initial sync 2023-07-07 18:19:07 -05:00
Riley Testut
f184639c6b [Delta Sync] Fixes incorrect mass conflicts when signing out then back in 2023-07-07 18:17:13 -05:00
Riley Testut
043fb923ae [Delta Sync] Displays activity indicator when signing-in
Without an indicator it can feel like the app has froze, when really it’s just preparing to sync.
2023-07-07 14:59:41 -05:00
Riley Testut
19fb333a67 Toggles Delta Sync switch back on if user cancels “Disable Syncing?” warning alert 2023-07-06 19:11:09 -05:00
Riley Testut
35a8f90a1c Converts Delta Sync action sheets into alerts
Implicitly fixes crashing on iPad.
2023-07-06 18:44:18 -05:00
Riley Testut
c898f72847 Fixes “file does not exist” sync error after restoring previous version
Due to a bug, it was possible for Harmony records to contain duplicate file entries after restoring a previous version. Harmony would then try to download _all_ files, including the duplicates, and would fail if any of them no longer exist.

These changes fix the underlying bug, and also fix existing corrupted records on the fly.
2023-06-28 13:45:44 -05:00
Riley Testut
981c868f6e Fixes “Harmony.sqlite couldn’t be opened” sync error when there are more than 1000 games 2023-06-28 13:37:20 -05:00
Riley Testut
15e228f287 Adds GameSave.sha1 to sync hash between devices
Fixes redundant record uploads post-sync due to comparing hashes against locally-cached hash via extended attributes.
2023-06-28 13:33:16 -05:00
Riley Testut
707116a39b Automatically resolves Cheat + ControllerSkin sync conflicts 2023-06-27 18:58:41 -05:00
Riley Testut
750740ac16 Updates app version to 1.5b3 (69) 2023-06-22 13:11:13 -05:00
Riley Testut
6909b6248f Skips checksum verification when importing zipped games
Verification can take an annoyingly long time, especially for larger ROMs.
2023-06-19 19:19:40 -05:00
Riley Testut
8bd6fe1e11 Replaces UIDocumentBrowserViewController with UIDocumentPickerViewController on iOS 17+
Prior to iOS 17, UIDocumentPickerViewController was too buggy to reliably use with iCloud Drive.
2023-06-19 19:19:40 -05:00
Riley Testut
4cf705f141 [ExpFeat] Fixes saving screenshots to Photos as JPEGs 2023-06-16 16:57:00 -05:00
Riley Testut
99417b418a [ExpFeat] Adds missing @unknown default to PHAuthorizationStatus switch statement 2023-06-16 16:46:35 -05:00
Riley Testut
648e9b8393 [ExpFeat] Fixes saving screenshots to Photos with .limited authorization 2023-06-16 16:44:24 -05:00
Riley Testut
69eff8fa28 Fixes displaying system name in dark text (again) when remapping inputs on iOS 17 2023-06-16 15:55:51 -05:00
Riley Testut
3e858c652f Fixes crash loading save states on iOS 17
Crashes due to GridCollectionViewLayout returning outdated cached layout information when inserting “Auto” save states section for the first time.

To fix this, we now clear the layout cache in invalidateLayout(with:) when relevant.
2023-06-16 15:25:49 -05:00
Riley Testut
21147969ea Fixes GridCollectionViewCell "Unable to simultaneously satisfy constraints" runtime error 2023-06-16 15:18:02 -05:00
Riley Testut
731de7023f Merge branch 'app_store' into develop 2023-06-16 15:14:39 -05:00
Riley Testut
810bc4572c Replaces app icon variants with single 1024x1024 version 2023-06-16 15:11:59 -05:00
Riley Testut
4e8580b8f5 Obfuscates private API usage to pass TestFlight App Review 2023-06-16 15:04:47 -05:00
Riley Testut
2e21141bc6 [Pods] Removes Fabric + Crashlytics 2023-05-10 13:36:44 -05:00
Riley Testut
08a40b3516 [Pods] Updates GoogleSignIn dependency to 5.0.2
* GoogleSignIn (4.4.0 -> 5.0.2)
* GTMSessionFetcher (1.5.0 -> 1.7.2)
* GoogleToolboxForMac (Removed)
2023-05-10 13:30:30 -05:00
Riley Testut
7b9ab2488e Fixes accidentally deleting Games directory during sync in rare circumstances
If a Game with empty filename happens to be deleted (e.g. during sync merge), it will accidentally delete the *entire* Games folder due to its fileURL being “Games/[empty]”.

To prevent this, we now explicitly check that a Game’s identifier isn’t empty AND that that Game.fileURL doesn’t point to a directory before deleting local files.
2023-05-02 14:29:23 -05:00
Riley Testut
00121bd31f [iPad] Fixes crash when resolving sync merge conflicts 2023-05-02 14:29:23 -05:00
Riley Testut
ea260cb8a6 Updates Settings to use large titles where appropriate
* SettingsViewController
* PreferredControllerSkinsViewController
2023-05-02 14:29:23 -05:00
Riley Testut
b0bd5ba906 Updates most Settings view controllers to use .insetGrouped style
Excludes PreferredControllerSkinsViewController and ControllerSkinsViewController
2023-04-28 17:22:20 -05:00
Riley Testut
726c4ab93b Resolves Settings.storyboard ambiguity warnings
Expands static UITableViewController subclasses to show all static cells.

Wow I wish I knew this years ago…
2023-04-28 16:54:21 -05:00
Riley Testut
5dc91c87c6 Updates app version to 1.5b2 2023-04-28 16:04:51 -05:00
Riley Testut
de7a812cbd [Contributors] Credits Chris Rittenhouse for experimental features
* Show Status Bar
* Game Screenshots
* Toast Notifications
2023-04-28 15:56:51 -05:00
Riley Testut
b1a3a5076f Merge branch 'experimental_features' into develop
# Conflicts:
#	Delta.xcodeproj/project.pbxproj
#	Delta/Emulation/GameViewController.swift
#	Delta/Pause Menu/PauseViewController.swift
2023-04-28 15:51:08 -05:00
Riley Testut
9470caf83a Sorts Delta’s Info.plist items alphabetically 2023-04-28 15:42:22 -05:00
Riley Testut
bdee5d17a5 Updates Xcode project file format
* Adds DEVELOPMENT_TEAM to Delta target
* Updates LD_RUNPATH_SEARCH_PATHS format
2023-04-28 15:42:22 -05:00
Riley Testut
85d53162c1 Fixes internal location of CharacterSet+Filename.swift in Xcode project 2023-04-28 15:42:22 -05:00
Riley Testut
75814ca04d [Experimental Feature] Adds VariableFastForward.allowUnrestrictedSpeeds @Option
When enabled, the user can choose any integer speed from 1x to 8x for their preferred Fast Forward speed, regardless of the system’s maximumFastForwardSpeed.
2023-04-28 15:42:22 -05:00
Riley Testut
2ead48ad40 [Features] Supports dynamic @Option values that may change over time
Uses @autoclosure to keep call site the same, but allows a single picker @Option to show different values depending on other factors (e.g. other @Options).
2023-04-28 15:42:11 -05:00
Riley Testut
6fd7f9e1d5 [Experimental Feature] Implements VariableFastForward feature 2023-04-28 15:42:10 -05:00
Riley Testut
7fceccc114 [Experimental Feature] Toast Notifications (#244)
commit c340cf842fbf5fea476a6637efe4928dbd734eba
Author: Chris Rittenhouse <dev@litritt.com>
Date:   Thu Apr 27 17:24:30 2023 -0400

    Addresses Riley's requested changes
    - Minor code structure change in extension
    - Minor changes to text and phrasing

commit 2a928dfa637dfb503e861dc863f6f85f5240941a
Author: Chris Rittenhouse <dev@litritt.com>
Date:   Wed Apr 26 20:11:38 2023 -0400

    Adds implementation for Toast Notifications Experimental Feature

commit 4fa7d139669994eff888c41bf7af9ac0b6cd2a75
Author: Chris Rittenhouse <dev@litritt.com>
Date:   Wed Apr 26 20:11:04 2023 -0400

    Adds @Feature and @Options for Toast Notifications Experimental Feature

Co-authored-by: Chris Rittenhouse <dev@litritt.com>
2023-04-28 15:32:13 -05:00
Chris Rittenhouse
6bdc05f640
[Experimental Feature] Game Screenshots (#242)
* Adds extension to handle interactions with Photos app
- isAuthorized to check/ask for authorization
- saveUIImage to save a UIImage to Photos

* Adds a Pause Menu button for taking game screenshots

* Adds @Feature and @Options for Game Screenshots

* Implements Game Screenshots feature in GameViewController

* Updates project settings

* Passes call to save to Photos as a closure into authorization prompt
- Ensures that the screenshot is saved when the user is first prompted for access to Photos
- More elegant extension code

---------

Co-authored-by: Riley Testut <riley@rileytestut.com>
2023-04-28 14:35:26 -05:00
Chris Rittenhouse
05e94902b8
[Experimental Feature] Show Status Bar (#241)
* Adds @Feature for Show Status Bar
* Shows the Status Bar if the @Feature is enabled
* Forces light content on Status Bar
2023-04-28 14:26:57 -05:00
Riley Testut
233ef7d418 Removes accidental togglePreviewsEnabled: action selector from isAltJITEnabled switch 2023-04-27 16:39:13 -05:00
Riley Testut
5cef975a9e Fixes incorrect controller skin appearance after rotating device 2023-04-27 15:20:14 -05:00
Riley Testut
39522fda58 [Experimental Feature] Supports AirPlay controller skins
Allows users to customize controller skin when AirPlaying games to an external display.
2023-04-27 14:58:51 -05:00
Riley Testut
1137189b57 Adds Nintendo DS AirPlay settings to customize how games appear on TV
* Top Screen Only = Shows just the top screen on TV
* Layout Horizontally = Places screens side-by-side on TV (instead of stacked vertically)
2023-04-26 16:07:17 -05:00
Riley Testut
32e7c1f93e Supports AirPlaying games to external displays 2023-04-26 14:56:45 -05:00
Riley Testut
7ad5df1949 [Features] Fixes potential crash when handling .settingsDidChange Notification
Handling .settingsDidChange notification in the same run loop as changing an @Option’s value can result in exclusive memory access violation due to accessing Option.settingsKey. As a workaround, we delay posting the notification until a later run loop via Task.
2023-04-25 15:14:16 -05:00
Riley Testut
77b26210ab [Experimental Features] Adds (unimplemented) VariableFastForward feature 2023-04-21 14:51:45 -05:00
Riley Testut
20749c5419 Adds “Experimental Features” section to SettingsViewController 2023-04-21 14:51:45 -05:00
Riley Testut
14adb41ff8 [Previews] Adds example “Random Dancing” experimental feature 2023-04-21 14:51:45 -05:00
Riley Testut
8efefd19a0 [Previews] Adds example “Custom Tint Color” feature to preview ExperimentalFeaturesView 2023-04-21 14:51:45 -05:00
Riley Testut
bd0c72e847 Adds ExperimentalFeaturesView to browse and configure experimental features 2023-04-21 14:03:10 -05:00
Riley Testut
5b4f9ea593 [Features] Removes redundant public access modifier from SettingsUserInfoKey constants 2023-04-21 13:43:24 -05:00
Riley Testut
ef47d78c64 [Features] Adds displayInline(_:) View modifier
Controls whether @Option detailView will be displayed inline in the Feature detail view in Delta’s settings, or as a full-screen view that’s pushed onto navigation stack when tapped.
2023-04-14 18:23:34 -05:00
Riley Testut
9f40223e6c [Features] Provides default toggle view for Bool @Options 2023-04-14 18:15:26 -05:00
Riley Testut
6d95924145 [Features] Provides default picker view for @Options with pre-set values
To use, pass in a collection of values to `values` parameter in @Option initializer.
2023-04-14 18:10:55 -05:00
Riley Testut
240b74de94 [Features] Supports user-facing @Options with custom SwiftUI views
@Options with non-nil names will be exposed in Delta’s settings and can be configured by users via provided SwiftUI view.
2023-04-14 16:41:16 -05:00
Riley Testut
4d30ef2929 [Features] Supports @Feature-specific settings via @Option property wrapper 2023-04-14 16:17:31 -05:00
Riley Testut
415450a943 [Features] Adds UserDefaults+OptionValues to read/write arbitrary OptionValues 2023-04-14 15:38:19 -05:00
Riley Testut
80a9132ff5 [Features] Adds OptionValue + LocalizedOptionValue 2023-04-13 17:22:18 -05:00
Riley Testut
d613cc9ad7 [Features] Adds @Feature property wrapper
Simplifies defining feature flags that can enabled + disabled via UserDefaults.
2023-04-13 16:20:54 -05:00
Riley Testut
3fb7e8b4b7 [Features] Moves Notification.Name.settingsDidChange to DeltaFeatures
Re-exports as Settings.didChangeNotification to allow accessing without explicitly importing DeltaFeatures.
2023-04-13 15:57:25 -05:00
Riley Testut
9406cfe6cc [Features] Moves Settings.Name + Settings.NotificationUserInfoKey to DeltaFeatures
Also refactors from enums to RawRepresentable structs to support arbitrary values.
2023-04-13 15:43:43 -05:00
Riley Testut
c3af9f7209 [Features] Adds DeltaFeatures target 2023-04-13 15:08:17 -05:00
Riley Testut
af0d239de1 [Previews] Links target with DeltaCore and Roxas pods 2023-04-13 15:00:33 -05:00
Riley Testut
ff65b15277 [Pods] Updates Cocoapods to 1.12 2023-04-13 14:59:24 -05:00
Riley Testut
91d40cbeea [Previews] Adds DeltaPreviews target for previewing SwiftUI views
The main Delta target cannot use SwiftUI Previews due to linker errors with Systems.framework, so we’ve made a separate target specifically for previewing SwiftUI views.
2023-04-13 14:58:58 -05:00
Riley Testut
21f628fd1e [Contributors] Credits Ian Clawson for Local Multiplayer 2023-02-28 19:00:51 -06:00
Riley Testut
f5b124b175 Updates app version to 1.5b1 2023-02-28 18:52:51 -06:00
Riley Testut
10af836105 Supports local multiplayer (up to 4 players)
Heavily based on Ian Clawson’s PRs, including #128
2023-02-28 18:49:32 -06:00
Riley Testut
5a019e5950 Optimizes default input mappings for Joy-Cons, Switch Online, and other non-MFi controllers
* Uses Home button as Menu button when possible
* Supports “Start/Select” buttons for Switch NES controllers
* Rotates single JoyCon face buttons 90º
* Re-maps single JoyCon control stick from dPad to leftAnalogStick
* Re-maps L1/R1/L2/R2 buttons for N64 core
2023-02-28 18:12:14 -06:00
Riley Testut
c8860c6aaa Raises deployment target to iOS 14.0 2023-02-28 17:31:28 -06:00
Riley Testut
fb0975f0d6 Updates app version to 1.4 2023-02-28 17:31:28 -06:00
Riley Testut
dd314a12af Automatically disables AltJIT for non-BETA builds 2023-02-27 12:51:14 -06:00
Riley Testut
68ad2185dd Hides AltJIT setting for non-BETA builds 2023-02-27 12:46:04 -06:00
Riley Testut
66e5258368 Updates Chris Rittenhouse credits
Replaces GitHub link with personal website, and fixes incorrect Twitter handle.
2023-02-06 15:35:05 -06:00
Riley Testut
fcc19ae830 Updates app version to 1.4rc 2023-02-06 15:15:58 -06:00
Riley Testut
6a683be907 Replaces cheatbase.sqlite with trimmed cheatbase.zip
CheatBase now only contains two tables, CHEATS and CHEAT_CATEGORIES.

Delta unzips SQLite database from cheatbase.zip on launch whenever CheatBase.cheatsVersion changes.
2023-02-06 15:11:27 -06:00
Riley Testut
d79002ea6b Changes cheat activation alert title to “How to Activate" 2023-02-06 14:47:06 -06:00
Riley Testut
913cb788a2 Improves CheatBase error messages 2023-02-06 14:45:48 -06:00
Riley Testut
45665138b2 Adds “Contributors” section to Credits
Lists everyone who has contributed to Delta in some way besides the core team, as well as what they contributed.

Moves Grant Gliner and Chris Rittenhouse to Contributors from main Credits.
2023-02-06 14:35:43 -06:00
Riley Testut
d1c45c9ad0 Adds Shane Gill to Credits 2023-02-06 13:53:15 -06:00
Riley Testut
d31229001f Fixed incorrect font size for Credits section in Settings
All labels should use 17pt system font, but Credits used 16pt by accident
2023-02-06 13:41:48 -06:00
Riley Testut
c3a83d7542 Updates app version to 1.4b5 2023-01-31 14:36:38 -06:00
Riley Testut
5bc2f08084 Limits “Search CheatBase” option to DS games
CheatBase currently only contains cheats for DS games, so no use showing option for other systems (yet).
2023-01-31 14:36:38 -06:00
Riley Testut
041cce64b0 Prefetches CheatBase cheats + disables “Search CheatBase” option if there aren’t any 2023-01-31 14:36:38 -06:00
Riley Testut
74ccf1a246 Shrinks cheatbase.sqlite file size by removing unused columns 2023-01-31 14:36:38 -06:00
Riley Testut
a135ea236d Integrates CheatBase to browse and easily add cheats for recognized games
Limited to DS games right now.
2023-01-31 14:36:37 -06:00
Riley Testut
d204ea35bd Adds CheatBase dependency 2023-01-31 14:36:11 -06:00
Riley Testut
77983e73dd Adds “Respect Silent Mode” setting to configure whether Delta plays game audio in Silent Mode
Delta will also now automatically mute game audio if another app is playing audio.

[Missed] Mutes game audio correctly
2023-01-31 14:34:32 -06:00
Riley Testut
6aee8c84cd Updates app version to 1.4b4 2022-11-04 14:33:37 -05:00
Riley Testut
45757878d8 Fixes app freezing when using Hold Button 2022-11-04 14:30:39 -05:00
Riley Testut
8ccd86de0f Fixes re-activating sustained inputs 2022-11-04 14:28:14 -05:00
Riley Testut
ceb66d46be Updates Swift Packages 2022-10-24 15:25:45 -05:00
Riley Testut
0f2792fdbc Fixes “Hold Button” for continuous inputs mapped to discrete inputs 2022-10-24 15:19:42 -05:00
Riley Testut
eeae27cc24 Fixes using analog sticks as dpad inputs with Xbox controllers 2022-10-20 14:12:00 -05:00
Riley Testut
7677421ef4 Updates app version to 1.4b3 2022-10-19 17:22:46 -05:00
Riley Testut
d17a1f3d8f Fixes remapping continuous inputs 2022-10-19 17:14:22 -05:00
Riley Testut
7d93470738 Fixes taps sometimes not dismissing active callout view when remapping inputs 2022-10-19 17:07:56 -05:00
Riley Testut
a2b6771715 [iPad] Fixes software keyboard controller bugs on iPadOS 16.1 RC 2022-10-19 17:02:19 -05:00
Riley Testut
aa7ef0041f Enables parallelized compiling for Delta target
No longer uses “Manual” Build Order to determine compilation order.
2022-09-20 13:58:34 -05:00
Riley Testut
ee536f9ce5 [README] Updates compilation instructions
* Adds instructions for updating Systems.xcworkspace
* Asks user to install Git LFS
2022-08-17 10:51:47 -05:00
Riley Testut
b2ab33bcd1 Fixes “Revision.h file not found” compiler error 2022-08-17 10:51:15 -05:00
Riley Testut
48be35cbf2 Fixes displaying system name in dark text when remapping inputs on iOS 16 2022-08-15 16:18:04 -05:00
Riley Testut
fd2cf223dc Fixes missing controller skin when remapping inputs 2022-08-15 16:11:44 -05:00
Riley Testut
8155bc5ca8 Updates app version to 1.4b2 2022-08-15 11:43:46 -05:00
Riley Testut
cd6de86fb1 Fixes compiling with Xcode 13.x 2022-08-15 11:42:46 -05:00
Riley Testut
b2568efeb1 Updates dependencies 2022-08-14 11:10:04 -05:00
Riley Testut
5805b859f5 [iPad] Dismisses keyboard controller when pausing 2022-08-12 19:38:28 -05:00
Riley Testut
d061f56951 [iPad] Fixes keyboard controller not appearing when selecting buttons to hold 2022-08-12 19:37:26 -05:00
Riley Testut
c3e9cfe526 [iPad] Fixes keyboard controller sometimes using incorrect skin orientation 2022-08-12 19:35:37 -05:00
Riley Testut
3cf87afa2d [iPad] Initial support for Split View / Stage Manager controller skins
When Delta is in Split View, Slide Over, or windowed with Stage Manager, it will now present a special full-width “keyboard controller”, allowing for much easier gameplay than being constrained to the app window.

Each system’s controller skin has been updated to support Split View, which means every system can now be played without a game controller/keyboard when not in full screen.
2022-08-12 19:33:02 -05:00
Riley Testut
ea871c7520 Removes unnecessary ControllerSkin.inputs(for:at:)
ControllerSkinProtocol no longer requires this method, so we can just remove it.
2022-08-12 19:26:13 -05:00
Riley Testut
e1ee540d27 [iPad] Fixes automatically pausing + resuming emulation with Stage Manager on iOS 16 beta 5
We use DeltaCore’s new UIWindow subclass GameWindow in SceneDelegate to fix issues that were introduced with iOS 16 beta 5.

Also removes touchControllerSkin.layoutGuide = self.view.safeAreaLayoutGuide assignment which no longer compiles due to TouchControllerSkin refactoring.
2022-08-12 19:23:23 -05:00
Riley Testut
bb812c7f02 [iPad] Uses window size to determine TouchControllerSkin axis, not interface orientation
iPads in landscape orientation should only place DS screens side-by-side if the app window is wider than it is tall. Otherwise, it should use the default vertical screen layout.
2022-08-12 19:11:58 -05:00
Riley Testut
6ba648ed17 [iPad] Initial support for Split View / Stage Manager
Requires game controller (or hardware keyboard) to play games because we still need to update controller skins to support Split View.
2022-08-12 19:05:02 -05:00
Riley Testut
05a66a140e Fixes not detecting keyboard presses when remapping inputs 2022-08-11 17:42:36 -05:00
Riley Testut
52a68e28dd Switches to UIScene-based app lifecycle 2022-07-25 17:24:57 -05:00
Riley Testut
4829b393c5 Updates app version to 1.4b1 2022-06-01 10:00:06 -07:00
Riley Testut
b11766c973 [iPad] Updates standard controller skins to support iPad 2022-05-31 18:08:49 -07:00
Riley Testut
c09bfead65 Updates Cocoapods to 1.11.2 2022-05-31 18:05:30 -07:00
Riley Testut
7b1db2614f Fixes ControllerInputsViewController’s system picker UI 2022-05-31 18:03:26 -07:00
Riley Testut
973238e1a4 Disables AltJIT by default
melonDS save states created with JIT enabled cannot be loaded later without JIT, which made it very easy to accidentally replace a save state with one that could only be loaded when JIT is available.

We plan to remove AltJIT eventually for this reason, but for now we’ll just disable it by default.
2022-05-31 17:59:01 -07:00
Riley Testut
d4e22942b8 [Harmony] Fixes potential Core Data threading violation 2022-05-31 17:55:23 -07:00
Riley Testut
7c934cebe1 Merge branch 'ipad' into develop
# Conflicts:
#	Delta.xcodeproj/project.pbxproj
2022-05-31 17:51:31 -07:00
Riley Testut
b134c73301 Merge branch 'altjit' into develop
# Conflicts:
#	Delta.xcodeproj/project.pbxproj
2022-05-31 17:41:37 -07:00
Riley Testut
fce4fc1bec [iPad] Temporarily disables split view support 2022-05-16 14:54:42 -07:00
Riley Testut
977f3d8005 Fixes previous game controller remaining selected when changing controller 2022-05-09 16:44:29 -07:00
Riley Testut
edab6ea432 Fixes sharing games + exporting save files
* Makes temporary copy instead of symbolic link when exporting game
* Sanitizes game name before exporting game
* Fixes prematurely deleting temporary game
* Exported save file names now match exported game names
2022-04-28 18:13:25 -07:00
Riley Testut
9e437797d9 Improves CopyDeepLinkActivity
* Uses SF Symbol instead of bundled image
* Actually calls activityDidFinish(_:)
2022-04-28 16:57:06 -07:00
Riley Testut
25afda3b60 Replaces UIAlertController with UIMenu for importing games 2022-04-28 16:54:18 -07:00
Riley Testut
836297718b [iPad] Fixes game context menu actions 2022-04-28 16:38:14 -07:00
Riley Testut
da8415f4aa Improves SaveStatesViewController UI on iPad 2022-04-28 16:15:48 -07:00
Riley Testut
68c1b05313 Improves GameCollectionViewController UI on iPad 2022-04-28 15:47:05 -07:00
Riley Testut
2a4dbabae5 Fixes crash when presenting ImportController on iPad 2022-04-28 12:49:16 -07:00
Riley Testut
aafe673811 Fixes invisible navigation bar + toolbar on iPadOS 15 2022-04-27 17:57:55 -07:00
Riley Testut
adccf8fca5 Fixes ControllerInputsViewController UI on iPad 2022-04-27 16:15:09 -07:00
Riley Testut
d333672b95 Enables basic iPad support 2022-04-26 12:23:04 -07:00
Riley Testut
0df313188d Fixes keyboard support on iOS 15+ 2022-04-26 12:21:59 -07:00
Riley Testut
fd0427d2ad Fixes BIOSError compilation error when compiling with Xcode 13
Xcode 12 and older incorrectly let us declare BIOSError.incorrectSize as @available(iOS 13), but Swift doesn't support @available for enum cases with associated values. Xcode 13 now properly enforces this restriction, so we instead mark the enum itself as @available(iOS 13).
2022-04-19 14:20:40 -07:00
Riley Testut
394030ad43 Ensures melonDS is preferred DS core for release versions 2021-12-02 13:36:37 -08:00
Riley Testut
5f2e021560 Updates app version to 1.3.1 2021-12-02 13:14:39 -08:00
Riley Testut
17e1bf710b Dynamically maps outdated artwork URLs to correct URLs 2021-12-02 13:12:07 -08:00
Riley Testut
baf895939d Updates OpenVGDB to latest version
Fixes broken OpenVGDB cover art URLs due to host moving from gamefaqs1.cbsistatic.com to gamefaqs.gamespot.com.
2021-12-02 13:12:01 -08:00
Riley Testut
2705849cf2 Ensures melonDS is preferred DS core for release versions 2021-11-17 11:43:00 -08:00
Riley Testut
79bf977904 Updates app version to 1.3.1b 2021-11-16 16:39:30 -08:00
Riley Testut
11041ef1e9 Dynamically maps outdated artwork URLs to correct URLs 2021-11-16 16:31:58 -08:00
Riley Testut
08e870c94c Updates OpenVGDB to latest version
Fixes broken OpenVGDB cover art URLs due to host moving from gamefaqs1.cbsistatic.com to gamefaqs.gamespot.com.
2021-11-16 16:27:09 -08:00
Riley Testut
9492f3165e Hides AltJIT setting on unsupported devices 2021-11-16 15:04:19 -08:00
Riley Testut
f14bb0f890 Supports AltJIT
Automatically enables JIT for MelonDS core when on the same WiFi as AltServer.
2021-11-16 14:39:48 -08:00
Riley Testut
829d127269 Fixes BIOSError compilation error when compiling with Xcode 13
Xcode 12 and older incorrectly let us declare BIOSError.incorrectSize as @available(iOS 13), but Swift doesn't support @available for enum cases with associated values. Xcode 13 now properly enforces this restriction, so we instead mark the enum itself as @available(iOS 13).
2021-08-09 16:55:19 -07:00
Riley Testut
f1f75d8cc0 Updates app version to 1.3 2021-04-21 12:43:39 -07:00
Riley Testut
3128783105 Fixes melonDS graphical bugs when fast forwarding with JIT disabled 2021-04-21 12:41:35 -07:00
Riley Testut
abd7338a08 Replaces placeholder README with detailed README
Adds following sections to README:

* Intro
* Supported Systems
* Features
* Installation Instructions
* Project Requirements
* Licensing
* Contact Me
2021-04-21 12:41:16 -07:00
Riley Testut
c396698ca0 Fixes visible grid lines on DS controller skin buttons 2021-03-22 12:31:20 -07:00
Riley Testut
cd87438fb4 Updates app version to 1.3b5 2021-03-11 15:54:35 -06:00
Riley Testut
eafabb7f43 Enables melonDS core for public versions 2021-03-11 14:39:31 -06:00
Riley Testut
de315eacf5 Updates Licenses screen to include melonDS and Genesis Plus GX 2021-03-11 14:39:30 -06:00
Riley Testut
af6b92a441 Fixes erroneous sync error when syncing deleted files that were never uploaded 2021-03-11 13:49:15 -06:00
Riley Testut
d2215ed91e Updates DS controller skin 2021-03-11 13:27:24 -06:00
Riley Testut
20a470ddd1 Fixes crash playing DS games when another app is using microphone 2021-03-11 13:26:23 -06:00
Riley Testut
9f58aac350 Removes “(Beta)” from DS’s short name 2021-03-11 12:21:35 -06:00
Riley Testut
931a16c544 Hides Genesis skin credit for public versions 2021-03-10 14:33:57 -06:00
Riley Testut
8f7e7280f9 Removes support for 128KB DS firmwares
128KB DS firmwares come from DSi/3DS and aren’t bootable, so we consider them unsupported.
2021-03-10 14:32:09 -06:00
Riley Testut
8888b72d29 Limits DSi support to beta versions 2021-03-10 14:27:56 -06:00
Riley Testut
6cfca53dc8 Fixes game artwork not updating immediately when changed 2021-03-10 14:19:26 -06:00
Riley Testut
1bfe030dd9 Deletes temporary image file after changing artwork 2021-03-10 14:16:02 -06:00
Riley Testut
98ed657f8a Improves support for transparent and/or rotated custom artwork 2021-03-10 14:14:14 -06:00
Riley Testut
c22518ce23 Updates app version to 1.3b4 2021-02-24 13:29:43 -06:00
Riley Testut
58921cfb7f Fixes legacy plist format for GBA Game and Delta Skin UTIs 2021-02-24 13:25:07 -06:00
Riley Testut
dae3164d53 Credits Chris Rittenhouse (@litritt_z) for Genesis skin 2021-02-24 13:19:21 -06:00
Riley Testut
5ccf209af7 Changes Genesis placeholder skin to temporary one by @litritt_z 2021-02-24 13:17:25 -06:00
Riley Testut
bb6fbfea37 Replaces placeholder DS Home Screen image 2021-02-24 13:02:21 -06:00
Riley Testut
edb2af4dd5 Compares DSi BIOS files against unsupported files
DSi BIOS files can have various hashes, so rather than compare them against an expected hash, we now compare them against unsupported hashes and throw an error if it matches one.
2021-02-18 17:16:44 -06:00
Riley Testut
7c3b67fbfb Adds “Import Controller Skin” button to ControllerSkinsViewController 2021-02-18 14:07:39 -06:00
Riley Testut
bf2461fae1 Enables syncing DS(i) BIOS files
Excludes DSi NAND for now, since it is ~240MB and Harmony can’t selectively download files (yet).
2021-02-18 13:45:49 -06:00
Riley Testut
f316e7cca0 Fixes erroneous microphone indicator after returning from background 2021-02-12 14:57:57 -06:00
Riley Testut
3f70300afb Fixes incorrectly previewing DS home screen instead of DSi home screen 2021-02-12 13:18:55 -06:00
Riley Testut
2c52821e72 Fixes treating DS & DSi Home Screens as the same game 2021-02-12 13:14:33 -06:00
Riley Testut
4ed4b8ba06 Fixes misaligned ControllerInputsViewController callout views on iOS 14.5 2021-02-12 13:03:47 -06:00
Riley Testut
c3c6fb32cc Fixes ControllerInputsViewController DS layout
Presents ControllerInputsViewController full screen so DS portrait skin is not distorted.
2021-02-12 13:01:58 -06:00
Riley Testut
6f3a7501af Unlinks Cocoapods’ DeltaCore
Fixes runtime conflicts with Systems’ own DeltaCore.
2021-02-11 14:25:43 -06:00
Riley Testut
1b859ce769 [Systems] Fixes bitcode error when archiving 2021-02-10 12:31:27 -06:00
Riley Testut
46cb7db897 Disables cheats for Genesis games 2021-02-10 12:29:40 -06:00
Riley Testut
a29e4e61eb Emulates Sega Genesis games 2021-02-09 17:31:42 -06:00
Riley Testut
6a01a74608 Adds GPGXDeltaCore dependency
Links indirectly via new Systems.framework to avoid conflicts between Cocoapods and SwiftPM.
2021-02-09 16:51:47 -06:00
Riley Testut
945ffb1ed7 Enables new Xcode build system 2021-02-09 14:13:37 -06:00
Riley Testut
0a4c927277 Supports new Xcode build system 2021-02-09 14:13:13 -06:00
Riley Testut
c67b72068a Adds missing imports 2021-02-09 12:26:16 -06:00
Riley Testut
5127d5a65a Updates app version to 1.3b3 2021-01-21 15:18:36 -06:00
Riley Testut
c97611482e Fixes crash when previewing DS games without BIOS files 2021-01-19 14:41:55 -06:00
Riley Testut
f81f6cbf3d Hides DS “Home Screen” until BIOS files have been imported 2021-01-19 14:31:16 -06:00
Riley Testut
a079e68713 Changes default DS core from DeSmuME to melonDS 2021-01-19 14:20:00 -06:00
Riley Testut
66cfc272c1 Lowers MelonDSDeltaCore non-JIT maximum Fast Forward speed to 1.5x
Without JIT, the processor throttles very quickly at 2x. 1.5x allows at least a couple minutes before throttling kicks in.
2021-01-19 14:13:53 -06:00
Riley Testut
1871f69aca Disables JIT on iOS 14.4
JIT no longer works on iOS 14.4 beta 2, so disable for now until it (hopefully) works again.
2021-01-19 13:04:27 -06:00
Riley Testut
7034b1dd8a Fixes missing Fast Forward option for MelonDSDeltaCore 2021-01-19 12:49:55 -06:00
Riley Testut
3e0a983048 Validates melonDS BIOS files
Compares file sizes and MD5 hashes (when relevant) to ensure BIOS files are correct.
2021-01-19 12:44:54 -06:00
Riley Testut
826cf7b0b1 Fixes performance issues when previewing games + save states 2021-01-13 14:41:27 -06:00
Riley Testut
1b874ce9c1 Displays preview save state image even if context menu previews are disabled 2021-01-13 14:41:27 -06:00
Riley Testut
0ad0e752f8 Lowers N64DeltaCore maximum Fast Forward speed to 1.5x for some older devices 2021-01-13 14:41:03 -06:00
Riley Testut
d0823b1acb Raises MelonDSDeltaCore maximum Fast Forward speed to 3x 2021-01-11 14:14:02 -06:00
Riley Testut
474cae0a5b Updates MelonDSDeltaCore to 0.9.1 2021-01-11 14:05:10 -06:00
Riley Testut
0d5e7e97cc Adds “Context Menu Previews” setting
Controls whether Delta previews games and save states when using context menus. Enabled by default.
2021-01-04 14:30:56 -06:00
Riley Testut
a58d201b1b Fixes crash launching home screen shortcut when AppIconShortcutsViewController is visible 2021-01-04 14:22:44 -06:00
Riley Testut
58346140a8 Unhides “Home Screen Shortcuts” setting on devices without 3D Touch
All devices on iOS 13 or later support either 3D Touch or Haptic Touch, which means all devices now support home screen shortcuts.
2021-01-04 14:20:25 -06:00
Riley Testut
cb77be106a Renames “App Icon Shortcuts” setting to “Home Screen Shortcuts” 2021-01-04 14:19:42 -06:00
Riley Testut
ced5d6099e Fixes crash when customizing app icon shortcuts 2021-01-04 14:01:05 -06:00
Riley Testut
9f2f1bad77 Updates pods 2020-12-22 13:03:45 -06:00
Riley Testut
c7329136ac Supports touch inputs when external controller is connected 2020-12-10 15:34:16 -06:00
Riley Testut
a63de5db4d Updates MelonDSDeltaCore pod 2020-12-10 15:28:56 -06:00
Riley Testut
543e271563 Updates app version to 1.3b2 2020-12-02 12:09:43 -06:00
Riley Testut
ee79b6c8c9 Fixes garbled audio during emulation 2020-11-30 16:31:23 -06:00
Riley Testut
1f3f9d4bd1 Fixes MelonDS crash on devices without JIT support 2020-11-30 14:41:42 -06:00
Riley Testut
ffb6d7b02a Merge branch 'melonDS_0.9' into develop
# Conflicts:
#	Delta/Base.lproj/Settings.storyboard
2020-11-24 13:24:46 -06:00
Riley Testut
64df7b97ab Supports MelonDS JIT 2020-11-24 13:11:02 -06:00
Riley Testut
a1f80e74b5 Emulates DS microphone 2020-11-24 13:08:38 -06:00
Riley Testut
358accbcb7 Adds DSi support
Requires DSi BIOS files.
2020-11-24 13:06:29 -06:00
Riley Testut
8a273b31d2
Merge pull request #82 from ericlewis/support-dark-mode
feat: support iOS 13+ dark mode
2020-11-06 11:59:30 -08:00
Eric Lewis
15cab0bca8 feat: support iOS 13+ dark mode 2020-11-06 11:45:25 -05:00
Riley Testut
865c681df0 Updates app version to 1.2 2020-10-21 10:58:15 -07:00
Riley Testut
86c7ca3ce8 Updates app version to 1.2b3 2020-10-12 11:42:21 -07:00
Riley Testut
77512147ef Fixes swapped DS screens 2020-10-12 11:37:50 -07:00
Riley Testut
b85230b0ff Improves sync error messages when a game is missing or can’t be synced 2020-06-12 13:00:44 -07:00
Riley Testut
3cb3b9a10b Fixes various issues with controller skin filters 2020-05-05 11:18:46 -07:00
Riley Testut
e4404d179e Fixes NES games crashing after playing an N64 game 2020-05-01 11:28:16 -07:00
Riley Testut
9c99578206 Fixes misplaced DS screens when using external controller 2020-05-01 11:23:48 -07:00
Riley Testut
5c9332e61e Fixes importing games + controller skins from Files
Exposing Documents directory in Files app requires us to support opening files in place (despite LSSupportsOpeningDocumentsInPlace set to NO in Info.plist), so we now coordinate access to any external file URL
2020-04-28 14:44:06 -07:00
Riley Testut
a739926e17 Updates app version to 1.2b2 2020-04-27 14:40:15 -07:00
Riley Testut
fd79b04ff0 Updates DeltaCore dependency 2020-04-27 14:39:51 -07:00
Riley Testut
75869c06fd Fixes overwriting save file when previewing games 2020-04-27 13:13:34 -07:00
Riley Testut
e11e4437c5 Adds coreID to SaveState’s Harmony metadata for backwards compatibility 2020-04-27 13:03:28 -07:00
Riley Testut
f0d245ef8d Fixes always using melonDS core even if DeSmuME core is selected 2020-04-27 13:01:09 -07:00
Riley Testut
610697be5d Updates Harmony to add future backwards compatibility
Harmony will now persist properties from future model versions and later upload them, allowing for basic backwards compatibility.
2020-04-27 12:25:55 -07:00
Riley Testut
a9a2819b19 Adds Export Save File option to game context menu 2020-04-24 13:25:01 -07:00
Riley Testut
ec6fb6c03c Fixes N64 games crashing due to stripped library symbols 2020-04-24 13:20:54 -07:00
Riley Testut
1f6ad51c99 Adds support for 8 character NES Game Genie cheat codes 2020-04-23 18:04:37 -07:00
Riley Testut
0e8c9fbc5c Exposes Documents directory in Files app 2020-04-23 18:02:02 -07:00
Riley Testut
0b6567d98f Fixes incorrect game name color after quitting emulation 2020-04-23 17:25:09 -07:00
Riley Testut
01320b4dec Adds SaveState.coreIdentifier to filter out save states from other cores
Prevents DeSmuME save states from appearing while using melonDS core and vice versa.
2020-04-23 17:24:04 -07:00
Riley Testut
77da71cd62 Adds “Home Screen” DS game to boot into DS main menu 2020-04-23 17:18:59 -07:00
Riley Testut
6f336a82a5 Adds DS settings UI to import melonDS BIOS + switch DS cores 2020-04-23 17:16:44 -07:00
Riley Testut
35fe306c12 Switches to melonDS-based core for DS games 2020-04-23 16:52:29 -07:00
Riley Testut
427ec9da73 Fixes incorrect cheat code formatting 2020-04-23 16:19:05 -07:00
Riley Testut
9dc823f25c Fixes missing GameType declarations with Xcode 11.4 2020-03-18 13:17:44 -07:00
Riley Testut
d99b54f8ff Fixes broken submodule reference 2020-02-11 19:02:21 -08:00
Riley Testut
38591bf374 Updates app version to 1.2b 2020-02-11 16:36:21 -08:00
Riley Testut
4ba2fa8d21 Adds support for new Nintendo DS controller skin 2020-02-11 16:34:57 -08:00
Riley Testut
8b5ac435a6 Fixes assigning non-X controller skins to games on X-devices 2020-02-11 16:32:20 -08:00
Riley Testut
89db6b0d3a Migrates from Core Data model v4 to v5 2020-02-11 15:59:47 -08:00
Riley Testut
59beb243c0 Adds Save State and Fast Forward controller skin actions 2020-02-07 16:01:49 -08:00
Riley Testut
0373b757f7 Adds ability to assign controller skins per game 2020-02-07 15:57:11 -08:00
Riley Testut
cd7e9652ab Replaces peek & pop with context menus on iOS 13+ 2020-02-06 14:37:21 -08:00
689 changed files with 43414 additions and 18065 deletions

1
.gitignore vendored
View File

@ -8,6 +8,7 @@
## Build generated ## Build generated
build/ build/
DerivedData DerivedData
.build
## Various settings ## Various settings
*.pbxuser *.pbxuser

9
.gitmodules vendored
View File

@ -25,3 +25,12 @@
[submodule "Cores/DSDeltaCore"] [submodule "Cores/DSDeltaCore"]
path = Cores/DSDeltaCore path = Cores/DSDeltaCore
url = https://github.com/rileytestut/DSDeltaCore.git url = https://github.com/rileytestut/DSDeltaCore.git
[submodule "Cores/MelonDSDeltaCore"]
path = Cores/MelonDSDeltaCore
url = https://github.com/rileytestut/MelonDSDeltaCore.git
[submodule "Cores/GPGXDeltaCore"]
path = Cores/GPGXDeltaCore
url = https://github.com/rileytestut/GPGXDeltaCore.git
[submodule "External/CheatBase"]
path = External/CheatBase
url = https://github.com/rileytestut/CheatBase.git

@ -1 +1 @@
Subproject commit 88037a5745399074cedb665f435564bb5d89ba91 Subproject commit 6c84366b3a76045782905293c9616e33f5da1a35

@ -1 +1 @@
Subproject commit 5570db1dfe95d6e08b0abaefe63b89a9cac211fc Subproject commit c1db5f51cd455a7033801cc19dc3dbfcb6f2b42c

@ -1 +1 @@
Subproject commit d4bc2da2b19dddb87610c62ea190c42029fdf3c2 Subproject commit 8ea36dff87bc1f787765de45fa8ccbcc1256a0e3

@ -1 +1 @@
Subproject commit a15e8ae6fee927fd95a8243231ee849eab31e1ef Subproject commit 81f8ffba56823637706689fb5c6bc634ee4d9b32

1
Cores/GPGXDeltaCore Submodule

@ -0,0 +1 @@
Subproject commit 18c595887a12ef23e0d54c63f83c91c99e7f4827

@ -0,0 +1 @@
Subproject commit 697ba731981824f53460f6e0193f159f71f22ba2

@ -1 +1 @@
Subproject commit 9f9b7b32503b0ed6bcc0065e7880e02c75859623 Subproject commit c8816c51f82210a9c4cc62b1a7c53fa21bc705ee

@ -1 +1 @@
Subproject commit 04d17a5400711e7551d07cd158ca856a0302a005 Subproject commit 78a092d4e795f83153e98749b5cbeb66cf812d7e

@ -1 +1 @@
Subproject commit b90b6030a74420152b071073c3a4b2fdbe82f5af Subproject commit d5717291325578f64d519822aeb2be81217c67f3

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@
LastUpgradeVersion = "1020" LastUpgradeVersion = "1020"
version = "1.3"> version = "1.3">
<BuildAction <BuildAction
parallelizeBuildables = "NO" parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"> buildImplicitDependencies = "YES">
<BuildActionEntries> <BuildActionEntries>
<BuildActionEntry <BuildActionEntry
@ -29,7 +29,7 @@
<BuildableReference <BuildableReference
BuildableIdentifier = "primary" BuildableIdentifier = "primary"
BlueprintIdentifier = "BFFA71D61AAC406100EE9DD1" BlueprintIdentifier = "BFFA71D61AAC406100EE9DD1"
BuildableName = "Delta.app" BuildableName = "Retro Game Emulator.app"
BlueprintName = "Delta" BlueprintName = "Delta"
ReferencedContainer = "container:Delta.xcodeproj"> ReferencedContainer = "container:Delta.xcodeproj">
</BuildableReference> </BuildableReference>
@ -45,7 +45,7 @@
<BuildableReference <BuildableReference
BuildableIdentifier = "primary" BuildableIdentifier = "primary"
BlueprintIdentifier = "BFFA71D61AAC406100EE9DD1" BlueprintIdentifier = "BFFA71D61AAC406100EE9DD1"
BuildableName = "Delta.app" BuildableName = "Retro Game Emulator.app"
BlueprintName = "Delta" BlueprintName = "Delta"
ReferencedContainer = "container:Delta.xcodeproj"> ReferencedContainer = "container:Delta.xcodeproj">
</BuildableReference> </BuildableReference>
@ -54,7 +54,7 @@
</Testables> </Testables>
</TestAction> </TestAction>
<LaunchAction <LaunchAction
buildConfiguration = "Debug" buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
enableASanStackUseAfterReturn = "YES" enableASanStackUseAfterReturn = "YES"
@ -69,7 +69,7 @@
<BuildableReference <BuildableReference
BuildableIdentifier = "primary" BuildableIdentifier = "primary"
BlueprintIdentifier = "BFFA71D61AAC406100EE9DD1" BlueprintIdentifier = "BFFA71D61AAC406100EE9DD1"
BuildableName = "Delta.app" BuildableName = "Retro Game Emulator.app"
BlueprintName = "Delta" BlueprintName = "Delta"
ReferencedContainer = "container:Delta.xcodeproj"> ReferencedContainer = "container:Delta.xcodeproj">
</BuildableReference> </BuildableReference>
@ -107,7 +107,7 @@
<BuildableReference <BuildableReference
BuildableIdentifier = "primary" BuildableIdentifier = "primary"
BlueprintIdentifier = "BFFA71D61AAC406100EE9DD1" BlueprintIdentifier = "BFFA71D61AAC406100EE9DD1"
BuildableName = "Delta.app" BuildableName = "Retro Game Emulator.app"
BlueprintName = "Delta" BlueprintName = "Delta"
ReferencedContainer = "container:Delta.xcodeproj"> ReferencedContainer = "container:Delta.xcodeproj">
</BuildableReference> </BuildableReference>

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1420"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D5D7C1F029E60DFF00663793"
BuildableName = "libDeltaFeatures.a"
BlueprintName = "DeltaFeatures"
ReferencedContainer = "container:Delta.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D5D7C1F029E60DFF00663793"
BuildableName = "libDeltaFeatures.a"
BlueprintName = "DeltaFeatures"
ReferencedContainer = "container:Delta.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D539102E29E88B6B0006B350"
BuildableName = "DeltaPreviews.framework"
BlueprintName = "DeltaPreviews"
ReferencedContainer = "container:Delta.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D539102E29E88B6B0006B350"
BuildableName = "DeltaPreviews.framework"
BlueprintName = "DeltaPreviews"
ReferencedContainer = "container:Delta.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "BF6E70B925D2187800E41CD1"
BuildableName = "Systems"
BlueprintName = "Systems"
ReferencedContainer = "container:Delta.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "BF6E70B925D2187800E41CD1"
BuildableName = "Systems"
BlueprintName = "Systems"
ReferencedContainer = "container:Delta.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "BF14D8941DE7A512002CA1BE"
BuildableName = "mogenerator"
BlueprintName = "mogenerator"
ReferencedContainer = "container:Delta.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "BF14D8941DE7A512002CA1BE"
BuildableName = "mogenerator"
BlueprintName = "mogenerator"
ReferencedContainer = "container:Delta.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -22,9 +22,15 @@
<FileRef <FileRef
location = "group:Cores/N64DeltaCore/N64DeltaCore.xcodeproj"> location = "group:Cores/N64DeltaCore/N64DeltaCore.xcodeproj">
</FileRef> </FileRef>
<FileRef
location = "group:Cores/MelonDSDeltaCore/MelonDSDeltaCore.xcodeproj">
</FileRef>
<FileRef <FileRef
location = "group:Cores/DSDeltaCore/DSDeltaCore.xcodeproj"> location = "group:Cores/DSDeltaCore/DSDeltaCore.xcodeproj">
</FileRef> </FileRef>
<FileRef
location = "group:Cores/GPGXDeltaCore">
</FileRef>
<FileRef <FileRef
location = "group:External/Harmony/Harmony.xcodeproj"> location = "group:External/Harmony/Harmony.xcodeproj">
</FileRef> </FileRef>

View File

@ -2,9 +2,9 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>BuildSystemType</key>
<string>Original</string>
<key>IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded</key> <key>IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded</key>
<false/> <false/>
<key>PreviewsEnabled</key>
<false/>
</dict> </dict>
</plist> </plist>

View File

@ -0,0 +1,34 @@
{
"object": {
"pins": [
{
"package": "AltKit",
"repositoryURL": "https://github.com/rileytestut/AltKit.git",
"state": {
"branch": null,
"revision": "2fd376df1c79ec06a5c80cc8933da027f65b3148",
"version": null
}
},
{
"package": "DeltaCore",
"repositoryURL": "https://github.com/rileytestut/DeltaCore.git",
"state": {
"branch": "ios14",
"revision": "74d2a7a6e36035cb5730d0b0cf2456cbeb6faf0c",
"version": null
}
},
{
"package": "ZIPFoundation",
"repositoryURL": "https://github.com/weichsel/ZIPFoundation.git",
"state": {
"branch": null,
"revision": "02b6abe5f6eef7e3cbd5f247c5cc24e246efcfe0",
"version": "0.9.19"
}
}
]
},
"version": 1
}

View File

@ -10,9 +10,7 @@ import UIKit
import DeltaCore import DeltaCore
import Harmony import Harmony
import AltKit
import Fabric
import Crashlytics
private extension CFNotificationName private extension CFNotificationName
{ {
@ -39,30 +37,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate
Settings.registerDefaults() Settings.registerDefaults()
self.registerCores() self.registerCores()
#if DEBUG
// Must go AFTER registering cores, or else NESDeltaCore may not work correctly when not connected to debugger 🤷
Fabric.with([Crashlytics.self])
#else
// Fabric doesn't allow us to change what value it uses for the bundle identifier.
// Normally this wouldn't be an issue, except AltStore creates a unique bundle identifier per user.
// Rather than have every copy of Delta be listed separately in Fabric, we temporarily swizzle Bundle.infoDictionary
// to return a constant identifier while Fabric is starting up. This way, Fabric will now group
// all copies of Delta under the bundle identifier "com.rileytestut.Delta.AltStore".
Bundle.swizzleBundleID {
Fabric.with([Crashlytics.self])
}
#endif
self.configureAppearance() self.configureAppearance()
// Controllers // Controllers
ExternalGameControllerManager.shared.startMonitoring() ExternalGameControllerManager.shared.startMonitoring()
// JIT
ServerManager.shared.prepare()
// Notifications // Notifications
let center = CFNotificationCenterGetDarwinNotifyCenter() let center = CFNotificationCenterGetDarwinNotifyCenter()
CFNotificationCenterAddObserver(center, nil, ReceivedApplicationState, CFNotificationName.altstoreRequestAppState.rawValue, nil, .deliverImmediately) CFNotificationCenterAddObserver(center, nil, ReceivedApplicationState, CFNotificationName.altstoreRequestAppState.rawValue, nil, .deliverImmediately)
@ -110,6 +92,34 @@ class AppDelegate: UIResponder, UIApplicationDelegate
} }
} }
@available(iOS 13, *)
extension AppDelegate
{
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration
{
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
if connectingSceneSession.role == .windowExternalDisplay
{
// External Display
return UISceneConfiguration(name: "External Display", sessionRole: connectingSceneSession.role)
}
else
{
// Default Scene
return UISceneConfiguration(name: "Main", sessionRole: connectingSceneSession.role)
}
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>)
{
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
}
private extension AppDelegate private extension AppDelegate
{ {
func registerCores() func registerCores()
@ -128,7 +138,7 @@ private extension AppDelegate
#if BETA #if BETA
System.allCases.forEach { Delta.register($0.deltaCore) } System.allCases.forEach { Delta.register($0.deltaCore) }
#else #else
System.allCases.filter { $0 != .ds }.forEach { Delta.register($0.deltaCore) } System.allCases.filter { $0 != .genesis }.forEach { Delta.register($0.deltaCore) }
#endif #endif
#endif #endif

View File

@ -1,11 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="6bq-zy-UZU"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15705" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="6bq-zy-UZU">
<device id="retina4_7" orientation="portrait"> <device id="retina4_7" orientation="portrait" appearance="light"/>
<adaptation id="fullscreen"/>
</device>
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15706"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
<scenes> <scenes>
@ -25,7 +23,7 @@
<navigationItem key="navigationItem" title="Games Database" id="rwF-kd-avR"> <navigationItem key="navigationItem" title="Games Database" id="rwF-kd-avR">
<barButtonItem key="leftBarButtonItem" systemItem="cancel" id="BnB-5n-Rff"> <barButtonItem key="leftBarButtonItem" systemItem="cancel" id="BnB-5n-Rff">
<connections> <connections>
<segue destination="mUU-ug-yNs" kind="unwind" unwindAction="unwindFromGamesDatabaseBrowserWith:" id="zdg-Az-WwQ"/> <segue destination="mUU-ug-yNs" kind="unwind" unwindAction="unwindToGameCollectionViewController:" id="nzI-4n-kDg"/>
</connections> </connections>
</barButtonItem> </barButtonItem>
</navigationItem> </navigationItem>
@ -41,7 +39,7 @@
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="6bq-zy-UZU" sceneMemberID="viewController"> <navigationController automaticallyAdjustsScrollViewInsets="NO" id="6bq-zy-UZU" sceneMemberID="viewController">
<toolbarItems/> <toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" barStyle="black" id="uzY-vR-coL"> <navigationBar key="navigationBar" contentMode="scaleToFill" barStyle="black" id="uzY-vR-coL">
<rect key="frame" x="0.0" y="20" width="375" height="44"/> <rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
</navigationBar> </navigationBar>
<nil name="viewControllers"/> <nil name="viewControllers"/>

View File

@ -1,13 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13528" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="dkK-ii-Bx4"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="dkK-ii-Bx4">
<device id="retina4_7" orientation="portrait"> <device id="retina4_7" orientation="portrait" appearance="light"/>
<adaptation id="fullscreen"/>
</device>
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13526"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22684"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
<scenes> <scenes>
@ -23,21 +19,32 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Delta" translatesAutoresizingMaskIntoConstraints="NO" id="plh-tL-LY0"> <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" insetsLayoutMarginsFromSafeArea="NO" image="LaunchViewC" translatesAutoresizingMaskIntoConstraints="NO" id="5XD-I3-tLg">
<rect key="frame" x="94" y="250" width="187.5" height="167"/> <rect key="frame" x="0.0" y="50" width="375" height="378"/>
<constraints>
<constraint firstAttribute="width" secondItem="plh-tL-LY0" secondAttribute="height" multiplier="64:57" id="8qM-L2-ASa"/>
</constraints>
</imageView> </imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Retro Game Emulator" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vhb-Xd-o6a">
<rect key="frame" x="55.5" y="448" width="264" height="33.5"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="28"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" alpha="0.44999998807907104" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="ENJOY CLASSIC MOMENT" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="wWH-Lx-U9x">
<rect key="frame" x="90.5" y="513.5" width="194.5" height="19.5"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
</subviews> </subviews>
<color key="backgroundColor" white="0.14728124936421713" alpha="1" colorSpace="calibratedWhite"/> <color key="backgroundColor" red="0.071399740870000006" green="0.082175157959999995" blue="0.10832635309999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints> <constraints>
<constraint firstItem="plh-tL-LY0" firstAttribute="width" relation="lessThanOrEqual" secondItem="8Uu-wz-ps8" secondAttribute="width" multiplier="0.5" id="8j9-39-Y2s"/> <constraint firstItem="5XD-I3-tLg" firstAttribute="top" secondItem="qMb-3x-uIu" secondAttribute="bottom" constant="30" id="Aiv-ac-bYx"/>
<constraint firstItem="plh-tL-LY0" firstAttribute="centerY" secondItem="8Uu-wz-ps8" secondAttribute="centerY" id="COW-Co-NFK"/> <constraint firstItem="wWH-Lx-U9x" firstAttribute="centerX" secondItem="vhb-Xd-o6a" secondAttribute="centerX" id="DEu-U7-qVq"/>
<constraint firstItem="plh-tL-LY0" firstAttribute="height" secondItem="8Uu-wz-ps8" secondAttribute="height" multiplier="0.5" priority="900" id="G3L-7B-xVc"/> <constraint firstAttribute="trailing" secondItem="5XD-I3-tLg" secondAttribute="trailing" id="Gc5-y0-Vsy"/>
<constraint firstItem="plh-tL-LY0" firstAttribute="width" secondItem="8Uu-wz-ps8" secondAttribute="width" multiplier="0.5" priority="950" id="n3i-kS-7eQ"/> <constraint firstItem="vhb-Xd-o6a" firstAttribute="top" secondItem="5XD-I3-tLg" secondAttribute="bottom" constant="20" id="Ncn-Yh-ecr"/>
<constraint firstItem="plh-tL-LY0" firstAttribute="centerX" secondItem="8Uu-wz-ps8" secondAttribute="centerX" id="sp5-Kf-N7G"/> <constraint firstItem="5XD-I3-tLg" firstAttribute="leading" secondItem="8Uu-wz-ps8" secondAttribute="leading" id="SSl-CS-XOC"/>
<constraint firstItem="plh-tL-LY0" firstAttribute="height" relation="lessThanOrEqual" secondItem="8Uu-wz-ps8" secondAttribute="height" multiplier="0.5" id="ubN-Qh-I5H"/> <constraint firstItem="5XD-I3-tLg" firstAttribute="height" secondItem="8Uu-wz-ps8" secondAttribute="height" multiplier="1.7:3" id="WGx-z3-vXf"/>
<constraint firstItem="wWH-Lx-U9x" firstAttribute="top" secondItem="vhb-Xd-o6a" secondAttribute="bottom" constant="32" id="lVY-5z-fz7"/>
<constraint firstItem="vhb-Xd-o6a" firstAttribute="centerX" secondItem="8Uu-wz-ps8" secondAttribute="centerX" id="oCf-dA-bJX"/>
</constraints> </constraints>
</view> </view>
</viewController> </viewController>
@ -47,6 +54,6 @@
</scene> </scene>
</scenes> </scenes>
<resources> <resources>
<image name="Delta" width="1342" height="1196"/> <image name="LaunchViewC" width="375" height="472.5"/>
</resources> </resources>
</document> </document>

View File

@ -1,16 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14868" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="SPq-Bk-fQl"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="SPq-Bk-fQl">
<device id="retina4_7" orientation="portrait" appearance="light"/> <device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14824"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22684"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
<scenes> <scenes>
<!--Games--> <!--Games View Controller-->
<scene sceneID="Cd2-Pf-cua"> <scene sceneID="Cd2-Pf-cua">
<objects> <objects>
<viewController id="jeE-WD-wXO" customClass="GamesViewController" customModule="Delta" customModuleProvider="target" sceneMemberID="viewController"> <viewController id="jeE-WD-wXO" customClass="GamesViewController" customModule="Retro_Game_Emulator" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides> <layoutGuides>
<viewControllerLayoutGuide type="top" id="WoX-O4-qy5"/> <viewControllerLayoutGuide type="top" id="WoX-O4-qy5"/>
<viewControllerLayoutGuide type="bottom" id="0om-QB-N5a"/> <viewControllerLayoutGuide type="bottom" id="0om-QB-N5a"/>
@ -25,48 +25,80 @@
<segue destination="tpK-ou-yEA" kind="embed" identifier="embedPageViewController" id="cjU-nW-cHY"/> <segue destination="tpK-ou-yEA" kind="embed" identifier="embedPageViewController" id="cjU-nW-cHY"/>
</connections> </connections>
</containerView> </containerView>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="bg" translatesAutoresizingMaskIntoConstraints="NO" id="J8K-ZI-4X1">
<rect key="frame" x="0.0" y="56" width="375" height="591"/>
</imageView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="CxB-GP-B6S">
<rect key="frame" x="0.0" y="538" width="375" height="109"/>
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
<state key="normal" image="home_tab"/>
<connections>
<segue destination="xMK-Cs-fAS" kind="presentation" modalPresentationStyle="fullScreen" id="bxS-9X-3vh"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="n4H-Kw-HPj">
<rect key="frame" x="143.5" y="517" width="100" height="100"/>
<constraints>
<constraint firstAttribute="height" constant="100" id="SLR-9h-t9y"/>
<constraint firstAttribute="width" constant="100" id="Tdv-6u-nlA"/>
</constraints>
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
<state key="normal" image="addtwo"/>
<connections>
<action selector="importfilesBtn:" destination="jeE-WD-wXO" eventType="touchUpInside" id="T2w-zr-j8V"/>
</connections>
</button>
</subviews> </subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints> <constraints>
<constraint firstAttribute="trailing" secondItem="CxB-GP-B6S" secondAttribute="trailing" id="5sO-AB-YB5"/>
<constraint firstAttribute="trailing" secondItem="J8K-ZI-4X1" secondAttribute="trailing" id="7MY-qA-ANn"/>
<constraint firstAttribute="trailing" secondItem="tmn-gd-5UN" secondAttribute="trailing" id="9Rq-HM-vqk"/> <constraint firstAttribute="trailing" secondItem="tmn-gd-5UN" secondAttribute="trailing" id="9Rq-HM-vqk"/>
<constraint firstItem="J8K-ZI-4X1" firstAttribute="leading" secondItem="3Bk-k3-7J9" secondAttribute="leading" id="9kW-o9-BMv"/>
<constraint firstItem="CxB-GP-B6S" firstAttribute="centerX" secondItem="3Bk-k3-7J9" secondAttribute="centerX" id="Dbp-v1-mUp"/>
<constraint firstItem="n4H-Kw-HPj" firstAttribute="centerX" secondItem="3Bk-k3-7J9" secondAttribute="centerX" constant="6" id="H9T-X7-RK8"/>
<constraint firstItem="0om-QB-N5a" firstAttribute="top" secondItem="n4H-Kw-HPj" secondAttribute="bottom" constant="30" id="QHB-jA-R0s"/>
<constraint firstItem="0om-QB-N5a" firstAttribute="top" secondItem="CxB-GP-B6S" secondAttribute="bottom" id="QzJ-Kr-VZk"/>
<constraint firstItem="CxB-GP-B6S" firstAttribute="leading" secondItem="3Bk-k3-7J9" secondAttribute="leading" id="axc-ed-3zE"/>
<constraint firstItem="tmn-gd-5UN" firstAttribute="leading" secondItem="3Bk-k3-7J9" secondAttribute="leading" id="f1f-sa-dBA"/> <constraint firstItem="tmn-gd-5UN" firstAttribute="leading" secondItem="3Bk-k3-7J9" secondAttribute="leading" id="f1f-sa-dBA"/>
<constraint firstAttribute="bottom" secondItem="tmn-gd-5UN" secondAttribute="bottom" id="ifM-Wa-u9y"/> <constraint firstAttribute="bottom" secondItem="tmn-gd-5UN" secondAttribute="bottom" id="ifM-Wa-u9y"/>
<constraint firstItem="J8K-ZI-4X1" firstAttribute="top" secondItem="WoX-O4-qy5" secondAttribute="bottom" id="jaI-AF-tpn"/>
<constraint firstItem="tmn-gd-5UN" firstAttribute="top" secondItem="3Bk-k3-7J9" secondAttribute="top" id="nhS-aC-rUR"/> <constraint firstItem="tmn-gd-5UN" firstAttribute="top" secondItem="3Bk-k3-7J9" secondAttribute="top" id="nhS-aC-rUR"/>
<constraint firstItem="0om-QB-N5a" firstAttribute="top" secondItem="J8K-ZI-4X1" secondAttribute="bottom" id="tvh-Sd-zA1"/>
</constraints> </constraints>
</view> </view>
<navigationItem key="navigationItem" title="Games" id="pFk-as-3k4"> <navigationItem key="navigationItem" id="pFk-as-3k4">
<barButtonItem key="leftBarButtonItem" image="SettingsButton" id="2gg-lC-FhX"> <barButtonItem key="leftBarButtonItem" image="home" id="2gg-lC-FhX"/>
<connections> <barButtonItem key="rightBarButtonItem" style="plain" id="FeA-O5-xd2">
<segue destination="xMK-Cs-fAS" kind="presentation" identifier="showSettings" id="uN5-PN-7FK"/>
</connections>
</barButtonItem>
<barButtonItem key="rightBarButtonItem" systemItem="add" id="FeA-O5-xd2">
<connections> <connections>
<action selector="importFiles" destination="jeE-WD-wXO" id="A1s-kE-NkM"/> <action selector="importFiles" destination="jeE-WD-wXO" id="A1s-kE-NkM"/>
</connections> </connections>
</barButtonItem> </barButtonItem>
</navigationItem> </navigationItem>
<connections>
<outlet property="importButton" destination="FeA-O5-xd2" id="A44-3S-Okz"/>
</connections>
</viewController> </viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="JYx-xE-nis" userLabel="First Responder" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="JYx-xE-nis" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects> </objects>
<point key="canvasLocation" x="1036" y="1002"/> <point key="canvasLocation" x="1036" y="1001.649175412294"/>
</scene> </scene>
<!--Game Collection View Controller--> <!--Game Collection View Controller-->
<scene sceneID="qNA-NP-TiF"> <scene sceneID="qNA-NP-TiF">
<objects> <objects>
<collectionViewController storyboardIdentifier="gameCollectionViewController" clearsSelectionOnViewWillAppear="NO" id="kqu-75-owz" customClass="GameCollectionViewController" customModule="Delta" customModuleProvider="target" sceneMemberID="viewController"> <collectionViewController storyboardIdentifier="gameCollectionViewController" clearsSelectionOnViewWillAppear="NO" id="kqu-75-owz" customClass="GameCollectionViewController" customModule="Retro_Game_Emulator" customModuleProvider="target" sceneMemberID="viewController">
<collectionView key="view" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" indicatorStyle="white" dataMode="prototypes" id="OIq-Z8-kxO"> <collectionView key="view" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" indicatorStyle="white" dataMode="prototypes" id="OIq-Z8-kxO">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/> <color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="20" minimumInteritemSpacing="10" id="NKN-dd-bTh" customClass="GridCollectionViewLayout" customModule="Delta" customModuleProvider="target"> <collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="20" minimumInteritemSpacing="10" id="NKN-dd-bTh" customClass="GridCollectionViewLayout" customModule="Retro_Game_Emulator" customModuleProvider="target">
<size key="itemSize" width="100" height="100"/> <size key="itemSize" width="100" height="100"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/> <size key="headerReferenceSize" width="0.0" height="0.0"/>
<size key="footerReferenceSize" width="0.0" height="0.0"/> <size key="footerReferenceSize" width="0.0" height="0.0"/>
<inset key="sectionInset" minX="0.0" minY="20" maxX="0.0" maxY="20"/> <inset key="sectionInset" minX="0.0" minY="20" maxX="0.0" maxY="20"/>
</collectionViewFlowLayout> </collectionViewFlowLayout>
<cells> <cells>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="Cell" id="ioT-sh-j8y" customClass="GridCollectionViewCell" customModule="Delta" customModuleProvider="target"> <collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="Cell" id="ioT-sh-j8y" customClass="GridCollectionViewCell" customModule="Retro_Game_Emulator" customModuleProvider="target">
<rect key="frame" x="0.0" y="20" width="100" height="100"/> <rect key="frame" x="0.0" y="20" width="100" height="100"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center"> <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
@ -82,7 +114,9 @@
</collectionView> </collectionView>
<connections> <connections>
<segue destination="X2o-q6-XD5" kind="unwind" identifier="unwindFromGames" unwindAction="unwindFromGamesViewControllerWith:" id="k8C-Xn-maU"/> <segue destination="X2o-q6-XD5" kind="unwind" identifier="unwindFromGames" unwindAction="unwindFromGamesViewControllerWith:" id="k8C-Xn-maU"/>
<segue destination="MPk-bF-nkj" kind="presentation" identifier="saveStates" customClass="SaveStatesStoryboardSegue" customModule="Delta" customModuleProvider="target" id="1Xp-2J-0cq"/> <segue destination="MPk-bF-nkj" kind="presentation" identifier="saveStates" customClass="SaveStatesStoryboardSegue" customModule="Retro_Game_Emulator" customModuleProvider="target" id="1Xp-2J-0cq"/>
<segue destination="qdE-gb-V2e" kind="presentation" identifier="preferredControllerSkins" id="i6y-cP-3WM"/>
<segue destination="V2x-v0-jWm" kind="presentation" identifier="showDSSettings" id="kuV-tY-Y0B"/>
</connections> </connections>
</collectionViewController> </collectionViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="bW1-t8-idm" userLabel="First Responder" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="bW1-t8-idm" userLabel="First Responder" sceneMemberID="firstResponder"/>
@ -93,7 +127,7 @@
<!--Launch View Controller--> <!--Launch View Controller-->
<scene sceneID="p7y-IT-nlb"> <scene sceneID="p7y-IT-nlb">
<objects> <objects>
<viewController id="SPq-Bk-fQl" customClass="LaunchViewController" customModule="Delta" customModuleProvider="target" sceneMemberID="viewController"> <viewController id="SPq-Bk-fQl" customClass="LaunchViewController" customModule="Retro_Game_Emulator" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides> <layoutGuides>
<viewControllerLayoutGuide type="top" id="Qap-U8-zpQ"/> <viewControllerLayoutGuide type="top" id="Qap-U8-zpQ"/>
<viewControllerLayoutGuide type="bottom" id="dca-QO-wba"/> <viewControllerLayoutGuide type="bottom" id="dca-QO-wba"/>
@ -112,12 +146,38 @@
<containerView opaque="NO" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="vf5-Iy-lAb" userLabel="Launch Screen"> <containerView opaque="NO" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="vf5-Iy-lAb" userLabel="Launch Screen">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="0.071399740870000006" green="0.082175157959999995" blue="0.10832635309999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections> <connections>
<segue destination="ibA-aC-X3M" kind="embed" id="fsv-uf-AOE"/> <segue destination="ibA-aC-X3M" kind="embed" id="fsv-uf-AOE"/>
</connections> </connections>
</containerView> </containerView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Mgn-IF-ax7">
<rect key="frame" x="187.5" y="448" width="0.0" height="0.0"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="28"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" alpha="0.44999998807907104" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="wnW-MB-udh">
<rect key="frame" x="187.5" y="480" width="0.0" height="0.0"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="50O-wR-1hq">
<rect key="frame" x="0.0" y="50" width="375" height="378"/>
</imageView>
</subviews> </subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <color key="backgroundColor" red="0.071399740870000006" green="0.082175157959999995" blue="0.10832635309999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="50O-wR-1hq" secondAttribute="trailing" id="2Xh-ZZ-Dbc"/>
<constraint firstItem="50O-wR-1hq" firstAttribute="leading" secondItem="8jv-0a-ItC" secondAttribute="leading" id="6rJ-Cz-C3Z"/>
<constraint firstItem="Mgn-IF-ax7" firstAttribute="centerX" secondItem="8jv-0a-ItC" secondAttribute="centerX" id="8kV-gZ-4TW"/>
<constraint firstItem="50O-wR-1hq" firstAttribute="height" secondItem="8jv-0a-ItC" secondAttribute="height" multiplier="1.7:3" id="FTt-Ru-HhA"/>
<constraint firstItem="wnW-MB-udh" firstAttribute="top" secondItem="Mgn-IF-ax7" secondAttribute="bottom" constant="32" id="IAR-im-kU7"/>
<constraint firstItem="50O-wR-1hq" firstAttribute="top" secondItem="Qap-U8-zpQ" secondAttribute="bottom" constant="30" id="bo1-Am-BdP"/>
<constraint firstItem="wnW-MB-udh" firstAttribute="centerX" secondItem="8jv-0a-ItC" secondAttribute="centerX" id="djF-KX-NgM"/>
<constraint firstItem="Mgn-IF-ax7" firstAttribute="top" secondItem="50O-wR-1hq" secondAttribute="bottom" constant="20" id="igk-jf-lgM"/>
</constraints>
</view> </view>
<connections> <connections>
<outlet property="gameViewContainerView" destination="oBZ-xU-jeC" id="jMI-iF-JlU"/> <outlet property="gameViewContainerView" destination="oBZ-xU-jeC" id="jMI-iF-JlU"/>
@ -138,7 +198,7 @@
<!--Game View Controller--> <!--Game View Controller-->
<scene sceneID="ASV-Uk-0aP"> <scene sceneID="ASV-Uk-0aP">
<objects> <objects>
<viewController id="yhz-fF-D91" customClass="GameViewController" customModule="Delta" customModuleProvider="target" sceneMemberID="viewController"> <viewController id="yhz-fF-D91" customClass="GameViewController" customModule="Retro_Game_Emulator" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides> <layoutGuides>
<viewControllerLayoutGuide type="top" id="ItC-Bu-WRI"/> <viewControllerLayoutGuide type="top" id="ItC-Bu-WRI"/>
<viewControllerLayoutGuide type="bottom" id="g58-HO-6L5"/> <viewControllerLayoutGuide type="bottom" id="g58-HO-6L5"/>
@ -146,12 +206,23 @@
<view key="view" contentMode="scaleToFill" id="skW-1S-YD4"> <view key="view" contentMode="scaleToFill" id="skW-1S-YD4">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/> <subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="bg" translatesAutoresizingMaskIntoConstraints="NO" id="0b6-zE-QS0">
<rect key="frame" x="0.0" y="20" width="375" height="647"/>
</imageView>
</subviews>
<color key="backgroundColor" red="0.02214059979" green="0.092763282360000004" blue="0.18196243049999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="0b6-zE-QS0" secondAttribute="trailing" id="5n6-uA-WLa"/>
<constraint firstItem="0b6-zE-QS0" firstAttribute="top" secondItem="ItC-Bu-WRI" secondAttribute="bottom" id="DTE-cg-9BW"/>
<constraint firstItem="0b6-zE-QS0" firstAttribute="leading" secondItem="skW-1S-YD4" secondAttribute="leading" id="Ej3-6D-wcR"/>
<constraint firstItem="g58-HO-6L5" firstAttribute="top" secondItem="0b6-zE-QS0" secondAttribute="bottom" id="ozO-Ni-qpr"/>
</constraints>
</view> </view>
<connections> <connections>
<segue destination="Yrw-9v-Pcr" kind="presentation" identifier="pause" customClass="PauseStoryboardSegue" customModule="Delta" customModuleProvider="target" id="FLq-Zt-HDv"/> <segue destination="Yrw-9v-Pcr" kind="presentation" identifier="pause" customClass="PauseStoryboardSegue" customModule="Retro_Game_Emulator" customModuleProvider="target" id="FLq-Zt-HDv"/>
<segue destination="wKV-3d-NIY" kind="presentation" identifier="showGamesViewController" customClass="GamesStoryboardSegue" customModule="Delta" customModuleProvider="target" id="Tey-6Z-UHp"/> <segue destination="wKV-3d-NIY" kind="presentation" identifier="showGamesViewController" customClass="GamesStoryboardSegue" customModule="Retro_Game_Emulator" customModuleProvider="target" id="Tey-6Z-UHp"/>
<segue destination="wKV-3d-NIY" kind="presentation" identifier="showInitialGamesViewController" customClass="InitialGamesStoryboardSegue" customModule="Delta" customModuleProvider="target" id="eR2-0c-0Rv"/> <segue destination="wKV-3d-NIY" kind="presentation" identifier="showInitialGamesViewController" customClass="InitialGamesStoryboardSegue" customModule="Retro_Game_Emulator" customModuleProvider="target" id="eR2-0c-0Rv"/>
</connections> </connections>
</viewController> </viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="gxI-00-NlJ" userLabel="First Responder" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="gxI-00-NlJ" userLabel="First Responder" sceneMemberID="firstResponder"/>
@ -169,10 +240,12 @@
<!--Settings--> <!--Settings-->
<scene sceneID="L3X-MM-hJL"> <scene sceneID="L3X-MM-hJL">
<objects> <objects>
<viewControllerPlaceholder storyboardName="Settings" id="xMK-Cs-fAS" sceneMemberID="viewController"/> <viewControllerPlaceholder storyboardName="Settings" id="xMK-Cs-fAS" sceneMemberID="viewController">
<navigationItem key="navigationItem" id="7yR-QM-2bX"/>
</viewControllerPlaceholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="2N5-3k-beA" userLabel="First Responder" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="2N5-3k-beA" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects> </objects>
<point key="canvasLocation" x="1036" y="605"/> <point key="canvasLocation" x="1578" y="774"/>
</scene> </scene>
<!--Navigation Controller--> <!--Navigation Controller-->
<scene sceneID="zJI-sC-1sm"> <scene sceneID="zJI-sC-1sm">
@ -183,6 +256,8 @@
<navigationBar key="navigationBar" contentMode="scaleToFill" id="wj9-1e-eev"> <navigationBar key="navigationBar" contentMode="scaleToFill" id="wj9-1e-eev">
<rect key="frame" x="0.0" y="0.0" width="375" height="56"/> <rect key="frame" x="0.0" y="0.0" width="375" height="56"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="barTintColor" red="0.032843004910000001" green="0.076728828250000006" blue="0.13726195690000001" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
</navigationBar> </navigationBar>
<nil name="viewControllers"/> <nil name="viewControllers"/>
<toolbar key="toolbar" opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="M4r-sO-G4H"> <toolbar key="toolbar" opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="M4r-sO-G4H">
@ -217,7 +292,7 @@
<nil name="viewControllers"/> <nil name="viewControllers"/>
<connections> <connections>
<segue destination="Eae-Qk-9MI" kind="relationship" relationship="rootViewController" id="1Jh-Zf-ntp"/> <segue destination="Eae-Qk-9MI" kind="relationship" relationship="rootViewController" id="1Jh-Zf-ntp"/>
<segue destination="WQV-Du-4IA" kind="unwind" identifier="unwindFromSaveStates" customClass="SaveStatesStoryboardUnwindSegue" customModule="Delta" customModuleProvider="target" unwindAction="unwindFromSaveStatesViewControllerWith:" id="dwO-iv-XDr"/> <segue destination="WQV-Du-4IA" kind="unwind" identifier="unwindFromSaveStates" customClass="SaveStatesStoryboardUnwindSegue" customModule="Retro_Game_Emulator" customModuleProvider="target" unwindAction="unwindToGameCollectionViewController:" id="dwO-iv-XDr"/>
</connections> </connections>
</navigationController> </navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="htj-tq-2KP" userLabel="First Responder" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="htj-tq-2KP" userLabel="First Responder" sceneMemberID="firstResponder"/>
@ -225,6 +300,16 @@
</objects> </objects>
<point key="canvasLocation" x="2652" y="1718"/> <point key="canvasLocation" x="2652" y="1718"/>
</scene> </scene>
<!--preferredControllerSkins-->
<scene sceneID="aKY-Ld-et6">
<objects>
<viewControllerPlaceholder storyboardName="Settings" referencedIdentifier="preferredControllerSkins" id="dbc-pQ-iun" sceneMemberID="viewController">
<navigationItem key="navigationItem" id="xth-MV-SHp"/>
</viewControllerPlaceholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="za6-AO-ZFe" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="3405" y="2394"/>
</scene>
<!--saveStatesViewController--> <!--saveStatesViewController-->
<scene sceneID="f1R-Kb-FOU"> <scene sceneID="f1R-Kb-FOU">
<objects> <objects>
@ -235,11 +320,46 @@
</objects> </objects>
<point key="canvasLocation" x="3409" y="1716"/> <point key="canvasLocation" x="3409" y="1716"/>
</scene> </scene>
<!--Navigation Controller-->
<scene sceneID="eMh-8N-ZGA">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="qdE-gb-V2e" sceneMemberID="viewController">
<toolbarItems/>
<navigationItem key="navigationItem" id="Dg6-He-v5H"/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" largeTitles="YES" id="35T-4Q-Mmp">
<rect key="frame" x="0.0" y="0.0" width="375" height="108"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="dbc-pQ-iun" kind="relationship" relationship="rootViewController" id="oRb-B6-c0J"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="XmB-QY-yA3" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2652" y="2394"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="OW2-zT-pbF">
<objects>
<navigationController id="V2x-v0-jWm" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="pjb-4I-yar">
<rect key="frame" x="0.0" y="0.0" width="375" height="56"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Jo9-gl-p5p" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2652" y="3085"/>
</scene>
</scenes> </scenes>
<resources>
<image name="SettingsButton" width="22" height="22"/>
</resources>
<inferredMetricsTieBreakers> <inferredMetricsTieBreakers>
<segue reference="Tey-6Z-UHp"/> <segue reference="Tey-6Z-UHp"/>
</inferredMetricsTieBreakers> </inferredMetricsTieBreakers>
<resources>
<image name="addtwo" width="519" height="519"/>
<image name="bg" width="375" height="812"/>
<image name="home" width="92" height="37"/>
<image name="home_tab" width="384.5" height="109"/>
</resources>
</document> </document>

View File

@ -1,9 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15400" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Dt0-nV-isV"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17506" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Dt0-nV-isV">
<device id="retina4_7" orientation="portrait" appearance="light"/> <device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15404"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17504.1"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
<scenes> <scenes>
@ -167,7 +168,7 @@
</connections> </connections>
</barButtonItem> </barButtonItem>
<barButtonItem style="plain" id="has-I3-HDZ"> <barButtonItem style="plain" id="has-I3-HDZ">
<button key="customView" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="y2a-9f-EFz"> <button key="customView" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" id="y2a-9f-EFz">
<rect key="frame" x="288.5" y="13" width="30" height="30"/> <rect key="frame" x="288.5" y="13" width="30" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="▼"/> <state key="normal" title="▼"/>
@ -206,7 +207,7 @@
<visualEffectView opaque="NO" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="emc-gw-KkJ" userLabel="Selected Background View"> <visualEffectView opaque="NO" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="emc-gw-KkJ" userLabel="Selected Background View">
<rect key="frame" x="0.0" y="0.0" width="375" height="45"/> <rect key="frame" x="0.0" y="0.0" width="375" height="45"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" ambiguous="YES" id="9bA-Tg-Bko"> <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="9bA-Tg-Bko">
<rect key="frame" x="0.0" y="0.0" width="375" height="45"/> <rect key="frame" x="0.0" y="0.0" width="375" height="45"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
@ -266,7 +267,7 @@
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" keyboardDismissMode="interactive" dataMode="static" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" id="BV9-ff-x83"> <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" keyboardDismissMode="interactive" dataMode="static" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" id="BV9-ff-x83">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> <color key="backgroundColor" red="0.94901960784313721" green="0.94901960784313721" blue="0.96862745098039216" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<sections> <sections>
<tableViewSection headerTitle="Name" id="QT6-DZ-g70"> <tableViewSection headerTitle="Name" id="QT6-DZ-g70">
<cells> <cells>
@ -337,7 +338,7 @@
<subviews> <subviews>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" text="XXXXXXXX YYYYYYYY" translatesAutoresizingMaskIntoConstraints="NO" id="a17-LB-QXD" customClass="CheatTextView" customModule="Delta" customModuleProvider="target"> <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" text="XXXXXXXX YYYYYYYY" translatesAutoresizingMaskIntoConstraints="NO" id="a17-LB-QXD" customClass="CheatTextView" customModule="Delta" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="375" height="210"/> <rect key="frame" x="0.0" y="0.0" width="375" height="210"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> <color key="textColor" systemColor="labelColor"/>
<fontDescription key="fontDescription" name="Menlo-Regular" family="Menlo" pointSize="26"/> <fontDescription key="fontDescription" name="Menlo-Regular" family="Menlo" pointSize="26"/>
<textInputTraits key="textInputTraits" autocapitalizationType="allCharacters" autocorrectionType="no" spellCheckingType="no" returnKeyType="done"/> <textInputTraits key="textInputTraits" autocapitalizationType="allCharacters" autocorrectionType="no" spellCheckingType="no" returnKeyType="done"/>
<connections> <connections>
@ -398,4 +399,9 @@
<point key="canvasLocation" x="2385" y="1377"/> <point key="canvasLocation" x="2385" y="1377"/>
</scene> </scene>
</scenes> </scenes>
<resources>
<systemColor name="labelColor">
<color white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document> </document>

File diff suppressed because it is too large Load Diff

View File

@ -17,8 +17,7 @@ extension Action
case destructive case destructive
case selected case selected
var alertActionStyle: UIAlertAction.Style var alertActionStyle: UIAlertAction.Style {
{
switch self switch self
{ {
case .default, .selected: return .default case .default, .selected: return .default
@ -27,8 +26,7 @@ extension Action
} }
} }
var previewActionStyle: UIPreviewAction.Style? var previewActionStyle: UIPreviewAction.Style? {
{
switch self switch self
{ {
case .default: return .default case .default: return .default
@ -40,11 +38,40 @@ extension Action
} }
} }
@available(iOS 13, *)
extension Action.Style
{
var menuAttributes: UIMenuElement.Attributes {
switch self
{
case .default, .cancel, .selected: return []
case .destructive: return .destructive
}
}
var menuState: UIMenuElement.State {
switch self
{
case .default, .cancel, .destructive: return .off
case .selected: return .on
}
}
}
struct Action struct Action
{ {
let title: String var title: String
let style: Style var style: Style
let action: ((Action) -> Void)? var image: UIImage? = nil
var action: ((Action) -> Void)?
init(title: String, style: Style = .default, image: UIImage? = nil, action: ((Action) -> Void)? = nil)
{
self.title = title
self.style = style
self.image = image
self.action = action
}
} }
extension UIAlertAction extension UIAlertAction
@ -82,6 +109,19 @@ extension UIAlertController
} }
} }
@available(iOS 13.0, *)
extension UIAction
{
convenience init?(_ action: Action)
{
guard action.style != .cancel else { return nil }
self.init(title: action.title, image: action.image, attributes: action.style.menuAttributes, state: action.style.menuState) { _ in
action.action?(action)
}
}
}
extension RangeReplaceableCollection where Iterator.Element == Action extension RangeReplaceableCollection where Iterator.Element == Action
{ {
var alertActions: [UIAlertAction] { var alertActions: [UIAlertAction] {
@ -93,4 +133,10 @@ extension RangeReplaceableCollection where Iterator.Element == Action
let actions = self.compactMap { UIPreviewAction($0) } let actions = self.compactMap { UIPreviewAction($0) }
return actions return actions
} }
@available(iOS 13.0, *)
var menuActions: [UIAction] {
let actions = self.compactMap { UIAction($0) }
return actions
}
} }

View File

@ -39,7 +39,7 @@ class GridCollectionViewCell: UICollectionViewCell
} }
} }
var maximumImageSize: CGSize = CGSize(width: 100, height: 100) { var maximumImageSize: CGSize = CGSize(width: 150, height: 120) {
didSet { didSet {
self.updateMaximumImageSize() self.updateMaximumImageSize()
} }
@ -109,13 +109,15 @@ class GridCollectionViewCell: UICollectionViewCell
// Image View // Image View
self.imageView.translatesAutoresizingMaskIntoConstraints = false self.imageView.translatesAutoresizingMaskIntoConstraints = false
self.imageView.topAnchor.constraint(equalTo: self.contentView.topAnchor).isActive = true self.imageView.topAnchor.constraint(equalTo: self.vibrancyView.topAnchor).isActive = true
self.imageView.centerXAnchor.constraint(equalTo: self.contentView.centerXAnchor).isActive = true self.imageView.centerXAnchor.constraint(equalTo: self.vibrancyView.centerXAnchor).isActive = true
self.imageViewWidthConstraint = self.imageView.widthAnchor.constraint(equalToConstant: self.maximumImageSize.width) self.imageViewWidthConstraint = self.imageView.widthAnchor.constraint(equalToConstant: 150)
self.imageViewWidthConstraint.isActive = true self.imageViewWidthConstraint.isActive = true
self.imageViewHeightConstraint = self.imageView.heightAnchor.constraint(equalToConstant: self.maximumImageSize.height) self.imageViewHeightConstraint = self.imageView.heightAnchor.constraint(equalToConstant: 120)
self.imageViewHeightConstraint.priority = UILayoutPriority(999) // Fixes "Unable to simultaneously satisfy constraints" runtime error when inserting new grid row.
self.imageViewHeightConstraint.isActive = true self.imageViewHeightConstraint.isActive = true
@ -181,10 +183,15 @@ private extension GridCollectionViewCell
{ {
func updateMaximumImageSize() func updateMaximumImageSize()
{ {
self.imageViewWidthConstraint.constant = self.maximumImageSize.width self.imageViewWidthConstraint.constant = 150
self.imageViewHeightConstraint.constant = self.maximumImageSize.height self.imageViewHeightConstraint.constant = 120
self.textLabelVerticalSpacingConstraint.constant = 8 self.textLabelVerticalSpacingConstraint.constant = 8
self.textLabelFocusedVerticalSpacingConstraint?.constant = self.maximumImageSize.height / 10.0 self.textLabelFocusedVerticalSpacingConstraint?.constant = self.maximumImageSize.height / 10.0
// textLabel 30
// let textLabelFixedHeight: CGFloat = 30
//
// self.textLabelVerticalSpacingConstraint.constant = textLabelFixedHeight
// self.textLabelFocusedVerticalSpacingConstraint?.constant = textLabelFixedHeight / 50
} }
} }

View File

@ -50,6 +50,8 @@ class GridCollectionViewLayout: UICollectionViewFlowLayout
return interitemSpacing return interitemSpacing
} }
private var cachedCellLayoutAttributes = [IndexPath: UICollectionViewLayoutAttributes]()
override var estimatedItemSize: CGSize { override var estimatedItemSize: CGSize {
didSet { didSet {
fatalError("GridCollectionViewLayout does not support self-sizing cells.") fatalError("GridCollectionViewLayout does not support self-sizing cells.")
@ -64,6 +66,18 @@ class GridCollectionViewLayout: UICollectionViewFlowLayout
self.sectionInset.right = self.interitemSpacing + self.contentInset.right self.sectionInset.right = self.interitemSpacing + self.contentInset.right
} }
override func invalidateLayout(with context: UICollectionViewLayoutInvalidationContext)
{
super.invalidateLayout(with: context)
if let context = context as? UICollectionViewFlowLayoutInvalidationContext,
context.invalidateFlowLayoutAttributes || context.invalidateFlowLayoutDelegateMetrics || context.invalidateEverything
{
// Clear layout cache to prevent crashing due to returning outdated layout attributes.
self.cachedCellLayoutAttributes = [:]
}
}
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]?
{ {
let layoutAttributes = super.layoutAttributesForElements(in: rect)?.map({ $0.copy() }) as! [UICollectionViewLayoutAttributes] let layoutAttributes = super.layoutAttributesForElements(in: rect)?.map({ $0.copy() }) as! [UICollectionViewLayoutAttributes]
@ -137,9 +151,24 @@ class GridCollectionViewLayout: UICollectionViewFlowLayout
} }
} }
for attributes in layoutAttributes where attributes.representedElementCategory == .cell
{
// Update cached attributes for layoutAttributesForItem(at:)
self.cachedCellLayoutAttributes[attributes.indexPath] = attributes
}
return layoutAttributes return layoutAttributes
} }
override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes?
{
if let cachedAttributes = self.cachedCellLayoutAttributes[indexPath]
{
return cachedAttributes
}
return super.layoutAttributesForItem(at: indexPath)
}
} }
private extension GridCollectionViewLayout private extension GridCollectionViewLayout

View File

@ -21,7 +21,8 @@ class ListMenuViewController: UITableViewController
override var preferredContentSize: CGSize { override var preferredContentSize: CGSize {
get { get {
let navigationBarHeight = self.navigationController?.navigationBar.bounds.height ?? 0.0 // Don't include navigation bar height in calculation (as of iOS 13).
let navigationBarHeight = 0.0 // self.navigationController?.navigationBar.bounds.height ?? 0.0
return CGSize(width: 0, height: (self.tableView.rowHeight * CGFloat(self.items.count)) + navigationBarHeight) return CGSize(width: 0, height: (self.tableView.rowHeight * CGFloat(self.items.count)) + navigationBarHeight)
} }
set {} set {}

View File

@ -17,7 +17,7 @@ extension UINavigationBar
} }
// Make "copy" of self. // Make "copy" of self.
let navigationBar = UINavigationBar(frame: .zero) let navigationBar = UINavigationBar(frame: self.bounds) // Use self.bounds to avoid "Unable to simultaneously satisfy constraints" runtime error.
navigationBar.barStyle = self.barStyle navigationBar.barStyle = self.barStyle
// Set item with title so we can retrieve default text attributes. // Set item with title so we can retrieve default text attributes.
@ -38,11 +38,33 @@ extension UINavigationBar
private var _defaultTitleTextAttributes: [NSAttributedString.Key: Any]? { private var _defaultTitleTextAttributes: [NSAttributedString.Key: Any]? {
guard self.titleTextAttributes == nil else { return self.titleTextAttributes } guard self.titleTextAttributes == nil else { return self.titleTextAttributes }
guard guard let contentView = self.subviews.first(where: { NSStringFromClass(type(of: $0)).contains("ContentView") || NSStringFromClass(type(of: $0)).contains("ItemView") })
let contentView = self.subviews.first(where: { NSStringFromClass(type(of: $0)).contains("ContentView") || NSStringFromClass(type(of: $0)).contains("ItemView") }),
let titleLabel = contentView.subviews.first(where: { $0 is UILabel }) as? UILabel
else { return nil } else { return nil }
let containerView: UIView
//TODO: Recursively search all subviews for title UILabel instead of hardcoded OS version-specific hierarchy traversals...
if #available(iOS 16, *)
{
guard let titleControl = contentView.subviews.first(where: { NSStringFromClass(type(of: $0)).contains("Title") }) else { return nil }
if #available(iOS 17, *)
{
guard let view = titleControl.subviews.first else { return nil }
containerView = view
}
else
{
containerView = titleControl
}
}
else
{
containerView = contentView
}
guard let titleLabel = containerView.subviews.first(where: { $0 is UILabel }) as? UILabel else { return nil }
let textAttributes = titleLabel.attributedText?.attributes(at: 0, effectiveRange: nil) let textAttributes = titleLabel.attributedText?.attributes(at: 0, effectiveRange: nil)
return textAttributes return textAttributes
} }
@ -63,6 +85,8 @@ class PopoverMenuButton: UIControl
private let arrowLabel: UILabel private let arrowLabel: UILabel
private let stackView: UIStackView private let stackView: UIStackView
private var _didLayoutSubviews = false
private var parentNavigationBar: UINavigationBar? { private var parentNavigationBar: UINavigationBar? {
guard let navigationController = self.parentViewController as? UINavigationController ?? self.parentViewController?.navigationController else { return nil } guard let navigationController = self.parentViewController as? UINavigationController ?? self.parentViewController?.navigationController else { return nil }
guard self.isDescendant(of: navigationController.navigationBar) else { return nil } guard self.isDescendant(of: navigationController.navigationBar) else { return nil }
@ -104,6 +128,21 @@ class PopoverMenuButton: UIControl
{ {
self.updateTextAttributes() self.updateTextAttributes()
} }
override func layoutSubviews()
{
super.layoutSubviews()
if !_didLayoutSubviews
{
_didLayoutSubviews = true
// didMoveToSuperview() can be too early to accurately
// update text attributes, so ensure we also update
// during first layoutSubviews() call.
self.updateTextAttributes()
}
}
} }
private extension PopoverMenuButton private extension PopoverMenuButton

View File

@ -0,0 +1,143 @@
//
// CheatBase.swift
// Delta
//
// Created by Riley Testut on 1/17/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import Foundation
import SQLite
import Roxas
private extension UserDefaults
{
@NSManaged var previousCheatBaseVersion: Int
}
extension ExpressionType
{
static var cheatID: SQLite.Expression<Int> {
return SQLite.Expression<Int>("cheatID")
}
static var cheatName: SQLite.Expression<String> {
return SQLite.Expression<String>("cheatName")
}
static var cheatDescription: SQLite.Expression<String?> {
return SQLite.Expression<String?>("cheatDescription")
}
static var cheatCode: SQLite.Expression<String> {
return SQLite.Expression<String>("cheatCode")
}
static var cheatDeviceID: SQLite.Expression<Int> {
return SQLite.Expression<Int>("cheatDeviceID")
}
static var cheatActivation: SQLite.Expression<String?> {
return SQLite.Expression<String?>("cheatActivation")
}
static var cheatCategoryID: SQLite.Expression<Int> {
return SQLite.Expression<Int>("cheatCategoryID")
}
static var cheatCategoryName: SQLite.Expression<String> {
return SQLite.Expression<String>("cheatCategory")
}
static var cheatCategoryDescription: SQLite.Expression<String> {
return SQLite.Expression<String>("cheatCategoryDescription")
}
}
extension Table
{
static var cheats: Table {
return Table("CHEATS")
}
static var cheatCategories: Table {
return Table("CHEAT_CATEGORIES")
}
}
@available(iOS 14, *)
class CheatBase: GamesDatabase
{
static let cheatsVersion = 1
static var previousCheatsVersion: Int? {
return UserDefaults.standard.previousCheatBaseVersion
}
private let connection: Connection
override init() throws
{
let fileURL = DatabaseManager.cheatBaseURL
guard FileManager.default.fileExists(atPath: fileURL.path) else { throw GamesDatabase.Error.doesNotExist }
self.connection = try Connection(fileURL.path)
try super.init()
UserDefaults.standard.previousCheatBaseVersion = CheatBase.cheatsVersion
}
func cheats(for game: Game) async throws -> [CheatMetadata]?
{
let metadata = await withCheckedContinuation { continuation in
if let context = game.managedObjectContext
{
context.perform {
let metadata = self.metadata(for: game)
continuation.resume(returning: metadata)
}
}
else
{
let metadata = self.metadata(for: game)
continuation.resume(returning: metadata)
}
}
guard let romIDValue = metadata?.romID else { return nil }
let cheatID = Expression<Any>.cheatID
let cheatName = Expression<Any>.cheatName
let cheatCode = Expression<Any>.cheatCode
let cheatDescription = Expression<Any>.cheatDescription
let cheatActivation = Expression<Any>.cheatActivation
let cheatDeviceID = Expression<Any>.cheatDeviceID
let categoryID = Expression<Any>.cheatCategoryID
let categoryName = Expression<Any>.cheatCategoryName
let categoryDescription = Expression<Any>.cheatCategoryDescription
let romID = Expression<Any>.romID
let query = Table.cheats.select(cheatID, cheatName, cheatCode, cheatDescription, cheatActivation, cheatDeviceID, Table.cheats[categoryID], categoryName, categoryDescription)
.filter(romID == romIDValue)
.join(Table.cheatCategories, on: Table.cheats[categoryID] == Table.cheatCategories[categoryID])
.order(cheatName)
let rows = try self.connection.prepare(query)
let results = rows.compactMap { (row) -> CheatMetadata? in
guard case let deviceID = Int16(row[cheatDeviceID]), let device = CheatDevice(rawValue: deviceID) else { return nil }
let id = row[Table.cheats[categoryID]]
let category = CheatCategory(id: id, name: row[categoryName], categoryDescription: row[categoryDescription])
let metadata = CheatMetadata(id: row[cheatID], name: row[cheatName], code: row[cheatCode], description: row[cheatDescription], activationHint: row[cheatActivation], device: device, category: category)
return metadata
}
return results
}
}

View File

@ -0,0 +1,273 @@
//
// CheatBaseView.swift
// Delta
//
// Created by Riley Testut on 1/17/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import SwiftUI
import enum SQLite.Result
@available(iOS 14, *)
extension CheatBaseView
{
private class ViewModel: ObservableObject
{
@Published
var allCheats: [CheatMetadata]? {
didSet {
guard let cheats = allCheats else {
self.cheatsByCategory = nil
return
}
let cheatsByCategory = Dictionary(grouping: cheats, by: { $0.category }).sorted { $0.key.id < $1.key.id }
self.cheatsByCategory = cheatsByCategory
}
}
@Published
private(set) var cheatsByCategory: [(CheatCategory, [CheatMetadata])]?
@Published
private(set) var error: Error?
@Published
var searchText: String = "" {
didSet {
self.searchCheats()
}
}
@Published
private(set) var filteredCheats: [CheatMetadata]?
@MainActor
func fetchCheats(for game: Game) async
{
guard self.allCheats == nil else { return }
do
{
let database = try CheatBase()
let cheats = try await database.cheats(for: game) ?? []
self.allCheats = cheats
}
catch
{
self.error = error
}
}
private func searchCheats()
{
if let cheats = self.allCheats, !self.searchText.isEmpty
{
let predicate = NSPredicate(forSearchingForText: self.searchText, inValuesForKeyPaths: [#keyPath(CheatMetadata.name), #keyPath(CheatMetadata.cheatDescription)])
let filteredCheats = cheats.filter { predicate.evaluate(with: $0) }
self.filteredCheats = filteredCheats
}
else
{
self.filteredCheats = nil
}
}
}
}
@available(iOS 14, *)
struct CheatBaseView: View
{
let game: Game?
var cancellationHandler: (() -> Void)?
var selectionHandler: ((CheatMetadata) -> Void)?
@StateObject
private var viewModel = ViewModel()
@State
private var activationHintCheat: CheatMetadata?
var body: some View {
NavigationView {
ZStack {
if let cheats = viewModel.allCheats, !cheats.isEmpty
{
// Only show List if there is at least one cheat for this game.
cheatList()
}
// Place above List
placeholderView()
}
.alert(item: $activationHintCheat) { cheat in
Alert(title: Text("How to Activate"),
message: Text(cheat.activationHint ?? ""),
dismissButton: .default(Text("OK")))
}
.navigationTitle(Text(game?.name ?? "CheatBase"))
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button("Cancel") {
cancellationHandler?()
}
}
}
}
.onAppear {
Task {
guard let game = self.game else { return }
await viewModel.fetchCheats(for: game)
}
}
}
private func cheatList() -> some View
{
VStack {
if #unavailable(iOS 15)
{
LegacySearchBar(text: $viewModel.searchText)
}
let listView = List {
if let filteredCheats = viewModel.filteredCheats
{
ForEach(filteredCheats) { cheat in
cell(for: cheat)
}
}
else if let cheats = viewModel.cheatsByCategory
{
ForEach(cheats, id: \.0.id) { (category, cheats) in
Section {
DisclosureGroup {
ForEach(cheats) { cheat in
cell(for: cheat)
}
} label: {
Text(category.name)
}
} footer: {
Text(category.categoryDescription)
}
}
}
}
if #available(iOS 15, *)
{
listView.searchable(text: $viewModel.searchText)
}
else
{
listView
}
}
.listStyle(.insetGrouped)
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .top)
}
private func cell(for cheat: CheatMetadata) -> some View
{
ZStack(alignment: .leading) {
Button(action: { choose(cheat) }) {}
HStack {
// Name + Description
VStack(alignment: .leading, spacing: 4) {
Text(cheat.name)
if let description = cheat.cheatDescription
{
Text(description)
.font(.caption)
}
}
// Activation Hint
if cheat.activationHint != nil
{
Spacer()
Button(action: { activationHintCheat = cheat }) {
Image(systemName: "info.circle")
}
.buttonStyle(.borderless)
}
}
.multilineTextAlignment(.leading)
}
}
private func placeholderView() -> some View
{
VStack(spacing: 8) {
if let error = viewModel.error
{
Text("Unable to Load Cheats")
.font(.title)
if let error = error as? SQLite.Result
{
// SQLite.Result implements CustomStringConvertible.description, but not localizedDescription.
Text(String(describing: error))
.font(.callout)
}
else
{
Text(error.localizedDescription)
.font(.callout)
}
}
else if let filteredCheats = viewModel.filteredCheats, filteredCheats.isEmpty
{
Text("Cheat Not Found")
.font(.title)
Text("Please make sure the name is correct, or try searching for another cheat.")
.font(.callout)
}
else if let cheats = viewModel.allCheats, cheats.isEmpty
{
Text("No Cheats")
.font(.title)
Text("There are no cheats for this game in Delta's CheatBase. Please try a different game.")
.font(.callout)
}
else if viewModel.allCheats == nil
{
ProgressView()
.progressViewStyle(.circular)
}
}
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center)
.foregroundColor(.gray)
.padding()
}
init(game: Game, cheats: [CheatMetadata]? = nil)
{
self.game = game
let viewModel = ViewModel()
viewModel.allCheats = cheats
self._viewModel = StateObject(wrappedValue: viewModel)
}
}
@available(iOS 14, *)
private extension CheatBaseView
{
func choose(_ cheatMetadata: CheatMetadata)
{
self.selectionHandler?(cheatMetadata)
}
}

View File

@ -0,0 +1,111 @@
//
// CheatDevice.swift
// Delta
//
// Created by Riley Testut on 1/30/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import Foundation
import DeltaCore
import NESDeltaCore
@objc
enum CheatDevice: Int16
{
case famicomGameGenie = 1
case famicomRaw = 2
case famicomRawCompare = 3
case gbGameGenie = 4
case gbaActionReplayMax = 5
case gbaCodeBreaker = 6
case gbaGameShark = 7
case gbcGameShark = 8
case n64GameShark = 9
case dsActionReplay = 10
case dsCodeBreaker = 11
case nesGameGenie = 12
case nesRaw = 13
case nesRawCompare = 14
case snesActionReplay = 15
case snesGameGenie = 16
case gameGearActionReplay = 17
case gameGearGameGenie = 18
case masterSystemActionReplay = 19
case masterSystemGameGenie = 20
case cdActionReplay10 = 21
case cdActionReplay8 = 22
case genesisActionReplay10 = 23
case genesisActionReplay8 = 24
}
extension CheatDevice
{
var cheatType: CheatType? {
switch self
{
case .snesActionReplay, .gbaActionReplayMax, .dsActionReplay, .gameGearActionReplay, .masterSystemActionReplay, .genesisActionReplay8, .genesisActionReplay10, .cdActionReplay8, .cdActionReplay10:
return .actionReplay
case .n64GameShark, .gbcGameShark, .gbaGameShark:
return .gameShark
case .famicomGameGenie, .snesGameGenie, .gbGameGenie, .gameGearGameGenie, .masterSystemGameGenie:
return .gameGenie
case .nesGameGenie:
return CheatType(rawValue: DeltaCore.CheatType.gameGenie8.rawValue)
case .gbaCodeBreaker, .dsCodeBreaker:
return .codeBreaker
case .famicomRaw, .famicomRawCompare:
return nil
case .nesRaw, .nesRawCompare:
return nil
}
}
var gameType: GameType? {
switch self
{
case .famicomGameGenie, .famicomRaw, .famicomRawCompare: return .nes
case .nesGameGenie, .nesRaw, .nesRawCompare: return .nes
case .snesActionReplay, .snesGameGenie: return .snes
case .n64GameShark: return .n64
case .gbGameGenie, .gbcGameShark: return .gbc
case .gbaActionReplayMax, .gbaGameShark, .gbaCodeBreaker: return .gba
case .dsActionReplay, .dsCodeBreaker: return .ds
case .genesisActionReplay8, .genesisActionReplay10: return .genesis
case .cdActionReplay8, .cdActionReplay10: return .genesis
// Not yet supported
case .gameGearActionReplay, .gameGearGameGenie: return nil
case .masterSystemActionReplay, .masterSystemGameGenie: return nil
}
}
var cheatFormat: CheatFormat? {
guard
let cheatType = self.cheatType,
let gameType = self.gameType,
let deltaCore = Delta.core(for: gameType)
else { return nil }
let cheatFormat = deltaCore.supportedCheatFormats.first { $0.type == cheatType }
return cheatFormat
}
}

View File

@ -0,0 +1,45 @@
//
// CheatMetadata.swift
// Delta
//
// Created by Riley Testut on 1/17/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import UIKit
import DeltaCore
struct CheatCategory: Identifiable, Hashable
{
var id: Int
var name: String
var categoryDescription: String
}
@objcMembers // @objcMembers required for NSPredicate-based filtering.
final class CheatMetadata: NSObject, Identifiable
{
let id: Int
let name: String
let code: String
let cheatDescription: String?
let activationHint: String?
let device: CheatDevice
let category: CheatCategory
init(id: Int, name: String, code: String, description: String?, activationHint: String?, device: CheatDevice, category: CheatCategory)
{
self.id = id
self.name = name
self.code = code
self.cheatDescription = description
self.activationHint = activationHint
self.device = device
self.category = category
}
}

View File

@ -0,0 +1,51 @@
//
// LegacySearchBar.swift
// Delta
//
// Created by Riley Testut on 1/25/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import UIKit
import SwiftUI
@available(iOS 13, *)
struct LegacySearchBar: UIViewRepresentable
{
class Coordinator: NSObject, UISearchBarDelegate
{
@Binding
var text: String
init(text: Binding<String>)
{
self._text = text
}
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String)
{
self.text = searchText
}
}
@Binding
var text: String
func makeUIView(context: Context) -> UISearchBar
{
let searchBar = UISearchBar(frame: .zero)
searchBar.delegate = context.coordinator
searchBar.placeholder = NSLocalizedString("Search", comment: "")
return searchBar
}
func updateUIView(_ uiView: UISearchBar, context: Context)
{
uiView.text = self.text
}
func makeCoordinator() -> Coordinator
{
return Coordinator(text: $text)
}
}

View File

@ -14,6 +14,7 @@ import DeltaCore
import Harmony import Harmony
import Roxas import Roxas
import ZIPFoundation import ZIPFoundation
import MelonDSDeltaCore
extension DatabaseManager extension DatabaseManager
{ {
@ -22,13 +23,24 @@ extension DatabaseManager
extension DatabaseManager extension DatabaseManager
{ {
enum ImportError: Error, Hashable, Equatable enum ImportError: LocalizedError, Hashable, Equatable
{ {
case doesNotExist(URL) case doesNotExist(URL)
case invalid(URL) case invalid(URL)
case unsupported(URL) case unsupported(URL)
case unknown(URL, NSError) case unknown(URL, NSError)
case saveFailed(Set<URL>, NSError) case saveFailed(Set<URL>, NSError)
var errorDescription: String? {
switch self
{
case .doesNotExist: return NSLocalizedString("The file does not exist.", comment: "")
case .invalid: return NSLocalizedString("The file is invalid.", comment: "")
case .unsupported: return NSLocalizedString("This file is not supported.", comment: "")
case .unknown(_, let error): return error.localizedDescription
case .saveFailed(_, let error): return error.localizedDescription
}
}
} }
} }
@ -42,6 +54,8 @@ final class DatabaseManager: RSTPersistentContainer
private var validationManagedObjectContext: NSManagedObjectContext? private var validationManagedObjectContext: NSManagedObjectContext?
private let importController = ImportController(documentTypes: [])
private init() private init()
{ {
guard guard
@ -62,6 +76,12 @@ extension DatabaseManager
{ {
guard !self.isStarted else { return } guard !self.isStarted else { return }
for description in self.persistentStoreDescriptions
{
// Set configuration so RSTPersistentContainer can determine how to migrate this and Harmony's database independently.
description.configuration = NSManagedObjectModel.Configuration.external.rawValue
}
self.loadPersistentStores { (description, error) in self.loadPersistentStores { (description, error) in
guard error == nil else { return completionHandler(error) } guard error == nil else { return completionHandler(error) }
@ -74,6 +94,114 @@ extension DatabaseManager
} }
} }
} }
func prepare(_ core: DeltaCoreProtocol, in context: NSManagedObjectContext)
{
guard let system = System(gameType: core.gameType) else { return }
if let skin = ControllerSkin(system: system, context: context)
{
print("Updated default skin (\(skin.identifier)) for system:", system)
}
else
{
print("Failed to update default skin for system:", system)
}
switch system
{
case .ds where core == MelonDS.core:
// Returns nil if game already exists.
func makeBIOS(name: String, identifier: String) -> Game?
{
let predicate = NSPredicate(format: "%K == %@", #keyPath(Game.identifier), identifier)
if let _ = Game.instancesWithPredicate(predicate, inManagedObjectContext: context, type: Game.self).first
{
// BIOS already exists, so don't do anything.
return nil
}
let filename: String
switch identifier
{
case Game.melonDSBIOSIdentifier:
guard
FileManager.default.fileExists(atPath: MelonDSEmulatorBridge.shared.bios7URL.path) &&
FileManager.default.fileExists(atPath: MelonDSEmulatorBridge.shared.bios9URL.path) &&
FileManager.default.fileExists(atPath: MelonDSEmulatorBridge.shared.firmwareURL.path)
else { return nil }
filename = "nds.bios"
case Game.melonDSDSiBIOSIdentifier:
#if BETA
guard
FileManager.default.fileExists(atPath: MelonDSEmulatorBridge.shared.dsiBIOS7URL.path) &&
FileManager.default.fileExists(atPath: MelonDSEmulatorBridge.shared.dsiBIOS9URL.path) &&
FileManager.default.fileExists(atPath: MelonDSEmulatorBridge.shared.dsiFirmwareURL.path) &&
FileManager.default.fileExists(atPath: MelonDSEmulatorBridge.shared.dsiNANDURL.path)
else { return nil }
filename = "dsi.bios"
#else
return nil
#endif
default: filename = "system.bios"
}
let bios = Game(context: context)
bios.name = name
bios.identifier = identifier
bios.type = .ds
bios.filename = filename
if let artwork = UIImage(named: "DS Home Screen"), let artworkData = artwork.pngData()
{
do
{
let destinationURL = DatabaseManager.artworkURL(for: bios)
try artworkData.write(to: destinationURL, options: .atomic)
bios.artworkURL = destinationURL
}
catch
{
print("Failed to copy default DS home screen artwork.", error)
}
}
return bios
}
let insertedGames = [
(name: NSLocalizedString("Home Screen", comment: ""), identifier: Game.melonDSBIOSIdentifier),
(name: NSLocalizedString("Home Screen (DSi)", comment: ""), identifier: Game.melonDSDSiBIOSIdentifier)
].compactMap(makeBIOS)
// Break if we didn't create any new Games.
guard !insertedGames.isEmpty else { break }
let gameCollection = GameCollection(context: context)
gameCollection.identifier = GameType.ds.rawValue
gameCollection.index = Int16(System.ds.year)
gameCollection.games.formUnion(insertedGames)
case .ds:
let predicate = NSPredicate(format: "%K IN %@", #keyPath(Game.identifier), [Game.melonDSBIOSIdentifier, Game.melonDSDSiBIOSIdentifier])
let games = Game.instancesWithPredicate(predicate, inManagedObjectContext: context, type: Game.self)
for game in games
{
context.delete(game)
}
default: break
}
}
} }
//MARK: - Update - //MARK: - Update -
@ -113,13 +241,7 @@ private extension DatabaseManager
for system in System.allCases for system in System.allCases
{ {
guard let deltaControllerSkin = DeltaCore.ControllerSkin.standardControllerSkin(for: system.gameType) else { continue } self.prepare(system.deltaCore, in: context)
let controllerSkin = ControllerSkin(context: context)
controllerSkin.isStandard = true
controllerSkin.filename = deltaControllerSkin.fileURL.lastPathComponent
controllerSkin.configure(with: deltaControllerSkin)
} }
do do
@ -133,10 +255,27 @@ private extension DatabaseManager
do do
{ {
if !FileManager.default.fileExists(atPath: DatabaseManager.gamesDatabaseURL.path) if !FileManager.default.fileExists(atPath: DatabaseManager.gamesDatabaseURL.path) || GamesDatabase.version != GamesDatabase.previousVersion
{ {
guard let bundleURL = Bundle.main.url(forResource: "openvgdb", withExtension: "sqlite") else { throw GamesDatabase.Error.doesNotExist } guard let bundleURL = Bundle.main.url(forResource: "openvgdb", withExtension: "sqlite") else { throw GamesDatabase.Error.doesNotExist }
try FileManager.default.copyItem(at: bundleURL, to: DatabaseManager.gamesDatabaseURL) try FileManager.default.copyItem(at: bundleURL, to: DatabaseManager.gamesDatabaseURL, shouldReplace: true)
}
if #available(iOS 14, *), !FileManager.default.fileExists(atPath: DatabaseManager.cheatBaseURL.path) || CheatBase.cheatsVersion != CheatBase.previousCheatsVersion
{
guard let archiveURL = Bundle.main.url(forResource: "cheatbase", withExtension: "zip") else { throw GamesDatabase.Error.doesNotExist }
let temporaryDirectoryURL = FileManager.default.uniqueTemporaryURL()
try FileManager.default.createDirectory(at: temporaryDirectoryURL, withIntermediateDirectories: true)
defer {
try? FileManager.default.removeItem(at: temporaryDirectoryURL)
}
// Unzip to temporaryDirectoryURL first to ensure we don't accidentally unzip other items into DatabaseManager.cheatBaseURL directory (e.g. __MACOSX directory).
try FileManager.default.unzipItem(at: archiveURL, to: temporaryDirectoryURL, skipCRC32: true) // skipCRC32 to avoid ~10 second extraction.
let extractedDatabaseURL = temporaryDirectoryURL.appendingPathComponent("cheatbase.sqlite")
try FileManager.default.copyItem(at: extractedDatabaseURL, to: DatabaseManager.cheatBaseURL, shouldReplace: true)
} }
self.gamesDatabase = try GamesDatabase() self.gamesDatabase = try GamesDatabase()
@ -157,7 +296,20 @@ extension DatabaseManager
{ {
func importGames(at urls: Set<URL>, completion: ((Set<Game>, Set<ImportError>) -> Void)?) func importGames(at urls: Set<URL>, completion: ((Set<Game>, Set<ImportError>) -> Void)?)
{ {
var errors = Set<ImportError>() let externalFileURLs = urls.filter { !FileManager.default.isReadableFile(atPath: $0.path) }
guard externalFileURLs.isEmpty else {
self.importExternalFiles(at: externalFileURLs) { (importedURLs, externalImportErrors) in
var availableFileURLs = urls.filter { !externalFileURLs.contains($0) }
availableFileURLs.formUnion(importedURLs)
self.importGames(at: Set(availableFileURLs)) { (importedGames, importErrors) in
let allErrors = importErrors.union(externalImportErrors)
completion?(importedGames, allErrors)
}
}
return
}
let zipFileURLs = urls.filter { $0.pathExtension.lowercased() == "zip" } let zipFileURLs = urls.filter { $0.pathExtension.lowercased() == "zip" }
if zipFileURLs.count > 0 if zipFileURLs.count > 0
@ -175,6 +327,7 @@ extension DatabaseManager
self.performBackgroundTask { (context) in self.performBackgroundTask { (context) in
var errors = Set<ImportError>()
var identifiers = Set<String>() var identifiers = Set<String>()
for url in urls for url in urls
@ -270,10 +423,24 @@ extension DatabaseManager
func importControllerSkins(at urls: Set<URL>, completion: ((Set<ControllerSkin>, Set<ImportError>) -> Void)?) func importControllerSkins(at urls: Set<URL>, completion: ((Set<ControllerSkin>, Set<ImportError>) -> Void)?)
{ {
var errors = Set<ImportError>() let externalFileURLs = urls.filter { !FileManager.default.isReadableFile(atPath: $0.path) }
guard externalFileURLs.isEmpty else {
self.importExternalFiles(at: externalFileURLs) { (importedURLs, externalImportErrors) in
var availableFileURLs = urls.filter { !externalFileURLs.contains($0) }
availableFileURLs.formUnion(importedURLs)
self.importControllerSkins(at: Set(availableFileURLs)) { (importedSkins, importErrors) in
let allErrors = importErrors.union(externalImportErrors)
completion?(importedSkins, allErrors)
}
}
return
}
self.performBackgroundTask { (context) in self.performBackgroundTask { (context) in
var errors = Set<ImportError>()
var identifiers = Set<String>() var identifiers = Set<String>()
for url in urls for url in urls
@ -378,7 +545,7 @@ extension DatabaseManager
try FileManager.default.removeItem(at: outputURL) try FileManager.default.removeItem(at: outputURL)
} }
_ = try archive.extract(entry, to: outputURL) _ = try archive.extract(entry, to: outputURL, skipCRC32: true)
outputURLs.insert(outputURL) outputURLs.insert(outputURL)
} }
@ -412,6 +579,32 @@ extension DatabaseManager
completion(outputURLs, errors) completion(outputURLs, errors)
} }
} }
private func importExternalFiles(at urls: Set<URL>, completion: @escaping ((Set<URL>, Set<ImportError>) -> Void))
{
var outputURLs = Set<URL>()
var errors = Set<ImportError>()
let dispatchGroup = DispatchGroup()
for url in urls
{
dispatchGroup.enter()
self.importController.importExternalFile(at: url) { (result) in
switch result
{
case .failure(let error): errors.insert(.unknown(url, error as NSError))
case .success(let fileURL): outputURLs.insert(fileURL)
}
dispatchGroup.leave()
}
}
dispatchGroup.notify(queue: .global()) {
completion(outputURLs, errors)
}
}
} }
//MARK: - File URLs - //MARK: - File URLs -
@ -442,6 +635,12 @@ extension DatabaseManager
let gamesDatabaseURL = self.defaultDirectoryURL().appendingPathComponent("openvgdb.sqlite") let gamesDatabaseURL = self.defaultDirectoryURL().appendingPathComponent("openvgdb.sqlite")
return gamesDatabaseURL return gamesDatabaseURL
} }
class var cheatBaseURL: URL
{
let gamesDatabaseURL = self.defaultDirectoryURL().appendingPathComponent("cheatbase.sqlite")
return gamesDatabaseURL
}
class var gamesDirectoryURL: URL class var gamesDirectoryURL: URL
{ {
@ -487,7 +686,7 @@ extension DatabaseManager
{ {
let gameURL = game.fileURL let gameURL = game.fileURL
let artworkURL = gameURL.deletingPathExtension().appendingPathExtension("jpg") let artworkURL = gameURL.deletingPathExtension().appendingPathExtension("png")
return artworkURL return artworkURL
} }
} }

View File

@ -3,6 +3,6 @@
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>_XCCurrentVersionName</key> <key>_XCCurrentVersionName</key>
<string>Delta 4.xcdatamodel</string> <string>Delta 7.xcdatamodel</string>
</dict> </dict>
</plist> </plist>

View File

@ -0,0 +1,159 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="15702" systemVersion="19C57" minimumToolsVersion="Xcode 7.0" sourceLanguage="Objective-C" userDefinedModelVersionIdentifier="1.0">
<entity name="Cheat" representedClassName="Cheat" syncable="YES">
<attribute name="code" attributeType="String" syncable="YES"/>
<attribute name="creationDate" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<attribute name="identifier" attributeType="String" syncable="YES"/>
<attribute name="isEnabled" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="NO" syncable="YES"/>
<attribute name="modifiedDate" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<attribute name="name" attributeType="String" syncable="YES"/>
<attribute name="type" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="CheatType"/>
</userInfo>
</attribute>
<relationship name="game" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Game" inverseName="cheats" inverseEntity="Game" syncable="YES"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="identifier"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="ControllerSkin" representedClassName="ControllerSkin" syncable="YES">
<attribute name="filename" attributeType="String" syncable="YES"/>
<attribute name="gameType" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="GameType"/>
</userInfo>
</attribute>
<attribute name="identifier" attributeType="String" syncable="YES"/>
<attribute name="isStandard" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES" syncable="YES"/>
<attribute name="name" attributeType="String" syncable="YES"/>
<attribute name="supportedConfigurations" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES" syncable="YES">
<userInfo>
<entry key="attributeValueScalarType" value="ControllerSkinConfigurations"/>
</userInfo>
</attribute>
<relationship name="preferredLandscapeSkinByGames" toMany="YES" deletionRule="Nullify" destinationEntity="Game" inverseName="preferredLandscapeSkin" inverseEntity="Game" syncable="YES"/>
<relationship name="preferredPortraitSkinByGames" toMany="YES" deletionRule="Nullify" destinationEntity="Game" inverseName="preferredPortraitSkin" inverseEntity="Game" syncable="YES"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="identifier"/>
<constraint value="gameType"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="Game" representedClassName="Game" syncable="YES">
<attribute name="artworkURL" optional="YES" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="URL"/>
</userInfo>
</attribute>
<attribute name="filename" attributeType="String" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="NSURL"/>
</userInfo>
</attribute>
<attribute name="identifier" attributeType="String" syncable="YES"/>
<attribute name="name" attributeType="String" syncable="YES"/>
<attribute name="playedDate" optional="YES" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<attribute name="type" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="GameType"/>
</userInfo>
</attribute>
<relationship name="cheats" toMany="YES" deletionRule="Cascade" destinationEntity="Cheat" inverseName="game" inverseEntity="Cheat" syncable="YES"/>
<relationship name="gameCollection" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="GameCollection" inverseName="games" inverseEntity="GameCollection" syncable="YES"/>
<relationship name="gameSave" optional="YES" maxCount="1" deletionRule="Cascade" destinationEntity="GameSave" inverseName="game" inverseEntity="GameSave" syncable="YES"/>
<relationship name="preferredLandscapeSkin" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="ControllerSkin" inverseName="preferredLandscapeSkinByGames" inverseEntity="ControllerSkin" syncable="YES"/>
<relationship name="preferredPortraitSkin" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="ControllerSkin" inverseName="preferredPortraitSkinByGames" inverseEntity="ControllerSkin" syncable="YES"/>
<relationship name="previewSaveState" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="SaveState" inverseName="previewGame" inverseEntity="SaveState" syncable="YES"/>
<relationship name="saveStates" toMany="YES" deletionRule="Cascade" destinationEntity="SaveState" inverseName="game" inverseEntity="SaveState" 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="index" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
<relationship name="games" toMany="YES" deletionRule="Nullify" destinationEntity="Game" inverseName="gameCollection" inverseEntity="Game" syncable="YES"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="identifier"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="GameControllerInputMapping" representedClassName="GameControllerInputMapping" syncable="YES">
<attribute name="deltaCoreInputMapping" attributeType="Transformable" valueTransformerName="GameControllerInputMappingTransformer" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="Any"/>
</userInfo>
</attribute>
<attribute name="gameControllerInputType" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="GameControllerInputType"/>
</userInfo>
</attribute>
<attribute name="gameType" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="GameType"/>
</userInfo>
</attribute>
<attribute name="identifier" attributeType="String" syncable="YES"/>
<attribute name="playerIndex" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="gameControllerInputType"/>
<constraint value="gameType"/>
<constraint value="playerIndex"/>
</uniquenessConstraint>
<uniquenessConstraint>
<constraint value="identifier"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="GameSave" representedClassName="GameSave" syncable="YES">
<attribute name="identifier" attributeType="String" syncable="YES"/>
<attribute name="modifiedDate" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<relationship name="game" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Game" inverseName="gameSave" inverseEntity="Game" syncable="YES"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="identifier"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="SaveState" representedClassName="SaveState" versionHashModifier="quick" syncable="YES">
<attribute name="creationDate" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<attribute name="filename" attributeType="String" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="NSURL"/>
</userInfo>
</attribute>
<attribute name="identifier" attributeType="String" syncable="YES"/>
<attribute name="modifiedDate" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<attribute name="name" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="type" attributeType="Integer 16" defaultValueString="2" usesScalarValueType="NO" syncable="YES">
<userInfo>
<entry key="attributeValueScalarType" value="SaveStateType"/>
</userInfo>
</attribute>
<relationship name="game" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Game" inverseName="saveStates" inverseEntity="Game" syncable="YES"/>
<relationship name="previewGame" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Game" inverseName="previewSaveState" inverseEntity="Game" syncable="YES"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="identifier"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<elements>
<element name="Cheat" positionX="-198" positionY="-63" width="128" height="165"/>
<element name="ControllerSkin" positionX="-387" positionY="90" width="128" height="163"/>
<element name="Game" positionX="-378" positionY="-54" width="128" height="238"/>
<element name="GameCollection" positionX="-585" positionY="-27" width="128" height="90"/>
<element name="GameControllerInputMapping" positionX="-387" positionY="90" width="128" height="120"/>
<element name="GameSave" positionX="-387" positionY="90" width="128" height="90"/>
<element name="SaveState" positionX="-198" positionY="113" width="128" height="165"/>
</elements>
</model>

View File

@ -0,0 +1,160 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="16119" systemVersion="19E287" minimumToolsVersion="Xcode 7.0" sourceLanguage="Objective-C" userDefinedModelVersionIdentifier="1.0">
<entity name="Cheat" representedClassName="Cheat" syncable="YES">
<attribute name="code" attributeType="String" syncable="YES"/>
<attribute name="creationDate" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<attribute name="identifier" attributeType="String" syncable="YES"/>
<attribute name="isEnabled" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="NO" syncable="YES"/>
<attribute name="modifiedDate" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<attribute name="name" attributeType="String" syncable="YES"/>
<attribute name="type" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="CheatType"/>
</userInfo>
</attribute>
<relationship name="game" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Game" inverseName="cheats" inverseEntity="Game" syncable="YES"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="identifier"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="ControllerSkin" representedClassName="ControllerSkin" syncable="YES">
<attribute name="filename" attributeType="String" syncable="YES"/>
<attribute name="gameType" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="GameType"/>
</userInfo>
</attribute>
<attribute name="identifier" attributeType="String" syncable="YES"/>
<attribute name="isStandard" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES" syncable="YES"/>
<attribute name="name" attributeType="String" syncable="YES"/>
<attribute name="supportedConfigurations" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES" syncable="YES">
<userInfo>
<entry key="attributeValueScalarType" value="ControllerSkinConfigurations"/>
</userInfo>
</attribute>
<relationship name="preferredLandscapeSkinByGames" toMany="YES" deletionRule="Nullify" destinationEntity="Game" inverseName="preferredLandscapeSkin" inverseEntity="Game" syncable="YES"/>
<relationship name="preferredPortraitSkinByGames" toMany="YES" deletionRule="Nullify" destinationEntity="Game" inverseName="preferredPortraitSkin" inverseEntity="Game" syncable="YES"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="identifier"/>
<constraint value="gameType"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="Game" representedClassName="Game" syncable="YES">
<attribute name="artworkURL" optional="YES" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="URL"/>
</userInfo>
</attribute>
<attribute name="filename" attributeType="String" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="NSURL"/>
</userInfo>
</attribute>
<attribute name="identifier" attributeType="String" syncable="YES"/>
<attribute name="name" attributeType="String" syncable="YES"/>
<attribute name="playedDate" optional="YES" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<attribute name="type" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="GameType"/>
</userInfo>
</attribute>
<relationship name="cheats" toMany="YES" deletionRule="Cascade" destinationEntity="Cheat" inverseName="game" inverseEntity="Cheat" syncable="YES"/>
<relationship name="gameCollection" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="GameCollection" inverseName="games" inverseEntity="GameCollection" syncable="YES"/>
<relationship name="gameSave" optional="YES" maxCount="1" deletionRule="Cascade" destinationEntity="GameSave" inverseName="game" inverseEntity="GameSave" syncable="YES"/>
<relationship name="preferredLandscapeSkin" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="ControllerSkin" inverseName="preferredLandscapeSkinByGames" inverseEntity="ControllerSkin" syncable="YES"/>
<relationship name="preferredPortraitSkin" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="ControllerSkin" inverseName="preferredPortraitSkinByGames" inverseEntity="ControllerSkin" syncable="YES"/>
<relationship name="previewSaveState" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="SaveState" inverseName="previewGame" inverseEntity="SaveState" syncable="YES"/>
<relationship name="saveStates" toMany="YES" deletionRule="Cascade" destinationEntity="SaveState" inverseName="game" inverseEntity="SaveState" 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="index" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
<relationship name="games" toMany="YES" deletionRule="Nullify" destinationEntity="Game" inverseName="gameCollection" inverseEntity="Game" syncable="YES"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="identifier"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="GameControllerInputMapping" representedClassName="GameControllerInputMapping" syncable="YES">
<attribute name="deltaCoreInputMapping" attributeType="Transformable" valueTransformerName="GameControllerInputMappingTransformer" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="Any"/>
</userInfo>
</attribute>
<attribute name="gameControllerInputType" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="GameControllerInputType"/>
</userInfo>
</attribute>
<attribute name="gameType" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="GameType"/>
</userInfo>
</attribute>
<attribute name="identifier" attributeType="String" syncable="YES"/>
<attribute name="playerIndex" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="gameControllerInputType"/>
<constraint value="gameType"/>
<constraint value="playerIndex"/>
</uniquenessConstraint>
<uniquenessConstraint>
<constraint value="identifier"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="GameSave" representedClassName="GameSave" syncable="YES">
<attribute name="identifier" attributeType="String" syncable="YES"/>
<attribute name="modifiedDate" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<relationship name="game" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Game" inverseName="gameSave" inverseEntity="Game" syncable="YES"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="identifier"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="SaveState" representedClassName="SaveState" versionHashModifier="quick" syncable="YES">
<attribute name="coreIdentifier" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="creationDate" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<attribute name="filename" attributeType="String" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="NSURL"/>
</userInfo>
</attribute>
<attribute name="identifier" attributeType="String" syncable="YES"/>
<attribute name="modifiedDate" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<attribute name="name" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="type" attributeType="Integer 16" defaultValueString="2" usesScalarValueType="NO" syncable="YES">
<userInfo>
<entry key="attributeValueScalarType" value="SaveStateType"/>
</userInfo>
</attribute>
<relationship name="game" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Game" inverseName="saveStates" inverseEntity="Game" syncable="YES"/>
<relationship name="previewGame" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Game" inverseName="previewSaveState" inverseEntity="Game" syncable="YES"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="identifier"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<elements>
<element name="Cheat" positionX="-198" positionY="-63" width="128" height="165"/>
<element name="ControllerSkin" positionX="-387" positionY="90" width="128" height="163"/>
<element name="Game" positionX="-378" positionY="-54" width="128" height="238"/>
<element name="GameCollection" positionX="-585" positionY="-27" width="128" height="90"/>
<element name="GameControllerInputMapping" positionX="-387" positionY="90" width="128" height="120"/>
<element name="GameSave" positionX="-387" positionY="90" width="128" height="90"/>
<element name="SaveState" positionX="-198" positionY="113" width="128" height="178"/>
</elements>
</model>

View File

@ -0,0 +1,152 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22158.8" systemVersion="22F66" minimumToolsVersion="Xcode 7.0" sourceLanguage="Objective-C" userDefinedModelVersionIdentifier="1.0">
<entity name="Cheat" representedClassName="Cheat" syncable="YES">
<attribute name="code" attributeType="String" syncable="YES"/>
<attribute name="creationDate" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<attribute name="identifier" attributeType="String" syncable="YES"/>
<attribute name="isEnabled" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="NO" syncable="YES"/>
<attribute name="modifiedDate" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<attribute name="name" attributeType="String" syncable="YES"/>
<attribute name="type" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="CheatType"/>
</userInfo>
</attribute>
<relationship name="game" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Game" inverseName="cheats" inverseEntity="Game" syncable="YES"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="identifier"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="ControllerSkin" representedClassName="ControllerSkin" syncable="YES">
<attribute name="filename" attributeType="String" syncable="YES"/>
<attribute name="gameType" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="GameType"/>
</userInfo>
</attribute>
<attribute name="identifier" attributeType="String" syncable="YES"/>
<attribute name="isStandard" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES" syncable="YES"/>
<attribute name="name" attributeType="String" syncable="YES"/>
<attribute name="supportedConfigurations" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES" syncable="YES">
<userInfo>
<entry key="attributeValueScalarType" value="ControllerSkinConfigurations"/>
</userInfo>
</attribute>
<relationship name="preferredLandscapeSkinByGames" toMany="YES" deletionRule="Nullify" destinationEntity="Game" inverseName="preferredLandscapeSkin" inverseEntity="Game" syncable="YES"/>
<relationship name="preferredPortraitSkinByGames" toMany="YES" deletionRule="Nullify" destinationEntity="Game" inverseName="preferredPortraitSkin" inverseEntity="Game" syncable="YES"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="identifier"/>
<constraint value="gameType"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="Game" representedClassName="Game" syncable="YES">
<attribute name="artworkURL" optional="YES" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="URL"/>
</userInfo>
</attribute>
<attribute name="filename" attributeType="String" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="NSURL"/>
</userInfo>
</attribute>
<attribute name="identifier" attributeType="String" syncable="YES"/>
<attribute name="name" attributeType="String" syncable="YES"/>
<attribute name="playedDate" optional="YES" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<attribute name="type" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="GameType"/>
</userInfo>
</attribute>
<relationship name="cheats" toMany="YES" deletionRule="Cascade" destinationEntity="Cheat" inverseName="game" inverseEntity="Cheat" syncable="YES"/>
<relationship name="gameCollection" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="GameCollection" inverseName="games" inverseEntity="GameCollection" syncable="YES"/>
<relationship name="gameSave" optional="YES" maxCount="1" deletionRule="Cascade" destinationEntity="GameSave" inverseName="game" inverseEntity="GameSave" syncable="YES"/>
<relationship name="preferredLandscapeSkin" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="ControllerSkin" inverseName="preferredLandscapeSkinByGames" inverseEntity="ControllerSkin" syncable="YES"/>
<relationship name="preferredPortraitSkin" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="ControllerSkin" inverseName="preferredPortraitSkinByGames" inverseEntity="ControllerSkin" syncable="YES"/>
<relationship name="previewSaveState" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="SaveState" inverseName="previewGame" inverseEntity="SaveState" syncable="YES"/>
<relationship name="saveStates" toMany="YES" deletionRule="Cascade" destinationEntity="SaveState" inverseName="game" inverseEntity="SaveState" 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="index" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
<relationship name="games" toMany="YES" deletionRule="Nullify" destinationEntity="Game" inverseName="gameCollection" inverseEntity="Game" syncable="YES"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="identifier"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="GameControllerInputMapping" representedClassName="GameControllerInputMapping" syncable="YES">
<attribute name="deltaCoreInputMapping" attributeType="Transformable" valueTransformerName="GameControllerInputMappingTransformer" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="Any"/>
</userInfo>
</attribute>
<attribute name="gameControllerInputType" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="GameControllerInputType"/>
</userInfo>
</attribute>
<attribute name="gameType" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="GameType"/>
</userInfo>
</attribute>
<attribute name="identifier" attributeType="String" syncable="YES"/>
<attribute name="playerIndex" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="gameControllerInputType"/>
<constraint value="gameType"/>
<constraint value="playerIndex"/>
</uniquenessConstraint>
<uniquenessConstraint>
<constraint value="identifier"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="GameSave" representedClassName="GameSave" syncable="YES">
<attribute name="identifier" attributeType="String" syncable="YES"/>
<attribute name="modifiedDate" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<attribute name="sha1" optional="YES" attributeType="String" syncable="YES"/>
<relationship name="game" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Game" inverseName="gameSave" inverseEntity="Game" syncable="YES"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="identifier"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="SaveState" representedClassName="SaveState" versionHashModifier="quick" syncable="YES">
<attribute name="coreIdentifier" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="creationDate" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<attribute name="filename" attributeType="String" syncable="YES">
<userInfo>
<entry key="attributeValueClassName" value="NSURL"/>
</userInfo>
</attribute>
<attribute name="identifier" attributeType="String" syncable="YES"/>
<attribute name="modifiedDate" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<attribute name="name" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="type" attributeType="Integer 16" defaultValueString="2" usesScalarValueType="NO" syncable="YES">
<userInfo>
<entry key="attributeValueScalarType" value="SaveStateType"/>
</userInfo>
</attribute>
<relationship name="game" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Game" inverseName="saveStates" inverseEntity="Game" syncable="YES"/>
<relationship name="previewGame" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Game" inverseName="previewSaveState" inverseEntity="Game" syncable="YES"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="identifier"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
</model>

View File

@ -53,4 +53,9 @@ extension Cheat: Syncable
public var syncableLocalizedName: String? { public var syncableLocalizedName: String? {
return self.name return self.name
} }
public func resolveConflict(_ record: AnyRecord) -> ConflictResolution
{
return .newest
}
} }

View File

@ -13,16 +13,27 @@ import Harmony
extension ControllerSkinConfigurations extension ControllerSkinConfigurations
{ {
init(traits: DeltaCore.ControllerSkin.Traits) init?(traits: DeltaCore.ControllerSkin.Traits)
{ {
switch (traits.displayType, traits.orientation) switch (traits.device, traits.displayType, traits.orientation)
{ {
case (.standard, .portrait): self = .standardPortrait case (.iphone, .standard, .portrait): self = .iphoneStandardPortrait
case (.standard, .landscape): self = .standardLandscape case (.iphone, .standard, .landscape): self = .iphoneStandardLandscape
case (.edgeToEdge, .portrait): self = .edgeToEdgePortrait case (.iphone, .edgeToEdge, .portrait): self = .iphoneEdgeToEdgePortrait
case (.edgeToEdge, .landscape): self = .edgeToEdgeLandscape case (.iphone, .edgeToEdge, .landscape): self = .iphoneEdgeToEdgeLandscape
case (.splitView, .portrait): self = .splitViewPortrait case (.iphone, .splitView, _): return nil
case (.splitView, .landscape): self = .splitViewLandscape
case (.ipad, .standard, .portrait): self = .ipadStandardPortrait
case (.ipad, .standard, .landscape): self = .ipadStandardLandscape
case (.ipad, .edgeToEdge, .portrait): self = .ipadEdgeToEdgePortrait
case (.ipad, .edgeToEdge, .landscape): self = .ipadEdgeToEdgeLandscape
case (.ipad, .splitView, .portrait): self = .ipadSplitViewPortrait
case (.ipad, .splitView, .landscape): self = .ipadSplitViewLandscape
case (.tv, .standard, .portrait): self = .tvStandardPortrait
case (.tv, .standard, .landscape): self = .tvStandardLandscape
case (.tv, .edgeToEdge, _): return nil
case (.tv, .splitView, _): return nil
} }
} }
} }
@ -71,11 +82,6 @@ extension ControllerSkin: ControllerSkinProtocol
return self.controllerSkin?.thumbstick(for: item, traits: traits, preferredSize: preferredSize) return self.controllerSkin?.thumbstick(for: item, traits: traits, preferredSize: preferredSize)
} }
public func inputs(for traits: DeltaCore.ControllerSkin.Traits, at point: CGPoint) -> [Input]?
{
return self.controllerSkin?.inputs(for: traits, at: point)
}
public func items(for traits: DeltaCore.ControllerSkin.Traits) -> [DeltaCore.ControllerSkin.Item]? public func items(for traits: DeltaCore.ControllerSkin.Traits) -> [DeltaCore.ControllerSkin.Item]?
{ {
return self.controllerSkin?.items(for: traits) return self.controllerSkin?.items(for: traits)
@ -86,15 +92,20 @@ extension ControllerSkin: ControllerSkinProtocol
return self.controllerSkin?.isTranslucent(for: traits) return self.controllerSkin?.isTranslucent(for: traits)
} }
public func gameScreenFrame(for traits: DeltaCore.ControllerSkin.Traits) -> CGRect? public func screens(for traits: DeltaCore.ControllerSkin.Traits) -> [DeltaCore.ControllerSkin.Screen]?
{ {
return self.controllerSkin?.gameScreenFrame(for: traits) return self.controllerSkin?.screens(for: traits)
} }
public func aspectRatio(for traits: DeltaCore.ControllerSkin.Traits) -> CGSize? public func aspectRatio(for traits: DeltaCore.ControllerSkin.Traits) -> CGSize?
{ {
return self.controllerSkin?.aspectRatio(for: traits) return self.controllerSkin?.aspectRatio(for: traits)
} }
public func contentSize(for traits: DeltaCore.ControllerSkin.Traits) -> CGSize?
{
return self.controllerSkin?.contentSize(for: traits)
}
} }
extension ControllerSkin: Syncable extension ControllerSkin: Syncable
@ -118,4 +129,9 @@ extension ControllerSkin: Syncable
public var syncableLocalizedName: String? { public var syncableLocalizedName: String? {
return self.name return self.name
} }
public func resolveConflict(_ record: AnyRecord) -> ConflictResolution
{
return .newest
}
} }

View File

@ -9,14 +9,22 @@
import Foundation import Foundation
import DeltaCore import DeltaCore
import MelonDSDeltaCore
import Harmony import Harmony
public extension Game
{
static let melonDSBIOSIdentifier = "com.rileytestut.MelonDSDeltaCore.BIOS"
static let melonDSDSiBIOSIdentifier = "com.rileytestut.MelonDSDeltaCore.DSiBIOS"
}
@objc(Game) @objc(Game)
public class Game: _Game, GameProtocol public class Game: _Game, GameProtocol
{ {
public var fileURL: URL { public var fileURL: URL {
var fileURL: URL! var fileURL: URL!
// self URL
self.managedObjectContext?.performAndWait { self.managedObjectContext?.performAndWait {
fileURL = DatabaseManager.gamesDirectoryURL.appendingPathComponent(self.filename) fileURL = DatabaseManager.gamesDirectoryURL.appendingPathComponent(self.filename)
} }
@ -37,12 +45,16 @@ public class Game: _Game, GameProtocol
// Recreate the stored URL relative to current sandbox location. // Recreate the stored URL relative to current sandbox location.
artworkURL = URL(fileURLWithPath: unwrappedArtworkURL.relativePath, relativeTo: DatabaseManager.gamesDirectoryURL) artworkURL = URL(fileURLWithPath: unwrappedArtworkURL.relativePath, relativeTo: DatabaseManager.gamesDirectoryURL)
} }
else if unwrappedArtworkURL.host?.lowercased() == "img.gamefaqs.net", var components = URLComponents(url: unwrappedArtworkURL, resolvingAgainstBaseURL: false) else if let host = unwrappedArtworkURL.host?.lowercased(), host == "img.gamefaqs.net" || host == "gamefaqs1.cbsistatic.com",
var components = URLComponents(url: unwrappedArtworkURL, resolvingAgainstBaseURL: false)
{ {
// Quick fix for broken album artwork URLs due to host change. // Quick fix for broken album artwork URLs due to host change.
components.host = "gamefaqs1.cbsistatic.com" components.host = "gamefaqs.gamespot.com"
components.scheme = "https" components.scheme = "https"
let updatedPath = "/a" + components.path
components.path = updatedPath
if let url = components.url if let url = components.url
{ {
artworkURL = url artworkURL = url
@ -89,12 +101,18 @@ extension Game
super.prepareForDeletion() super.prepareForDeletion()
guard let managedObjectContext = self.managedObjectContext else { return } guard let managedObjectContext = self.managedObjectContext else { return }
// If filename == empty string (e.g. during merge), ignore this deletion.
// Otherwise, we may accidentally delete the entire Games directory!
guard !self.filename.isEmpty else { return }
// If a game with the same identifier is also currently being inserted, Core Data is more than likely resolving a conflict by deleting the previous instance // If a game with the same identifier is also currently being inserted, Core Data is more than likely resolving a conflict by deleting the previous instance
// In this case, we make sure we DON'T delete the game file + misc other Core Data relationships, or else we'll just lose all that data // In this case, we make sure we DON'T delete the game file + misc other Core Data relationships, or else we'll just lose all that data
guard !managedObjectContext.insertedObjects.contains(where: { ($0 as? Game)?.identifier == self.identifier }) else { return } guard !managedObjectContext.insertedObjects.contains(where: { ($0 as? Game)?.identifier == self.identifier }) else { return }
guard FileManager.default.fileExists(atPath: self.fileURL.path) else { return } // Double-check fileURL is NOT actually a directory, which we should never delete.
var isDirectory: ObjCBool = false
guard FileManager.default.fileExists(atPath: self.fileURL.path, isDirectory: &isDirectory), !isDirectory.boolValue else { return }
do do
{ {
@ -136,12 +154,42 @@ extension Game: Syncable
} }
public var syncableFiles: Set<File> { public var syncableFiles: Set<File> {
let gameFile = File(identifier: "game", fileURL: self.fileURL) let artworkURL: URL
if let fileURL = self.artworkURL, fileURL.isFileURL
{
artworkURL = fileURL
}
else
{
artworkURL = DatabaseManager.artworkURL(for: self)
}
let artworkURL = DatabaseManager.artworkURL(for: self)
let artworkFile = File(identifier: "artwork", fileURL: artworkURL) let artworkFile = File(identifier: "artwork", fileURL: artworkURL)
return [gameFile, artworkFile] switch self.identifier
{
case Game.melonDSBIOSIdentifier:
let bios7File = File(identifier: "bios7", fileURL: MelonDSEmulatorBridge.shared.bios7URL)
let bios9File = File(identifier: "bios9", fileURL: MelonDSEmulatorBridge.shared.bios9URL)
let firmwareFile = File(identifier: "firmware", fileURL: MelonDSEmulatorBridge.shared.firmwareURL)
return [artworkFile, bios7File, bios9File, firmwareFile]
case Game.melonDSDSiBIOSIdentifier:
let bios7File = File(identifier: "bios7", fileURL: MelonDSEmulatorBridge.shared.dsiBIOS7URL)
let bios9File = File(identifier: "bios9", fileURL: MelonDSEmulatorBridge.shared.dsiBIOS9URL)
let firmwareFile = File(identifier: "firmware", fileURL: MelonDSEmulatorBridge.shared.dsiFirmwareURL)
// DSi NAND is ~240MB, so don't sync for now until Harmony can selectively download files.
// let nandFile = File(identifier: "nand", fileURL: MelonDSEmulatorBridge.shared.dsiNANDURL)
return [artworkFile, bios7File, bios9File, firmwareFile]
default:
let gameFile = File(identifier: "game", fileURL: self.fileURL)
return [artworkFile, gameFile]
}
} }
public var syncableRelationships: Set<AnyKeyPath> { public var syncableRelationships: Set<AnyKeyPath> {
@ -151,4 +199,14 @@ extension Game: Syncable
public var syncableLocalizedName: String? { public var syncableLocalizedName: String? {
return self.name return self.name
} }
public func awakeFromSync(_ record: AnyRecord) throws
{
guard let gameCollection = self.gameCollection else { throw SyncValidationError.incorrectGameCollection(nil) }
if gameCollection.identifier != self.type.rawValue
{
throw SyncValidationError.incorrectGameCollection(gameCollection.name)
}
}
} }

View File

@ -8,6 +8,8 @@
import Foundation import Foundation
import GBCDeltaCore
import Harmony import Harmony
@objc(GameSave) @objc(GameSave)
@ -28,7 +30,7 @@ extension GameSave: Syncable
} }
public var syncableKeys: Set<AnyKeyPath> { public var syncableKeys: Set<AnyKeyPath> {
return [\GameSave.modifiedDate] return [\GameSave.modifiedDate, \GameSave.sha1]
} }
public var syncableRelationships: Set<AnyKeyPath> { public var syncableRelationships: Set<AnyKeyPath> {
@ -51,10 +53,64 @@ extension GameSave: Syncable
public var syncableMetadata: [HarmonyMetadataKey : String] { public var syncableMetadata: [HarmonyMetadataKey : String] {
guard let game = self.game else { return [:] } guard let game = self.game else { return [:] }
return [.gameID: game.identifier, .gameName: game.name]
// Use self.identifier to always link with exact matching game.
return [.gameID: self.identifier, .gameName: game.name]
} }
public var syncableLocalizedName: String? { public var syncableLocalizedName: String? {
return self.game?.name return self.game?.name
} }
public var isSyncingEnabled: Bool {
// self.game may be nil if being downloaded, so don't enforce it.
// guard let identifier = self.game?.identifier else { return false }
return self.game?.identifier != Game.melonDSBIOSIdentifier && self.game?.identifier != Game.melonDSDSiBIOSIdentifier
}
public func awakeFromSync(_ record: AnyRecord) throws
{
do
{
guard let game = self.game else { throw SyncValidationError.incorrectGame(nil) }
if game.identifier != self.identifier
{
let fetchRequest = GameSave.fetchRequest()
fetchRequest.predicate = NSPredicate(format: "%K == %@", #keyPath(GameSave.identifier), game.identifier)
if let misplacedGameSave = try self.managedObjectContext?.fetch(fetchRequest).first, misplacedGameSave.game == nil
{
// Relink game with its correct gameSave, in case we accidentally misplaced it.
// Otherwise, corrupted records might displace already-downloaded GameSaves
// due to automatic Core Data relationship propagation, despite us throwing error.
game.gameSave = misplacedGameSave
}
else
{
// Either there is no misplacedGameSave, or there is but it's linked to another game somehow.
game.gameSave = nil
}
throw SyncValidationError.incorrectGame(game.name)
}
}
catch let error as SyncValidationError
{
guard SyncManager.shared.ignoredCorruptedRecordIDs.contains(record.recordID) else { throw error }
let fetchRequest = Game.fetchRequest()
fetchRequest.predicate = NSPredicate(format: "%K == %@", #keyPath(Game.identifier), self.identifier)
if let correctGame = try self.managedObjectContext?.fetch(fetchRequest).first
{
self.game = correctGame
}
else
{
throw ValidationError.nilRelationshipObjects(keys: [#keyPath(GameSave.game)])
}
}
}
} }

View File

@ -11,6 +11,8 @@ import Foundation
import DeltaCore import DeltaCore
import Harmony import Harmony
import struct DSDeltaCore.DS
@objc public enum SaveStateType: Int16 @objc public enum SaveStateType: Int16
{ {
case auto case auto
@ -111,7 +113,7 @@ extension SaveState: Syncable
} }
public var syncableKeys: Set<AnyKeyPath> { public var syncableKeys: Set<AnyKeyPath> {
return [\SaveState.creationDate, \SaveState.filename, \SaveState.modifiedDate, \SaveState.name, \SaveState.type] return [\SaveState.creationDate, \SaveState.filename, \SaveState.modifiedDate, \SaveState.name, \SaveState.type, \SaveState.coreIdentifier]
} }
public var syncableFiles: Set<File> { public var syncableFiles: Set<File> {
@ -123,15 +125,70 @@ extension SaveState: Syncable
} }
public var isSyncingEnabled: Bool { public var isSyncingEnabled: Bool {
return self.type != .auto && self.type != .quick // self.game may be nil if being downloaded, so don't enforce it.
// guard let identifier = self.game?.identifier else { return false }
let isSyncingEnabled = (self.type != .auto && self.type != .quick) && (self.game?.identifier != Game.melonDSBIOSIdentifier && self.game?.identifier != Game.melonDSDSiBIOSIdentifier)
return isSyncingEnabled
} }
public var syncableMetadata: [HarmonyMetadataKey : String] { public var syncableMetadata: [HarmonyMetadataKey : String] {
guard let game = self.game else { return [:] } guard let game = self.game else { return [:] }
return [.gameID: game.identifier, .gameName: game.name] return [.gameID: game.identifier, .gameName: game.name, .coreID: self.coreIdentifier, .verifiedGameID: game.identifier].compactMapValues { $0 }
} }
public var syncableLocalizedName: String? { public var syncableLocalizedName: String? {
return self.localizedName return self.localizedName
} }
public func awakeFromSync(_ record: AnyRecord) throws
{
let verifiedGameID = record.remoteMetadata?[.verifiedGameID]
do
{
guard let game = self.game else { return }
if let system = System(gameType: game.type), self.coreIdentifier == nil
{
if let coreIdentifier = record.remoteMetadata?[.coreID]
{
// SaveState was synced to older version of Delta and lost its coreIdentifier,
// but it remains in the remote metadata so we can reassign it.
self.coreIdentifier = coreIdentifier
}
else
{
switch system
{
case .ds: self.coreIdentifier = DS.core.identifier // Assume DS save state with nil coreIdentifier is from DeSmuME core.
default: self.coreIdentifier = system.deltaCore.identifier
}
}
}
if let verifiedGameID, verifiedGameID != game.identifier
{
// Game does not match verified game ID, which most likely means
// this SaveState was reviewed + fixed on another device, but not uploaded.
throw SyncValidationError.incorrectGame(game.name)
}
}
catch let error as SyncValidationError
{
guard let verifiedGameID, SyncManager.shared.ignoredCorruptedRecordIDs.contains(record.recordID) else { throw error }
let fetchRequest = Game.fetchRequest()
fetchRequest.predicate = NSPredicate(format: "%K == %@", #keyPath(Game.identifier), verifiedGameID)
if let correctGame = try self.managedObjectContext?.fetch(fetchRequest).first
{
self.game = correctGame
}
else
{
throw ValidationError.nilRelationshipObjects(keys: [#keyPath(GameSave.game)])
}
}
}
} }

View File

@ -28,5 +28,9 @@ public class _ControllerSkin: NSManagedObject
// MARK: - Relationships // MARK: - Relationships
@NSManaged public var preferredLandscapeSkinByGames: Set<Game>
@NSManaged public var preferredPortraitSkinByGames: Set<Game>
} }

View File

@ -34,6 +34,10 @@ public class _Game: NSManagedObject
@NSManaged public var gameSave: GameSave? @NSManaged public var gameSave: GameSave?
@NSManaged public var preferredLandscapeSkin: ControllerSkin?
@NSManaged public var preferredPortraitSkin: ControllerSkin?
@NSManaged public var previewSaveState: SaveState? @NSManaged public var previewSaveState: SaveState?
@NSManaged public var saveStates: Set<SaveState> @NSManaged public var saveStates: Set<SaveState>

View File

@ -18,6 +18,8 @@ public class _GameSave: NSManagedObject
@NSManaged public var modifiedDate: Date @NSManaged public var modifiedDate: Date
@NSManaged public var sha1: String?
// MARK: - Relationships // MARK: - Relationships
@NSManaged public var game: Game? @NSManaged public var game: Game?

View File

@ -14,6 +14,8 @@ public class _SaveState: NSManagedObject
// MARK: - Properties // MARK: - Properties
@NSManaged public var coreIdentifier: String?
@NSManaged public var creationDate: Date @NSManaged public var creationDate: Date
@NSManaged public var filename: String @NSManaged public var filename: String

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -8,6 +8,10 @@
import UIKit import UIKit
import DeltaCore
import struct DSDeltaCore.DS
@objc(SaveStateToSaveStateMigrationPolicy) @objc(SaveStateToSaveStateMigrationPolicy)
class SaveStateToSaveStateMigrationPolicy: NSEntityMigrationPolicy class SaveStateToSaveStateMigrationPolicy: NSEntityMigrationPolicy
{ {
@ -23,3 +27,19 @@ class SaveStateToSaveStateMigrationPolicy: NSEntityMigrationPolicy
} }
} }
} }
// Delta5 to Delta6
extension SaveStateToSaveStateMigrationPolicy
{
@objc(defaultCoreIdentifierForGameType:)
func defaultCoreIdentifier(for gameType: GameType) -> String?
{
guard let system = System(gameType: gameType) else { return nil }
switch system
{
case .ds: return DS.core.identifier // Assume any existing save state is from DeSmuME.
default: return system.deltaCore.identifier
}
}
}

View File

@ -9,16 +9,35 @@
#ifndef ControllerSkinConfigurations_h #ifndef ControllerSkinConfigurations_h
#define ControllerSkinConfigurations_h #define ControllerSkinConfigurations_h
// Every possible (supported) combination of traits.
typedef NS_OPTIONS(int16_t, ControllerSkinConfigurations) typedef NS_OPTIONS(int16_t, ControllerSkinConfigurations)
{ {
ControllerSkinConfigurationStandardPortrait = 1 << 0, /* iPhone */
ControllerSkinConfigurationStandardLandscape = 1 << 1, ControllerSkinConfigurationiPhoneStandardPortrait NS_SWIFT_NAME(iphoneStandardPortrait) = 1 << 0,
ControllerSkinConfigurationiPhoneStandardLandscape NS_SWIFT_NAME(iphoneStandardLandscape) = 1 << 1,
ControllerSkinConfigurationSplitViewPortrait = 1 << 2, // iPhone doesn't support Split View
ControllerSkinConfigurationSplitViewLandscape = 1 << 3, // ControllerSkinConfigurationiPhoneSplitViewPortrait = 1 << 2,
// ControllerSkinConfigurationiPhoneSplitViewLandscape = 1 << 3,
ControllerSkinConfigurationEdgeToEdgePortrait = 1 << 4, ControllerSkinConfigurationiPhoneEdgeToEdgePortrait NS_SWIFT_NAME(iphoneEdgeToEdgePortrait) = 1 << 4,
ControllerSkinConfigurationEdgeToEdgeLandscape = 1 << 5, ControllerSkinConfigurationiPhoneEdgeToEdgeLandscape NS_SWIFT_NAME(iphoneEdgeToEdgeLandscape) = 1 << 5,
/* iPad */
ControllerSkinConfigurationiPadStandardPortrait NS_SWIFT_NAME(ipadStandardPortrait) = 1 << 6,
ControllerSkinConfigurationiPadStandardLandscape NS_SWIFT_NAME(ipadStandardLandscape) = 1 << 7,
ControllerSkinConfigurationiPadSplitViewPortrait NS_SWIFT_NAME(ipadSplitViewPortrait) = 1 << 2, // Backwards compatible with legacy ControllerSkinConfigurationSplitViewPortrait
ControllerSkinConfigurationiPadSplitViewLandscape NS_SWIFT_NAME(ipadSplitViewLandscape) = 1 << 3, // Backwards compatible with legacy ControllerSkinConfigurationSplitViewLandscape
ControllerSkinConfigurationiPadEdgeToEdgePortrait NS_SWIFT_NAME(ipadEdgeToEdgePortrait) = 1 << 8,
ControllerSkinConfigurationiPadEdgeToEdgeLandscape NS_SWIFT_NAME(ipadEdgeToEdgeLandscape) = 1 << 9,
/* TV */
ControllerSkinConfigurationTVStandardPortrait = 1 << 10,
ControllerSkinConfigurationTVStandardLandscape = 1 << 11,
}; };
#endif /* ControllerSkinConfigurations_h */ #endif /* ControllerSkinConfigurations_h */

View File

@ -11,15 +11,17 @@ import Foundation
// Must be an NSObject subclass so it can be used with RSTCellContentDataSource. // Must be an NSObject subclass so it can be used with RSTCellContentDataSource.
class GameMetadata: NSObject class GameMetadata: NSObject
{ {
let identifier: Int let releaseID: Int
let romID: Int
let name: String? let name: String?
let artworkURL: URL? let artworkURL: URL?
init(identifier: Int, name: String?, artworkURL: URL?) init(releaseID: Int, romID: Int, name: String?, artworkURL: URL?)
{ {
self.releaseID = releaseID
self.romID = romID
self.name = name self.name = name
self.identifier = identifier
self.artworkURL = artworkURL self.artworkURL = artworkURL
} }
} }
@ -27,13 +29,13 @@ class GameMetadata: NSObject
extension GameMetadata extension GameMetadata
{ {
override var hash: Int { override var hash: Int {
return self.identifier.hashValue return self.releaseID.hashValue ^ self.romID.hashValue
} }
override func isEqual(_ object: Any?) -> Bool override func isEqual(_ object: Any?) -> Bool
{ {
guard let metadata = object as? GameMetadata else { return false } guard let metadata = object as? GameMetadata else { return false }
return self.identifier == metadata.identifier return self.releaseID == metadata.releaseID && self.romID == metadata.romID
} }
} }

View File

@ -57,16 +57,26 @@ extension VirtualTable
extension GamesDatabase extension GamesDatabase
{ {
enum Error: Swift.Error enum Error: LocalizedError
{ {
case doesNotExist case doesNotExist
case connection(Swift.Error)
var errorDescription: String? {
switch self
{
case .doesNotExist:
return NSLocalizedString("The SQLite database could not be found.", comment: "")
}
}
} }
} }
class GamesDatabase class GamesDatabase
{ {
static let version = -1 static let version = 3
static var previousVersion: Int? {
return UserDefaults.standard.previousGamesDatabaseVersion
}
private let connection: Connection private let connection: Connection
@ -80,7 +90,7 @@ class GamesDatabase
} }
catch catch
{ {
throw Error.connection(error) throw error
} }
self.invalidateVirtualTableIfNeeded() self.invalidateVirtualTableIfNeeded()
@ -89,10 +99,11 @@ class GamesDatabase
func metadataResults(forGameName gameName: String) -> [GameMetadata] func metadataResults(forGameName gameName: String) -> [GameMetadata]
{ {
let releaseID = Expression<Any>.releaseID let releaseID = Expression<Any>.releaseID
let romID = Expression<Any>.romID
let name = Expression<Any>.name let name = Expression<Any>.name
let artworkAddress = Expression<Any>.artworkAddress let artworkAddress = Expression<Any>.artworkAddress
let query = VirtualTable.search.select(releaseID, name, artworkAddress).filter(name.match(gameName + "*")) let query = VirtualTable.search.select(releaseID, romID, name, artworkAddress).filter(name.match(gameName + "*"))
do do
{ {
@ -111,7 +122,7 @@ class GamesDatabase
} }
let metadata = GameMetadata(identifier: row[releaseID], name: row[name], artworkURL: artworkURL) let metadata = GameMetadata(releaseID: row[releaseID], romID: row[romID], name: row[name], artworkURL: artworkURL)
return metadata return metadata
} }
@ -145,7 +156,7 @@ class GamesDatabase
let romID = Expression<Any>.romID let romID = Expression<Any>.romID
let gameHash = game.identifier.uppercased() let gameHash = game.identifier.uppercased()
let query = Table.roms.select(releaseID, name, artworkAddress).filter(sha1Hash == gameHash).join(Table.releases, on: Table.roms[romID] == Table.releases[romID]) let query = Table.roms.select(releaseID, name, artworkAddress, Table.roms[romID]).filter(sha1Hash == gameHash).join(Table.releases, on: Table.roms[romID] == Table.releases[romID])
do do
{ {
@ -161,7 +172,7 @@ class GamesDatabase
artworkURL = nil artworkURL = nil
} }
let metadata = GameMetadata(identifier: row[releaseID], name: row[name], artworkURL: artworkURL) let metadata = GameMetadata(releaseID: row[releaseID], romID: row[Table.roms[romID]], name: row[name], artworkURL: artworkURL)
return metadata return metadata
} }
} }
@ -197,12 +208,13 @@ private extension GamesDatabase
let name = Expression<Any>.name let name = Expression<Any>.name
let artworkAddress = Expression<Any>.artworkAddress let artworkAddress = Expression<Any>.artworkAddress
let releaseID = Expression<Any>.releaseID let releaseID = Expression<Any>.releaseID
let romID = Expression<Any>.romID
do do
{ {
try self.connection.run(VirtualTable.search.create(.FTS4([releaseID, name, artworkAddress], tokenize: .Unicode61()))) try self.connection.run(VirtualTable.search.create(.FTS4([releaseID, romID, name, artworkAddress], tokenize: .Unicode61())))
let update = VirtualTable.search.insert(Table.releases.select(releaseID, name, artworkAddress)) let update = VirtualTable.search.insert(Table.releases.select(releaseID, romID, name, artworkAddress))
_ = try self.connection.run(update) _ = try self.connection.run(update)
} }
catch catch

View File

@ -0,0 +1,126 @@
//
// GamePickerViewController.swift
// Delta
//
// Created by Riley Testut on 8/4/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import UIKit
import Roxas
class GamePickerViewController: UITableViewController
{
private lazy var dataSource = self.makeDataSource()
var gameHandler: ((Game?) -> Void)?
init()
{
super.init(style: .insetGrouped)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad()
{
super.viewDidLoad()
self.navigationController?.delegate = self
self.dataSource.proxy = self
self.tableView.dataSource = self.dataSource
self.tableView.prefetchDataSource = self.dataSource
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: RSTCellContentGenericCellIdentifier)
self.navigationItem.title = NSLocalizedString("Choose Game", comment: "")
self.navigationItem.searchController = self.dataSource.searchController
self.navigationItem.hidesSearchBarWhenScrolling = false
}
}
private extension GamePickerViewController
{
func makeDataSource() -> RSTFetchedResultsTableViewPrefetchingDataSource<Game, UIImage>
{
let fetchRequest = Game.fetchRequest()
fetchRequest.propertiesToFetch = [#keyPath(Game.name), #keyPath(Game.identifier), #keyPath(Game.artworkURL)]
fetchRequest.sortDescriptors = [NSSortDescriptor(keyPath: \Game.gameCollection?.index, ascending: true), NSSortDescriptor(keyPath: \Game.name, ascending: true)]
let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: DatabaseManager.shared.viewContext, sectionNameKeyPath: #keyPath(Game.gameCollection.name), cacheName: nil)
let dataSource = RSTFetchedResultsTableViewPrefetchingDataSource<Game, UIImage>(fetchedResultsController: fetchedResultsController)
dataSource.cellConfigurationHandler = { (cell, game, indexPath) in
var configuration = UIListContentConfiguration.valueCell()
configuration.prefersSideBySideTextAndSecondaryText = false
configuration.text = game.name
configuration.secondaryText = game.identifier
configuration.secondaryTextProperties.font = .preferredFont(forTextStyle: .caption1)
configuration.image = UIImage(named: "BoxArt")
configuration.imageProperties.maximumSize = CGSize(width: 48, height: 48)
configuration.imageProperties.reservedLayoutSize = CGSize(width: 48, height: 48)
configuration.imageProperties.cornerRadius = 4
cell.contentConfiguration = configuration
}
dataSource.prefetchHandler = { (game, indexPath, completionHandler) in
guard let artworkURL = game.artworkURL else {
completionHandler(nil, nil)
return nil
}
let imageOperation = LoadImageURLOperation(url: artworkURL)
imageOperation.resultHandler = { (image, error) in
completionHandler(image, error)
}
return imageOperation
}
dataSource.prefetchCompletionHandler = { (cell, image, indexPath, error) in
guard let image = image, var config = cell.contentConfiguration as? UIListContentConfiguration else { return }
config.image = image
cell.contentConfiguration = config
}
dataSource.searchController.searchableKeyPaths = [#keyPath(Game.name), #keyPath(Game.identifier)]
return dataSource
}
}
extension GamePickerViewController
{
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
let game = self.dataSource.item(at: indexPath)
self.gameHandler?(game)
self.navigationController?.delegate = nil // Prevent calling navigationController(_:willShow:)
self.navigationController?.popViewController(animated: true)
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?
{
guard let section = self.dataSource.fetchedResultsController.sections?[section], !section.name.isEmpty else {
return NSLocalizedString("Unknown System", comment: "")
}
return section.name
}
}
extension GamePickerViewController: UINavigationControllerDelegate
{
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool)
{
guard viewController != self else { return }
self.gameHandler?(nil)
}
}

View File

@ -0,0 +1,479 @@
//
// RepairDatabaseViewController.swift
// Delta
//
// Created by Riley Testut on 8/4/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import UIKit
import OSLog
import DeltaCore
import Roxas
import Harmony
private extension String
{
func sanitizedFilePath() -> String
{
let sanitizedFilePath = self.components(separatedBy: .urlFilenameAllowed.inverted).joined()
return sanitizedFilePath
}
}
class RepairDatabaseViewController: UIViewController
{
var completionHandler: (() -> Void)?
private var _viewDidAppear = false
private lazy var managedObjectContext = DatabaseManager.shared.newBackgroundSavingViewContext()
private lazy var gameSavesContext = DatabaseManager.shared.newBackgroundContext(withParent: self.managedObjectContext)
private var gamesByID: [String: Game]?
private lazy var backupsDirectory = FileManager.default.documentsDirectory.appendingPathComponent("Backups")
private lazy var gameSavesDirectory = DatabaseManager.gamesDirectoryURL
override func viewDidLoad()
{
super.viewDidLoad()
self.view.backgroundColor = .systemBackground
self.isModalInPresentation = true
let placeholderView = RSTPlaceholderView()
placeholderView.textLabel.text = NSLocalizedString("Verifying Database…", comment: "")
placeholderView.detailTextLabel.text = nil
placeholderView.activityIndicatorView.startAnimating()
placeholderView.stackView.spacing = 15
self.view.addSubview(placeholderView, pinningEdgesWith: .zero)
}
override func viewDidAppear(_ animated: Bool)
{
super.viewDidAppear(animated)
if !_viewDidAppear
{
self.repairDatabase()
}
_viewDidAppear = true
}
}
private extension RepairDatabaseViewController
{
func repairDatabase()
{
Logger.database.info("Begin repairing database...")
self.repairGames { result in
switch result
{
case .failure(let error):
DispatchQueue.main.async {
let alertController = UIAlertController(title: "Unable to Repair Games", error: error)
self.present(alertController, animated: true)
}
case .success:
self.repairGameSaves { result in
DispatchQueue.main.async {
switch result
{
case .failure(let error):
let alertController = UIAlertController(title: "Unable to Repair Save Files", error: error)
self.present(alertController, animated: true)
case .success:
self.showReviewViewController()
}
}
}
}
}
}
func repairGames(completion: @escaping (Result<Void, Error>) -> Void)
{
self.managedObjectContext.perform {
do
{
let fetchRequest = Game.fetchRequest()
fetchRequest.propertiesToFetch = [#keyPath(Game.type)]
fetchRequest.relationshipKeyPathsForPrefetching = [#keyPath(Game.gameCollection)]
let allGames = try self.managedObjectContext.fetch(fetchRequest)
let affectedGames = allGames.filter { $0.type.rawValue != $0.gameCollection?.identifier }
let gameCollections = try self.managedObjectContext.fetch(GameCollection.fetchRequest())
let gameCollectionsByID = gameCollections.reduce(into: [:]) { $0[$1.identifier] = $1 }
for game in affectedGames
{
let gameCollection = gameCollectionsByID[game.type.rawValue]
game.gameCollection = gameCollection
Logger.database.notice("Re-associating “\(game.name, privacy: .public)” with GameCollection: \(gameCollection?.identifier ?? "nil", privacy: .public)")
}
try self.managedObjectContext.save()
completion(.success)
}
catch
{
completion(.failure(error))
}
}
}
func repairGameSaves(completion: @escaping (Result<Void, Error>) -> Void)
{
self.managedObjectContext.perform {
do
{
// Fetch GameSaves that don't have same identifier as their Game,
// OR GameSaves that have a non-nil SHA1 hash.
//
// This covers GameSaves connected to wrong games and GameSaves with nil Games,
// as well as any GameSaves modified since last beta (which we assume are corrupted).
let fetchRequest = GameSave.fetchRequest()
fetchRequest.predicate = NSPredicate(format: "(%K == nil) OR (%K != %K) OR (%K != nil)",
#keyPath(GameSave.game),
#keyPath(GameSave.identifier), #keyPath(GameSave.game.identifier),
#keyPath(GameSave.sha1))
let gameSaves = try self.managedObjectContext.fetch(fetchRequest)
let gameSavesByID = gameSaves.reduce(into: [:]) { $0[$1.identifier] = $1 }
let gamesFetchRequest = Game.fetchRequest()
gamesFetchRequest.predicate = NSPredicate(format: "%K IN %@", #keyPath(Game.identifier), Set(gameSavesByID.keys))
let games = try self.managedObjectContext.fetch(gamesFetchRequest)
self.gamesByID = games.reduce(into: [:]) { $0[$1.identifier] = $1 }
let savesBackupsDirectory = self.backupsDirectory.appendingPathComponent("Saves")
try FileManager.default.createDirectory(at: savesBackupsDirectory, withIntermediateDirectories: true)
var conflictedGames = Set<Game>()
for gameSave in gameSaves
{
let expectedGame = self.repair(gameSave, backupsDirectory: savesBackupsDirectory)
// At this point, gameSave is only updated in gameSavesContext,
// so gameSave here still points to previous game,
if let game = gameSave.game
{
Logger.database.notice("The save file for “\(game.name, privacy: .public)” is potentially corrupted, writing to conflicts.txt")
conflictedGames.insert(game)
}
if let expectedGame
{
Logger.database.notice("The save file for “\(expectedGame.name, privacy: .public)” is potentially corrupted, writing to conflicts.txt")
conflictedGames.insert(expectedGame)
}
}
try self.gameSavesContext.performAndWait {
try self.gameSavesContext.save()
}
try self.managedObjectContext.save()
let outputURL = self.backupsDirectory.appendingPathComponent("conflicts.txt")
let conflictsLog = conflictedGames.map { $0.name + " (" + $0.identifier + ")" }.sorted().joined(separator: "\n")
try conflictsLog.write(to: outputURL, atomically: true, encoding: .utf8)
completion(.success)
}
catch
{
completion(.failure(error))
}
}
}
// Returns expectedGame, but in managedObjectContext (not gameSavesContext)
func repair(_ gameSave: GameSave, backupsDirectory: URL) -> Game?
{
Logger.database.notice("Repairing GameSave \(gameSave.identifier, privacy: .public)...")
guard let expectedGame = self.gamesByID?[gameSave.identifier] else {
// Game doesn't exist, so we'll back up save file and delete record.
Logger.database.warning("Orphaning GameSave \(gameSave.identifier, privacy: .public) due to no matching game.")
do
{
try self.backup(gameSave, for: nil, to: backupsDirectory)
}
catch
{
Logger.database.error("Failed to back up save file for orphaned GameSave \(gameSave.identifier, privacy: .public). \(error, privacy: .public)")
}
self.gameSavesContext.performAndWait {
let gameSave = self.gameSavesContext.object(with: gameSave.objectID) as! GameSave
gameSave.game = nil
}
return nil
}
let misplacedGameSave: GameSave?
if let otherGameSave = expectedGame.gameSave, otherGameSave != gameSave
{
misplacedGameSave = otherGameSave
Logger.database.info("GameSave \(gameSave.identifier, privacy: .public) will misplace \(otherGameSave.identifier, privacy: .public)")
}
else
{
misplacedGameSave = nil
}
do
{
// Back up the save file gameSave (incorrectly) refers to, but name it after the _expected_ game.
try self.backup(gameSave, for: expectedGame, to: backupsDirectory)
}
catch
{
Logger.database.error("Failed to back up save file for GameSave \(gameSave.identifier, privacy: .public). Expected Game: \(expectedGame.identifier). \(error, privacy: .public)")
}
// Ignore error if we can't hash file, not that big a deal.
let hash = try? RSTHasher.sha1HashOfFile(at: expectedGame.gameSaveURL)
// Make changes on separate context so we don't change any relationships until we're finished.
// This allows us to refer to previous relationships.
self.gameSavesContext.performAndWait {
let gameSave = self.gameSavesContext.object(with: gameSave.objectID) as! GameSave
let expectedGame = self.gameSavesContext.object(with: expectedGame.objectID) as! Game
let misplacedGameSave: GameSave? = misplacedGameSave.map { self.gameSavesContext.object(with: $0.objectID) as! GameSave }
if hash == gameSave.sha1
{
// .sav has same hash as GameSave SHA1,
// so we can relink without changes.
Logger.database.info("GameSave \(gameSave.identifier, privacy: .public)'s hash matches .sav, relinking without changes.")
}
else if let misplacedGameSave
{
// GameSave data differs from actual .sav file,
// so copy metadata from misplacedGameSave.
Logger.database.info("GameSave \(gameSave.identifier, privacy: .public)'s hash does NOT match .sav, ignoring misplaced GameSave \(misplacedGameSave.identifier, privacy: .public).")
// Not worth potential conflicts.
// gameSave.sha1 = misplacedGameSave.sha1
// gameSave.modifiedDate = misplacedGameSave.modifiedDate
}
else
{
// GameSave data differs from actual .sav file,
// so copy metadata from disk.
Logger.database.info("GameSave \(gameSave.identifier, privacy: .public)'s hash does NOT match .sav, ignoring.")
// Not worth potential conflicts.
// let modifiedDate = try? FileManager.default.attributesOfItem(atPath: expectedGame.gameSaveURL.path)[.modificationDate] as? Date
// gameSave.sha1 = hash
// gameSave.modifiedDate = modifiedDate ?? Date()
}
gameSave.game = expectedGame
}
return expectedGame
}
func backup(_ gameSave: GameSave, for expectedGame: Game?, to backupsDirectory: URL) throws
{
Logger.database.notice("Backing up GameSave \(gameSave.identifier, privacy: .public). Expected Game: \(expectedGame?.name ?? "nil", privacy: .public)")
if let game = gameSave.game
{
// GameSave is linked with incorrect game.
// Prefer using expectedGame's saveFileExtension over game's.
let saveFileExtension: String
if let deltaCore = Delta.core(for: expectedGame?.type ?? game.type)
{
saveFileExtension = deltaCore.gameSaveFileExtension
}
else
{
saveFileExtension = "sav"
}
// 1. Backup existing file at `game`'s expected save file location
if FileManager.default.fileExists(atPath: game.gameSaveURL.path)
{
// Filename = expectedGame.name? + game.identifier
let filename: String
if let expectedGame
{
filename = expectedGame.name + "_" + game.identifier
}
else
{
filename = game.identifier
}
let sanitizedFilename = filename.sanitizedFilePath()
let destinationURL = backupsDirectory.appendingPathComponent(sanitizedFilename).appendingPathExtension(saveFileExtension)
try FileManager.default.copyItem(at: game.gameSaveURL, to: destinationURL, shouldReplace: true)
Logger.database.notice("Backed up save file \(game.gameSaveURL.lastPathComponent, privacy: .public) to \(destinationURL.lastPathComponent, privacy: .public)")
let rtcFileURL = game.gameSaveURL.deletingPathExtension().appendingPathExtension("rtc")
if FileManager.default.fileExists(atPath: rtcFileURL.path)
{
let destinationURL = backupsDirectory.appendingPathComponent(sanitizedFilename).appendingPathExtension("rtc")
try FileManager.default.copyItem(at: rtcFileURL, to: destinationURL, shouldReplace: true)
Logger.database.notice("Backed up RTC save file \(rtcFileURL.lastPathComponent, privacy: .public) to \(destinationURL.lastPathComponent, privacy: .public)")
}
}
// 2. Backup existing file at `expectedGame`'s save file location
if let expectedGame, FileManager.default.fileExists(atPath: expectedGame.gameSaveURL.path)
{
// Filename = expectedGame.name + (misplacedGameSave.identifier ?? expectedGame.identifier)
let filename = expectedGame.name + "_" + (expectedGame.gameSave?.identifier ?? expectedGame.identifier)
let sanitizedFilename = filename.sanitizedFilePath()
let destinationURL = backupsDirectory.appendingPathComponent(sanitizedFilename).appendingPathExtension(saveFileExtension)
try FileManager.default.copyItem(at: expectedGame.gameSaveURL, to: destinationURL, shouldReplace: true)
Logger.database.notice("Backed up expected save file \(expectedGame.gameSaveURL.lastPathComponent, privacy: .public) to \(destinationURL.lastPathComponent, privacy: .public)")
let rtcFileURL = expectedGame.gameSaveURL.deletingPathExtension().appendingPathExtension("rtc")
if FileManager.default.fileExists(atPath: rtcFileURL.path)
{
let destinationURL = backupsDirectory.appendingPathComponent(sanitizedFilename).appendingPathExtension("rtc")
try FileManager.default.copyItem(at: rtcFileURL, to: destinationURL, shouldReplace: true)
Logger.database.notice("Backed up expected RTC save file \(rtcFileURL.lastPathComponent, privacy: .public) to \(destinationURL.lastPathComponent, privacy: .public)")
}
}
}
else
{
@discardableResult
func backUp(_ saveFileURL: URL) throws -> Bool
{
guard FileManager.default.fileExists(atPath: saveFileURL.path) else { return false }
// Filename = expectedGame.name? + gameSave.identifier
let filename: String
if let expectedGame
{
filename = expectedGame.name + "_" + gameSave.identifier
}
else
{
filename = gameSave.identifier
}
let sanitizedFilename = filename.sanitizedFilePath()
let destinationURL = backupsDirectory.appendingPathComponent(sanitizedFilename).appendingPathExtension(saveFileURL.pathExtension)
try FileManager.default.copyItem(at: saveFileURL, to: destinationURL, shouldReplace: true)
Logger.database.notice("Backed up discovered save file \(saveFileURL.lastPathComponent, privacy: .public) to \(destinationURL.lastPathComponent, privacy: .public)")
return true
}
// GameSave is _not_ linked to a Game, so instead we iterate through all save files on disk to find match.
let savURL = self.gameSavesDirectory.appendingPathComponent(gameSave.identifier).appendingPathExtension("sav")
let srmURL = self.gameSavesDirectory.appendingPathComponent(gameSave.identifier).appendingPathExtension("srm")
let dsvURL = self.gameSavesDirectory.appendingPathComponent(gameSave.identifier).appendingPathExtension("dsv")
let saveFileURLs = [savURL, srmURL, dsvURL]
for saveFileURL in saveFileURLs
{
if try backUp(saveFileURL)
{
break
}
}
// ALWAYS attempt to back up RTC file.
let rtcURL = self.gameSavesDirectory.appendingPathComponent(gameSave.identifier).appendingPathExtension("rtc")
try backUp(rtcURL)
}
}
func showReviewViewController()
{
Logger.database.info("Finished repairing Games and GameSaves, reviewing recent SaveStates...")
let viewController = ReviewSaveStatesViewController()
viewController.filter = .sinceLastBeta
viewController.completionHandler = { [weak self] in
self?.finish()
}
self.navigationController?.pushViewController(viewController, animated: true)
}
func finish()
{
Logger.database.info("Finished repairing database!")
DispatchQueue.global(qos: .userInitiated).async {
if #available(iOS 15, *)
{
do
{
let store = try OSLogStore(scope: .currentProcessIdentifier)
// All logs since the app launched.
let position = store.position(timeIntervalSinceLatestBoot: 0)
let entries = try store.getEntries(at: position)
.compactMap { $0 as? OSLogEntryLog }
.filter { $0.subsystem == Logger.deltaSubsystem || $0.subsystem == Logger.harmonySubsystem }
.map { "[\($0.date.formatted())] [\($0.level.localizedName)] \($0.composedMessage)" }
let outputURL = self.backupsDirectory.appendingPathComponent("repair.log")
try FileManager.default.createDirectory(at: self.backupsDirectory, withIntermediateDirectories: true)
let outputText = entries.joined(separator: "\n")
try outputText.write(to: outputURL, atomically: true, encoding: .utf8)
}
catch
{
print("Failed to export Harmony logs.", error)
}
}
DispatchQueue.main.async {
let alertController = UIAlertController(title: NSLocalizedString("Database Repaired", comment: ""),
message: NSLocalizedString("Some save files may still be corrupted and require you to restore an older version from the Delta Sync settings.\n\nA text file listing all affected games has been saved to “On My Device/Delta/Backups/conflicts.txt” in the Files app, alongside backups of any conflicted save files.", comment: ""),
preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: UIAlertAction.ok.title, style: UIAlertAction.ok.style) { _ in
self.completionHandler?()
})
self.present(alertController, animated: true)
}
}
}
}

View File

@ -0,0 +1,377 @@
//
// ReviewSaveStatesViewController.swift
// Delta
//
// Created by Riley Testut on 8/4/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import UIKit
import OSLog
import Harmony
import Roxas
extension ReviewSaveStatesViewController
{
enum Filter
{
case recent
case all
case sinceLastBeta
}
}
extension RecordFlags
{
static let isGameRelationshipVerified = RecordFlags(rawValue: 1 << 0)
}
class ReviewSaveStatesViewController: UITableViewController
{
var filter: Filter = .recent {
didSet {
self.updateDataSource()
}
}
var completionHandler: (() -> Void)?
private lazy var managedObjectContext = DatabaseManager.shared.newBackgroundSavingViewContext()
private lazy var dataSource = self.makeDataSource()
private lazy var descriptionDataSource = self.makeDescriptionDataSource()
private lazy var saveStatesDataSource = self.makeSaveStatesDataSource()
private weak var _parentNavigationController: UINavigationController?
init()
{
super.init(style: .insetGrouped)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad()
{
super.viewDidLoad()
self.dataSource.proxy = self
self.tableView.dataSource = self.dataSource
self.tableView.prefetchDataSource = self.dataSource
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: RSTCellContentGenericCellIdentifier)
let doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(ReviewSaveStatesViewController.finish))
self.navigationItem.rightBarButtonItem = doneButton
self.navigationItem.title = NSLocalizedString("Review Save States", comment: "")
// Disable going back to RepairDatabaseViewController.
self.navigationItem.setHidesBackButton(true, animated: false)
self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false
}
override func viewWillAppear(_ animated: Bool)
{
super.viewWillAppear(animated)
if let parent = self.parent, parent.navigationItem.title == nil
{
// Must change parent's navigationItem when we're contained in SwiftUI View.
parent.navigationItem.title = NSLocalizedString("Review Save States", comment: "")
parent.navigationItem.rightBarButtonItem = self.makeFilterButton()
}
}
override func viewWillDisappear(_ animated: Bool)
{
super.viewWillDisappear(animated)
_parentNavigationController = self.parent?.navigationController
}
override func viewDidDisappear(_ animated: Bool)
{
super.viewDidDisappear(animated)
switch self.filter
{
case .all, .recent:
if self.parent == nil || self.parent?.parent == nil
{
// Only finish if we're popped off navigation controller.
self.finish()
}
case .sinceLastBeta: break
}
}
}
private extension ReviewSaveStatesViewController
{
func makeDataSource() -> RSTCompositeTableViewPrefetchingDataSource<SaveState, UIImage>
{
let dataSource = RSTCompositeTableViewPrefetchingDataSource<SaveState, UIImage>(dataSources: [self.descriptionDataSource, self.saveStatesDataSource])
return dataSource
}
func makeDescriptionDataSource() -> RSTDynamicTableViewPrefetchingDataSource<SaveState, UIImage>
{
let dataSource = RSTDynamicTableViewPrefetchingDataSource<SaveState, UIImage>()
dataSource.numberOfSectionsHandler = { 1 }
dataSource.numberOfItemsHandler = { _ in 0 }
return dataSource
}
func makeSaveStatesDataSource() -> RSTFetchedResultsTableViewPrefetchingDataSource<SaveState, UIImage>
{
let fetchedResultsController = self.makeSaveStatesFetchedResultsController()
let dataSource = RSTFetchedResultsTableViewPrefetchingDataSource<SaveState, UIImage>(fetchedResultsController: fetchedResultsController)
dataSource.cellConfigurationHandler = { (cell, saveState, indexPath) in
var configuration = UIListContentConfiguration.valueCell()
configuration.prefersSideBySideTextAndSecondaryText = false
let fontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .body).withSymbolicTraits(.traitBold) ?? .preferredFontDescriptor(withTextStyle: .body)
configuration.text = saveState.name ?? NSLocalizedString("Untitled", comment: "")
configuration.textProperties.font = UIFont(descriptor: fontDescriptor, size: 0)
configuration.secondaryText = SaveState.localizedDateFormatter.string(from: saveState.modifiedDate)
configuration.secondaryTextProperties.font = .preferredFont(forTextStyle: .caption1)
configuration.image = nil
configuration.imageProperties.maximumSize = CGSize(width: 80, height: 80)
configuration.imageProperties.reservedLayoutSize = CGSize(width: 80, height: 80)
configuration.imageProperties.cornerRadius = 6
cell.contentConfiguration = configuration
cell.accessoryType = .disclosureIndicator
}
dataSource.prefetchHandler = { (saveState, indexPath, completionHandler) in
guard saveState.game != nil else {
completionHandler(nil, nil)
return nil
}
let imageOperation = LoadImageURLOperation(url: saveState.imageFileURL)
imageOperation.resultHandler = { (image, error) in
completionHandler(image, error)
}
if self.isAppearing
{
imageOperation.start()
imageOperation.waitUntilFinished()
return nil
}
return imageOperation
}
dataSource.prefetchCompletionHandler = { (cell, image, indexPath, error) in
guard let image = image, var config = cell.contentConfiguration as? UIListContentConfiguration else { return }
config.image = image
cell.contentConfiguration = config
}
return dataSource
}
func makeSaveStatesFetchedResultsController() -> NSFetchedResultsController<SaveState>
{
let fetchRequest = SaveState.fetchRequest()
fetchRequest.returnsObjectsAsFaults = false
fetchRequest.sortDescriptors = [NSSortDescriptor(keyPath: \SaveState.game?.name, ascending: true), NSSortDescriptor(keyPath: \SaveState.modifiedDate, ascending: false)]
let predicate = NSPredicate(format: "%K != %@", #keyPath(SaveState.type), SaveStateType.auto.rawValue as NSNumber)
switch self.filter
{
case .recent:
let oneMonthAgo = Calendar.current.date(byAdding: .month, value: -1, to: Date()) ?? Date().addingTimeInterval(-1 * 60 * 60 * 24 * 30)
let recentPredicate = NSPredicate(format: "%K > %@", #keyPath(SaveState.modifiedDate), oneMonthAgo as NSDate)
fetchRequest.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [predicate, recentPredicate])
case .all:
fetchRequest.predicate = predicate
case .sinceLastBeta:
let dateComponents = DateComponents(year: 2023, month: 7, day: 18, hour: 0, minute: 0, second: 0)
let lastBetaDate = Calendar.current.date(from: dateComponents) ?? Date().addingTimeInterval(-1 * 60 * 60 * 24 * 45)
let sinceLastBetaPredicate = NSPredicate(format: "%K > %@", #keyPath(SaveState.modifiedDate), lastBetaDate as NSDate)
fetchRequest.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [predicate, sinceLastBetaPredicate])
}
let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self.managedObjectContext, sectionNameKeyPath: #keyPath(SaveState.game.name), cacheName: nil)
return fetchedResultsController
}
func updateDataSource()
{
let fetchedResultsController = self.makeSaveStatesFetchedResultsController()
self.saveStatesDataSource.fetchedResultsController = fetchedResultsController
}
func makeFilterButton() -> UIBarButtonItem
{
let recentAction = UIAction(title: NSLocalizedString("Past Month", comment: ""), image: UIImage(systemName: "calendar")) { [weak self] _ in
self?.filter = .recent
}
let allAction = UIAction(title: NSLocalizedString("All Time", comment: ""), image: UIImage(systemName: "clock")) { [weak self] _ in
self?.filter = .all
}
var options: UIMenu.Options = []
if #available(iOS 15, *)
{
options = .singleSelection
recentAction.state = self.filter == .recent ? .on : .off
allAction.state = self.filter == .all ? .on : .off
}
let filterMenu = UIMenu(options: options, children: [recentAction, allAction])
let filterButton = UIBarButtonItem(title: NSLocalizedString("Filter", comment: ""), image: UIImage(systemName: "calendar.badge.clock"), menu: filterMenu)
return filterButton
}
}
private extension ReviewSaveStatesViewController
{
func pickGame(for saveState: SaveState)
{
let gamePickerViewController = GamePickerViewController()
gamePickerViewController.gameHandler = { game in
guard let game else { return }
let previousGame = saveState.game
if previousGame != nil
{
// Move files to new location.
let destinationDirectory = DatabaseManager.saveStatesDirectoryURL(for: game)
for fileURL in [saveState.fileURL, saveState.imageFileURL]
{
guard FileManager.default.fileExists(atPath: fileURL.path) else { continue }
let destinationURL = destinationDirectory.appendingPathComponent(fileURL.lastPathComponent)
do
{
try FileManager.default.copyItem(at: fileURL, to: destinationURL, shouldReplace: true) // Copy, don't move, in case app quits before user confirms.
}
catch
{
Logger.database.error("Failed to copy SaveState “\(saveState.localizedName, privacy: .public)” from \(fileURL, privacy: .public) to \(destinationURL, privacy: .public). \(error.localizedDescription, privacy: .public)")
}
}
}
let tempGame = self.managedObjectContext.object(with: game.objectID) as! Game
saveState.game = tempGame
Logger.database.notice("Re-associated SaveState “\(saveState.localizedName, privacy: .public)” with game “\(tempGame.name, privacy: .public)”. Previously: \(previousGame?.name ?? "nil", privacy: .public)")
}
self.navigationController?.pushViewController(gamePickerViewController, animated: true)
}
@objc func finish()
{
self.navigationItem.rightBarButtonItem?.isIndicatingActivity = true
self.managedObjectContext.perform {
do
{
let saveStates: [SaveState]?
switch self.filter
{
case .recent, .all:
// Only upload metadata for changed SaveStates.
saveStates = self.managedObjectContext.updatedObjects.compactMap { $0 as? SaveState }
case .sinceLastBeta:
// Upload metadata for _all_ SaveStates.
saveStates = self.saveStatesDataSource.fetchedResultsController.fetchedObjects
}
try self.managedObjectContext.save()
if let saveStates = saveStates, let coordinator = SyncManager.shared.coordinator
{
let records = try coordinator.recordController.fetchRecords(for: saveStates)
if let context = records.first?.recordedObject?.managedObjectContext
{
try context.performAndWait {
for record in records
{
record.perform { managedRecord in
managedRecord.flags.insert(.isGameRelationshipVerified)
managedRecord.setNeedsMetadataUpdate()
let saveState = record.recordedObject
Logger.database.notice("Flagged SaveState “\(saveState?.localizedName ?? record.recordID.identifier, privacy: .public)” for metadata update.")
}
}
try context.save()
}
}
}
DispatchQueue.main.async {
self.completionHandler?()
}
}
catch
{
DispatchQueue.main.async {
self.navigationItem.rightBarButtonItem?.isIndicatingActivity = false
let alertController = UIAlertController(title: NSLocalizedString("Unable to Save Changes", comment: ""), error: error)
(self._parentNavigationController ?? self).present(alertController, animated: true)
}
}
}
}
}
extension ReviewSaveStatesViewController
{
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
let saveState = self.dataSource.item(at: indexPath)
self.pickGame(for: saveState)
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?
{
if section == 0
{
return nil
}
else
{
let section = section - 1
guard let gameName = self.saveStatesDataSource.fetchedResultsController.sections?[section].name else { return NSLocalizedString("Unknown Game", comment: "") }
return gameName
}
}
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String?
{
guard section == 0 else { return nil }
return NSLocalizedString("These save states have been modified recently and may be associated with the wrong game.\n\nPlease change any incorrectly associated save states to the correct game by tapping them.", comment: "")
}
}

View File

@ -15,6 +15,8 @@ extension UIActivity.ActivityType
class CopyDeepLinkActivity: UIActivity class CopyDeepLinkActivity: UIActivity
{ {
private var deepLink: URL?
override class var activityCategory: UIActivity.Category { override class var activityCategory: UIActivity.Category {
return .action return .action
} }
@ -28,7 +30,7 @@ class CopyDeepLinkActivity: UIActivity
} }
override var activityImage: UIImage? { override var activityImage: UIImage? {
return UIImage(named: "Link") return UIImage(symbolNameIfAvailable: "link") ?? UIImage(named: "Link")
} }
override func canPerform(withActivityItems activityItems: [Any]) -> Bool override func canPerform(withActivityItems activityItems: [Any]) -> Bool
@ -47,7 +49,19 @@ class CopyDeepLinkActivity: UIActivity
{ {
guard let game = activityItems.first(where: { $0 is Game }) as? Game else { return } guard let game = activityItems.first(where: { $0 is Game }) as? Game else { return }
let deepLink = URL(action: .launchGame(identifier: game.identifier)) self.deepLink = URL(action: .launchGame(identifier: game.identifier))
UIPasteboard.general.url = deepLink }
override func perform()
{
if let deepLink = self.deepLink
{
UIPasteboard.general.url = deepLink
self.activityDidFinish(true)
}
else
{
self.activityDidFinish(false)
}
} }
} }

View File

@ -23,8 +23,16 @@ extension UIViewController
struct DeepLinkController struct DeepLinkController
{ {
private var window: UIWindow? { private var window: UIWindow? {
guard let delegate = UIApplication.shared.delegate, let window = delegate.window else { return nil } if #available(iOS 13, *)
return window {
guard let delegate = UIApplication.shared.connectedScenes.lazy.compactMap({ $0.delegate as? UIWindowSceneDelegate }).first, let window = delegate.window else { return nil }
return window
}
else
{
guard let delegate = UIApplication.shared.delegate, let window = delegate.window else { return nil }
return window
}
} }
private var topViewController: UIViewController? { private var topViewController: UIViewController? {

View File

@ -18,6 +18,7 @@ enum ActionInput: String
case quickSave case quickSave
case quickLoad case quickLoad
case fastForward case fastForward
case toggleFastForward
} }
extension ActionInput: Input extension ActionInput: Input

View File

@ -7,14 +7,29 @@
// //
import UIKit import UIKit
import Photos
import DeltaCore import DeltaCore
import GBADeltaCore import GBADeltaCore
import MelonDSDeltaCore
import Systems
import struct DSDeltaCore.DS
import Roxas import Roxas
import AltKit
private var kvoContext = 0 private var kvoContext = 0
private extension DeltaCore.ControllerSkin
{
func hasTouchScreen(for traits: DeltaCore.ControllerSkin.Traits) -> Bool
{
let hasTouchScreen = self.items(for: traits)?.contains(where: { $0.kind == .touchScreen }) ?? false
return hasTouchScreen
}
}
private extension GameViewController private extension GameViewController
{ {
struct PausedSaveState: SaveStateProtocol struct PausedSaveState: SaveStateProtocol
@ -31,6 +46,30 @@ private extension GameViewController
} }
} }
struct DefaultInputMapping: GameControllerInputMappingProtocol
{
let gameController: GameController
var gameControllerInputType: GameControllerInputType {
return self.gameController.inputType
}
func input(forControllerInput controllerInput: Input) -> Input?
{
if let mappedInput = self.gameController.defaultInputMapping?.input(forControllerInput: controllerInput)
{
return mappedInput
}
// Only intercept controller skin inputs.
//
guard controllerInput.type == .controller(.controllerSkin) else { return nil }
let actionInput = ActionInput(stringValue: controllerInput.stringValue)
return actionInput
}
}
struct SustainInputsMapping: GameControllerInputMappingProtocol struct SustainInputsMapping: GameControllerInputMappingProtocol
{ {
let gameController: GameController let gameController: GameController
@ -54,6 +93,7 @@ private extension GameViewController
class GameViewController: DeltaCore.GameViewController class GameViewController: DeltaCore.GameViewController
{ {
/// Assumed to be Delta.Game instance /// Assumed to be Delta.Game instance
/// /// Delta.Game
override var game: GameProtocol? { override var game: GameProtocol? {
willSet { willSet {
self.emulatorCore?.removeObserver(self, forKeyPath: #keyPath(EmulatorCore.state), context: &kvoContext) self.emulatorCore?.removeObserver(self, forKeyPath: #keyPath(EmulatorCore.state), context: &kvoContext)
@ -74,8 +114,8 @@ class GameViewController: DeltaCore.GameViewController
self.shouldResetSustainedInputs = true self.shouldResetSustainedInputs = true
} }
self.updateControllerSkin()
self.updateControllers() self.updateControllers()
self.updateAudio()
self.presentedGyroAlert = false self.presentedGyroAlert = false
} }
@ -133,6 +173,8 @@ class GameViewController: DeltaCore.GameViewController
private var isGyroActive = false private var isGyroActive = false
private var presentedGyroAlert = false private var presentedGyroAlert = false
private var presentedJITAlert = false
override var shouldAutorotate: Bool { override var shouldAutorotate: Bool {
return !self.isGyroActive return !self.isGyroActive
} }
@ -141,6 +183,14 @@ class GameViewController: DeltaCore.GameViewController
return .all return .all
} }
override var prefersStatusBarHidden: Bool {
return !ExperimentalFeatures.shared.showStatusBar.isEnabled
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
required init() required init()
{ {
super.init() super.init()
@ -164,11 +214,18 @@ class GameViewController: DeltaCore.GameViewController
NotificationCenter.default.addObserver(self, selector: #selector(GameViewController.didEnterBackground(with:)), name: UIApplication.didEnterBackgroundNotification, object: UIApplication.shared) NotificationCenter.default.addObserver(self, selector: #selector(GameViewController.didEnterBackground(with:)), name: UIApplication.didEnterBackgroundNotification, object: UIApplication.shared)
NotificationCenter.default.addObserver(self, selector: #selector(GameViewController.settingsDidChange(with:)), name: .settingsDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(GameViewController.settingsDidChange(with:)), name: Settings.didChangeNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(GameViewController.deepLinkControllerLaunchGame(with:)), name: .deepLinkControllerLaunchGame, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(GameViewController.deepLinkControllerLaunchGame(with:)), name: .deepLinkControllerLaunchGame, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(GameViewController.didActivateGyro(with:)), name: GBA.didActivateGyroNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(GameViewController.didActivateGyro(with:)), name: GBA.didActivateGyroNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(GameViewController.didDeactivateGyro(with:)), name: GBA.didDeactivateGyroNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(GameViewController.didDeactivateGyro(with:)), name: GBA.didDeactivateGyroNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(GameViewController.emulationDidQuit(with:)), name: EmulatorCore.emulationDidQuitNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(GameViewController.didEnableJIT(with:)), name: ServerManager.didEnableJITNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(GameViewController.sceneWillConnect(with:)), name: UIScene.willConnectNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(GameViewController.sceneDidDisconnect(with:)), name: UIScene.didDisconnectNotification, object: nil)
} }
deinit deinit
@ -190,7 +247,7 @@ class GameViewController: DeltaCore.GameViewController
self.inputsToSustain[AnyInput(input)] = value self.inputsToSustain[AnyInput(input)] = value
} }
} }
else if self.emulatorCore?.state == .running else if let emulatorCore = self.emulatorCore, emulatorCore.state == .running
{ {
guard let actionInput = ActionInput(input: input) else { return } guard let actionInput = ActionInput(input: input) else { return }
@ -199,6 +256,9 @@ class GameViewController: DeltaCore.GameViewController
case .quickSave: self.performQuickSaveAction() case .quickSave: self.performQuickSaveAction()
case .quickLoad: self.performQuickLoadAction() case .quickLoad: self.performQuickLoadAction()
case .fastForward: self.performFastForwardAction(activate: true) case .fastForward: self.performFastForwardAction(activate: true)
case .toggleFastForward:
let isFastForwarding = (emulatorCore.rate != emulatorCore.deltaCore.supportedRates.lowerBound)
self.performFastForwardAction(activate: !isFastForwarding)
} }
} }
} }
@ -223,6 +283,7 @@ class GameViewController: DeltaCore.GameViewController
case .quickSave: break case .quickSave: break
case .quickLoad: break case .quickLoad: break
case .fastForward: self.performFastForwardAction(activate: false) case .fastForward: self.performFastForwardAction(activate: false)
case .toggleFastForward: break
} }
} }
} }
@ -240,14 +301,12 @@ extension GameViewController
// Lays out self.gameView, so we can pin self.sustainButtonsContentView to it without resulting in a temporary "cannot satisfy constraints". // Lays out self.gameView, so we can pin self.sustainButtonsContentView to it without resulting in a temporary "cannot satisfy constraints".
self.view.layoutIfNeeded() self.view.layoutIfNeeded()
let gameViewContainerView = self.gameView.superview!
self.controllerView.translucentControllerSkinOpacity = Settings.translucentControllerSkinOpacity self.controllerView.translucentControllerSkinOpacity = Settings.translucentControllerSkinOpacity
self.sustainButtonsContentView = UIView(frame: CGRect(x: 0, y: 0, width: self.gameView.bounds.width, height: self.gameView.bounds.height)) self.sustainButtonsContentView = UIView(frame: CGRect(x: 0, y: 0, width: self.gameView.bounds.width, height: self.gameView.bounds.height))
self.sustainButtonsContentView.translatesAutoresizingMaskIntoConstraints = false self.sustainButtonsContentView.translatesAutoresizingMaskIntoConstraints = false
self.sustainButtonsContentView.isHidden = true self.sustainButtonsContentView.isHidden = true
self.view.insertSubview(self.sustainButtonsContentView, aboveSubview: gameViewContainerView) self.view.insertSubview(self.sustainButtonsContentView, aboveSubview: self.gameView)
let blurEffect = UIBlurEffect(style: .dark) let blurEffect = UIBlurEffect(style: .dark)
let vibrancyEffect = UIVibrancyEffect(blurEffect: blurEffect) let vibrancyEffect = UIVibrancyEffect(blurEffect: blurEffect)
@ -273,19 +332,37 @@ extension GameViewController
vibrancyView.contentView.addSubview(self.sustainButtonsBackgroundView) vibrancyView.contentView.addSubview(self.sustainButtonsBackgroundView)
// Auto Layout // Auto Layout
self.sustainButtonsContentView.leadingAnchor.constraint(equalTo: gameViewContainerView.leadingAnchor).isActive = true self.sustainButtonsContentView.leadingAnchor.constraint(equalTo: self.gameView.leadingAnchor).isActive = true
self.sustainButtonsContentView.trailingAnchor.constraint(equalTo: gameViewContainerView.trailingAnchor).isActive = true self.sustainButtonsContentView.trailingAnchor.constraint(equalTo: self.gameView.trailingAnchor).isActive = true
self.sustainButtonsContentView.topAnchor.constraint(equalTo: gameViewContainerView.topAnchor).isActive = true self.sustainButtonsContentView.topAnchor.constraint(equalTo: self.gameView.topAnchor).isActive = true
self.sustainButtonsContentView.bottomAnchor.constraint(equalTo: gameViewContainerView.bottomAnchor).isActive = true self.sustainButtonsContentView.bottomAnchor.constraint(equalTo: self.gameView.bottomAnchor).isActive = true
self.updateControllerSkin()
self.updateControllers() self.updateControllers()
} }
override func viewDidAppear(_ animated: Bool)
{
super.viewDidAppear(animated)
if self.emulatorCore?.deltaCore == DS.core, UserDefaults.standard.desmumeDeprecatedAlertCount < 3
{
let toastView = RSTToastView(text: NSLocalizedString("DeSmuME Core Deprecated", comment: ""), detailText: NSLocalizedString("Switch to the melonDS core in Settings for latest improvements.", comment: ""))
self.show(toastView, duration: 5.0)
UserDefaults.standard.desmumeDeprecatedAlertCount += 1
}
else if self.emulatorCore?.deltaCore == MelonDS.core, ProcessInfo.processInfo.isJITAvailable
{
self.showJITEnabledAlert()
}
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
{ {
super.viewWillTransition(to: size, with: coordinator) super.viewWillTransition(to: size, with: coordinator)
guard UIApplication.shared.applicationState != .background else { return }
coordinator.animate(alongsideTransition: { (context) in coordinator.animate(alongsideTransition: { (context) in
self.updateControllerSkin() self.updateControllerSkin()
}, completion: nil) }, completion: nil)
@ -302,10 +379,18 @@ extension GameViewController
{ {
case "showGamesViewController": case "showGamesViewController":
let gamesViewController = (segue.destination as! UINavigationController).topViewController as! GamesViewController let gamesViewController = (segue.destination as! UINavigationController).topViewController as! GamesViewController
gamesViewController.theme = .translucent
gamesViewController.activeEmulatorCore = self.emulatorCore
self.updateAutoSaveState() if let emulatorCore = self.emulatorCore
{
gamesViewController.theme = .translucent
gamesViewController.activeEmulatorCore = emulatorCore
self.updateAutoSaveState()
}
else
{
gamesViewController.theme = .opaque
}
case "pause": case "pause":
@ -333,6 +418,9 @@ extension GameViewController
pauseViewController.fastForwardItem?.action = { [unowned self] item in pauseViewController.fastForwardItem?.action = { [unowned self] item in
self.performFastForwardAction(activate: item.isSelected) self.performFastForwardAction(activate: item.isSelected)
} }
pauseViewController.screenshotItem?.action = { [unowned self] item in
self.performScreenshotAction()
}
pauseViewController.sustainButtonsItem?.isSelected = gameController.sustainedInputs.count > 0 pauseViewController.sustainButtonsItem?.isSelected = gameController.sustainedInputs.count > 0
pauseViewController.sustainButtonsItem?.action = { [unowned self, unowned pauseViewController] item in pauseViewController.sustainButtonsItem?.action = { [unowned self, unowned pauseViewController] item in
@ -352,17 +440,21 @@ extension GameViewController
self.pausingGameController = gameController self.pausingGameController = gameController
} }
if self.emulatorCore?.deltaCore.supportedRates.upperBound == 1
{
pauseViewController.fastForwardItem = nil
}
switch self.game?.type switch self.game?.type
{ {
case .n64? where !UIDevice.current.hasA9ProcessorOrBetter: case .ds? where self.emulatorCore?.deltaCore == DS.core:
// A8 processors and earlier aren't powerful enough to run N64 games faster than 1x speed. // Cheats are not supported by DeSmuME core.
pauseViewController.fastForwardItem = nil
case .ds?:
// Cheats and Fast Forwarding are not yet supported for DS games.
pauseViewController.cheatCodesItem = nil pauseViewController.cheatCodesItem = nil
pauseViewController.fastForwardItem = nil
case .genesis?:
// GPGX core does not support cheats yet.
pauseViewController.cheatCodesItem = nil
default: break default: break
} }
@ -412,6 +504,13 @@ extension GameViewController
} }
self._isLoadingSaveState = false self._isLoadingSaveState = false
if self.emulatorCore?.deltaCore == MelonDS.core, ProcessInfo.processInfo.isJITAvailable
{
self.transitionCoordinator?.animate(alongsideTransition: nil, completion: { (context) in
self.showJITEnabledAlert()
})
}
} }
case "unwindToGames": case "unwindToGames":
@ -491,16 +590,27 @@ private extension GameViewController
} }
// If Settings.localControllerPlayerIndex is non-nil, and there isn't a connected controller with same playerIndex, show controller view. // If Settings.localControllerPlayerIndex is non-nil, and there isn't a connected controller with same playerIndex, show controller view.
if let index = Settings.localControllerPlayerIndex, !ExternalGameControllerManager.shared.connectedControllers.contains { $0.playerIndex == index } if let index = Settings.localControllerPlayerIndex, !ExternalGameControllerManager.shared.connectedControllers.contains(where: { $0.playerIndex == index })
{ {
self.controllerView.playerIndex = index self.controllerView.playerIndex = index
self.controllerView.isHidden = false self.controllerView.isHidden = false
} }
else else
{ {
self.controllerView.playerIndex = nil if let game = self.game,
self.controllerView.isHidden = true let traits = self.controllerView.controllerSkinTraits,
let controllerSkin = DeltaCore.ControllerSkin.standardControllerSkin(for: game.type),
controllerSkin.hasTouchScreen(for: traits)
{
self.controllerView.isHidden = false
self.controllerView.playerIndex = 0
}
else
{
self.controllerView.isHidden = true
self.controllerView.playerIndex = nil
}
Settings.localControllerPlayerIndex = nil Settings.localControllerPlayerIndex = nil
} }
@ -518,16 +628,19 @@ private extension GameViewController
{ {
if gameController.playerIndex != nil if gameController.playerIndex != nil
{ {
if let inputMapping = GameControllerInputMapping.inputMapping(for: gameController, gameType: game.type, in: DatabaseManager.shared.viewContext) let inputMapping: GameControllerInputMappingProtocol
if let mapping = GameControllerInputMapping.inputMapping(for: gameController, gameType: game.type, in: DatabaseManager.shared.viewContext)
{ {
gameController.addReceiver(self, inputMapping: inputMapping) inputMapping = mapping
gameController.addReceiver(emulatorCore, inputMapping: inputMapping)
} }
else else
{ {
gameController.addReceiver(self) inputMapping = DefaultInputMapping(gameController: gameController)
gameController.addReceiver(emulatorCore)
} }
gameController.addReceiver(self, inputMapping: inputMapping)
gameController.addReceiver(emulatorCore, inputMapping: inputMapping)
} }
else else
{ {
@ -552,18 +665,81 @@ private extension GameViewController
self.controllerView.isButtonHapticFeedbackEnabled = Settings.isButtonHapticFeedbackEnabled self.controllerView.isButtonHapticFeedbackEnabled = Settings.isButtonHapticFeedbackEnabled
self.controllerView.isThumbstickHapticFeedbackEnabled = Settings.isThumbstickHapticFeedbackEnabled self.controllerView.isThumbstickHapticFeedbackEnabled = Settings.isThumbstickHapticFeedbackEnabled
self.updateControllerSkin()
} }
func updateControllerSkin() func updateControllerSkin()
{ {
guard let game = self.game, let system = System(gameType: game.type), let window = self.view.window else { return } guard let game = self.game as? Game, let window = self.view.window else { return }
let traits = DeltaCore.ControllerSkin.Traits.defaults(for: window) let traits = DeltaCore.ControllerSkin.Traits.defaults(for: window)
let controllerSkin = Settings.preferredControllerSkin(for: system, traits: traits) if Settings.localControllerPlayerIndex != nil
self.controllerView.controllerSkin = controllerSkin {
let controllerSkin = Settings.preferredControllerSkin(for: game, traits: traits)
self.controllerView.controllerSkin = controllerSkin
}
else if let controllerSkin = DeltaCore.ControllerSkin.standardControllerSkin(for: game.type), controllerSkin.hasTouchScreen(for: traits)
{
var touchControllerSkin = TouchControllerSkin(controllerSkin: controllerSkin)
if UIApplication.shared.isExternalDisplayConnected
{
// Only show touch screen if external display is connected.
touchControllerSkin.screenPredicate = { $0.isTouchScreen }
}
if self.view.bounds.width > self.view.bounds.height
{
touchControllerSkin.screenLayoutAxis = .horizontal
}
else
{
touchControllerSkin.screenLayoutAxis = .vertical
}
self.controllerView.controllerSkin = touchControllerSkin
}
self.view.setNeedsUpdateConstraints() self.updateExternalDisplay()
self.view.setNeedsLayout()
}
func updateGameViews()
{
if UIApplication.shared.isExternalDisplayConnected
{
// AirPlaying, hide all (non-touch) screens.
if let traits = self.controllerView.controllerSkinTraits, let screens = self.controllerView.controllerSkin?.screens(for: traits)
{
for (screen, gameView) in zip(screens, self.gameViews)
{
gameView.isEnabled = screen.isTouchScreen
gameView.isHidden = !screen.isTouchScreen
}
}
else
{
// Either self.controllerView.controllerSkin is `nil`, or it doesn't support these traits.
// Most likely this system only has 1 screen, so just hide self.gameView.
self.gameView.isEnabled = false
self.gameView.isHidden = true
}
}
else
{
// Not AirPlaying, show all screens.
for gameView in self.gameViews
{
gameView.isEnabled = true
gameView.isHidden = false
}
}
} }
} }
@ -581,23 +757,30 @@ private extension GameViewController
let game = context.object(with: game.objectID) as! Game let game = context.object(with: game.objectID) as! Game
let hash = try RSTHasher.sha1HashOfFile(at: game.gameSaveURL) let hash = try RSTHasher.sha1HashOfFile(at: game.gameSaveURL)
let previousHash = game.gameSaveURL.extendedAttribute(name: "com.rileytestut.delta.sha1Hash") let previousHash = game.gameSave?.sha1
guard hash != previousHash else { return } guard hash != previousHash else { return }
if let gameSave = game.gameSave if let gameSave = game.gameSave
{ {
gameSave.modifiedDate = Date() gameSave.modifiedDate = Date()
gameSave.sha1 = hash
} }
else else
{ {
let gameSave = GameSave(context: context) let gameSave = GameSave(context: context)
gameSave.identifier = game.identifier gameSave.identifier = game.identifier
gameSave.sha1 = hash
game.gameSave = gameSave game.gameSave = gameSave
} }
try context.save() try context.save()
try game.gameSaveURL.setExtendedAttribute(name: "com.rileytestut.delta.sha1Hash", value: hash)
if ExperimentalFeatures.shared.toastNotifications.gameSaveEnabled
{
self.presentExperimentalToastView(NSLocalizedString("Game Data Saved", comment: ""))
}
} }
catch CocoaError.fileNoSuchFile catch CocoaError.fileNoSuchFile
{ {
@ -620,6 +803,8 @@ extension GameViewController: SaveStatesViewControllerDelegate
// Ensures game is non-nil and also a Game subclass // Ensures game is non-nil and also a Game subclass
guard let game = self.game as? Game else { return } guard let game = self.game as? Game else { return }
guard let emulatorCore = self.emulatorCore, emulatorCore.state != .stopped else { return }
// If pausedSaveState exists and has already been saved, don't update auto save state // If pausedSaveState exists and has already been saved, don't update auto save state
// This prevents us from filling our auto save state slots with the same save state // This prevents us from filling our auto save state slots with the same save state
let savedPausedSaveState = self.pausedSaveState?.isSaved ?? false let savedPausedSaveState = self.pausedSaveState?.isSaved ?? false
@ -699,7 +884,7 @@ extension GameViewController: SaveStatesViewControllerDelegate
self.emulatorCore?.saveSaveState(to: saveState.fileURL) self.emulatorCore?.saveSaveState(to: saveState.fileURL)
} }
if let snapshot = self.gameView.snapshot(), let data = snapshot.pngData() if let snapshot = self.emulatorCore?.videoManager.snapshot(), let data = snapshot.pngData()
{ {
do do
{ {
@ -712,6 +897,13 @@ extension GameViewController: SaveStatesViewControllerDelegate
} }
saveState.modifiedDate = Date() saveState.modifiedDate = Date()
saveState.coreIdentifier = self.emulatorCore?.deltaCore.identifier
if ExperimentalFeatures.shared.toastNotifications.stateSaveEnabled,
saveState.type != .auto
{
self.presentExperimentalToastView(NSLocalizedString("Saved Save State", comment: ""))
}
if isRunning if isRunning
{ {
@ -760,6 +952,11 @@ extension GameViewController: SaveStatesViewControllerDelegate
{ {
try self.emulatorCore?.load(saveState) try self.emulatorCore?.load(saveState)
} }
if ExperimentalFeatures.shared.toastNotifications.stateLoadEnabled
{
self.presentExperimentalToastView(NSLocalizedString("Loaded Save State", comment: ""))
}
} }
catch EmulatorCore.SaveStateError.doesNotExist catch EmulatorCore.SaveStateError.doesNotExist
{ {
@ -817,6 +1014,16 @@ extension GameViewController: CheatsViewControllerDelegate
} }
} }
//MARK: - Audio -
/// Audio
private extension GameViewController
{
func updateAudio()
{
self.emulatorCore?.audioManager.respectsSilentMode = Settings.respectSilentMode
}
}
//MARK: - Sustain Buttons - //MARK: - Sustain Buttons -
private extension GameViewController private extension GameViewController
{ {
@ -837,6 +1044,8 @@ private extension GameViewController
UIView.animate(withDuration: 0.4) { UIView.animate(withDuration: 0.4) {
self.sustainButtonsBlurView.effect = blurEffect self.sustainButtonsBlurView.effect = blurEffect
self.sustainButtonsBackgroundView.alpha = 1.0 self.sustainButtonsBackgroundView.alpha = 1.0
} completion: { _ in
self.controllerView.becomeFirstResponder()
} }
} }
@ -932,13 +1141,190 @@ extension GameViewController
if activate if activate
{ {
emulatorCore.rate = emulatorCore.deltaCore.supportedRates.upperBound if ExperimentalFeatures.shared.variableFastForward.isEnabled,
let preferredSpeed = ExperimentalFeatures.shared.variableFastForward[emulatorCore.game.type],
(preferredSpeed.rawValue <= emulatorCore.deltaCore.supportedRates.upperBound || ExperimentalFeatures.shared.variableFastForward.allowUnrestrictedSpeeds)
{
emulatorCore.rate = preferredSpeed.rawValue
}
else
{
emulatorCore.rate = emulatorCore.deltaCore.supportedRates.upperBound
}
if ExperimentalFeatures.shared.toastNotifications.fastForwardEnabled
{
self.presentExperimentalToastView(NSLocalizedString("Fast Forward Enabled", comment: ""))
}
} }
else else
{ {
emulatorCore.rate = emulatorCore.deltaCore.supportedRates.lowerBound emulatorCore.rate = emulatorCore.deltaCore.supportedRates.lowerBound
if ExperimentalFeatures.shared.toastNotifications.fastForwardEnabled
{
self.presentExperimentalToastView(NSLocalizedString("Fast Forward Disabled", comment: ""))
}
} }
} }
func performScreenshotAction()
{
guard let snapshot = self.emulatorCore?.videoManager.snapshot() else { return }
let imageScale = ExperimentalFeatures.shared.gameScreenshots.size?.rawValue ?? 1.0
let imageSize = CGSize(width: snapshot.size.width * imageScale, height: snapshot.size.height * imageScale)
let screenshotData: Data
if imageScale == 1, let data = snapshot.pngData()
{
// No need to redraw image because it's already the correct size.
screenshotData = data
}
else
{
let format = UIGraphicsImageRendererFormat()
format.scale = 1
let renderer = UIGraphicsImageRenderer(size: imageSize, format: format)
screenshotData = renderer.pngData { (context) in
context.cgContext.interpolationQuality = .none
snapshot.draw(in: CGRect(origin: .zero, size: imageSize))
}
}
if ExperimentalFeatures.shared.gameScreenshots.saveToPhotos
{
PHPhotoLibrary.runIfAuthorized
{
PHPhotoLibrary.saveImageData(screenshotData)
}
}
if ExperimentalFeatures.shared.gameScreenshots.saveToFiles
{
let screenshotsDirectory = FileManager.default.documentsDirectory.appendingPathComponent("Screenshots")
do
{
try FileManager.default.createDirectory(at: screenshotsDirectory, withIntermediateDirectories: true, attributes: nil)
}
catch
{
print(error)
}
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd_HH-mm-ss"
let fileName: URL
if let game = self.game as? Game
{
let filename = game.name + "_" + dateFormatter.string(from: date) + ".png"
fileName = screenshotsDirectory.appendingPathComponent(filename)
}
else
{
fileName = screenshotsDirectory.appendingPathComponent(dateFormatter.string(from: date) + ".png")
}
do
{
try screenshotData.write(to: fileName)
}
catch
{
print(error)
}
}
self.pauseViewController?.screenshotItem?.isSelected = false
}
}
private extension GameViewController
{
func connectExternalDisplay(for scene: ExternalDisplayScene)
{
// We need to receive gameViewController(_:didUpdateGameViews) callback.
scene.gameViewController.delegate = self
self.updateControllerSkin()
// Implicitly called from updateControllerSkin()
// self.updateExternalDisplay()
}
func updateExternalDisplay()
{
guard let scene = UIApplication.shared.externalDisplayScene else { return }
if scene.game?.fileURL != self.game?.fileURL
{
scene.game = self.game
}
var controllerSkin: ControllerSkinProtocol?
if let game = self.game, let traits = scene.gameViewController.controllerView.controllerSkinTraits
{
if ExperimentalFeatures.shared.airPlaySkins.isEnabled,
let preferredControllerSkin = ExperimentalFeatures.shared.airPlaySkins.preferredAirPlayControllerSkin(for: game.type), preferredControllerSkin.supports(traits)
{
// Use preferredControllerSkin directly.
controllerSkin = preferredControllerSkin
}
else if let standardSkin = DeltaCore.ControllerSkin.standardControllerSkin(for: game.type), standardSkin.supports(traits)
{
if standardSkin.hasTouchScreen(for: traits)
{
// Only use TouchControllerSkin for standard controller skins with touch screens.
var touchControllerSkin = DeltaCore.TouchControllerSkin(controllerSkin: standardSkin)
touchControllerSkin.screenLayoutAxis = Settings.features.dsAirPlay.layoutAxis
if Settings.features.dsAirPlay.topScreenOnly
{
touchControllerSkin.screenPredicate = { !$0.isTouchScreen }
}
controllerSkin = touchControllerSkin
}
else
{
controllerSkin = standardSkin
}
}
}
scene.gameViewController.controllerView.controllerSkin = controllerSkin
// Implicitly called when assigning controllerSkin.
// self.updateExternalDisplayGameViews()
}
func updateExternalDisplayGameViews()
{
guard let scene = UIApplication.shared.externalDisplayScene, let emulatorCore = self.emulatorCore else { return }
for gameView in scene.gameViewController.gameViews
{
emulatorCore.add(gameView)
}
}
func disconnectExternalDisplay(for scene: ExternalDisplayScene)
{
scene.gameViewController.delegate = nil
for gameView in scene.gameViewController.gameViews
{
self.emulatorCore?.remove(gameView)
}
self.updateControllerSkin() // Reset TouchControllerSkin + GameViews
}
} }
//MARK: - GameViewControllerDelegate - //MARK: - GameViewControllerDelegate -
@ -947,6 +1333,8 @@ extension GameViewController: GameViewControllerDelegate
{ {
func gameViewController(_ gameViewController: DeltaCore.GameViewController, handleMenuInputFrom gameController: GameController) func gameViewController(_ gameViewController: DeltaCore.GameViewController, handleMenuInputFrom gameController: GameController)
{ {
guard gameViewController == self else { return }
if let pausingGameController = self.pausingGameController if let pausingGameController = self.pausingGameController
{ {
guard pausingGameController == gameController else { return } guard pausingGameController == gameController else { return }
@ -964,12 +1352,16 @@ extension GameViewController: GameViewControllerDelegate
else if self.presentedViewController == nil else if self.presentedViewController == nil
{ {
self.pauseEmulation() self.pauseEmulation()
self.controllerView.resignFirstResponder()
self.performSegue(withIdentifier: "pause", sender: gameController) self.performSegue(withIdentifier: "pause", sender: gameController)
} }
} }
func gameViewControllerShouldResumeEmulation(_ gameViewController: DeltaCore.GameViewController) -> Bool func gameViewControllerShouldResumeEmulation(_ gameViewController: DeltaCore.GameViewController) -> Bool
{ {
guard gameViewController == self else { return false }
var result = false var result = false
rst_dispatch_sync_on_main_thread { rst_dispatch_sync_on_main_thread {
@ -978,6 +1370,72 @@ extension GameViewController: GameViewControllerDelegate
return result return result
} }
func gameViewController(_ gameViewController: DeltaCore.GameViewController, didUpdateGameViews gameViews: [GameView])
{
// gameViewController could be `self` or ExternalDisplayScene.gameViewController.
if gameViewController == self
{
self.updateGameViews()
}
else
{
self.updateExternalDisplayGameViews()
}
}
}
private extension GameViewController
{
func show(_ toastView: RSTToastView, duration: TimeInterval = 3.0)
{
toastView.textLabel.textAlignment = .center
toastView.presentationEdge = .top
toastView.show(in: self.view, duration: duration)
}
func showJITEnabledAlert()
{
guard !self.presentedJITAlert, self.presentedViewController == nil, self.game != nil else { return }
self.presentedJITAlert = true
func presentToastView()
{
let detailText: String?
let duration: TimeInterval
if UserDefaults.standard.jitEnabledAlertCount < 3
{
detailText = NSLocalizedString("You can now Fast Forward DS games up to 3x speed.", comment: "")
duration = 5.0
}
else
{
detailText = nil
duration = 2.0
}
let toastView = RSTToastView(text: NSLocalizedString("JIT Compilation Enabled", comment: ""), detailText: detailText)
toastView.edgeOffset.vertical = 8
self.show(toastView, duration: duration)
UserDefaults.standard.jitEnabledAlertCount += 1
}
DispatchQueue.main.async {
if let transitionCoordinator = self.transitionCoordinator
{
transitionCoordinator.animate(alongsideTransition: nil) { (context) in
presentToastView()
}
}
else
{
presentToastView()
}
}
}
} }
//MARK: - Notifications - //MARK: - Notifications -
@ -1020,9 +1478,24 @@ private extension GameViewController
self.updateControllerSkin() self.updateControllerSkin()
} }
case .translucentControllerSkinOpacity: self.controllerView.translucentControllerSkinOpacity = Settings.translucentControllerSkinOpacity case .translucentControllerSkinOpacity:
self.controllerView.translucentControllerSkinOpacity = Settings.translucentControllerSkinOpacity
case .syncingService: break case .respectSilentMode:
self.updateAudio()
case .syncingService, .isAltJITEnabled: break
case Settings.features.dsAirPlay.$topScreenOnly.settingsKey: fallthrough
case Settings.features.dsAirPlay.$layoutAxis.settingsKey:
self.updateExternalDisplay()
case ExperimentalFeatures.shared.airPlaySkins.settingsKey: fallthrough
case _ where settingsName.rawValue.hasPrefix(ExperimentalFeatures.shared.airPlaySkins.settingsKey.rawValue):
// Update whenever any of the AirPlay skins have changed.
self.updateExternalDisplay()
default: break
} }
} }
@ -1078,16 +1551,7 @@ private extension GameViewController
func presentToastView() func presentToastView()
{ {
let toastView = RSTToastView(text: NSLocalizedString("Autorotation Disabled", comment: ""), detailText: NSLocalizedString("Pause game to change orientation.", comment: "")) let toastView = RSTToastView(text: NSLocalizedString("Autorotation Disabled", comment: ""), detailText: NSLocalizedString("Pause game to change orientation.", comment: ""))
toastView.textLabel.textAlignment = .center self.show(toastView)
toastView.presentationEdge = .bottom
if let traits = self.controllerView.controllerSkinTraits, traits.orientation == .landscape, self.controllerView?.controllerSkin?.gameScreenFrame(for: traits) == nil
{
// Only change landscape vertical offset if there is no custom game screen frame for the current controller skin.
toastView.edgeOffset.vertical = 30
}
toastView.show(in: self.gameView, duration: 3.0)
} }
DispatchQueue.main.async { DispatchQueue.main.async {
@ -1108,4 +1572,97 @@ private extension GameViewController
{ {
self.isGyroActive = false self.isGyroActive = false
} }
@objc func didEnableJIT(with notification: Notification)
{
DispatchQueue.main.async {
self.showJITEnabledAlert()
}
DispatchQueue.global(qos: .utility).async {
guard let emulatorCore = self.emulatorCore, let emulatorBridge = emulatorCore.deltaCore.emulatorBridge as? MelonDSEmulatorBridge, !emulatorBridge.isJITEnabled
else { return }
guard emulatorCore.state != .stopped else {
// Emulator core is not running, which means we can set
// isJITEnabled to true without resetting the core.
emulatorBridge.isJITEnabled = true
return
}
let isVideoEnabled = emulatorCore.videoManager.isEnabled
emulatorCore.videoManager.isEnabled = false
let isRunning = (emulatorCore.state == .running)
if isRunning
{
self.pauseEmulation()
}
let temporaryFileURL = FileManager.default.uniqueTemporaryURL()
let saveState = emulatorCore.saveSaveState(to: temporaryFileURL)
emulatorCore.stop()
emulatorBridge.isJITEnabled = true
emulatorCore.start()
emulatorCore.pause()
do
{
try emulatorCore.load(saveState)
}
catch
{
print("Failed to load save state after enabling JIT.", error)
}
if isRunning
{
self.resumeEmulation()
}
emulatorCore.videoManager.isEnabled = isVideoEnabled
}
}
@objc func emulationDidQuit(with notification: Notification)
{
DispatchQueue.main.async {
guard self.presentedViewController == nil else { return }
// Wait for emulation to stop completely before performing segue.
var token: NSKeyValueObservation?
token = self.emulatorCore?.observe(\.state, options: [.initial]) { (emulatorCore, change) in
guard emulatorCore.state == .stopped else { return }
DispatchQueue.main.async {
self.game = nil
self.performSegue(withIdentifier: "showGamesViewController", sender: nil)
}
token?.invalidate()
}
}
}
@objc func sceneWillConnect(with notification: Notification)
{
guard let scene = notification.object as? ExternalDisplayScene else { return }
self.connectExternalDisplay(for: scene)
}
@objc func sceneDidDisconnect(with notification: Notification)
{
guard let scene = notification.object as? ExternalDisplayScene else { return }
self.disconnectExternalDisplay(for: scene)
}
}
private extension UserDefaults
{
@NSManaged var desmumeDeprecatedAlertCount: Int
@NSManaged var jitEnabledAlertCount: Int
} }

View File

@ -15,19 +15,31 @@ private var kvoContext = 0
class PreviewGameViewController: DeltaCore.GameViewController class PreviewGameViewController: DeltaCore.GameViewController
{ {
// If non-nil, will override the default preview action items returned in previewActionItems() // If non-nil, will override the default preview action items returned in previewActionItems()
// nilpreviewActionItems()
var overridePreviewActionItems: [UIPreviewActionItem]? var overridePreviewActionItems: [UIPreviewActionItem]?
// Save state to be loaded upon preview // Save state to be loaded upon preview
//
var previewSaveState: SaveStateProtocol? var previewSaveState: SaveStateProtocol?
// Initial image to be shown while loading // Initial image to be shown while loading
//
var previewImage: UIImage? { var previewImage: UIImage? {
didSet { didSet {
self.updatePreviewImage() self.updatePreviewImage()
} }
} }
var isLivePreview: Bool = true
private var emulatorCoreQueue = DispatchQueue(label: "com.rileytestut.Delta.PreviewGameViewController.emulatorCoreQueue", qos: .userInitiated) private var emulatorCoreQueue = DispatchQueue(label: "com.rileytestut.Delta.PreviewGameViewController.emulatorCoreQueue", qos: .userInitiated)
private var copiedSaveFiles = [(originalURL: URL, copyURL: URL)]()
private lazy var temporaryDirectoryURL: URL = {
let directoryURL = FileManager.default.temporaryDirectory.appendingPathComponent("preview-" + UUID().uuidString)
try? FileManager.default.createDirectory(at: directoryURL, withIntermediateDirectories: true, attributes: nil)
return directoryURL
}()
override var game: GameProtocol? { override var game: GameProtocol? {
willSet { willSet {
@ -41,7 +53,8 @@ class PreviewGameViewController: DeltaCore.GameViewController
emulatorCore.addObserver(self, forKeyPath: #keyPath(EmulatorCore.state), options: [.old], context: &kvoContext) emulatorCore.addObserver(self, forKeyPath: #keyPath(EmulatorCore.state), options: [.old], context: &kvoContext)
self.preferredContentSize = emulatorCore.preferredRenderingSize let size = CGSize(width: emulatorCore.preferredRenderingSize.width * 2.0, height: emulatorCore.preferredRenderingSize.height * 2.0)
self.preferredContentSize = size
} }
} }
@ -50,8 +63,28 @@ class PreviewGameViewController: DeltaCore.GameViewController
return previewActionItems return previewActionItems
} }
public required init()
{
super.init()
self.delegate = self
}
public required init?(coder aDecoder: NSCoder)
{
super.init(coder: aDecoder)
self.delegate = self
}
deinit deinit
{ {
// Explicitly stop emulatorCore _before_ we remove ourselves as observer
// so we can wait until stopped before restoring save files (again).
// emulatorCore
//
self.emulatorCore?.stop()
self.emulatorCore?.removeObserver(self, forKeyPath: #keyPath(EmulatorCore.state), context: &kvoContext) self.emulatorCore?.removeObserver(self, forKeyPath: #keyPath(EmulatorCore.state), context: &kvoContext)
} }
} }
@ -65,17 +98,26 @@ extension PreviewGameViewController
super.viewDidLoad() super.viewDidLoad()
self.controllerView.isHidden = true self.controllerView.isHidden = true
self.controllerView.controllerSkin = nil // Skip loading controller skin from disk, which may be slow.
// Temporarily prevent emulatorCore from updating gameView to prevent flicker of black, or other visual glitches // Temporarily prevent emulatorCore from updating gameView to prevent flicker of black, or other visual glitches
// emulatorCore gameView
self.emulatorCore?.remove(self.gameView) self.emulatorCore?.remove(self.gameView)
} }
override func viewWillAppear(_ animated: Bool)
{
super.viewWillAppear(animated)
self.copySaveFiles()
}
override func viewDidAppear(_ animated: Bool) override func viewDidAppear(_ animated: Bool)
{ {
super.viewDidAppear(animated) super.viewDidAppear(animated)
self.emulatorCoreQueue.async { self.emulatorCoreQueue.async {
self.emulatorCore?.resume() self.startEmulation()
} }
} }
@ -84,14 +126,33 @@ extension PreviewGameViewController
super.viewWillDisappear(animated) super.viewWillDisappear(animated)
// Pause in viewWillDisappear and not viewDidDisappear like DeltaCore.GameViewController so the audio cuts off earlier if being dismissed // Pause in viewWillDisappear and not viewDidDisappear like DeltaCore.GameViewController so the audio cuts off earlier if being dismissed
// viewWillDisappear DeltaCore.GameViewController viewDidDisappear
self.emulatorCore?.pause() self.emulatorCore?.pause()
} }
override func viewDidDisappear(_ animated: Bool)
{
super.viewDidDisappear(animated)
// Already stopped = we've already restored save files and removed directory.
// =
if self.emulatorCore?.state != .stopped
{
// Pre-emptively restore save files in case something goes wrong while stopping emulation.
// This also ensures if the core is never stopped (for some reason), saves are still restored.
// 仿
//
self.restoreSaveFiles(removeCopyDirectory: false)
}
}
override func viewDidLayoutSubviews() override func viewDidLayoutSubviews()
{ {
super.viewDidLayoutSubviews() super.viewDidLayoutSubviews()
// Need to update in viewDidLayoutSubviews() to ensure bounds of gameView are not CGRect.zero // Need to update in viewDidLayoutSubviews() to ensure bounds of gameView are not CGRect.zero
// viewDidLayoutSubviews() gameView CGRect.zero
self.updatePreviewImage() self.updatePreviewImage()
} }
@ -99,6 +160,7 @@ extension PreviewGameViewController
{ {
super.didReceiveMemoryWarning() super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated. // Dispose of any resources that can be recreated.
//
} }
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?)
@ -111,17 +173,24 @@ extension PreviewGameViewController
let state = self.emulatorCore?.state let state = self.emulatorCore?.state
else { return } else { return }
if previousState == .stopped, state == .running switch state
{ {
self.emulatorCoreQueue.sync { case .running where previousState == .stopped:
if self.isAppearing self.emulatorCoreQueue.async {
{ // Pause to prevent it from starting before visible (in case user peeked slowly)
// Pause to prevent it from starting before visible (in case user peeked slowly) //
self.emulatorCore?.pause() self.emulatorCore?.pause()
}
self.preparePreview() self.preparePreview()
} }
case .stopped:
// Emulation has stopped, so we can safely restore save files,
// and also remove the directory they were copied to.
//
//
self.restoreSaveFiles(removeCopyDirectory: true)
default: break
} }
} }
} }
@ -171,6 +240,69 @@ private extension PreviewGameViewController
self.emulatorCore?.updateCheats() self.emulatorCore?.updateCheats()
// Re-enable emulatorCore to update gameView again // Re-enable emulatorCore to update gameView again
// emulatorCoregameView
self.emulatorCore?.add(self.gameView) self.emulatorCore?.add(self.gameView)
self.emulatorCore?.resume()
}
func copySaveFiles()
{
guard let game = self.game as? Game, let gameSave = game.gameSave else { return }
self.copiedSaveFiles.removeAll()
let fileURLs = gameSave.syncableFiles.lazy.map { $0.fileURL }
for fileURL in fileURLs
{
do
{
let destinationURL = self.temporaryDirectoryURL.appendingPathComponent(fileURL.lastPathComponent)
try FileManager.default.copyItem(at: fileURL, to: destinationURL, shouldReplace: true)
self.copiedSaveFiles.append((fileURL, destinationURL))
print("Copied save file:", fileURL.lastPathComponent)
}
catch
{
print("Failed to back up save file \(fileURL.lastPathComponent).", error)
}
}
}
func restoreSaveFiles(removeCopyDirectory: Bool)
{
for (originalURL, copyURL) in self.copiedSaveFiles
{
do
{
try FileManager.default.copyItem(at: copyURL, to: originalURL, shouldReplace: true)
print("Restored save file:", originalURL.lastPathComponent)
}
catch
{
print("Failed to restore copied save file \(copyURL.lastPathComponent).", error)
}
}
if removeCopyDirectory
{
do
{
try FileManager.default.removeItem(at: self.temporaryDirectoryURL)
}
catch
{
print("Failed to remove preview temporary directory.", error)
}
}
}
}
extension PreviewGameViewController: GameViewControllerDelegate
{
func gameViewControllerShouldResumeEmulation(_ gameViewController: DeltaCore.GameViewController) -> Bool
{
return self.isLivePreview
} }
} }

View File

@ -0,0 +1,53 @@
//
// ExperimentalFeatures.swift
// Delta
//
// Created by Riley Testut on 4/6/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import DeltaFeatures
struct ExperimentalFeatures: FeatureContainer
{
static let shared = ExperimentalFeatures()
@Feature(name: "AirPlay Skins",
description: "Customize the appearance of games when AirPlaying to your TV.",
options: AirPlaySkinsOptions())
var airPlaySkins
@Feature(name: "Variable Fast Forward",
description: "Change the preferred Fast Foward speed per-system. You can also change it by long-pressing the Fast Forward button from the Pause Menu.",
options: VariableFastForwardOptions())
var variableFastForward
@Feature(name: "Show Status Bar",
description: "Enable to show the Status Bar during gameplay.")
var showStatusBar
@Feature(name: "Game Screenshots",
description: "When enabled, a Screenshot button will appear in the Pause Menu, allowing you to save a screenshot of your game. You can choose to save the screenshot to Photos or Files.",
options: GameScreenshotsOptions())
var gameScreenshots
@Feature(name: "Toast Notifications",
description: "Show toast notifications as a confirmation for various actions, such as saving your game or loading a save state.",
options: ToastNotificationOptions())
var toastNotifications
@Feature(name: "Review Save States",
description: "Review recent Save States to make sure they are associated with the correct game.",
options: ReviewSaveStatesOptions())
var reviewSaveStates
@Feature(name: "Alternate App Icon",
description: "Change the app icon.",
options: AlternateAppIconOptions())
var alternateAppIcons
private init()
{
self.prepareFeatures()
}
}

View File

@ -0,0 +1,167 @@
//
// AirPlaySkins.swift
// Delta
//
// Created by Riley Testut on 4/20/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import SwiftUI
import DeltaFeatures
import DeltaCore
extension Feature where Options == AirPlaySkinsOptions
{
func preferredAirPlayControllerSkin(for gameType: GameType) -> ControllerSkin?
{
guard let identifier = self[gameType] else { return nil }
let predicate = NSPredicate(format: "%K == %@", #keyPath(ControllerSkin.identifier), identifier)
let controllerSkin = ControllerSkin.instancesWithPredicate(predicate, inManagedObjectContext: DatabaseManager.shared.viewContext, type: ControllerSkin.self).first
return controllerSkin
}
}
struct AirPlaySkinsOptions
{
@Option(name: "Manage Skins", detailView: { _ in SkinManager() })
private var skinManager: String = "" // Hack until I figure out how to support Void properties...
@Option(name: LocalizedStringKey(System.nes.localizedName), description: "The controller skin used when AirPlaying NES games.", detailView: { SkinPicker(gameType: .nes, controllerSkinID: $0) })
var nes: String?
@Option(name: LocalizedStringKey(System.snes.localizedName), description: "The controller skin used when AirPlaying SNES games.", detailView: { SkinPicker(gameType: .snes, controllerSkinID: $0) })
var snes: String?
@Option(name: LocalizedStringKey(System.genesis.localizedName), description: "The controller skin used when AirPlaying Genesis games.", detailView: { SkinPicker(gameType: .genesis, controllerSkinID: $0) })
var genesis: String?
@Option(name: LocalizedStringKey(System.n64.localizedName), description: "The controller skin used when AirPlaying N64 games.", detailView: { SkinPicker(gameType: .n64, controllerSkinID: $0) })
var n64: String?
@Option(name: LocalizedStringKey(System.gbc.localizedName), description: "The controller skin used when AirPlaying GBC games.", detailView: { SkinPicker(gameType: .gbc, controllerSkinID: $0) })
var gbc: String?
@Option(name: LocalizedStringKey(System.gba.localizedName), description: "The controller skin used when AirPlaying GBA games.", detailView: { SkinPicker(gameType: .gba, controllerSkinID: $0) })
var gba: String?
@Option(name: LocalizedStringKey(System.ds.localizedName), description: "The controller skin used when AirPlaying DS games.", detailView: { SkinPicker(gameType: .ds, controllerSkinID: $0) })
var ds: String?
subscript(gameType: GameType) -> String? {
guard let system = System(gameType: gameType) else { return nil }
switch system
{
case .nes: return self.nes
case .snes: return self.snes
case .genesis: return self.genesis
case .n64: return self.n64
case .gbc: return self.gbc
case .gba: return self.gba
case .ds: return self.ds
}
}
}
fileprivate extension AirPlaySkinsOptions
{
struct SkinPicker: View
{
let gameType: GameType
@Binding
var controllerSkinID: String?
@FetchRequest
private var controllerSkins: FetchedResults<ControllerSkin>
@Environment(\.featureOption)
private var option
var body: some View {
Picker(option.name ?? "", selection: $controllerSkinID) {
ForEach(controllerSkins, id: \.identifier) { controllerSkin in
Text(controllerSkin.name)
.tag(Optional<String>(controllerSkin.identifier)) // Must be Optional<String> in order for selection to work.
// .tag(controllerSkin.identifier)
}
Text("None")
.tag(String?.none)
}
.pickerStyle(.menu)
.displayInline()
}
init(gameType: GameType, controllerSkinID: Binding<String?>)
{
self.gameType = gameType
self._controllerSkinID = controllerSkinID
let configuration = ControllerSkinConfigurations.tvStandardLandscape
let predicate = NSPredicate(format: "%K == %@ AND (%K & %d) != 0 AND %K == NO",
#keyPath(ControllerSkin.gameType), self.gameType.rawValue,
#keyPath(ControllerSkin.supportedConfigurations), configuration.rawValue,
#keyPath(ControllerSkin.isStandard))
self._controllerSkins = FetchRequest(entity: ControllerSkin.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \ControllerSkin.name, ascending: true)], predicate: predicate)
}
}
struct SkinManager: View
{
@FetchRequest(entity: ControllerSkin.entity(),
sortDescriptors: [NSSortDescriptor(keyPath: \ControllerSkin.name, ascending: true)],
predicate: {
let configuration = ControllerSkinConfigurations.tvStandardLandscape
return NSPredicate(format: "(%K & %d) != 0 AND %K == NO",
#keyPath(ControllerSkin.supportedConfigurations), configuration.rawValue,
#keyPath(ControllerSkin.isStandard))
}())
private var controllerSkins: FetchedResults<ControllerSkin>
var body: some View {
if controllerSkins.isEmpty
{
Text("No AirPlay Skins")
.foregroundColor(.gray)
}
else
{
List {
ForEach(controllerSkins, id: \.identifier) { controllerSkin in
HStack {
Text(controllerSkin.name)
Spacer()
if let system = System(gameType: controllerSkin.gameType)
{
Text(system.localizedShortName)
.foregroundColor(.gray)
}
}
}
.onDelete(perform: deleteAirPlaySkins)
}
}
}
private func deleteAirPlaySkins(at indexes: IndexSet)
{
let objectIDs = indexes.map { controllerSkins[$0].objectID }
DatabaseManager.shared.performBackgroundTask { context in
let controllerSkins = objectIDs.compactMap { context.object(with: $0) as? ControllerSkin }
for controllerSkin in controllerSkins
{
context.delete(controllerSkin)
}
context.saveWithErrorLogging()
}
}
}
}

View File

@ -0,0 +1,124 @@
//
// AlternateAppIcons.swift
// Delta
//
// Created by Chris Rittenhouse on 5/2/23.
// Copyright © 2023 LitRitt. All rights reserved.
//
import SwiftUI
import DeltaFeatures
enum AppIcon: String, CaseIterable, CustomStringConvertible, Identifiable
{
case normal = "Default"
case gba4ios = "GBA4iOS"
case inverted = "Inverted"
case pixelated = "Pixelated"
case skin = "Controller Skin"
var description: String {
return self.rawValue
}
var id: String {
return self.rawValue
}
var author: String {
switch self
{
case .normal: return "Caroline Moore"
case .gba4ios: return "Paul Thorsen"
case .inverted, .skin, .pixelated: return "LitRitt"
}
}
var assetName: String {
switch self
{
case .normal: return "AppIcon"
case .gba4ios: return "IconGBA4iOS"
case .inverted: return "IconInverted"
case .pixelated: return "IconPixelated"
case .skin: return "IconSkin"
}
}
}
extension AppIcon: Equatable
{
static func == (lhs: AppIcon, rhs: AppIcon) -> Bool
{
return lhs.description == rhs.description
}
}
extension AppIcon: LocalizedOptionValue
{
var localizedDescription: Text {
Text(self.description)
}
}
struct AlternateAppIconOptions
{
@Option(name: "Alternate App Icon",
description: "Choose from alternate app icons created by the community.",
detailView: { value in
List {
ForEach(AppIcon.allCases) { icon in
HStack {
if icon == value.wrappedValue
{
Text("")
}
icon.localizedDescription
Text("- by \(icon.author)")
.font(.system(size: 15))
.foregroundColor(.gray)
Spacer()
Image(uiImage: Bundle.appIcon(for: icon) ?? UIImage())
.cornerRadius(13)
}
.contentShape(Rectangle())
.onTapGesture {
value.wrappedValue = icon
}
}
}
.onChange(of: value.wrappedValue) { _ in
updateAppIcon()
}
.displayInline()
})
var icon: AppIcon = .normal
}
extension AlternateAppIconOptions
{
static func updateAppIcon()
{
// Get current icon
let currentIcon = UIApplication.shared.alternateIconName
// Apply chosen icon if feature is enabled
if ExperimentalFeatures.shared.alternateAppIcons.isEnabled
{
let icon = ExperimentalFeatures.shared.alternateAppIcons.icon
// Only apply new icon if it's not already the current icon
switch icon
{
case .normal: if currentIcon != nil { UIApplication.shared.setAlternateIconName(nil) } // Default app icon
default: if currentIcon != icon.assetName { UIApplication.shared.setAlternateIconName(icon.assetName) } // Alternate app icon
}
}
else
{
// Remove alternate icons if feature is disabled
if currentIcon != nil { UIApplication.shared.setAlternateIconName(nil) }
}
}
}

View File

@ -0,0 +1,54 @@
//
// GameScreenshots.swift
// Delta
//
// Created by Chris Rittenhouse on 4/24/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import SwiftUI
import DeltaFeatures
enum ScreenshotSize: Double, CaseIterable, CustomStringConvertible
{
case x5 = 5
case x4 = 4
case x3 = 3
case x2 = 2
var description: String {
if #available(iOS 15, *)
{
let formattedText = self.rawValue.formatted(.number.decimalSeparator(strategy: .automatic))
return "\(formattedText)x Size"
}
else
{
return "\(self.rawValue)x Size"
}
}
}
extension ScreenshotSize: LocalizedOptionValue
{
var localizedDescription: Text {
Text(self.description)
}
static var localizedNilDescription: Text {
Text("Original Size")
}
}
struct GameScreenshotsOptions
{
@Option(name: "Save to Files", description: "Save the screenshot to the app's directory in Files.")
var saveToFiles: Bool = true
@Option(name: "Save to Photos", description: "Save the screenshot to the Photo Library.")
var saveToPhotos: Bool = false
@Option(name: "Image Size", description: "Choose the size of screenshots. This only increases the export size, it does not increase the quality.", values: ScreenshotSize.allCases)
var size: ScreenshotSize?
}

View File

@ -0,0 +1,30 @@
//
// LinkSaveStatesOptions.swift
// Delta
//
// Created by Riley Testut on 8/7/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import SwiftUI
import DeltaFeatures
struct ReviewSaveStatesView: UIViewControllerRepresentable
{
func makeUIViewController(context: Context) -> ReviewSaveStatesViewController
{
let viewController = ReviewSaveStatesViewController()
return viewController
}
func updateUIViewController(_ uiViewController: ReviewSaveStatesViewController, context: Context)
{
}
}
struct ReviewSaveStatesOptions
{
@Option(name: "View Save States", detailView: { _ in ReviewSaveStatesView() })
private var reviewSaveStates: String = "" // Hack until I figure out how to support Void properties...
}

View File

@ -0,0 +1,38 @@
//
// ToastNotificationOptions.swift
// Delta
//
// Created by Chris Rittenhouse on 4/25/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import SwiftUI
import DeltaFeatures
struct ToastNotificationOptions
{
@Option(name: "Duration", description: "Change how long toasts should be shown.", detailView: { duration in
HStack {
Text("Duration: \(duration.wrappedValue, specifier: "%.1f")s")
Slider(value: duration, in: 1...5, step: 0.5).displayInline()
}
})
var duration: Double = 1.5
@Option(name: "Game Data Saved",
description: "Show toasts when performing an in game save.")
var gameSaveEnabled: Bool = true
@Option(name: "Saved Save State",
description: "Show toasts when saving a save state.")
var stateSaveEnabled: Bool = true
@Option(name: "Loaded Save State",
description: "Show toasts when loading a save state.")
var stateLoadEnabled: Bool = true
@Option(name: "Fast Forward Toggled",
description: "Show toasts when toggling fast forward.")
var fastForwardEnabled: Bool = true
}

View File

@ -0,0 +1,129 @@
//
// VariableFastForward.swift
// Delta
//
// Created by Riley Testut on 4/5/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import SwiftUI
import DeltaCore
import DeltaFeatures
struct FastForwardSpeed: RawRepresentable
{
let rawValue: Double
init(rawValue: Double)
{
self.rawValue = rawValue
}
static func speeds(in range: ClosedRange<Double>) -> [FastForwardSpeed]
{
var range = range
if ExperimentalFeatures.shared.variableFastForward.allowUnrestrictedSpeeds
{
range = 1.0...8.0
}
// .dropFirst() to remove 1x speed.
var speeds = stride(from: range.lowerBound, to: range.upperBound, by: 1.0).dropFirst().map { FastForwardSpeed(rawValue: $0) }
// Handles both integer and non-integer maximum speeds, because range.upperBound is not included in `speeds`.
speeds.append(.init(rawValue: range.upperBound))
return speeds
}
}
extension FastForwardSpeed: CustomStringConvertible, LocalizedOptionValue
{
var description: String {
if #available(iOS 15, *)
{
let formattedText = self.rawValue.formatted(.number.decimalSeparator(strategy: .automatic))
return "\(formattedText)x"
}
else
{
return "\(self.rawValue)x"
}
}
var localizedDescription: Text {
Text(self.description)
}
static var localizedNilDescription: Text {
Text("Maximum")
}
}
struct VariableFastForwardOptions
{
// Alternatively, this feature could be implemented with single hidden dictionary @Option mapping preferred speeds to systems,
// because we support changing these values by long-pressing the Fast Forward button in the pause menu.
// However, we want to also show these options in Delta's settings, which requires us to explicitly define them one-by-one.
//
// @Option // No name = hidden
// var preferredSpeedsBySystem: [String: Double] = [:]
@Option(name: "Nintendo", description: "Preferred NES fast forward speed.", values: FastForwardSpeed.speeds(in: System.nes.deltaCore.supportedRates))
var nes: FastForwardSpeed?
@Option(name: "Super Nintendo", description: "Preferred SNES fast forward speed.", values: FastForwardSpeed.speeds(in: System.snes.deltaCore.supportedRates))
var snes: FastForwardSpeed?
@Option(name: "Sega Genesis", description: "Preferred Genesis fast forward speed.", values: FastForwardSpeed.speeds(in: System.genesis.deltaCore.supportedRates))
var genesis: FastForwardSpeed?
@Option(name: "Nintendo 64", description: "Preferred N64 fast forward speed.", values: FastForwardSpeed.speeds(in: System.n64.deltaCore.supportedRates))
var n64: FastForwardSpeed?
@Option(name: "Game Boy Color", description: "Preferred GBC fast forward speed.", values: FastForwardSpeed.speeds(in: System.gbc.deltaCore.supportedRates))
var gbc: FastForwardSpeed?
@Option(name: "Game Boy Advance", description: "Preferred GBA fast forward speed.", values: FastForwardSpeed.speeds(in: System.gba.deltaCore.supportedRates))
var gba: FastForwardSpeed?
@Option(name: "Nintendo DS", description: "Preferred DS fast forward speed.", values: FastForwardSpeed.speeds(in: System.ds.deltaCore.supportedRates))
var ds: FastForwardSpeed?
@Option(name: "Allow Unrestricted Speeds", description: "Allow choosing speeds that exceed the maximum supported speed of a system.\n\nThis can be used to test the performance of new iOS devices.")
var allowUnrestrictedSpeeds: Bool = false
}
extension Feature where Options == VariableFastForwardOptions
{
subscript(gameType: GameType) -> FastForwardSpeed? {
get {
guard let system = System(gameType: gameType) else { return nil }
switch system
{
case .nes: return self.nes
case .snes: return self.snes
case .genesis: return self.genesis
case .n64: return self.n64
case .gbc: return self.gbc
case .gba: return self.gba
case .ds: return self.ds
}
}
set {
guard let system = System(gameType: gameType) else { return }
switch system
{
case .nes: self.nes = newValue
case .snes: self.snes = newValue
case .genesis: self.genesis = newValue
case .n64: self.n64 = newValue
case .gbc: self.gbc = newValue
case .gba: self.gba = newValue
case .ds: self.ds = newValue
}
}
}
}

View File

@ -0,0 +1,34 @@
//
// Bundle+AppIconImage.swift
// Delta
//
// Created by Chris Rittenhouse on 7/20/23.
// Copyright © 2023 LitRitt. All rights reserved.
//
import UIKit
extension Bundle
{
static func appIcon(for icon: AppIcon = .normal) -> UIImage? {
guard let appIcons = Bundle.main.infoDictionary?["CFBundleIcons"] as? [String: Any] else { return nil }
switch icon
{
case .normal:
guard let primaryAppIcon = appIcons["CFBundlePrimaryIcon"] as? [String: Any],
let appIconFiles = primaryAppIcon["CFBundleIconFiles"] as? [String],
let appIcon = appIconFiles.first else { return nil }
return UIImage(named:appIcon)
default:
guard let alternateAppIcons = appIcons["CFBundleAlternateIcons"] as? [String: Any],
let alternateAppIcon = alternateAppIcons[icon.assetName] as? [String: Any],
let appIconFiles = alternateAppIcon["CFBundleIconFiles"] as? [String],
let appIcon = appIconFiles.first else { return nil }
return UIImage(named:appIcon)
}
}
}

View File

@ -0,0 +1,22 @@
//
// CharacterSet+Filename.swift
// Delta
//
// Created by Riley Testut on 4/28/22.
// Copyright © 2022 Riley Testut. All rights reserved.
//
import Foundation
extension CharacterSet
{
// Different than .urlPathAllowed
// Copied from https://stackoverflow.com/a/39443252
static var urlFilenameAllowed: CharacterSet {
var illegalCharacters = CharacterSet(charactersIn: ":/")
illegalCharacters.formUnion(.newlines)
illegalCharacters.formUnion(.illegalCharacters)
illegalCharacters.formUnion(.controlCharacters)
return illegalCharacters.inverted
}
}

View File

@ -6,10 +6,24 @@
// Copyright © 2016 Riley Testut. All rights reserved. // Copyright © 2016 Riley Testut. All rights reserved.
// //
import UIKit
import DeltaCore import DeltaCore
extension ControllerSkin extension ControllerSkin
{ {
convenience init?(system: System, context: NSManagedObjectContext)
{
guard let deltaControllerSkin = DeltaCore.ControllerSkin.standardControllerSkin(for: system.gameType) else { return nil }
self.init(context: context)
self.isStandard = true
self.filename = deltaControllerSkin.fileURL.lastPathComponent
self.configure(with: deltaControllerSkin)
}
func configure(with skin: DeltaCore.ControllerSkin) func configure(with skin: DeltaCore.ControllerSkin)
{ {
// Manually copy values to be stored in database. // Manually copy values to be stored in database.
@ -20,21 +34,20 @@ extension ControllerSkin
var configurations = ControllerSkinConfigurations() var configurations = ControllerSkinConfigurations()
let device: DeltaCore.ControllerSkin.Device = (UIDevice.current.userInterfaceIdiom == .pad) ? .ipad : .iphone let allTraitCombinations = DeltaCore.ControllerSkin.Device.allCases.flatMap { device in
DeltaCore.ControllerSkin.DisplayType.allCases.flatMap { displayType in
let traitCollections: [(displayType: DeltaCore.ControllerSkin.DisplayType, orientation: DeltaCore.ControllerSkin.Orientation)] = DeltaCore.ControllerSkin.Orientation.allCases.map { orientation in
[(.standard, .portrait), (.standard, .landscape), (.edgeToEdge, .portrait), (.edgeToEdge, .landscape), (.splitView, .portrait), (.splitView, .landscape)] DeltaCore.ControllerSkin.Traits(device: device, displayType: displayType, orientation: orientation)
}
for collection in traitCollections
{
let traits = DeltaCore.ControllerSkin.Traits(device: device, displayType: collection.displayType, orientation: collection.orientation)
if skin.supports(traits)
{
let configuration = ControllerSkinConfigurations(traits: traits)
configurations.formUnion(configuration)
} }
} }
for traits in allTraitCombinations
{
guard let configuration = ControllerSkinConfigurations(traits: traits), skin.supports(traits) else { continue }
configurations.formUnion(configuration)
}
self.supportedConfigurations = configurations self.supportedConfigurations = configurations
} }
} }

View File

@ -1,26 +0,0 @@
//
// DeltaCoreProtocol+Delta.swift
// Delta
//
// Created by Riley Testut on 4/30/17.
// Copyright © 2017 Riley Testut. All rights reserved.
//
import DeltaCore
extension DeltaCoreProtocol
{
var supportedRates: ClosedRange<Double> {
guard let system = System(gameType: self.gameType) else { return 1...1 }
switch system
{
case .nes: return 1...4
case .snes: return 1...4
case .gbc: return 1...4
case .gba: return 1...3
case .n64: return 1...3
case .ds: return 1...1
}
}
}

View File

@ -0,0 +1,25 @@
//
// GameViewController+ExperimentalToasts.swift
// Delta
//
// Created by Chris Rittenhouse on 4/26/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import Roxas
extension GameViewController
{
func presentExperimentalToastView(_ text: String)
{
guard ExperimentalFeatures.shared.toastNotifications.isEnabled else { return }
DispatchQueue.main.async {
let toastView = RSTToastView(text: text, detailText: nil)
toastView.edgeOffset.vertical = 8
toastView.textLabel.textAlignment = .center
toastView.presentationEdge = .top
toastView.show(in: self.view, duration: ExperimentalFeatures.shared.toastNotifications.duration)
}
}
}

View File

@ -12,4 +12,8 @@ extension HarmonyMetadataKey
{ {
static let gameID = HarmonyMetadataKey("gameID") static let gameID = HarmonyMetadataKey("gameID")
static let gameName = HarmonyMetadataKey("gameName") static let gameName = HarmonyMetadataKey("gameName")
static let verifiedGameID = HarmonyMetadataKey("verifiedGameID")
// Backwards compatibility
static let coreID = HarmonyMetadataKey("coreID")
} }

View File

@ -124,6 +124,8 @@ extension Input
case .leftTrigger: return NSLocalizedString("L2", comment: "") case .leftTrigger: return NSLocalizedString("L2", comment: "")
case .rightShoulder: return NSLocalizedString("R1", comment: "") case .rightShoulder: return NSLocalizedString("R1", comment: "")
case .rightTrigger: return NSLocalizedString("R2", comment: "") case .rightTrigger: return NSLocalizedString("R2", comment: "")
case .start: return NSLocalizedString("Start", comment: "")
case .select: return NSLocalizedString("Select", comment: "")
} }
case .controller(.keyboard): case .controller(.keyboard):

View File

@ -23,4 +23,29 @@ extension NSManagedObjectContext
print("Error saving NSManagedObjectContext: ", error, error.userInfo) print("Error saving NSManagedObjectContext: ", error, error.userInfo)
} }
} }
// MARK: - Perform -
func performAndWait<T>(_ block: @escaping () -> T) -> T
{
var result: T! = nil
self.performAndWait {
result = block()
}
return result
}
func performAndWait<T>(_ block: @escaping () throws -> T) throws -> T
{
var result: Result<T, Error>! = nil
self.performAndWait {
result = Result { try block() }
}
let value = try result.get()
return value
}
} }

View File

@ -0,0 +1,38 @@
//
// OSLog+Delta.swift
// Delta
//
// Created by Riley Testut on 8/10/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import OSLog
extension OSLog.Category
{
static let database = "Database"
}
extension Logger
{
static let deltaSubsystem = "com.rileytestut.Delta"
static let database = Logger(subsystem: deltaSubsystem, category: OSLog.Category.database)
}
@available(iOS 15, *)
extension OSLogEntryLog.Level
{
var localizedName: String {
switch self
{
case .undefined: return NSLocalizedString("Undefined", comment: "")
case .debug: return NSLocalizedString("Debug", comment: "")
case .info: return NSLocalizedString("Info", comment: "")
case .notice: return NSLocalizedString("Notice", comment: "")
case .error: return NSLocalizedString("Error", comment: "")
case .fault: return NSLocalizedString("Fault", comment: "")
@unknown default: return NSLocalizedString("Unknown", comment: "")
}
}
}

View File

@ -0,0 +1,46 @@
//
// PHPhotoLibrary+Authorization.swift
// Delta
//
// Created by Chris Rittenhouse on 4/24/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import UIKit
import Photos
extension PHPhotoLibrary
{
static func runIfAuthorized(code: @escaping () -> Void)
{
PHPhotoLibrary.requestAuthorization(for: .addOnly, handler: { success in
switch success
{
case .authorized, .limited:
code()
case .denied, .restricted, .notDetermined: break
@unknown default: break
}
})
}
static func saveImageData(_ data: Data)
{
// Save the image to the Photos app
PHPhotoLibrary.shared().performChanges({
PHAssetCreationRequest.forAsset().addResource(with: .photo, data: data, options: nil)
}, completionHandler: { success, error in
if success
{
// Image saved successfully
print("Image saved to Photos app.")
}
else
{
// Error saving image
print("Error saving image: \(error?.localizedDescription ?? "Unknown error")")
}
})
}
}

View File

@ -0,0 +1,41 @@
//
// ProcessInfo+JIT.swift
// Delta
//
// Created by Riley Testut on 9/14/21.
// Copyright © 2021 Riley Testut. All rights reserved.
//
import UIKit
private let CS_OPS_STATUS: UInt32 = 0 /* OK */
private let CS_DEBUGGED: UInt32 = 0x10000000 /* Process is or has been attached to debugger. */
@_silgen_name("csops")
func csops(_ pid: pid_t, _ ops: UInt32, _ useraddr: UnsafeMutableRawPointer?, _ usersize: Int) -> Int
extension ProcessInfo
{
static var isJITDisabled = false
var isDebugging: Bool {
var flags: UInt32 = 0
let result = csops(getpid(), CS_OPS_STATUS, &flags, MemoryLayout<UInt32>.size)
let isDebugging = result == 0 && (flags & CS_DEBUGGED == CS_DEBUGGED)
return isDebugging
}
var isJITAvailable: Bool {
guard UIDevice.current.supportsJIT && !ProcessInfo.isJITDisabled else { return false }
let ios14_4 = OperatingSystemVersion(majorVersion: 14, minorVersion: 4, patchVersion: 0)
if #available(iOS 14.2, *), !ProcessInfo.processInfo.isOperatingSystemAtLeast(ios14_4)
{
// JIT is always available on supported devices running iOS 14.2 - 14.3.
return true
}
return self.isDebugging
}
}

View File

@ -0,0 +1,104 @@
//
// ServerManager+Delta.swift
// Delta
//
// Created by Riley Testut on 9/15/21.
// Copyright © 2021 Riley Testut. All rights reserved.
//
import AltKit
extension ServerManager
{
static let didEnableJITNotification = Notification.Name("didEnableJITNotification")
}
extension ServerManager
{
func prepare()
{
NotificationCenter.default.addObserver(self, selector: #selector(ServerManager.didChangeJITMode(_:)), name: Settings.didChangeNotification, object: nil)
#if DEBUG
if ProcessInfo.processInfo.isDebugging
{
// Debugger is attached at app launch, so we assume
// we're connected to Xcode for debugging purposes.
// In that case, we manually treat JIT as unavailable
// until AltServer is discovered to simulate real-world use.
ProcessInfo.isJITDisabled = true
}
#endif
self.start()
}
}
private extension ServerManager
{
func start()
{
guard Settings.isAltJITEnabled && !ProcessInfo.processInfo.isJITAvailable else { return }
self.startDiscovering()
self.autoconnect()
}
func autoconnect()
{
self.autoconnect { result in
switch result
{
case .failure(let error):
print("Could not auto-connect to server.", error)
self.autoconnect()
case .success(let connection):
func finish(result: Result<Void, Error>)
{
switch result
{
case .failure(ALTServerError.unknownRequest), .failure(ALTServerError.deviceNotFound):
// Try connecting to a different server.
self.autoconnect()
case .failure(let error):
print("Could not enable JIT compilation.", error)
case .success:
print("Successfully enabled JIT compilation!")
NotificationCenter.default.post(name: ServerManager.didEnableJITNotification, object: nil)
self.stopDiscovering()
}
connection.disconnect()
}
if ProcessInfo.isJITDisabled
{
ProcessInfo.isJITDisabled = false
finish(result: .success(()))
}
else
{
connection.enableUnsignedCodeExecution(completion: finish)
}
}
}
}
@objc func didChangeJITMode(_ notification: Notification)
{
guard let name = notification.userInfo?[Settings.NotificationUserInfoKey.name] as? Settings.Name, name == Settings.Name.isAltJITEnabled else { return }
if Settings.isAltJITEnabled
{
self.start()
}
else
{
self.stopDiscovering()
}
}
}

View File

@ -20,16 +20,6 @@ extension UIAlertController
class func alertController(for importType: ImportType, with errors: Set<DatabaseManager.ImportError>) -> UIAlertController class func alertController(for importType: ImportType, with errors: Set<DatabaseManager.ImportError>) -> UIAlertController
{ {
let title: String
switch importType
{
case .games: title = NSLocalizedString("Error Importing Games", comment: "")
case .controllerSkins: title = NSLocalizedString("Error Importing Controller Skins", comment: "")
}
let alertController = UIAlertController(title: title, message: nil, preferredStyle: .alert)
var urls = Set<URL>() var urls = Set<URL>()
for error in errors for error in errors
@ -44,38 +34,54 @@ extension UIAlertController
} }
} }
let filenames = urls.map{ $0.lastPathComponent }.sorted() let title: String
let message: String
if filenames.count > 0 if let fileURL = urls.first, let error = errors.first, errors.count == 1
{ {
var message: String title = String(format: NSLocalizedString("Could not import “%@”.", comment: ""), fileURL.lastPathComponent)
message = error.localizedDescription
switch importType
{
case .games: message = NSLocalizedString("The following game files could not be imported:", comment: "") + "\n"
case .controllerSkins: message = NSLocalizedString("The following controller skin files could not be imported:", comment: "") + "\n"
}
for filename in filenames
{
message += "\n" + filename
}
alertController.message = message
} }
else else
{ {
// This branch can be executed when there are no input URLs when importing, but there is an error saving the database anyway.
switch importType switch importType
{ {
case .games: alertController.message = NSLocalizedString("Delta was unable to import games. Please try again later.", comment: "") case .games: title = NSLocalizedString("Error Importing Games", comment: "")
case .controllerSkins: alertController.message = NSLocalizedString("Delta was unable to import controller skins. Please try again later.", comment: "") case .controllerSkins: title = NSLocalizedString("Error Importing Controller Skins", comment: "")
}
if urls.count > 0
{
var tempMessage: String
switch importType
{
case .games: tempMessage = NSLocalizedString("The following game files could not be imported:", comment: "") + "\n"
case .controllerSkins: tempMessage = NSLocalizedString("The following controller skin files could not be imported:", comment: "") + "\n"
}
let filenames = urls.map { $0.lastPathComponent }.sorted()
for filename in filenames
{
tempMessage += "\n" + filename
}
message = tempMessage
}
else
{
// This branch can be executed when there are no input URLs when importing, but there is an error saving the database anyway.
switch importType
{
case .games: message = NSLocalizedString("Delta was unable to import games. Please try again later.", comment: "")
case .controllerSkins: message = NSLocalizedString("Delta was unable to import controller skins. Please try again later.", comment: "")
}
} }
} }
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: RSTSystemLocalizedString("OK"), style: .cancel, handler: nil)) alertController.addAction(UIAlertAction(title: RSTSystemLocalizedString("OK"), style: .cancel, handler: nil))
return alertController return alertController
} }
} }

View File

@ -10,6 +10,6 @@ import UIKit
extension UIColor extension UIColor
{ {
static let deltaPurple = UIColor(named: "Purple")! static let deltaPurple = UIColor.purple
static let deltaDarkGray = UIColor(named: "DarkGray")! static let deltaDarkGray = #colorLiteral(red: 0.07139974087, green: 0.08217515796, blue: 0.1083263531, alpha: 1)
} }

View File

@ -8,12 +8,28 @@
import UIKit import UIKit
import ARKit import ARKit
import Metal
extension UIDevice extension UIDevice
{ {
private static var mtlDevice: MTLDevice? = MTLCreateSystemDefaultDevice()
var hasA9ProcessorOrBetter: Bool { var hasA9ProcessorOrBetter: Bool {
// ARKit is only supported by devices with an A9 processor or better, according to the documentation. // ARKit is only supported by devices with an A9 processor or better, according to the documentation.
// https://developer.apple.com/documentation/arkit/arconfiguration/2923553-issupported // https://developer.apple.com/documentation/arkit/arconfiguration/2923553-issupported
return ARConfiguration.isSupported return ARConfiguration.isSupported
} }
var hasA11ProcessorOrBetter: Bool {
guard let mtlDevice = UIDevice.mtlDevice else { return false }
return mtlDevice.supportsFeatureSet(.iOS_GPUFamily4_v1) // iOS GPU Family 4 = A11 GPU
}
var supportsJIT: Bool {
guard #available(iOS 14.0, *) else { return false }
// JIT is supported on devices with an A12 processor or better running iOS 14.0 or later.
// ARKit 3 is only supported by devices with an A12 processor or better, according to the documentation.
return ARBodyTrackingConfiguration.isSupported
}
} }

View File

@ -0,0 +1,24 @@
//
// UIImage+SymbolFallback.swift
// Delta
//
// Created by Riley Testut on 2/5/20.
// Copyright © 2020 Riley Testut. All rights reserved.
//
import UIKit
extension UIImage
{
convenience init?(symbolNameIfAvailable name: String)
{
if #available(iOS 13, *)
{
self.init(systemName: name)
}
else
{
return nil
}
}
}

View File

@ -1,45 +0,0 @@
//
// URL+ExtendedAttributes.swift
// Delta
//
// Created by Riley Testut on 3/26/19.
// Copyright © 2019 Riley Testut. All rights reserved.
//
import Foundation
extension URL
{
func setExtendedAttribute(name: String, value: String) throws
{
try self.withUnsafeFileSystemRepresentation { (path) in
let data = value.data(using: .utf8)
let result = data?.withUnsafeBytes { (buffer) in
setxattr(path, name, buffer.baseAddress, buffer.count, 0, 0)
}
if let result = result, result < 0
{
throw POSIXError(POSIXErrorCode(rawValue: errno) ?? .ENOENT)
}
}
}
func extendedAttribute(name: String) -> String?
{
let value = self.withUnsafeFileSystemRepresentation { (path) -> String? in
let size = getxattr(path, name, nil, 0, 0, 0)
guard size >= 0 else { return nil }
var data = Data(count: size)
let result = data.withUnsafeMutableBytes { getxattr(path, name, $0.baseAddress, $0.count, 0, 0) }
guard result >= 0 else { return nil }
let value = String(data: data, encoding: .utf8)!
return value
}
return value
}
}

View File

@ -0,0 +1,14 @@
//
// UserDefaults+Delta.swift
// Delta
//
// Created by Riley Testut on 8/10/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import Foundation
extension UserDefaults
{
@NSManaged var shouldRepairDatabase: Bool
}

View File

@ -8,8 +8,10 @@
import UIKit import UIKit
import MobileCoreServices import MobileCoreServices
import AVFoundation
import DeltaCore import DeltaCore
import MelonDSDeltaCore
import Roxas import Roxas
import Harmony import Harmony
@ -22,6 +24,7 @@ extension GameCollectionViewController
{ {
case alreadyRunning case alreadyRunning
case downloadingGameSave case downloadingGameSave
case biosNotFound
} }
} }
@ -40,6 +43,8 @@ class GameCollectionViewController: UICollectionViewController
// Calling reloadData sometimes will not update the cells correctly if an insertion/deletion animation is in progress // Calling reloadData sometimes will not update the cells correctly if an insertion/deletion animation is in progress
// As a workaround, we manually iterate over and configure each cell ourselves // As a workaround, we manually iterate over and configure each cell ourselves
// / reloadData
//
for cell in self.collectionView?.visibleCells ?? [] for cell in self.collectionView?.visibleCells ?? []
{ {
if let indexPath = self.collectionView?.indexPath(for: cell) if let indexPath = self.collectionView?.indexPath(for: cell)
@ -59,12 +64,16 @@ class GameCollectionViewController: UICollectionViewController
private let prototypeCell = GridCollectionViewCell() private let prototypeCell = GridCollectionViewCell()
private var _performing3DTouchTransition = false private var _performingPreviewTransition = false
private weak var _destination3DTouchTransitionViewController: UIViewController? private weak var _previewTransitionViewController: PreviewGameViewController?
private weak var _previewTransitionDestinationViewController: UIViewController?
private weak var _popoverSourceView: UIView?
private var _renameAction: UIAlertAction? private var _renameAction: UIAlertAction?
private var _changingArtworkGame: Game? private var _changingArtworkGame: Game?
private var _importingSaveFileGame: Game? private var _importingSaveFileGame: Game?
private var _exportedSaveFileURL: URL?
required init?(coder aDecoder: NSCoder) required init?(coder aDecoder: NSCoder)
{ {
@ -88,31 +97,33 @@ extension GameCollectionViewController
self.collectionView?.prefetchDataSource = self.dataSource self.collectionView?.prefetchDataSource = self.dataSource
self.collectionView?.delegate = self self.collectionView?.delegate = self
let layout = self.collectionViewLayout as! GridCollectionViewLayout if #available(iOS 13, *) {}
layout.itemWidth = 90 else
layout.minimumInteritemSpacing = 12 {
self.registerForPreviewing(with: self, sourceView: self.collectionView!)
let longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(GameCollectionViewController.handleLongPressGesture(_:)))
self.collectionView?.addGestureRecognizer(longPressGestureRecognizer)
}
self.registerForPreviewing(with: self, sourceView: self.collectionView!) self.update()
let longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(GameCollectionViewController.handleLongPressGesture(_:)))
self.collectionView?.addGestureRecognizer(longPressGestureRecognizer)
} }
override func viewWillDisappear(_ animated: Bool) override func viewWillDisappear(_ animated: Bool)
{ {
super.viewWillDisappear(animated) super.viewWillDisappear(animated)
if _performing3DTouchTransition if _performingPreviewTransition
{ {
_performing3DTouchTransition = false _performingPreviewTransition = false
// Unlike our custom transitions, 3D Touch transition doesn't manually call appearance methods for us // Unlike our custom transitions, 3D Touch transition doesn't manually call appearance methods for us
// To compensate, we call them ourselves // To compensate, we call them ourselves
_destination3DTouchTransitionViewController?.beginAppearanceTransition(true, animated: true) _previewTransitionDestinationViewController?.beginAppearanceTransition(true, animated: true)
self.transitionCoordinator?.animate(alongsideTransition: nil, completion: { (context) in self.transitionCoordinator?.animate(alongsideTransition: nil, completion: { (context) in
self._destination3DTouchTransitionViewController?.endAppearanceTransition() self._previewTransitionDestinationViewController?.endAppearanceTransition()
self._destination3DTouchTransitionViewController = nil self._previewTransitionDestinationViewController = nil
}) })
} }
} }
@ -122,6 +133,13 @@ extension GameCollectionViewController
super.didReceiveMemoryWarning() super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated. // Dispose of any resources that can be recreated.
} }
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?)
{
super.traitCollectionDidChange(previousTraitCollection)
self.update()
}
} }
//MARK: - Segues - //MARK: - Segues -
@ -142,6 +160,12 @@ extension GameCollectionViewController
saveStatesViewController.game = game saveStatesViewController.game = game
saveStatesViewController.mode = .loading saveStatesViewController.mode = .loading
saveStatesViewController.theme = self.theme saveStatesViewController.theme = self.theme
case "preferredControllerSkins":
let game = sender as! Game
let preferredControllerSkinsViewController = (segue.destination as! UINavigationController).topViewController as! PreferredControllerSkinsViewController
preferredControllerSkinsViewController.game = game
case "unwindFromGames": case "unwindFromGames":
let destinationViewController = segue.destination as! GameViewController let destinationViewController = segue.destination as! GameViewController
@ -152,9 +176,28 @@ extension GameCollectionViewController
destinationViewController.game = game destinationViewController.game = game
if let emulatorBridge = destinationViewController.emulatorCore?.deltaCore.emulatorBridge as? MelonDSEmulatorBridge
{
//TODO: Update this to work with multiple processes by retrieving emulatorBridge directly from emulatorCore.
//TODO emulatorCore emulatorBridge 使
if game.identifier == Game.melonDSDSiBIOSIdentifier
{
emulatorBridge.systemType = .dsi
}
else
{
emulatorBridge.systemType = .ds
}
emulatorBridge.isJITEnabled = ProcessInfo.processInfo.isJITAvailable
}
if let saveState = self.activeSaveState if let saveState = self.activeSaveState
{ {
// Must be synchronous or else there will be a flash of black // Must be synchronous or else there will be a flash of black
//
destinationViewController.emulatorCore?.start() destinationViewController.emulatorCore?.start()
destinationViewController.emulatorCore?.pause() destinationViewController.emulatorCore?.pause()
@ -176,20 +219,16 @@ extension GameCollectionViewController
self.activeSaveState = nil self.activeSaveState = nil
if _performing3DTouchTransition if _performingPreviewTransition
{ {
_destination3DTouchTransitionViewController = destinationViewController _previewTransitionDestinationViewController = destinationViewController
} }
default: break default: break
} }
} }
@IBAction private func unwindFromSaveStatesViewController(with segue: UIStoryboardSegue) @IBAction private func unwindToGameCollectionViewController(_ segue: UIStoryboardSegue)
{
}
@IBAction private func unwindFromGamesDatabaseBrowser(with segue: UIStoryboardSegue)
{ {
} }
} }
@ -197,6 +236,27 @@ extension GameCollectionViewController
//MARK: - Private Methods - //MARK: - Private Methods -
private extension GameCollectionViewController private extension GameCollectionViewController
{ {
func update()
{
let layout = self.collectionViewLayout as! GridCollectionViewLayout
switch self.traitCollection.horizontalSizeClass
{
case .regular:
layout.itemWidth = 150
layout.minimumInteritemSpacing = 25 // 30 == only 3 games per line for iPad mini 6 in portrait
// 30 == iPad mini 6 3
case .unspecified, .compact:
layout.itemWidth = 90
layout.minimumInteritemSpacing = 12
@unknown default: break
}
self.collectionView.reloadData()
}
//MARK: - Data Source //MARK: - Data Source
func prepareDataSource() func prepareDataSource()
{ {
@ -255,11 +315,24 @@ private extension GameCollectionViewController
cell.isImageViewVibrancyEnabled = true cell.isImageViewVibrancyEnabled = true
} }
cell.imageView.image = #imageLiteral(resourceName: "BoxArt") cell.imageView.image = #imageLiteral(resourceName: "zw")
if self.traitCollection.horizontalSizeClass == .regular
{
let fontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .subheadline).withSymbolicTraits(.traitBold)!
cell.textLabel.font = UIFont(descriptor: fontDescriptor, size: 0)
}
else
{
cell.textLabel.font = UIFont.preferredFont(forTextStyle: .caption1)
}
let layout = self.collectionViewLayout as! GridCollectionViewLayout
cell.maximumImageSize = CGSize(width: layout.itemWidth, height: layout.itemWidth)
cell.maximumImageSize = CGSize(width: 90, height: 90)
cell.textLabel.text = game.name cell.textLabel.text = game.name
cell.textLabel.textColor = UIColor.gray cell.textLabel.textColor = UIColor.gray
cell.tintColor = cell.textLabel.textColor
} }
//MARK: - Emulation //MARK: - Emulation
@ -302,11 +375,13 @@ private extension GameCollectionViewController
} }
// Disable videoManager to prevent flash of black // Disable videoManager to prevent flash of black
// videoManager
self.activeEmulatorCore?.videoManager.isEnabled = false self.activeEmulatorCore?.videoManager.isEnabled = false
launchGame(ignoringErrors: [LaunchError.alreadyRunning]) launchGame(ignoringErrors: [LaunchError.alreadyRunning])
// The game hasn't changed, so the activeEmulatorCore is the same as before, so we need to enable videoManager it again // The game hasn't changed, so the activeEmulatorCore is the same as before, so we need to enable videoManager it again
// activeEmulatorCorevideoManager
self.activeEmulatorCore?.videoManager.isEnabled = true self.activeEmulatorCore?.videoManager.isEnabled = true
})) }))
alertController.addAction(UIAlertAction(title: NSLocalizedString("Restart", comment: ""), style: .destructive, handler: { (action) in alertController.addAction(UIAlertAction(title: NSLocalizedString("Restart", comment: ""), style: .destructive, handler: { (action) in
@ -320,6 +395,16 @@ private extension GameCollectionViewController
alertController.addAction(.ok) alertController.addAction(.ok)
self.present(alertController, animated: true, completion: nil) self.present(alertController, animated: true, completion: nil)
} }
catch LaunchError.biosNotFound
{
let alertController = UIAlertController(title: NSLocalizedString("Missing Required DS Files", comment: ""), message: NSLocalizedString("Delta requires certain files to play Nintendo DS games. Please import them to launch this game.", comment: ""), preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: NSLocalizedString("Import Files", comment: ""), style: .default) { _ in
self.performSegue(withIdentifier: "showDSSettings", sender: nil)
})
alertController.addAction(.cancel)
self.present(alertController, animated: true, completion: nil)
}
catch catch
{ {
let alertController = UIAlertController(title: NSLocalizedString("Unable to Launch Game", comment: ""), error: error) let alertController = UIAlertController(title: NSLocalizedString("Unable to Launch Game", comment: ""), error: error)
@ -336,7 +421,7 @@ private extension GameCollectionViewController
launchGame(ignoringErrors: []) launchGame(ignoringErrors: [])
} }
} }
//
func validateLaunchingGame(_ game: Game, ignoringErrors ignoredErrors: [Error]) throws func validateLaunchingGame(_ game: Game, ignoringErrors ignoredErrors: [Error]) throws
{ {
let ignoredErrors = ignoredErrors.map { $0 as NSError } let ignoredErrors = ignoredErrors.map { $0 as NSError }
@ -370,6 +455,27 @@ private extension GameCollectionViewController
} }
} }
} }
if game.type == .ds && Settings.preferredCore(for: .ds) == MelonDS.core
{
if game.identifier == Game.melonDSDSiBIOSIdentifier
{
guard
FileManager.default.fileExists(atPath: MelonDSEmulatorBridge.shared.dsiBIOS7URL.path) &&
FileManager.default.fileExists(atPath: MelonDSEmulatorBridge.shared.dsiBIOS9URL.path) &&
FileManager.default.fileExists(atPath: MelonDSEmulatorBridge.shared.dsiFirmwareURL.path) &&
FileManager.default.fileExists(atPath: MelonDSEmulatorBridge.shared.dsiNANDURL.path)
else { throw LaunchError.biosNotFound }
}
else
{
guard
FileManager.default.fileExists(atPath: MelonDSEmulatorBridge.shared.bios7URL.path) &&
FileManager.default.fileExists(atPath: MelonDSEmulatorBridge.shared.bios9URL.path) &&
FileManager.default.fileExists(atPath: MelonDSEmulatorBridge.shared.firmwareURL.path)
else { throw LaunchError.biosNotFound }
}
}
} }
} }
@ -380,40 +486,54 @@ private extension GameCollectionViewController
{ {
let cancelAction = Action(title: NSLocalizedString("Cancel", comment: ""), style: .cancel, action: nil) let cancelAction = Action(title: NSLocalizedString("Cancel", comment: ""), style: .cancel, action: nil)
let renameAction = Action(title: NSLocalizedString("Rename", comment: ""), style: .default, action: { [unowned self] action in let renameAction = Action(title: NSLocalizedString("Rename", comment: ""), style: .default, image: UIImage(symbolNameIfAvailable: "pencil.and.ellipsis.rectangle"), action: { [unowned self] action in
self.rename(game) self.rename(game)
}) })
let changeArtworkAction = Action(title: NSLocalizedString("Change Artwork", comment: ""), style: .default) { [unowned self] action in let changeArtworkAction = Action(title: NSLocalizedString("Change Artwork", comment: ""), style: .default, image: UIImage(symbolNameIfAvailable: "photo")) { [unowned self] action in
self.changeArtwork(for: game) self.changeArtwork(for: game)
} }
let shareAction = Action(title: NSLocalizedString("Share", comment: ""), style: .default, action: { [unowned self] action in let changeControllerSkinAction = Action(title: NSLocalizedString("Change Controller Skin", comment: ""), style: .default, image: UIImage(symbolNameIfAvailable: "gamecontroller")) { [unowned self] _ in
self.changePreferredControllerSkin(for: game)
}
let shareAction = Action(title: NSLocalizedString("Share", comment: ""), style: .default, image: UIImage(symbolNameIfAvailable: "square.and.arrow.up"), action: { [unowned self] action in
self.share(game) self.share(game)
}) })
let saveStatesAction = Action(title: NSLocalizedString("Save States", comment: ""), style: .default, action: { [unowned self] action in let saveStatesAction = Action(title: NSLocalizedString("Save States", comment: ""), style: .default, image: UIImage(symbolNameIfAvailable: "doc.on.doc"), action: { [unowned self] action in
self.viewSaveStates(for: game) self.viewSaveStates(for: game)
}) })
let importSaveFile = Action(title: NSLocalizedString("Import Save File", comment: ""), style: .default) { [unowned self] _ in let importSaveFile = Action(title: NSLocalizedString("Import Save File", comment: ""), style: .default, image: UIImage(symbolNameIfAvailable: "tray.and.arrow.down")) { [unowned self] _ in
self.importSaveFile(for: game) self.importSaveFile(for: game)
} }
let deleteAction = Action(title: NSLocalizedString("Delete", comment: ""), style: .destructive, action: { [unowned self] action in let exportSaveFile = Action(title: NSLocalizedString("Export Save File", comment: ""), style: .default, image: UIImage(symbolNameIfAvailable: "tray.and.arrow.up")) { [unowned self] _ in
self.exportSaveFile(for: game)
}
let deleteAction = Action(title: NSLocalizedString("Delete", comment: ""), style: .destructive, image: UIImage(symbolNameIfAvailable: "trash"), action: { [unowned self] action in
self.delete(game) self.delete(game)
}) })
switch game.type switch game.type
{ {
case GameType.unknown: return [cancelAction, renameAction, changeArtworkAction, shareAction, deleteAction] case GameType.unknown:
default: return [cancelAction, renameAction, changeArtworkAction, shareAction, saveStatesAction, importSaveFile, deleteAction] return [cancelAction, renameAction, changeArtworkAction, shareAction, deleteAction]
case .ds where game.identifier == Game.melonDSBIOSIdentifier || game.identifier == Game.melonDSDSiBIOSIdentifier:
return [cancelAction, renameAction, changeArtworkAction, changeControllerSkinAction, saveStatesAction]
default:
return [cancelAction, renameAction, changeArtworkAction, changeControllerSkinAction, shareAction, saveStatesAction, importSaveFile, exportSaveFile, deleteAction]
} }
} }
func delete(_ game: Game) func delete(_ game: Game)
{ {
let confirmationAlertController = UIAlertController(title: NSLocalizedString("Are you sure you want to delete this game? All associated data, such as saves, save states, and cheat codes, will also be deleted.", comment: ""), message: nil, preferredStyle: .actionSheet) let confirmationAlertController = UIAlertController(title: NSLocalizedString("Are you sure you want to delete this game?", comment: ""),
message: NSLocalizedString("All associated data, such as saves, save states, and cheat codes, will also be deleted.", comment: ""),
preferredStyle: .alert)
confirmationAlertController.addAction(UIAlertAction(title: NSLocalizedString("Delete Game", comment: ""), style: .destructive, handler: { action in confirmationAlertController.addAction(UIAlertAction(title: NSLocalizedString("Delete Game", comment: ""), style: .destructive, handler: { action in
DatabaseManager.shared.performBackgroundTask { (context) in DatabaseManager.shared.performBackgroundTask { (context) in
@ -483,11 +603,19 @@ private extension GameCollectionViewController
let importController = ImportController(documentTypes: [kUTTypeImage as String]) let importController = ImportController(documentTypes: [kUTTypeImage as String])
importController.delegate = self importController.delegate = self
importController.importOptions = [clipboardImportOption, photoLibraryImportOption, gamesDatabaseImportOption] importController.importOptions = [clipboardImportOption, photoLibraryImportOption, gamesDatabaseImportOption]
importController.sourceView = self._popoverSourceView
self.present(importController, animated: true, completion: nil) self.present(importController, animated: true, completion: nil)
} }
func changeArtwork(for game: Game, toImageAt url: URL?, errors: [Error]) func changeArtwork(for game: Game, toImageAt url: URL?, errors: [Error])
{ {
defer {
if let temporaryImageURL = url
{
try? FileManager.default.removeItem(at: temporaryImageURL)
}
}
var errors = errors var errors = errors
var imageURL: URL? var imageURL: URL?
@ -503,7 +631,8 @@ private extension GameCollectionViewController
if if
let image = UIImage(data: imageData), let image = UIImage(data: imageData),
let resizedImage = image.resizing(toFit: CGSize(width: 300, height: 300)), let resizedImage = image.resizing(toFit: CGSize(width: 300, height: 300)),
let resizedData = resizedImage.jpegData(compressionQuality: 0.85) let rotatedImage = resizedImage.rotatedToIntrinsicOrientation(), // in case image was imported directly from Files
let resizedData = rotatedImage.pngData()
{ {
let destinationURL = DatabaseManager.artworkURL(for: game) let destinationURL = DatabaseManager.artworkURL(for: game)
try resizedData.write(to: destinationURL, options: .atomic) try resizedData.write(to: destinationURL, options: .atomic)
@ -529,6 +658,14 @@ private extension GameCollectionViewController
if let imageURL = imageURL if let imageURL = imageURL
{ {
self.dataSource.prefetchItemCache.removeObject(forKey: game)
if let cacheManager = SDWebImageManager.shared()
{
let cacheKey = cacheManager.cacheKey(for: imageURL)
cacheManager.imageCache.removeImage(forKey: cacheKey)
}
DatabaseManager.shared.performBackgroundTask { (context) in DatabaseManager.shared.performBackgroundTask { (context) in
let temporaryGame = context.object(with: game.objectID) as! Game let temporaryGame = context.object(with: game.objectID) as! Game
temporaryGame.artworkURL = imageURL temporaryGame.artworkURL = imageURL
@ -538,6 +675,15 @@ private extension GameCollectionViewController
SyncManager.shared.recordController?.updateRecord(for: temporaryGame) SyncManager.shared.recordController?.updateRecord(for: temporaryGame)
DispatchQueue.main.async { DispatchQueue.main.async {
if let indexPath = self.dataSource.fetchedResultsController.indexPath(forObject: game)
{
// Manually reload item because collection view may not be in window hierarchy,
// which means it won't automatically update when we save the context.
//
//
self.collectionView.reloadItems(at: [indexPath])
}
self.presentedViewController?.dismiss(animated: true, completion: nil) self.presentedViewController?.dismiss(animated: true, completion: nil)
} }
} }
@ -569,26 +715,36 @@ private extension GameCollectionViewController
func share(_ game: Game) func share(_ game: Game)
{ {
let temporaryDirectory = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) let temporaryDirectory = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString, isDirectory: true)
let symbolicURL = temporaryDirectory.appendingPathComponent(game.name + "." + game.fileURL.pathExtension)
let sanitizedName = game.name.components(separatedBy: .urlFilenameAllowed.inverted).joined()
let temporaryURL = temporaryDirectory.appendingPathComponent(sanitizedName + "." + game.fileURL.pathExtension, isDirectory: false)
do do
{ {
try FileManager.default.createDirectory(at: temporaryDirectory, withIntermediateDirectories: true, attributes: nil) try FileManager.default.createDirectory(at: temporaryDirectory, withIntermediateDirectories: true, attributes: nil)
// Create a symbolic link so we can control the file name used when sharing. // Make a temporary copy so we can control the filename used when sharing.
// Otherwise, if we just passed in game.fileURL to UIActivityViewController, the file name would be the game's SHA1 hash. // Otherwise, if we just passed in game.fileURL to UIActivityViewController, the file name would be the game's SHA1 hash.
try FileManager.default.createSymbolicLink(at: symbolicURL, withDestinationURL: game.fileURL) try FileManager.default.copyItem(at: game.fileURL, to: temporaryURL, shouldReplace: true)
} }
catch catch
{ {
print(error) let alertController = UIAlertController(title: NSLocalizedString("Could Not Share Game", comment: ""), error: error)
self.present(alertController, animated: true, completion: nil)
return
} }
let copyDeepLinkActivity = CopyDeepLinkActivity() let copyDeepLinkActivity = CopyDeepLinkActivity()
let activityViewController = UIActivityViewController(activityItems: [symbolicURL, game], applicationActivities: [copyDeepLinkActivity]) let activityViewController = UIActivityViewController(activityItems: [temporaryURL, game], applicationActivities: [copyDeepLinkActivity])
activityViewController.popoverPresentationController?.sourceView = self._popoverSourceView?.superview
activityViewController.popoverPresentationController?.sourceRect = self._popoverSourceView?.frame ?? .zero
activityViewController.completionWithItemsHandler = { (activityType, finished, returnedItems, error) in activityViewController.completionWithItemsHandler = { (activityType, finished, returnedItems, error) in
// Make sure the user either shared the game or cancelled before deleting temporaryDirectory.
guard finished || activityType == nil else { return }
do do
{ {
try FileManager.default.removeItem(at: temporaryDirectory) try FileManager.default.removeItem(at: temporaryDirectory)
@ -598,6 +754,7 @@ private extension GameCollectionViewController
print(error) print(error)
} }
} }
self.present(activityViewController, animated: true, completion: nil) self.present(activityViewController, animated: true, completion: nil)
} }
@ -649,6 +806,33 @@ private extension GameCollectionViewController
} }
} }
func exportSaveFile(for game: Game)
{
do
{
let sanitizedFilename = game.name.components(separatedBy: .urlFilenameAllowed.inverted).joined()
let temporaryURL = FileManager.default.temporaryDirectory.appendingPathComponent(sanitizedFilename)
try FileManager.default.copyItem(at: game.gameSaveURL, to: temporaryURL, shouldReplace: true)
self._exportedSaveFileURL = temporaryURL
let documentPicker = UIDocumentPickerViewController(urls: [temporaryURL], in: .exportToService)
documentPicker.delegate = self
self.present(documentPicker, animated: true, completion: nil)
}
catch
{
let alertController = UIAlertController(title: NSLocalizedString("Failed to Export Save File", comment: ""), error: error)
self.present(alertController, animated: true, completion: nil)
}
}
func changePreferredControllerSkin(for game: Game)
{
self.performSegue(withIdentifier: "preferredControllerSkins", sender: game)
}
@objc func textFieldTextDidChange(_ textField: UITextField) @objc func textFieldTextDidChange(_ textField: UITextField)
{ {
let text = textField.text ?? "" let text = textField.text ?? ""
@ -685,8 +869,23 @@ extension GameCollectionViewController: UIViewControllerPreviewingDelegate
previewingContext.sourceRect = layoutAttributes.frame previewingContext.sourceRect = layoutAttributes.frame
let cell = collectionView.cellForItem(at: indexPath)
self._popoverSourceView = cell
let game = self.dataSource.item(at: indexPath) let game = self.dataSource.item(at: indexPath)
let gameViewController = self.makePreviewGameViewController(for: game)
_previewTransitionViewController = gameViewController
return gameViewController
}
func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController)
{
self.commitPreviewTransition()
}
func makePreviewGameViewController(for game: Game) -> PreviewGameViewController
{
let gameViewController = PreviewGameViewController() let gameViewController = PreviewGameViewController()
gameViewController.game = game gameViewController.game = game
@ -696,37 +895,63 @@ extension GameCollectionViewController: UIViewControllerPreviewingDelegate
gameViewController.previewImage = UIImage(contentsOfFile: previewSaveState.imageFileURL.path) gameViewController.previewImage = UIImage(contentsOfFile: previewSaveState.imageFileURL.path)
} }
if let emulatorBridge = gameViewController.emulatorCore?.deltaCore.emulatorBridge as? MelonDSEmulatorBridge
{
//TODO: Update this to work with multiple processes by retrieving emulatorBridge directly from emulatorCore.
if game.identifier == Game.melonDSDSiBIOSIdentifier
{
emulatorBridge.systemType = .dsi
}
else
{
emulatorBridge.systemType = .ds
}
emulatorBridge.isJITEnabled = ProcessInfo.processInfo.isJITAvailable
}
let actions = self.actions(for: game).previewActions let actions = self.actions(for: game).previewActions
gameViewController.overridePreviewActionItems = actions gameViewController.overridePreviewActionItems = actions
return gameViewController return gameViewController
} }
func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) func commitPreviewTransition()
{ {
let gameViewController = viewControllerToCommit as! PreviewGameViewController guard let gameViewController = _previewTransitionViewController else { return }
let game = gameViewController.game as! Game
let game = gameViewController.game as! Game
gameViewController.pauseEmulation() gameViewController.pauseEmulation()
let indexPath = self.dataSource.fetchedResultsController.indexPath(forObject: game)! let indexPath = self.dataSource.fetchedResultsController.indexPath(forObject: game)!
let fileURL = FileManager.default.uniqueTemporaryURL() let fileURL = FileManager.default.uniqueTemporaryURL()
self.activeSaveState = gameViewController.emulatorCore?.saveSaveState(to: fileURL)
if gameViewController.isLivePreview
{
self.activeSaveState = gameViewController.emulatorCore?.saveSaveState(to: fileURL)
}
else
{
self.activeSaveState = gameViewController.previewSaveState
}
gameViewController.emulatorCore?.stop() gameViewController.emulatorCore?.stop()
_performing3DTouchTransition = true _performingPreviewTransition = true
self.launchGame(at: indexPath, clearScreen: true, ignoreAlreadyRunningError: true) self.launchGame(at: indexPath, clearScreen: true, ignoreAlreadyRunningError: true)
do if gameViewController.isLivePreview
{ {
try FileManager.default.removeItem(at: fileURL) do
} {
catch try FileManager.default.removeItem(at: fileURL)
{ }
print(error) catch
{
print(error)
}
} }
} }
} }
@ -793,6 +1018,7 @@ extension GameCollectionViewController: UICollectionViewDelegateFlowLayout
{ {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
{ {
let collectionViewLayout = collectionView.collectionViewLayout as! GridCollectionViewLayout let collectionViewLayout = collectionView.collectionViewLayout as! GridCollectionViewLayout
let widthConstraint = self.prototypeCell.contentView.widthAnchor.constraint(equalToConstant: collectionViewLayout.itemWidth) let widthConstraint = self.prototypeCell.contentView.widthAnchor.constraint(equalToConstant: collectionViewLayout.itemWidth)
@ -802,6 +1028,99 @@ extension GameCollectionViewController: UICollectionViewDelegateFlowLayout
self.configure(self.prototypeCell, for: indexPath) self.configure(self.prototypeCell, for: indexPath)
let size = self.prototypeCell.contentView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize) let size = self.prototypeCell.contentView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
return size // return size
return CGSize(width: 150, height: 150)
}
}
@available(iOS 13.0, *)
extension GameCollectionViewController
{
override func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration?
{
let game = self.dataSource.item(at: indexPath)
let actions = self.actions(for: game)
let cell = self.collectionView.cellForItem(at: indexPath)
self._popoverSourceView = cell
return UIContextMenuConfiguration(identifier: indexPath as NSIndexPath, previewProvider: { [weak self] in
guard let self = self else { return nil }
do
{
try self.validateLaunchingGame(game, ignoringErrors: [LaunchError.alreadyRunning])
}
catch
{
print("Error trying to preview game:", error)
return nil
}
let previewViewController = self.makePreviewGameViewController(for: game)
previewViewController.isLivePreview = Settings.isPreviewsEnabled
guard previewViewController.isLivePreview || previewViewController.previewSaveState != nil else { return nil }
self._previewTransitionViewController = previewViewController
return previewViewController
}) { suggestedActions in
return UIMenu(title: game.name, children: actions.menuActions)
}
}
override func collectionView(_ collectionView: UICollectionView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating)
{
self.commitPreviewTransition()
}
override func collectionView(_ collectionView: UICollectionView, previewForHighlightingContextMenuWithConfiguration configuration: UIContextMenuConfiguration) -> UITargetedPreview?
{
guard let indexPath = configuration.identifier as? NSIndexPath else { return nil }
guard let cell = collectionView.cellForItem(at: indexPath as IndexPath) as? GridCollectionViewCell else { return nil }
let parameters = UIPreviewParameters()
parameters.backgroundColor = .clear
if let image = cell.imageView.image
{
let artworkFrame = AVMakeRect(aspectRatio: image.size, insideRect: cell.imageView.bounds)
let bezierPath = UIBezierPath(rect: artworkFrame)
parameters.visiblePath = bezierPath
}
let preview = UITargetedPreview(view: cell.imageView, parameters: parameters)
return preview
}
override func collectionView(_ collectionView: UICollectionView, previewForDismissingContextMenuWithConfiguration configuration: UIContextMenuConfiguration) -> UITargetedPreview?
{
_previewTransitionViewController = nil
return self.collectionView(collectionView, previewForHighlightingContextMenuWithConfiguration: configuration)
}
}
extension GameCollectionViewController: UIDocumentPickerDelegate
{
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL])
{
if let saveFileURL = self._exportedSaveFileURL
{
try? FileManager.default.removeItem(at: saveFileURL)
}
self._exportedSaveFileURL = nil
}
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController)
{
if let saveFileURL = self._exportedSaveFileURL
{
try? FileManager.default.removeItem(at: saveFileURL)
}
self._exportedSaveFileURL = nil
} }
} }

View File

@ -47,6 +47,7 @@ class GamesViewController: UIViewController
private let fetchedResultsController: NSFetchedResultsController<NSFetchRequestResult> private let fetchedResultsController: NSFetchedResultsController<NSFetchRequestResult>
private var searchController: RSTSearchController? private var searchController: RSTSearchController?
private lazy var importController: ImportController = self.makeImportController()
private var syncingToastView: RSTToastView? { private var syncingToastView: RSTToastView? {
didSet { didSet {
@ -58,6 +59,8 @@ class GamesViewController: UIViewController
} }
private var syncingProgressObservation: NSKeyValueObservation? private var syncingProgressObservation: NSKeyValueObservation?
@IBOutlet private var importButton: UIBarButtonItem!
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
fatalError("initWithNibName: not implemented") fatalError("initWithNibName: not implemented")
} }
@ -75,6 +78,15 @@ class GamesViewController: UIViewController
NotificationCenter.default.addObserver(self, selector: #selector(GamesViewController.syncingDidStart(_:)), name: SyncCoordinator.didStartSyncingNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(GamesViewController.syncingDidStart(_:)), name: SyncCoordinator.didStartSyncingNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(GamesViewController.syncingDidFinish(_:)), name: SyncCoordinator.didFinishSyncingNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(GamesViewController.syncingDidFinish(_:)), name: SyncCoordinator.didFinishSyncingNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(GamesViewController.settingsDidChange(_:)), name: Settings.didChangeNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(GamesViewController.emulationDidQuit(_:)), name: EmulatorCore.emulationDidQuitNotification, object: nil)
}
@IBAction func importfilesBtn(_ sender: UIButton) {
self.present(self.importController, animated: true, completion: nil)
} }
} }
@ -88,9 +100,16 @@ extension GamesViewController
self.placeholderView = RSTPlaceholderView(frame: self.view.bounds) self.placeholderView = RSTPlaceholderView(frame: self.view.bounds)
self.placeholderView.autoresizingMask = [.flexibleWidth, .flexibleHeight] self.placeholderView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.placeholderView.textLabel.text = NSLocalizedString("No Games", comment: "") self.placeholderView.textLabel.text = NSLocalizedString("", comment: "")
self.placeholderView.detailTextLabel.text = NSLocalizedString("You can import games by pressing the + button in the top right.", comment: "") self.placeholderView.detailTextLabel.text = NSLocalizedString("You have not added any games", comment: "")
let placeholderImagV = UIImageView(image: UIImage(named: "nogame"))
placeholderImagV.frame = CGRect(x: (self.view.bounds.width - 87) / 2, y: (self.view.bounds.height - (placeholderImagV.bounds.height + 80)) / 2, width: 87, height: 64)
placeholderImagV.contentMode = .center
self.view.insertSubview(self.placeholderView, at: 0) self.view.insertSubview(self.placeholderView, at: 0)
self.placeholderView.addSubview(placeholderImagV)
self.pageControl = UIPageControl() self.pageControl = UIPageControl()
self.pageControl.translatesAutoresizingMaskIntoConstraints = false self.pageControl.translatesAutoresizingMaskIntoConstraints = false
@ -103,25 +122,47 @@ extension GamesViewController
self.pageControl.centerXAnchor.constraint(equalTo: (self.navigationController?.toolbar.centerXAnchor)!, constant: 0).isActive = true self.pageControl.centerXAnchor.constraint(equalTo: (self.navigationController?.toolbar.centerXAnchor)!, constant: 0).isActive = true
self.pageControl.centerYAnchor.constraint(equalTo: (self.navigationController?.toolbar.centerYAnchor)!, constant: 0).isActive = true self.pageControl.centerYAnchor.constraint(equalTo: (self.navigationController?.toolbar.centerYAnchor)!, constant: 0).isActive = true
if let navigationController = self.navigationController // if let navigationController = self.navigationController
// {
// if #available(iOS 13.0, *)
// {
// navigationController.overrideUserInterfaceStyle = .dark
//
// let navigationBarAppearance = navigationController.navigationBar.standardAppearance.copy()
// navigationBarAppearance.backgroundEffect = UIBlurEffect(style: .dark)
// navigationController.navigationBar.standardAppearance = navigationBarAppearance
// navigationController.navigationBar.scrollEdgeAppearance = navigationBarAppearance
//
// let toolbarAppearance = navigationController.toolbar.standardAppearance.copy()
// toolbarAppearance.backgroundEffect = UIBlurEffect(style: .dark)
// navigationController.toolbar.standardAppearance = toolbarAppearance
//
// if #available(iOS 15, *)
// {
// navigationController.toolbar.scrollEdgeAppearance = toolbarAppearance
// }
// }
// else
// {
// navigationController.navigationBar.barStyle = .blackTranslucent
// navigationController.toolbar.barStyle = .blackTranslucent
// }
// }
if #available(iOS 14, *)
{ {
if #available(iOS 13.0, *) self.importController.presentingViewController = self
{
navigationController.overrideUserInterfaceStyle = .dark let importActions = self.importController.makeActions().menuActions
let importMenu = UIMenu(title: NSLocalizedString("Import From…", comment: ""), image: UIImage(systemName: "square.and.arrow.down"), children: importActions)
let navigationBarAppearance = navigationController.navigationBar.standardAppearance.copy() self.importButton.menu = importMenu
navigationBarAppearance.backgroundEffect = UIBlurEffect(style: .dark)
navigationController.navigationBar.standardAppearance = navigationBarAppearance self.importButton.action = nil
self.importButton.target = nil
let toolbarAppearance = navigationController.toolbar.standardAppearance.copy() }
toolbarAppearance.backgroundEffect = UIBlurEffect(style: .dark) else
navigationController.toolbar.standardAppearance = toolbarAppearance {
} self.importController.barButtonItem = self.importButton
else
{
navigationController.navigationBar.barStyle = .blackTranslucent
navigationController.toolbar.barStyle = .blackTranslucent
}
} }
self.prepareSearchController() self.prepareSearchController()
@ -225,6 +266,7 @@ private extension GamesViewController
return nil return nil
} }
self.searchController?.searchBar.barStyle = .black self.searchController?.searchBar.barStyle = .black
self.searchController?.searchBar.placeholder = "Game here"
self.navigationItem.searchController = self.searchController self.navigationItem.searchController = self.searchController
self.navigationItem.hidesSearchBarWhenScrolling = false self.navigationItem.hidesSearchBarWhenScrolling = false
@ -327,7 +369,8 @@ private extension GamesViewController
self.pageViewController.setViewControllers([viewController], direction: .forward, animated: false, completion: nil) self.pageViewController.setViewControllers([viewController], direction: .forward, animated: false, completion: nil)
self.title = viewController.title // self.title = viewController.title
self.title = ""
self.pageControl.currentPage = index self.pageControl.currentPage = index
} }
} }
@ -350,26 +393,40 @@ private extension GamesViewController
/// Importing /// Importing
extension GamesViewController: ImportControllerDelegate extension GamesViewController: ImportControllerDelegate
{ {
@IBAction private func importFiles() private func makeImportController() -> ImportController
{ {
var documentTypes = Set(System.registeredSystems.map { $0.gameType.rawValue }) var documentTypes = Set(System.registeredSystems.map { $0.gameType.rawValue })
documentTypes.insert(kUTTypeZipArchive as String) documentTypes.insert(kUTTypeZipArchive as String)
documentTypes.insert("com.rileytestut.delta.skin")
#if BETA
// .bin files (Genesis ROMs)
documentTypes.insert("com.apple.macbinary-archive")
#endif
// Add GBA4iOS's exported UTIs in case user has GBA4iOS installed (which may override Delta's UTI declarations) // Add GBA4iOS's exported UTIs in case user has GBA4iOS installed (which may override Delta's UTI declarations)
documentTypes.insert("com.rileytestut.gba") documentTypes.insert("com.rileytestut.gba")
documentTypes.insert("com.rileytestut.gbc") documentTypes.insert("com.rileytestut.gbc")
documentTypes.insert("com.rileytestut.gb") documentTypes.insert("com.rileytestut.gb")
documentTypes.insert("com.rileytestut.delta.skin") // let itunesImportOption = iTunesImportOption(presentingViewController: self)
let itunesImportOption = iTunesImportOption(presentingViewController: self)
let importController = ImportController(documentTypes: documentTypes) let importController = ImportController(documentTypes: documentTypes)
importController.delegate = self importController.delegate = self
importController.importOptions = [itunesImportOption] // importController.importOptions = [itunesImportOption]
self.present(importController, animated: true, completion: nil)
return importController
} }
@IBAction private func importFiles()
{
self.present(self.importController, animated: true, completion: nil)
}
func importController(_ importController: ImportController, didImportItemsAt urls: Set<URL>, errors: [Error]) func importController(_ importController: ImportController, didImportItemsAt urls: Set<URL>, errors: [Error])
{ {
for error in errors for error in errors
@ -419,6 +476,8 @@ private extension GamesViewController
SyncManager.shared.sync() SyncManager.shared.sync()
} }
func showSyncingToastViewIfNeeded() func showSyncingToastViewIfNeeded()
{ {
guard let coordinator = SyncManager.shared.coordinator, let syncProgress = SyncManager.shared.syncProgress, coordinator.isSyncing && self.syncingToastView == nil else { return } guard let coordinator = SyncManager.shared.coordinator, let syncProgress = SyncManager.shared.syncProgress, coordinator.isSyncing && self.syncingToastView == nil else { return }
@ -469,6 +528,23 @@ private extension GamesViewController
let navigationController = SyncResultViewController.make(result: result) let navigationController = SyncResultViewController.make(result: result)
self.present(navigationController, animated: true, completion: nil) self.present(navigationController, animated: true, completion: nil)
} }
func quitEmulation()
{
DispatchQueue.main.async {
self.activeEmulatorCore = nil
if let viewControllers = self.pageViewController.viewControllers as? [GameCollectionViewController]
{
for collectionViewController in viewControllers
{
collectionViewController.activeEmulatorCore = nil
}
}
self.theme = .opaque
}
}
} }
//MARK: - Notifications - //MARK: - Notifications -
@ -483,16 +559,12 @@ private extension GamesViewController
{ {
if deletedObjects.contains(game) if deletedObjects.contains(game)
{ {
DispatchQueue.main.async { self.quitEmulation()
self.theme = .opaque
}
} }
} }
else else
{ {
DispatchQueue.main.async { self.quitEmulation()
self.theme = .opaque
}
} }
} }
@ -510,6 +582,27 @@ private extension GamesViewController
self.showSyncFinishedToastView(result: result) self.showSyncFinishedToastView(result: result)
} }
} }
@objc func emulationDidQuit(_ notification: Notification)
{
self.quitEmulation()
}
@objc func settingsDidChange(_ notification: Notification)
{
guard let emulatorCore = self.activeEmulatorCore else { return }
guard let game = emulatorCore.game as? Game else { return }
game.managedObjectContext?.performAndWait {
guard
let name = notification.userInfo?[Settings.NotificationUserInfoKey.name] as? String, name == Settings.preferredCoreSettingsKey(for: emulatorCore.game.type),
let core = notification.userInfo?[Settings.NotificationUserInfoKey.core] as? DeltaCoreProtocol, core != emulatorCore.deltaCore
else { return }
emulatorCore.stop()
self.quitEmulation()
}
}
} }
//MARK: - UIPageViewController - //MARK: - UIPageViewController -
@ -575,7 +668,7 @@ extension GamesViewController: NSFetchedResultsControllerDelegate
extension GamesViewController: UIAdaptivePresentationControllerDelegate extension GamesViewController: UIAdaptivePresentationControllerDelegate
{ {
func presentationControllerWillDismiss(_ presentationController: UIPresentationController) func presentationControllerDidDismiss(_ presentationController: UIPresentationController)
{ {
self.sync() self.sync()
} }

View File

@ -19,8 +19,11 @@ struct ClipboardImportOption: ImportOption
func `import`(withCompletionHandler completionHandler: @escaping (Set<URL>?) -> Void) func `import`(withCompletionHandler completionHandler: @escaping (Set<URL>?) -> Void)
{ {
guard UIPasteboard.general.hasImages else { return completionHandler([]) } guard UIPasteboard.general.hasImages else { return completionHandler([]) }
guard let data = UIPasteboard.general.data(forPasteboardType: kUTTypeImage as String) else { return completionHandler([]) } guard let image = UIPasteboard.general.image,
let rotatedImage = image.rotatedToIntrinsicOrientation(),
let data = rotatedImage.pngData()
else { return completionHandler([]) }
do do
{ {

View File

@ -42,7 +42,7 @@ extension PhotoLibraryImportOption: UIImagePickerControllerDelegate, UINavigatio
{ {
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any])
{ {
guard let image = info[.originalImage] as? UIImage, let data = image.jpegData(compressionQuality: 0.85) else { guard let image = info[.originalImage] as? UIImage, let rotatedImage = image.rotatedToIntrinsicOrientation(), let data = rotatedImage.pngData() else {
self.completionHandler?([]) self.completionHandler?([])
return return
} }

View File

@ -13,7 +13,7 @@ import DeltaCore
struct iTunesImportOption: ImportOption struct iTunesImportOption: ImportOption
{ {
let title = NSLocalizedString("iTunes", comment: "") let title = NSLocalizedString("iTunes", comment: "")
let image: UIImage? = nil let image: UIImage? = UIImage(symbolNameIfAvailable: "music.note")
private let presentingViewController: UIViewController private let presentingViewController: UIViewController

View File

@ -8,6 +8,7 @@
import UIKit import UIKit
import MobileCoreServices import MobileCoreServices
import UniformTypeIdentifiers
import ObjectiveC import ObjectiveC
import DeltaCore import DeltaCore
@ -37,7 +38,10 @@ class ImportController: NSObject
var delegate: ImportControllerDelegate? var delegate: ImportControllerDelegate?
var importOptions: [ImportOption]? var importOptions: [ImportOption]?
private weak var presentingViewController: UIViewController? weak var presentingViewController: UIViewController?
weak var barButtonItem: UIBarButtonItem?
weak var sourceView: UIView?
// Store presentedViewController separately, since when we dismiss we don't know if it has already been dismissed. // Store presentedViewController separately, since when we dismiss we don't know if it has already been dismissed.
// Calling dismiss on presentingViewController in that case would dismiss presentingViewController, which is bad. // Calling dismiss on presentingViewController in that case would dismiss presentingViewController, which is bad.
@ -61,26 +65,54 @@ class ImportController: NSObject
super.init() super.init()
} }
func makeActions() -> [Action]
{
assert(self.presentingViewController != nil, "presentingViewController must be set before calling makeActions()")
var actions = (self.importOptions ?? []).map { (option) -> Action in
let action = Action(title: option.title, style: .default, image: option.image) { _ in
option.import { importedURLs in
self.finish(with: importedURLs, errors: [])
}
}
return action
}
let filesAction = Action(title: NSLocalizedString("Files", comment: ""), style: .default, image: UIImage(symbolNameIfAvailable: "doc")) { action in
self.presentDocumentBrowser()
}
actions.append(filesAction)
return actions
}
fileprivate func presentImportController(from presentingViewController: UIViewController, animated: Bool, completionHandler: (() -> Void)?) fileprivate func presentImportController(from presentingViewController: UIViewController, animated: Bool, completionHandler: (() -> Void)?)
{ {
self.presentingViewController = presentingViewController self.presentingViewController = presentingViewController
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) let actions = self.makeActions()
alertController.addAction(UIAlertAction.cancel)
if let importOptions = self.importOptions if actions.count > 1
{ {
for importOption in importOptions let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
alertController.addAction(UIAlertAction.cancel)
let alertActions = actions.map { UIAlertAction($0) }
for action in alertActions
{ {
alertController.add(importOption) { [unowned self] (urls) in alertController.addAction(action)
self.finish(with: urls, errors: [])
}
} }
let filesAction = UIAlertAction(title: NSLocalizedString("Files", comment: ""), style: .default) { (action) in if let sourceView = self.sourceView
self.presentDocumentBrowser() {
alertController.popoverPresentationController?.sourceView = sourceView.superview
alertController.popoverPresentationController?.sourceRect = sourceView.frame
}
else
{
alertController.popoverPresentationController?.barButtonItem = self.barButtonItem
} }
alertController.addAction(filesAction)
self.presentedViewController = alertController self.presentedViewController = alertController
self.presentingViewController?.present(alertController, animated: true, completion: nil) self.presentingViewController?.present(alertController, animated: true, completion: nil)
@ -116,24 +148,90 @@ class ImportController: NSObject
private func presentDocumentBrowser() private func presentDocumentBrowser()
{ {
let cancelButton = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(ImportController.cancel)) let supportedTypes = self.documentTypes.compactMap { UTType($0) }
let documentBrowserViewController = UIDocumentBrowserViewController(forOpeningFilesWithContentTypes: Array(self.documentTypes)) let presentedViewController: UIViewController
documentBrowserViewController.delegate = self
documentBrowserViewController.modalPresentationStyle = .fullScreen
documentBrowserViewController.browserUserInterfaceStyle = .dark
documentBrowserViewController.allowsPickingMultipleItems = true
documentBrowserViewController.allowsDocumentCreation = false
documentBrowserViewController.additionalTrailingNavigationBarButtonItems = [cancelButton]
self.presentedViewController = documentBrowserViewController if #available(iOS 17, *)
self.presentingViewController?.present(documentBrowserViewController, animated: true, completion: nil) {
// Prior to iOS 17, UIDocumentPickerViewController was too buggy to reliably use with iCloud Drive.
let documentPickerViewController = UIDocumentPickerViewController(forOpeningContentTypes: supportedTypes, asCopy: true)
documentPickerViewController.delegate = self
documentPickerViewController.overrideUserInterfaceStyle = .dark
documentPickerViewController.allowsMultipleSelection = true
presentedViewController = documentPickerViewController
}
else
{
let documentBrowserViewController = UIDocumentBrowserViewController(forOpening: supportedTypes)
documentBrowserViewController.delegate = self
documentBrowserViewController.modalPresentationStyle = .fullScreen
documentBrowserViewController.browserUserInterfaceStyle = .dark
documentBrowserViewController.allowsPickingMultipleItems = true
documentBrowserViewController.allowsDocumentCreation = false
let cancelButton = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(ImportController.cancel))
documentBrowserViewController.additionalTrailingNavigationBarButtonItems = [cancelButton]
presentedViewController = documentBrowserViewController
}
self.presentedViewController = presentedViewController
self.presentingViewController?.present(presentedViewController, animated: true, completion: nil)
}
}
extension ImportController
{
func importExternalFile(at fileURL: URL, completionHandler: @escaping (Result<URL, Error>) -> Void)
{
let intent = NSFileAccessIntent.readingIntent(with: fileURL)
self.fileCoordinator.coordinate(with: [intent], queue: self.importQueue) { (error) in
do
{
if let error = error
{
throw error
}
else
{
// User intent.url, not url, as the system may have updated it when requesting access.
guard intent.url.startAccessingSecurityScopedResource() else { throw CocoaError.error(.fileReadNoPermission) }
defer { intent.url.stopAccessingSecurityScopedResource() }
// Use url, not intent.url, to ensure the file name matches what was in the document browser.
let temporaryURL = FileManager.default.temporaryDirectory.appendingPathComponent(fileURL.lastPathComponent)
try FileManager.default.copyItem(at: intent.url, to: temporaryURL, shouldReplace: true)
completionHandler(.success(temporaryURL))
}
}
catch
{
completionHandler(.failure(error))
}
}
}
}
extension ImportController: UIDocumentPickerDelegate
{
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt documentURLs: [URL])
{
self.finish(with: Set(documentURLs), errors: [])
}
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController)
{
self.cancel()
} }
} }
extension ImportController: UIDocumentBrowserViewControllerDelegate extension ImportController: UIDocumentBrowserViewControllerDelegate
{ {
func documentBrowser(_ controller: UIDocumentBrowserViewController, didPickDocumentURLs documentURLs: [URL]) func documentBrowser(_ controller: UIDocumentBrowserViewController, didPickDocumentsAt documentURLs: [URL])
{ {
var coordinatedURLs = Set<URL>() var coordinatedURLs = Set<URL>()
var errors = [Error]() var errors = [Error]()
@ -144,31 +242,11 @@ extension ImportController: UIDocumentBrowserViewControllerDelegate
{ {
dispatchGroup.enter() dispatchGroup.enter()
let intent = NSFileAccessIntent.readingIntent(with: url) self.importExternalFile(at: url) { (result) in
self.fileCoordinator.coordinate(with: [intent], queue: self.importQueue) { (error) in switch result
do
{ {
if let error = error case .failure(let error): errors.append(error)
{ case .success(let fileURL): coordinatedURLs.insert(fileURL)
throw error
}
else
{
// User intent.url, not url, as the system may have updated it when requesting access.
guard intent.url.startAccessingSecurityScopedResource() else { throw CocoaError.error(.fileReadNoPermission) }
defer { intent.url.stopAccessingSecurityScopedResource() }
// Use url, not intent.url, to ensure the file name matches what was in the document browser.
let temporaryURL = FileManager.default.temporaryDirectory.appendingPathComponent(url.lastPathComponent)
try FileManager.default.copyItem(at: intent.url, to: temporaryURL, shouldReplace: true)
coordinatedURLs.insert(temporaryURL)
}
}
catch
{
errors.append(error)
} }
dispatchGroup.leave() dispatchGroup.leave()
@ -185,7 +263,7 @@ private var ImportControllerKey: UInt8 = 0
extension UIViewController extension UIViewController
{ {
fileprivate(set) var importController: ImportController? fileprivate var importController: ImportController?
{ {
set set
{ {

View File

@ -13,7 +13,9 @@ import Harmony
class LaunchViewController: RSTLaunchViewController class LaunchViewController: RSTLaunchViewController
{ {
@IBOutlet private var gameViewContainerView: UIView! @IBOutlet private var gameViewContainerView: UIView!
private var gameViewController: GameViewController! private var gameViewController: GameViewController!
private var presentedGameViewController: Bool = false private var presentedGameViewController: Bool = false
@ -76,7 +78,42 @@ extension LaunchViewController
} }
} }
return [isDatabaseManagerStarted, isSyncingManagerStarted] // Repair database _after_ starting SyncManager so we can access RecordController.
let isDatabaseRepaired = RSTLaunchCondition(condition: { !UserDefaults.standard.shouldRepairDatabase }) { completionHandler in
func finish()
{
UserDefaults.standard.shouldRepairDatabase = false
completionHandler(nil)
}
do
{
let fetchRequest = Game.fetchRequest()
fetchRequest.fetchLimit = 1
let isDatabaseEmpty = try DatabaseManager.shared.viewContext.count(for: fetchRequest) == 0
guard !isDatabaseEmpty else {
// Database has no games, so no need to repair database.
finish()
return
}
}
catch
{
print("Failed to fetch games at launch, repairing database just to be safe.", error)
}
let repairViewController = RepairDatabaseViewController()
repairViewController.completionHandler = { [weak repairViewController] in
repairViewController?.dismiss(animated: true)
finish()
}
let navigationController = UINavigationController(rootViewController: repairViewController)
self.present(navigationController, animated: true)
}
return [isDatabaseManagerStarted, isSyncingManagerStarted, isDatabaseRepaired]
} }
override func handleLaunchError(_ error: Error) override func handleLaunchError(_ error: Error)

View File

@ -12,13 +12,26 @@ import DeltaCore
extension CheatValidator extension CheatValidator
{ {
enum Error: Swift.Error enum Error: LocalizedError
{ {
case invalidCode case invalidCode
case invalidName case invalidName
case invalidGame case invalidGame
case duplicateName case duplicateName
case duplicateCode case duplicateCode
case unknownCheatType
var errorDescription: String? {
switch self
{
case .invalidCode: return NSLocalizedString("The cheat code isn't in the correct format.", comment: "")
case .invalidName: return NSLocalizedString("The name of this cheat is invalid.", comment: "")
case .invalidGame: return NSLocalizedString("There is no associated game with this cheat.", comment: "")
case .duplicateName: return NSLocalizedString("A cheat already exists with this name.", comment: "")
case .duplicateCode: return NSLocalizedString("A cheat already exists with this code.", comment: "")
case .unknownCheatType: return NSLocalizedString("Delta does not support this cheat type.", comment: "")
}
}
} }
} }

View File

@ -8,8 +8,10 @@
import UIKit import UIKit
import CoreData import CoreData
import SwiftUI
import DeltaCore import DeltaCore
import MelonDSDeltaCore
import Roxas import Roxas
@ -30,6 +32,8 @@ class CheatsViewController: UITableViewController
weak var delegate: CheatsViewControllerDelegate? weak var delegate: CheatsViewControllerDelegate?
private let dataSource = RSTFetchedResultsTableViewDataSource<Cheat>(fetchedResultsController: NSFetchedResultsController()) private let dataSource = RSTFetchedResultsTableViewDataSource<Cheat>(fetchedResultsController: NSFetchedResultsController())
private var cheatBaseCheats: [CheatMetadata]?
} }
extension CheatsViewController extension CheatsViewController
@ -61,6 +65,21 @@ extension CheatsViewController
self.tableView.separatorEffect = vibrancyEffect self.tableView.separatorEffect = vibrancyEffect
self.registerForPreviewing(with: self, sourceView: self.tableView) self.registerForPreviewing(with: self, sourceView: self.tableView)
if #available(iOS 14, *)
{
self.updateAddCheatMenu()
}
}
override func viewWillAppear(_ animated: Bool)
{
super.viewWillAppear(animated)
if #available(iOS 14, *), self.cheatBaseCheats == nil
{
self.fetchCheatBaseCheats()
}
} }
override func didReceiveMemoryWarning() override func didReceiveMemoryWarning()
@ -91,6 +110,37 @@ private extension CheatsViewController
self.dataSource.fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: DatabaseManager.shared.viewContext, sectionNameKeyPath: nil, cacheName: nil) self.dataSource.fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: DatabaseManager.shared.viewContext, sectionNameKeyPath: nil, cacheName: nil)
} }
@available(iOS 14, *) @MainActor
func updateAddCheatMenu()
{
// CheatBase only contains DS cheats for now, so hide option completely for other systems.
guard self.game.type == .ds else { return }
var searchCheatBaseTitle = NSLocalizedString("Search CheatBase", comment: "")
var attributes: UIMenuElement.Attributes = []
if let cheats = self.cheatBaseCheats, cheats.isEmpty
{
searchCheatBaseTitle = NSLocalizedString("No Cheats in CheatBase", comment: "")
attributes = [.disabled]
}
let addCheatMenu = UIMenu(children: [
UIAction(title: NSLocalizedString("New Cheat Code", comment: ""), image: UIImage(systemName: "square.and.pencil")) { [weak self] _ in
self?.addCheat()
},
UIAction(title: searchCheatBaseTitle, image: UIImage(systemName: "magnifyingglass"), attributes: attributes) { [weak self] _ in
self?.searchCheatBase()
},
])
self.navigationItem.rightBarButtonItem?.target = nil
self.navigationItem.rightBarButtonItem?.action = nil
self.navigationItem.rightBarButtonItem?.menu = addCheatMenu
}
} }
//MARK: - Managing Cheats - //MARK: - Managing Cheats -
@ -103,6 +153,78 @@ private extension CheatsViewController
editCheatViewController.presentWithPresentingViewController(self) editCheatViewController.presentWithPresentingViewController(self)
} }
@available(iOS 14, *)
func fetchCheatBaseCheats()
{
Task {
do
{
let cheatBase = try CheatBase()
let cheats = try await cheatBase.cheats(for: self.game) ?? []
self.cheatBaseCheats = cheats
self.updateAddCheatMenu()
}
catch
{
print("[RSTLog] Failed to prefetch cheats from CheatBase:", error)
}
}
}
@available(iOS 14, *)
func searchCheatBase()
{
var rootView = CheatBaseView(game: self.game, cheats: self.cheatBaseCheats)
rootView.cancellationHandler = { [weak self] in
self?.presentedViewController?.dismiss(animated: true)
}
rootView.selectionHandler = { [weak self] cheatMetadata in
self?.saveCheatMetadata(cheatMetadata)
self?.presentedViewController?.dismiss(animated: true)
}
let hostingController = UIHostingController(rootView: rootView)
self.present(hostingController, animated: true, completion: nil)
}
func saveCheatMetadata(_ cheatMetadata: CheatMetadata)
{
DatabaseManager.shared.performBackgroundTask { context in
do
{
guard let cheatType = cheatMetadata.device.cheatType, let cheatFormat = cheatMetadata.device.cheatFormat else { throw CheatValidator.Error.unknownCheatType }
let cheat = Cheat(context: context)
cheat.name = cheatMetadata.name
cheat.type = cheatType
cheat.isEnabled = true
let sanitizedCode = cheatMetadata.code.components(separatedBy: .whitespacesAndNewlines).joined()
let formattedCode = sanitizedCode.formatted(with: cheatFormat)
cheat.code = formattedCode
let game = context.object(with: self.game.objectID) as! Game
cheat.game = game
let validator = CheatValidator(format: cheatFormat, managedObjectContext: context)
try validator.validate(cheat)
self.delegate?.cheatsViewController(self, activateCheat: cheat)
try context.save()
}
catch
{
DispatchQueue.main.async {
let alertController = UIAlertController(title: NSLocalizedString("Unable to Add Cheat", comment: ""), error: error)
self.present(alertController, animated: true, completion: nil)
}
}
}
}
func deleteCheat(_ cheat: Cheat) func deleteCheat(_ cheat: Cheat)
{ {
self.delegate?.cheatsViewController(self, deactivateCheat: cheat) self.delegate?.cheatsViewController(self, deactivateCheat: cheat)

View File

@ -183,9 +183,12 @@ extension EditCheatViewController
if let superview = self.codeTextView.superview if let superview = self.codeTextView.superview
{ {
let layoutMargins = superview.layoutMargins let layoutMargins = superview.layoutMargins
self.codeTextView.textContainerInset = layoutMargins if self.codeTextView.textContainerInset.left != layoutMargins.left
{
self.codeTextView.textContainer.lineFragmentPadding = 0 self.codeTextView.textContainerInset.left = layoutMargins.left // Don't change right inset because CheatTextView adjusts it as well.
self.codeTextView.textContainer.lineFragmentPadding = 0
self.codeTextView.setNeedsLayout()
}
} }
if self.isAppearing && !self.isPreviewing if self.isAppearing && !self.isPreviewing
@ -252,6 +255,8 @@ private extension EditCheatViewController
self.tableView.endUpdates() self.tableView.endUpdates()
} }
self.view.setNeedsLayout()
} }
func updateSaveButtonState() func updateSaveButtonState()

Some files were not shown because too many files have changed in this diff Show More