#include #include '_ShellFile.au3' If @Compiled = 0 Then Exit MsgBox($MB_SYSTEMMODAL, '@Compiled Returned 0.', 'Please compile the program before testing. Thanks.') EndIf Func CompGetFileName($Path) ; https://www.sinister.ly/Thread-AutoIt-Get-File-Extension-Filename-and-Parent-directory-from-Path ;by 1234hotmaster If StringLen($Path) < 4 Then Return -1 $ret = StringSplit($Path,"\",2) If IsArray($ret) Then Return $ret[UBound($ret)-1] EndIf If @error Then Return -1 EndFunc _Main() Func _Main() Local $sFilePath = '' If $CmdLine[0] > 0 Then $sFilePath = $CmdLine[1] EndIf Local $hGUI = GUICreate('vYouOpen - GUI', 370, 210) GUICtrlCreateEdit(_GetFile($sFilePath), 10, 5, 350, 120) ; If a file was passed via commandline then random text will appear in the GUICtrlCreateEdit(). Local $iAdd = GUICtrlCreateButton('Add FileType', 10, 180, 75, 25) Local $iRemove = GUICtrlCreateButton('Remove FileType', 90, 180, 95, 25) Local $iClipboard = GUICtrlCreateButton('Copy to clipboard', 190, 180, 105, 25) Local $iOpenlink = GUICtrlCreateButton('Open URL', 300, 180, 65, 25) GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iAdd _ShellFile_Install('vYouOpen - GUI', 'mkv') ; Add the running EXE to the Shell ContextMenu. If @error Then MsgBox($MB_SYSTEMMODAL, 'Association NOT Created.', '".autoit" was not associated due to an error occurring.') Else MsgBox($MB_SYSTEMMODAL, 'Association Created.', '"RandomFile.autoit" file was created to show that the filetype ".autoit" has been associtated with ' & @ScriptName & '.' & @CRLF & "Do not delete or remove this .exe file without previously disabling the association!!!" & @CRLF & @CRLF & 'If you restart the computer you''ll see the icon of "RandomFile.autoit" is the same as the program icon.' & @CRLF & @CRLF & 'Now close the program and double/right click on "RandomFile.autoit" to display the random text in the edit box.') EndIf _SetFile(_RandomText(5000), @ScriptDir & '\RandomFile.autoit', 1) ; Create a file with Random text. Case $iRemove _ShellFile_Uninstall('mkv') ; Remove the running EXE from the Shell ContextMenu. If @error Then MsgBox($MB_SYSTEMMODAL, 'Association NOT Deleted.', '".autoit" was not deleted from the Registry due to an error occurring.') Else MsgBox($MB_SYSTEMMODAL, 'Association Deleted.', '".autoit" was successfully deleted from the Registry and is no longer associated with ' & @ScriptName & '.') EndIf Case $iClipboard if IsDeclared("ytURL") then ClipPut($ytURL) else MsgBox($MB_SYSTEMMODAL, "Failed", "ytURL not defined or could not be generated") endif Case $iOpenlink if IsDeclared("ytURL") then ShellExecute($ytURL) Exit(0) else MsgBox($MB_SYSTEMMODAL, "Failed", "ytURL not defined or could not be generated") endif EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>_Main Func _GetFile($sFilePath, $sFormat = 0) Local $hFileOpen = FileOpen($sFilePath, $sFormat) If $hFileOpen = -1 Then Return SetError(1, 0, 'No File Was Passed Via Commandline.') EndIf FileClose($hFileOpen) Local $fileName = CompGetFileName($sFilePath) Local $sData = "File name: " & $fileName & @CRLF local $mathmax1 = StringInStr($fileName, " ", 0, -1) local $mathmax2 = StringInStr($fileName, ")", 0, -1) local $firstSpace if $mathmax1 > $mathmax2 and $mathmax1 <> 0 then $firstSpace = $mathmax1 else $firstSpace = $mathmax2 endif if $firstSpace == 0 then $firstSpace = 1 endif $sData = $sData & "First space position: " & $firstSpace & @CRLF Local $firstHyphen = StringInStr($fileName, "-", 0, 1, $firstSpace) if $firstHyphen == 0 then Return SetError(1, 0, 'No Hyphen found.') endif Local $extensionDot = StringInStr($fileName, ".", 0, -1) if $extensionDot == 0 then Return SetError(1, 0, 'No Dot found.') endif $sData = $sData & "Dot Position: " & $extensionDot & @CRLF Local $VID = StringMid($fileName, $firstHyphen + 1, $extensionDot - $firstHyphen - 1 ) $sData = $sData & "Video ID: " & $VID & @CRLF Global $ytURL = "https://www.youtube.com/watch?v=" & $VID $sData = $sData & "URL: " & $ytURL Return $sData EndFunc ;==>_GetFile Func _RandomText($iLength = 7) Local $iCount = 0, $iCRLF, $sData = '', $sRandom For $i = 1 To $iLength $sRandom = Random(55, 116, 1) If $iCount = 100 Then $iCRLF = @CRLF $iCount = 0 EndIf $sData &= Chr($sRandom + 6 * ($sRandom > 90) - 7 * ($sRandom < 65)) & $iCRLF $iCount += 1 $iCRLF = '' Next Return $sData EndFunc ;==>_RandomText Func _SetFile($sString, $sFilePath, $iOverwrite = 0) Local $hFileOpen = FileOpen($sFilePath, $iOverwrite + 1) FileWrite($hFileOpen, $sString) FileClose($hFileOpen) If @error Then Return SetError(1, 0, $sString) EndIf Return $sString EndFunc ;==>_SetFile