Page 1 of 1

Return Own Program Version

Posted: Wed Apr 11, 2012 10:05 pm
by charvista
When I update a program, it is obvious to update the version number in Compiler/Compiler Options..., tab "Version Info".
1st question: is there a way to store the version number in a variable? (is there a #constant ?)
2nd question: what is the difference between "Program Version (n,n,n,n)" and "File Version (n,n,n,n)" ?
Thanks!

Re: Return Own Program Version

Posted: Wed Apr 11, 2012 11:12 pm
by jassing
Product version and file version can be different...
Your product might be 3.0.0.0 and a file version 3.0.1.0
or you could keep them the same.

They're also stored in the resources of the file; so you can just read your resources and store it..

Re: Return Own Program Version

Posted: Wed Apr 11, 2012 11:30 pm
by charvista
Jassing,
Thank you, I will keep both the product version and file version identical, but I still don't know the difference between them.
In the resources of the file... if you mean the "VersionField0" and "VersionField1" that is located at the bottom of the .pb file (not visible in the PB-editor), that's fine for running programs from the editor through the [F5] key, but where is it when the program is compiled in .exe?

I think I found a code in C# on the web, but I don't know how to write this in PB:

Code: Select all

    public static string Version
    {
        get
        {
            Assembly asm = Assembly.GetExecutingAssembly();
            FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location);
            return String.Format("{0}.{1}", fvi.ProductMajorPart, fvi.ProductMinorPart);
        }
    }

Re: Return Own Program Version

Posted: Wed Apr 11, 2012 11:40 pm
by xorc1zt
the difference come if you keep unchanged files from a previous version

example:

your app version 1.0
app.exe file version 1.0
app.dll file version 1.0

now if your next version just update app.exe so it will be like this

app version 1.1
app.exe file ver 1.1
app.dll file ver 1.0

Re: Return Own Program Version

Posted: Mon Mar 17, 2014 2:36 am
by yazak
The version is store in the .pbp in xml format you could read that file to get the version, I do find it strange their is know built in method like in VB6 you used App.Major , App.Minor, App.Revision to get version number parts of you own application.

Your could add the version number manually but you have to remember to update it when you change the version info in Compliler options ... Version INFO

;example how to add version manually this is how i do it
Global Version.s = "06.17.01.03"

Re: Return Own Program Version

Posted: Mon Mar 17, 2014 11:27 am
by Poltergeist
I'm using this piece of code I found somewhere:

Code: Select all

; GetFileVersionInfo exe/dll any language 

;/ gfvi.pb - GetFileVersionInfo for PureBasic 
;/ 2005-02-03 sverson v1.0
;/ 2008-06-13 sverson v2.0
;/  * PB 4.20 - OK
;/  * unicode - except Language!
;/ 2008-06-14 sverson v2.1
;/  * unicode - Language fixed
;/
;/ more info on this topic: 
;/ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/versioninformation.asp 

Enumeration;- element name keys 
  #GFVI_FileVersion      = $0001 
  #GFVI_FileDescription  = $0002 
  #GFVI_LegalCopyright   = $0004 
  #GFVI_InternalName     = $0008 
  #GFVI_OriginalFilename = $0010 
  #GFVI_ProductName      = $0020 
  #GFVI_ProductVersion   = $0040 
  #GFVI_CompanyName      = $0080 
  #GFVI_LegalTrademarks  = $0100 
  #GFVI_SpecialBuild     = $0200 
  #GFVI_PrivateBuild     = $0400 
  #GFVI_Comments         = $0800 
  #GFVI_Language         = $1000 
  #GFVI_All              = $1FFF 
EndEnumeration 

Procedure.s GFVI_GetElementName(elementKey.l);- get element name from key [gfvi] 
  If     elementKey = #GFVI_FileVersion      : ProcedureReturn "FileVersion" 
  ElseIf elementKey = #GFVI_FileDescription  : ProcedureReturn "FileDescription" 
  ElseIf elementKey = #GFVI_LegalCopyright   : ProcedureReturn "LegalCopyright" 
  ElseIf elementKey = #GFVI_InternalName     : ProcedureReturn "InternalName" 
  ElseIf elementKey = #GFVI_OriginalFilename : ProcedureReturn "OriginalFilename" 
  ElseIf elementKey = #GFVI_ProductName      : ProcedureReturn "ProductName" 
  ElseIf elementKey = #GFVI_ProductVersion   : ProcedureReturn "ProductVersion" 
  ElseIf elementKey = #GFVI_CompanyName      : ProcedureReturn "CompanyName" 
  ElseIf elementKey = #GFVI_LegalTrademarks  : ProcedureReturn "LegalTrademarks" 
  ElseIf elementKey = #GFVI_SpecialBuild     : ProcedureReturn "SpecialBuild" 
  ElseIf elementKey = #GFVI_PrivateBuild     : ProcedureReturn "PrivateBuild" 
  ElseIf elementKey = #GFVI_Comments         : ProcedureReturn "Comments" 
  ElseIf elementKey = #GFVI_Language         : ProcedureReturn "Language" 
  EndIf 
EndProcedure 

CompilerIf #PB_Compiler_Unicode
  Prototype.l GetFileVersionInfoSizeW(lptstrFilename.p-unicode, lpdwHandle.l)
  Prototype.l GetFileVersionInfoW(lptstrFilename.p-unicode, dwHandle.l, dwLen.l, lpData.l)
  Prototype.l VerQueryValueW(pBlock.l,lpSubBlock.p-unicode,lplpBuffer.l,puLen.w)
  Prototype.l VerLanguageNameW(wLang.l,szLang.p-unicode,cchLang.l) 
CompilerElse
  Prototype.l GetFileVersionInfoSizeA(lptstrFilename.p-ascii, lpdwHandle.l)
  Prototype.l GetFileVersionInfoA(lptstrFilename.p-ascii, dwHandle.l, dwLen.l, lpData.l)
  Prototype.l VerQueryValueA(pBlock.l,lpSubBlock.p-ascii,lplpBuffer.l,puLen.w)
  Prototype.l VerLanguageNameA(wLang.l,szLang.p-ascii,cchLang.l)  
CompilerEndIf


Procedure.s GFVI_GetInfo(lptstrFilename$,lekFlags,bFieldName);- get exe/dll file information [gfvi] 
  Protected lpdwHandle.l, dwLen.w, lpData.l, lplpBuffer.l, puLen.l, *pBlock, lpSubBlock$ 
  Protected nSize.w, szLang$, bBit.b, lekFlag.l, sElement$, sGFVI$ 
  
  lplpBuffer = 0 : puLen = 0 : sGFVI$ = "" : nSize = 128 : szLang$ = Space(nSize) 
  
  If FileSize(lptstrFilename$)>0 
    If OpenLibrary(1,"Version.dll") 
      CompilerIf #PB_Compiler_Unicode
        GetFileVersionInfoSize.GetFileVersionInfoSizeW = GetFunction(1,"GetFileVersionInfoSizeW")
        GetFileVersionInfo.GetFileVersionInfoW = GetFunction(1,"GetFileVersionInfoW")
        VerQueryValue.VerQueryValueW = GetFunction(1,"VerQueryValueW")
        VerLanguageName.VerLanguageNameW = GetFunction(1,"VerLanguageNameW")
      CompilerElse
        GetFileVersionInfoSize.GetFileVersionInfoSizeA = GetFunction(1,"GetFileVersionInfoSizeA")
        GetFileVersionInfo.GetFileVersionInfoA = GetFunction(1,"GetFileVersionInfoA")
        VerQueryValue.VerQueryValueA = GetFunction(1,"VerQueryValueA")
        VerLanguageName.VerLanguageNameA = GetFunction(1,"VerLanguageNameA")
      CompilerEndIf
      
      dwLen = GetFileVersionInfoSize(lptstrFilename$,@lpdwHandle) 
      If dwLen>0 
        *pBlock=AllocateMemory(dwLen) 
        If *pBlock>0 
          Result = GetFileVersionInfo(lptstrFilename$,0,dwLen,*pBlock) 
          If Result 
            lpSubBlock$ = "\\VarFileInfo\\Translation" 
            Result      = VerQueryValue(*pBlock,lpSubBlock$,@lplpBuffer,@puLen) 
            If Result 
              CPLI$  = RSet(Hex(PeekW(lplpBuffer)),4,"0")+RSet(Hex(PeekW(lplpBuffer+2)),4,"0") 
              VerLanguageName(PeekW(lplpBuffer),szLang$,nSize)
            EndIf 
            lekFlag = 1 
            For bBit = 1 To 12 
              If lekFlag & lekFlags 
                sElement$   = GFVI_GetElementName(lekFlag) 
                lpSubBlock$ = "\\StringFileInfo\\"+CPLI$+"\\"+sElement$ 
                Result      = VerQueryValue(*pBlock,lpSubBlock$,@lplpBuffer,@puLen)
                If Result 
                  If sGFVI$<>"" : sGFVI$+Chr(10) : EndIf 
                  If bFieldName 
                    sGFVI$=sGFVI$+sElement$+":"+Chr(9)+PeekS(lplpBuffer,puLen)
                  Else 
                    sGFVI$=sGFVI$+PeekS(lplpBuffer,puLen) 
                  EndIf 
                EndIf 
              EndIf 
              lekFlag << 1 
            Next 
            If lekFlag & lekFlags 
              If sGFVI$<>"" : sGFVI$+Chr(10) : EndIf 
              If bFieldName 
                sElement$ = GFVI_GetElementName(lekFlag) 
                sGFVI$    = sGFVI$+sElement$+":"+Chr(9)+szLang$
              Else 
                sGFVI$    = sGFVI$+szLang$
              EndIf 
            EndIf 
          EndIf 
          FreeMemory(*pBlock) 
        EndIf 
      EndIf 
      CloseLibrary(1) 
    EndIf 
  EndIf 
  ProcedureReturn sGFVI$ 
EndProcedure 
and use

Code: Select all

version.s=GFVI_GetInfo(ProgramFilename(),#GFVI_FileVersion,#False)
to get the version of the running executable...

Re: Return Own Program Version

Posted: Mon Mar 17, 2014 5:25 pm
by JackWebb
My understanding is that file version is the actual files (raw) version. Program version (MajorVersion and MinorVersion) is whatever you want it to be. It all depends on how you wish to keep track of things.. Nice thing about PB is that these numbers are updated for you automatically if you check them off in the compiler options menu. Well at least the build count and compile count. The major and minor revision you do manually. Again it all depends on how you keep track of your versions.

This works for me :)

Code: Select all

;VersionTest.pb
;  Under Compiler Options > Contants tab
;  Check #PB_Editor_CompileCount and #PB_Editor_BuildCount
;  Add a Custom Constant, #Version = 1.0. and set it just like that.
;  Make sure your new constant is checked
;

MessageRequester("Version Numbers", #version + Str(#pb_editor_buildcount) + "." + Str(#pb_editor_compilecount), #PB_MessageRequester_Ok )
Good Luck!
Jack 8)