#include-once #RequireAdmin #include #include #include ; #FUNCTION# ==================================================================================================================== ; Name...........: _RightPath ; Description ...: Performs version comparison between two files ; Syntax.........: _RightPath($sFullPath = 0, $sSingleton = 0) ; Parameters ....: $sFullPath - full qualified path's file ; $sSingleton - singleton string's file ; Return values .: Success - Execute the script/app ; Failure - 1 at least one or more input terms is empty ; | 2 script is not compiled ; | 3 input drive is not real or error ; | 4 error on close proccess ; Author ........: Detefon ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: _RightPath("C:\Program Files (x86)\alfa\try.exe", $SINGLETON) ; =============================================================================================================================== Func _RightPath($sFullPath = 0, $sSingleton = 0) If Not @Compiled Then Return SetError(2, 0, 0) If Not $sFullPath Or Not $sSingleton Then Return SetError(1, 0, 0) Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = "" Local $aPathSplit = _PathSplit($sFullPath, $sDrive, $sDir, $sFilename, $sExtension) Local $iSingleton = _Singleton($sSingleton, 1) If Not IsDeclared("__FULL_PATH") Then Global $__FULL_PATH = $sDrive & $sDir If Not IsDeclared("__APP") Then Global $__APP = $sFilename & $sExtension If (@ScriptFullPath == $__FULL_PATH & $__APP) Then Switch $iSingleton Case 0 Exit Case Else Return 1 EndSwitch EndIf Local $aDrives = DriveGetDrive("FIXED") If _ArraySearch($aDrives, $sDrive) == -1 Then Return SetError(3, 0, 0) Local $iCompare = __FileVersionCompare($__FULL_PATH & $__APP, @ScriptFullPath) Local $iAttempts = 0 If $iCompare == 3 Then If $iSingleton == 0 Then Local $PID = ProcessExists($__APP) ProcessClose($PID) Do Sleep(1000) $iAttempts += 1 If $iAttempts > 20 Then Return SetError(4, 0, 0) Until Not ProcessExists($PID) EndIf FileDelete($__FULL_PATH & $__APP) DirCreate($__FULL_PATH) FileCopy(@ScriptFullPath, $__FULL_PATH & $__APP, 1 + 8) OnAutoItExitRegister("__RightPath_ExecOnExit") EndIf If $iSingleton Then OnAutoItExitRegister("__RightPath_ExecOnExit") Exit EndFunc ;==>_RightPath ; #FUNCTION# ==================================================================================================================== ; Name...........: __FileVersionCompare ; Description ...: Performs version comparison between two files ; Syntax.........: __FileVersionCompare($file1, $file2) ; Parameters ....: $file1 - path's file1 ; $file2 - path's file2 ; Return values .: Success - Integer: 1, 2 Or 3 ; | 1 $file1 is greater ; | 2 $file1 and $file2 is equal ; | 3 $file2 is greater ; Failure - None ; Author ........: Detefon ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __FileVersionCompare($file1 = 0, $file2 = 0) If FileExists($file1) Then $file1 = FileGetVersion($file1) Else $file1 = "0.0.0.0" EndIf If FileExists($file2) Then $file2 = FileGetVersion($file2) Else $file2 = "0.0.0.0" EndIf $file1 = StringSplit($file1, ".", 2) $file2 = StringSplit($file2, ".", 2) For $ii = 0 To 3 $file1[$ii] = Number($file1[$ii]) $file2[$ii] = Number($file2[$ii]) Next If $file1[0] == $file2[0] And $file1[1] == $file2[1] And $file1[2] == $file2[2] And $file1[3] == $file2[3] Then Return 2 If $file1[0] > $file2[0] Then Return 1 If $file1[0] >= $file2[0] And $file1[1] > $file2[1] Then Return 1 If $file1[0] >= $file2[0] And $file1[1] >= $file2[1] And $file1[2] > $file2[2] Then Return 1 If $file1[0] >= $file2[0] And $file1[1] >= $file2[1] And $file1[2] >= $file2[2] And $file1[3] > $file2[3] Then Return 1 Return 3 EndFunc ;==>__FileVersionCompare ; #FUNCTION# ==================================================================================================================== ; Name...........: __FileVersionCompare ; Description ...: Performs version comparison between two files ; Syntax.........: __FileVersionCompare($file1, $file2) ; Parameters ....: $file1 - path's file1 ; $file2 - path's file2 ; Return values .: Success - Integer: 1, 2 Or 3 ; | 1 $file1 is greater ; | 2 $file1 and $file2 is equal ; | 3 $file2 is greater ; Failure - None ; Author ........: Detefon ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __RightPath_ExecOnExit() ShellExecute($__APP, "", $__FULL_PATH) EndFunc ;==>__RightPath_ExecOnExit