Skip to content

Commit

Permalink
Almost ready
Browse files Browse the repository at this point in the history
Now it's almost ready for an installer.
  • Loading branch information
philpw99 committed Oct 19, 2021
1 parent 3bb87b1 commit cf5bbb5
Show file tree
Hide file tree
Showing 15 changed files with 254 additions and 1,497 deletions.
54 changes: 32 additions & 22 deletions Stash_Helper.au3
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ EndIf
Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected.
; Now create the top level tray menu items.
If $stashVersion <> "" Then
TrayTip("Stash is Active", $stashVersion, 20, $TIP_ICONASTERISK+$TIP_NOSOUND )
TrayTip("Stash is Active", $stashVersion, 10, $TIP_ICONASTERISK+$TIP_NOSOUND )
EndIf

TrayCreateItem("Stash Helper 1.0")
TrayCreateItem("")
Global $trayMenuScenes = TrayCreateMenu("Scenes")
Global $trayMenuImages = TrayCreateMenu("Images")
Global $trayMenuMovies = TrayCreateMenu("Movies")
Expand Down Expand Up @@ -140,14 +142,16 @@ Switch $stashBrowser
EndSwitch

; Slow down a bit here, or the web driver is not ready.
Sleep(2000)
Sleep(1000)

Global $iConsolePID = _WD_Startup()
If @error <> $_WD_ERROR_Success Then BrowserError(@extended)

$sSession = _WD_CreateSession($sDesiredCapabilities)
If @error <> $_WD_ERROR_Success Then BrowserError(@extended)

Global $sBrowserHandle

#EndRegion Globals

#Region Tray Menu Handling
Expand All @@ -163,10 +167,11 @@ While True
Case 0
; Nothing should be here.
Case $trayAbout
MsgBox(64,"Stash Helper","Stash helper written by Philip Wang, at your service." _
MsgBox(64,"Stash Helper 1.0","Stash helper 1.0, written by Philip Wang, at your service." _
& @CRLF & "Hopefully this little program will make you navigate the powerful Stash App more easily." _
& @CRLF & "Kudos to the great Stash App team ! kermieisinthehouse, WithoutPants, bnkai ... and all other great contributors working for the project." _
& @CRLF & "Kudos also go to ISN AutoIt Studio's powerful AutoIt IDE, which making this program much easier to write.",20)
& @CRLF & "Kudos also go to ISN AutoIt Studio's powerful AutoIt IDE, which making this program much easier to write." _
& @CRLF & "Also thanks to InstallForge for such an easy-to-build installer!" ,20)
Case $trayExit
ExitScript()
Case $traySettings
Expand Down Expand Up @@ -254,59 +259,61 @@ Func CloseSession()
EndFunc

Func SetupFirefox()

