#RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=.\Icon\add2.ico #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_OutFile_X64=AppendVersion_x64.exe #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Res_Comment=Free for Personal and Commercial use. #AutoIt3Wrapper_Res_Description=Append File Properties Version Number To File Name #AutoIt3Wrapper_Res_FileVersion_AutoIncrement=y #AutoIt3Wrapper_Res_Fileversion_First_Increment=y #AutoIt3Wrapper_Res_Fileversion=1.0.3.525 #AutoIt3Wrapper_Res_ProductVersion=1.0.3 #AutoIt3Wrapper_Res_ProductName=AppendVersion_x64.exe #AutoIt3Wrapper_Res_CompanyName=Prizm Adventures #AutoIt3Wrapper_Res_LegalCopyright=Free for Personal and Commercial Use #AutoIt3Wrapper_Res_Language=1033 #AutoIt3Wrapper_Res_Field=Written and maintained by|David James #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 #AutoIt3Wrapper_Run_Tidy=y #Tidy_Parameters=/tc 4 /ri /reel /sf #Au3Stripper_Parameters=/so /rm #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** Opt("MustDeclareVars", 1) Opt('TrayMenuMode', 1) #include If _Singleton(@ScriptName, 1) = 0 Then Exit #include #include #include #include #include #include #include #include #include #include ;Define Global variables Global $Pre_ver, $Pre_pver, $Pre_uver Global Const $No_fver = "0.0.0.0" Global Const $No_fpver = "0.0.0" Global Const $INI_Dir = @ScriptDir & "\Settings.ini" __Main() Func __Main() Local $f_Drive, $f_Dir, $f_Name, $f_Ext, $TargetDir, $sFileVersion, $sFileProdVersion, $CurrFileName, $FingerPrint, $ZippedFileSel, $scArray, $targArray Local $sc_Drive, $sc_Dir, $sc_Name, $sc_Ext Local $ValidInp, $PassThru, $gMsg Local $guiVersionNumber, $tversionnumber, $bOKV, $bCancelV, $bExitV Local $hGuiMain _Import_INI_Settings() ; Check for a SendTo link for AppendVersion. Create if not found. _Check_SendTo_LNK() For $i = 1 To $CmdLine[0] If _WinAPI_PathIsDirectory($CmdLine[$i]) Then $targArray = _FileListToArrayRec($CmdLine[$i], _ "*.exe;*.msi;*.lnk;*.zip;*.7z;*.rar;*.tar|Uninstall*;Documents*;Videos*;Music*;Pictures*;Recycle Bin*;SendTo*|Windows System*", _ $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, 2) If @error = 1 Then ContinueLoop ;~ _ArrayDisplay($targArray, "Folder contents") Else Dim $targArray[2] = [1, $CmdLine[$i]] EndIf ; Process each file in the argument parameters supplied For $k = 1 To $targArray[0] ;Does each file supplied actually exist? If FileExists($targArray[$k]) Then $f_Drive = "" $f_Dir = "" $f_Name = "" $f_Ext = "" $TargetDir = "" $sFileVersion = "" $sFileProdVersion = "" $CurrFileName = "" $FingerPrint = "" $ZippedFileSel = "" _PathSplit($targArray[$k], $f_Drive, $f_Dir, $f_Name, $f_Ext) $TargetDir = $f_Drive & $f_Dir If $f_Ext = ".zip" Or $f_Ext = ".7z" Or $f_Ext = ".rar" Or $f_Ext = ".tar" Then RunWait('"' & @ScriptDir & "\peazip\peazip.exe" & '"' & ' -ext2smart -o ' & '"' & @ScriptDir & "\UnZip" & '"' & ' -i ' & '"' & $targArray[$k] & '"', "") If FileExists(@ScriptDir & "\UnZip") Then $ZippedFileSel = StringStripWS(FileOpenDialog("Contents of: " & $f_Name & $f_Ext, @ScriptDir & "\UnZip", "All (*.*) | Executable (*.exe;*.msi)", $FD_FILEMUSTEXIST), 3) FileChangeDir(@ScriptDir) If $ZippedFileSel <> "" Then $FingerPrint = StringStripWS(FileGetVersion($ZippedFileSel, $FV_INTERNALNAME) & FileGetVersion($ZippedFileSel, $FV_ORIGINALFILENAME) & FileGetVersion($ZippedFileSel, $FV_PRODUCTNAME) & _ FileGetVersion($ZippedFileSel, $FV_COMPANYNAME) & FileGetVersion($ZippedFileSel, $FV_FILEDESCRIPTION) & FileGetVersion($ZippedFileSel, $FV_LEGALTRADEMARKS) & _ FileGetVersion($ZippedFileSel, $FV_COMMENTS) & FileGetVersion($ZippedFileSel, "DefaultLangCodePage"), 8) $sFileVersion = StringStripWS(FileGetVersion($ZippedFileSel), 3) $sFileProdVersion = StringStripWS(FileGetVersion($ZippedFileSel, $FV_PRODUCTVERSION), 3) DirRemove(@ScriptDir & "\UnZip", 1) Else DirRemove(@ScriptDir & "\UnZip", 1) ContinueLoop EndIf Else MsgBox($MB_SETFOREGROUND + $MB_TOPMOST + $MB_TASKMODAL, "Settings File Creation Error", "The UnZip folder could not be created to extract the " & $targArray[$k] & " file to.") ContinueLoop EndIf ElseIf $f_Ext = ".lnk" Then $scArray = FileGetShortcut($targArray[$k]) _PathSplit($scArray[0], $sc_Drive, $sc_Dir, $sc_Name, $sc_Ext) If Not @error Then If Not IsAdmin() And (($f_Drive & $f_Dir = @ProgramsDir & "\") Or ($f_Drive & $f_Dir = @ProgramsCommonDir & "\")) Then MsgBox($MB_SETFOREGROUND + $MB_TOPMOST + $MB_TASKMODAL, "Administrator Privilege Required", "You do not have full administrator privilege to rename shortcuts in the folders:" & @CRLF & @CRLF & _ @ProgramsDir & @CRLF & @CRLF & @ProgramsCommonDir & @CRLF & @CRLF & "Run AppendVersion as an Administrator to rename these Start Menu links.") ContinueLoop ElseIf $sc_Ext = ".exe" Or $sc_Ext = ".msi" Then $FingerPrint = StringStripWS(FileGetVersion($scArray[0], $FV_INTERNALNAME) & FileGetVersion($scArray[0], $FV_ORIGINALFILENAME) & FileGetVersion($scArray[0], $FV_PRODUCTNAME) & _ FileGetVersion($scArray[0], $FV_COMPANYNAME) & FileGetVersion($scArray[0], $FV_FILEDESCRIPTION) & FileGetVersion($scArray[0], $FV_LEGALTRADEMARKS) & _ FileGetVersion($scArray[0], $FV_COMMENTS) & FileGetVersion($scArray[0], "DefaultLangCodePage"), 8) $sFileVersion = StringStripWS(FileGetVersion($scArray[0]), 3) $sFileProdVersion = StringStripWS(FileGetVersion($scArray[0], $FV_PRODUCTVERSION), 3) Else ContinueLoop EndIf Else MsgBox($MB_SETFOREGROUND + $MB_TOPMOST + $MB_TASKMODAL, "Shortcut Error", "The shortcut " & $targArray[$k] & " could not be accessed.") ContinueLoop EndIf ElseIf $f_Ext = ".exe" Or $f_Ext = ".msi" Then $FingerPrint = StringStripWS(FileGetVersion($targArray[$k], $FV_INTERNALNAME) & FileGetVersion($targArray[$k], $FV_ORIGINALFILENAME) & FileGetVersion($targArray[$k], $FV_PRODUCTNAME) & _ FileGetVersion($targArray[$k], $FV_COMPANYNAME) & FileGetVersion($targArray[$k], $FV_FILEDESCRIPTION) & FileGetVersion($targArray[$k], $FV_LEGALTRADEMARKS) & _ FileGetVersion($targArray[$k], $FV_COMMENTS) & FileGetVersion($targArray[$k], "DefaultLangCodePage"), 8) $sFileVersion = StringStripWS(FileGetVersion($targArray[$k]), 3) $sFileProdVersion = StringStripWS(FileGetVersion($targArray[$k], $FV_PRODUCTVERSION), 3) Else ContinueLoop EndIf If $sFileVersion = $No_fver Or $sFileVersion = "" Then ; empty or no file version. Look for product version number instead If $sFileProdVersion = $No_fpver Or $sFileProdVersion = $No_fver Or $sFileProdVersion = "" Then ; empty or no file or product version $hGuiMain = GUICreate("Enter File Version Number", 342, 310, -1, -1) _GUICtrlRichEdit_Create($hGuiMain, "Enter the published file version number for file:" & @CRLF & @CRLF & $targArray[$k] & @CRLF & @CRLF & _ "The file version number must be in the format:" & @CRLF & @CRLF & " #.#.#.#" & @CRLF & @CRLF & "Each # value cannot exceed 65535" & @CRLF & @CRLF & _ "Press Cancel to skip renaming this file.", 11, 8, 320, 180, BitOR($ES_READONLY, $ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL), $WS_EX_TRANSPARENT) $tversionnumber = GUICtrlCreateInput("0.0.0.0", 42, 210, 248, 20, -1, $WS_EX_STATICEDGE) GUICtrlSetTip(-1, "Enter File Version Number") $bOKV = GUICtrlCreateButton("OK", 17, 260, 50, 30, $BS_DEFPUSHBUTTON) $bCancelV = GUICtrlCreateButton("Cancel", 144, 260, 50, 30) $bExitV = GUICtrlCreateButton("Exit", 272, 260, 50, 30) GUISetState(@SW_SHOW) GUICtrlSetData($tversionnumber, "0.0.0.0") GUICtrlSetState($tversionnumber, $GUI_FOCUS) While 1 $gMsg = GUIGetMsg() Switch $gMsg Case $bOKV $sFileVersion = StringStripWS(GUICtrlRead($tversionnumber), 8) _Check_Valid_Input($ValidInp, $sFileVersion) If $ValidInp Then ; If user entered a valid File Version number $PassThru = False _Base_Name($f_Name, $f_Ext, $PassThru, $FingerPrint, $scArray, "File Version: ", $sFileVersion) If Not $PassThru Then ;$PassThru variable passed back from Base name cancellation $CurrFileName = $f_Name & $Pre_uver & $sFileVersion & $f_Ext _Rename_File($TargetDir, $CurrFileName, $targArray[$k]) ExitLoop EndIf EndIf GUICtrlSetData($tversionnumber, "0.0.0.0") GUICtrlSetState($tversionnumber, $GUI_FOCUS) Case $bCancelV ExitLoop Case $bExitV Exit Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($guiVersionNumber) Else ; If valid Product Version number exists $PassThru = False _Base_Name($f_Name, $f_Ext, $PassThru, $FingerPrint, $scArray, "Product Version: ", $sFileProdVersion) If Not $PassThru Then $CurrFileName = $f_Name & $Pre_pver & $sFileProdVersion & $f_Ext _Rename_File($TargetDir, $CurrFileName, $targArray[$k]) EndIf EndIf Else ; If valid File Version number exists $PassThru = False _Base_Name($f_Name, $f_Ext, $PassThru, $FingerPrint, $scArray, "File Version: ", $sFileVersion) If Not $PassThru Then $CurrFileName = $f_Name & $Pre_ver & $sFileVersion & $f_Ext _Rename_File($TargetDir, $CurrFileName, $targArray[$k]) EndIf EndIf Else MsgBox($MB_SETFOREGROUND + $MB_TOPMOST + $MB_TASKMODAL, "File Not Found", "The argument file parameter:" & @CRLF & @CRLF & $targArray[$k] & @CRLF & @CRLF & _ "passed to the script could not be found.") EndIf Next Next MsgBox($MB_SETFOREGROUND + $MB_TOPMOST + $MB_TASKMODAL, "AppendVersion Operations Completed", "All operations have completed.", 20) EndFunc ;==>__Main ; Create new basename(s) from the examined file or link name. If validated name, add to the $INI_Dir [BaseNames] section Func _Base_Name(ByRef $f_Name, $f_Ext, ByRef $PassThru, $FingerPrint, $scArray, $VerType, $VerNumber) Local $NewBaseName, $InBaseNames, $nMsg, $Foundv, $Foundpv, $Founduv, $bArray, $StrLen, $aArray, $foundBN, $hFileOpen, $SplitArr, $Match, $filler Local $guiBaseName, $tbasename, $bCreateBaseName, $bUseOrigFN, $bCancelB, $hEditBaseName, $lb_BaseNameList, $bresetInput, $hEditFingerprint, $bExitB, $bHelp $InBaseNames = False $bArray = IniReadSection($INI_Dir, "BaseNames") If @error = 0 Then ;$INI_Dir [BaseNames] section exists and is populated For $b = 1 To $bArray[0][0] $SplitArr = StringSplit($bArray[$b][0], ":", 1) If @error = 1 Then ;no delimiter. Assign $f_Name to all of $bArray[$b][0] If StringInStr($f_Name, $bArray[$b][0], 0, 1, 1) > 0 Then $InBaseNames = True $f_Name = $bArray[$b][0] ExitLoop EndIf Else ;has delimiter that separates partial base names to match portions of $f_Name $Match = True For $i = 1 To $SplitArr[0] If StringInStr($f_Name, $SplitArr[$i]) = 0 Then $Match = False ExitLoop EndIf Next If $Match And $bArray[$b][1] = $FingerPrint Then $InBaseNames = True $f_Name = $SplitArr[1] & $SplitArr[2] ExitLoop EndIf EndIf Next Else ; [BaseNames] sections does not exist, or [BaseNames] section is empty ;check that [BaseNames] exists $foundBN = False $aArray = IniReadSectionNames($INI_Dir) If Not @error Then For $i = 1 To $aArray[0] If $aArray[$i] = "BaseNames" Then $foundBN = True ExitLoop EndIf Next EndIf If Not $foundBN Then ; create [BaseNames] section $hFileOpen = FileOpen($INI_Dir, $FO_APPEND) FileWrite($INI_Dir, @CRLF) FileClose($hFileOpen) IniWriteSection($INI_Dir, "BaseNames", "") EndIf EndIf If Not $InBaseNames Then ; Prompt user to create new base name(s) from $f_Name $guiBaseName = GUICreate("Create Base Names", 848, 550, -1, -1) $tbasename = GUICtrlCreateInput($f_Name, 19, 344, 530, 21) GUICtrlSetFont(-1, 10, $FW_BOLD, 0, "Arial") $bresetInput = GUICtrlCreateButton("Reset To Current Filename", 410, 316, 140, 20) GUICtrlSetFont(-1, 8, $FW_NORMAL, 0, "Arial") $bHelp = GUICtrlCreateButton("?", 555, 345, 18, 18) GUICtrlSetFont(-1, 8, $FW_NORMAL, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xC5D6E7) GUICtrlCreateLabel("Configure Base Name(s):", 19, 316, 340, 20) GUICtrlSetFont(-1, 10, $FW_NORMAL, 0, "Arial") $bCreateBaseName = GUICtrlCreateButton("Create", 29, 490, 49, 33, $BS_DEFPUSHBUTTON) GUICtrlSetFont(-1, 8, $FW_NORMAL, 0, "Arial") $bUseOrigFN = GUICtrlCreateButton("Use Current File's name", 120, 490, 129, 33) GUICtrlSetFont(-1, 8, $FW_NORMAL, 0, "Arial") $bCancelB = GUICtrlCreateButton("Cancel / Next", 292, 490, 72, 33) GUICtrlSetFont(-1, 8, $FW_NORMAL, 0, "Arial") $bExitB = GUICtrlCreateButton("Exit", 471, 490, 49, 33) GUICtrlSetFont(-1, 8, $FW_NORMAL, 0, "Arial") $lb_BaseNameList = GUICtrlCreateList("", 580, 32, 247, 490, BitOR($GUI_SS_DEFAULT_LIST, $WS_HSCROLL)) GUICtrlSetBkColor($lb_BaseNameList, 0xfafad2) GUICtrlSetFont(-1, 8, $FW_NORMAL, 0, "Arial") GUICtrlCreateLabel("Existing Base Names:", 580, 10, 134, 20) GUICtrlSetFont(-1, 10, $FW_NORMAL, 0, "Arial") GUICtrlCreateLabel("Current File's Fingerprint:", 19, 380, 340, 20) GUICtrlSetFont(-1, 10, $FW_NORMAL, 0, "Arial") $hEditFingerprint = _GUICtrlRichEdit_Create($guiBaseName, $FingerPrint, 19, 404, 530, 60, BitOR($ES_READONLY, $ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL), $WS_EX_CLIENTEDGE) _GUICtrlRichEdit_SetBkColor($hEditFingerprint, 0xeeeeee) If $f_Ext = ".lnk" Then $filler = " " & $f_Name & $f_Ext & " points to:" & @CRLF & @CRLF & " " & $scArray[0] & @CRLF & @CRLF & " " & $VerType & $VerNumber Else $filler = " " & $f_Name & $f_Ext & @CRLF & @CRLF & " " & $VerType & $VerNumber EndIf $hEditBaseName = _GUICtrlRichEdit_Create($guiBaseName, "Unless you opt to stick with the currrent file's name to append the file's version number to, " & _ "base names must be substrings within the current file's name." & @CRLF & @CRLF & $filler & @CRLF & @CRLF & "Once base names are set, base names will be used in renaming this file. " & _ "Base names will be used in automatically identifying later file versions and in renaming them with little or no user interaction." & @CRLF & @CRLF & "This will work " & _ "just as long as the base names remain substrings in the file name of future file versions AND the 'fingerprinted' properties of future file versions does " & _ "not change. File properties and base names that do not usually change from one file version to the next are used in fingerprinting, file identification and renaming.", _ 8, 11, 556, 290, BitOR($ES_READONLY, $ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL), $WS_EX_TRANSPARENT) _GUICtrlRichEdit_SetSel($hEditBaseName, 1, -1, True) _GUICtrlRichEdit_SetFont($hEditBaseName, 10, "Arial") $bArray = IniReadSection($INI_Dir, "BaseNames") If @error = 0 Then _ArraySort($bArray, 0, 1) ;populate $lb_BaseNameList with keys (base name(s)) from sorted $bArray For $b = 1 To $bArray[0][0] GUICtrlSetData($lb_BaseNameList, @CRLF & $bArray[$b][0]) Next EndIf GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $bCreateBaseName $NewBaseName = StringStripWS(GUICtrlRead($tbasename), 3) If $NewBaseName <> "" Then $SplitArr = StringSplit($NewBaseName, ":", 1) If @error = 1 Then If StringInStr($f_Name, $NewBaseName, 0, 1, 1) > 0 Then $f_Name = $NewBaseName ; write new key and value to $INI_Dir [BaseNames] section IniWrite($INI_Dir, "BaseNames", $f_Name, $FingerPrint) ; reload $bArray with new values $bArray = IniReadSection($INI_Dir, "BaseNames") _ArraySort($bArray, 0, 1) ; re-write the sorted $bArray back to $INI_Dir [BaseNames] section IniWriteSection($INI_Dir, "BaseNames", $bArray) ExitLoop Else ; Prompt user that the base name entered is not a substring in $f_Name MsgBox($MB_SETFOREGROUND + $MB_TOPMOST + $MB_TASKMODAL, "Match Error", "The base name entered:" & @CRLF & @CRLF & _ $NewBaseName & @CRLF & @CRLF & "is NOT a substring in " & $f_Name & @CRLF & @CRLF & "Try again.") GUICtrlSetData($tbasename, $f_Name) GUICtrlSetState($tbasename, $GUI_FOCUS) EndIf Else $Match = True For $i = 1 To $SplitArr[0] If StringInStr($f_Name, $SplitArr[$i]) = 0 Then $Match = False ; Prompt user that the base name entered is not a substring in $f_Name MsgBox($MB_SETFOREGROUND + $MB_TOPMOST + $MB_TASKMODAL, "Match Error", "The partial base name entered:" & @CRLF & @CRLF & _ $SplitArr[$i] & @CRLF & @CRLF & "is NOT a substring in " & $f_Name & @CRLF & @CRLF & "Try again.") GUICtrlSetData($tbasename, $f_Name) GUICtrlSetState($tbasename, $GUI_FOCUS) ExitLoop EndIf Next If $Match Then $f_Name = $SplitArr[1] & $SplitArr[2] ; write new key and value to $INI_Dir [BaseNames] section IniWrite($INI_Dir, "BaseNames", $SplitArr[1] & ":" & $SplitArr[2], $FingerPrint) ; reload $bArray with new values $bArray = IniReadSection($INI_Dir, "BaseNames") _ArraySort($bArray, 0, 1) ; re-write the sorted $bArray back to $INI_Dir [BaseNames] section IniWriteSection($INI_Dir, "BaseNames", $bArray) ExitLoop EndIf EndIf Else ; Prompt user that the base name entered is an empty string MsgBox($MB_SETFOREGROUND + $MB_TOPMOST + $MB_TASKMODAL, "Empty Entry", "The base name entered is an empty entry." & @CRLF & @CR & "Try again.") GUICtrlSetData($tbasename, $f_Name) GUICtrlSetState($tbasename, $GUI_FOCUS) EndIf Case $lb_BaseNameList ; display selected $lb_BaseNameList entry's $Fingerprint. If empty, listbox selection is ignored For $b = 1 To $bArray[0][0] If StringStripWS(GUICtrlRead($lb_BaseNameList), 3) = $bArray[$b][0] Then MsgBox($MB_SETFOREGROUND + $MB_TOPMOST + $MB_TASKMODAL, "Fingerprint: " & $bArray[$b][0], $bArray[$b][1]) EndIf Next Case $bresetInput ; reset $tbasename input to the original file name GUICtrlSetData($tbasename, $f_Name) Case $bUseOrigFN ; Do not create a base name from $f_Name. Instead, use the original $f_Name to append the version number to. ; strip off any existing quotedprefixed version numbers before appending a new prefix version number to file name $Foundv = StringInStr($f_Name, $Pre_ver, 0, -1) $Foundpv = StringInStr($f_Name, $Pre_pver, 0, -1) $Founduv = StringInStr($f_Name, $Pre_uver, 0, -1) $StrLen = StringLen($f_Name) ; Ensure that at least one character exists in the file name before trimming the prefix away. If $Foundv > 1 And $StrLen > 8 Then $f_Name = StringTrimRight($f_Name, $StrLen - $Foundv + 1) ElseIf $Foundpv > 1 And $StrLen > 8 Then $f_Name = StringTrimRight($f_Name, $StrLen - $Foundpv + 1) ElseIf $Founduv > 1 And $StrLen > 8 Then $f_Name = StringTrimRight($f_Name, $StrLen - $Founduv + 1) EndIf ExitLoop Case $bHelp ShellExecute(@ScriptDir & "\ReadMe.pdf", "", "", $SHEX_OPEN) Case $bCancelB ; Cancel the operation and skip renaming operation. $PassThru = True ExitLoop Case $bExitB Exit Case $GUI_EVENT_CLOSE $PassThru = True ExitLoop EndSwitch WEnd GUIDelete($guiBaseName) EndIf EndFunc ;==>_Base_Name ; Check that an AppendVersion SendTo link exists. If not, create it. Func _Check_SendTo_LNK() Local $arrtest, $lnkDir, $CreateRslt = 0 ; SendTo folder path link $lnkDir = @AppDataDir & "\Microsoft\Windows\SendTo\Append File Version.lnk" ; Test for existent link in SendTo folder $arrtest = FileGetShortcut($lnkDir) If @error Then ;No link found ; Create link in SendTo folder $CreateRslt = FileCreateShortcut(@ScriptDir & "\AppendVersion_x64.exe", $lnkDir, @HomeDrive & @HomePath & _ "\Downloads", "", "Append File Version to File Name", @ScriptDir & "\AppendVersion_x64.exe", "", "0", @SW_SHOWNORMAL) ; If link could not be created (0), prompt user If $CreateRslt = 0 Then MsgBox($MB_SETFOREGROUND + $MB_TOPMOST + $MB_TASKMODAL, "Link Creation Error", "Could not create a SendTo link for AppendVersion") Exit Else ; Link created! Display newly created link details. $arrtest = FileGetShortcut($lnkDir) MsgBox($MB_SETFOREGROUND + $MB_TOPMOST + $MB_TASKMODAL, "SendTo Link Created", "A shortcut has been created in the SendTo menu for AppendVersion." & @CRLF & _ "The link creation is a one-time event that only occurs the very first time that you run AppendVersion_x64 with or without " & _ "argument parameters." & @CRLF & @CRLF & _ "Shorcut Details:" & @CRLF & @CRLF & _ "File Path: " & $arrtest[0] & @CRLF & @CRLF & _ "Working Directory: " & $arrtest[1] & @CRLF & @CRLF & _ "Arguments: " & $arrtest[2] & @CRLF & @CRLF & _ "Description: " & $arrtest[3] & @CRLF & @CRLF & _ "Icon Filename: " & $arrtest[4] & @CRLF & @CRLF & _ "Icon Index: " & $arrtest[5] & @CRLF & @CRLF & _ "Shortcut State: " & $arrtest[6]) EndIf EndIf EndFunc ;==>_Check_SendTo_LNK ; Check that version number entered must be a valid "0.0.0" or "0.0.0.0" format If not, return $ValidInp=False ; ProdVersion max values: [255.255.65535] FileVersion max values: [65535.65535.65535.65535] ; "." is delimiter, test user entered $sFileVersion format Func _Check_Valid_Input(ByRef $ValidInp, $sFileVersion) Local $SplitArr If $sFileVersion <> $No_fver And $sFileVersion <> $No_fpver And $sFileVersion <> "" Then ;values are not empty $SplitArr = StringSplit($sFileVersion, ".", 1) If Not @error And $SplitArr[0] = 4 Then For $i = 1 To 4 If StringIsDigit($SplitArr[$i]) Then If $SplitArr[$i] >= 0 And $SplitArr[$i] <= 65535 Then $ValidInp = True Else MsgBox($MB_SETFOREGROUND + $MB_TOPMOST + $MB_TASKMODAL, "Numeric Value Entry Error", "The entered file version number '" & $sFileVersion & _ "' has a numeric value of: '" & $SplitArr[$i] & "' that is not within the allowable range of 0 to 65535.") $ValidInp = False ExitLoop EndIf Else MsgBox($MB_SETFOREGROUND + $MB_TOPMOST + $MB_TASKMODAL, "Non-Numeric Entry Error", "The entered file version number '" & $sFileVersion & _ "' contains non-numeric characters: '" & $SplitArr[$i] & "'.") $ValidInp = False ExitLoop EndIf Next Else MsgBox($MB_SETFOREGROUND + $MB_TOPMOST + $MB_TASKMODAL, "Non-Numeric Entry Error", "The entered file version number '" & $sFileVersion & "' is not formatted correctly.") $ValidInp = False EndIf Else MsgBox($MB_SETFOREGROUND + $MB_TOPMOST + $MB_TASKMODAL, "Format Entry Error", "The entered file version number '" & $sFileVersion & "' cannot be all zeroes nor be empty." & @CRLF & _ @CRLF & "You can press the Cancel button to skip renaming this file for now, until you can acquire the published file version number.") $ValidInp = False EndIf EndFunc ;==>_Check_Valid_Input ; Import $INI_Dir settings, or create the INI file if it does not exist and populate it with default sections, keys and values Func _Import_INI_Settings() Local $hFileOpen ; If the 'Settings.ini' file does not exist, set some user modifiable default version prefixes If Not FileExists($INI_Dir) Then IniWrite($INI_Dir, "QuotedPreFix", "fver", """ - fver_ """) ;File Version number prefix, default prefix IniWrite($INI_Dir, "QuotedPreFix", "pver", """ - pver_ """) ;Product Version number prefix, used when no file version number exists in file properites IniWrite($INI_Dir, "QuotedPreFix", "uver", """ - uver_ """) ;User Version number prefix, when no file or product version numbers exist in file properties $hFileOpen = FileOpen($INI_Dir, $FO_APPEND) FileWrite($INI_Dir, @CRLF) FileClose($hFileOpen) IniWriteSection($INI_Dir, "BaseNames", "") $Pre_ver = IniRead($INI_Dir, "QuotedPreFix", "fver", " - ver_ ") $Pre_pver = IniRead($INI_Dir, "QuotedPreFix", "pver", " - pver_ ") $Pre_uver = IniRead($INI_Dir, "QuotedPreFix", "uver", " - uver_ ") MsgBox($MB_SETFOREGROUND + $MB_TOPMOST + $MB_TASKMODAL, "Info", "A 'Settings.ini' file has been created in the script's directory, preset with version number prefixes:" & @CRLF & @CRLF & _ "'" & $Pre_ver & "' File version prefix, preferred when a file version number exists in the file's properties." & @CRLF & @CRLF & "'" & $Pre_pver & _ "' Product version prefix, fallback when no file version number exists in the file's properties." & @CRLF & @CRLF & "'" & $Pre_uver & _ "' User entered file version prefix, used when neither file nor product version numbers exist in the file's properties" & @CRLF & _ @CRLF & "These three prefixes can be edited in Settings.ini to meet your formatting preferences.") Else $Pre_ver = IniRead($INI_Dir, "QuotedPreFix", "fver", " - fver_ ") $Pre_pver = IniRead($INI_Dir, "QuotedPreFix", "pver", " - pver_ ") $Pre_uver = IniRead($INI_Dir, "QuotedPreFix", "uver", " - uver_ ") EndIf EndFunc ;==>_Import_INI_Settings ; Rename the file with the chosen base name(s) and the appropriate appended file version number with correct prefix-format Func _Rename_File($TargetDir, $CurrFileName, $TargetFullPath) Local $NewPath $NewPath = $TargetDir & $CurrFileName FileMove($TargetFullPath, $NewPath, 1) If Not FileExists($NewPath) Then MsgBox($MB_SETFOREGROUND + $MB_TOPMOST + $MB_TASKMODAL, "File Renaming Error", $TargetFullPath & @CRLF & @CRLF & "could not be renamed to" & @CRLF & @CRLF & $NewPath) EndIf EndFunc ;==>_Rename_File