From fb4f02a4100a996df0488a31ba679caaab3b5ef8 Mon Sep 17 00:00:00 2001 From: jahorton Date: Fri, 12 Jun 2020 15:25:38 +0700 Subject: [PATCH] fix(ios/engine): fixes older migration breakages --- .../Classes/Resource Management/Storage.swift | 16 ++++------------ ...nt-0.1.4.model.kmp => nrc.en.mtnt.model.kmp} | Bin ...il_euro_latin-1.8.1.js => sil_euro_latin.js} | 0 .../KMEI/KeymanEngineTests/MigrationTests.swift | 3 +++ 4 files changed, 7 insertions(+), 12 deletions(-) rename ios/engine/KMEI/KeymanEngine/resources/Keyman.bundle/Contents/Resources/{nrc.en.mtnt-0.1.4.model.kmp => nrc.en.mtnt.model.kmp} (100%) rename ios/engine/KMEI/KeymanEngine/resources/Keyman.bundle/Contents/Resources/{sil_euro_latin-1.8.1.js => sil_euro_latin.js} (100%) diff --git a/ios/engine/KMEI/KeymanEngine/Classes/Resource Management/Storage.swift b/ios/engine/KMEI/KeymanEngine/Classes/Resource Management/Storage.swift index 384660824f..66709d8d36 100644 --- a/ios/engine/KMEI/KeymanEngine/Classes/Resource Management/Storage.swift +++ b/ios/engine/KMEI/KeymanEngine/Classes/Resource Management/Storage.swift @@ -259,7 +259,7 @@ extension Storage { // Since we only want to do this installation the first time (rather than constantly force-reinstalling // the resource), we don't want this excluded from backup. try Storage.copy(from: bundle, - resourceName: "\(Defaults.keyboard.id)-\(Defaults.keyboard.version).js", + resourceName: "\(Defaults.keyboard.id).js", dstDir: defaultKeyboardDir, excludeFromBackup: false) try Storage.copy(from: bundle, @@ -276,25 +276,17 @@ extension Storage { // Since we only want to do this installation the first time (rather than constantly force-reinstalling // the resource), we don't want this excluded from backup. try Storage.copy(from: bundle, - resourceName: "\(Defaults.lexicalModel.id)-\(Defaults.lexicalModel.version).model.kmp", + resourceName: "\(Defaults.lexicalModel.id).model.kmp", dstDir: defaultLexicalModelDir, excludeFromBackup: false) // Perform an auto-install of the lexical model's KMP if not already installed. - let lexicalModelURLasZIP = Storage.active.lexicalModelPackageURL(forID: Defaults.lexicalModel.id, - asZip: true) let lexicalModelURL = Storage.active.lexicalModelPackageURL(forID: Defaults.lexicalModel.id, asZip: false) - // Because of how our .zip dependency works, we need to make the .kmp look like a .zip. A simple rename will do. do { - try Storage.copy(at: lexicalModelURL, to: lexicalModelURLasZIP, excludeFromBackup: true) - let downloader = ResourceDownloadQueue() - - // Hijacking the download queue's KMP installer. - // Issue - requests DL confirmation - // Issue - in a roundabout way, results in attempted access to Manager.shared during Manager.init, causing crash. - _ = downloader.installLexicalModelPackage(downloadedPackageFile: lexicalModelURLasZIP) + let package = try ResourceFileManager.shared.prepareKMPInstall(from: lexicalModelURL) + try ResourceFileManager.shared.finalizePackageInstall(package, isCustom: false) } catch { log.error("Failed to install the default lexical model from the bundled KMP: \(error)") } diff --git a/ios/engine/KMEI/KeymanEngine/resources/Keyman.bundle/Contents/Resources/nrc.en.mtnt-0.1.4.model.kmp b/ios/engine/KMEI/KeymanEngine/resources/Keyman.bundle/Contents/Resources/nrc.en.mtnt.model.kmp similarity index 100% rename from ios/engine/KMEI/KeymanEngine/resources/Keyman.bundle/Contents/Resources/nrc.en.mtnt-0.1.4.model.kmp rename to ios/engine/KMEI/KeymanEngine/resources/Keyman.bundle/Contents/Resources/nrc.en.mtnt.model.kmp diff --git a/ios/engine/KMEI/KeymanEngine/resources/Keyman.bundle/Contents/Resources/sil_euro_latin-1.8.1.js b/ios/engine/KMEI/KeymanEngine/resources/Keyman.bundle/Contents/Resources/sil_euro_latin.js similarity index 100% rename from ios/engine/KMEI/KeymanEngine/resources/Keyman.bundle/Contents/Resources/sil_euro_latin-1.8.1.js rename to ios/engine/KMEI/KeymanEngine/resources/Keyman.bundle/Contents/Resources/sil_euro_latin.js diff --git a/ios/engine/KMEI/KeymanEngineTests/MigrationTests.swift b/ios/engine/KMEI/KeymanEngineTests/MigrationTests.swift index 6136246b6a..1a929443a6 100644 --- a/ios/engine/KMEI/KeymanEngineTests/MigrationTests.swift +++ b/ios/engine/KMEI/KeymanEngineTests/MigrationTests.swift @@ -53,6 +53,7 @@ class MigrationTests: XCTestCase { func testVersion12AdhocMigration() throws { TestUtils.Migrations.applyBundleToFileSystem(TestUtils.Migrations.adhoc_12) + Storage.active.userDefaults.lastEngineVersion = Version.firstTracked Migrations.migrate(storage: Storage.active) // The files in the .documents directory should be erased after this method is run. @@ -69,6 +70,7 @@ class MigrationTests: XCTestCase { func testVersion10ResourceMigration() { TestUtils.Migrations.applyBundleToFileSystem(TestUtils.Migrations.simple_10) + Storage.active.userDefaults.lastEngineVersion = nil Migrations.updateResources(storage: Storage.active) let userDefaults = Storage.active.userDefaults @@ -98,6 +100,7 @@ class MigrationTests: XCTestCase { TestUtils.Migrations.applyBundleToFileSystem(TestUtils.Migrations.noDefault_10) Migrations.updateResources(storage: Storage.active) + Storage.active.userDefaults.lastEngineVersion = nil let userDefaults = Storage.active.userDefaults // No new resources should be installed - only what was originally present should be there.