Permalink
Browse files

Update source code compatibility

* Remove forward SDK declaration for 10.8 and below (since that is the minimum required development SDK)
* Fix one case where a method unconditionally required a 10.9+ runtime
* Move all of the forward/backward hacks into their own file
  • Loading branch information...
dmoagx committed Mar 31, 2017
1 parent 004af0c commit 2a6e6504a3ae379d80fb9c4bd19250382b9180ad
@@ -50,6 +50,7 @@
#import "SPWindowManagement.h"
#import "SPCopyTable.h"
#import "SPSyntaxParser.h"
#import "SPOSInfo.h"

#import <PSMTabBar/PSMTabBarControl.h>
#import <Sparkle/Sparkle.h>
@@ -825,7 +826,14 @@ - (void)handleEventWithURL:(NSURL*)url
// remove percent encoding
NSMutableArray *decodedPathComponents = [NSMutableArray arrayWithCapacity:pathComponents.count];
for (NSString *component in pathComponents) {
[decodedPathComponents addObject:component.stringByRemovingPercentEncoding];
NSString *decoded;
if([SPOSInfo isOSVersionAtLeastMajor:10 minor:9 patch:0]) {
decoded = [component stringByRemovingPercentEncoding];
}
else {
decoded = [component stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}
[decodedPathComponents addObject:decoded];
}
pathComponents = decodedPathComponents.copy;

@@ -1599,7 +1607,7 @@ - (IBAction)reloadBundles:(id)sender
NSMenu *menu = [[[NSApp mainMenu] itemWithTag:SPMainMenuBundles] submenu];

// Clean menu
[menu compatibleRemoveAllItems];
[menu removeAllItems];

// Set up the bundle search paths
// First process all in Application Support folder installed ones then Default ones
@@ -29,7 +29,6 @@
// More info at <https://github.com/sequelpro/sequelpro>

#import "SPBundleEditorController.h"
#import "SPMenuAdditions.h"
#import "SPBundleCommandRunner.h"
#import "SPOutlineView.h"
#import "SPBundleCommandTextView.h"
@@ -245,7 +244,7 @@ - (void)awakeFromNib
}

NSMenuItem *anItem;
[inputGeneralScopePopUpMenu compatibleRemoveAllItems];
[inputGeneralScopePopUpMenu removeAllItems];
anItem = [[NSMenuItem alloc] initWithTitle:SP_BUNDLEEDITOR_SCOPE_GENERAL_STRING action:@selector(scopeButtonChanged:) keyEquivalent:@""];
[anItem setTag:kGeneralScopeArrayIndex];
[inputGeneralScopePopUpMenu addItem:anItem];
@@ -73,9 +73,7 @@ - (id)init
[webView setDrawsBackground:YES];
[webView setEditable:NO];
[webView setShouldCloseWithWindow:YES];
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
[webView setShouldUpdateWhileOffscreen:NO];
#endif
suppressExceptionAlerting = NO;
}

@@ -42,7 +42,6 @@
#import "SPWindowAdditions.h"
#import "SPDataAdditions.h"
#import "SPDataBase64EncodingAdditions.h"
#import "SPMenuAdditions.h"
#import "SPNotLoaded.h"
#import "SPMainThreadTrampoline.h"
#import "SPColorAdditions.h"
@@ -0,0 +1,151 @@
//
// SPCompatibility.h
// sequel-pro
//
// Created by Max Lohrmann on 31.03.17.
// Copyright (c) 2017 Max Lohrmann. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// More info at <https://github.com/sequelpro/sequelpro>

/**
* This file contains declarations for backward compatibility to
* older XCode versions / SDKs.
*
* The current minimum required SDK is 10.8!
*/

#ifndef SPCompatibility
#define SPCompatibility

#pragma mark - 10.8 Mountain Lion

#ifndef __MAC_10_8
#define __MAC_10_8 1080
#endif

#if __MAC_OS_X_VERSION_MAX_ALLOWED < __MAC_10_8
#error You need to have at least SDK 10.8!
#endif

#pragma mark - 10.9 Mavericks

#ifndef __MAC_10_9
#define __MAC_10_9 1090
#endif

#if __MAC_OS_X_VERSION_MAX_ALLOWED < __MAC_10_9

@interface NSString (Mavericks)

@property (readonly, copy) NSString *stringByRemovingPercentEncoding;

