project_files/HedgewarsMobile/Classes/CommodityFunctions.m
changeset 5483 fc755bb8096d
parent 5207 4c9ae0f484da
child 5486 e75f7c3c6275
equal deleted inserted replaced
5482:c047e70c53f4 5483:fc755bb8096d
    25 #import <mach/mach.h>
    25 #import <mach/mach.h>
    26 #import <mach/mach_host.h>
    26 #import <mach/mach_host.h>
    27 #import <QuartzCore/QuartzCore.h>
    27 #import <QuartzCore/QuartzCore.h>
    28 #import <AudioToolbox/AudioToolbox.h>
    28 #import <AudioToolbox/AudioToolbox.h>
    29 #import <CommonCrypto/CommonDigest.h>
    29 #import <CommonCrypto/CommonDigest.h>
       
    30 #import <SystemConfiguration/SCNetworkReachability.h>
       
    31 #import <netinet/in.h>
    30 #import "PascalImports.h"
    32 #import "PascalImports.h"
    31 #import "hwconsts.h"
    33 #import "hwconsts.h"
    32 
    34 
    33 
    35 
    34 NSInteger inline randomPort () {
    36 NSInteger inline randomPort () {
   124     [theLabel.layer setBorderColor:borderColor.CGColor];
   126     [theLabel.layer setBorderColor:borderColor.CGColor];
   125     [theLabel.layer setCornerRadius:8.0f];
   127     [theLabel.layer setCornerRadius:8.0f];
   126     [theLabel.layer setMasksToBounds:YES];
   128     [theLabel.layer setMasksToBounds:YES];
   127     
   129     
   128     return theLabel;
   130     return theLabel;
       
   131 }
       
   132 
       
   133 BOOL isNetworkReachable (void) {
       
   134     // Create zero addy
       
   135     struct sockaddr_in zeroAddress;
       
   136     bzero(&zeroAddress, sizeof(zeroAddress));
       
   137     zeroAddress.sin_len = sizeof(zeroAddress);
       
   138     zeroAddress.sin_family = AF_INET;
       
   139 
       
   140     // Recover reachability flags
       
   141     SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress);
       
   142     SCNetworkReachabilityFlags flags;
       
   143 
       
   144     BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags);
       
   145     CFRelease(defaultRouteReachability);
       
   146 
       
   147     if (!didRetrieveFlags) {
       
   148         NSLog(@"Error. Could not recover network reachability flags");
       
   149         return NO;
       
   150     }
       
   151 
       
   152     BOOL isReachable = flags & kSCNetworkFlagsReachable;
       
   153     BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired;
       
   154     BOOL nonWiFi = flags & kSCNetworkReachabilityFlagsTransientConnection;
       
   155 
       
   156     NSURL *testURL = [NSURL URLWithString:@"http://www.apple.com/"];
       
   157     NSURLRequest *testRequest = [NSURLRequest requestWithURL:testURL
       
   158                                                  cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
       
   159                                              timeoutInterval:20.0];
       
   160     NSURLConnection *testConnection = [[NSURLConnection alloc] initWithRequest:testRequest delegate:nil];
       
   161     BOOL testResult = testConnection ? YES : NO;
       
   162     [testConnection release];
       
   163 
       
   164     return ((isReachable && !needsConnection) || nonWiFi) ? testResult : NO;
   129 }
   165 }
   130 
   166 
   131 // this routine checks for the PNG size without loading it in memory
   167 // this routine checks for the PNG size without loading it in memory
   132 // https://github.com/steipete/PSFramework/blob/master/PSFramework%20Version%200.3/PhotoshopFramework/PSMetaDataFunctions.m
   168 // https://github.com/steipete/PSFramework/blob/master/PSFramework%20Version%200.3/PhotoshopFramework/PSMetaDataFunctions.m
   133 CGSize PSPNGSizeFromMetaData (NSString *aFileName) {
   169 CGSize PSPNGSizeFromMetaData (NSString *aFileName) {