[futurebasic] Re: [FB] Software version check

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 2014 : Group Archive : Group : All Groups

From: Brian S <fblistserve@...>
Date: Wed, 8 Oct 2014 22:22:51 -0700
On Oct 8, 2014, at 4:41 PM, Brian S <fblistserve@...> wrote:

> Loop through the array and apply the logic described above.

Here is the previous example with the simple loop search:

'-----------------------
include "ConsoleWindow"

local fn CreateStringFromURL( urlOnWeb as CFStringRef ) as CFStringRef
'~'1
dim as CFStringRef s  : s = _nil
beginCCode
    NSURLRequest  *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:(NSMutableString *)urlOnWeb]];
    NSURLResponse   *response = nil;
    NSError            *error = nil;
    NSData *data              = [NSURLConnection sendSynchronousRequest:urlRequest
                                                      returningResponse:&response
                                                                  error:&error];
    if (error == nil) {
          s = (CFStringRef)[[NSString alloc] initWithData:data
                                                 encoding:NSMacOSRomanStringEncoding];
    } else {
          // do something about the error
    }
endC

end fn = s

local fn IsVersionChanged ( strFromWeb as CFStringRef, compareStr as CFStringRef ) as Boolean
'~'1
dim as Boolean isChanged : isChanged = _false
beginCCode
    NSArray *arrayFromWeb = [(NSString *)strFromWeb componentsSeparatedByString:@"."]; 
    NSArray *compareArray = [(NSString *)compareStr componentsSeparatedByString:@"."];
    
    for (int i = 0; i <= 2; i++) {
        if ( ![[arrayFromWeb objectAtIndex:i] isEqualToString:[compareArray objectAtIndex:i]]) {
            isChanged = true;
            break;
        }
    }
endC

end fn = isChanged

local fn DoIt
'~'1
dim as CFStringRef myStr

myStr = fn CreateStringFromURL( @"http://www.brilorsoftware.com/demo_version.txt" )
fn ConsolePrintCFString( myStr )  // should show "3.9.4" which is a ficticious version #

//if ( fn IsVersionChanged ( myStr, @"3.9.4" ) ) then print "Changed" else print "Same"
if ( fn IsVersionChanged ( myStr, @"3.9.2" ) ) then print "Changed" else print "Same"
CFRelease( myStr )

end fn

fn DoIt
'-----------------------



Brian