Sign in to follow this  
Followers 0
Briandr

number (integer) replace within script

2 posts in this topic

#1 ·  Posted (edited)

Hi,

I found this script someone else posted who was asking for help. This pertains to customizing Firefox settings. I been following Mozilla's guide but I wanted to try a different approach. I think this is correct except for I don't how to code this for a number replace as seen in the settings I am trying to change. Can someone assist? 

Thanks.

 

; wait for Firefox to close because the prefs.js will be overwritten when Firefox closes and the changes we make will be lost
ProcessWaitClose("firefox.exe")

If FileExists( @AppDataDir & "\Mozilla\Firefox\profiles.ini" ) Then
    $var = IniRead(@AppDataDir & "\Mozilla\Firefox\profiles.ini", "Profile0", "Path", "NotFound")
Else
    Exit 1
EndIf

; replace the / in the Path with a backslash
$var = StringReplace($var,"/","\")
$preffile = @AppDataDir & "\Mozilla\Firefox\" & $var & "\prefs.js"

; if the file exists then open it
If FileExists( $preffile ) Then
    $fh = FileOpen( $preffile, 0 ) ; read
    If $fh = -1 Then Exit 2
    $message = FileRead( $fh )
    FileClose( $fh )
    ; if the string doesn't exist we need to add it otherwise we make sure it is set to false
    
    If StringInStr( $message, "app.update.enabled" ) Then
        ; check to see if it is already true.. if so just Exit
        If StringInStr( $message, "user_pref(""app.update.enabled"", false);" ) Then
            $message = StringReplace( $message, "user_pref(""app.update.enabled"", false)", "user_pref(""app.update.enabled"", true)")
            $UpdateEnabled=True
        Else
            ; it is already true so just Exit
            Exit
        EndIf
    Else
        $message = StringReplace( $message, " */" & @CRLF & @CRLF,  " */" & @CRLF & @CRLF & "user_pref(""app.update.enabled"", true);" & @CRLF )
        $UpdateEnabled=True
    EndIf
     
    If StringInStr( $message, "app.update.interval" ) Then
        ; check to see if it is already it is 14400... if so just Exit
        If StringInStr( $message, "user_pref(""app.update.interval"", 43200);" ) Then
            $message = StringReplace( $message, "user_pref(""app.update.interval"", 43200)", "user_pref(""app.update.mode"", 14400)")
            $UpdateInterval = 14400
        Else
            ; it is already set to 14400 so just Exit
            Exit
        EndIf
    Else
        $message = StringReplace( $message, " */" & @CRLF & @CRLF,  " */" & @CRLF & @CRLF & "user_pref(""app.update.interval"", 14400);" & @CRLF )
        $UpdateInterval = 14400
    EndIf

    If StringInStr( $message, "app.update.mode" ) Then
        ; check to see if it is already it is 2... if so just Exit
        If StringInStr( $message, "user_pref(""app.update.mode"", 1);" ) Then
            $message = StringReplace( $message, "user_pref(""app.update.mode"", 1)", "user_pref(""app.update.mode"", 2)")
            $UpdateMode = 2
        Else
            ; it is already set to 2 so just Exit
            Exit
        EndIf
    Else
        $message = StringReplace( $message, " */" & @CRLF & @CRLF,  " */" & @CRLF & @CRLF & "user_pref(""app.update.mode"", 2);" & @CRLF )
        $UpdateMode = 2
    EndIf
Else
    Exit 3
    ; $message = "Prefs file does not exist."
EndIf
    
If $UpdateMode Then
    ; we need to update the file
    $fh = FileOpen($preffile, 2) ; erase
    ; Check if file opened for writing OK
    If $fh = -1 Then Exit 4
    FileWrite($fh, $message)
    FileClose($fh)
EndIf

 

Edited by Briandr

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I went back in and revised the code above. Orginally this was only intended to change on Firefox setting. The last If-EndIf section related to changing the preferences file. That applied for just one setting. How can this be changed to cover all settings needing to be changed, if need be based upn the settings I am checking. Can someone also tell me if something looks incorrect with the code as whole? 

Thanks

Edited by Briandr

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  
Followers 0