2013-02-14 17:59:12 +04:00
|
|
|
|
/*
|
|
|
|
|
Utility functions
|
2016-08-05 14:14:55 +03:00
|
|
|
|
|
2013-12-04 14:37:57 +04:00
|
|
|
|
Copyright 2013 Thincast Technologies GmbH, Authors: Martin Fleisz, Dorian Johnson
|
2016-08-05 14:14:55 +03:00
|
|
|
|
|
|
|
|
|
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
2013-02-14 17:59:12 +04:00
|
|
|
|
If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#import "Utils.h"
|
|
|
|
|
#import "OrderedDictionary.h"
|
|
|
|
|
#import "TSXAdditions.h"
|
|
|
|
|
|
|
|
|
|
#import <freerdp/input.h>
|
2013-11-07 14:11:58 +04:00
|
|
|
|
#import <freerdp/version.h>
|
2013-02-14 17:59:12 +04:00
|
|
|
|
#import "config.h"
|
|
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
#include <ifaddrs.h>
|
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
|
|
2016-08-05 14:14:55 +03:00
|
|
|
|
BOOL ScanHostNameAndPort(NSString* address, NSString** host,
|
|
|
|
|
unsigned short* port)
|
2013-02-14 17:59:12 +04:00
|
|
|
|
{
|
2016-08-05 14:14:55 +03:00
|
|
|
|
*host = @"";
|
|
|
|
|
*port = 0;
|
|
|
|
|
|
2013-02-14 17:59:12 +04:00
|
|
|
|
if (![address length])
|
|
|
|
|
return NO;
|
2016-08-05 14:14:55 +03:00
|
|
|
|
|
|
|
|
|
NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"rdp://%@",
|
|
|
|
|
address]];
|
|
|
|
|
|
2013-02-14 17:59:12 +04:00
|
|
|
|
if (!url || ![[url host] length])
|
|
|
|
|
return NO;
|
2016-08-05 14:14:55 +03:00
|
|
|
|
|
2013-02-14 17:59:12 +04:00
|
|
|
|
*host = [url host];
|
|
|
|
|
*port = [[url port] unsignedShortValue];
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
#pragma mark Working with Screen Resolutions
|
|
|
|
|
|
|
|
|
|
NSString* LocalizedFitScreen()
|
|
|
|
|
{
|
2016-08-05 14:14:55 +03:00
|
|
|
|
return NSLocalizedString(@"Automatic",
|
|
|
|
|
@"Screen resolution selector: Automatic resolution (Full Screen on iPad, reasonable size on iPhone)");
|
2013-02-14 17:59:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSString* LocalizedCustom()
|
|
|
|
|
{
|
2016-08-05 14:14:55 +03:00
|
|
|
|
return NSLocalizedString(@"Custom", @"Screen resolution selector: Custom");
|
2013-02-14 17:59:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-05 14:14:55 +03:00
|
|
|
|
BOOL ScanScreenResolution(NSString* description, int* width, int* height,
|
|
|
|
|
TSXScreenOptions* type)
|
2013-02-14 17:59:12 +04:00
|
|
|
|
{
|
2016-08-05 14:14:55 +03:00
|
|
|
|
*height = 0;
|
|
|
|
|
*width = 0;
|
|
|
|
|
*type = TSXScreenOptionFixed;
|
|
|
|
|
|
2013-02-14 17:59:12 +04:00
|
|
|
|
if ([description isEqualToString:LocalizedFitScreen()])
|
|
|
|
|
{
|
|
|
|
|
*type = TSXScreenOptionFitScreen;
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
else if ([description isEqualToString:LocalizedCustom()])
|
|
|
|
|
{
|
|
|
|
|
*type = TSXScreenOptionCustom;
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
2016-08-05 14:14:55 +03:00
|
|
|
|
|
|
|
|
|
NSArray* resolution_components = [description
|
|
|
|
|
componentsSeparatedByCharactersInSet:[NSCharacterSet
|
|
|
|
|
characterSetWithCharactersInString:@"x*×"]];
|
|
|
|
|
|
2013-02-14 17:59:12 +04:00
|
|
|
|
if ([resolution_components count] != 2)
|
|
|
|
|
return NO;
|
2016-08-05 14:14:55 +03:00
|
|
|
|
|
2013-02-14 17:59:12 +04:00
|
|
|
|
*width = [[resolution_components objectAtIndex:0] intValue];
|
2016-08-05 14:14:55 +03:00
|
|
|
|
*height = [[resolution_components objectAtIndex:1] intValue];
|
2013-02-14 17:59:12 +04:00
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-05 14:14:55 +03:00
|
|
|
|
NSString* ScreenResolutionDescription(TSXScreenOptions type, int width,
|
|
|
|
|
int height)
|
2013-02-14 17:59:12 +04:00
|
|
|
|
{
|
|
|
|
|
if (type == TSXScreenOptionFitScreen)
|
|
|
|
|
return LocalizedFitScreen();
|
|
|
|
|
else if (type == TSXScreenOptionCustom)
|
|
|
|
|
return LocalizedCustom();
|
2016-08-05 14:14:55 +03:00
|
|
|
|
|
2013-02-14 17:59:12 +04:00
|
|
|
|
return [NSString stringWithFormat:@"%dx%d", width, height];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NSDictionary* SelectionForColorSetting()
|
|
|
|
|
{
|
2016-08-05 14:14:55 +03:00
|
|
|
|
OrderedDictionary* dict = [OrderedDictionary dictionaryWithCapacity:3];
|
|
|
|
|
[dict setValue:[NSNumber numberWithInt:8] forKey:NSLocalizedString(
|
|
|
|
|
@"Palette Color (8 Bit)", @"8 bit color selection")];
|
|
|
|
|
[dict setValue:[NSNumber numberWithInt:15] forKey:NSLocalizedString(
|
|
|
|
|
@"High Color (15 Bit)", @"15 bit color selection")];
|
|
|
|
|
[dict setValue:[NSNumber numberWithInt:16] forKey:NSLocalizedString(
|
|
|
|
|
@"High Color (16 Bit)", @"16 bit color selection")];
|
|
|
|
|
[dict setValue:[NSNumber numberWithInt:24] forKey:NSLocalizedString(
|
|
|
|
|
@"True Color (24 Bit)", @"24 bit color selection")];
|
|
|
|
|
[dict setValue:[NSNumber numberWithInt:32] forKey:NSLocalizedString(
|
|
|
|
|
@"Highest Quality (32 Bit)", @"32 bit color selection")];
|
|
|
|
|
return dict;
|
2013-02-14 17:59:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSArray* ResolutionModes()
|
|
|
|
|
{
|
2016-08-05 14:14:55 +03:00
|
|
|
|
NSArray* array = [NSArray arrayWithObjects:ScreenResolutionDescription(
|
|
|
|
|
TSXScreenOptionFitScreen, 0, 0),
|
|
|
|
|
ScreenResolutionDescription(TSXScreenOptionFixed, 640, 480),
|
|
|
|
|
ScreenResolutionDescription(TSXScreenOptionFixed, 800, 600),
|
|
|
|
|
ScreenResolutionDescription(TSXScreenOptionFixed, 1024, 768),
|
|
|
|
|
ScreenResolutionDescription(TSXScreenOptionFixed, 1280, 1024),
|
|
|
|
|
ScreenResolutionDescription(TSXScreenOptionFixed, 1440, 900),
|
|
|
|
|
ScreenResolutionDescription(TSXScreenOptionFixed, 1440, 1050),
|
|
|
|
|
ScreenResolutionDescription(TSXScreenOptionFixed, 1600, 1200),
|
|
|
|
|
ScreenResolutionDescription(TSXScreenOptionFixed, 1920, 1080),
|
|
|
|
|
ScreenResolutionDescription(TSXScreenOptionFixed, 1920, 1200),
|
|
|
|
|
ScreenResolutionDescription(TSXScreenOptionCustom, 0, 0), nil];
|
|
|
|
|
return array;
|
2013-02-14 17:59:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark Working with Security Protocols
|
|
|
|
|
|
|
|
|
|
NSString* LocalizedAutomaticSecurity()
|
|
|
|
|
{
|
2016-08-05 14:14:55 +03:00
|
|
|
|
return NSLocalizedString(@"Automatic", @"Automatic protocl security selection");
|
2013-02-14 17:59:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSString* ProtocolSecurityDescription(TSXProtocolSecurityOptions type)
|
|
|
|
|
{
|
|
|
|
|
if (type == TSXProtocolSecurityNLA)
|
|
|
|
|
return @"NLA";
|
|
|
|
|
else if (type == TSXProtocolSecurityTLS)
|
|
|
|
|
return @"TLS";
|
|
|
|
|
else if (type == TSXProtocolSecurityRDP)
|
|
|
|
|
return @"RDP";
|
2016-08-05 14:14:55 +03:00
|
|
|
|
|
2013-02-14 17:59:12 +04:00
|
|
|
|
return LocalizedAutomaticSecurity();
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-05 14:14:55 +03:00
|
|
|
|
BOOL ScanProtocolSecurity(NSString* description,
|
|
|
|
|
TSXProtocolSecurityOptions* type)
|
2013-02-14 17:59:12 +04:00
|
|
|
|
{
|
|
|
|
|
*type = TSXProtocolSecurityRDP;
|
2016-08-05 14:14:55 +03:00
|
|
|
|
|
2013-02-14 17:59:12 +04:00
|
|
|
|
if ([description isEqualToString:@"NLA"])
|
|
|
|
|
{
|
|
|
|
|
*type = TSXProtocolSecurityNLA;
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
else if ([description isEqualToString:@"TLS"])
|
|
|
|
|
{
|
|
|
|
|
*type = TSXProtocolSecurityTLS;
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
else if ([description isEqualToString:@"RDP"])
|
|
|
|
|
{
|
|
|
|
|
*type = TSXProtocolSecurityRDP;
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
else if ([description isEqualToString:LocalizedAutomaticSecurity()])
|
|
|
|
|
{
|
|
|
|
|
*type = TSXProtocolSecurityAutomatic;
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
2016-08-05 14:14:55 +03:00
|
|
|
|
|
2013-02-14 17:59:12 +04:00
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSDictionary* SelectionForSecuritySetting()
|
|
|
|
|
{
|
2016-08-05 14:14:55 +03:00
|
|
|
|
OrderedDictionary* dict = [OrderedDictionary dictionaryWithCapacity:4];
|
|
|
|
|
[dict setValue:[NSNumber numberWithInt:TSXProtocolSecurityAutomatic] forKey:
|
|
|
|
|
ProtocolSecurityDescription(TSXProtocolSecurityAutomatic)];
|
|
|
|
|
[dict setValue:[NSNumber numberWithInt:TSXProtocolSecurityRDP] forKey:
|
|
|
|
|
ProtocolSecurityDescription(TSXProtocolSecurityRDP)];
|
|
|
|
|
[dict setValue:[NSNumber numberWithInt:TSXProtocolSecurityTLS] forKey:
|
|
|
|
|
ProtocolSecurityDescription(TSXProtocolSecurityTLS)];
|
|
|
|
|
[dict setValue:[NSNumber numberWithInt:TSXProtocolSecurityNLA] forKey:
|
|
|
|
|
ProtocolSecurityDescription(TSXProtocolSecurityNLA)];
|
|
|
|
|
return dict;
|
2013-02-14 17:59:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
#pragma mark Bookmarks
|
|
|
|
|
|
|
|
|
|
#import "Bookmark.h"
|
|
|
|
|
|
|
|
|
|
NSMutableArray* FilterBookmarks(NSArray* bookmarks, NSArray* filter_words)
|
|
|
|
|
{
|
|
|
|
|
NSMutableArray* matching_items = [NSMutableArray array];
|
2016-08-05 14:14:55 +03:00
|
|
|
|
NSArray* searched_keys = [NSArray arrayWithObjects:@"label", @"params.hostname",
|
|
|
|
|
@"params.username", @"params.domain", nil];
|
|
|
|
|
|
|
|
|
|
for (ComputerBookmark * cur_bookmark in bookmarks)
|
|
|
|
|
{
|
|
|
|
|
double match_score = 0.0;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < [searched_keys count]; i++)
|
|
|
|
|
{
|
|
|
|
|
NSString* val = [cur_bookmark valueForKeyPath:[searched_keys objectAtIndex:i]];
|
|
|
|
|
|
|
|
|
|
if (![val isKindOfClass:[NSString class]] || ![val length])
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
for (NSString * word in filter_words)
|
|
|
|
|
if ([val rangeOfString:word options:(NSCaseInsensitiveSearch |
|
|
|
|
|
NSWidthInsensitiveSearch)].location != NSNotFound)
|
|
|
|
|
match_score += (1.0 / [filter_words count]) * pow(2, [searched_keys count] - i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (match_score > 0.001)
|
|
|
|
|
[matching_items addObject:[NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
|
cur_bookmark, @"bookmark",
|
|
|
|
|
[NSNumber numberWithFloat:match_score], @"score",
|
|
|
|
|
nil]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[matching_items sortUsingComparator:^NSComparisonResult(NSDictionary * obj1,
|
|
|
|
|
NSDictionary * obj2)
|
|
|
|
|
{
|
2013-02-14 17:59:12 +04:00
|
|
|
|
return [[obj2 objectForKey:@"score"] compare:[obj1 objectForKey:@"score"]];
|
|
|
|
|
}];
|
|
|
|
|
return matching_items;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSMutableArray* FilterHistory(NSArray* history, NSString* filterStr)
|
|
|
|
|
{
|
2016-08-05 14:14:55 +03:00
|
|
|
|
NSMutableArray* result = [NSMutableArray array];
|
|
|
|
|
|
|
|
|
|
for (NSString * item in history)
|
|
|
|
|
{
|
|
|
|
|
if ([item rangeOfString:filterStr].location != NSNotFound)
|
|
|
|
|
[result addObject:item];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
2013-02-14 17:59:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark Version Info
|
|
|
|
|
NSString* TSXAppFullVersion()
|
|
|
|
|
{
|
2013-03-18 15:29:47 +04:00
|
|
|
|
return [NSString stringWithUTF8String:GIT_REVISION];
|
2013-02-14 17:59:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark iPad/iPhone detection
|
|
|
|
|
|
|
|
|
|
BOOL IsPad()
|
|
|
|
|
{
|
|
|
|
|
#ifdef UI_USER_INTERFACE_IDIOM
|
2016-08-05 14:14:55 +03:00
|
|
|
|
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
|
2013-02-14 17:59:12 +04:00
|
|
|
|
#else
|
2016-08-05 14:14:55 +03:00
|
|
|
|
return NO;
|
2013-02-14 17:59:12 +04:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOL IsPhone()
|
|
|
|
|
{
|
|
|
|
|
#ifdef UI_USER_INTERFACE_IDIOM
|
2016-08-05 14:14:55 +03:00
|
|
|
|
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone);
|
2013-02-14 17:59:12 +04:00
|
|
|
|
#else
|
2016-08-05 14:14:55 +03:00
|
|
|
|
return NO;
|
|
|
|
|
#endif
|
2013-02-14 17:59:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set mouse buttons swapped flag
|
|
|
|
|
static BOOL g_swap_mouse_buttons = NO;
|
|
|
|
|
void SetSwapMouseButtonsFlag(BOOL swapped)
|
|
|
|
|
{
|
2016-08-05 14:14:55 +03:00
|
|
|
|
g_swap_mouse_buttons = swapped;
|
2013-02-14 17:59:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set invert scrolling flag
|
|
|
|
|
static BOOL g_invert_scrolling = NO;
|
|
|
|
|
void SetInvertScrollingFlag(BOOL invert)
|
|
|
|
|
{
|
2016-08-05 14:14:55 +03:00
|
|
|
|
g_invert_scrolling = invert;
|
2013-02-14 17:59:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-05 14:14:55 +03:00
|
|
|
|
// return event value for left mouse button
|
2013-02-14 17:59:12 +04:00
|
|
|
|
int GetLeftMouseButtonClickEvent(BOOL down)
|
|
|
|
|
{
|
2016-08-05 14:14:55 +03:00
|
|
|
|
if (g_swap_mouse_buttons)
|
|
|
|
|
return (PTR_FLAGS_BUTTON2 | (down ? PTR_FLAGS_DOWN : 0));
|
|
|
|
|
else
|
|
|
|
|
return (PTR_FLAGS_BUTTON1 | (down ? PTR_FLAGS_DOWN : 0));
|
2013-02-14 17:59:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-05 14:14:55 +03:00
|
|
|
|
// return event value for right mouse button
|
2013-02-14 17:59:12 +04:00
|
|
|
|
int GetRightMouseButtonClickEvent(BOOL down)
|
|
|
|
|
{
|
2016-08-05 14:14:55 +03:00
|
|
|
|
if (g_swap_mouse_buttons)
|
|
|
|
|
return (PTR_FLAGS_BUTTON1 | (down ? PTR_FLAGS_DOWN : 0));
|
|
|
|
|
else
|
|
|
|
|
return (PTR_FLAGS_BUTTON2 | (down ? PTR_FLAGS_DOWN : 0));
|
2013-02-14 17:59:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get mouse move event
|
|
|
|
|
int GetMouseMoveEvent()
|
|
|
|
|
{
|
2016-08-05 14:14:55 +03:00
|
|
|
|
return (PTR_FLAGS_MOVE);
|
2013-02-14 17:59:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// return mouse wheel event
|
|
|
|
|
int GetMouseWheelEvent(BOOL down)
|
|
|
|
|
{
|
2016-08-05 14:14:55 +03:00
|
|
|
|
if (g_invert_scrolling)
|
|
|
|
|
down = !down;
|
|
|
|
|
|
|
|
|
|
if (down)
|
|
|
|
|
return (PTR_FLAGS_WHEEL | PTR_FLAGS_WHEEL_NEGATIVE | (0x0088));
|
|
|
|
|
else
|
|
|
|
|
return (PTR_FLAGS_WHEEL | (0x0078));
|
2013-02-14 17:59:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// scrolling gesture detection delta
|
|
|
|
|
CGFloat GetScrollGestureDelta()
|
|
|
|
|
{
|
2016-08-05 14:14:55 +03:00
|
|
|
|
return 10.0f;
|
2013-02-14 17:59:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// this hack activates the iphone's WWAN interface in case it is offline
|
|
|
|
|
void WakeUpWWAN()
|
|
|
|
|
{
|
2016-08-05 14:14:55 +03:00
|
|
|
|
NSURL* url = [[[NSURL alloc] initWithString:
|
|
|
|
|
@"http://www.nonexistingdummyurl.com"] autorelease];
|
|
|
|
|
//NSData * data =
|
|
|
|
|
[NSData dataWithContentsOfURL:
|
|
|
|
|
url]; // we don't need data but assigning one causes a "data not used" compiler warning
|
2013-02-14 17:59:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark System Info functions
|
|
|
|
|
|
2016-08-05 14:14:55 +03:00
|
|
|
|
NSString* TSXGetPrimaryMACAddress(NSString* sep)
|
2013-02-14 17:59:12 +04:00
|
|
|
|
{
|
2016-08-05 14:14:55 +03:00
|
|
|
|
NSString* macaddress = @"";
|
|
|
|
|
struct ifaddrs* addrs;
|
|
|
|
|
|
|
|
|
|
if (getifaddrs(&addrs) < 0)
|
|
|
|
|
{
|
|
|
|
|
NSLog(@"getPrimaryMACAddress: getifaddrs failed.");
|
|
|
|
|
return macaddress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (struct ifaddrs* cursor = addrs; cursor != NULL; cursor = cursor->ifa_next)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp(cursor->ifa_name, "en0"))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if ((cursor->ifa_addr->sa_family == AF_LINK)
|
|
|
|
|
&& (((struct sockaddr_dl*) cursor->ifa_addr)->sdl_type == 0x6 /*IFT_ETHER*/))
|
|
|
|
|
{
|
|
|
|
|
struct sockaddr_dl* dlAddr = (struct sockaddr_dl*) cursor->ifa_addr;
|
|
|
|
|
|
|
|
|
|
if (dlAddr->sdl_alen != 6)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
unsigned char* base = (unsigned char*) &dlAddr->sdl_data[dlAddr->sdl_nlen];
|
|
|
|
|
macaddress = [NSString hexStringFromData:base ofSize:6 withSeparator:sep
|
|
|
|
|
afterNthChar:1];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
freeifaddrs(addrs);
|
|
|
|
|
return macaddress;
|
2013-02-14 17:59:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOL TSXDeviceHasJailBreak()
|
|
|
|
|
{
|
2016-08-05 14:14:55 +03:00
|
|
|
|
if ([[NSFileManager defaultManager] fileExistsAtPath:
|
|
|
|
|
@"/Applications/Cydia.app/"])
|
|
|
|
|
return YES;
|
2013-02-14 17:59:12 +04:00
|
|
|
|
|
2016-08-05 14:14:55 +03:00
|
|
|
|
if ([[NSFileManager defaultManager] fileExistsAtPath:@"/etc/apt/"])
|
|
|
|
|
return YES;
|
2013-02-14 17:59:12 +04:00
|
|
|
|
|
2016-08-05 14:14:55 +03:00
|
|
|
|
return NO;
|
2013-02-14 17:59:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSString* TSXGetPlatform()
|
|
|
|
|
{
|
2016-08-05 14:14:55 +03:00
|
|
|
|
size_t size;
|
|
|
|
|
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
|
|
|
|
|
char* machine = malloc(size);
|
|
|
|
|
sysctlbyname("hw.machine", machine, &size, NULL, 0);
|
|
|
|
|
NSString* platform = [NSString stringWithCString:machine encoding:
|
|
|
|
|
NSASCIIStringEncoding];
|
|
|
|
|
free(machine);
|
|
|
|
|
return platform;
|
2013-02-14 17:59:12 +04:00
|
|
|
|
}
|
|
|
|
|
|