Jump to content
Sign in to follow this  
Rizonetech

Tame the fox with Firemin

Recommended Posts

Rizonetech

Here is a scrpt I did some time ago. Firemin reduces the memory Firefox uses. I know that Windows will also periodically scan running processes and tell them to release their unused memory. You could argue that this makes Firemin unnecessary, and you would be spot on. However, It is my opinion that Windows does not clean out memory as often as I would like it to. Firemin runs the clean memory API call a few times per second. The method Firemin uses to decrease Firefox memory usage is not proven and the debate over if it works or not will go on until the end of time, but here is my opinion; If Firemin works for you, use it and if it does not, delete it!

Firemin-Options.jpg

You can download Firemin and Source Code at: https://www.rizonesoft.com/download/firemin/ or view the script below:

Firemin.au3

 

 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Resources\Firemin.ico
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Description=Firemin
#AutoIt3Wrapper_Res_Fileversion=2.0.8.2087
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#AutoIt3Wrapper_Res_LegalCopyright=© 2014 Rizonesoft
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Res_Icon_Add=Resources\Facebook.ico
#AutoIt3Wrapper_Res_Icon_Add=Resources\Twitter.ico
#AutoIt3Wrapper_Res_Icon_Add=Resources\Palfarm.ico
#AutoIt3Wrapper_Res_Icon_Add=Resources\LinkedIn.ico
#AutoIt3Wrapper_Res_Icon_Add=Resources\Google.ico
#AutoIt3Wrapper_Res_Icon_Add=Resources\RSS.ico
#AutoIt3Wrapper_Res_Icon_Add=Resources\Info.ico
#AutoIt3Wrapper_Res_Icon_Add=Resources\PayPal.ico
#AutoIt3Wrapper_Res_File_Add=resources\gradbar.jpg, rt_rcdata, GRADBAR_IMAGE
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****


Opt("GUICloseOnESC", 0)             ;1=ESC  closes, 0=ESC won't close
Opt("GUIOnEventMode", 1)            ;0=disabled, 1=OnEvent mode enabled
Opt("TrayOnEventMode", 1)
Opt("MustDeclareVars", 1)           ;0=no, 1=require pre-declare
Opt("TrayAutoPause", 0)
Opt("TrayMenuMode", 3)


;~ #include <WindowsConstants.au3>
#include <StaticConstants.au3>
;~ #include <ButtonConstants.au3>
#include <GuiConstantsEx.au3>
#include <WinAPIProc.au3>
;~ #include <GuiEdit.au3>
#include <Misc.au3>

#include <UDF\Functions.au3>
#include <UDF\Resources.au3>
;#include <UDF\MemBoost.au3>


_Singleton(@ScriptName, 0)


Global $PATH_FIREFOX = ""
If @OSArch = "X64" Then
    $PATH_FIREFOX = @HomeDrive & "Program Files (x86)\Mozilla Firefox\firefox.exe"
Else
    $PATH_FIREFOX = @ProgramFilesDir & "\Mozilla Firefox\firefox.exe"
EndIf


Global $PATH_FIREFOXPROFILE = @AppDataDir & "\Mozilla\Firefox\Profiles"
Global $BIN_SQLITE = @ScriptDir & "\Bin\sqlite3.exe"
Global $USB_FIREFOX = @ScriptDir & "\FirefoxPortable.exe"
Global $USB_FIREFOXPROFILE = "\Data\profile"
Global $INI_FILE =  @ScriptDir & "\Firemin.ini"
Global $INI_BOOST = IniRead($INI_FILE, "Firemin", "Boost", 250)
Global $INI_LAUNCH = IniRead($INI_FILE, "Firemin", "Launch", 0)
Global $INI_FIREFOXPATH = IniRead($INI_FILE, "Firemin", "Path", $PATH_FIREFOX)

Global $fboGui, $tmnuAbout, $tmnuOptions, $tmnuOFire, $tmnuLaFire, $tmnuLaFSafe, $tmnuClose, $sldrMillisec
Global $msCount = 0, $lblSldValue, $radLchFire, $radLchSafe, $radLchNone, $chkAutStart
Global $inpFireLoc, $btnFireLoc, $ffPSize = 0, $dbScnd = 0
Global $aboutDlg


If Not FileExists($BIN_SQLITE) Then
    MsgBox(262160, "Firemin",    "Unfortunately the Optimize Firefox option will not be available, because the " & _
                                "‘\Bin\ sqlite3.exe’ could not be found. Why you assumed it was a good idea to delete it, we will never know.", 60)
EndIf


If $INI_LAUNCH = 1 Then _LaunchFirefox()
If $INI_LAUNCH = 2 Then _LaunchFirefoxSafeMode()


Func _LaunchFirefox()
    If Not ProcessExists("firefox.exe") Then
        ShellExecute($PATH_FIREFOX)
    EndIf
EndFunc


Func _LaunchFirefoxSafeMode()
    If Not ProcessExists("firefox.exe") Then
        ShellExecute($PATH_FIREFOX, "-safe-mode")
    EndIf
EndFunc


coreInterface()


Func coreInterface()

    ;~ Build Firemin Tray Menu
    $tmnuAbout = TrayCreateItem("About Firemin...")
    TrayCreateItem("")
    $tmnuOptions = TrayCreateItem("Options...")
    TrayCreateItem("")
    $tmnuOFire = TrayCreateItem("Optimize Firefox")
    If Not FileExists($BIN_SQLITE) Then TrayItemSetState($tmnuOFire, 128) ;~ $GUI_DISABLE = 128
    TrayCreateItem("")
    $tmnuLaFire = TrayCreateItem("Launch Firefox")
    $tmnuLaFSafe = TrayCreateItem("Launch Firefox in Safemode")
    TrayCreateItem("")
    $tmnuClose = TrayCreateItem("Close")

    TrayItemSetOnEvent($tmnuAbout, "_ShowAboutDlg")
    TrayItemSetOnEvent($tmnuOptions, "_OptionsDlg")
    TrayItemSetOnEvent($tmnuOFire, "_VacuumFirefox")
    TrayItemSetOnEvent($tmnuLaFire, "_LaunchFirefox")
    TrayItemSetOnEvent($tmnuLaFSafe, "_LaunchFirefoxSafeMode")
    TrayItemSetOnEvent($tmnuClose, "_CloseFiremin")

    TraySetState()
    TraySetClick(8)

    TraySetToolTip("Firemin " & FileGetVersion(@ScriptFullPath))

    AdlibRegister("_OptimizeFireFox", $INI_BOOST)

    While 1
        Sleep(100)
        _WinAPI_EmptyWorkingSet()
    WEnd

EndFunc


Func _CloseFiremin()
    TraySetState(2)
    Exit
EndFunc


Func _OptimizeFireFox()

    Local $aProcsList, $aPIniList

    $aPIniList = StringSplit("firefox.exe|plugin-container.exe", "|")

    $aProcsList = ProcessList()
    For $i = 1 To $aProcsList[0][0]
        For $x = 1 To $aPIniList[0]
            If $aProcsList[$i][0] = $aPIniList[$x] Then
                _WinAPI_EmptyWorkingSet($aProcsList[$i][1])
            EndIf
        Next
    Next

EndFunc


Func _VacuumFirefox()

    ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Warning, Timeout=60 ss
    If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
    $iMsgBoxAnswer = MsgBox(49,"Note","Firemin uses the SQLite Vacuum function to optimize the databases. Although this function is safe, it cannot be undone. If you’re not sure what the SQLite Vacuum function is, stop being daft and Google It!",60)
    Select
        Case $iMsgBoxAnswer = 1 ;OK
            TraySetToolTip("Optimizing or Breaking Firefox")
            TraySetState(4)

            If ProcessExists("firefox.exe") Then
                MsgBox(262192, "Firemin",     "For this function to work properly you will need to close Firefox. Yes, I mean you can close it know. " & _
                                            "Sorry about not being able to do it automatically, but the idiot who programmed Firemin is a lazy bugger and never got around to finishing the function.", 60)
            Else
                _VacuumDatabases()
            EndIf

        TraySetState(8)
        TraySetToolTip("Firefox " & FileGetVersion(@ScriptFullPath))

            Case $iMsgBoxAnswer = 2 ;Cancel
            Case $iMsgBoxAnswer = -1 ;Timeout

    EndSelect

EndFunc


Func _VacuumDatabases()

    ProgressOn("Breaking Firefox", "Initializing, I think", "Breaking Firefox")

    Local $ffProfile

    If FileExists($USB_FIREFOX) Then
        $ffProfile = @ScriptDir & $USB_FIREFOXPROFILE
    Else
        $ffProfile = $PATH_FIREFOXPROFILE
    EndIf

    $ffPSize = DirGetSize($ffProfile)

    Local $SearchHandle = FileFindFirstFile($ffProfile & "\*.*")
    If ($SearchHandle == -1) Then
        Return
    EndIf

    If (@error == 1) Then
;~         ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical, Timeout=60 ss
        If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
        $iMsgBoxAnswer = MsgBox(48, "Notice!", "Obviously we need something to scan. Good luck with finding support for this error.", 60)
        Return
    EndIf

    If Not _ScanProfileDir($SearchHandle, $ffProfile) Then

        ProgressOff()
        $ffPSize = 0
        $dbScnd = 0

        FileClose($SearchHandle)
        Return

    EndIf

EndFunc


