[futurebasic] Re: [FB] Software version check

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

From: Bernie <fblist.bw@...>
Date: Thu, 9 Oct 2014 06:56:48 +0100
Brian wrote:

> 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
> '-----------------------

Neat. Thanks Brian.

I realise above is quick demo but when implemented in final app suggest checking for NULL string returned from CreateStringFromURL (due to no internet connection, etc) or app will crash.

Also, suggest checking if valid version number returned. If url does not exist, myStr will probably contain an html 404 document.