Repo // Dump wrecked UOM data on crash when debug mode is ON.

This commit is contained in:
ShikiSuen 2023-07-28 02:41:27 +08:00
parent 339cfb0ad4
commit a4cd1fb69e
2 changed files with 33 additions and 11 deletions

View File

@ -66,21 +66,25 @@ public extension AppDelegate {
}
}
// 使
// 使
// Debug
// Debug
if PrefMgr.shared.failureFlagForUOMObservation {
DispatchQueue.main.async {
if PrefMgr.shared.isDebugModeEnabled {
LMMgr.relocateWreckedUOMData()
} else {
LMMgr.clearUserOverrideModelData(.imeModeCHS)
LMMgr.clearUserOverrideModelData(.imeModeCHT)
PrefMgr.shared.failureFlagForUOMObservation = false
let userNotification = NSUserNotification()
userNotification.title = NSLocalizedString("vChewing", comment: "")
userNotification.informativeText = NSLocalizedString(
"vChewing crashed while handling previously loaded UOM observation data. These data files are cleaned now to ensure the usability.",
comment: ""
)
userNotification.soundName = NSUserNotificationDefaultSoundName
NSUserNotificationCenter.default.deliver(userNotification)
}
PrefMgr.shared.failureFlagForUOMObservation = false
let userNotification = NSUserNotification()
userNotification.title = NSLocalizedString("vChewing", comment: "")
userNotification.informativeText = NSLocalizedString(
"vChewing crashed while handling previously loaded UOM observation data. These data files are cleaned now to ensure the usability.",
comment: ""
)
userNotification.soundName = NSUserNotificationDefaultSoundName
NSUserNotificationCenter.default.deliver(userNotification)
}
if !PrefMgr.shared.onlyLoadFactoryLangModelsIfNeeded { LMMgr.loadDataModelsOnAppDelegate() }

View File

@ -382,6 +382,24 @@ public class LMMgr {
}
}
public static func relocateWreckedUOMData() {
func dateStringTag(date givenDate: Date) -> String {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyyMMdd-HHmm"
dateFormatter.timeZone = .current
let strDate = dateFormatter.string(from: givenDate)
return strDate
}
let urls: [URL] = [userOverrideModelDataURL(.imeModeCHS), userOverrideModelDataURL(.imeModeCHT)]
let folderURL = URL(fileURLWithPath: dataFolderPath(isDefaultFolder: true)).deletingLastPathComponent()
urls.forEach { oldURL in
let newFileName = "[UOM-CRASH][\(dateStringTag(date: .init()))]\(oldURL.lastPathComponent)"
let newURL = folderURL.appendingPathComponent(newFileName)
try? FileManager.default.moveItem(at: oldURL, to: newURL)
}
}
public static func clearUserOverrideModelData(_ mode: Shared.InputMode = .imeModeNULL) {
switch mode {
case .imeModeCHS: