[ExpFeat] Adds “Repair Database” to explicitly repair database
Disables automatic database repairing at app launch.
This commit is contained in:
parent
aea0527828
commit
3e97e5c951
@ -41,6 +41,10 @@ struct ExperimentalFeatures: FeatureContainer
|
|||||||
options: ReviewSaveStatesOptions())
|
options: ReviewSaveStatesOptions())
|
||||||
var reviewSaveStates
|
var reviewSaveStates
|
||||||
|
|
||||||
|
@Feature(name: "Repair Database",
|
||||||
|
description: "Repair invalid relationships in Delta's game database on next app launch.")
|
||||||
|
var repairDatabase
|
||||||
|
|
||||||
@Feature(name: "Alternate App Icon",
|
@Feature(name: "Alternate App Icon",
|
||||||
description: "Change the app icon.",
|
description: "Change the app icon.",
|
||||||
options: AlternateAppIconOptions())
|
options: AlternateAppIconOptions())
|
||||||
|
|||||||
@ -78,33 +78,12 @@ extension LaunchViewController
|
|||||||
|
|
||||||
// Repair database _after_ starting SyncManager so we can access RecordController.
|
// Repair database _after_ starting SyncManager so we can access RecordController.
|
||||||
let isDatabaseRepaired = RSTLaunchCondition(condition: { !UserDefaults.standard.shouldRepairDatabase }) { completionHandler in
|
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()
|
let repairViewController = RepairDatabaseViewController()
|
||||||
repairViewController.completionHandler = { [weak repairViewController] in
|
repairViewController.completionHandler = { [weak repairViewController] in
|
||||||
repairViewController?.dismiss(animated: true)
|
repairViewController?.dismiss(animated: true)
|
||||||
finish()
|
|
||||||
|
UserDefaults.standard.shouldRepairDatabase = false
|
||||||
|
completionHandler(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
let navigationController = UINavigationController(rootViewController: repairViewController)
|
let navigationController = UINavigationController(rootViewController: repairViewController)
|
||||||
|
|||||||
@ -53,7 +53,7 @@ struct Settings
|
|||||||
|
|
||||||
static func registerDefaults()
|
static func registerDefaults()
|
||||||
{
|
{
|
||||||
var defaults = [#keyPath(UserDefaults.translucentControllerSkinOpacity): 0.7,
|
let defaults = [#keyPath(UserDefaults.translucentControllerSkinOpacity): 0.7,
|
||||||
#keyPath(UserDefaults.gameShortcutsMode): GameShortcutsMode.recent.rawValue,
|
#keyPath(UserDefaults.gameShortcutsMode): GameShortcutsMode.recent.rawValue,
|
||||||
#keyPath(UserDefaults.isButtonHapticFeedbackEnabled): true,
|
#keyPath(UserDefaults.isButtonHapticFeedbackEnabled): true,
|
||||||
#keyPath(UserDefaults.isThumbstickHapticFeedbackEnabled): true,
|
#keyPath(UserDefaults.isThumbstickHapticFeedbackEnabled): true,
|
||||||
@ -63,12 +63,7 @@ struct Settings
|
|||||||
#keyPath(UserDefaults.respectSilentMode): true,
|
#keyPath(UserDefaults.respectSilentMode): true,
|
||||||
Settings.preferredCoreSettingsKey(for: .ds): MelonDS.core.identifier] as [String : Any]
|
Settings.preferredCoreSettingsKey(for: .ds): MelonDS.core.identifier] as [String : Any]
|
||||||
|
|
||||||
#if BETA
|
#if !BETA
|
||||||
|
|
||||||
// Assume we need to repair database relationships until explicitly set to false.
|
|
||||||
defaults[#keyPath(UserDefaults.shouldRepairDatabase)] = true
|
|
||||||
|
|
||||||
#else
|
|
||||||
// Manually set MelonDS as preferred DS core in case DeSmuME is cached from a previous version.
|
// Manually set MelonDS as preferred DS core in case DeSmuME is cached from a previous version.
|
||||||
UserDefaults.standard.set(MelonDS.core.identifier, forKey: Settings.preferredCoreSettingsKey(for: .ds))
|
UserDefaults.standard.set(MelonDS.core.identifier, forKey: Settings.preferredCoreSettingsKey(for: .ds))
|
||||||
|
|
||||||
@ -77,6 +72,12 @@ struct Settings
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
UserDefaults.standard.register(defaults: defaults)
|
UserDefaults.standard.register(defaults: defaults)
|
||||||
|
|
||||||
|
if ExperimentalFeatures.shared.repairDatabase.isEnabled
|
||||||
|
{
|
||||||
|
UserDefaults.standard.shouldRepairDatabase = true
|
||||||
|
ExperimentalFeatures.shared.repairDatabase.isEnabled = false // Disable so we only repair database once.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user