@end

#endif

#pragma mark - 10.10 Yosemite

#ifndef __MAC_10_10
#define __MAC_10_10 101000
#endif

#if __MAC_OS_X_VERSION_MAX_ALLOWED < __MAC_10_10

// This enum is available since 10.5 but only got a "name" in 10.10
typedef NSUInteger NSCellHitResult;

@compatibility_alias NSTitlebarAccessoryViewController NSViewController;

@interface NSViewController (NSTitlebarAccessoryViewController)

@property NSLayoutAttribute layoutAttribute;

@end

@interface NSWindow (Yosemite)

- (NSArray *)titlebarAccessoryViewControllers;
- (void)removeTitlebarAccessoryViewControllerAtIndex:(NSInteger)index;
- (void)addTitlebarAccessoryViewController:(NSTitlebarAccessoryViewController *)controller;

@end

// This code is available since 10.8 but public only since 10.10
typedef struct {
NSInteger majorVersion;
NSInteger minorVersion;
NSInteger patchVersion;
} NSOperatingSystemVersion;

@interface NSProcessInfo ()
- (NSOperatingSystemVersion)operatingSystemVersion;
- (BOOL)isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion)version;
@end

#endif

#pragma mark - 10.11 El Capitan

#ifndef __MAC_10_11
#define __MAC_10_11 101100
#endif

#if !__has_feature(objc_kindof)
#define __kindof
#endif

#if __MAC_OS_X_VERSION_MAX_ALLOWED < __MAC_10_11

// formal protocol since 10.11, NSObject category before
@protocol WebFrameLoadDelegate <NSObject>
@end

@interface NSOpenPanel (ElCapitan)

@property (getter=isAccessoryViewDisclosed) BOOL accessoryViewDisclosed;

@end

#endif

#pragma mark - 10.12 Sierra

#ifndef __MAC_10_12
#define __MAC_10_12 101200
#endif

#if __MAC_OS_X_VERSION_MAX_ALLOWED < __MAC_10_12

//those enums got renamed in 10.12, probably for consistency
#define NSAlertStyleInformational NSInformationalAlertStyle
#define NSAlertStyleWarning NSWarningAlertStyle
#define NSAlertStyleCritical NSCriticalAlertStyle

@interface NSWindow (Sierra)
+ (void)setAllowsAutomaticWindowTabbing:(BOOL)arg;
@end

#endif

#endif
@@ -63,22 +63,6 @@
static NSString *SPExportFavoritesFilename = @"SequelProFavorites.plist";
#endif

#if __MAC_OS_X_VERSION_MAX_ALLOWED < __MAC_10_6
@interface NSSavePanel (NSSavePanel_unpublishedUntilSnowLeopardAPI)

- (void)setShowsHiddenFiles:(BOOL)flag;

@end
#endif

#if __MAC_OS_X_VERSION_MAX_ALLOWED < __MAC_10_11
@interface NSOpenPanel (NSOpenPanel_ElCaptian)

@property (getter=isAccessoryViewDisclosed) BOOL accessoryViewDisclosed;

@end
#endif

/**
* This is a utility function to validate SSL key/certificate files
* @param fileData The contents of the file
@@ -665,32 +665,6 @@ typedef NS_ENUM(NSInteger,SPErrorCode) { // error codes in SPErrorDomain
void _SPClear(id *addr);
#define SPClear(x) _SPClear(&x)

// Backwards compatibility
#ifndef __MAC_10_7
#define __MAC_10_7 1070
#endif

#ifndef __MAC_10_8
#define __MAC_10_8 1080
#endif

#ifndef __MAC_10_10
#define __MAC_10_10 101000
#endif

#ifndef __MAC_10_11
#define __MAC_10_11 101100
#endif

#ifndef __MAC_10_12
#define __MAC_10_12 101200
#endif

// This enum is available since 10.5 but only got a "name" in 10.10
#if __MAC_OS_X_VERSION_MAX_ALLOWED < __MAC_10_10
typedef NSUInteger NSCellHitResult;
#endif

// Stolen from Stack Overflow: http://stackoverflow.com/questions/969130
#define SPLog(fmt, ...) NSLog((@"%s:%d: " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)

@@ -29,13 +29,6 @@
//
// More info at <https://github.com/sequelpro/sequelpro>

// Forward-declare for 10.7 compatibility
#if !defined(MAC_OS_X_VERSION_10_7) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
enum {
NSFullScreenWindowMask = 1 << 14
};
#endif

#import "SPDatabaseDocument.h"
#import "SPConnectionController.h"
#import "SPConnectionHandler.h"
@@ -3990,10 +3983,11 @@ - (void)updateTitlebarStatusVisibilityForcingHide:(BOOL)forceHide
if (newIsVisible == windowTitleStatusViewIsVisible) return;

if (newIsVisible) {
if (NSClassFromString(@"NSTitlebarAccessoryViewController")) { // OS X 10.11 and later
Class controllerClass;
if ((controllerClass = NSClassFromString(@"NSTitlebarAccessoryViewController"))) { // OS X 10.11 and later
[titleAccessoryView setFrame:NSMakeRect(0, 0, titleAccessoryView.frame.size.width, 120)]; // make it really tall, so that it's on the top right of the title/toolbar area, instead of the bottom right (AppKit will not prevent it from going behind the toolbar)

NSTitlebarAccessoryViewController *accessoryViewController = [[[NSTitlebarAccessoryViewController alloc] init] autorelease];
NSTitlebarAccessoryViewController *accessoryViewController = [[[controllerClass alloc] init] autorelease];
accessoryViewController.view = titleAccessoryView;
accessoryViewController.layoutAttribute = NSLayoutAttributeRight;
[parentWindow addTitlebarAccessoryViewController:accessoryViewController];
@@ -351,7 +351,7 @@ - (void)updateColorSchemeSelectionMenu
[defaultItem setTarget:self];

// Build theme selection submenu
[themeSelectionMenu compatibleRemoveAllItems];
[themeSelectionMenu removeAllItems];
[themeSelectionMenu addItem:defaultItem];
[themeSelectionMenu addItem:[NSMenuItem separatorItem]];

@@ -41,13 +41,6 @@

#import <SPMySQL/SPMySQL.h>

#if __MAC_OS_X_VERSION_MAX_ALLOWED < __MAC_10_7
@interface NSTextView (LionPlus)
- (void)setUsesFindBar:(BOOL)value;
- (BOOL)usesFindBar;
@end
#endif

typedef enum {
TextSegment = 0,
ImageSegment,
@@ -2040,7 +2040,7 @@ - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTable
#endif

// Re-init recent menu
[recentGlobalValueMenu compatibleRemoveAllItems];
[recentGlobalValueMenu removeAllItems];
for(id item in recents)
[recentGlobalValueMenu addItemWithTitle:item action:@selector(insertRecentGlobalValue:) keyEquivalent:@""];

@@ -44,11 +44,10 @@ void SPMainQSync(void (^block)(void))

int SPBetterRandomBytes(uint8_t *buf, size_t count)
{
#if MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_7
if([SPOSInfo isOSVersionAtLeastMajor:10 minor:7 patch:0]) {
return SecRandomCopyBytes(kSecRandomDefault, count, buf);
}
#endif

// Version for 10.6
// https://developer.apple.com/library/prerelease/mac/documentation/Security/Conceptual/cryptoservices/RandomNumberGenerationAPIs/RandomNumberGenerationAPIs.html#//apple_ref/doc/uid/TP40011172-CH12-SW1
FILE *fp = fopen("/dev/random", "r");
@@ -230,10 +230,8 @@ - (void)deletePasswordForName:(NSString *)name account:(NSString *)account
*/
- (BOOL)passwordExistsForName:(NSString *)name account:(NSString *)account
{
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
// "kSecClassGenericPassword" was introduced with the 10.7 SDK.
// It won't work on 10.6 either (meaning this code never matches properly there).
// (That's why there are compile time and runtime checks here)
if([SPOSInfo isOSVersionAtLeastMajor:10 minor:7 patch:0]) {
NSMutableDictionary *query = [NSMutableDictionary dictionary];

@@ -248,7 +246,9 @@ - (BOOL)passwordExistsForName:(NSString *)name account:(NSString *)account

return SecItemCopyMatching((CFDictionaryRef)query, (CFTypeRef *)&result) == errSecSuccess;
}
#endif

//Version for 10.6

SecKeychainItemRef item;
SecKeychainSearchRef search = NULL;
NSInteger numberOfItemsFound = 0;
Oops, something went wrong.

0 comments on commit 2a6e650

Please sign in to comment.