Skip to content

Instantly share code, notes, and snippets.

@crosbymichael
Created August 30, 2012 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crosbymichael/3521509 to your computer and use it in GitHub Desktop.
Save crosbymichael/3521509 to your computer and use it in GitHub Desktop.
Disable Java in Firefox
package main
import (
"fmt"
"io/ioutil"
"os"
"os/user"
"path"
"strings"
)
const FILE_NAME = "pluginreg.dat"
const SEARCH_STRING = "Displays Java applet content"
const LINE_ENDING = "\n"
func main() {
basePath := getHomeDirectory()
profilePath := getFireFoxProfileDirectory(basePath)
profileContents := getDirectories(profilePath)
fmt.Printf(profilePath)
for i := 0; i < len(profileContents); i++ {
file := profileContents[i]
if file.IsDir() {
fmt.Printf("File Name: %s\n", file.Name())
processContets(profilePath, file.Name())
}
}
}
func getHomeDirectory() (string) {
currentUser, err := user.Current()
if err != nil {
panic(err)
}
return currentUser.HomeDir
}
func getFireFoxProfileDirectory(basePath string) (string) {
return path.Join(
basePath,
"Library",
"Application Support",
"Firefox",
"Profiles")
}
func getDirectories(path string) ([]os.FileInfo) {
files, err := ioutil.ReadDir(path)
if err != nil {
panic(err)
}
return files
}
func processContets(basePath string, dirName string) {
fullPath := path.Join(basePath, dirName, FILE_NAME)
lines := getLines(fullPath)
for i, line := range lines {
if strings.Contains(line, SEARCH_STRING) {
configLine := i - 1
lines[configLine] = processLine(lines[configLine])
fmt.Printf("%s\n", lines[configLine])
}
}
writeContents(lines, fullPath)
}
func getLines(path string) (lines []string) {
content, err := ioutil.ReadFile(path)
if err != nil {
panic(err)
}
return strings.Split(string(content), LINE_ENDING)
}
func processLine(line string) (string) {
lines := strings.Split(line, ":")
index := len(lines) - 2
lines[index] = "0"
return strings.Join(lines, ":")
}
func writeContents(contents []string, fullPath string) {
ioutil.WriteFile(
fullPath,
[]byte(strings.Join(
contents,
LINE_ENDING)),
0644)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment