Created
May 25, 2019 22:36
-
-
Save jscher2000/9bb73efe9046bcdbb1c8a31f78386d21 to your computer and use it in GitHub Desktop.
Firefox session history file backer upper script creator (Firefox 67+)
This file contains hidden or 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
Option Explicit | |
' Creates a Backup Script named Fx-backup-recoveryJS(profilefoldername).vbs in your (My) Documents folder to copy | |
' recovery.jsonlz4 or sessionstore.jsonlz4 from your default profile to an FxSessions folder in your (My) Documents folder | |
' v0.3 - 25 May 2019 - jscher2000 - MPL 2.0 license | |
Dim oShell, sAppData, sDocsFolder | |
' Get APPDATA path and My Documents path | |
Set oShell = CreateObject("Wscript.Shell") | |
sAppData = oShell.expandEnvironmentStrings("%APPDATA%") + "\Mozilla\Firefox" | |
sDocsFolder = oShell.SpecialFolders.Item("MyDocuments") | |
' Check for Firefox's installs.ini file | |
Dim oFSO, tsPI, sInstalls, iCount, sProfileFields, jCount, sPath, sFName, sFPath, tsVBS | |
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject") | |
If oFSO.FileExists(sAppData & "\installs.ini") Then | |
' Get the installs.ini contents | |
Set tsPI = oFSO.OpenTextFile(sAppData & "\installs.ini", 1) ' open ForReading | |
sInstalls = Split(tsPI.ReadAll, vbCrLf & vbCrLf) | |
tsPI.Close | |
Set tsPI = nothing | |
' Check the installs.ini contents and look for default path(s) | |
' WARNING: ONLY HANDLES RELATIVE PATHS FOR NOW (e.g., Default=Profiles/abcd1234.default-release) | |
sPath = vbNullString | |
For iCount = LBound(sInstalls) to UBound(sInstalls) | |
If InStr(1, sInstalls(iCount), "Default=Profiles/") > 0 Then | |
sProfileFields = Split(sInstalls(iCount), vbCrLf) | |
For jCount = LBound(sProfileFields) to UBound(sProfileFields) | |
If InStr(1, sProfileFields(jCount), "Default=Profiles/") > 0 Then | |
sPath = Split(sProfileFields(jCount), "=")(1) | |
If sPath <> vbNullString Then | |
sPath = Replace(sPath, "/", "\") | |
sFName = sDocsFolder & "\Fx-backup-recoveryJS(" & Replace(Mid(sPath, InStr(1, sPath, "\") + 1), " ", "_") & ").vbs" | |
sFPath = sAppData & "\" & sPath | |
' Create backup script in user's Documents folder | |
Set tsVBS = oFSO.CreateTextFile(sFName) ' Overwrite old file if it exists | |
tsVBS.WriteLine "Dim oFSO, sTgt, sName, sDest, datNow, strDT" | |
tsVBS.WriteLine "Set oFSO = WScript.CreateObject(""Scripting.FileSystemObject"")" | |
tsVBS.WriteLine "sTgt = """ & sFPath & "\sessionstore-backups\recovery.jsonlz4""" | |
tsVBS.WriteLine "If oFSO.FileExists(sTgt) Then" | |
tsVBS.WriteLine vbTab & "sName = """ & Replace(Mid(sPath, InStr(1, sPath, ".") + 1), " ", "_") & "-recovery""" | |
tsVBS.WriteLine "Else" | |
tsVBS.WriteLine vbTab & "sTgt = """ & sFPath & "\sessionstore.jsonlz4""" | |
tsVBS.WriteLine vbTab & "sName = """ & Replace(Mid(sPath, InStr(1, sPath, ".") + 1), " ", "_") & "-sessionstore""" | |
tsVBS.WriteLine "End If" | |
tsVBS.WriteLine "If oFSO.FileExists(sTgt) Then ' There is a recovery.jsonlz4 file in the targeted profile, so copy it" | |
tsVBS.WriteLine vbTab & "' Check for/set up destination folder under My Documents" | |
tsVBS.WriteLine vbTab & "sDest = """ & sDocsFolder & "\FxSessions""" | |
tsVBS.WriteLine vbTab & "If Not oFSO.FolderExists(sDest) Then" | |
tsVBS.WriteLine vbTab & vbTab & "oFSO.CreateFolder(sDest)" | |
tsVBS.WriteLine vbTab & "End If" | |
tsVBS.WriteLine vbTab & "' Prepare date/time string to add into the destination file name" | |
tsVBS.WriteLine vbTab & "datNow = Now" | |
tsVBS.WriteLine vbTab & "strDT = Year(datNow) & ""-"" & Right(""00"" & DatePart(""m"", datNow), 2) & ""-"" & Right(""00"" & DatePart(""d"", datNow), 2) & ""_"" & Right(""00"" & DatePart(""h"", datNow), 2) & Right(""00"" & DatePart(""n"", datNow), 2) & Right(""00"" & DatePart(""s"", datNow), 2)" | |
tsVBS.WriteLine vbTab & "' Copy the file" | |
tsVBS.WriteLine vbTab & "oFSO.CopyFile sTgt, sDest & ""\"" & sName & ""_"" & strDT & "".jsonlz4""" | |
tsVBS.WriteLine "Else" | |
tsVBS.WriteLine vbTab & "' Quit silently to avoid stranding pop-up messages when file is not found" | |
tsVBS.WriteLine "End If" | |
tsVBS.WriteLine "Set oFSO = Nothing" | |
tsVBS.Close | |
Set tsVBS = Nothing | |
' Launch Windows Explorer to the new VBS file | |
oShell.Run "explorer.exe /select,""" & sFName & """" | |
End If | |
End If | |
Next | |
End If | |
Next | |
If sPath = vbNullString Then | |
MsgBox ("Could not identify default profile path!") | |
End If | |
Else | |
MsgBox("Can't find installs.ini!") | |
End If | |
Set oFSO = Nothing | |
Set oShell = Nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment