LMConsolidator // Simplify the process of fixing EOFs.

This commit is contained in:
ShikiSuen 2022-05-04 18:12:30 +08:00
parent 871c8ac08f
commit f69e5c859b
1 changed files with 9 additions and 2 deletions

View File

@ -59,8 +59,15 @@ extension vChewing {
strIncoming += try String(contentsOf: urlPath, encoding: .utf8)
if !strIncoming.hasSuffix("\n") {
IME.prtDebugIntel("EOF Fix Necessity Confirmed, Start Fixing.")
strIncoming += "\n"
try strIncoming.write(to: urlPath, atomically: false, encoding: .utf8)
if let writeFile = FileHandle(forUpdatingAtPath: path),
let endl = "\n".data(using: .utf8)
{
writeFile.seekToEndOfFile()
writeFile.write(endl)
writeFile.closeFile()
} else {
return false
}
}
} catch {
IME.prtDebugIntel("EOF Fix Failed w/ File: \(path)")