Jump to content
Sunblood

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 :)


Share this post


Link to post
Share on other sites
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Fileversion=2.2.2.2
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Constants.au3>

Const $VERSION = @Compiled ? FileGetVersion(@ScriptName) : StringRegExp(FileRead(@ScriptName),"#AutoIt3Wrapper_Res_Fileversion=(.*)", 1)[0]

MsgBox ($MB_SYSTEMMODAL, "", $VERSION)

This ?

Share this post


Link to post
Share on other sites
Posted (edited)
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Posted (edited)

Perfecterer

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_FileVersion=2.3.4.5 ; test
#AutoIt3Wrapper_Outfile_type=a3x
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#pragma compile(Out, Temp1.a3x)
#pragma compile(Fileversion, 2.3.4.5)

#include <Constants.au3>

Const $VERSION = @Compiled ? FileGetVersion(@ScriptName) : StringRegExp(FileRead(@ScriptName),"(?i)#AutoIt3Wrapper_Res_Fileversion=(.*?)\h*[;|\v]", 1)[0]

MsgBox ($MB_SYSTEMMODAL, "", $VERSION)

 

Edited by Nine
added support to case insensitive

Share this post


Link to post
Share on other sites
Posted (edited)

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

Share this post


Link to post
Share on other sites

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...