summaryrefslogtreecommitdiff
path: root/CyteKit
diff options
context:
space:
mode:
authorJay Freeman (saurik) <saurik@saurik.com>2017-03-04 21:52:46 -0800
committerJay Freeman (saurik) <saurik@saurik.com>2017-03-04 21:52:46 -0800
commitf4f6714a329bf399840b3f9991b310bd17f7bed6 (patch)
tree63f2758b6de741020dcca8abe0d55146a4dfeddf /CyteKit
parent8511eb452e6188051960d2d96473a7810f85f5f2 (diff)
Try removing constructor (this is so annoying :/).
Diffstat (limited to 'CyteKit')
-rw-r--r--CyteKit/RegEx.hpp10
-rw-r--r--CyteKit/extern.h6
-rw-r--r--CyteKit/extern.mm49
3 files changed, 60 insertions, 5 deletions
diff --git a/CyteKit/RegEx.hpp b/CyteKit/RegEx.hpp
index 8892a3e..40068a7 100644
--- a/CyteKit/RegEx.hpp
+++ b/CyteKit/RegEx.hpp
@@ -58,14 +58,18 @@ class RegEx {
{
}
- RegEx(const char *regex, NSString *data = nil) :
+ RegEx(const char *regex) :
regex_(NULL),
size_(_not(size_t))
{
this->operator =(regex);
+ }
- if (data != nil)
- this->operator ()(data);
+ template <typename Type_>
+ RegEx(const char *regex, const Type_ &data) :
+ RegEx(regex)
+ {
+ this->operator ()(data);
}
void operator =(const char *regex) {
diff --git a/CyteKit/extern.h b/CyteKit/extern.h
index 12d0438..670f560 100644
--- a/CyteKit/extern.h
+++ b/CyteKit/extern.h
@@ -23,10 +23,16 @@
#define CyteKit_extern_H
#include <CoreGraphics/CoreGraphics.h>
+#include <Foundation/Foundation.h>
extern bool IsWildcat_;
extern CGFloat ScreenScale_;
+extern char *Machine_;
+extern const char *System_;
+
bool CyteIsReachable(const char *name);
+void CyteInitialize(NSString *app, NSString *version);
+
#endif//CyteKit_extern_H
diff --git a/CyteKit/extern.mm b/CyteKit/extern.mm
index cb8927a..aad3626 100644
--- a/CyteKit/extern.mm
+++ b/CyteKit/extern.mm
@@ -19,14 +19,25 @@
**/
/* }}} */
+#include <CyteKit/UCPlatform.h>
+
+#include <CyteKit/RegEx.hpp>
+#include <CyteKit/WebViewController.h>
#include <CyteKit/extern.h>
#include <SystemConfiguration/SystemConfiguration.h>
#include <UIKit/UIKit.h>
+#include <sys/sysctl.h>
+
+#include <Menes/ObjectHandle.h>
+
bool IsWildcat_;
CGFloat ScreenScale_;
+char *Machine_;
+const char *System_;
+
bool CyteIsReachable(const char *name) {
SCNetworkReachabilityFlags flags; {
SCNetworkReachabilityRef reachability(SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, name));
@@ -47,8 +58,7 @@ bool CyteIsReachable(const char *name) {
;
}
-__attribute__((__constructor__))
-void CyteKit_extern() {
+void CyteInitialize(NSString *app, NSString *version) {
UIScreen *screen([UIScreen mainScreen]);
if ([screen respondsToSelector:@selector(scale)])
ScreenScale_ = [screen scale];
@@ -61,4 +71,39 @@ void CyteKit_extern() {
if (idiom == UIUserInterfaceIdiomPad)
IsWildcat_ = true;
}
+
+ size_t size;
+
+ sysctlbyname("kern.osversion", NULL, &size, NULL, 0);
+ char *osversion = new char[size];
+ if (sysctlbyname("kern.osversion", osversion, &size, NULL, 0) == -1)
+ perror("sysctlbyname(\"kern.osversion\", ?)");
+ else
+ System_ = osversion;
+
+ sysctlbyname("hw.machine", NULL, &size, NULL, 0);
+ char *machine = new char[size];
+ if (sysctlbyname("hw.machine", machine, &size, NULL, 0) == -1)
+ perror("sysctlbyname(\"hw.machine\", ?)");
+ else
+ Machine_ = machine;
+
+ _H<NSString> product;
+ _H<NSString> safari;
+
+ if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:@"/Applications/MobileSafari.app/Info.plist"]) {
+ product = [info objectForKey:@"SafariProductVersion"] ?: [info objectForKey:@"CFBundleShortVersionString"];
+ safari = [info objectForKey:@"CFBundleVersion"];
+ }
+
+ NSString *agent([NSString stringWithFormat:@"%@/%@ CyF/%.2f", app, version, kCFCoreFoundationVersionNumber]);
+
+ if (RegEx match = RegEx("([0-9]+(\\.[0-9]+)+).*", safari))
+ agent = [NSString stringWithFormat:@"Safari/%@ %@", match[1], agent];
+ if (RegEx match = RegEx("([0-9]+[A-Z][0-9]+[a-z]?).*", System_))
+ agent = [NSString stringWithFormat:@"Mobile/%@ %@", match[1], agent];
+ if (RegEx match = RegEx("([0-9]+(\\.[0-9]+)+).*", product))
+ agent = [NSString stringWithFormat:@"Version/%@ %@", match[1], agent];
+
+ [CyteWebViewController setApplicationNameForUserAgent:agent];
}