Jump to content

Referencing #AutoIt3Wrapper_Res_Fileversion within the script


Recommended Posts

Is there any way for the script itself to reference the #AutoIt3Wrapper_Res_Fileversion as defined by AutoIt3Wrapper? To show the version number in a popup or tooltip, for example.

I realize I can just define and update my own $version variable but this is about automation, isn't it :)

Link to comment
Share on other sites

Link to comment
Share on other sites

8 minutes ago, argumentum said:

4096

perfecter :D

What is this magic number madness you call perfecter? :P

Edit: Btw, yours both fail if the user capitalizes Version in #AutoIt3Wrapper_Res_FileVersion. But I like this!

Edited by seadoggie01

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

Do you have a solution for using a3x files? It returns 0.0.0.0 since it is @Compiled and there is no version identifier

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

Link to comment
Share on other sites

ok, gloves off :P

Global Const $VERSION = GetScriptFileVersion()
ConsoleWrite('+++ $VERSION = ' & $VERSION & @TAB & ' -  Type:' & @extended & '  -  @ERROR: ' & @error & @CRLF)

Func GetScriptFileVersion($sFullPath = @ScriptFullPath, $UsePRODUCTVERSION = 0)
    ; https://www.autoitscript.com/forum/index.php?showtopic=205775&view=findpost&p=1481216
    Local $StrVersionType = $UsePRODUCTVERSION ? "PRODUCTVERSION" : "FILEVERSION"
    If Not FileGetSize($sFullPath) Then Return SetError(1, 0, "")
    If StringRight($sFullPath, 4) = ".exe" Then Return ValidFileVersionString(FileGetVersion($sFullPath, $StrVersionType))
    If StringRight($sFullPath, 4) = ".au3" Then
        Local $sPragma = "", $sWrapper = "", $aTemp, $n, $aArray = StringSplit(FileRead($sFullPath, 8192), @CRLF)
        For $n = 1 To UBound($aArray) - 1 ;                                                 reading 8k header should be enough, I hope
            $aArray[$n] = StringStripWS($aArray[$n], 8)
            If StringInStr($aArray[$n], "#AutoIt3Wrapper_Res_" & $StrVersionType & "=") = 1 Then ; last "Fileversion" found is used
                $aTemp = StringSplit($aArray[$n], "=;")
                If UBound($aTemp) < 3 Then ContinueLoop ; if commented out ";#AutoIt3Wrapper..." or ";#pragma ...", skip
                $sWrapper = ValidFileVersionString($aTemp[2], Int(Not $UsePRODUCTVERSION))
            EndIf
            If $sPragma = "" And StringInStr($aArray[$n], "#pragmacompile(" & $StrVersionType & ",") = 1 Then ; first "Fileversion" found is used
                $aTemp = StringSplit($aArray[$n], ",)")
                If UBound($aTemp) < 3 Then ContinueLoop
                $sPragma = ValidFileVersionString($aTemp[2], Int(Not $UsePRODUCTVERSION))
            EndIf
        Next
        If $sPragma <> "" Then Return SetError(0, 1, $sPragma) ; pragma supersedes wrapper (as in "rock paper scissors")
        If $sWrapper <> "" Then Return SetError(0, 2, $sWrapper)
        Return SetError(2, 0, "")
    EndIf
    Return SetError(3, 0, "")
EndFunc   ;==>GetScriptFileVersion

Func ValidFileVersionString($sStr, $iRedim = 1)
    Local $n, $sReturn = "", $aArray = StringSplit(StringReplace($sStr, ",", "."), ".", 2)
    If $iRedim Then ReDim $aArray[4] ;        Not the wrapper, nor Aut2exe, will accept comma separated.
    For $n = 0 To UBound($aArray) -1 ;  but could be used to get expected results. Ref.: https://www.autoitscript.com/forum/index.php?showtopic=205520
        If $n Then $sReturn &= "."
        $sReturn &= Int($aArray[$n])
    Next
    Return $sReturn
EndFunc   ;==>ValidFileVersionString

...what if, what if... .
Modified to get FileVersion as default, and optionally ProductVersion.

Edited by argumentum
better code

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...