]> git.saurik.com Git - cydia.git/blame - CyteKit/extern.mm
Ignore .dSYM folders I am suddenly ending up with.
[cydia.git] / CyteKit / extern.mm
CommitLineData
f3454874
JF
1/* Cydia - iPhone UIKit Front-End for Debian APT
2 * Copyright (C) 2008-2015 Jay Freeman (saurik)
3*/
4
5/* GNU General Public License, Version 3 {{{ */
6/*
7 * Cydia is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation, either version 3 of the License,
10 * or (at your option) any later version.
11 *
12 * Cydia is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Cydia. If not, see <http://www.gnu.org/licenses/>.
19**/
20/* }}} */
21
f4f6714a
JF
22#include <CyteKit/UCPlatform.h>
23
24#include <CyteKit/RegEx.hpp>
25#include <CyteKit/WebViewController.h>
f3454874 26#include <CyteKit/extern.h>
8658b2df
JF
27
28#include <SystemConfiguration/SystemConfiguration.h>
f3454874
JF
29#include <UIKit/UIKit.h>
30
f4f6714a
JF
31#include <sys/sysctl.h>
32
33#include <Menes/ObjectHandle.h>
34
f3454874
JF
35bool IsWildcat_;
36CGFloat ScreenScale_;
37
f4f6714a
JF
38char *Machine_;
39const char *System_;
40
8658b2df
JF
41bool CyteIsReachable(const char *name) {
42 SCNetworkReachabilityFlags flags; {
43 SCNetworkReachabilityRef reachability(SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, name));
44 SCNetworkReachabilityGetFlags(reachability, &flags);
45 CFRelease(reachability);
46 }
47
48 // XXX: this elaborate mess is what Apple is using to determine this? :(
49 // XXX: do we care if the user has to intervene? maybe that's ok?
50 return
51 (flags & kSCNetworkReachabilityFlagsReachable) != 0 && (
52 (flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0 || (
53 (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) != 0 ||
54 (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0
55 ) && (flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0 ||
56 (flags & kSCNetworkReachabilityFlagsIsWWAN) != 0
57 )
58 ;
59}
60
d60043e4 61void CyteInitialize(NSString *agent) {
f3454874
JF
62 UIScreen *screen([UIScreen mainScreen]);
63 if ([screen respondsToSelector:@selector(scale)])
64 ScreenScale_ = [screen scale];
65 else
66 ScreenScale_ = 1;
67
68 UIDevice *device([UIDevice currentDevice]);
69 if ([device respondsToSelector:@selector(userInterfaceIdiom)]) {
70 UIUserInterfaceIdiom idiom([device userInterfaceIdiom]);
71 if (idiom == UIUserInterfaceIdiomPad)
72 IsWildcat_ = true;
73 }
f4f6714a
JF
74
75 size_t size;
76
77 sysctlbyname("kern.osversion", NULL, &size, NULL, 0);
78 char *osversion = new char[size];
79 if (sysctlbyname("kern.osversion", osversion, &size, NULL, 0) == -1)
80 perror("sysctlbyname(\"kern.osversion\", ?)");
81 else
82 System_ = osversion;
83
84 sysctlbyname("hw.machine", NULL, &size, NULL, 0);
85 char *machine = new char[size];
86 if (sysctlbyname("hw.machine", machine, &size, NULL, 0) == -1)
87 perror("sysctlbyname(\"hw.machine\", ?)");
88 else
89 Machine_ = machine;
90
91 _H<NSString> product;
92 _H<NSString> safari;
93
94 if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:@"/Applications/MobileSafari.app/Info.plist"]) {
95 product = [info objectForKey:@"SafariProductVersion"] ?: [info objectForKey:@"CFBundleShortVersionString"];
96 safari = [info objectForKey:@"CFBundleVersion"];
97 }
98
d60043e4 99 agent = [NSString stringWithFormat:@"%@ CyF/%.2f", agent, kCFCoreFoundationVersionNumber];
f4f6714a 100
03191d51
JF
101 if (safari != nil)
102 if (RegEx match = RegEx("([0-9]+(\\.[0-9]+)+).*", safari))
103 agent = [NSString stringWithFormat:@"Safari/%@ %@", match[1], agent];
f4f6714a
JF
104 if (RegEx match = RegEx("([0-9]+[A-Z][0-9]+[a-z]?).*", System_))
105 agent = [NSString stringWithFormat:@"Mobile/%@ %@", match[1], agent];
03191d51
JF
106 if (product != nil)
107 if (RegEx match = RegEx("([0-9]+(\\.[0-9]+)+).*", product))
108 agent = [NSString stringWithFormat:@"Version/%@ %@", match[1], agent];
f4f6714a
JF
109
110 [CyteWebViewController setApplicationNameForUserAgent:agent];
f3454874 111}