Created
August 14, 2017 06:15
-
-
Save jcunews/e7083eee8accfad8d8faf6bd54930c6c to your computer and use it in GitHub Desktop.
Firefox Installation Fixer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub showError(msg) | |
wscript.echo msg | |
wscript.quit | |
end sub | |
sub help | |
showError "Firefox Installation Fixer" & vbcrlf & vbcrlf & _ | |
"Usage: fif {old path} {profile} {new path}" & vbcrlf & vbcrlf & _ | |
"e.g.:" & vbcrlf & _ | |
" fif E:\Mozilla\Firefox profiles\john E:\Firefox" & vbcrlf & _ | |
" fif ""E:\Mozilla Firefox"" profile E:\Firefox" & vbcrlf & vbcrlf & _ | |
"Profile is the profile folder name within the old path." & vbcrlf & _ | |
"e.g.: E:\Mozilla Firefox\profile" & vbcrlf & vbcrlf & _ | |
"Below files may be modified (and named as ""name.ext.new"")." & vbcrlf & _ | |
"- compatibility.ini" & vbcrlf & _ | |
"- extensions.ini" & vbcrlf & _ | |
"- extensions.json" & vbcrlf & _ | |
"- prefs.js" & vbcrlf & vbcrlf & _ | |
"This tool is intended for Firefox installation that uses" & vbcrlf & _ | |
"the -profile switch to launch the web browser." | |
end sub | |
function checkPath(path) | |
orgPath = shl.currentdirectory | |
on error resume next | |
shl.currentdirectory = path | |
on error goto 0 | |
checkPath = err.number | |
set folder = fso.getfolder(shl.currentdirectory) | |
fullPath = folder.path | |
shl.currentdirectory = orgPath | |
end function | |
function checkFile(file) | |
if not fso.fileexists(profilePath & "\" & file) then | |
showError "The """ & file & """ file in profile folder is not found." | |
end if | |
end function | |
sub processFile(file) | |
file = profilePath & "\" & file | |
set handle = fso.opentextfile(file, 1) | |
text = handle.readall | |
handle.close | |
set rx = new regexp | |
rx.global = true | |
rx.ignorecase = true | |
rx.pattern = replace(oldPath, "\", "\\") | |
text = rx.replace(text, newPath) | |
rx.pattern = replace(oldPath, "\", "/") | |
text = rx.replace(text, replace(newPath, "\", "/")) | |
rx.pattern = replace(oldPath, "\", "\\\\") | |
text = rx.replace(text, replace(newPath, "\", "\\")) | |
set handle = fso.opentextfile(file & ".new", 2, true) | |
handle.write(text) | |
handle.close | |
end sub | |
if wscript.arguments.count = 0 then help | |
oldPath = "" | |
profilePath = "" | |
newPath = "" | |
fullPath = "" | |
set fso = createobject("scripting.filesystemobject") | |
set shl = createobject("wscript.shell") | |
for i = 0 to wscript.arguments.count - 1 | |
s = wscript.arguments(i) | |
if lcase(s) = "/r" then | |
move = true | |
elseif oldPath = "" then | |
oldPath = s | |
elseif profilePath = "" then | |
profilePath = s | |
elseif newPath = "" then | |
newPath = s | |
else | |
help | |
end if | |
next | |
if newPath = "" then help | |
if not fso.folderexists(oldPath) then | |
showError "The old path is not found." | |
end if | |
on error resume next | |
e = checkPath(oldPath) | |
if e <> 0 then | |
showError "Old path is not accessible. Error code " & e | |
end if | |
oldPath = fullPath | |
profilePath = oldPath & "\" & profilePath | |
if not fso.folderexists(profilePath) then | |
showError "Profile folder is not found within the old path. i.e.:" & _ | |
vbcrlf & " " & profilePath | |
end if | |
e = checkPath(profilePath) | |
if e <> 0 then | |
showError "Profile path is not accessible. Error code " & e | |
end if | |
profilePath = fullPath | |
if not fso.folderexists(newPath) then | |
on error resume next | |
fso.createfolder newPath | |
on error goto 0 | |
e = err.number | |
if e = 0 then | |
checkPath newPath | |
fso.deleteFolder newPath | |
elseif e = 76 then | |
showError "The new path is invalid." | |
else | |
showError "Failed validating new path. Error code " & e | |
end if | |
else | |
checkPath newPath | |
end if | |
newPath = fullPath | |
wscript.echo oldPath & vbcrlf & profilePath & vbcrlf & "=> " & newPath | |
checkFile("compatibility.ini") | |
checkFile("extensions.ini") | |
checkFile("extensions.json") | |
checkFile("prefs.js") | |
processFile("compatibility.ini") | |
processFile("extensions.ini") | |
processFile("extensions.json") | |
processFile("prefs.js") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A VBScript to fix Firefox installation configuration after renaming the base folder or moving it to somewhere else. This tool automates the modifications of the configuration files. After it finished, any "name.ext.new" file (in the profile folder) must be renamed to its original file name (i.e. "name.ext"). The original files should be backed up before doing so, since this tool doesn't create them.
Executing it without any parameter will show the usage help like below.