Nicht angemeldet.
Hier können Sie Ihre eigenen Skripte und UDF's veröffentlichen undanderen zum Download anbieten oder von anderen herunterladen
#include-once #include <StaticConstants.au3> #include <ScreenCapture.au3> #include <Misc.au3> #include <File.au3> #cs Library Info/Header ; Name/Title: Opera Browser Automation UDF Library ; Description: Functions to handle some of the common routines for Opera Browser! ; Version: 1.02. ; Last Update: 03.Jul.2009 ; Requirements: AutoIt 3.2.8.1 or higher. ; Note: This UDF Library tested on Opera versions: 8.54-9.5, 10.0.1589. ; Support Link: ; Author: Copyright © 2007 - 2009 CreatoR's Lab (G.Sandler), www.autoit-script.ru ; ; ToDo: ; * Add UDFs: ; _OperaAddToolbarButton() ; _OperaRemoveToolbarButton() ; _OperaAddSkinIcon() -> Required 7zip/WinRar, or use system zipfolder. ; _OperaRemoveSkinIcon() -> Required 7zip/WinRar, or use system zipfolder. ; ; History Version: ; v1.02 [03.Jul.2009] ; * Now compatible with AutoIt 3.3.0.0. ; + Opera 10 support. ; + Added _OperaGetBookmarksFile() function. ; + Added _OperaScreenCapture() function... ; ATTENTION: supported only for v3.2.10.0 or higher, due to (lack of) callback support. ; + Added _OperaAddMenuItem()/_OperaRemoveMenuItem() function. ; * Fixed few function to read relative paths in opera prefs file. ; ; v1.01 [5.Jan.2008] ; * Now compatible with AutoIt 3.2.10.0. ; * Variable names and spell corrections. ; + Added 2 more UDFs: ; _OperaRestart() ; _OperaMultiUserModeIsOn() ; ; v1.0 [28.Dec.2007] ; * First Release. ; ; Functions List: ; User's funcs... ; 1)_OperaFindDir ; 2)_OperaGetDir ; 3)_OperaGetVersion ; 4)_OperaGetTitle ; 5)_OperaGetProfileDir ; 6)_OperaGetMailDir ; 7)_OperaGetUserJSDir ; 8)_OperaGetPluginsDir ; 9)_OperaGetSkinFile ; 10)_OperaGetLangFile ; 11)_OperaGetBookmarksFile ; 12)_OperaGetConfigFile ; 13)_OperaSetConfigFile ; 14)_OperaSetSkinFile ; 15)_OperaSetUserJSDir ; 16)_OperaSetLangFile ; 17)_OperaSelectFolder ; 18)_OperaAddMenuItem ; 19)_OperaRemoveMenuItem ; 20)_OperaIsRuning ; 21)_OperaRun ; 22)_OperaClose ; 23)_OperaKill ; 24)_OperaRestart ; 25)_OperaScreenCapture ; 26)_OperaMultiUserModeIsOn ; 27)_Opera_Integration_Example ; 28)_OpenGetURL ; ; internal funcs... ; 29)__WinGetTitleEx ; 30)__WinGetTitleByPID ; 31)__ProcessPathExists ; 32)__ProcessGetPath ; 33)__PathIsFolder ; 34)__PathIsOperaDir ; 35)__PathIsOperaProfileDir ; 36)__PathIsOperaConfigFile ; 37)__PathIsOperaLangFile ; 38)__PathIsOperaSkinFile ; 39)__PathIsOperaBookmarksFile ; 40)__PrefixStrIsOperaConfig ; 41)__ConfirmExitOperaWinExists ; 42)__Correct_Opera_Path ; 43)__GetOperaPIDs ; 44)__GetOperaPrefsFileName ; 45)__GetOperaPageHandle ; 46)__EnumOperaChildWindowsProc ; 47)__ExpandOperaMenuSectClassName ; 48)__Backup_Config ; 49)__FileNewName ; 50)__UTF8ToAnsi ; 51)__StringIsUTF8Format ; 52)__StringToUTF ; 53)__IniWriteToPos ; 54)__IniDeleteRegExp ; 55)__WinAPI_FindWindowEx ; 56)__WinAPI_GetClassName ; #ce Global $a_OperaChildWindows[1] Global Const $s_Opera_Exe = "Opera.exe" ;=============================================================================== ; ; Function Name: _OperaFindDir() ; ; Function Description: Performs a search for Opera Browser Installed Dir(s). ; ; Parameter(s): $sInitPath - [Optional] Initial Path to start search from, ; if used -1 (default) then the search performed in all fixed drives (C:\, D:\, etc.). ; $iRetCount - [Optional] Defins how many Opera Dirs to return: ; -1 - (default) will return the first found dir. ; ; Requirement(s): None. ; ; Return Value(s): On Success - Return array with full paths to Opera Dir, where: ; $aOperaPaths[0] is the total found Opera dirs. ; $aOperaPaths[N] is the full path to Opera Installed dir. ; On Failure - If no Opera dirs found, Set @error to 1 and return "" (empty string). ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaFindDir($sInitPath = -1, $iRetCount = -1) Local $aOperaPaths[1] Local $aInitPaths[2] = [1, $sInitPath] Local $aPaths[1], $hSearch, $sFindNext, $i If Not __PathIsFolder($sInitPath) Then $aInitPaths = DriveGetDrive("FIXED") If @error Then Return SetError(1, 0, "") For $iP = 1 To UBound($aInitPaths) - 1 Dim $aPaths[2] = [1, $aInitPaths[$iP]] $i = 0 While $i < $aPaths[0] $i += 1 $hSearch = FileFindFirstFile($aPaths[$i] & "\*") If $hSearch = -1 Then ContinueLoop While 1 $sFindNext = FileFindNextFile($hSearch) If @error Then ExitLoop If $sFindNext = $s_Opera_Exe Then $aOperaPaths[0] += 1 ReDim $aOperaPaths[$aOperaPaths[0] + 1] $aOperaPaths[$aOperaPaths[0]] = $aPaths[$i] If $iRetCount = -1 Or ($iRetCount > 0 And $aOperaPaths[0] >= $iRetCount) Then ExitLoop 3 EndIf $sFindNext = $aPaths[$i] & "\" & $sFindNext If __PathIsFolder($sFindNext) Then $aPaths[0] += 1 ReDim $aPaths[$aPaths[0] + 1] $aPaths[$aPaths[0]] = $sFindNext EndIf WEnd FileClose($hSearch) WEnd Next FileClose($hSearch) If $aOperaPaths[0] < 1 Then Return SetError(1, 0, "") Return $aOperaPaths EndFunc ;==>_OperaFindDir ;=============================================================================== ; ; Function Name: _OperaGetDir() ; ; Function Description: Returns full path to Opera Browser Installed Dir. ; ; Parameter(s): None. ; ; Requirement(s): None. ; ; Return Value(s): On Success - Return full path to Opera Dir, i.e. C:\Program Files\Opera 9.25 ; On Failure - Set @error to 1 and return "" (empty string). ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaGetDir() Local $sOperaDir = @ScriptDir If __PathIsOperaDir($sOperaDir) Then Return $sOperaDir Local $sOperaDirRegRead = RegRead("HKEY_CURRENT_USER\Software\Opera Software", "Last CommandLine v2") Local $aOperaDirArr = StringSplit($sOperaDirRegRead, "\" & $s_Opera_Exe, 1) If UBound($aOperaDirArr) > 1 Then $sOperaDir = $aOperaDirArr[1] If Not __PathIsOperaDir($sOperaDir) Then $sOperaDir = StringTrimRight($sOperaDirRegRead, 10) If Not __PathIsOperaDir($sOperaDir) Then $sOperaDir = @ProgramFilesDir & "\Opera" If Not __PathIsOperaDir($sOperaDir) Then Return SetError(1, 0, "") Return StringRegExpReplace($sOperaDir, "\\+$", "") EndFunc ;==>_OperaGetDir ;=============================================================================== ; ; Function Name: _OperaGetVersion() ; ; Function Description: Returns Opera.exe file Version. ; ; Parameter(s): $sOpDir - [Optional] Full path to Opera dir, ; so the returned Opera.exe version will be taken from specific Opera installation. ; ; Requirement(s): None. ; ; Return Value(s): On Success - String with Opera Version, i.e. 10.0.1355.0 ; On Failure - Returns 0 and set @error to: ; 1 - $sOpDir (Opera Dir) not found. ; 2 - Unable to get Opera version (FileGetVersion() fails). ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaGetVersion($sOpDir = -1) If Not __PathIsOperaDir($sOpDir) Then $sOpDir = _OperaGetDir() If @error Then Return SetError(1, 0, 0) Local $sOperaVersion = FileGetVersion($sOpDir & "\" & $s_Opera_Exe) If @error Then Return SetError(2, 0, 0) Return $sOperaVersion EndFunc ;==>_OperaGetVersion ;=============================================================================== ; ; Function Name: _OperaGetTitle() ; ; Function Description: Returns Title(s)/Win handle(s) for Opera Window. ; ; Parameter(s): $sOpDir - [Optional] Full path to Opera dir, ; so the returned Title will be related to specific Opera installation. ; $iRet - [Optional] Defins return type: ; -1 (default) - Will return only Opera Title. ; 0 - Will return only Opera Window Handle. ; 1 - Will return 2-elements array where [0] is Opera Title, and [1] is Opera Win Handle. ; 2 - Will return 2-dimentional array with all founded Opera Windows, where... ; $aOpWinList[0][0] is number of total windows found. ; $aOpWinList[N][0] is Opera Window Title. ; $aOpWinList[N][1] is Opera Window Handle. ; $sOpDir is ignored with this mode. ; $iUseDDE - [Optional] Get Opera Title method, if > 0 (0 is the default), ; then the Opera Title will be returned using DDE ; (for last executed Opera's Window). ; When this method used, $iRet can be only as -1 (default) or as 1 ; (other values are ignored). ; ; Requirement(s): None. ; ; Return Value(s): On Success - Return Opera Title(s)/Window Handle(s) according to passed parameters. ; On Failure - Returns "" (empty string) and set @error to: ; 1 - $iUseDDE > 0 and there was an error to get access to Opera DDE. ; 2 - $iRet = 2 and there was an error to get Opera Windows list. ; 3 - Unable to find Opera Title/Win Handle. ; 4 - Other error, such as incorrect passed parameter values or unable to find window. ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaGetTitle($sOpDir = -1, $iRet = -1, $iUseDDE = 0) Local $sOpTitle = "" If $iUseDDE Then $sOpTitle = _OpenGetURL("", -1, 1) If Not IsArray($sOpTitle) Then Return SetError(1, 0, "") $sOpTitle = StringRegExpReplace($sOpTitle[0], '\A".*?\[(.*)\]"$', '\1') If $iRet = 1 Then Local $aRetArr[2] = [$sOpTitle, WinGetHandle($sOpTitle) ] Return $aRetArr EndIf Return $sOpTitle EndIf If $iRet = 2 Then Local $aOpWinList = WinList("[REGEXPTITLE:(.*?)(- Opera.*|$);CLASS:OpWindow]") If Not IsArray($aOpWinList) Then Return SetError(2, 0, "") Return $aOpWinList EndIf If __PathIsOperaDir($sOpDir) Then $sOpTitle = __WinGetTitleEx($sOpDir & "\" & $s_Opera_Exe) If Not WinExists($sOpTitle) Or $sOpTitle = "" Then Return SetError(3, 0, "") Return $sOpTitle Else $sOpDir = _OperaGetDir() EndIf If __PathIsOperaDir($sOpDir) Then $sOpTitle = __WinGetTitleEx($sOpDir & "\" & $s_Opera_Exe) If Not WinExists($sOpTitle) Or $sOpTitle = "" Then $sOpTitle = WinGetTitle("[REGEXPTITLE:(.*?)(- Opera.*|$);CLASS:OpWindow]") $sOpTitle = StringLeft($sOpTitle, StringInStr($sOpTitle, "-", 0, -1)) If StringRight($sOpTitle, 1) = "-" Then $sOpTitle = StringStripWS(StringTrimRight($sOpTitle, 1), 3) If Not WinExists($sOpTitle) Or $sOpTitle = "" Then Return SetError(4, 0, "") ;$sOpTitle = "Opera" EndIf Local $hOphWnd = WinGetHandle($sOpTitle) Switch $iRet Case -1 Return $sOpTitle Case 0 Return $hOphWnd Case 1 Local $aRetArr[2] = [$sOpTitle, $hOphWnd] Return $aRetArr EndSwitch Return SetError(4, 0, "") EndFunc ;==>_OperaGetTitle ;=============================================================================== ; ; Function Name: _OperaGetProfileDir() ; ; Function Description: Returns full path to Opera Profile Dir. ; ; Parameter(s): $sOpDir - [Optional] Full path to Opera dir, ; so the returned profile dir will be related to specific Opera installed dir. ; ; Requirement(s): None. ; ; Return Value(s): On Success - Return full path to Opera Profile Dir, ; i.e. C:\Documents and Settings\User\Application Data\Opera\Opera 9.25\profile ; On Failure - Returns "" (empty string) and set @error to: ; 1 - $sOpDir (Opera Dir) not found. ; 2 - Opera6.ini (main Opera's config file) not found. ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaGetProfileDir($sOpDir = -1) If Not __PathIsOperaDir($sOpDir) Then $sOpDir = _OperaGetDir() If @error Then Return SetError(1, 0, "") Local $sOperaPrefs_FileName = __GetOperaPrefsFileName($sOpDir, 0) If _OperaMultiUserModeIsOn() Then $sOpDir = @AppDataDir & "\Opera\" & StringRegExpReplace($sOpDir, "^.*\\", "") If Not __PathIsOperaConfigFile($sOpDir & "\profile\" & $sOperaPrefs_FileName) Then Return SetError(2, 0, "") Return $sOpDir & "\profile" EndFunc ;==>_OperaGetProfileDir ;=============================================================================== ; ; Function Name: _OperaGetMailDir() ; ; Function Description: Returns full path to Opera Mail Dir. ; ; Parameter(s): $sOpDir - [Optional] Full path to Opera dir, ; so the returned Mail dir will be related to specific Opera installed dir. ; ; Requirement(s): None. ; ; Return Value(s): On Success - Return full path to Opera Mail Dir, ; i.e. C:\Documents and Settings\User\Application Data\Opera\Opera 9.25\mail ; On Failure - Returns "" (empty string) and set @error to: ; 1 - $sOpDir (Opera Dir) not found. ; 2 - Index.ini (main Opera's Mail config file) not found. ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaGetMailDir($sOpDir = -1) If Not __PathIsOperaDir($sOpDir) Then $sOpDir = _OperaGetDir() Local $sOpProfileDir = _OperaGetProfileDir($sOpDir) If @error Then Return SetError(1, 0, "") Local $sOperaPrefs_FileName = __GetOperaPrefsFileName($sOpDir, 0) Local $sOpMailDir = IniRead($sOpProfileDir & "\" & $sOperaPrefs_FileName, "Mail", "Mail Root Directory", "Def_ERROR") __Correct_Opera_Path($sOpMailDir, $sOpDir, $sOpProfileDir) If $sOpMailDir == "Def_ERROR" And _VersionCompare(_OperaGetVersion($sOpDir), "10") <> -1 Then _ $sOpMailDir = $sOpProfileDir & "\mail" If Not __PathIsOperaConfigFile($sOpMailDir & "\Index.ini") Then _ $sOpMailDir = StringRegExpReplace($sOpProfileDir, "\\[^\\]*$", "") & "\mail" If Not __PathIsOperaConfigFile($sOpMailDir & "\Index.ini") Then $sOpMailDir = @ScriptDir & "\mail" If Not __PathIsOperaConfigFile($sOpMailDir & "\Index.ini") Then Return SetError(2, 0, "") Return $sOpMailDir EndFunc ;==>_OperaGetMailDir ;=============================================================================== ; ; Function Name: _OperaGetUserJSDir() ; ; Function Description: Returns full path to Opera main UserJS Dir. ; ; Parameter(s): $sOpDir - [Optional] Full path to Opera dir, ; so the returned UserJS dir will be related to specific Opera installed dir. ; ; Requirement(s): None. ; ; Return Value(s): On Success - Return full path to Opera UserJS Dir, ; i.e. C:\Documents and Settings\User\Application Data\Opera\Opera 9.25\profile\UserJS ; On Failure - Returns "" (empty string) and set @error to: ; 1 - $sOpDir (Opera Dir) not found. ; 2 - UserJS dir not found. ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaGetUserJSDir($sOpDir = -1) If Not __PathIsOperaDir($sOpDir) Then $sOpDir = _OperaGetDir() Local $sOpProfileDir = _OperaGetProfileDir($sOpDir) If @error Then Return SetError(1, 0, "") Local $sOperaPrefs_FileName = __GetOperaPrefsFileName($sOpDir, 0) Local $sOpUserJSDir = IniRead($sOpProfileDir & "\" & $sOperaPrefs_FileName, "User Prefs", "User JavaScript File", "") __Correct_Opera_Path($sOpUserJSDir, $sOpDir, $sOpProfileDir) If Not __PathIsFolder($sOpUserJSDir) Then $sOpUserJSDir = _PathFull($sOpUserJSDir, $sOpProfileDir) If Not __PathIsFolder($sOpUserJSDir) Then Return SetError(2, 0, "") Return $sOpUserJSDir EndFunc ;==>_OperaGetUserJSDir ;=============================================================================== ; ; Function Name: _OperaGetPluginsDir() ; ; Function Description: Returns used paths to Opera main Plugins Dir(s). ; ; Parameter(s): $sOpDir - [Optional] Full path to Opera dir, ; so the returned Plugins dir will be related to specific Opera installed dir. ; ; Requirement(s): None. ; ; Return Value(s): On Success - Return array with full paths to Opera Plugins Dir. ; On Failure - Returns "" (empty string) and set @error to: ; 1 - $sOpDir (Opera Dir) not found. ; 2 - Plugins dir(s) not found. ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaGetPluginsDir($sOpDir = -1) If Not __PathIsOperaDir($sOpDir) Then $sOpDir = _OperaGetDir() If @error Then Return SetError(1, 0, "") Local $sOperaPrefs_DefFileName = __GetOperaPrefsFileName($sOpDir, 1) Local $sOpPluginsDir = IniRead($sOpDir & "\" & $sOperaPrefs_DefFileName, "User Prefs", "Plugin Path", "") Local $aOpPlugsDir, $aRetOpPlugsDir[1] $sOpPluginsDir = StringRegExpReplace($sOpPluginsDir, ";+$", "") If StringInStr($sOpPluginsDir, ";") Then $aOpPlugsDir = StringSplit($sOpPluginsDir, ";") For $i = 1 To UBound($aOpPlugsDir) - 1 If __PathIsFolder($aOpPlugsDir[$i]) Then $aRetOpPlugsDir[0] += 1 ReDim $aRetOpPlugsDir[$aRetOpPlugsDir[0] + 1] $aRetOpPlugsDir[$aRetOpPlugsDir[0]] = $aOpPlugsDir[$i] EndIf Next If $aRetOpPlugsDir[0] > 0 Then Return $aRetOpPlugsDir EndIf If Not __PathIsFolder($sOpPluginsDir) Then $sOpPluginsDir = RegRead("HKEY_CURRENT_USER\Software\Opera Software", "Plugin Path") If Not __PathIsFolder($sOpPluginsDir) Then $sOpPluginsDir = $sOpDir & "\program\plugins" If Not __PathIsFolder($sOpPluginsDir) Then Return SetError(2, 0, "") Dim $aRetOpPlugsDir[2] = [1, $sOpPluginsDir] Return $aRetOpPlugsDir EndFunc ;==>_OperaGetPluginsDir ;=============================================================================== ; ; Function Name: _OperaGetSkinFile() ; ; Function Description: Returns used Opera Skin file. ; ; Parameter(s): $sOpDir - [Optional] Full path to Opera dir, ; so the returned Skin file will be related to specific Opera installation. ; ; Requirement(s): None. ; ; Return Value(s): On Success - Return full path to Opera Skin file. ; On Failure - Returns "" (empty string) and set @error to: ; 1 - $sOpDir (Opera Dir) not found. ; 2 - Skin file not found. ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaGetSkinFile($sOpDir = -1) If Not __PathIsOperaDir($sOpDir) Then $sOpDir = _OperaGetDir() Local $sOpProfileDir = _OperaGetProfileDir($sOpDir) If @error Then Return SetError(1, 0, "") Local $sOperaPrefs_FileName = __GetOperaPrefsFileName($sOpDir, 0) Local $sOpSkinFile = IniRead($sOpProfileDir & "\" & $sOperaPrefs_FileName, "User Prefs", "Button Set", "") __Correct_Opera_Path($sOpSkinFile, $sOpDir, $sOpProfileDir) If Not __PathIsOperaSkinFile($sOpSkinFile) Then If Not __PathIsOperaDir($sOpDir) Then $sOpDir = _OperaGetDir() If Not @error Then $sOpSkinFile = $sOpDir & "\skin\standard_skin.zip" EndIf If Not __PathIsOperaSkinFile($sOpSkinFile) Then Return SetError(2, 0, "") Return $sOpSkinFile EndFunc ;==>_OperaGetSkinFile ;=============================================================================== ; ; Function Name: _OperaGetLangFile() ; ; Function Description: Returns used Opera Language file. ; ; Parameter(s): $sOpDir - [Optional] Full path to Opera dir, ; so the returned Language file will be related to specific Opera installation. ; ; Requirement(s): None. ; ; Return Value(s): On Success - Return full path to Opera Language file. ; On Failure - Returns "" (empty string) and set @error to: ; 1 - $sOpDir (Opera Dir) not found. ; 2 - Language file not found. ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaGetLangFile($sOpDir = -1) If Not __PathIsOperaDir($sOpDir) Then $sOpDir = _OperaGetDir() Local $sOpProfileDir = _OperaGetProfileDir($sOpDir) If @error Then Return SetError(1, 0, "") Local $sOperaPrefs_FileName = __GetOperaPrefsFileName($sOpDir, 0) Local $sOpLangFile = IniRead($sOpProfileDir & "\" & $sOperaPrefs_FileName, "User Prefs", "Language File", "") __Correct_Opera_Path($sOpLangFile, $sOpDir, $sOpProfileDir) If Not __PathIsOperaLangFile($sOpLangFile) Then If Not __PathIsOperaDir($sOpDir) Then $sOpDir = _OperaGetDir() If Not @error Then $sOpLangFile = $sOpDir & "\English.lng" EndIf If Not __PathIsOperaLangFile($sOpLangFile) Then $sOpLangFile = $sOpDir & "\locale\en\en.lng" If Not __PathIsOperaLangFile($sOpLangFile) Then Return SetError(2, 0, "") Return $sOpLangFile EndFunc ;==>_OperaGetLangFile ;=============================================================================== ; ; Function Name: _OperaGetBookmarksFile() ; ; Function Description: Return Opera's Bookmarks file. ; ; Parameter(s): $sOpDir - [Optional] Full path to Opera dir, ; so the returned Bookmarks file will be related to specific Opera installation. ; ; Requirement(s): None. ; ; Return Value(s): On Success - Return full path to Opera Bookmarks file. ; On Failure - Returns "" (empty string) and set @error to: ; 1 - $sOpDir (Opera Dir) not found. ; 2 - Bookmarks file not found. ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaGetBookmarksFile($sOpDir = -1) If Not __PathIsOperaDir($sOpDir) Then $sOpDir = _OperaGetDir() Local $sOpProfileDir = _OperaGetProfileDir($sOpDir) If @error Then Return SetError(1, 0, "") Local $sOperaPrefs_FileName = __GetOperaPrefsFileName($sOpDir, 0) Local $sOpBkmrksFile = IniRead($sOpProfileDir & "\" & $sOperaPrefs_FileName, "User Prefs", "Hot List File Ver2", "") If Not FileExists($sOpBkmrksFile) Then $sOpBkmrksFile = $sOpProfileDir & "\Opera6.adr" If Not FileExists($sOpBkmrksFile) Then $sOpBkmrksFile = $sOpProfileDir & "\Bookmarks.adr" If Not __PathIsOperaBookmarksFile($sOpBkmrksFile) Then Return SetError(2, 0, "") Return $sOpBkmrksFile EndFunc ;==>_OperaGetBookmarksFile ;=============================================================================== ; ; Function Name: _OperaGetConfigFile() ; ; Function Description: Returns used Opera Configuration file based on given prefix (see Parameter(s)). ; ; Parameter(s): $sConfig_Prefix - Prefix string that indicate what configurtion file to return, these are supported: ; Menu, Toolbar, Keyboard, Mouse ; $sOpDir - [Optional] Full path to Opera dir, ; so the returned Config file will be related to specific Opera installed dir. ; ; Requirement(s): None. ; ; Return Value(s): On Success - Return full path to specific Opera Configuration file. ; On Failure - Returns "" (empty string) and set @error to: ; 1 - $sConfig_Prefix is unsupported prefix string (in this case returns -1). ; 2 - If Opera profile dir not found. ; 3 - Configuration file not found, ; or founded configuration file is not an Opera Configuration file. ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaGetConfigFile($sConfig_Prefix, $sOpDir = -1) If Not __PrefixStrIsOperaConfig($sConfig_Prefix) Then Return SetError(1, 0, -1) If Not __PathIsOperaDir($sOpDir) Then $sOpDir = _OperaGetDir() Local $sOpProfileDir = _OperaGetProfileDir($sOpDir) If @error Then Return SetError(2, 0, "") Local $sOperaPrefs_FileName = __GetOperaPrefsFileName($sOpDir, 0) Local $sOpConfigFile = IniRead($sOpProfileDir & "\" & $sOperaPrefs_FileName, _ "User Prefs", $sConfig_Prefix & " Configuration", "") __Correct_Opera_Path($sOpConfigFile, $sOpDir, $sOpProfileDir) If Not __PathIsOperaConfigFile($sOpConfigFile) Then If Not __PathIsOperaDir($sOpDir) Then $sOpDir = _OperaGetDir() If Not @error Then $sOpConfigFile = $sOpDir & "\defaults\standard_" & $sConfig_Prefix & ".ini" If _VersionCompare(_OperaGetVersion($sOpDir), "10") <> -1 Then _ $sOpConfigFile = $sOpDir & "\ui\standard_" & $sConfig_Prefix & ".ini" EndIf EndIf If Not __PathIsOperaConfigFile($sOpConfigFile) Then Return SetError(3, 0, "") Return $sOpConfigFile EndFunc ;==>_OperaGetConfigFile ;=============================================================================== ; ; Function Name: _OperaSetConfigFile() ; ; Function Description: Set specific Opera Configuration file based on given prefix (see Parameter(s)). ; ; Parameter(s): $sConfig_Prefix - Prefix string that indicate what configurtion file to set, these are supported: ; Menu, Toolbar, Keyboard, Mouse ; $sConfig_Name - Name for the configuration file, used as file name and as menu info name. ; $sSetConfigFile - [Optional] Full path to external configuration file, ; this file will be used as main configuration file, ; if not found, standard file will be cloned to config dir with name = $sConfig_Name. ; $sOpDir - [Optional] Full path to Opera dir, ; so the returned Config file will be related to specific Opera installed dir. ; $iRepRenFlag - [Optional] Defines replace mode: ; -1 (default) or 0 will backup existing file in case the standard file is copied. ; (*Without* replacing the existing backup file). ; 1 will backup existing file in case the standard file is copied. ; (*Will* replace the existing backup file). ; 2 auto-rename existing file in case the standard file is copied. ; In other cases existing file will be replaced. ; ; Requirement(s): Opera Browser should be closed; otherwise the written values can be erased by Opera. ; ; Return Value(s): On Success - Set specific Opera Configuration file for usage in Opera Browser, ; and return full path to "old" (used) Opera specific Configuration file. ; On Failure - Returns "" (empty string) and set @error to: ; 1 - $sConfig_Prefix is unsupported prefix string (in this case returns -1). ; 2 - Opera profile dir not found. ; 3 - Current Configuration file = $sSetConfigFile. ; 4 - $sSetConfigFile is not found (or it is not an Opera config file), ; and Opera Dir not found. ; 5 - Unable to copy Configuration file (if standard config file cloned). ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaSetConfigFile($sConfig_Prefix, $sConfig_Name, $sSetConfigFile = -1, $sOpDir = -1, $iRepRenFlag = -1) If Not __PrefixStrIsOperaConfig($sConfig_Prefix) Then Return SetError(1, 0, -1) Local $sOpProfileDir = _OperaGetProfileDir($sOpDir) If @error Then Return SetError(2, 0, "") Local $sCurrConfigFile = _OperaGetConfigFile($sConfig_Prefix, $sOpDir) If Not @error And $sSetConfigFile = $sCurrConfigFile Then Return SetError(3, 0, $sCurrConfigFile) If StringRight($sConfig_Name, 4) <> ".ini" Then $sConfig_Name &= ".ini" If Not __PathIsOperaConfigFile($sSetConfigFile) Then If Not __PathIsOperaDir($sOpDir) Then $sOpDir = _OperaGetDir() If @error Then Return SetError(4, 0, "") $sStandard_ConfigFile = $sOpDir & "\defaults\standard_" & $sConfig_Prefix & ".ini" If _VersionCompare(_OperaGetVersion($sOpDir), "10") <> -1 Then _ $sStandard_ConfigFile = $sOpDir & "\ui\standard_" & $sConfig_Prefix & ".ini" If $iRepRenFlag = 2 Then $sConfig_Name = __FileNewName($sConfig_Name, $sOpProfileDir & "\" & $sConfig_Prefix) $sSetConfigFile = $sOpProfileDir & "\" & $sConfig_Prefix & "\" & $sConfig_Name Switch $iRepRenFlag Case Default, -1, 0 __Backup_Config($sSetConfigFile, 0) Case 1 __Backup_Config($sSetConfigFile, 1) EndSwitch If Not FileCopy($sStandard_ConfigFile, $sSetConfigFile, 9) Then Return SetError(5, 0, "") EndIf Local $sOperaPrefs_FileName = __GetOperaPrefsFileName($sOpDir, 0) IniWrite($sOpProfileDir & "\" & $sOperaPrefs_FileName, "User Prefs", $sConfig_Prefix & " Configuration", $sSetConfigFile) IniWrite($sSetConfigFile, "Info", "NAME", StringRegExpReplace($sConfig_Name, "(?i).ini+$", "")) Return $sCurrConfigFile EndFunc ;==>_OperaSetConfigFile ;=============================================================================== ; ; Function Name: _OperaSetSkinFile() ; ; Function Description: Set Opera Skin file. ; ; Parameter(s): $sOpSkinFile - Full path to skin file that needs to be set. ; $sOpDir - [Optional] Full path to Opera dir, ; so the Skin file will be set for specific Opera installation. ; $iCopyToSkins - [Optional] If this is <> 0 then skin file will be copied to Opera's Skin folder. ; $iRepRenFlag - [Optional] Defines replace mode: ; -1 (default) or 0 will backup existing file in case the skin file is copied. ; (*Without* replacing the existing backup file). ; 1 will backup existing file in case the skin file is copied. ; (*Will* replace the existing backup file). ; 2 auto-rename existing file in case the skin file is copied. ; In other cases existing file will be replaced. ; ; Requirement(s): Opera Browser should be closed; otherwise the written values can be erased by Opera. ; ; Return Value(s): On Success - Set Opera Skin file, and return full path to "old" (used) Opera Skin file. ; On Failure - Returns "" (empty string) and set @error to: ; 1 - Opera profile dir not found. ; 2 - Current Skin file = $sOpSkinFile. ; 3 - $sOpSkinFile not found, or it's not an Opera Skin file. ; 4 - Unable to copy skin file (with $iCopyToSkins mode on). ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaSetSkinFile($sOpSkinFile, $sOpDir = -1, $iCopyToSkins = 0, $iRepRenFlag = -1) Local $sOpProfileDir = _OperaGetProfileDir($sOpDir) If @error Then Return SetError(1, 0, "") Local $sCurrOpSkinFile = _OperaGetSkinFile($sOpDir) If Not @error And $sCurrOpSkinFile = $sOpSkinFile Then Return SetError(2, 0, "") If Not __PathIsOperaSkinFile($sOpSkinFile) Then Return SetError(3, 0, "") If $iCopyToSkins <> 0 Then Local $sOpSkinName = StringRegExpReplace($sOpSkinFile, "^.*\\", "") Local $sOpSkinPath = $sOpProfileDir & "\Skin" Local $sOpDestSkinFile = $sOpSkinPath & "\" & $sOpSkinName Switch $iRepRenFlag Case Default, -1, 0 __Backup_Config($sOpDestSkinFile, 0) Case 1 __Backup_Config($sOpDestSkinFile, 9) Case 2 $sOpDestSkinFile = $sOpSkinPath & "\" & __FileNewName($sOpSkinName, $sOpSkinPath) EndSwitch If Not FileCopy($sOpSkinFile, $sOpDestSkinFile, 9) Then SetError(4, 0, "") $sOpSkinFile = $sOpDestSkinFile EndIf Local $sOperaPrefs_FileName = __GetOperaPrefsFileName($sOpDir, 0) IniWrite($sOpProfileDir & "\" & $sOperaPrefs_FileName, "User Prefs", "Button Set", $sOpSkinFile) Return $sCurrOpSkinFile EndFunc ;==>_OperaSetSkinFile ;=============================================================================== ; ; Function Name: _OperaSetUserJSDir() ; ; Function Description: Set Opera UserJS directory. ; ; Parameter(s): $sOpUserJSDir - Full path to User JavaScript directory (that include UserJS scripts). ; $sOpDir - [Optional] Full path to Opera dir, ; so the UserJS directory will be set for specific Opera installation. ; $iEnableUserJS - [Optional] If this is = 1 (default) then UserJS will be enabled for Opera Browser. ; ; Requirement(s): Opera Browser should be closed; otherwise the written values can be erased by Opera. ; ; Return Value(s): On Success - Set Opera UserJS directory, and return full path to "old" (used) Opera UserJS directory. ; On Failure - Returns "" (empty string) and set @error to: ; 1 - Opera profile dir not found. ; 2 - Current UserJS dir = $sOpUserJSDir. ; 3 - $sOpUserJSDir is not an existing directory. ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaSetUserJSDir($sOpUserJSDir, $sOpDir = -1, $iEnableUserJS = 1) Local $sOpProfileDir = _OperaGetProfileDir($sOpDir) If @error Then Return SetError(1, 0, "") Local $sCurrOpUserJSDir = _OperaGetUserJSDir($sOpDir) If Not @error And $sCurrOpUserJSDir = $sOpUserJSDir Then Return SetError(2, 0, "") If Not __PathIsFolder($sOpUserJSDir) Then Return SetError(3, 0, "") Local $sOperaPrefs_FileName = __GetOperaPrefsFileName($sOpDir, 0) IniWrite($sOpProfileDir & "\" & $sOperaPrefs_FileName, "User Prefs", "User JavaScript File", $sOpUserJSDir) If $iEnableUserJS = 1 Then IniWrite($sOpProfileDir & "\" & $sOperaPrefs_FileName, "User Prefs", "Browser JavaScript", 2) IniWrite($sOpProfileDir & "\" & $sOperaPrefs_FileName, "User Prefs", "User JavaScript", 1) IniWrite($sOpProfileDir & "\" & $sOperaPrefs_FileName, "User Prefs", "Always Load User JavaScript", 1) EndIf Return $sCurrOpUserJSDir EndFunc ;==>_OperaSetUserJSDir ;=============================================================================== ; ; Function Name: _OperaSetLangFile() ; ; Function Description: Set Opera Language file. ; ; Parameter(s): $sOpLangFile - Full path to Language file that needs to be set. ; $sOpDir - [Optional] Full path to Opera dir, ; so the Language file will be set for specific Opera installation. ; $iCopyToOpDir - [Optional] If this is <> 0 then language file will be copied to Opera's folder. ; $iRepRenFlag - [Optional] Defines replace mode: ; -1 - (default) or 0 will backup existing file in case the lang file is copied. ; (*Without* replacing the existing backup file). ; 1 - will backup existing file in case the lang file is copied. ; (*Will* replace the existing backup file). ; 2 - auto-rename existing file in case the lang file is copied. ; * In other cases existing file will be replaced. ; ; Requirement(s): Opera Browser should be closed; otherwise the written values can be erased by Opera. ; ; Return Value(s): On Success - Set Opera Language file, and return full path to "old" (used) Opera Language file. ; On Failure - Returns "" (empty string), ; and set @error to: ; 1 - Opera profile dir not found. ; 2 - Current Language file = $sOpLangFile. ; 3 - $sOpLangFile not found, or it's not an Opera Language file. ; 4 - $sOpDir (Opera dir) not found. ; 5 - Unable to copy language file (with $iCopyToOpDir mode on). ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaSetLangFile($sOpLangFile, $sOpDir = -1, $iCopyToOpDir = 0, $iRepRenFlag = -1) Local $sOpProfileDir = _OperaGetProfileDir($sOpDir) If @error Then Return SetError(1, 0, "") Local $sCurrOpLangFile = _OperaGetLangFile($sOpDir) If Not @error And $sCurrOpLangFile = $sOpLangFile Then Return SetError(2, 0, "") If Not __PathIsOperaLangFile($sOpLangFile) Then Return SetError(3, 0, "") If $iCopyToOpDir <> 0 Then If Not __PathIsOperaDir($sOpDir) Then $sOpDir = _OperaGetDir() If @error Then Return SetError(4, 0, "") Local $sOpLangName = StringRegExpReplace($sOpLangFile, "^.*\\", "") Local $sOpDestLangFile = $sOpDir & "\" & $sOpLangName Switch $iRepRenFlag Case Default, -1, 0 __Backup_Config($sOpDestLangFile, 0) Case 1 __Backup_Config($sOpDestLangFile, 9) Case 2 $sOpDestLangFile = $sOpDir & "\" & __FileNewName($sOpLangName, $sOpDir) EndSwitch If Not FileCopy($sOpLangFile, $sOpDestLangFile, 9) Then SetError(5, 0, "") $sOpLangFile = $sOpDestLangFile EndIf Local $sOperaPrefs_FileName = __GetOperaPrefsFileName($sOpDir, 0) IniWrite($sOpProfileDir & "\" & $sOperaPrefs_FileName, "User Prefs", "Language File", $sOpLangFile) Return $sCurrOpLangFile EndFunc ;==>_OperaSetLangFile ;=============================================================================== ; ; Function Name: _OperaSelectFolder() ; ; Function Description: Open Browse Dialog to select Opera install dir. ; ; Parameter(s): $sTitle - Title for FileSelectFolder dialog. ; $sErrMsgText - Message string to show when selected wrong path to Opera Browser. ; $sOpDir - [Optional] Full path to initial Opera dir, to start FileSelectFolder dialog with. ; $iInputID - [Optional] Identifier to GUI Edit control, so the selected path will be updated in it. ; ; Requirement(s): None. ; ; Return Value(s): On Success - Return new selected Opera Dir. ; On Failure - Set @error to 1 and return old initial Opera dir ($sOpDir). ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaSelectFolder($sTitle, $sErrMsgText, $sOpDir = "", $iInputID = 0) Local $sSelectOpDir, $sInitDir = $sOpDir While 1 $sSelectOpDir = FileSelectFolder($sTitle, "", 2, $sInitDir) If @error Then Return SetError(1, 0, $sOpDir) If Not __PathIsOperaDir($sSelectOpDir) Then MsgBox(262144 + 48, "Attention", $sErrMsgText) $sInitDir = $sSelectOpDir ContinueLoop EndIf If $iInputID > 0 Then GUICtrlSetData($iInputID, $sSelectOpDir) Return $sSelectOpDir WEnd EndFunc ;==>_OperaSelectFolder ;=============================================================================== ; ; Function Name: _OperaAddMenuItem() ; ; Function Description: Adds Item to Opera menu file. ; ; Parameter(s): $sMenuSection - Menu section name to write the $sItemName. ; $sItemName - Menu item name (user should pass all the item, ; including "Item," and similar prefixes used in Opera). ; $sItemValue - Menu item value. ; $iItemPosition - [Optional] Defines in what position in section the function should write the item. ; * Negative number indicating that position should be checked from the bottom. ; * Default is -1 -> Write to the end of section. ; $sMenuFile - [Optional] Menu file wich is used to write the item ; (default is -1 -> Get current file, see next parameter). ; $sOpDir - [Optional] Opera dir. Used only to search the menu file if $sMenuFile not found. ; (default is -1 -> Get current Opera Dir from registry). ; ; Requirement(s): Opera Browser should be closed; otherwise the written values can be erased by Opera. ; ; Return Value(s): On Success - Returns 1. ; On Failure - Returns 0 and set @error to 1 if unable to add the item. ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaAddMenuItem($sMenuSection, $sItemName, $sItemValue, $iItemPosition = -1, $sMenuFile = -1, $sOpDir = -1) If Not __PathIsOperaConfigFile($sMenuFile) Then $sMenuFile = _OperaGetConfigFile("Menu", $sOpDir) __ExpandOperaMenuSectClassName($sMenuSection) If Not __StringIsUTF8Format($sItemName) Then $sItemName = __StringToUTF($sItemName) If Not __StringIsUTF8Format($sItemValue) Then $sItemValue = __StringToUTF($sItemValue) __Backup_Config($sMenuFile, 1) Local $iRet = __IniWriteToPos($sMenuFile, $sMenuSection, $sItemName, $sItemValue, $iItemPosition) If @error Then SetError(1) Return $iRet EndFunc ;==>_OperaAddMenuItem ;=============================================================================== ; ; Function Name: _OperaRemoveMenuItem() ; ; Function Description: Removes Item from Opera menu file. ; ; Parameter(s): $sMenuSection - Menu section name to search for $sItemName. ; $sItemName - Menu item name (user should pass all the item, ; including "Item," and similar prefixes used in Opera). ; $sItemValue - [Optional] Menu item value, ; to search item by it's value (default is empty string ("") - do not search by value). ; $iRegExpItem - [Optional] Defines whether the deletion should be performed using RegExp pattern or not. ; $sMenuFile - [Optional] Menu file wich is used to delete the item ; (default is -1 -> Get current file, see next parameter). ; $sOpDir - [Optional] Opera dir. Used only to search the menu file if $sMenuFile not found. ; (default is -1 -> Get current Opera Dir from registry). ; ; Requirement(s): Opera Browser should be closed; otherwise the written values can be erased by Opera. ; ; Return Value(s): On Success - Returns 1. ; On Failure - Returns 0 and set @error to 1 if unable to remove the item. ; ; Note(s): If $sItemName or $sItemValue will include non latin characters (not ANSI), ; the function will use case-sensitive comparision when deleting key ; (even with $iRegExpItem = 1 and "(?i)" in the pattern). ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaRemoveMenuItem($sMenuSection, $sItemName, $sItemValue = "", $iRegExpItem = 0, $sMenuFile = -1, $sOpDir = -1) If Not __PathIsOperaConfigFile($sMenuFile) Then $sMenuFile = _OperaGetConfigFile("Menu", $sOpDir) __ExpandOperaMenuSectClassName($sMenuSection) If Not __StringIsUTF8Format($sItemName) Then $sItemName = __StringToUTF($sItemName) If Not __StringIsUTF8Format($sItemValue) Then $sItemValue = __StringToUTF($sItemValue) __Backup_Config($sMenuFile, 1) Local $iRet = 0 If $iRegExpItem Then $iRet = __IniDeleteRegExp($sMenuFile, $sMenuSection, $sItemName, $sItemValue, 1) Else $iRet = IniDelete($sMenuFile, $sMenuSection, $sItemName) EndIf If @error Then SetError(1) Return $iRet EndFunc ;==>_OperaAddMenuItem ;=============================================================================== ; ; Function Name: _OperaIsRuning() ; ; Function Description: Check if Opera Browser process is currently runing. ; ; Parameter(s): $sOpDir - [Optional] Full path to Opera dir, ; to check the run state for the specific Opera executable file. ; ; Requirement(s): None. ; ; Return Value(s): On Success - Return True. ; On Failure - Returns False and set @error to 1 (even if unable check Opera's "Run State"). ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaIsRuning($sOpDir = -1) If Not ProcessExists($s_Opera_Exe) Then Return False If Not __PathIsOperaDir($sOpDir) Then $sOpDir = _OperaGetDir() If __PathIsOperaDir($sOpDir) And __ProcessPathExists($sOpDir & "\" & $s_Opera_Exe) Then Return True Local $sOpProfileDir = _OperaGetProfileDir($sOpDir) If @error Then Return SetError(1, 0, "") Local $sOperaPrefs_FileName = __GetOperaPrefsFileName($sOpDir, 0) Local $nRunState = IniRead($sOpProfileDir & "\" & $sOperaPrefs_FileName, "State", "Run", "Def_ERROR") If $nRunState == "Def_ERROR" Then Return SetError(1, 0, False) Return Not Number($nRunState) = 0 EndFunc ;==>_OperaIsRuning ;=============================================================================== ; ; Function Name: _OperaRun() ; ; Function Description: Run Opera Browser. ; ; Parameter(s): $sOpExec - [Optional] Full path to Opera executable file. ; $vArguments - [Optional] Arguments to pass when executing Opera.exe, can be a *one*-dimentional array. ; $sWorkDir - [Optional] Set Working directory when executing Opera.exe ; (-1 is the default, will set "Opera Dir" as working dir). ; $iState - [Optional] The "show" flag of the executed program, default is @SW_SHOWNORMAL. ; ; Requirement(s): None. ; ; Return Value(s): On Success - Returns 1 if Opera.exe was executed. ; On Failure - Returns 0 (zero) and set @error to: ; 1 - $sOpDir (Opera Dir) not found. ; 2 - Unable to execute Opera.exe. ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaRun($sOpExec = -1, $vArguments = "", $sWorkDir = -1, $iState = @SW_SHOWNORMAL) If Not FileExists($sOpExec) Or StringRight($sOpExec, 4) <> ".exe" Then $sOpExec = _OperaGetDir() & "\" & $s_Opera_Exe If @error Then Return SetError(1, 0, "") Local $sOpt_REF = "RunErrorsFatal" Local $iOld_Opt_REF = -1 ;If @AutoItVersion < "3.2.12.0" Then .... If _VersionCompare(@AutoItVersion, "3.2.12.0") = -1 Then $iOld_Opt_REF = Opt($sOpt_REF, 0) If IsArray($vArguments) And UBound($vArguments, 0) = 1 Then Local $aSwitchArr = $vArguments Local $sSpace = " ", $iUbound = UBound($aSwitchArr) - 1 $vArguments = "" For $i = 1 To $iUbound If $i = $iUbound Then $sSpace = "" $vArguments &= $aSwitchArr[$i] & $sSpace Next EndIf If $sWorkDir = -1 Or $sWorkDir = Default Then $sWorkDir = StringRegExpReplace($sOpExec, "\\[^\\]*$", "") ShellExecute($sOpExec, $vArguments, $sWorkDir, "open", $iState) Local $iError = @error If $iOld_Opt_REF <> -1 Then Opt($sOpt_REF, $iOld_Opt_REF) If $iError Then Return SetError(2, 0, 0) Return 1 EndFunc ;==>_OperaRun ;=============================================================================== ; ; Function Name: _OperaClose() ; ; Function Description: Close Opera Browser. ; ; Parameter(s): $sOpDir - [Optional] Full path to Opera dir, ; so the specific Opera window(s) will be closed. ; $iInstance - [Optional] Defins how many Opera instances to close: ; 0 (default) - will close instanse of Opera related to given/found Opera Dir. ; -1 - will close all found Opera instanses. ; > 0 - will close this much Opera instanses. ; $iForceClose - [Optional] If <> 0 then it will force to close Opera window(s), ; even if there will be a confirm close message (0 is the default). ; ; Requirement(s): None. ; ; Return Value(s): On Success - Return 1 regardless if Opera was closed or not. ; On Failure - Return 0 and set @error to: ; 1 - $sOpDir (Opera Dir) not found. ; 2 - Unable to get Opera title(s). ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaClose($sOpDir = -1, $iInstance = 0, $iForceClose = 0) If Not __PathIsOperaDir($sOpDir) Then $sOpDir = _OperaGetDir() If @error Then Return SetError(1, 0, 0) Switch $iInstance Case 0 Local $hOphWnd = _OperaGetTitle($sOpDir, 0) If @error Then Return SetError(2, 0, 0) Local $sConfirmExitWinExists While WinExists($hOphWnd) Or __ProcessPathExists($sOpDir & "\" & $s_Opera_Exe) If Not WinExists($hOphWnd) Then $hOphWnd = _OperaGetTitle($sOpDir, 0) If @error Then Return 1 EndIf WinActivate($hOphWnd) WinClose($hOphWnd) If $iForceClose <> 0 Then WinWaitClose($hOphWnd, "", 1) If $iForceClose <> 0 And WinExists($hOphWnd) Then $sConfirmExitWinExists = __ConfirmExitOperaWinExists($sOpDir) If $sConfirmExitWinExists <> False Then WinActivate($sConfirmExitWinExists) WinWaitActive($sConfirmExitWinExists, "", 1) ControlSend($sConfirmExitWinExists, "", "", "{ENTER}") Sleep(200) Else WinClose($hOphWnd) EndIf EndIf WEnd Case Else Local $sConfirmExitWinExists, $iWinProc, $sProcPath Local $aOpTitles = _OperaGetTitle("", 2) If @error Then Return SetError(2, 0, 0) If $iInstance < 0 Then $iInstance = $aOpTitles[0][0] For $i = 1 To $iInstance If $i > $aOpTitles[0][0] Then ExitLoop WinClose($aOpTitles[$i][1]) If $iForceClose <> 0 Then WinWaitClose($aOpTitles[$i][1], "", 1) If $iForceClose <> 0 And WinExists($aOpTitles[$i][1]) Then $iWinProc = WinGetProcess($aOpTitles[$i][1]) $sProcPath = StringRegExpReplace(__ProcessGetPath($iWinProc), "\\[^\\]*$", "") While WinExists($aOpTitles[$i][1]) Or ProcessExists($iWinProc) $sConfirmExitWinExists = __ConfirmExitOperaWinExists($sProcPath) If $sConfirmExitWinExists <> False Then WinActivate($sConfirmExitWinExists) ControlSend($sConfirmExitWinExists, "", "", "{ENTER}") Sleep(200) Else WinClose($aOpTitles[$i][1]) EndIf WEnd EndIf Next EndSwitch Return 1 EndFunc ;==>_OperaClose ;=============================================================================== ; ; Function Name: _OperaKill() ; ; Function Description: Kill Opera Browser. ; ; Parameter(s): $sOpDir - [Optional] Full path to Opera dir, ; so the specific Opera process (that executed from Opera dir) will be killed. ; $iInstance - [Optional] Defins how many Opera instances to kill: ; < 1 - (0 is the default) will kill instanse of Opera related to given/found Opera Dir. ; > 0 - will kill this much Opera instanses (processes). ; $iWaitClose - [Optional] If > 0 then function will wait this much time (seconds) ; until Opera process is closed. ; ; Requirement(s): None. ; ; Return Value(s): On Success - Return 1 regardless if Opera process was killed or not. ; On Failure - Returns 0 ; and set @error to: ; 1 - If $iInstance >= 1 and unable to get Opera process(es). ; 2 - If $sOpDir (Opera Dir) not found (when $iInstance < 1). ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaKill($sOpDir = -1, $iInstance = 0, $iWaitClose = 0) Select Case $iInstance >= 1 Local $aOperaPIDs = __GetOperaPIDs() If @error Then Return SetError(1, 0, 0) For $i = 1 To $aOperaPIDs[0] ProcessClose($aOperaPIDs[$i]) If $iWaitClose > 0 Then ProcessWaitClose($aOperaPIDs[$i], $iWaitClose) If $iInstance = $i Then Return 1 Next Case Else If Not __PathIsOperaDir($sOpDir) Then $sOpDir = _OperaGetDir() If @error Then Return SetError(1, 0, 0) Local $iOperaPID = __ProcessPathExists($sOpDir & "\" & $s_Opera_Exe) If @error Then Return SetError(2, 0, 0) ProcessClose($iOperaPID) If $iWaitClose > 0 Then ProcessWaitClose($iOperaPID, $iWaitClose) EndSelect Return 1 EndFunc ;==>_OperaKill ;=============================================================================== ; ; Function Name: _OperaRestart() ; ; Function Description: Restarts Opera Browser. ; ; Parameter(s): $sOpDir - [Optional] Full path to Opera dir, to restart specific Opera instance. ; $iForceClose - [Optional] If <> 0 then it will force to close Opera window(s), ; even if there will be a confirm close message (0 is the default). ; ; Requirement(s): None. ; ; Return Value(s): On Success - Return 1 if Opera restarted. ; On Failure - Returns 0 (zero) and set @error to: ; 1 - $sOpDir (Opera Dir) not found. ; 2 - Unable to close runing Opera.exe process. ; 3 - Unable to execute Opera, error by _OperaRun() function. ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaRestart($sOpDir = -1, $iForceClose = 0) If Not __PathIsOperaDir($sOpDir) Then $sOpDir = _OperaGetDir() If @error Then Return SetError(1, 0, 0) If ProcessExists($s_Opera_Exe) Then _OperaClose($sOpDir, 0, $iForceClose) If @error Then Return SetError(2, 0, 0) EndIf If __ProcessPathExists($sOpDir & "\" & $s_Opera_Exe) Then Return SetError(2, 0, 0) _OperaRun($sOpDir & "\" & $s_Opera_Exe) If @error Then Return SetError(3, 0, 0) Return 1 EndFunc ;==>_OperaRestart ;=============================================================================== ; ; Function Name: _OperaScreenCapture() ; ; Function Description: Make a screenshot of Opera page or entire Opera window. ; ; Parameter(s): $sFileName - [Optional] Full path and extension of the image file to save the screenshot. ; * If FileName is empty string (""), this function will capture the screen and return ; a HBITMAP handle to the bitmap image. In this case, after you are finished with the ; bitmap you must call _WinAPI_DeleteObject to delete the bitmap handle. ; $sOpTitle - [Optional] Opera Window Title to get the screenshot. ; $sOpDir - [Optional] Full path to Opera dir ; (used only to get Opera title of specific runing Opera instance ; in case that $sOpTitle = -1). ; $iCaptCursor - [Optional] If > 0 the cursor will be captured with the image (default is 0). ; $iFullWindow - [Optional] If <> 0 then the function will capture a screenshot for entire Opera window. ; ; Requirement(s): GDI+: GDI+ requires a redistributable for applications that ; run on the Microsoft Windows NT 4.0 SP6, Windows 2000, Windows 98, and Windows Me operating systems. ; ; Return Value(s): On Success - Depending on $sFileName (1 if it's <> "", otherwise HBITMAP handle to the bitmap image). ; On Failure - Returns @error and values as following: ; * Set @error to 1 and returns 0 - unable to activate Opera window. ; * Set @error on 2 and returns __GetOperaPageHandle error: ; -1 - Unable to get Opera page handle, probably popup message appear. ; -2 - Unable to get Opera page handle, other unknown error. ; * Set @error on 3 and returns 0 - unable to capture (or file writing issue). ; * Set @error on 4 and returns 0 - GDI+ error (probably GDI+ not installed). ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaScreenCapture($sFileName = "", $sOpTitle = -1, $sOpDir = -1, $iCaptCursor = 0, $iFullWindow = 0) If $sOpTitle = -1 Or Not WinExists($sOpTitle) Then $sOpTitle = _OperaGetTitle($sOpDir) If @error Or __WinAPI_GetClassName($sOpTitle) <> "OpWindow" Then Return SetError(1, 0, 0) Local $hOp_ScreenCapture Local $iLeft = 0, $iTop = 0, $iRight = -1, $Bottom = -1 WinActivate($sOpTitle) WinWaitActive($sOpTitle, "", 3) If Not WinActive($sOpTitle) Then Return SetError(1, 0, 0) If $iFullWindow = 0 Then $hOp_ScreenCapture = __GetOperaPageHandle($sOpTitle) If @error <> 0 Then Return SetError(2, 0, @error) Else $hOp_ScreenCapture = WinGetHandle($sOpTitle) Local $aCaptureWnd_Pos = WinGetPos($hOp_ScreenCapture) Dim $iLeft = 4, $iTop = 4, $iRight = $aCaptureWnd_Pos[2]-4, $Bottom = $aCaptureWnd_Pos[3]-4 EndIf Local $nRet = _ScreenCapture_CaptureWnd($sFileName, $hOp_ScreenCapture, $iLeft, $iTop, $iRight, $Bottom, $iCaptCursor) Local $iError = @error If $sFileName <> "" Then $nRet = 1 If $iError Then $iError = 3 $nRet = 0 If StringRegExp(@OSVersion, "WIN_2000|WIN_ME|WIN_98|WIN_95") Or _ (@OSVersion = "WIN_NT4" And @OSServicePack = "Service Pack 6") Then $iError = 4 EndIf Return SetError($iError, 0, $nRet) EndFunc ;==>_OperaScreenCapture ;=============================================================================== ; ; Function Name: _OperaMultiUserModeIsOn() ; ; Function Description: Check if Opera installed with Multi User profile. ; ; Parameter(s): $sOpDir - [Optional] Full path to Opera dir, ; to check for specific Opera installed dir. ; ; Requirement(s): None. ; ; Return Value(s): On Success - Returns True if Opera installed with Multi User profile, otherwise returns False. ; On Failure - Returns "" (empty string) and set @error to: ; 1 - Opera dir not found. ; 2 - Unable to read Opera's configuration file. ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _OperaMultiUserModeIsOn($sOpDir = -1) If Not __PathIsOperaDir($sOpDir) Then $sOpDir = _OperaGetDir() If @error Then Return SetError(1, 0, "") Local $sOperaPrefs_DefFileName = __GetOperaPrefsFileName($sOpDir, 1) Local $sReadMultiUser = IniRead($sOpDir & "\" & $sOperaPrefs_DefFileName, "System", "Multi User", "Def_ERROR") If $sReadMultiUser == "Def_ERROR" Then Return SetError(2, 0, "") Return Number($sReadMultiUser) = 1 EndFunc ;==>_OperaMultiUserModeIsOn ;=============================================================================== ; ; Function Name: _Opera_Integration_Example() ; ; Function Description: Show an Example (a "template" if you like ;) ) on how to integrate your app to Opera Browser. ; ; Parameter(s): None. ; ; Requirement(s): None. ; ; Return Value(s): None. ; ; Author(s): G.Sandler (a.k.a CreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _Opera_Integration_Example() #include <GuiConstants.au3> Local $OperaDir, $OperaProfileDir, $OpTitle Local $AppName, $AskIntegr, $OpPathReadInput Local $Intgr_GUI, $OperaPath_Input, $Browse_Button, $OK_Button, $Cancel_Button ;----- Set Opera Preferences ----- $OperaDir = _OperaGetDir() $OperaProfileDir = _OperaGetProfileDir($OperaDir) $AppName = "@Opera Integrator Example@" $OpTitle = _OperaGetTitle($OperaDir) ;----- Integration GUI ----- $AskIntegr = MsgBox(262144 + 36, _ $AppName & " - Integration to Opera", _ "Would you like to integrate this program into Opera Browser?") If $AskIntegr <> 6 Then Return $Intgr_GUI = GUICreate($AppName & " - Integration to Opera", 380, 190) $OperaPath_Input = GUICtrlCreateInput($OperaDir, 20, 120, 320, -1, -1, $SS_BLACKFRAME) GUICtrlSetTip(-1, "Path to browser Opera") $Browse_Button = GUICtrlCreateButton("...", 345, 120, 20, 20) GUICtrlCreateLabel("Type (or select) the path to Opera Browser:", 77, 50, -1, 50, $SS_CENTER) GUICtrlSetFont(-1, 10, 400, 0, "Georgia") GUICtrlCreateIcon($OperaDir & "\" & $s_Opera_Exe, 0, 175, 13) $OK_Button = GUICtrlCreateButton("OK", 110, 150, 50) $Cancel_Button = GUICtrlCreateButton("Cancel", 230, 150, 50) GUISetState(@SW_SHOW, $Intgr_GUI) While 1 Switch GUIGetMsg() Case $Browse_Button $OpPathReadInput = GUICtrlRead($OperaPath_Input) GUISetState(@SW_HIDE, $Intgr_GUI) $OperaDir = _OperaSelectFolder("Please Select Opera dir", _ "Can not find Opera files (" & $s_Opera_Exe & "), please select folder with Opera Browser...", _ $OpPathReadInput, $OperaPath_Input) GUISetState(@SW_SHOW, $Intgr_GUI) Case $OK_Button $OpPathReadInput = GUICtrlRead($OperaPath_Input) If Not __PathIsOperaDir($OpPathReadInput) Then MsgBox(262144 + 48, "Attention", _ "Can not find Opera files (" & $s_Opera_Exe & "), please select folder with Opera Browser...") GUISetState(@SW_HIDE, $Intgr_GUI) $OperaDir = _OperaSelectFolder("Please Select Opera dir", _ "Can not find Opera files (" & $s_Opera_Exe & "), please select folder with Opera Browser...", _ $OpPathReadInput, $OperaPath_Input) GUISetState(@SW_SHOW, $Intgr_GUI) EndIf If FileExists($OpPathReadInput & "\" & $s_Opera_Exe) Then GUIDelete($Intgr_GUI) ;Integration_Proc() ;Here is should be whatever you like to do when user ready to integrate your Application to Opera. MsgBox(262144 + 64, $AppName & " - Finishing..", "Integration to Opera is successful completed!") ExitLoop EndIf Case $GUI_EVENT_CLOSE, $Cancel_Button GUIDelete($Intgr_GUI) ExitLoop EndSwitch WEnd EndFunc ;==>_Opera_Integration_Example ;=============================================================================== ; ; Function Name: OpenGetURL() ; Function Description: Open/Get URL in/from certain browser using DDE. ; ; Parameter(s): $sURL - [Optional] Address of page to open, ; if this is empty string (default), then returned Url from address field of particular tab. ; $iWin - [Optional] Number of tab: ; -1 - Current tab. ; 0 - New tab (when opening). ; $iRetType - [Optional] Definds returned value: ; 0 - String with Title and URL address. ; 1 - Array with 3 elements... ; $aRetArr[0] = Title ; $aRetArr[1] = URL address ; $aRetArr[2] = String with Title And URL address. ; $sServer - [Optional] Serever to open/get Url in/from. ; $iWait - [Optional] Waiting Timeout in milliseconds, on overload will return an error. ; ; Requirement(s): None ; Return Value(s): On Success - See 'Parameter(s)'. ; On Failure - Returns "" (empty string) and set @error to: ; 1 - Error to open Dll (user32.dll) ; 2 - Error Initializing DDE ; (@extended includes more details about returned value from DllCall). ; 3 - Other DDE Errors ; (@extended macro include more details about returned value from DllCall). ; Author(s): amel27 (A.Melnichuk) ; ;===================================================================== Func _OpenGetURL($sURL = "", $iWin = -1, $iRetType = 0, $sServer = "Opera", $iWait = 10000) Local $aRet, $uIdInst = DllStructCreate("int") Local $hServer[1], $hTopic[1], $hItem[1], $hConv[1], $hData[1], $sData[1] Local $sTopic = "WWW_OpenURL", $sItem = $sURL & ',,0x' & Hex($iWin) If $sURL = '' Then $sTopic = "WWW_GetWindowInfo" $sItem = "0x" & Hex($iWin) EndIf Local $hDll = DllOpen("user32.dll") If $hDll = -1 Then Return SetError(1, 0, "") ; Error to open Dll $aRet = DllCall("user32.dll", "int", "DdeInitialize", "ptr", DllStructGetPtr($uIdInst), "ptr", 0, "int", 0, "int", 0) If $aRet[0] Then Return SetError(2, $aRet[0], "") ; Error Initializing DDE $hServer = DllCall($hDll, "int", "DdeCreateStringHandle", "int", DllStructGetData($uIdInst, 1), "str", $sServer, "int", 1004) If $hServer[0] Then $hTopic = DllCall($hDll, "int", "DdeCreateStringHandle", "int", DllStructGetData($uIdInst, 1), "str", $sTopic, "int", 1004) If $hTopic[0] Then $hItem = DllCall($hDll, "int", "DdeCreateStringHandle", _ "int", DllStructGetData($uIdInst, 1), "str", $sItem, "int", 1004) If $hItem[0] Then $hConv = DllCall($hDll, "int", "DdeConnect", "int", _ DllStructGetData($uIdInst, 1), "int", $hServer[0], "int", $hTopic[0], "int", 0) If $hConv[0] Then $hData = DllCall($hDll, "int", "DdeClientTransaction", "ptr", 0, "int", 0, _ "int", $hConv[0], "int", $hItem[0], "int", 1, "int", 0x20B0, "int", $iWait, "ptr", 0) If $hData[0] Then $sData = DllCall($hDll, "str", "DdeAccessData", "int", $hData[0], "ptr", 0) EndIf EndIf EndIf EndIf $iErr = DllCall($hDll, "int", "DdeGetLastError", "int", DllStructGetData($uIdInst, 1)) If $hData[0] Then DllCall($hDll, "int", "DdeFreeDataHandle", "int", $hData[0]) If $hConv[0] Then DllCall($hDll, "int", "DdeFreeDataHandle", "int", $hConv[0]) If $hItem[0] Then DllCall($hDll, "int", "DdeFreeDataHandle", "int", $hItem[0]) If $hTopic[0] Then DllCall($hDll, "int", "DdeFreeDataHandle", "int", $hTopic[0]) If $hServer[0] Then DllCall($hDll, "int", "DdeFreeDataHandle", "int", $hServer[0]) If $iErr[0] Then Return SetError(3, $iErr[0], "") ; Othe DDE Errors DllCall($hDll, "int", "DdeUninitialize", "int", DllStructGetData($uIdInst, 1)) DllClose($hDll) If StringRight($sData[0], 3) = ',""' Then $sData[0] = StringTrimRight($sData[0], 3) If $sURL = '' Then $sURL = StringRegExpReplace($sData[0], '^"([^"]*?)".*', '"\1"') If $iRetType = 1 Then Local $sRetTitle = StringReplace(StringTrimLeft($sData[0], StringLen($sURL) + 1), '\"', '"') Local $aRetArr[3] = [$sRetTitle, $sURL, StringReplace($sData[0], '\"', '"') ] Return $aRetArr EndIf Return $sURL EndFunc ;==>_OpenGetURL #Region ================================ Internal Functions ================================ ;Extended function to return Title Func __WinGetTitleEx($sExTitle) If IsHWnd($sExTitle) Then Return WinGetTitle($sExTitle) Local $iOld_Opt_WTMM = Opt("WinTitleMatchMode", 2) Local $sRetTitle = __ProcessPathExists($sExTitle) If $sRetTitle Then $sRetTitle = __WinGetTitleByPID($sRetTitle) If Not $sRetTitle Then $RetTitle = WinGetTitle($sExTitle) If Not WinExists($sRetTitle) Or Not $sRetTitle Then Opt("WinTitleMatchMode", 4) $sRetTitle = WinGetTitle($sExTitle) If Not $sRetTitle Then $sRetTitle = WinGetTitle("[REGEXPTITLE:(?i)(.*)" & $sExTitle & "(.*)]") EndIf Opt("WinTitleMatchMode", $iOld_Opt_WTMM) Return $sRetTitle EndFunc ;==>__WinGetTitleEx ;Retrieves Title base on given PID (Process ID) ;Based on Smoke_N's _WinGetHandleByPID() Func __WinGetTitleByPID($iPID, $iRetMode = 1) If IsString($iPID) Then $iPID = ProcessExists($iPID) Local $aWList = WinList(), $sHold For $iCC = 1 To $aWList[0][0] If WinGetProcess($aWList[$iCC][1]) = $iPID And BitAND(WinGetState($aWList[$iCC][1]), 2) Then If $iRetMode = 1 Then Return $aWList[$iCC][0] $sHold &= $aWList[$iCC][0] & Chr(1) EndIf Next If $sHold Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1)) Return SetError(1, 0, 0) EndFunc ;==>__WinGetTitleByPID ;Check if given path is a runing process and return PID of that process. Func __ProcessPathExists($sPath) If Not FileExists($sPath) Then Return SetError(1, 0, False) Local $sPathName = StringRegExpReplace($sPath, "^.*\\", "") Local $aProcList = ProcessList($sPathName) If Not ProcessExists($sPathName) Then Return SetError(2, 0, False) Local $iUbound = UBound($aProcList) - 1 Local $aProc, $aPath, $iError = 0, $sReturn = False Local $hKernel32DllOpen = DllOpen('kernel32.dll') Local $hPsapiDllOpen = DllOpen('Psapi.dll') Local $vStruct = DllStructCreate('int[1024]') For $i = 1 To $iUbound $aProc = DllCall($hKernel32DllOpen, 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $aProcList[$i][1]) If Not IsArray($aProc) Or Not $aProc[0] Then $iError = 3 ExitLoop EndIf DllCall($hPsapiDllOpen, 'int', 'EnumProcessModules', _ 'hwnd', $aProc[0], _ 'ptr', DllStructGetPtr($vStruct), _ 'int', DllStructGetSize($vStruct), _ 'int*', 0) $aPath = DllCall($hPsapiDllOpen, 'int', 'GetModuleFileNameEx', _ 'hwnd', $aProc[0], _ 'int', DllStructGetData($vStruct, 1), _ 'str', '', _ 'int', 2048) If IsArray($aPath) And $aPath[3] = $sPath Then $sReturn = $aProcList[$i][1] ExitLoop EndIf Next DllClose($hKernel32DllOpen) DllClose($hPsapiDllOpen) Return SetError($iError, $iUbound, $sReturn) EndFunc ;==>__ProcessPathExists ;Retrieves Path based on given PID (Process ID) Func __ProcessGetPath($iPID) If StringRight($iPID, 3) = "exe" Then $iPID = ProcessExists($iPID) If Not ProcessExists($iPID) Then Return SetError(1, 0, "") Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID) If Not IsArray($aProc) Or Not $aProc[0] Then Return SetError(1, 0, '') Local $vStruct = DllStructCreate('int[1024]') Local $hPsapi_Dll = DllOpen('Psapi.dll') If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@SystemDir & '\Psapi.dll') If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@WindowsDir & '\Psapi.dll') If $hPsapi_Dll = -1 Then Return SetError(2, 0, '') DllCall($hPsapi_Dll, 'int', 'EnumProcessModules', _ 'hwnd', $aProc[0], _ 'ptr', DllStructGetPtr($vStruct), _ 'int', DllStructGetSize($vStruct), _ 'int*', 0) Local $aRet = DllCall($hPsapi_Dll, 'int', 'GetModuleFileNameEx', _ 'hwnd', $aProc[0], _ 'int', DllStructGetData($vStruct, 1), _ 'str', '', _ 'int', 2048) DllClose($hPsapi_Dll) If Not IsArray($aRet) Or StringLen($aRet[3]) = 0 Then Return SetError(3, 0, '') Return $aRet[3] EndFunc ;==>__ProcessGetPath ;Check if given path is an existing directory Func __PathIsFolder($sPath) Return StringInStr(FileGetAttrib($sPath), "D") > 0 EndFunc ;==>__PathIsFolder ;Check if given path is an Opera's Install Dir Func __PathIsOperaDir($sPath) Return FileExists($sPath & "\" & $s_Opera_Exe) = 1 EndFunc ;==>__PathIsOperaDir ;Check if given path is an Opera's Profile Dir Func __PathIsOperaProfileDir($sPath) Return __PathIsOperaConfigFile($sPath & "\opera6.ini") Or __PathIsOperaConfigFile($sPath & "\operaprefs.ini") EndFunc ;==>__PathIsOperaProfileDir ;Check if given path is an Opera's Configuration file Func __PathIsOperaConfigFile($sPath) Local $hFileOpen = FileOpen($sPath, 0) If $hFileOpen = -1 Then Return False Local $sReadLines = FileReadLine($hFileOpen, 1) & FileReadLine($hFileOpen, 2) & FileReadLine($hFileOpen, 3) FileClose($hFileOpen) Return FileExists($sPath) And StringRight($sPath, 4) = ".ini" And StringInStr($sReadLines, "Opera Preferences") EndFunc ;==>__PathIsOperaConfigFile ;Check if given path is an Opera's Language file Func __PathIsOperaLangFile($sPath) Local $hFileOpen = FileOpen($sPath, 0) If $hFileOpen = -1 Then Return False Local $sReadLines = FileReadLine($hFileOpen, 1) & FileReadLine($hFileOpen, 2) & FileReadLine($hFileOpen, 3) FileClose($hFileOpen) Return FileExists($sPath) And StringRight($sPath, 4) = ".lng" And StringInStr($sReadLines, "Opera Language") EndFunc ;==>__PathIsOperaLangFile ;Check if given path is an Opera's Skin file Func __PathIsOperaSkinFile($sPath) Return FileExists($sPath) = 1 And StringRight($sPath, 4) = ".zip" EndFunc ;==>__PathIsOperaSkinFile ;Check if given path is an Opera's Bookmarks file Func __PathIsOperaBookmarksFile($sPath) Return FileExists($sPath) = 1 And StringRight($sPath, 4) = ".adr" EndFunc ;==>__PathIsOperaSkinFile ;Check if Prefix string is a supported string to use as Opera's Configuration file Func __PrefixStrIsOperaConfig($sConfig_Prefix) Return StringRegExp($sConfig_Prefix, "(?i)\A(Menu|Toolbar|Keyboard|Mouse)$") = 1 EndFunc ;==>__PrefixStrIsOperaConfig ;Check the existing of Opera's dialog that prompt about closing Opera Browser, if exists Title of that dialog is returned Func __ConfirmExitOperaWinExists($sOpDir = -1) Local $sLangFile = _OperaGetLangFile($sOpDir) If @error Then Return SetError(1, 0, False) Local $sOpExitTitle = IniRead($sLangFile, "Translation", "1534399195", "") Local $sOpActiveTransTitle = IniRead($sLangFile, "Translation", "603725896", "") If __StringIsUTF8Format($sOpExitTitle) Then $sOpExitTitle = __UTF8ToAnsi($sOpExitTitle) If __StringIsUTF8Format($sOpActiveTransTitle) Then $sOpActiveTransTitle = __UTF8ToAnsi($sOpActiveTransTitle) If $sOpExitTitle <> "" And WinExists($sOpExitTitle) Then Return "[TITLE:" & $sOpExitTitle & "; CLASS:OpWindow]" If $sOpActiveTransTitle <> "" And WinExists($sOpActiveTransTitle) Then _ Return "[TITLE:" & $sOpActiveTransTitle & "; CLASS:OpWindow]" Return False EndFunc ;==>__ConfirmExitOperaWinExists ;Correct strange path classes used in Opera 10 Func __Correct_Opera_Path(ByRef $sPath, $sOpDir, $sOpProfileDir) $sPath = StringReplace($sPath, "{Resources}", $sOpDir & "\") $sPath = StringReplace($sPath, "{LargePrefs}", $sOpProfileDir & "\") EndFunc ;==>__Correct_Opera_Path ;Retrieves all runing Opera's PIDs (Process IDs) Func __GetOperaPIDs() Local $aProcList = ProcessList($s_Opera_Exe) If @error Then Return SetError(1, 0, 0) Local $aRetPIDs[1] For $i = 1 To UBound($aProcList) - 1 $aRetPIDs[0] += 1 ReDim $aRetPIDs[$aRetPIDs[0] + 1] $aRetPIDs[$aRetPIDs[0]] = $aProcList[$i][1] Next Return $aRetPIDs EndFunc ;==>__GetOperaPIDs ;Returns OperaPrefs file name (to be compatible with different Opera versions) Func __GetOperaPrefsFileName($sOpDir = -1, $iDefault = 0) If Not __PathIsOperaDir($sOpDir) Then $sOpDir = _OperaGetDir() Local $sOperaPrefs_FileName = "Opera6.ini" Local $sOperaPrefs_DefFileName = "Operadef6.ini" If Not FileExists($sOpDir & "\" & $sOperaPrefs_DefFileName) And _VersionCompare(_OperaGetVersion($sOpDir), "10") <> -1 Then $sOperaPrefs_FileName = "Operaprefs.ini" $sOperaPrefs_DefFileName = "operaprefs_default.ini" EndIf If $iDefault Then Return $sOperaPrefs_DefFileName Return $sOperaPrefs_FileName EndFunc ;==>__GetOperaPrefsFileName ;Retrieves Opera page's body control handle Func __GetOperaPageHandle($sTitle) Local $sPart_OpTitle = StringRegExpReplace($sTitle, "(.*) -.*$", "\1") Local $hOpWnd = WinGetHandle($sTitle) Local $hCB_ChildWnds = DllCallbackRegister("__EnumOperaChildWindowsProc", "int", "hwnd;lparam") DllCall("User32.dll", "int", "EnumChildWindows", "hwnd", $hOpWnd, "int", DllCallbackGetPtr($hCB_ChildWnds), "int", 1) DllCallbackFree($hCB_ChildWnds) For $hWndChild In $a_OperaChildWindows If Not IsHWnd($hWndChild) Then ContinueLoop $sGetChildTitle = WinGetTitle($hWndChild) If $sGetChildTitle = $sPart_OpTitle Or $sGetChildTitle = $sTitle Then Local $hLast_OpWnd = 0 $hLast_OpWnd = __WinAPI_FindWindowEx($hWndChild, 0, 'OperaWindowClass') $hLast_OpWnd = __WinAPI_FindWindowEx($hLast_OpWnd, 0, 'OpWindow') $hLast_OpWnd = __WinAPI_FindWindowEx($hLast_OpWnd, 0, 'OperaWindowClass') $hLast_OpWnd = __WinAPI_FindWindowEx($hLast_OpWnd, 0, 'OperaWindowClass') $a_OperaChildWindows = 0 If $hLast_OpWnd = 0 Then Return SetError(-1, 0, 0) Return $hLast_OpWnd EndIf Next $a_OperaChildWindows = 0 Return SetError(-2, 0, 0) EndFunc ;==>__GetOperaPageHandle ;CallBack function to enumerate opera child windows Func __EnumOperaChildWindowsProc($hWnd, $lParam) Local $i_Ubound = UBound($a_OperaChildWindows) ReDim $a_OperaChildWindows[$i_Ubound+1] $a_OperaChildWindows[$i_Ubound] = $hWnd Return True ; To get next window EndFunc ;==>__EnumOperaChildWindowsProc ;Converts Menu ClassName into Opera Menu Section Name Func __ExpandOperaMenuSectClassName(ByRef $sMenuSectClassName) $sMenuSectClassName = StringRegExpReplace($sMenuSectClassName, "\A\[+|\]+\z", "") Local $aMenu_Classes = StringSplit( _ "Main|File|Edit|View|Bookmarks|Widgets|Feeds|Mail|Chat|Tools|Window|Help|" & _ "Documents|HotClick|Link|Selected.Link|Image|Image.Link", "|") Local $aMenu_Classes_Expand = StringSplit( _ "Browser Menu Bar|Browser File Menu|Browser Edit Menu|Browser View Menu|Browser Bookmarks Menu|" & _ "Browser Widgets Menu|Browser Feeds Menu|Browser Mail Menu|Browser Chat Menu|Browser Tools Menu|" & _ "Browser Window Menu|Browser Help Menu|Documents Popup Menu|Hotclick Popup Menu|Link Popup Menu|" & _ "Link Selection Popup Menu|Image Popup Menu|Image Link Popup Menu", "|") For $i = 1 To $aMenu_Classes[0] $sMenuSectClassName = StringRegExpReplace($sMenuSectClassName, _ "\A(?i)" & $aMenu_Classes[$i] & ".Menu\z", $aMenu_Classes_Expand[$i]) Next EndFunc ;==>__ExpandOperaMenuSectClassName ;Perform a backup operation for specific file Func __Backup_Config($sSourceFile, $iReplaceFlag = 0) Local $iBackupMode = 0 Switch $iReplaceFlag Case 1, 8, 1 + 8 $iBackupMode = $iReplaceFlag Case Else $iBackupMode = 0 EndSwitch FileCopy($sSourceFile, $sSourceFile & ".bak", $iBackupMode) EndFunc ;==>__Backup_Config ;Retrieves new file name for existing file (File (1).txt, File (2).txt etc.) ;by amel27 (A.Melnichuk), mod. by MsCreatoR (G.Sandler) Func __FileNewName($sFileName, $sDir, $sDelim1 = -1, $sDelim2 = -2) If Not __PathIsFolder($sDir) Then Return $sFileName If Not FileExists($sDir & "\" & $sFileName) Then Return $sFileName $sDir = StringRegExpReplace($sDir, "\\ *$", "") Local $sName = StringRegExpReplace($sFileName, "\.[^.]*$", "") Local $sExtn = StringMid($sFileName, StringLen($sName) + 1) Local $iCount = 1, $sRet_FileName = $sFileName While FileExists($sDir & "\" & $sRet_FileName) If $sDelim1 = -1 And $sDelim2 = -2 Then $sRet_FileName = $sName & " (" & $iCount & ")" & $sExtn ElseIf $sDelim1 <> -1 And $sDelim2 <> -2 Then $sRet_FileName = $sName & $sDelim1 & $iCount & $sDelim2 & $sExtn ElseIf $sDelim1 <> -1 And $sDelim2 = -2 Then $sRet_FileName = $sName & $sDelim1 & $iCount & $sExtn EndIf $iCount += 1 WEnd Return $sRet_FileName EndFunc ;==>__FileNewName ;Convert UTF-8 String to ANSI string ;by amel27 (A.Melnichuk) Func __UTF8ToAnsi($sUTF8) Local $iLen = StringLen($sUTF8) Local $stBuf = DllStructCreate("byte[" & $iLen * 2 & "];byte[2]") Local $aRet = DllCall("Kernel32.dll", "int", "MultiByteToWideChar", _ "int", 65001, "int", 0, _ "str", $sUTF8, "int", -1, _ "ptr", DllStructGetPtr($stBuf), "int", $iLen * 2 + 2) Local $stOut = DllStructCreate("char[" & $iLen & "];char") $aRet = DllCall("kernel32.dll", "int", "WideCharToMultiByte", _ "int", 0, "int", 0, _ "ptr", DllStructGetPtr($stBuf), "int", -1, _ "ptr", DllStructGetPtr($stOut), "int", $iLen + 1, _ "int", 0, "int", 0) Return DllStructGetData($stOut, 1) EndFunc ;==>__UTF8ToAnsi ;Check if string contain a UTF-8 format characters ;by amel27 (A.Melnichuk) Func __StringIsUTF8Format($sString) Local $sAsc, $sLen = StringLen($sString), $sExt = $sLen For $i = 1 To $sLen $sAsc = Asc(StringMid($sString, $i, 1)) If Not BitAND($sAsc, 0x80) Then $sExt = 0 ElseIf Not BitXOR(BitAND($sAsc, 0xE0), 0xC0) Then $sExt = 1 ElseIf Not (BitXOR(BitAND($sAsc, 0xF0), 0xE0)) Then $sExt = 2 ElseIf Not BitXOR(BitAND($sAsc, 0xF8), 0xF0) Then $sExt = 3 EndIf If $i + $sExt > $sLen Then Return False For $j = $i + 1 To $i + $sExt $sAsc = Asc(StringMid($sString, $j, 1)) If BitXOR(BitAND($sAsc, 0xC0), 0x80) Then Return False Next $i += $sExt Next Return True EndFunc ;==>__StringIsUTF8Format ;Convert string to UTF-8 format ;by LEX1 (A.Ruzanov) Func __StringToUTF($sString) Local $sResult = "", $iCode Local $aUTF_Split = StringSplit($sString, "") For $i = 1 To $aUTF_Split[0] $iCode = Asc($aUTF_Split[$i]) Select Case $iCode >= 192 And $iCode <= 239 $aUTF_Split[$i] = Chr(208) & Chr($iCode - 48) Case $iCode >= 240 And $iCode <= 255 $aUTF_Split[$i] = Chr(209) & Chr($iCode - 112) Case $iCode = 168 $aUTF_Split[$i] = Chr(208) & Chr(129) Case $iCode = 184 $aUTF_Split[$i] = Chr(209) & Chr(145) Case Else $aUTF_Split[$i] = Chr($iCode) EndSelect $sResult &= $aUTF_Split[$i] Next Return $sResult EndFunc ;==>__StringToUTF ;IniWrite function allows to write to certain position in the section (-N supported to reverse positioning) Func __IniWriteToPos($sIniFile, $sSection, $sKey, $sValue, $iPos=-1) If $iPos = -1 Then Return IniWrite($sIniFile, $sSection, $sKey, $sValue) If IniRead($sIniFile, $sSection, $sKey, "Def_Error") <> "Def_Error" Then Return IniWrite($sIniFile, $sSection, $sKey, $sValue) Local $hFileOpen, $aFileRead, $iCounter = 0, $iNew_Counter = 0, $iPos_Mark = 0, $iPos_Check = 0 Local $iKeyWritten = 0, $sIni_Content = "" $aFileRead = StringSplit(StringStripCR(FileRead($sIniFile)), @LF) If @error Then Return SetError(1, 0, 0) For $i = 1 To $aFileRead[0] If $aFileRead[$i] = "[" & $sSection & "]" Then $sIni_Content &= $aFileRead[$i] & @CRLF $i += 1 If $iPos < 0 Then $iPos_Mark = $i While 1 If $i > $aFileRead[0] Or StringRegExp($aFileRead[$i], "\A(;|)\[.*?\]\z") Then ExitLoop If $aFileRead[$i] <> "" Then $iCounter += 1 If StringRegExpReplace($aFileRead[$i], "\A(.*?)(=.*|$)", "\1") = $sKey Then _ Return IniWrite($sIniFile, $sSection, $sKey, $sValue) If $iPos > 0 Then If $iCounter = $iPos Then $iKeyWritten = 1 $sIni_Content &= $sKey & "=" & $sValue & @CRLF & $aFileRead[$i] & @CRLF ExitLoop EndIf $sIni_Content &= $aFileRead[$i] & @CRLF EndIf $i += 1 WEnd If $iPos < 0 Then $iPos_Check = BitNOT($iPos-1) For $j = $iPos_Mark To $i If $j > $aFileRead[0] Then ExitLoop If $aFileRead[$j] <> "" Then $iNew_Counter += 1 If $iCounter-$iNew_Counter = $iPos_Check-1 Then $iKeyWritten = 1 $sIni_Content &= $aFileRead[$j] & @CRLF & $sKey & "=" & $sValue & @CRLF Else $sIni_Content &= $aFileRead[$j] & @CRLF EndIf Next EndIf Else $sIni_Content &= $aFileRead[$i] & @CRLF EndIf Next If Not $iKeyWritten Then If $iPos < 0 Then Return __IniWriteToPos($sIniFile, $sSection, $sKey, $sValue, 1) Return IniWrite($sIniFile, $sSection, $sKey, $sValue) EndIf $hFileOpen = FileOpen($sIniFile, 2) If $hFileOpen = -1 Then Return SetError(2, 0, 0) FileWrite($hFileOpen, StringStripWS($sIni_Content, 2)) FileClose($hFileOpen) Return 1 EndFunc ;==>__IniWriteToPos ;IniDelete function allows to delete certain key(s) using RegExp engine + delete by key value Func __IniDeleteRegExp($sIniFile, $sSectionName, $sKeyPattern, $sValue="", $iDelCount=1) If Not FileExists($sIniFile) Then Return SetError(1, 0, -1) Local $aReadIniSectArr = IniReadSection($sIniFile, $sSectionName) If @error Then Return SetError(2, 0, 0) If Not IsArray($aReadIniSectArr) Then Return SetError(3, 0, 0) Local $sCurrentKey, $sCurrentValue, $iDel_Counter = 0 For $i = 1 To $aReadIniSectArr[0][0] $sCurrentKey = $aReadIniSectArr[$i][0] $sCurrentValue = $aReadIniSectArr[$i][1] If StringRegExp($sCurrentKey, $sKeyPattern) And StringRegExp($sCurrentValue, $sValue) Then IniDelete($sIniFile, $sSectionName, $sCurrentKey) $iDel_Counter += 1 If $iDel_Counter = $iDelCount Then Return 1 EndIf Next EndFunc ;==>__IniDeleteRegExp ;Extended function to find window (by parent/child handle, class name and window name Func __WinAPI_FindWindowEx($hWnd_Parent, $hWnd_Child, $sClass_Name="", $sWindow_Name="") Local $aResult = DllCall("User32.dll", "hwnd", "FindWindowEx", _ "hwnd", $hWnd_Parent, "hwnd", $hWnd_Child, "str", $sClass_Name, "str", $sWindow_Name) Return $aResult[0] EndFunc ;==>__WinAPI_FindWindowEx Func __WinAPI_GetClassName($hWnd) If Not IsHWnd($hWnd) Then If IsString($hWnd) Then $hWnd = WinGetHandle($hWnd) Else $hWnd = GUICtrlGetHandle($hWnd) EndIf EndIf Local $aResult = DllCall("User32.dll", "int", "GetClassName", "hwnd", $hWnd, "str", "", "int", 4096) If @error Then Return SetError(@error, 0, "") Return $aResult[2] EndFunc #EndRegion ================================ Internal Functions ================================
Dauerhaft angemeldet bleiben?