LMMgr // Connecting properties regarding Cassette module.
This commit is contained in:
parent
c3757e2ac3
commit
1174a08360
|
@ -194,6 +194,18 @@ public enum LMMgr {
|
|||
}
|
||||
}
|
||||
|
||||
/// 載入磁帶資料。
|
||||
/// - Remark: cassettePath() 會在輸入法停用磁帶時直接返回
|
||||
public static func loadCassetteData() {
|
||||
let pathForCassette = cassettePath()
|
||||
if !Self.lmCHT.isCassetteEnabled {
|
||||
Self.lmCHT.loadCassetteData(path: pathForCassette)
|
||||
}
|
||||
if !Self.lmCHS.isCassetteEnabled {
|
||||
Self.lmCHT.loadCassetteData(path: pathForCassette)
|
||||
}
|
||||
}
|
||||
|
||||
public static func loadUserPhrasesData() {
|
||||
Self.lmCHT.loadUserPhrasesData(
|
||||
path: userPhrasesDataURL(.imeModeCHT).path,
|
||||
|
@ -271,6 +283,11 @@ public enum LMMgr {
|
|||
Self.lmCHS.isSCPCEnabled = state
|
||||
}
|
||||
|
||||
public static func setCassetteEnabled(_ state: Bool) {
|
||||
Self.lmCHT.isCassetteEnabled = state
|
||||
Self.lmCHS.isCassetteEnabled = state
|
||||
}
|
||||
|
||||
public static func setDeltaOfCalendarYears(_ delta: Int) {
|
||||
Self.lmCHT.deltaOfCalendarYears = delta
|
||||
Self.lmCHS.deltaOfCalendarYears = delta
|
||||
|
@ -428,10 +445,18 @@ public enum LMMgr {
|
|||
if ((folderExist && !isFolder.boolValue) || !folderExist) || !isFolderWritable {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// 檢查給定的磁帶目錄是否存在讀入合規性、且是否為指定格式。
|
||||
public static func checkCassettePathValidity(_ cassettePath: String?) -> Bool {
|
||||
var isFolder = ObjCBool(true)
|
||||
let isExist = FileManager.default.fileExists(atPath: cassettePath ?? "", isDirectory: &isFolder)
|
||||
// The above "&" mutates the "isFolder" value to the real one received by the "isExist".
|
||||
let isReadable = FileManager.default.isReadableFile(atPath: cassettePath ?? "")
|
||||
return !isFolder.boolValue && isExist && isReadable
|
||||
}
|
||||
|
||||
// 檢查給定的目錄是否存在寫入合規性、且糾偏,不接受任何傳入變數。
|
||||
public static var userDataFolderExists: Bool {
|
||||
let folderPath = Self.dataFolderPath(isDefaultFolder: false)
|
||||
|
@ -503,6 +528,16 @@ public enum LMMgr {
|
|||
return userDictPathDefault
|
||||
}
|
||||
|
||||
public static func cassettePath() -> String {
|
||||
let rawCassettePath = PrefMgr.shared.cassettePath
|
||||
if UserDefaults.standard.object(forKey: UserDef.kCassettePath.rawValue) != nil {
|
||||
BookmarkManager.shared.loadBookmarks()
|
||||
if Self.checkCassettePathValidity(rawCassettePath) { return rawCassettePath }
|
||||
UserDefaults.standard.removeObject(forKey: UserDef.kCassettePath.rawValue)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// MARK: - 重設使用者語彙檔案目錄
|
||||
|
||||
public static func resetSpecifiedUserDataFolder() {
|
||||
|
@ -510,6 +545,11 @@ public enum LMMgr {
|
|||
Self.initUserLangModels()
|
||||
}
|
||||
|
||||
public static func resetCassettePath() {
|
||||
UserDefaults.standard.removeObject(forKey: UserDef.kCassettePath.rawValue)
|
||||
Self.loadCassetteData()
|
||||
}
|
||||
|
||||
// MARK: - 寫入使用者檔案
|
||||
|
||||
public static func writeUserPhrase(
|
||||
|
|
Loading…
Reference in New Issue