A Startup Subscript: Checking version/platform/device

Funny how a new platform (FileMaker Go for iPad, in this case) helps you tighten your code design. While putting together the Charting on the iPad demo file (updated), naturally I rewrote the subscript that checks versions at file start to include mobile devices. For each variation it can specify minimum version and whether to enforce, allow/advise, or deny any access. The script is more modular and easily extensible by app version, OS, OS version, or device form factor. It has four parts, essentially:

1. You decide your desired behavior rules:

# Whether to advise & allow, enforce version, or deny ANY access
# ( 0 or null=ignore, 1=advise but allow, 2=enforce version, 
#   3=deny ANY access, 4=unsupported platform but allow )

# Min version & enforcement level of FM Go for iPad
Set Variable [ $minVersion_FMGo_iPad; Value:"1.0" ]
Set Variable [ $enforceLevel_FMGo_iPad; Value:1 ]
# 
# Min version & enforcement level of FM Go (for iPhone)
Set Variable [ $minVersion_FMGo_iPhone; Value:"99" //will assure test fail ]
Set Variable [ $enforceLevel_FMGo_iPhone; Value:4 ]
etc., etc., etc.

2. Then you query the computing environment:

Set Variable [ $$savvy_currentAppPlatForm; Value:Let( [
vApp = Get( ApplicationVersion ) ;
vLen = Length( vApp ) ;
vLastSpace = Position( vApp ; " " ; vLen ; -1 ) ;
vAppName = Left( vApp ; vLastSpace - 1 ) ;
vAppVersion = Right( vApp ; vLen - vLastSpace ) ;
vPlatform = Choose ( Abs( Get( SystemPlatform )) ;"";"Mac OS X";"Windows";"iOS") ;
vPlatVersion = Get ( SystemVersion ) ;
vAppNameFormal = Case (
   etc., etc., etc. )

3. Next, test reality against the rules (I like how that sounds, in general):

If [ PatternCount($currentAppType ; "Pro" )
   and
   Abs( $currentAppVersion ) < Abs( $minVersion_FMPro ) ]
   Set Variable [ $failedversionTest; Value:1 //true ]
   Set Variable [ $enforceLevel; Value:$minVersionEnforce_FMPro ]
#
Else If [ PatternCount($currentAppType ; "iPad" )
   and
   Abs( $currentAppVersion ) < Abs( $minVersion_FMGo_iPad ) ]
   Set Variable [ $failedversionTest; Value:1 //true ]
   Set Variable [ $enforceLevel; Value:$minVersionEnforce_FMGo_iPad ]
#
Else If [ PatternCount($currentAppType ; "iPad" )
   Set Variable [ $failedversionTest; Value:0 //not True per prior If ]
#
Else If [ PatternCount($currentAppType ;  "Go" /*(for iPhone)*/ )
   and
   Abs( $currentAppVersion ) < Abs( $minVersion_FMGo_iPhone ) ]
   Set Variable [ $failedversionTest; Value:1 //true ]
   Set Variable [ $enforceLevel; Value:$minVersionEnforce_FMGo_iPhone ]
#
End If

4. And finally enforce/allow/deny and inform the user, as applicable:

If [ not IsEmpty( $failedVersionTest ) ]
   #
   Set Variable [ $minVersion; Value:Case(
      $failedVersionTest = "Pro" ; $minVersion_FMPro ;
      $failedVersionTest = "iPad" ; $minVersion_FMGo_iPad ;
      $failedVersionTest = "Go" ; $minVersion_FMGo_iPhone ;
      $failedVersionTest = "Web" ; $minVersion_Web ;
      "unknown" ) ]
   #
   If [ $enforceLevel = 3 // 3=deny ANY access ]
      Show Custom Dialog [ Title: "Unsupported Platform"; 
      Message: "This file is not designed to run on FileMaker " &
         $currentAppType & ". File will now Close."; Buttons: “OK” ]
      Close File [ Current File ]
      #
   Else If [ $enforceLevel = 2 // 2=enforce version ]
      Show Custom Dialog [ Title: "Version Alert"; 
      Message: "This file requires FileMaker " & $currentAppType & " version " &
         $minVersion & " or higher. File will now Close."; Buttons: “OK” ]
      Close File [ Current File ]
      #
   Else If [ $enforceLevel = 1 // 1=advise version but allow ]
      Show Custom Dialog [ Title: "Version Advisory"; 
      Message: "This file requires FileMaker " & $currentAppType & " version " &
         $minVersion & " or higher. Open anyway or Close?"; Buttons: “Close”, “Open” ]
      If [ Get(LastMessageChoice) = 1 ]
         Close File [ Current File ]
      End If
      #
   Else If [ $enforceLevel = 4 // 4=unsupported platform but allow ]
      Show Custom Dialog [ Title: "Unsupported Platform"; 
      Message: "This file is not optimized to run on FileMaker " &
         $currentAppType & ". Open anyway or Close?"; Buttons: “Close”, “Open” ]
      If [ Get(LastMessageChoice) = 1 ]
         Close File [ Current File ]
      End If
      #
   Else
      # "nothing to see here... move along"
   End If
End If

Like I said, modular and extensible — just how I'd like all my code to be (and still working it...). You can grab the PDF of the script, or download one of our demo files that includes it, such as ChartingWithWebTech.fp7 via its blog posting.

Enjoy, and let me know what you think,

-Lee

Post a comment.