If Not FileExists(@ScriptDir & "\" & "geckodriver.exe") Then
If Not FileExists(@AppDataDir & "\Webdriver\" & "geckodriver.exe") Then
Local $b64 = ( @CPUArch = "X64" )
Local $bGood = _WD_UPdateDriver ("firefox", Default , $b64, True) ; Force update
Local $bGood = _WD_UPdateDriver ("firefox", @AppDataDir & "\Webdriver" , $b64, True) ; Force update
If Not $bGood Then
MsgBox(48,"Error Getting Firefox Driver", _
"There is an error getting the driver for Firefox. Maybe your Internet is down?" _
& @CRLF & "The program will try to get the driver again next time you launch it.",0)
ExitScript()
Exit
EndIf
EndIf

_WD_Option('Driver', 'geckodriver.exe')
_WD_Option('Driver', @AppDataDir & "\Webdriver\" & 'geckodriver.exe')
_WD_Option('DriverClose', True)
_WD_Option('DriverParams', '--log trace')
_WD_Option('Port', 4444)

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts":true}}}'
EndFunc ;==>SetupGecko

Func SetupChrome()
If Not FileExists(@ScriptDir & "\" & "chromedriver.exe") Then
Local $bGood = _WD_UPdateDriver ("chrome", Default , Default, True) ; Force update
If Not FileExists( @AppDataDir & "\Webdriver\" & "chromedriver.exe") Then
Local $bGood = _WD_UPdateDriver ("chrome", @AppDataDir & "\Webdriver" , Default, True) ; Force update
If Not $bGood Then
MsgBox(48,"Error Getting Firefox Driver", _
"There is an error getting the driver for Firefox. Maybe your Internet is down?" _
& @CRLF & "The program will try to get the driver again next time you launch it.",0)
ExitScript()
Exit
EndIf
EndIf

_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('Driver', @AppDataDir & "\Webdriver\" & 'chromedriver.exe')
_WD_Option('DriverClose', True)
_WD_Option('Port', 9515)
_WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"')
_WD_Option('DriverParams', '--verbose --log-path="' & @AppDataDir & "\Webdriver\chrome.log")

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"]}}}}'
EndFunc ;==>SetupChrome

Func SetupEdge()
If Not FileExists(@ScriptDir & "\" & "msedgedriver.exe") Then
If Not FileExists(@AppDataDir & "\Webdriver\" & "msedgedriver.exe") Then
Local $b64 = ( @CPUArch = "X64" )
Local $bGood = _WD_UPdateDriver ("msedge", Default , $b64 , True) ; Force update
Local $bGood = _WD_UPdateDriver ("msedge", @AppDataDir & "\Webdriver" , $b64 , True) ; Force update
If Not $bGood Then
MsgBox(48,"Error Getting Firefox Driver", _
"There is an error getting the driver for Firefox. Maybe your Internet is down?" _
& @CRLF & "The program will try to get the driver again next time you launch it.",0)
ExitScript()
Exit
EndIf
EndIf


_WD_Option('Driver', 'msedgedriver.exe')
_WD_Option('Driver', @AppDataDir & "\Webdriver\" & 'msedgedriver.exe')
_WD_Option('DriverClose', True)
_WD_Option('Port', 9515)
_WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\msedge.log"')
_WD_Option('DriverParams', '--verbose --log-path="' & @AppDataDir & "\Webdriver\msedge.log")

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"ms:edgeOptions": {"excludeSwitches": [ "enable-automation"]}}}}'
EndFunc ;==>SetupEdge
Expand All @@ -320,13 +327,16 @@ Func BrowserError($code)
EndFunc

Func OpenURL($url)
$sBrowserHandle = _WD_Window($sSession, "Window")
If $sBrowserHandle = "" Then
; The session is invalid.
$sSession = _WD_CreateSession($sDesiredCapabilities)
EndIf

_WD_Navigate($sSession, $url)

$result = _WD_Window($sSession, "Window")
c("Window result:" & $result)
If @error <> $_WD_ERROR_Success Then
; Session is invalid, need to create a new one
$sSession = _WD_CreateSession($sDesiredCapabilities)
; Get the new handle.
_WD_Navigate($sSession, $url)
EndIf
Expand Down
Binary file modified Stash_Helper.isn
Binary file not shown.
190 changes: 190 additions & 0 deletions TrayMenuEx.au3
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
; FILE: TrayMenuEx.au3
; VESION: 1.0.0
; LAST EDIT: 30 Mar 2006
; PURPOSE: Provide udf's to extend TrayMenu functionality.
; Image support is implemented
;
; RESOURCES: Scopinho: http://www.autoitscript.com/forum/index.php?showtopic=20798&hl=AddImageToMenu
; RESOURCES: MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwui/html/msdn_icons.asp
; CREATED BY: Uten: http://www.autoitscript.com/forum/index.php?showuser=7836
; TODO:
; ---------------------------------------------------------------------
; * Add support to get the icon viewed in explorer for any exe.
; ---------------------------------------------------------------------
; CHANGE LOG:
; ---------------------------------------------------------------------
; uten 30 Mar 2006 First release.
; ---------------------------------------------------------------------
#cs - User calltip entries: Tools->User calltip entries
_LoadImage($imagePathName, $imageType) Returns handel to image in memory. Load image from a image file (bmp, ico). Set $imageType as $IMAGE_BITMAP=0 or $IMAGE_ICON=1
_TrayMenuAddIcon(ByRef $hIcon, $TrayMenuNr[, $ParentMenu = 0[, $IndexType = 0x00000400]] ) Add, bitmap in, icon to a tray item. $hIco: Handel to icon in memory. $TrayMenuNr: TrayItems index nr in menu.First item is 0. $ParentMenu: controlID returned by TrayCreateMenu. $IndexType: $MF_BYPOSITION | $MF_BYCOMMAND Changes behaviour of $TrayMenuNr
_TrayMenuAddImage( ByRef $hBmp, $MenuIndex[, $ParentMenu = 0[, $IndexType = 0x00000400]] )Add bitmap to a tray item. $hBmp: Handel to bitmap in memory. $TrayMenuNr: TrayItems index nr in menu.First item is 0. $ParentMenu: controlID returned by TrayCreateMenu. $IndexType: $MF_BYPOSITION | $MF_BYCOMMAND Changes behaviour of $TrayMenuNr
_IconExtractFromFile($szIconFile, $iconID) Extract icon from file. $szIconFile: PathName to file (dll or exe) containing the icon. $iconID: Resource reference in the file.
_IconDestroy(ByRef $hIcon) Destroy icon in memory. $hIcon may be a array of handels. Could be called after the icon has been pased on to menuItem.
_IconGetInfo( ByRef $hIcon, ByRef $structICONINFO) $hIcon: Handel to icon in memory. $structICONINFO: A array resembeling the ICONSTRUCT structure. item 5 is a handel to the bitmap.
_GetMenuItemID($hMenu, $itemRelativePos) Returns itemID of a item in menu $hMenu with relative pos $itemRelativePos.
#ce

#include <GUIConstants.au3>
#include-once

; ---------------------------------------------------------------------
;Global Const $MF_BYCOMMAND = 0x00000000 ; In <GUIConstants.au3>
;Global Const $MF_BYPOSITION = 0x00000400 ; In <GUIConstants.au3>
Global Const $IMAGE_BITMAP = 0
Global Const $IMAGE_ICON = 1

Global Const $LR_LOADMAP3DCOLORS = 0x00001000
Global Const $LR_LOADFROMFILE = 0x0010
;
Global Const $Debug = 1
Global Const $ModuleName = "TrayMenuEx.au3"
; ---------------------------------------------------------------------
#cs TEST CODE:
_Main()
Func _Main()
Opt("TrayMenuMode", 1) ; Don't show the default tray context menu
local $autoitIcons="C:\Program Files (x86)" & "\Autoit3\icons\"
local $bmpPathName = "c:\temp\test.bmp"
local $IExplorerPath = "c:\program files\internet explorer\iexplorer.exe"
local $TMControlIDs[8], $hImg[8]
; Create a menu structure
$TMControlIDs[0] = TrayCreateMenu("Options")
$TMControlIDs[1] = TrayCreateItem("Opt1",$TMControlIDs[0])
$TMControlIDs[2] = TrayCreateItem("Opt2",$TMControlIDs[0])
$TMControlIDs[3] = TrayCreateItem("")
$TMControlIDs[4] = TrayCreateItem("Test1")
$TMControlIDs[5] = TrayCreateItem("IExplorer")
$TMControlIDs[6] = TrayCreateItem("")
$TMControlIDs[7] = TrayCreateItem("Exit")
; Add some icons
$hImg[0] = _IconExtractFromFile("shell32.dll", 15) ; Computer icon in dll
$hImg[1] = _LoadImage($autoitIcons & "MyAutoIt3_Blue.ico", $IMAGE_ICON)
$hImg[2] = _LoadImage($autoitIcons & "MyAutoIt3_Green.ico", $IMAGE_ICON)
$hImg[4] = _IconExtractFromFile(@AutoItExe, 0) ; This does not work for all files (ex:firefox). Even if the item reference is correct
$hImg[5] = _IconExtractFromFile($IExplorerPath, 32528)
$hImg[7] = _LoadImage($bmpPathName, $IMAGE_BITMAP)
_TrayMenuAddIcon($hImg[0], 0) ; CReate a submenu
_TrayMenuAddIcon($hImg[1], 0,$TMControlIDs[0]) ; First item on the sub menu
_TrayMenuAddIcon($hImg[2], 1,$TMControlIDs[0]) ; Second on sub menu
;_TrayMenuAddIcon($hImg[3], 1) ; Seperator, between submenu and root
_TrayMenuAddIcon($hImg[4], 2) ; Test1, expect Autoit icon
_TrayMenuAddIcon($hImg[5], 3) ; IExplorer
;_TrayMenuAddIcon($hImg[6], 4) ; Seperator
_TrayMenuAddImage($hImg[7], 5) ; Exit, expect blue bmp
TraySetState()
; We can destroy the icon references after it has been loaded by the TrayItem
_IconDestroy($hImg) ;Destroys handel or array of handels
local $msg, $TrayMsg
While 1
if TrayGetMsg()= $TMControlIDs[7] then Exit
$msg = GUIGetMsg()
switch $msg
case $GUI_EVENT_CLOSE
exit
case Else
If $msg = 0 Then
;sleep(250)
Else
if $debug then ConsoleWrite("MSG LOOP: $msg:=" & $msg & @LF)
EndIf
EndSwitch
WEnd
EndFunc ;==>_Main
#ce
; ---------------------------------------------------------------------
Func _LoadImage($imagePathName, $imageType)
; $imageType=[$IMAGE_BITMAP|$IMAGE_ICON]
; Loads image to memory, returns pointer
If $Debug AND Not FileExists($imagePathName) Then ConsoleWrite($ModuleName & _
" ERROR: _LoadImage($imagePathName:=" & _
$imagePathName & ", $imageType:="& $imageType & _
") File does not exist" & @LF)
Local $hRet = DllCall("user32.dll", "hwnd", "LoadImage", "hwnd", 0, _
"str", $imagePathName, _
"int", $imageType, _
"int", 0, _
"int", 0, _
"int", BitOR($LR_LOADFROMFILE, $LR_LOADMAP3DCOLORS))
; TODO: Consider LR_LOADTRANSPARENT, LR_SHARED
if $Debug AND $hRet[0] = 0 Then ConsoleWrite($ModuleName & _
" ERROR: _LoadImage($imagePathName:=" & _
$imagePathName & ", $imageType:="& $imageType & _
") Did not return img handel." & @LF)
$hRet = $hRet[0]
Return $hRet
EndFunc

Func _TrayMenuAddIcon(ByRef $hIcon, $TrayMenuNr, $ParentMenu = 0, $IndexType = 0x00000400 ); $MF_POSITION=0x00000400
dim $pIcoInfo, $hBmp
If _IconGetInfo($hIcon, $pIcoInfo) <> 0 Then
; Get a handel to the bmp in the icon def.
$hBmp = DllStructGetData($pIcoInfo,5)
_TrayMenuAddImage($hBmp, $TrayMenuNr, $ParentMenu, $IndexType)
$pIcoInfo = 0
Else
If $Debug Then ConsoleWrite($ModuleName & " ERROR: In _TrayMenuAddIcon($hIcon:=" & $hIcon & _
", $TrayMenuNr:=" & $TrayMenuNr _
& ") Call to _GetIconInfo Trying to use $hIcon as bmp handel" & @LF)
_TrayMenuAddImage($hIcon, $TrayMenuNr, $ParentMenu, $IndexType)
EndIf
EndFunc ; ==>_TrayMenuAddIcon

Func _TrayMenuAddImage( ByRef $hBmp, $MenuIndex, $ParentMenu = 0, $IndexType = 0x00000400 ); $MF_POSITION=0x00000400
if $Debug Then ConsoleWrite("_TrayMenuAddIcon( $hBmp:=" & $hBmp & ", $MenuIndex:=" & _
$MenuIndex & ", $ParentMenu:=" & $ParentMenu & ", $IndexType:=" & $IndexType &" )" & @LF)
local $ret = DllCall("user32.dll", "int", "SetMenuItemBitmaps", "hwnd", TrayItemGetHandle($ParentMenu), _
"int", $MenuIndex, _
"int", $IndexType, _
"hwnd", $hBmp, _
"hwnd", $hBmp)
EndFunc ; ==>_TrayMenuAddImage

Func _IconExtractFromFile($szIconFile, $iconID)
; TODO: This will not extract icons (as in a embeded resource) from a normal exe.
Local $hIcon = DllStructCreate("int")
;PROTO: UINT ExtractIconEx(LPCTSTR lpszFile, int nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIcons);
Local $result = DllCall("shell32.dll", "hwnd", "ExtractIconEx", "str", $szIconFile, "int", $iconID, "hwnd", 0, "ptr", DllStructGetPtr($hIcon), "int", 1)
;TODO: Do we have to make shure some cleanup is done? Or will the memory bee freed when Autoit terminates
$ret = DllStructGetData($hIcon,1)
Return $ret
EndFunc ; ==> _IconExtractFromFile

Func _IconDestroy(ByRef $hIcon)
if IsArray($hIcon) Then
local $i
For $i = 0 to UBound($hIcon) - 1
DllCall("user32.dll", "int", "DestroyIcon", "hwnd", DllStructGetPtr($hIcon[$i]))
Next
else
DllCall("user32.dll", "int", "DestroyIcon", "hwnd", DllStructGetPtr($hIcon))
EndIf
EndFunc ; ==>_IconDestroy

Func _IconGetInfo( ByRef $hIcon, ByRef $structICONINFO)
local $def = "int; dword; dword; ptr; ptr"
$structICONINFO = DllStructCreate($def)
; PROTO: BOOL GetIconInfo( HICON hIcon, PICONINFO piconinfo);
Local $ret = DllCall("user32.dll", "long", "GetIconInfo","ptr", $hIcon, "ptr", DllStructGetPtr($structICONINFO))
if $Debug AND @error <> 0 then ConsoleWrite( $ModuleName & "_IconGetInfo: @ERROR:=" & @error & @CRLF & _
"@ERROR:=1 > unable to use the DLL file: user32.dll" & @CRLF & _
"@ERROR:=2 > unknown return type" & @CRLF & _
"@ERROR:=3 > function: GetIconInfo not found in user32.dll" & @LF)
; 0 Is failure andything else is success.
return $ret[0]
EndFunc ; ==> _IconGEtInfo

Func _GetMenuItemID($hMenu, $itemRelativePos)
;PROTO: UINT GetMenuItemID( HMENU hMenu, int nPos);
local $ret = dllcall("", "int", "GetMenuItemID","hwnd", $hMenu, "int", $itemRelativePos)
Return $ret[0]
EndFunc
; ---------------------------------------------------------------------
Loading

0 comments on commit cf5bbb5

Please sign in to comment.