2
0

Mac OS X build fixes of shared code from iOS.

[FIXED]     Build problems with code shared from the iOS project in the
            Mac project.
This commit is contained in:
Maarten Billemont
2012-03-05 22:43:20 +01:00
parent 02ffa9611a
commit f3c24fd96f
13 changed files with 89 additions and 75 deletions

View File

@@ -6,7 +6,6 @@
// Copyright (c) 2011 Lyndir. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "MPAppDelegate.h"
@interface MPAppDelegate ()

View File

@@ -6,11 +6,9 @@
// Copyright (c) 2011 Lyndir. All rights reserved.
//
#import "MPConfig.h"
#import "MPAppDelegate_Key.h"
#import "MPMainViewController.h"
#import "IASKSettingsReader.h"
@implementation MPAppDelegate (Key)
static NSDictionary *keyQuery() {
@@ -44,7 +42,7 @@ static NSDictionary *keyHashQuery() {
[PearlKeyChain deleteItemForQuery:keyHashQuery()];
[[NSNotificationCenter defaultCenter] postNotificationName:MPNotificationKeyForgotten object:self];
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[TestFlight passCheckpoint:MPTestFlightCheckpointMPForgotten];
#endif
}
@@ -56,7 +54,7 @@ static NSDictionary *keyHashQuery() {
- (void)loadStoredKey {
if ([[MPiOSConfig get].storeKey boolValue]) {
if ([[MPConfig get].storeKey boolValue]) {
// Key is stored in keychain. Load it.
dbg(@"Loading key from key chain.");
[self updateKey:[PearlKeyChain dataOfItemForQuery:keyQuery()]];
@@ -65,15 +63,21 @@ static NSDictionary *keyHashQuery() {
// Key should not be stored in keychain. Delete it.
dbg(@"Deleting key from key chain.");
[PearlKeyChain deleteItemForQuery:keyQuery()];
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[TestFlight passCheckpoint:MPTestFlightCheckpointMPUnstored];
#endif
}
}
+ (MPAppDelegate *)get {
return (MPAppDelegate *)[super get];
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
return (MPAppDelegate *)[UIApplication sharedApplication].delegate;
#elif defined (__MAC_OS_X_VERSION_MIN_REQUIRED)
return (MPAppDelegate *)[NSApplication sharedApplication].delegate;
#else
#error Unsupported OS.
#endif
}
- (BOOL)tryMasterPassword:(NSString *)tryPassword {
@@ -92,13 +96,13 @@ static NSDictionary *keyHashQuery() {
if (![keyHash isEqual:tryKeyHash]) {
dbg(@"Key phrase hash mismatch. Expected: %@, answer: %@.", keyHash, tryKeyHash);
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[TestFlight passCheckpoint:MPTestFlightCheckpointMPMismatch];
#endif
return NO;
}
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[TestFlight passCheckpoint:MPTestFlightCheckpointMPAsked];
#endif
@@ -123,18 +127,22 @@ static NSDictionary *keyHashQuery() {
[PearlKeyChain addOrUpdateItemForQuery:keyHashQuery()
withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
self.keyHash, (__bridge id)kSecValueData,
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
kSecAttrAccessibleWhenUnlocked, (__bridge id)kSecAttrAccessible,
#endif
nil]];
if ([[MPiOSConfig get].storeKey boolValue]) {
if ([[MPConfig get].storeKey boolValue]) {
dbg(@"Storing key in key chain.");
[PearlKeyChain addOrUpdateItemForQuery:keyQuery()
withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
key, (__bridge id)kSecValueData,
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
kSecAttrAccessibleWhenUnlocked, (__bridge id)kSecAttrAccessible,
#endif
nil]];
}
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[TestFlight passCheckpoint:[NSString stringWithFormat:MPTestFlightCheckpointSetKeyphraseLength, key.length]];
#endif
}

View File

@@ -32,7 +32,7 @@ typedef enum {
MPElementTypeStoredDevicePrivate = MPElementTypeClassStored | 0x02,
} MPElementType;
#ifndef PRODUCTION
#ifdef TESTFLIGHT
#define MPTestFlightCheckpointAction @"MPTestFlightCheckpointAction"
#define MPTestFlightCheckpointHelpChapter @"MPTestFlightCheckpointHelpChapter_%@"
#define MPTestFlightCheckpointCopyToPasteboard @"MPTestFlightCheckpointCopyToPasteboard"

View File

@@ -17,15 +17,9 @@
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) MPPasswordWindowController *passwordWindow;
@property (readonly, strong, nonatomic) NSData *keyPhrase;
@property (readonly, strong, nonatomic) NSString *keyPhraseHashHex;
+ (MPAppDelegate *)get;
+ (NSManagedObjectModel *)managedObjectModel;
+ (NSManagedObjectContext *)managedObjectContext;
- (IBAction)saveAction:(id)sender;
- (NSData *)keyPhraseWithLength:(NSUInteger)keyLength;
@end

View File

@@ -6,7 +6,7 @@
// Copyright (c) 2012 Lyndir. All rights reserved.
//
#import "MPAppDelegate.h"
#import "MPAppDelegate_Key.h"
@interface MPAppDelegate ()
@@ -20,12 +20,10 @@
@synthesize managedObjectModel = __managedObjectModel;
@synthesize managedObjectContext = __managedObjectContext;
@synthesize passwordWindow;
@synthesize keyPhrase;
+ (MPAppDelegate *)get {
return (MPAppDelegate *)[NSApplication sharedApplication].delegate;
}
@synthesize key;
@synthesize keyHash;
@synthesize keyHashHex;
+ (NSManagedObjectContext *)managedObjectContext {
@@ -54,11 +52,6 @@
return [appSupportURL URLByAppendingPathComponent:@"com.lyndir.lhunath.MasterPassword"];
}
- (NSData *)keyPhraseWithLength:(NSUInteger)keyLength {
return [self.keyPhrase subdataWithRange:NSMakeRange(0, MIN(keyLength, self.keyPhrase.length))];
}
#pragma mark - Core Data stack
- (NSManagedObjectModel *)managedObjectModel {

View File

@@ -7,7 +7,7 @@
//
#import "MPPasswordWindowController.h"
#import "MPAppDelegate.h"
#import "MPAppDelegate_Key.h"
@interface MPPasswordWindowController ()
@@ -46,7 +46,7 @@
fetchRequestFromTemplateWithName:@"MPElements"
substitutionVariables:[NSDictionary dictionaryWithObjectsAndKeys:
query, @"query",
[MPAppDelegate get].keyPhraseHashHex, @"mpHashHex",
[MPAppDelegate get].keyHashHex, @"mpHashHex",
nil]];
return [NSArray arrayWithObjects:@"cow", @"milk", @"hippopotamus", nil];

View File

@@ -40,7 +40,7 @@
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#ifndef PRODUCTION
#ifdef TESTFLIGHT
@try {
[TestFlight takeOff:@"bd44885deee7adce0645ce8e5498d80a_NDQ5NDQyMDExLTEyLTAyIDExOjM1OjQ4LjQ2NjM4NA"];
[TestFlight setOptions:[NSDictionary dictionaryWithObjectsAndKeys:
@@ -124,7 +124,7 @@
[self loadKey:YES];
}];
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[PearlAlert showAlertWithTitle:@"Welcome, tester!" message:
@"Thank you for taking the time to test Master Password.\n\n"
@"Please provide any feedback, however minor it may seem, via the Feedback action item accessible from the top right.\n\n"
@@ -149,7 +149,7 @@
else
[self loadKey:NO];
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[TestFlight passCheckpoint:MPTestFlightCheckpointActivated];
#endif
}
@@ -158,7 +158,7 @@
[self.navigationController performSegueWithIdentifier:@"MP_Guide" sender:self];
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[TestFlight passCheckpoint:MPTestFlightCheckpointShowGuide];
#endif
}
@@ -193,7 +193,7 @@
if (![[MPiOSConfig get].rememberKey boolValue])
[self updateKey:nil];
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[TestFlight passCheckpoint:MPTestFlightCheckpointDeactivated];
#endif
}
@@ -202,7 +202,7 @@
[self saveContext];
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[TestFlight passCheckpoint:MPTestFlightCheckpointTerminated];
#endif
}
@@ -298,7 +298,7 @@
[[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil];
#endif
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[TestFlight passCheckpoint:MPTestFlightCheckpointStoreIncompatible];
#endif

View File

@@ -216,7 +216,7 @@
- (void)setHelpChapter:(NSString *)chapter {
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[TestFlight passCheckpoint:[NSString stringWithFormat:MPTestFlightCheckpointHelpChapter, chapter]];
#endif
@@ -280,7 +280,7 @@
[self showContentTip:@"Copied!" withIcon:nil];
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[TestFlight passCheckpoint:MPTestFlightCheckpointCopyToPasteboard];
#endif
}
@@ -295,7 +295,7 @@
++((MPElementGeneratedEntity *) self.activeElement).counter;
}];
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[TestFlight passCheckpoint:MPTestFlightCheckpointIncrementPasswordCounter];
#endif
}
@@ -323,7 +323,7 @@
[self.contentField becomeFirstResponder];
}
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[TestFlight passCheckpoint:MPTestFlightCheckpointEditPassword];
#endif
}
@@ -336,7 +336,7 @@
self.alertBody.text = nil;
}];
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[TestFlight passCheckpoint:MPTestFlightCheckpointCloseAlert];
#endif
}
@@ -365,7 +365,7 @@
[self.navigationController pushViewController:settingsVC animated:YES];
break;
}
#ifndef PRODUCTION
#ifdef TESTFLIGHT
case 4:
[TestFlight openFeedbackView];
break;
@@ -380,13 +380,13 @@
}
}
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[TestFlight passCheckpoint:MPTestFlightCheckpointAction];
#endif
} cancelTitle:[PearlStrings get].commonButtonCancel destructiveTitle:nil
otherTitles:
[self isHelpVisible]? @"Hide Help": @"Show Help", @"FAQ", @"Tutorial", @"Settings",
#ifndef PRODUCTION
#ifdef TESTFLIGHT
@"Feedback",
#endif
@"Sign Out",
@@ -418,7 +418,7 @@
self.activeElement.type = type;
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[TestFlight passCheckpoint:[NSString stringWithFormat:MPTestFlightCheckpointSelectType, NSStringFromMPElementType(type)]];
#endif
@@ -436,7 +436,7 @@
[self.searchDisplayController setActive:NO animated:YES];
self.searchDisplayController.searchBar.text = self.activeElement.name;
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[TestFlight passCheckpoint:MPTestFlightCheckpointSelectElement];
#endif
}
@@ -474,7 +474,7 @@
navigationType:(UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[TestFlight passCheckpoint:MPTestFlightCheckpointExternalLink];
#endif

View File

@@ -54,7 +54,7 @@
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[TestFlight passCheckpoint:MPTestFlightCheckpointCancelSearch];
#endif
@@ -302,7 +302,7 @@
MPElementEntity *element = [self.fetchedResultsController objectAtIndexPath:indexPath];
[self.fetchedResultsController.managedObjectContext deleteObject:element];
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[TestFlight passCheckpoint:MPTestFlightCheckpointDeleteElement];
#endif
}];

View File

@@ -214,7 +214,7 @@ typedef enum {
[[MPAppDelegate get] loadKey:YES];
#ifndef PRODUCTION
#ifdef TESTFLIGHT
[TestFlight passCheckpoint:MPTestFlightCheckpointMPChanged];
#endif
}