Versioning on the About menu option

Versioning on the About menu option

Postby reinaldocrespo » Fri Jan 06, 2012 4:58 pm

Hi.

I find that offering versioning information from the about option on the menu is a must for any serious application. Many times you are never too sure how old is the app where bugs are being reported or it is hard to determine what release a user is executing.

In an attempt to solve this matter, I wrote a small app that reads from the file directory the footprint left by svn declaring the subversion number of any svn update and/or commit. The script would read the svn info to then write version.ch which is inclueded on the app. Using xMate user command option, the script gets executed upon a successful built. So, you had the inconvenience of having to build a release twice but that worked well.

Image

Recently I upgraded my svn client. They changed how svn information is stored and my script no longer works. Furthermore, it seems like a daunting task trying to decipher how exactly svn numbers are stored. So I've been searching for other ways. I came across a small utility that can patch your .exe with version information. You can google verpatch.

Using VerPatch you can add resource version information to your compiled exe. By just adding a short script (batch file) to be executed upon successful link from xmate you can patch the .exe with version info. Here is my batch file:
Code: Select all  Expand view

set VERSION="10.0.0"
set FILEDESCR=/s desc "PathLabs Main Module"
set BUILDINFO=/s pb "Built by %USERNAME%"
set COMPINFO=/s company "Structured Systems Corp" /s (c) "(c) Copyright Reinaldo Crespo-Bazán -all rights reserved 2011"
set PRODINFO=/s product "PathLabs10" /pv "10.0 %date% %time%"

f:\mp10\verpatch-bin-1.0.9\verpatch /va f:\mp\PathLabs10.exe %VERSION% %FILEDESCR% %COMPINFO% %PRODINFO% %BUILDINFO%
 


Using %date% and %time% I'm at least able to find a point in time when the release was built. Still not ideal, but it works automatically and it has the advantage of not needing to build a final release twice.

Can someone advise how to read version resource information so that it can be displayed on the about dialog?

Can someone here suggest how to read svn numbers from the repository or directory as it is now being stored (sqlite db)?

Thank you,


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Versioning on the About menu option

Postby reinaldocrespo » Fri Jan 06, 2012 6:39 pm

Here is that link to VerPatch webpage.

http://www.codeproject.com/KB/install/V ... sg=3207401



Reinaldo.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Versioning on the About menu option

Postby fivewin » Fri Jan 06, 2012 7:56 pm

Hello,

Insert at your .rc file:


1 VERSIONINFO LOADONCALL MOVEABLE
FILEVERSION 2012, 0, 0, 0
PRODUCTVERSION 2012, 0, 0, 0
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_APP
{
BLOCK "StringFileInfo"
{
BLOCK "040904b0"
{
VALUE "CompanyName", "http://www.myweb.pt/\000"
VALUE "FileDescription", "Test sample\000"
VALUE "FileVersion", "2012\000"
VALUE "LegalCopyright", "(c) Me\000"
VALUE "LegalTrademarks", "(c) Me\000"
VALUE "ProductName", "Flota\000"
VALUE "ProductVersion", "2012\000"
}

}

BLOCK "VarFileInfo"
{
VALUE "Translation", 1033, 1200
}

}
fivewin
 
Posts: 4
Joined: Wed Jan 04, 2012 8:00 pm

Re: Versioning on the About menu option

Postby reinaldocrespo » Fri Jan 06, 2012 8:05 pm

Thank you. Not the solution I'm looking for.

You see, that is static information. It does not change with each compile. You would have to go change it manually each time. Far from ideal and I'm sure there are better ways to spend programmer's time. Specially if you are maintaining may projects at once.

At any rate, I did find a way to retrieve svn numbers by simply using the svn command svnversion -n. In short, just have a batch file to execute svnversin -n >> svn.txt, then a short script can receive the output as input to produce svn.ch with the correct #DEFINE information.




Reinaldo.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Versioning on the About menu option

Postby fivewin » Fri Jan 06, 2012 8:21 pm

Reinaldo,

You could create a prg that changes that number.

See for example:

Code: Select all  Expand view
// Just for FWH 32 bits

#include "FiveWin.ch"

//----------------------------------------------------------------------------//

function Main()

   local n

   for n = 1 to 12
    //   MsgInfo( GetFileVersionInfo( "filever.exe", n ), cvaltochar(n) )
   next

   MsgInfo( GetFileVersionInfo( "filever.exe", 13 ), cvaltochar(n) )

return nil

//----------------------------------------------------------------------------//


#pragma BEGINDUMP

#include "hbapi.h"
#include "windows.h"

HB_FUNC( GETFILEVERSIONINFO )
{
   char * szFile  = hb_parc( 1 );
   UINT uAction   = HB_ISNUM( 2 ) ? hb_parni( 2 ) : 1;
   DWORD dwHandle = 0;
   DWORD dwSize   = GetFileVersionInfoSize( szFile, &dwHandle );
   char * szOut   = NULL;
   BOOL  bOk      = FALSE;

   if( dwSize )
   {
      char * szBlock = ( char * ) hb_xgrab( 255 );
      char * szSubBlock = ( char * ) hb_xgrab( 255 );
      HGLOBAL hMem = GlobalAlloc( GMEM_MOVEABLE, dwSize );
      VS_FIXEDFILEINFO * vsInfo;
      UINT nLen = 0;

      if( hMem )
      {
         LPVOID pMem = GlobalLock( hMem );

         if( pMem && GetFileVersionInfo( szFile, dwHandle, dwSize, pMem ) )
         {
            if( VerQueryValue( pMem, "\\VarFileInfo\\Translation", ( LPVOID * ) &vsInfo, &nLen ) )
            {
               *( LPDWORD ) vsInfo = MAKELONG( HIWORD( *( LPDWORD ) vsInfo ), LOWORD( *( LPDWORD ) vsInfo ) );

               sprintf( szBlock, "\\StringFileInfo\\%08lx\\", *( LPDWORD )( vsInfo ) );

               switch( uAction )
               {
                  case 1:
                     sprintf( szSubBlock, "%s%s", szBlock, "Comments" );
                     break;

                  case 2:
                     sprintf( szSubBlock, "%s%s", szBlock, "CompanyName" );
                     break;

                  case 3:
                     sprintf( szSubBlock, "%s%s", szBlock, "FileDescription" );
                     break;

                  case 4:
                     sprintf( szSubBlock, "%s%s", szBlock, "FileVersion" );
                     break;

                  case 5:
                     sprintf( szSubBlock, "%s%s", szBlock, "InternalName" );
                     break;

                  case 6:
                     sprintf( szSubBlock, "%s%s", szBlock, "LegalCopyright" );
                     break;

                  case 7:
                     sprintf( szSubBlock, "%s%s", szBlock, "LegalTrademarks" );
                     break;

                  case 8:
                     sprintf( szSubBlock, "%s%s", szBlock, "OriginalFilename" );
                     break;

                  case 9:
                     sprintf( szSubBlock, "%s%s", szBlock, "PrivateBuild" );
                     break;

                  case 10:
                     sprintf( szSubBlock, "%s%s", szBlock, "ProductName" );
                     break;

                  case 11:
                     sprintf( szSubBlock, "%s%s", szBlock, "ProductVersion" );
                     break;

                  case 12:
                     sprintf( szSubBlock, "%s%s", szBlock, "SpecialBuild" );
                     break;

                  case 13:
                     sprintf( szSubBlock, "%s%s", szBlock, "FILEVERSION" );
                     break;
               }

               if( VerQueryValue( pMem, szSubBlock, ( LPVOID * ) &szOut, &nLen ) )
                  bOk = TRUE;

               hb_xfree( szBlock );
               hb_xfree( szSubBlock );
            }

            GlobalUnlock( hMem );
            GlobalFree( hMem );
         }
      }
   }

   if( bOk )
      hb_retc( szOut );
   else
      hb_retc( "" );
}

#pragma ENDDUMP

//----------------------------------------------------------------------------//


 




.rc file

Code: Select all  Expand view
// RESOURCE SCRIPT generated by "Pelles C for Windows, version 2.90".

LANGUAGE LANG_SPANISH,SUBLANG_SPANISH_MODERN

#define fv "2012.6.6.6\0"
#define fv2 2012,6,6,6
#define pv "2012\0"