Func _ScanProfileDir($SearchHandle, $ffProfile)

    Local $Return, $sQliteDb, $SecSearch, $dbScndPr

    While (True)

        $sQliteDb = FileFindNextFile($SearchHandle)
        If @error Then ExitLoop

        $Return &= $ffProfile & "\" & $sQliteDb

        If StringInStr(FileGetAttrib($ffProfile & "\" & $sQliteDb), "D") Then
            $SecSearch = FileFindFirstFile($ffProfile & "\" & $sQliteDb & "\*.*")
            $Return &= _ScanProfileDir($SecSearch, $ffProfile & "\" & $sQliteDb)
            FileClose($SecSearch)
        Else

            $dbScnd += FileGetSize($Return)
            $dbScndPr = Round(($dbScnd * 100) / $ffPSize)

            Local $aSplPath = StringSplit($Return, ".")
            If StringInStr($aSplPath[$aSplPath[0]], "sqlite") Then
                Sleep(50)
                If FileExists($BIN_SQLITE) Then ShellExecute(@ScriptDir & "\Bin\sqlite3.exe", Chr(34) & $Return & Chr(34) & " vacuum", "", "", @SW_HIDE)
                Local $aSplFile = StringSplit($Return, "\")
                ProgressSet($dbScndPr, "Breaking [ " & $aSplFile[$aSplFile[0]] & " ]", "Breaking Firefox (" & $dbScndPr & "%)")
            EndIf

        EndIf

        $Return = ""

    WEnd

    Return $Return

EndFunc


Func _OptionsDlg()

    Local Const $OptionsTitle = "Firemin " & _GetExecVersioning(@ScriptFullPath, 5) & " Options"

    If _Singleton($OptionsTitle, 1) Then

        Local $picGradBar, $lblSlDesc

        $fboGui = GUICreate($OptionsTitle, 350, 350, -1, -1)
        GUISetFont(8.5, 400, 0, "Verdana", $fboGui, 5)

        $picGradBar = GUICtrlCreatePic("", 25, 10, 300, 20)
        _ResourceSetImageToCtrl($picGradBar, "GRADBAR_IMAGE", $RT_RCDATA)
        $lblSldValue = GUICtrlCreateLabel(0, 127, 12, 100, 20, 0x1) ;~ $SS_CENTER = 0x1
        GUICtrlSetBkColor($lblSldValue, -2) ;~ $GUI_BKCOLOR_TRANSPARENT = -2

        $sldrMillisec = GUICtrlCreateSlider(25, 35, 300, 35)
        GUICtrlSetLimit($sldrMillisec, 1000, 100)
        GuiCtrlSetData($sldrMillisec, $INI_BOOST)

        _SetMilliseconds()
        GUICtrlSetOnEvent($sldrMillisec, "_SetMilliseconds")

        $lblSlDesc = GUICtrlCreateLabel("The faster you set the optimization the more processing power " & _
                                    "is needed, but the less memory Firefox uses and vice versa. " & _
                                    "Between 300 and 500 is a good setting.", 10, 85, 330, 55)
        GuiCtrlSetColor($lblSlDesc, 0x555555)

        $radLchFire = GUICtrlCreateRadio("Launch Firefox when Firemin starts", 20, 155, 330, 20)
        $radLchSafe = GUICtrlCreateRadio("Launch Firefox in Safemode when Firemin starts", 20, 173, 330, 20)
        $radLchNone = GUICtrlCreateRadio("Don't Launch Firefox when Firemin starts", 20, 191, 330, 20)
        $chkAutStart = GUICtrlCreateCheckbox(" Start Firemin when Windows starts", 20, 230, 330, 20)

        GUICtrlCreateGroup("Firefox location (firefox.exe)", 10, 275, 330, 60)
        $inpFireLoc = GUICtrlCreateInput($INI_FIREFOXPATH, 20, 300, 265, 20)
        GuiCtrlSetTip($inpFireLoc, $INI_FIREFOXPATH)
        $btnFireLoc = GUICtrlCreateButton("...", 290, 297, 30, 25)
        GUICtrlCreateGroup("", -99, -99, 1, 1)  ;close group

        GUICtrlSetOnEvent($btnFireLoc, "_BrowseFireLocation")

        If $INI_LAUNCH = 0 Then
            GUICtrlSetState($radLchNone, $GUI_CHECKED)
        ElseIf $INI_LAUNCH = 1 Then
            GUICtrlSetState($radLchFire, $GUI_CHECKED)
        ElseIf $INI_LAUNCH = 2 Then
            GUICtrlSetState($radLchSafe, $GUI_CHECKED)
        EndIf

        If FileExists(@StartupDir & "\Firemin.lnk") Then GUICtrlSetState($ChkAutStart, $GUI_CHECKED)

        GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseOptionsDlg", $fboGui)

        If FileExists($USB_FIREFOX) Then
            GUICtrlSetState($inpFireLoc, $GUI_DISABLE)
            GUICtrlSetState($btnFireLoc, $GUI_DISABLE)
        EndIf

    EndIf

    GUISetState(@SW_SHOW, $fboGui)

EndFunc


Func _SetMilliseconds()

    $INI_BOOST = GuiCtrlRead($sldrMillisec)

    GuiCtrlSetData($lblSldValue, $INI_BOOST)
    AdlibRegister("_OptimizeFireFox", $INI_BOOST)

EndFunc


Func _BrowseFireLocation()

    $INI_FIREFOXPATH = FileOpenDialog("Select Firefox Location", $INI_FIREFOXPATH, "Firefox (firefox.exe)", 1)
    GUICtrlSetData($inpFireLoc, $INI_FIREFOXPATH)

EndFunc


Func _CloseOptionsDlg()

    ;~ $GUI_CHECKED = 1
    If GUICtrlRead($radLchFire) = 1 Then
        $INI_LAUNCH = 1
    ElseIf GUICtrlRead($radLchSafe) = 1 Then
        $INI_LAUNCH = 2
    ElseIf GUICtrlRead($radLchNone) = 1 Then
        $INI_LAUNCH = 0
    EndIf

    If GUICtrlRead($chkAutStart) = 1 Then
        FileDelete(@StartupDir & "\Firemin.lnk")
        FileCreateShortcut(@ScriptFullPath, @StartupDir & "\Firemin.lnk", @StartupDir)
    Else
        FileDelete(@StartupDir & "\Firemin.lnk")
    EndIf

    IniWrite($INI_FILE, "Firemin", "Launch", $INI_LAUNCH)
    IniWrite($INI_FILE, "Firemin", "Boost", $INI_BOOST)
    If Not FileExists($USB_FIREFOX) Then
        $INI_FIREFOXPATH = GUICtrlRead($inpFireLoc)
        IniWrite($INI_FILE, "Firemin", "Path", $INI_FIREFOXPATH)
    EndIf

    GUISetState(@SW_HIDE, @GUI_WinHandle)

EndFunc


Func _ShowAboutDlg()
    _AboutDlg("Firemin", FileGetVersion(@ScriptFullPath))
EndFunc


Func _AboutDlg($aTitle = "", $aVer = "0.0.0.0")

    If _Singleton("About : " & $aTitle, 1) Then


        Local $aSpaceLabel, $aSpaceProg, $aBtnOK, $abMsg
        Local $aScriptDrive = StringSplit(@ScriptDir, "\")
        Local $DrvSpaceUsed = DriveSpaceTotal($aScriptDrive[1]) - DriveSpaceFree($aScriptDrive[1])
        Local $abTitle, $abVersion, $abCopyright, $abHome, $abGNU
        Local $abPayPal, $abRSS, $abFacebook, $abTwittter, $abPalfarm, $abLinkedIn, $abGoogle

        $aboutDlg = GUICreate("About : " & $aTitle, 400, 500, -1, -1, BitOR(0x00C00000, 0x80000000, 0x00080000)) ;~ $WS_CAPTION = 0x00C00000, $WS_POPUP = 0x80000000, $WS_SYSMENU = 0x00080000
        GUISetFont(8.5, 400, 0, "Verdana", $AboutDlg, 5)
        GUISetIcon(@ScriptFullPath, 207)

        GUISetOnEvent(-3, "_CloseAboutDlg", $AboutDlg) ; Global Const $GUI_EVENT_CLOSE = -3

        GUICtrlCreateIcon(@ScriptFullPath, 99, 10, 10, 64, 64)
        $abPayPal = GUICtrlCreateIcon(@ScriptFullPath, 208, 320, 0, 64, 64)
        GUICtrlSetTip($abPayPal, "Help us keep our software free.")
        GUICtrlSetCursor($abPayPal, 0)
        $abTitle = GUICtrlCreateLabel($aTitle, 88, 16, 220, 18)
        GuiCtrlSetFont($abTitle, 9, 800)
        $abVersion = GUICtrlCreateLabel("Version " & FileGetVersion(@ScriptFullPath), 88, 40, 220, 20)
        $abCopyright = GUICtrlCreateLabel("Copyright © 2014 Rizonesoft", 88, 55, 220, 20)
        GuiCtrlSetColor(-1, 0x555555)

        GUICtrlCreateLabel("Rizonesoft Home: ", 20, 90, 130, 15, $SS_RIGHT)
        $abHome = GUICtrlCreateLabel("www.rizonesoft.com", 155, 90, 280, 15)
        GuiCtrlSetFont($abHome, -1, -1, 4) ;Underlined
        GuiCtrlSetColor($abHome, 0x0000FF)
        GuiCtrlSetCursor($abHome, 0)
        $abGNU = GUICtrlCreateLabel("This program is free software: you can redistribute it and/or modify " & _
                                "it under the terms of the GNU General Public License as published by " & _
                                "the Free Software Foundation, either version 3 of the License, or " & _
                                "(at your option) any later version." & @CRLF & @CRLF & _
                                "This program is distributed in the hope that it will be useful, " & _
                                "but WITHOUT ANY WARRANTY; without even the implied warranty of " & _
                                "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " & _
                                "GNU General Public License for more details.", 20, 125, 350, 180)
        GuiCtrlSetColor($abGNU, 0x555555)
        GUICtrlCreateLabel(    "Contributors: Derick Payne (Rizonesoft)", 20, 280, 350, 100)

        $abFacebook = GUICtrlCreateIcon(@ScriptFullPath, 201, 20, 450, 32, 32)
        GUICtrlSetCursor($abFacebook, 0)
        $abTwittter = GUICtrlCreateIcon(@ScriptFullPath, 202, 55, 450, 32, 32)
        GUICtrlSetCursor($abTwittter, 0)
        $abLinkedIn = GUICtrlCreateIcon(@ScriptFullPath, 204, 90, 450, 32, 32)
        GUICtrlSetCursor($abLinkedIn, 0)
        $abGoogle = GUICtrlCreateIcon(@ScriptFullPath, 205, 125, 450, 32, 32)
        GUICtrlSetCursor($abGoogle, 0)

        $aSpaceLabel =     GUICtrlCreateLabel("(" & $aScriptDrive[1] & ") " & Round(DriveSpaceFree($aScriptDrive[1]) / 1024, 1) & " GB free of " & _
                        Round(DriveSpaceTotal($aScriptDrive[1]) / 1024, 1) & " GB", 15, 380, 330, 15)
        $aSpaceProg = GUICtrlCreateProgress(15, 400, 360, 15)
        GUICtrlSetData($aSpaceProg, ($DrvSpaceUsed / DriveSpaceTotal($aScriptDrive[1])) * 100)

        $aBtnOK = GUICtrlCreateButton("OK", 255, 450, 123, 33, 0x0001) ;~ $BS_DEFPUSHBUTTON = 0x0001

        GUICtrlSetOnEvent($aBtnOK, "_CloseAboutDlg")
        GUICtrlSetOnEvent($abHome, "_HomePageClicked")
        GUICtrlSetOnEvent($abFacebook, "_OpenFacebook")
        GUICtrlSetOnEvent($abTwittter, "_FollowOnTwitter")
        GUICtrlSetOnEvent($abLinkedIn, "_OpenLinkedIn")
        GUICtrlSetOnEvent($abGoogle, "_OpenGooglePlus")

        GUISetOnEvent(-3, "_CloseAboutDlg") ;~ $GUI_EVENT_CLOSE = -3

    EndIf

    GUISetState(@SW_SHOW, $aboutDlg)

EndFunc


Func _CloseAboutDlg()
    GUISetState(@SW_HIDE, @GUI_WinHandle)
EndFunc


Func _HomePageClicked()
    ShellExecute("http://www.rizonesoft.com")
EndFunc


Func _OpenFacebook()
    ShellExecute("https://www.facebook.com/rizonesoft")
EndFunc


Func _FollowOnTwitter()
    ShellExecute("https://twitter.com/rizonesoft")
EndFunc


Func _OpenLinkedIn()
    ShellExecute("http://www.linkedin.com/in/rizonesoft")
EndFunc

Func _OpenGooglePlus()
    ShellExecute("https://plus.google.com/+Rizonesoftsa/posts")
EndFunc

Func _DonateSomething()
    ShellExecute("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=7UGGCSDUZJPFE")
EndFunc

 

 

 

Edited by Rizonetech

Rizonesoft Open Source Home Scripts: Complete Internet Repair | Development: Rizonesoft SDK

Share this post


Link to post
Share on other sites
JohnOne

I have an opinion, I can't be bothered navigating to external unknown websites that may or may not be rife with malware viruses and drive by downloads.

Post your script here, unless you are just after hits on your website..

And what is the "clean memory API call" ? Is it anything like the ReduceMemory UDF which uses EmptyWorkingSet API and works on any process you pass to it?

EDIT:

For anyone else not like navigating away to look at code.

FireMin.au3

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Resources\Firemin.ico
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Description=Firemin
#AutoIt3Wrapper_Res_Fileversion=2.0.8.2087
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#AutoIt3Wrapper_Res_LegalCopyright=© 2014 Rizonesoft
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Res_Icon_Add=Resources\Facebook.ico
#AutoIt3Wrapper_Res_Icon_Add=Resources\Twitter.ico
#AutoIt3Wrapper_Res_Icon_Add=Resources\Palfarm.ico
#AutoIt3Wrapper_Res_Icon_Add=Resources\LinkedIn.ico
#AutoIt3Wrapper_Res_Icon_Add=Resources\Google.ico
#AutoIt3Wrapper_Res_Icon_Add=Resources\RSS.ico
#AutoIt3Wrapper_Res_Icon_Add=Resources\Info.ico
#AutoIt3Wrapper_Res_Icon_Add=Resources\PayPal.ico
#AutoIt3Wrapper_Res_File_Add=resources\gradbar.jpg, rt_rcdata, GRADBAR_IMAGE
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****


Opt("GUICloseOnESC", 0)             ;1=ESC  closes, 0=ESC won't close
Opt("GUIOnEventMode", 1)            ;0=disabled, 1=OnEvent mode enabled
Opt("TrayOnEventMode", 1)
Opt("MustDeclareVars", 1)           ;0=no, 1=require pre-declare
Opt("TrayAutoPause", 0)
Opt("TrayMenuMode", 3)


;~ #include <WindowsConstants.au3>
#include <StaticConstants.au3>
;~ #include <ButtonConstants.au3>
#include <GuiConstantsEx.au3>
#include <WinAPIProc.au3>
;~ #include <GuiEdit.au3>
#include <Misc.au3>

#include <UDF\Functions.au3>
#include <UDF\Resources.au3>
;#include <UDF\MemBoost.au3>


_Singleton(@ScriptName, 0)


Global $PATH_FIREFOX = ""
If @OSArch = "X64" Then
    $PATH_FIREFOX = @HomeDrive & "Program Files (x86)\Mozilla Firefox\firefox.exe"
Else
    $PATH_FIREFOX = @ProgramFilesDir & "\Mozilla Firefox\firefox.exe"
EndIf


Global $PATH_FIREFOXPROFILE = @AppDataDir & "\Mozilla\Firefox\Profiles"
Global $BIN_SQLITE = @ScriptDir & "\Bin\sqlite3.exe"
Global $USB_FIREFOX = @ScriptDir & "\FirefoxPortable.exe"
Global $USB_FIREFOXPROFILE = "\Data\profile"
Global $INI_FILE =  @ScriptDir & "\Firemin.ini"
Global $INI_BOOST = IniRead($INI_FILE, "Firemin", "Boost", 250)
Global $INI_LAUNCH = IniRead($INI_FILE, "Firemin", "Launch", 0)
Global $INI_FIREFOXPATH = IniRead($INI_FILE, "Firemin", "Path", $PATH_FIREFOX)

Global $fboGui, $tmnuAbout, $tmnuOptions, $tmnuOFire, $tmnuLaFire, $tmnuLaFSafe, $tmnuClose, $sldrMillisec
Global $msCount = 0, $lblSldValue, $radLchFire, $radLchSafe, $radLchNone, $chkAutStart
Global $inpFireLoc, $btnFireLoc, $ffPSize = 0, $dbScnd = 0
Global $aboutDlg


If Not FileExists($BIN_SQLITE) Then
    MsgBox(262160, "Firemin",   "Unfortunately the Optimize Firefox option will not be available, because the " & _
                                "‘\Bin\ sqlite3.exe’ could not be found. Why you assumed it was a good idea to delete it, we will never know.", 60)
EndIf


If $INI_LAUNCH = 1 Then _LaunchFirefox()
If $INI_LAUNCH = 2 Then _LaunchFirefoxSafeMode()


Func _LaunchFirefox()
    If Not ProcessExists("firefox.exe") Then
        ShellExecute($PATH_FIREFOX)
    EndIf
EndFunc


Func _LaunchFirefoxSafeMode()
    If Not ProcessExists("firefox.exe") Then
        ShellExecute($PATH_FIREFOX, "-safe-mode")
    EndIf
EndFunc


coreInterface()


Func coreInterface()

    ;~ Build Firemin Tray Menu
    $tmnuAbout = TrayCreateItem("About Firemin...")
    TrayCreateItem("")
    $tmnuOptions = TrayCreateItem("Options...")
    TrayCreateItem("")
    $tmnuOFire = TrayCreateItem("Optimize Firefox")
    If Not FileExists($BIN_SQLITE) Then TrayItemSetState($tmnuOFire, 128) ;~ $GUI_DISABLE = 128
    TrayCreateItem("")
    $tmnuLaFire = TrayCreateItem("Launch Firefox")
    $tmnuLaFSafe = TrayCreateItem("Launch Firefox in Safemode")
    TrayCreateItem("")
    $tmnuClose = TrayCreateItem("Close")

    TrayItemSetOnEvent($tmnuAbout, "_ShowAboutDlg")
    TrayItemSetOnEvent($tmnuOptions, "_OptionsDlg")
    TrayItemSetOnEvent($tmnuOFire, "_VacuumFirefox")
    TrayItemSetOnEvent($tmnuLaFire, "_LaunchFirefox")
    TrayItemSetOnEvent($tmnuLaFSafe, "_LaunchFirefoxSafeMode")
    TrayItemSetOnEvent($tmnuClose, "_CloseFiremin")

    TraySetState()
    TraySetClick(8)

    TraySetToolTip("Firemin " & FileGetVersion(@ScriptFullPath))

    AdlibRegister("_OptimizeFireFox", $INI_BOOST)

    While 1
        Sleep(100)
        _WinAPI_EmptyWorkingSet()
    WEnd

EndFunc


Func _CloseFiremin()
    TraySetState(2)
    Exit
EndFunc


Func _OptimizeFireFox()

    Local $aProcsList, $aPIniList

    $aPIniList = StringSplit("firefox.exe|plugin-container.exe", "|")

    $aProcsList = ProcessList()
    For $i = 1 To $aProcsList[0][0]
        For $x = 1 To $aPIniList[0]
            If $aProcsList[$i][0] = $aPIniList[$x] Then
                _WinAPI_EmptyWorkingSet($aProcsList[$i][1])
            EndIf
        Next
    Next

EndFunc


Func _VacuumFirefox()

    ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Warning, Timeout=60 ss
    If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
    $iMsgBoxAnswer = MsgBox(49,"Note","Firemin uses the SQLite Vacuum function to optimize the databases. Although this function is safe, it cannot be undone. If you’re not sure what the SQLite Vacuum function is, stop being daft and Google It!",60)
    Select
        Case $iMsgBoxAnswer = 1 ;OK
            TraySetToolTip("Optimizing or Breaking Firefox")
            TraySetState(4)

            If ProcessExists("firefox.exe") Then
                MsgBox(262192, "Firemin",   "For this function to work properly you will need to close Firefox. Yes, I mean you can close it know. " & _
                                            "Sorry about not being able to do it automatically, but the idiot who programmed Firemin is a lazy bugger and never got around to finishing the function.", 60)
            Else
                _VacuumDatabases()
            EndIf

        TraySetState(8)
        TraySetToolTip("Firefox " & FileGetVersion(@ScriptFullPath))

            Case $iMsgBoxAnswer = 2 ;Cancel
            Case $iMsgBoxAnswer = -1 ;Timeout

    EndSelect

EndFunc


Func _VacuumDatabases()

    ProgressOn("Breaking Firefox", "Initializing, I think", "Breaking Firefox")

    Local $ffProfile

    If FileExists($USB_FIREFOX) Then
        $ffProfile = @ScriptDir & $USB_FIREFOXPROFILE
    Else
        $ffProfile = $PATH_FIREFOXPROFILE
    EndIf

    $ffPSize = DirGetSize($ffProfile)

    Local $SearchHandle = FileFindFirstFile($ffProfile & "\*.*")
    If ($SearchHandle == -1) Then
        Return
    EndIf

    If (@error == 1) Then
;~      ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical, Timeout=60 ss
        If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
        $iMsgBoxAnswer = MsgBox(48, "Notice!", "Obviously we need something to scan. Good luck with finding support for this error.", 60)
        Return
    EndIf

    If Not _ScanProfileDir($SearchHandle, $ffProfile) Then

        ProgressOff()
        $ffPSize = 0
        $dbScnd = 0

        FileClose($SearchHandle)
        Return

    EndIf

EndFunc


Func _ScanProfileDir($SearchHandle, $ffProfile)

    Local $Return, $sQliteDb, $SecSearch, $dbScndPr

    While (True)

        $sQliteDb = FileFindNextFile($SearchHandle)
        If @error Then ExitLoop

        $Return &= $ffProfile & "\" & $sQliteDb

        If StringInStr(FileGetAttrib($ffProfile & "\" & $sQliteDb), "D") Then
            $SecSearch = FileFindFirstFile($ffProfile & "\" & $sQliteDb & "\*.*")
            $Return &= _ScanProfileDir($SecSearch, $ffProfile & "\" & $sQliteDb)
            FileClose($SecSearch)
        Else

            $dbScnd += FileGetSize($Return)
            $dbScndPr = Round(($dbScnd * 100) / $ffPSize)

            Local $aSplPath = StringSplit($Return, ".")
            If StringInStr($aSplPath[$aSplPath[0]], "sqlite") Then
                Sleep(50)
                If FileExists($BIN_SQLITE) Then ShellExecute(@ScriptDir & "\Bin\sqlite3.exe", Chr(34) & $Return & Chr(34) & " vacuum", "", "", @SW_HIDE)
                Local $aSplFile = StringSplit($Return, "\")
                ProgressSet($dbScndPr, "Breaking [ " & $aSplFile[$aSplFile[0]] & " ]", "Breaking Firefox (" & $dbScndPr & "%)")
            EndIf

        EndIf

        $Return = ""

    WEnd

    Return $Return

EndFunc


Func _OptionsDlg()

    Local Const $OptionsTitle = "Firemin " & _GetExecVersioning(@ScriptFullPath, 5) & " Options"

    If _Singleton($OptionsTitle, 1) Then

        Local $picGradBar, $lblSlDesc

        $fboGui = GUICreate($OptionsTitle, 350, 350, -1, -1)
        GUISetFont(8.5, 400, 0, "Verdana", $fboGui, 5)

        $picGradBar = GUICtrlCreatePic("", 25, 10, 300, 20)
        _ResourceSetImageToCtrl($picGradBar, "GRADBAR_IMAGE", $RT_RCDATA)
        $lblSldValue = GUICtrlCreateLabel(0, 127, 12, 100, 20, 0x1) ;~ $SS_CENTER = 0x1
        GUICtrlSetBkColor($lblSldValue, -2) ;~ $GUI_BKCOLOR_TRANSPARENT = -2

        $sldrMillisec = GUICtrlCreateSlider(25, 35, 300, 35)
        GUICtrlSetLimit($sldrMillisec, 1000, 100)
        GuiCtrlSetData($sldrMillisec, $INI_BOOST)

        _SetMilliseconds()
        GUICtrlSetOnEvent($sldrMillisec, "_SetMilliseconds")

        $lblSlDesc = GUICtrlCreateLabel("The faster you set the optimization the more processing power " & _
                                    "is needed, but the less memory Firefox uses and vice versa. " & _
                                    "Between 300 and 500 is a good setting.", 10, 85, 330, 55)
        GuiCtrlSetColor($lblSlDesc, 0x555555)

        $radLchFire = GUICtrlCreateRadio("Launch Firefox when Firemin starts", 20, 155, 330, 20)
        $radLchSafe = GUICtrlCreateRadio("Launch Firefox in Safemode when Firemin starts", 20, 173, 330, 20)
        $radLchNone = GUICtrlCreateRadio("Don't Launch Firefox when Firemin starts", 20, 191, 330, 20)
        $chkAutStart = GUICtrlCreateCheckbox(" Start Firemin when Windows starts", 20, 230, 330, 20)

        GUICtrlCreateGroup("Firefox location (firefox.exe)", 10, 275, 330, 60)
        $inpFireLoc = GUICtrlCreateInput($INI_FIREFOXPATH, 20, 300, 265, 20)
        GuiCtrlSetTip($inpFireLoc, $INI_FIREFOXPATH)
        $btnFireLoc = GUICtrlCreateButton("...", 290, 297, 30, 25)
        GUICtrlCreateGroup("", -99, -99, 1, 1)  ;close group

        GUICtrlSetOnEvent($btnFireLoc, "_BrowseFireLocation")

        If $INI_LAUNCH = 0 Then
            GUICtrlSetState($radLchNone, $GUI_CHECKED)
        ElseIf $INI_LAUNCH = 1 Then
            GUICtrlSetState($radLchFire, $GUI_CHECKED)
        ElseIf $INI_LAUNCH = 2 Then
            GUICtrlSetState($radLchSafe, $GUI_CHECKED)
        EndIf

        If FileExists(@StartupDir & "\Firemin.lnk") Then GUICtrlSetState($ChkAutStart, $GUI_CHECKED)

        GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseOptionsDlg", $fboGui)

        If FileExists($USB_FIREFOX) Then
            GUICtrlSetState($inpFireLoc, $GUI_DISABLE)
            GUICtrlSetState($btnFireLoc, $GUI_DISABLE)
        EndIf

    EndIf

    GUISetState(@SW_SHOW, $fboGui)

EndFunc


Func _SetMilliseconds()

    $INI_BOOST = GuiCtrlRead($sldrMillisec)

    GuiCtrlSetData($lblSldValue, $INI_BOOST)
    AdlibRegister("_OptimizeFireFox", $INI_BOOST)

EndFunc


Func _BrowseFireLocation()

    $INI_FIREFOXPATH = FileOpenDialog("Select Firefox Location", $INI_FIREFOXPATH, "Firefox (firefox.exe)", 1)
    GUICtrlSetData($inpFireLoc, $INI_FIREFOXPATH)

EndFunc


Func _CloseOptionsDlg()

    ;~ $GUI_CHECKED = 1
    If GUICtrlRead($radLchFire) = 1 Then
        $INI_LAUNCH = 1
    ElseIf GUICtrlRead($radLchSafe) = 1 Then
        $INI_LAUNCH = 2
    ElseIf GUICtrlRead($radLchNone) = 1 Then
        $INI_LAUNCH = 0
    EndIf

    If GUICtrlRead($chkAutStart) = 1 Then
        FileDelete(@StartupDir & "\Firemin.lnk")
        FileCreateShortcut(@ScriptFullPath, @StartupDir & "\Firemin.lnk", @StartupDir)
    Else
        FileDelete(@StartupDir & "\Firemin.lnk")
    EndIf

    IniWrite($INI_FILE, "Firemin", "Launch", $INI_LAUNCH)
    IniWrite($INI_FILE, "Firemin", "Boost", $INI_BOOST)
    If Not FileExists($USB_FIREFOX) Then
        $INI_FIREFOXPATH = GUICtrlRead($inpFireLoc)
        IniWrite($INI_FILE, "Firemin", "Path", $INI_FIREFOXPATH)
    EndIf

    GUISetState(@SW_HIDE, @GUI_WinHandle)

EndFunc


Func _ShowAboutDlg()
    _AboutDlg("Firemin", FileGetVersion(@ScriptFullPath))
EndFunc


Func _AboutDlg($aTitle = "", $aVer = "0.0.0.0")

    If _Singleton("About : " & $aTitle, 1) Then


        Local $aSpaceLabel, $aSpaceProg, $aBtnOK, $abMsg
        Local $aScriptDrive = StringSplit(@ScriptDir, "\")
        Local $DrvSpaceUsed = DriveSpaceTotal($aScriptDrive[1]) - DriveSpaceFree($aScriptDrive[1])
        Local $abTitle, $abVersion, $abCopyright, $abHome, $abGNU
        Local $abPayPal, $abRSS, $abFacebook, $abTwittter, $abPalfarm, $abLinkedIn, $abGoogle

        $aboutDlg = GUICreate("About : " & $aTitle, 400, 500, -1, -1, BitOR(0x00C00000, 0x80000000, 0x00080000)) ;~ $WS_CAPTION = 0x00C00000, $WS_POPUP = 0x80000000, $WS_SYSMENU = 0x00080000
        GUISetFont(8.5, 400, 0, "Verdana", $AboutDlg, 5)
        GUISetIcon(@ScriptFullPath, 207)

        GUISetOnEvent(-3, "_CloseAboutDlg", $AboutDlg) ; Global Const $GUI_EVENT_CLOSE = -3

        GUICtrlCreateIcon(@ScriptFullPath, 99, 10, 10, 64, 64)
        $abPayPal = GUICtrlCreateIcon(@ScriptFullPath, 208, 320, 0, 64, 64)
        GUICtrlSetTip($abPayPal, "Help us keep our software free.")
        GUICtrlSetCursor($abPayPal, 0)
        $abTitle = GUICtrlCreateLabel($aTitle, 88, 16, 220, 18)
        GuiCtrlSetFont($abTitle, 9, 800)
        $abVersion = GUICtrlCreateLabel("Version " & FileGetVersion(@ScriptFullPath), 88, 40, 220, 20)
        $abCopyright = GUICtrlCreateLabel("Copyright © 2014 Rizonesoft", 88, 55, 220, 20)
        GuiCtrlSetColor(-1, 0x555555)

        GUICtrlCreateLabel("Rizonesoft Home: ", 20, 90, 130, 15, $SS_RIGHT)
        $abHome = GUICtrlCreateLabel("www.rizonesoft.com", 155, 90, 280, 15)
        GuiCtrlSetFont($abHome, -1, -1, 4) ;Underlined
        GuiCtrlSetColor($abHome, 0x0000FF)
        GuiCtrlSetCursor($abHome, 0)
        $abGNU = GUICtrlCreateLabel("This program is free software: you can redistribute it and/or modify " & _
                                "it under the terms of the GNU General Public License as published by " & _
                                "the Free Software Foundation, either version 3 of the License, or " & _
                                "(at your option) any later version." & @CRLF & @CRLF & _
                                "This program is distributed in the hope that it will be useful, " & _
                                "but WITHOUT ANY WARRANTY; without even the implied warranty of " & _
                                "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " & _
                                "GNU General Public License for more details.", 20, 125, 350, 180)
        GuiCtrlSetColor($abGNU, 0x555555)
        GUICtrlCreateLabel( "Contributors: Derick Payne (Rizonesoft)", 20, 280, 350, 100)

        $abFacebook = GUICtrlCreateIcon(@ScriptFullPath, 201, 20, 450, 32, 32)
        GUICtrlSetCursor($abFacebook, 0)
        $abTwittter = GUICtrlCreateIcon(@ScriptFullPath, 202, 55, 450, 32, 32)
        GUICtrlSetCursor($abTwittter, 0)
        $abLinkedIn = GUICtrlCreateIcon(@ScriptFullPath, 204, 90, 450, 32, 32)
        GUICtrlSetCursor($abLinkedIn, 0)
        $abGoogle = GUICtrlCreateIcon(@ScriptFullPath, 205, 125, 450, 32, 32)
        GUICtrlSetCursor($abGoogle, 0)

        $aSpaceLabel =  GUICtrlCreateLabel("(" & $aScriptDrive[1] & ") " & Round(DriveSpaceFree($aScriptDrive[1]) / 1024, 1) & " GB free of " & _
                        Round(DriveSpaceTotal($aScriptDrive[1]) / 1024, 1) & " GB", 15, 380, 330, 15)
        $aSpaceProg = GUICtrlCreateProgress(15, 400, 360, 15)
        GUICtrlSetData($aSpaceProg, ($DrvSpaceUsed / DriveSpaceTotal($aScriptDrive[1])) * 100)

        $aBtnOK = GUICtrlCreateButton("OK", 255, 450, 123, 33, 0x0001) ;~ $BS_DEFPUSHBUTTON = 0x0001

        GUICtrlSetOnEvent($aBtnOK, "_CloseAboutDlg")
        GUICtrlSetOnEvent($abHome, "_HomePageClicked")
        GUICtrlSetOnEvent($abFacebook, "_OpenFacebook")
        GUICtrlSetOnEvent($abTwittter, "_FollowOnTwitter")
        GUICtrlSetOnEvent($abLinkedIn, "_OpenLinkedIn")
        GUICtrlSetOnEvent($abGoogle, "_OpenGooglePlus")

        GUISetOnEvent(-3, "_CloseAboutDlg") ;~ $GUI_EVENT_CLOSE = -3

    EndIf

    GUISetState(@SW_SHOW, $aboutDlg)

EndFunc


Func _CloseAboutDlg()
    GUISetState(@SW_HIDE, @GUI_WinHandle)
EndFunc


Func _HomePageClicked()
    ShellExecute("http://www.rizonesoft.com")
EndFunc


Func _OpenFacebook()
    ShellExecute("https://www.facebook.com/rizonesoft")
EndFunc


Func _FollowOnTwitter()
    ShellExecute("https://twitter.com/rizonesoft")
EndFunc


Func _OpenLinkedIn()
    ShellExecute("http://www.linkedin.com/in/rizonesoft")
EndFunc

Func _OpenGooglePlus()
    ShellExecute("https://plus.google.com/+Rizonesoftsa/posts")
EndFunc

Func _DonateSomething()
    ShellExecute("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=7UGGCSDUZJPFE")
EndFunc 

Functions.au3

Func _GetExecVersioning($sExecPath, $iFlag = 6)

    If FileExists($sExecPath) Then
        Local $verReturn = FileGetVersion($sExecPath)
        Local $splReturn = StringSplit($verReturn, ".")

        If $splReturn[0] >= 4 Then
            If $iFlag = 1 Then
                Return $splReturn[1]
            ElseIf $iFlag = 2 Then
                Return $splReturn[2]
            ElseIf $iFlag = 3 Then
                Return $splReturn[3]
            ElseIf $iFlag = 4 Then
                Return $splReturn[4]
            ElseIf $iFlag = 5 Then
                Return $splReturn[1] & " : Build " & $splReturn[4]
            ElseIf $iFlag = 6 Then
                Return $verReturn
            EndIf
        EndIf
    Else
        Return "0000001" ;ERROR CODE: DOORS VERSIONING: PATH TO EXECUTABLE NOT FOUND
    EndIf
EndFunc ;==>_GetDoorsVersion

Resources.au3

#include-once
#include <Constants.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <Memory.au3>

_GDIPlus_Startup()

Global Const $RT_CURSOR = 1
Global Const $RT_BITMAP = 2
Global Const $RT_ICON = 3
Global Const $RT_MENU = 4
Global Const $RT_DIALOG = 5
Global Const $RT_STRING = 6
Global Const $RT_FONTDIR = 7
Global Const $RT_FONT = 8
Global Const $RT_ACCELERATOR = 9
Global Const $RT_RCDATA = 10
Global Const $RT_MESSAGETABLE = 11
Global Const $RT_GROUP_CURSOR = 12
Global Const $RT_GROUP_ICON = 14
Global Const $RT_VERSION = 16
Global Const $RT_DLGINCLUDE = 17
Global Const $RT_PLUGPLAY = 19
Global Const $RT_VXD = 20
Global Const $RT_ANICURSOR = 21
Global Const $RT_ANIICON = 22
Global Const $RT_HTML = 23
Global Const $RT_MANIFEST = 24

Global Const $SND_RESOURCE = 0x00040004
Global Const $SND_SYNC = 0x0
Global Const $SND_ASYNC = 0x1
Global Const $SND_MEMORY = 0x4
Global Const $SND_LOOP = 0x8
Global Const $SND_NOSTOP = 0x10
Global Const $SND_NOWAIT = 0x2000
Global Const $SND_PURGE = 0x40

Func _ResourceGet($ResName, $ResType = 10, $ResLang = 0, $DLL = -1) ; $RT_RCDATA = 10
    Local Const $IMAGE_BITMAP = 0
    Local $hInstance, $hBitmap, $InfoBlock, $GlobalMemoryBlock, $MemoryPointer, $ResSize

    If $DLL = -1 Then
      $hInstance = _WinAPI_GetModuleHandle("")
    Else
      $hInstance = _WinAPI_LoadLibraryEx($DLL, $LOAD_LIBRARY_AS_DATAFILE)
    EndIf
    If $hInstance = 0 Then Return SetError(1, 0, 0)

    If $ResType = $RT_BITMAP Then
        $hBitmap = _WinAPI_LoadImage($hInstance, $ResName, $IMAGE_BITMAP, 0, 0, 0)
        If @error Then Return SetError(2, 0, 0)
        Return $hBitmap ; returns handle to Bitmap
    EndIf

    If $ResLang <> 0 Then
        $InfoBlock = DllCall("kernel32.dll", "ptr", "FindResourceExW", "ptr", $hInstance, "long", $ResType, "wstr", $ResName, "short", $ResLang)
    Else
        $InfoBlock = DllCall("kernel32.dll", "ptr", "FindResourceW", "ptr", $hInstance, "wstr", $ResName, "long", $ResType)
    EndIf

    If @error Then Return SetError(3, 0, 0)
    $InfoBlock = $InfoBlock[0]
    If $InfoBlock = 0 Then Return SetError(4, 0, 0)

    $ResSize = DllCall("kernel32.dll", "dword", "SizeofResource", "ptr", $hInstance, "ptr", $InfoBlock)
    If @error Then Return SetError(5, 0, 0)
    $ResSize = $ResSize[0]
    If $ResSize = 0 Then Return SetError(6, 0, 0)

    $GlobalMemoryBlock = DllCall("kernel32.dll", "ptr", "LoadResource", "ptr", $hInstance, "ptr", $InfoBlock)
    If @error Then Return SetError(7, 0, 0)
    $GlobalMemoryBlock = $GlobalMemoryBlock[0]
    If $GlobalMemoryBlock = 0 Then Return SetError(8, 0, 0)

    $MemoryPointer = DllCall("kernel32.dll", "ptr", "LockResource", "ptr", $GlobalMemoryBlock)
    If @error Then Return SetError(9, 0, 0)
    $MemoryPointer = $MemoryPointer[0]
    If $MemoryPointer = 0 Then Return SetError(10, 0, 0)

    If $DLL <> -1 Then _WinAPI_FreeLibrary($hInstance)
    If @error Then Return SetError(11, 0, 0)

    SetExtended($ResSize)
    Return $MemoryPointer
EndFunc

; for ANSI strings
Func _ResourceGetAsString($ResName, $ResType = 10, $ResLang = 0, $DLL = -1) ; $RT_RCDATA = 10
    Local $ResPointer, $ResSize, $struct

    $ResPointer = _ResourceGet($ResName, $ResType, $ResLang, $DLL)
    If @error Then
        SetError(1, 0, 0)
        Return ''
    EndIf
    $ResSize = @extended
    $struct = DllStructCreate("char[" & $ResSize & "]", $ResPointer)
    Return DllStructGetData($struct, 1) ; returns string
EndFunc

; for Unicode strings (Widechar)
Func _ResourceGetAsStringW($ResName, $ResType = 10, $ResLang = 0, $DLL = -1) ; $RT_RCDATA = 10
    Local $ResPointer, $ResSize, $struct

    $ResPointer = _ResourceGet($ResName, $ResType, $ResLang, $DLL)
    If @error Then
        SetError(1, 0, 0)
        Return ''
    EndIf
    $ResSize = @extended
    $struct = DllStructCreate("wchar[" & $ResSize & "]", $ResPointer)
    Return DllStructGetData($struct, 1) ; returns string
EndFunc

; _ResourceGetAsBytes() doesn't work for RT_BITMAP type
; because _ResourceGet() returns hBitmap instead of memory pointer in this case
Func _ResourceGetAsBytes($ResName, $ResType = 10, $ResLang = 0, $DLL = -1) ; $RT_RCDATA = 10
    Local $ResPointer, $ResSize

    $ResPointer = _ResourceGet($ResName, $ResType, $ResLang, $DLL)
    If @error Then Return SetError(1, 0, 0)
    $ResSize = @extended
    Return DllStructCreate("byte[" & $ResSize & "]", $ResPointer) ; returns struct with bytes
EndFunc

; returned hImage can be used in many GDI+ functions:
; $width =  _GDIPlus_ImageGetWidth ($hImage)
; $height = _GDIPlus_ImageGetHeight($hImage)
Func _ResourceGetAsImage($ResName, $ResType = 10, $DLL = -1) ; $RT_RCDATA = 10
    Local $ResData, $nSize, $hData, $pData, $pStream, $pBitmap, $hBitmap, $hImage

    $ResData = _ResourceGet($ResName, $ResType, 0, $DLL)
    If @error Then Return SetError(1, 0, 0)
    $nSize = @extended

    If $ResType = $RT_BITMAP Then
        ; $ResData is hBitmap type
        $hImage = _GDIPlus_BitmapCreateFromHBITMAP($ResData)
    Else
        ; $ResData is memory pointer
        ; thanks ProgAndy
        $hData = _MemGlobalAlloc($nSize,2)
        $pData = _MemGlobalLock($hData)
        _MemMoveMemory($ResData,$pData,$nSize)
        _MemGlobalUnlock($hData)
        $pStream = DllCall( "ole32.dll","int","CreateStreamOnHGlobal", "ptr",$hData, "int",1, "ptr*",0)
        $pStream = $pStream[3]
        $hImage = DllCall($ghGDIPDll,"int","GdipCreateBitmapFromStream", "ptr",$pStream, "ptr*",0)
        $hImage = $hImage[2]
        _WinAPI_DeleteObject($pStream)
        ; next line must be commented otherwise animated GIFs will not work
;~      _MemGlobalFree($hData)
    EndIf

    Return $hImage ; hImage type
EndFunc

Func _ResourceGetAsBitmap($ResName, $ResType = 10, $DLL = -1) ; $RT_RCDATA = 10
    Local $hImage = _ResourceGetAsImage($ResName, $ResType, $DLL)
    If @error Then Return SetError(1, 0, 0)
    Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    Return $hBitmap ; hBitmap type
EndFunc

Func _ResourceSaveToFile($FileName, $ResName, $ResType = 10, $ResLang = 0, $CreatePath = 0, $DLL = -1) ; $RT_RCDATA = 10
    Local $ResStruct, $ResSize, $FileHandle, $hImage

    If $CreatePath Then $CreatePath = 8 ; mode 8 = Create directory structure if it doesn't exist in FileOpen()

    If $ResType = $RT_BITMAP Then
        ; workaround: for RT_BITMAP _ResourceGetAsBytes() doesn't work so use _ResourceGetAsImage()
        $hImage = _ResourceGetAsImage($ResName, $ResType)
        If @error Then Return SetError(10, 0, 0)

        ; create filepath if doesn't exist
        $FileHandle = FileOpen($FileName, 2+16+$CreatePath)
        If @error Then Return SetError(11, 0, 0)
        FileClose($FileHandle)
        If @error Then Return SetError(12, 0, 0)

        _GDIPlus_ImageSaveToFile($hImage, $FileName)
        _GDIPlus_ImageDispose($hImage)

        $ResSize = FileGetSize($FileName)
    Else
        ; standard way
        $ResStruct = _ResourceGetAsBytes($ResName, $ResType, $ResLang, $DLL)
        If @error Then Return SetError(1, 0, 0)
        $ResSize = DllStructGetSize($ResStruct)

        $FileHandle = FileOpen($FileName, 2+16+$CreatePath)
        If @error Then Return SetError(2, 0, 0)
        FileWrite($FileHandle, DllStructGetData($ResStruct, 1))
        If @error Then Return SetError(3, 0, 0)
        FileClose($FileHandle)
        If @error Then Return SetError(4, 0, 0)
    EndIf

    Return $ResSize
EndFunc

Func _ResourceSetImageToCtrl($CtrlId, $ResName, $ResType = 10, $DLL = -1) ; $RT_RCDATA = 10
    Local $ResData, $nSize, $hData, $pData, $pStream, $pBitmap, $hBitmap

    $ResData = _ResourceGet($ResName, $ResType, 0, $DLL)
    If @error Then Return SetError(1, 0, 0)
    $nSize = @extended

    If $ResType = $RT_BITMAP Then
        _SetBitmapToCtrl($CtrlId, $ResData)
        If @error Then Return SetError(2, 0, 0)
    Else
        ; thanks ProgAndy
        ; for other types than BITMAP use GDI+ for converting to bitmap first
        $hData = _MemGlobalAlloc($nSize,2)
        $pData = _MemGlobalLock($hData)
        _MemMoveMemory($ResData,$pData,$nSize)
        _MemGlobalUnlock($hData)
        $pStream = DllCall( "ole32.dll","int","CreateStreamOnHGlobal", "ptr",$hData, "int",1, "ptr*",0)
        $pStream = $pStream[3]
        $pBitmap = DllCall($ghGDIPDll,"int","GdipCreateBitmapFromStream", "ptr",$pStream, "ptr*",0)
        $pBitmap = $pBitmap[2]
        $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($pBitmap)
        _SetBitmapToCtrl($CtrlId, $hBitmap)
        If @error Then SetError(3, 0, 0)
        _GDIPlus_BitmapDispose($pBitmap)
        _WinAPI_DeleteObject($pStream)
        _MemGlobalFree($hData)
    EndIf

    Return 1
EndFunc

; internal helper function
; thanks for improvements Melba
Func _SetBitmapToCtrl($CtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $STM_GETIMAGE = 0x0173
    Local Const $BM_SETIMAGE = 0xF7
    Local Const $BM_GETIMAGE = 0xF6
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0x0E
    Local Const $BS_BITMAP = 0x0080
    Local Const $GWL_STYLE = -16

    Local $hWnd, $hPrev, $Style, $iCtrl_SETIMAGE, $iCtrl_GETIMAGE, $iCtrl_BITMAP

    $hWnd = GUICtrlGetHandle($CtrlId)
    If $hWnd = 0 Then Return SetError(1, 0, 0)

    $CtrlId = _WinAPI_GetDlgCtrlID($hWnd) ; support for $CtrlId = -1
    If @error Then Return SetError(2, 0, 0)

    ; determine control class and adjust constants accordingly
    Switch _WinAPI_GetClassName($CtrlId)
        Case "Button" ; button,checkbox,radiobutton,groupbox
            $iCtrl_SETIMAGE = $BM_SETIMAGE
            $iCtrl_GETIMAGE = $BM_GETIMAGE
            $iCtrl_BITMAP = $BS_BITMAP
        Case "Static" ; picture,icon,label
            $iCtrl_SETIMAGE = $STM_SETIMAGE
            $iCtrl_GETIMAGE = $STM_GETIMAGE
            $iCtrl_BITMAP = $SS_BITMAP
        Case Else
            Return SetError(3, 0, 0)
    EndSwitch

    ; set SS_BITMAP/BS_BITMAP style to the control
    $Style = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
    If @error Then Return SetError(4, 0, 0)
    _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, BitOR($Style, $iCtrl_BITMAP))
    If @error Then Return SetError(5, 0, 0)

    ; set image to the control
    $hPrev  = _SendMessage($hWnd, $iCtrl_SETIMAGE, $IMAGE_BITMAP, $hBitmap)
    If @error Then Return SetError(6, 0, 0)
    If $hPrev Then _WinAPI_DeleteObject($hPrev)

    Return 1
EndFunc

; thanks Larry,ProgAndy
; MSDN: http://msdn2.microsoft.com/en-us/library/ms712879.aspx
; default flag is $SND_SYNC = 0
Func _ResourcePlaySound($ResName, $Flag = 0, $DLL = -1)
    Local $hInstance

    If $DLL = -1 Then
      $hInstance = 0
    Else
      $hInstance = _WinAPI_LoadLibraryEx($DLL, $LOAD_LIBRARY_AS_DATAFILE)
    EndIf

    Local $ret = DllCall("winmm.dll", "int", "PlaySound", "str", $ResName, "hwnd", $hInstance, "int", BitOr($SND_RESOURCE,$Flag))
    If @error Then Return SetError(1, 0, 0)

    If $DLL <> -1 Then _WinAPI_FreeLibrary($hInstance)
    If @error Then Return SetError(2, 0, 0)

    Return $ret[0]
EndFunc
 

Licence 

 

Firemin will eliminate all memory leaks in Firefox.

Copyright © 2014  Rizonesoft (www.rizonesoft.com)
 
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

EDIT2: Nice GUI

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
Rizonetech

I have an opinion, I can't be bothered navigating to external unknown websites that may or may not be rife with malware viruses and drive by downloads.

Post your script here, unless you are just after hits on your website..

And what is the "clean memory API call" ? Is it anything like the ReduceMemory UDF which uses EmptyWorkingSet API and works on any process you pass to it?

 

I will post the script next time. I did not post the links for hits to my site. Just want to give everyone a location to get the resources and executable also. I'm getting enough hits as is without me needing to spam forums.

Firemin uses the EmptyWorkingSet API.

Thank you for your comment.


Rizonesoft Open Source Home Scripts: Complete Internet Repair | Development: Rizonesoft SDK

Share this post


Link to post
Share on other sites
JohnOne

I looked at your site, it's decent with some great software, but my only critique would be some rather grandiose claims about what your memory boosting and indeed this apps can do.

As I understand it emptyworkingset can cause problems when called directly and especially on third party processes. I'm not knocking it, because I've used the method myself, but only with buggy leaky apps.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
Rizonetech

I looked at your site, it's decent with some great software, but my only critique would be some rather grandiose claims about what your memory boosting and indeed this apps can do.

As I understand it emptyworkingset can cause problems when called directly and especially on third party processes. I'm not knocking it, because I've used the method myself, but only with buggy leaky apps.

 

You are absolutely right. When I wrote Memory Booster and Firemin, I was still running Windows XP and can't remember the Firefox build, but it was one with bad memory leaks. When I tested the apps it actually improved the performance of my system and solved the memory leak issues in Firefox. On my Windows 8 system, I do not notice much difference. It is the choice of the user to use the apps. Personally, I do not use them anymore, because I have 16GB RAM now and believe in letting Windows do its thing.

That all said, I keep the programs and descriptions as is, because it still works very well for some people. Memory booster has an option to control process priority that will also help with system performance. About the claims, it was all freeware and had to "sell" it, but tried to keep it as honest as possible.

Edited by Rizonetech

Rizonesoft Open Source Home Scripts: Complete Internet Repair | Development: Rizonesoft SDK

Share this post


Link to post
Share on other sites
Rizonetech

As and aside, I used _WinAPI_ReadProcessMemory to get how much memory was being used, and only emptied it if it was above my specified amount.

 

That is actually an extremely good idea. Mind if I use it for future Firemin upgrades?


Rizonesoft Open Source Home Scripts: Complete Internet Repair | Development: Rizonesoft SDK

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • Carm01
      By Carm01
      All,
      I have decided to release my code for the automated clean install, set up and configuration of Mozilla Firefox with a Mozilla.cfg file included in my example as well. I seen an older version of this and decided to post mine on here. This is Windows 10 friendly.
      The whole process once compiled executes in about 15 seconds on my machine from start to finish as it is extremely fast.
      If you want to include your own Mozilla.cfg into the mix simply place Your Mozilla.cfg file in the same directory as the exe when it is run. If you do not wish to embed the Mozilla.cfg file into the script as a back up in case you forget you need to remove that line of code to embed it.
      I hope this helps some people esp those wanting to understand how to use a cfg file to set default settings for all users without having to do it by putting all those files and folders in the defaultapp data folders.
      #RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Clear-App-firefox.ico #AutoIt3Wrapper_Outfile=FirefoxUpdater(x64Stable)_x.exe #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_UseUpx=y #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Res_Comment=Preformes a clean install of Firefox 64bit Stable version. Auto downloads latest version. #AutoIt3Wrapper_Res_Description=Updates to the Latest 64bit Stable #AutoIt3Wrapper_Res_Fileversion=2.5.0.0 #AutoIt3Wrapper_Res_ProductVersion=2.5.0.0 #AutoIt3Wrapper_Res_Language=1033 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <InetConstants.au3> #include <EventLog.au3> #include <Inet.au3> #include <File.au3> #include <array.au3> #include <Misc.au3> #include <TrayConstants.au3> ; Required for the $TRAY_CHECKED and $TRAY_ICONSTATE_SHOW constants. If UBound(ProcessList(@ScriptName)) > 2 Then Exit TraySetToolTip("Firefox Updater") HotKeySet("^!m", "MyExit") ; ctrl+Alt+m kills program ( hotkey ) Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode. Opt("TrayOnEventMode", 1) ; Enable TrayOnEventMode. TrayCreateItem("About") TrayItemSetOnEvent(-1, "About") TrayCreateItem("") ; Create a separator line. TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "ExitScript") TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "About") ; Display the About MsgBox when the tray icon is double clicked on with the primary mouse button. TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu. Local $sVersion, $CVersion, $ecode ;https://www.mozilla.org/en-US/firefox/developer/all/ ;https://www.mozilla.org/en-US/firefox/all/# ;https://www.mozilla.org/en-US/firefox/all/#en-US ;https://www.mozilla.org/en-US/firefox/beta/all/#en-US ;https://archive.mozilla.org/pub/firefox/candidates/48.0b1-candidates/build2/ ;https://archive.mozilla.org/pub/firefox/candidates/ getfiles() compare() killapps() uninstall() dlinstall() Exit Func killapps() ; kill firefox and plugin if running If FileExists("C:\Program Files\Mozilla Firefox\") Then $cmd = "taskkill.exe /im firefox.exe /f /t" RunWait('"' & @ComSpec & '" /c ' & $cmd, @SystemDir, @SW_HIDE) Sleep(300) $cmd = "taskkill.exe /im plugin* /f /t" RunWait('"' & @ComSpec & '" /c ' & $cmd, @SystemDir, @SW_HIDE) Sleep(300) Call("remcfg64") EndIf If FileExists("C:\Program Files (x86)\Mozilla Firefox\") Then $cmd = "taskkill.exe /im firefox.exe /f /t" RunWait('"' & @ComSpec & '" /c ' & $cmd, @SystemDir, @SW_HIDE) Sleep(300) $cmd = "taskkill.exe /im plugin* /f /t" RunWait('"' & @ComSpec & '" /c ' & $cmd, @SystemDir, @SW_HIDE) Sleep(300) Call("remcfg32") EndIf EndFunc ;==>killapps Func remcfg64() ; delete existing config file if exist $SSlist = _FileListToArrayRec("C:\Program Files\Mozilla Firefox\", "*", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) For $i = 1 To UBound($SSlist) - 1 If StringInStr($SSlist[$i], "mozilla.cfg") > 1 Then FileDelete($SSlist[$i]) ElseIf StringInStr($SSlist[$i], "override.ini") > 1 Then FileDelete($SSlist[$i]) ElseIf StringInStr($SSlist[$i], "local-settings.js") > 1 Then FileDelete($SSlist[$i]) EndIf Next EndFunc ;==>remcfg64 Func remcfg32() $SSlist = _FileListToArrayRec("C:\Program Files (x86)\Mozilla Firefox\", "*", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) For $i = 1 To UBound($SSlist) - 1 If StringInStr($SSlist[$i], "mozilla.cfg") > 1 Then FileDelete($SSlist[$i]) ElseIf StringInStr($SSlist[$i], "override.ini") > 1 Then FileDelete($SSlist[$i]) ElseIf StringInStr($SSlist[$i], "local-settings.js") > 1 Then FileDelete($SSlist[$i]) EndIf Next EndFunc ;==>remcfg32 Func uninstall() ; uninstall existing Firefox If FileExists("C:\Program Files\Mozilla Firefox\Firefox.exe") Then ShellExecuteWait("helper.exe", " /S", "C:\Program Files\Mozilla Firefox\uninstall") EndIf If FileExists("C:\Program Files (x86)\Mozilla Firefox\Firefox.exe") Then ShellExecuteWait("helper.exe", " /S", "C:\Program Files (x86)\Mozilla Firefox\uninstall") EndIf Sleep(1500) DirRemove("C:\Program Files (x86)\Mozilla Firefox\", 1) DirRemove("C:\Program Files\Mozilla Firefox\", 1) EndFunc ;==>uninstall Func getfiles() ; get latest download Local $sTxt, $sTxt1 $xjs = "C:\windows\temp\xjs.tmp" $xjs1 = "C:\windows\temp\xjs1.tmp" ;$sSite = "https://www.mozilla.org/en-US/firefox/beta/all/" $sSite = "https://www.mozilla.org/en-US/firefox/all/" ;$sNotes = "https://www.mozilla.org/en-US/firefox/beta/notes/" $sNotes = "https://www.mozilla.org/en-US/firefox/notes/" SplashTextOn("Progress", "", 210, 75, -1, -1, 18, "Tahoma", 10) ControlSetText("Progress", "", "Static1", "Initializing", 2) $source = _INetGetSource($sSite) $sTxt = StringSplit($source, @LF) $q = 0 $i = 0 For $i = 1 To UBound($sTxt) - 1 ; is like saying read the line number ;GUIGetMsg();prevent high cpu usage If StringInStr($sTxt[$i], "=win64&amp;lang=en-US") > 1 Then $sActiveX1 = StringSplit($sTxt[$i], 'href="', 1) $sActiveX2 = StringSplit($sActiveX1[2], '"') Global $dia = $sActiveX2[1] $q = 1 EndIf If UBound($sTxt) - 1 = $i Then $ecode = '404' EventLog() Exit EndIf If $q = 1 Then ExitLoop EndIf Next ; FIND VERSION $source = _INetGetSource($sNotes) $sTxt1 = StringSplit($source, @LF) $q = 0 $i = 0 For $i = 1 To UBound($sTxt1) - 1 ; is like saying read the line number ;GUIGetMsg();prevent high cpu usage If StringInStr($sTxt1[$i], "<title>Firefox") > 1 Then $sActiveX1 = StringSplit($sTxt1[$i], '<title>Firefox', 1) $sActiveX2 = StringSplit($sActiveX1[2], ',') $sVersion = StringStripWS($sActiveX2[1], 3) $q = 1 EndIf If $sVersion = "" Then ; error correcting if mozilla changes page where version notes are located. $sVersion = "Current Version" EndIf If $q = 1 Then ExitLoop EndIf Next SplashOff() EndFunc ;==>getfiles Func dlinstall() ; download and install $Version = $sVersion & " - 64 bit" _webDownloader($dia, "FFInstall.exe", $Version) SplashTextOn("Progress", "", 210, 75, -1, -1, 18, "Tahoma", 10) ControlSetText("Progress", "", "Static1", "Installing Version " & $sVersion, 2) ShellExecuteWait("FFInstall.exe", " -ms", "C:\Windows\Temp\") If FileExists(@ScriptDir & "\mozilla.cfg") Then FileCopy(@ScriptDir & "\mozilla.cfg", "C:\Program Files\Mozilla Firefox\mozilla.cfg", 1) Else FileInstall("G:\Users\username\Documents\Project\FirefoxDefault\mozilla.cfg", "C:\Program Files\Mozilla Firefox\mozilla.cfg", 1) EndIf FileWrite("C:\Program Files\Mozilla Firefox\defaults\pref\local-settings.js", 'pref("general.config.obscure_value", 0);' & @CRLF & 'pref("general.config.filename", "mozilla.cfg");' & @CRLF) FileWrite("C:\Program Files\Mozilla Firefox\browser\override.ini", '[XRE]' & @CRLF & 'EnableProfileMigrator=false' & @CRLF) FileDelete("C:\windows\temp\" & "\FFInstall.exe") $CVersion = FileGetVersion('C:\Program Files\Mozilla Firefox\firefox.exe', $FV_PRODUCTVERSION) SplashOff() EndFunc ;==>dlinstall Func _webDownloader($sSourceURL, $sTargetName, $sVisibleName, $sTargetDir = "C:\windows\temp", $bProgressOff = True, $iEndMsgTime = 2000, $sDownloaderTitle = "Mozilla Firefox") ; Declare some general vars Local $iMBbytes = 1048576 ; If the target directory doesn't exist -> create the dir If Not FileExists($sTargetDir) Then DirCreate($sTargetDir) ; Get download and target info Local $sTargetPath = $sTargetDir & "\" & $sTargetName Local $iFileSize = InetGetSize($sSourceURL) Local $hFileDownload = InetGet($sSourceURL, $sTargetPath, $INET_LOCALCACHE, $INET_DOWNLOADBACKGROUND) ; Show progress UI ProgressOn($sDownloaderTitle, "" & $sVisibleName) GUISetFont(8, 400) ; Keep checking until download completed Do Sleep(250) ; Set vars Local $iDLPercentage = Round(InetGetInfo($hFileDownload, $INET_DOWNLOADREAD) * 100 / $iFileSize, 0) Local $iDLBytes = Round(InetGetInfo($hFileDownload, $INET_DOWNLOADREAD) / $iMBbytes, 2) Local $iDLTotalBytes = Round($iFileSize / $iMBbytes, 2) ; Update progress UI If IsNumber($iDLBytes) And $iDLBytes >= 0 Then ProgressSet($iDLPercentage, $iDLPercentage & "% - Downloaded " & $iDLBytes & " MB of " & $iDLTotalBytes & " MB") Else ProgressSet(0, "Downloading '" & $sVisibleName & "'") EndIf Until InetGetInfo($hFileDownload, $INET_DOWNLOADCOMPLETE) ; If the download was successfull, return the target location If InetGetInfo($hFileDownload, $INET_DOWNLOADSUCCESS) Then ProgressSet(100, "Downloading '" & $sVisibleName & "' completed") If $bProgressOff Then Sleep($iEndMsgTime) ProgressOff() EndIf Return $sTargetPath ; If the download failed, set @error and return False Else Local $errorCode = InetGetInfo($hFileDownload, $INET_DOWNLOADERROR) ProgressSet(0, "Downloading '" & $sVisibleName & "' failed." & @CRLF & "Error code: " & $errorCode) If $bProgressOff Then Sleep($iEndMsgTime) ProgressOff() EndIf SetError(1, $errorCode, False) FileDelete("C:\windows\temp\" & "\FFInstall.exe") SplashOff() EndIf EndFunc ;==>_webDownloader Func compare() $CVersion = FileGetVersion('C:\Program Files\Mozilla Firefox\firefox.exe', $FV_PRODUCTVERSION) If $sVersion = $CVersion Then $ecode = '411' MsgBox(64, "Firefox says:", 'You have the latest version ' & $CVersion , 5) EventLog() Exit EndIf EndFunc ;==>compare Func EventLog() If $ecode = '404' Then Local $hEventLog, $aData[4] = [0, 4, 0, 4] $hEventLog = _EventLog__Open("", "Application") _EventLog__Report($hEventLog, 1, 0, 404, @UserName, @UserName & ' No "exe" found for Mozilla Firefox. The webpage and/or download link might have changed. ' & @CRLF, $aData) _EventLog__Close($hEventLog) EndIf If $ecode = '411' Then Local $hEventLog, $aData[4] = [0, 4, 1, 1] $hEventLog = _EventLog__Open("", "Application") _EventLog__Report($hEventLog, 0, 0, 411, @UserName, @UserName & " Mozilla Firefox " & "version " & $CVersion & " successfully installed." & @CRLF, $aData) _EventLog__Close($hEventLog) EndIf EndFunc ;==>EventLog Func MyExit() Exit EndFunc ;==>MyExit Func About() ; Display a message box about the AutoIt version and installation path of the AutoIt executable. MsgBox($MB_SYSTEMMODAL, "", "Firefox Update Tool" & @CRLF & @CRLF & _ "Version: 2.5.0.0" & @CRLF & _ "Firefox Updater by Carm0@Sourceforge" & @CRLF & "CTRL+ALT+m to kill", 5) ; Find the folder of a full path. EndFunc ;==>About Func ExitScript() Exit EndFunc ;==>ExitScript #comments-start http://superuser.com/questions/823530/change-some-default-settings-for-firefox-globally http://mxr.mozilla.org/mozilla-release/source/browser/app/profile/firefox.js#387 http://smallbusiness.chron.com/change-default-homepage-users-54727.html https://developer.mozilla.org/en-US/Firefox/Enterprise_deployment https://mike.kaply.com/2012/03/16/customizing-firefox-autoconfig-files/ https://wiki.mozilla.org/Installer:Command_Line_Arguments https://support.mozilla.org/en-US/questions/971189 http://forums.mozillazine.org/viewtopic.php?p=2228066 http://forums.mozillazine.org/viewtopic.php?f=38&t=2950829 ; updates auto http://forums.mozillazine.org/viewtopic.php?f=8&t=2753795 http://superuser.com/questions/697018/how-to-disable-popups-in-firefox-without-add-ons http://www.itninja.com/blog/view/deploy-popup-allowed-sites-with-firefox deploy with certain opous enabled #ce Mozilla.cfg file:
      // pref("browser.search.geoSpecificDefaults", false); pref("browser.search.defaultenginename.US", "data:text/plain,browser.search.defaultenginename.US=Google"); //https://support.mozilla.org/en-US/questions/1034136 // set Firefox Default homepage defaultPref("browser.startup.homepage", "data:text/plain,browser.startup.homepage=https://www.startpage.com/do/mypage.pl?prf=381c658b828c3fe50ec7563137fef98f"); // Don't show WhatsNew on first run after every update pref("browser.startup.homepage_override.mstone","ignore"); // disables the 'know your rights' button from displaying on first run pref("browser.rights.3.shown", true); pref("browser.usedOnWindows10", true); pref("browser.rights.override", true); // Do not perform system default browser check on startup pref("browser.shell.checkDefaultBrowser", false); // set all plugins to always activated - two settings pref("plugin.default.state", 2); // https://support.mozilla.org/en-US/questions/982143 reference about click to play flash // set flash and silverlight always ask = 1 always activate = 2 defaultPref("plugin.state.flash", 2); // hide choose what i share which pops up at the bottom after a minute lockPref("datareporting.policy.dataSubmissionPolicyBypassNotification", true); // https://groups.google.com/forum/#!topic/mozilla.support.firefox/DRXvfTA6Hnc //disable the "Improve Firefox" suggestion pref("toolkit.telemetry.prompted", 2); //https://support.mozilla.org/en-US/questions/898549 // do not block popups - can only be default or locked pref defaultPref("dom.disable_open_during_load", false); //http://superuser.com/questions/697018/how-to-disable-popups-in-firefox-without-add-ons //lockpref("privacy.sanitize.migrateFx3Prefs", true); // http://www.pcc-services.com/kixtart/firefox-lockdown.html //pref("browser.privatebrowsing.autostart", true); // prevent reader view from popping down at the top pref("reader.parse-on-load.enabled",false); // click to play - disabled so you are not prompted - https://support.mozilla.org/en-US/questions/934809 pref("plugins.click_to_play", false); // below will set the cache only to clear on exit, you need to tell it what to do with the reset of the data not just cache leave cache out. Just add a '\\' to whatever you want to clear on browser exit. //defaultPref("privacy.clearOnShutdown.cookies", false); defaultPref("privacy.clearOnShutdown.downloads", false); defaultPref("privacy.clearOnShutdown.formdata", false); defaultPref("privacy.clearOnShutdown.history", false); defaultPref("privacy.clearOnShutdown.sessions", false); defaultPref("privacy.sanitize.migrateClearSavedPwdsOnExit", false); defaultPref("privacy.sanitize.sanitizeOnShutdown", true); //pref("browser.privatebrowsing.autostart", true); //prevent autoplay https://support.mozilla.org/en-US/questions/1103127 //defaultPref("media.autoplay.enabled", false); //https://wiki.mozilla.org/Electrolysis //pref("browser.tabs.remote.autostart", true); //pref("browser.tabs.remote.force-enable", true); // ref: http://www.itninja.com/question/firefox-22-for-enterprise-deployment-default-preferences // Prevent refresh message showing at the bottom if firefox is not used in a while - http://techdows.com/2016/05/firefox-reinstall-to-prompt-for-a-refresh.html https://support.mozilla.org/en-US/questions/1084402 pref("browser.disableResetPrompt", true); // disable plugin check - https://support.mozilla.org/en-US/questions/968056 //defaultPref("plugin.scan.plid.all",false); //defaultPref("plugins.update.url",""); // disable remember preferences //defaultPref("signon.rememberSignons", false); //https://twitter.com/HighTechDad/status/955916813178691584 //https://t.co/YTvSy9EBJ1 // defaultPref can also be lockPref defaultPref("privacy.donottrackheader.enabled", true); //defaultPref("privacy.trackingprotection.enabled", true); lockPref("privacy.trackingprotection.introCount", 20);  
    • rudi
      By rudi
      Hello,
      usually I do Win automations, so I have no skills at all to handle HTML forms :-/
      The script to catch and syntax check  the required information from Excel is done.
      Now I'd like to automate the upload using this form, too:
       
      http://flashcardsdeluxe.com/flashcards/Upload.aspx
      What browser is easiest to do so? (IE, Chrome, FF) The Values $DeckCode, $DeckName, $DeckDefinition shall go to their HTML form fields finally "click" the button "upload flashcards" <table width="70%" class="cssCenter" border="0"> <tr> <td style="width: 1%">Deck&nbsp;Code</td> <td style="width: 100%"><input name="ctlDeckCode" type="text" id="ctlDeckCode" style="width:50%;" /> (no spaces allowed)</td> <td></td> </tr> <tr> <td style="width: 1%">Deck&nbsp;Name</td> <td style="width: 100%"><input name="ctlDeckName" type="text" id="ctlDeckName" style="width:50%;" /> (optional)</td> <td style="width: 1%" align="right"><input type="submit" name="ctlUpload" value="Upload Flashcards" id="ctlUpload" /></td> </tr> <tr> <td valign="top" style="padding-top: 5px" >Flashcard&nbsp;Text</td> <td colspan="2"><textarea name="ctlFlashcardText" rows="2" cols="20" id="ctlFlashcardText" style="height:280px;width:100%;"></textarea></td> </tr> </table> If someone kindly could jump in showing how to address just one of the input fields and how to "click" the "upload flashcards" button, I should be able to do the rest myself.
      TIA, Rudi.

    • Faraz
      By Faraz
      I have to open a URL on Mozilla Firefox , cursor is by default userid textbox, had to send userid, send tab, send pwd with flag 1 , send tab, send Enter.
      But Script is Failing to take Password.
      Any Help
       
      #include <Constants.au3>
      #include <IE.au3>
      #include <PassMask.au3>
      If $CmdLine[0] <> 3 Then
          MsgBox($MB_OK, "Usage", "ps_weblogin_FireFox <Url> <Browser Title> <Text to Send>")
      Else
         web_login($CmdLine[1], $CmdLine[2], $CmdLine[3])
      EndIf
      Func web_login($bt_url, $bt_Title, $bt_SendText)
          Local $ff = Run("C:\Program Files (x86)\Mozilla Firefox\firefox.exe " & $bt_url)
              WinWaitActive($bt_Title)
          Sleep(2000)
          ControlSend("","","",$bt_SendText)
      EndFunc
      _______________________________________________
      _______________________________________________
      Func Mask_Password($Password)
          $MaskPassword = $Password
          $MaskPassword = StringReplace($MaskPassword, "#", "||||||#@@@@@@")
          $MaskPassword = StringReplace($MaskPassword, "!", "||||||!@@@@@@")
          $MaskPassword = StringReplace($MaskPassword, "+", "||||||+@@@@@@")
          $MaskPassword = StringReplace($MaskPassword, "^", "||||||^@@@@@@")
          $MaskPassword = StringReplace($MaskPassword, "{", "||||||{@@@@@@")
          $MaskPassword = StringReplace($MaskPassword, "}", "||||||}@@@@@@")
          $MaskPassword = StringReplace($MaskPassword, "||||||", "{")
          $MaskPassword = StringReplace($MaskPassword, "@@@@@@", "}")
          Return $MaskPassword
      EndFunc
    • Marc
      By Marc
      Profiler - yet another backup script for Firefox and Thunderbird profiles
      It automatically detects the last recently used profile directories of Firefox and Thunderbird (installed versions, no portables).
      Clicking the Backup-Button creates a complete Backup of the found profiles with a timestamp.
      Restore deletes the according profile dir and extracts the content of the selected archive into the profile directory.
      Uses Winrar as compression tool, but feel free to change it to your needs
      Best regards
      Marc

      Profiler.au3
    • BOUNCER
      By BOUNCER
      I'm trying to get the output data from https://www.guilded.gg but it uses a web app that generates that output on the fly and this doesn't show up in the page source.
      Only in web inspector of each browser does this data show up. How do I read this data in autoit (equivalent to the web inspector)
       
      thank you
×