diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index 599bf82f..c82bf019 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -169,7 +169,8 @@ static double FindHighestScore(const vector& nodes, double epsilon) [menu addItemWithTitle:NSLocalizedString(@"About vChewing…", @"") action:@selector(showAbout:) keyEquivalent:@""]; if (optionKeyPressed) { [menu addItemWithTitle:NSLocalizedString(@"Reboot vChewing…", @"") action:@selector(selfTerminate:) keyEquivalent:@""]; - [menu addItemWithTitle:NSLocalizedString(@"Deploy Zip Data…", @"") action:@selector(cnsDeploy:) keyEquivalent:@""]; + [menu addItemWithTitle:NSLocalizedString(@"Deploy CNS Data…", @"") action:@selector(cnsDeploy:) keyEquivalent:@""]; + [menu addItemWithTitle:NSLocalizedString(@"Load CNS Data…", @"") action:@selector(loadCNSData:) keyEquivalent:@""]; } return menu; } @@ -1551,6 +1552,16 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; } return YES; } +- (BOOL)_checkCNSFile +{ + if (![LanguageModelManager checkIfCNSDataExistAndHashMatched]) { + [self beep]; + NSLog(@"_checkCNSFile failed in the InputMethodController."); + return NO; + } + return YES; +} + - (void)cnsDeploy:(id)sender { [LanguageModelManager deployZipDataFile:@"UNICHARS"]; @@ -1586,6 +1597,15 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; } [LanguageModelManager loadUserPhraseReplacement]; } +- (void)loadCNSData:(id)sender +{ + if (!self._checkCNSFile) { + [self beep]; + } else { + [LanguageModelManager loadCNSData]; + } +} + - (void)showAbout:(id)sender { // show the About window, and also make the IME app itself the focus diff --git a/Source/LanguageModelManager.h b/Source/LanguageModelManager.h index 0d7dbfc8..52507e57 100644 --- a/Source/LanguageModelManager.h +++ b/Source/LanguageModelManager.h @@ -11,6 +11,7 @@ #import "UserOverrideModel.h" #import "vChewingLM.h" #import "SSZipArchive.h" +#import "AWFileHash.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Source/LanguageModelManager.mm b/Source/LanguageModelManager.mm index a16a1891..f4177cf3 100644 --- a/Source/LanguageModelManager.mm +++ b/Source/LanguageModelManager.mm @@ -12,7 +12,6 @@ #import #import "OVStringHelper.h" #import "OVUTF8Helper.h" -#import "AWFileHash.h" using namespace std; using namespace Taiyan::Gramambular; @@ -74,7 +73,9 @@ static void LTLoadLanguageModelFile(NSString *filenameWithoutExtension, vChewing NSLog(@"Extracted CNS Data Not Found."); return NO; } - if ([AWFileHash md5HashOfFileAtPath:[self cnsDataPath]] != [[NSUserDefaults standardUserDefaults] objectForKey:kMD5HashCNSData]) { + if (![[AWFileHash md5HashOfFileAtPath:[self cnsDataPath]] isEqualToString: [[NSUserDefaults standardUserDefaults] objectForKey:kMD5HashCNSData]]) { + NSLog(@"Existing CNS CSV Data Fingerprint: %@", [AWFileHash md5HashOfFileAtPath:[self cnsDataPath]]); + NSLog(@"UserPlist CNS CSV Data Fingerprint: %@", [[NSUserDefaults standardUserDefaults] objectForKey:kMD5HashCNSData]); NSLog(@"Existing CNS CSV Data fingerprint mismatch, must be tampered since it gets extracted."); return NO; }