VS_VERSION_INFO VERSIONINFO
//FILEVERSION 2012,11,1,2
//PRODUCTVERSION 2012,0,0,0
FILEVERSION fv2
FILEFLAGSMASK 0x3F
FILEFLAGS 0x0
FILEOS VOS__WINDOWS32
FILETYPE VFT_APP
FILESUBTYPE VFT2_UNKNOWN
BEGIN
  BLOCK "StringFileInfo"
  BEGIN
    BLOCK "040904B0"
    BEGIN
      VALUE "Comments", "This is a test to manage FileVersion resource\0"
      VALUE "CompanyName", "FiveTech Software\0"
      VALUE "FileDescription", "FileVer.prg demo\0"
      VALUE "FileVersion", fv
      VALUE "InternalName", "FileVer.prg / FileVer.rc\0"
      VALUE "LegalCopyright", "www.fivetechsoft.com\0"
      VALUE "LegalTrademarks", "FiveTech Software S.L.\0"
      VALUE "OriginalFilename", "FileVer.prg\0"
      VALUE "ProductName", "FileVer.prg demo\0"
      VALUE "ProductVersion", pv //"0.0.0.0\0"
    END
  END
  BLOCK "VarFileInfo"
  BEGIN
    VALUE "Translation", 0x409, 0x4B0
  END
END

 
fivewin
 
Posts: 4
Joined: Wed Jan 04, 2012 8:00 pm

Re: Versioning on the About menu option

Postby reinaldocrespo » Fri Jan 06, 2012 11:07 pm

Thank you. Actually filever.prg on the samples directory gave me an idea. This solution is a mix of three inputs working to produce a versioning control system. Hoping this will help others, I share the idea. Setting up an svn repository is not complicated, you only need to do it once, and it is free. Google svn to read more on the subject.

Here is the batch file that gets executed after each successful link from xmate:

Code: Select all  Expand view


cd \mp10\pathlabs\
REM set WC_PATH=f:\mp10\PathLabs\
REM ----------------------------------------------------------
REM     svn number gets written into svn.txt  
REM
    svnversion -n>\mp10\pathlabs\include\svn.txt
REM
REM---------------------------------------------------
REM
REM Environmental var VERSION is set from svn.txt
REM
    SET /P VERSION=<\mp10\pathlabs\include\svn.txt
    SET VERSION=10.0.%VERSION%
REM
    sET FILEDESCR=/s desc "PathLabs Main Module"
    sET BUILDINFO=/s pb "Built by %USERNAME%"
    sET COMPINFO=/s company "Structured Systems Corp." /s (c) "(c) Copyright Reinaldo Crespo-Bazán -all rights reserved 2011"
    sET PRODINFO=/s product "PathLabs10" /pv "%VERSION%" /sc "Built on %date% %time%"
REM
REM
REM verPatch burns these values into .exe
    f:\mp10\verpatch-bin-1.0.9\verpatch f:\mp\PathLabs10.exe /va %VERSION% %FILEDESCR% %COMPINFO% %PRODINFO% %BUILDINFO%
REM
REM
REM f:\mp10\mySvnVer f:\mp10\pathlabs\include\svn.txt f:\mp10\pathlabs\
 


You will need to store your code on an svn repository and VerPatch from code project (http://www.codeproject.com/KB/install/V ... sg=3207401).

Now from inside the app all you need is a method/function to display version information:
Code: Select all  Expand view

FUNCTION ShowAboutDialog( cText, oOwner )

   LOCAL oDlg, nTop, nLeft
   LOCAL nClr1 := nRGB( 75, 144, 223 )
   LOCAL nClr2 := nRGB( 41, 85, 145 )
   LOCAL bCenterDlg, bNoMove
   LOCAL cExe     := cFileName( GetModuleFileName( GetInstance() ) )
   LOCAL cText2   := cValToChar( GetFileVersionInfo( cExe, 1 ) )

   DEFAULT oOwner := WndMain()

   DEFINE DIALOG oDlg ;
              OF oOwner;
        RESOURCE "About" ;
     TRANSPARENT ;
           COLOR CLR_WHITE , RGB(240,240,240)

   REDEFINE IMAGE ID 1000 RESOURCE "TopBar" OF oDlg

   REDEFINE SAY PROMPT cText ID 1 OF oDlg TRANSPARENT COLOR CLR_BLACK
   REDEFINE SAY PROMPT cText2 ID 3 OF oDlg TRANSPARENT COLOR CLR_BLACK
   REDEFINE BUTTONBMP ID 2 OF oDlg BITMAP "exit16" PROMPT "Ok" TEXTRIGHT ACTION oDlg:END()

   oDlg:lHelpIcon := .f.

   ACTIVATE DIALOG oDlg ON INIT oDlg:Center( oOwner ) ON MOVE oDlg:Center( oOwner )
   //Eval( bCenterDlg ) ON MOVE eval( bNOMove )

   RETURN NIL
 


As an added bonus, by burning versioning information into a built .exe avoids having to re-build the application twice.

Here is the result:

Image



Reinaldo.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 86 guests