Skip to content

Instantly share code, notes, and snippets.

@DreamVB
Created July 3, 2016 10:41
Show Gist options
  • Save DreamVB/a876b23ac72e8d35f51fa8d94e822892 to your computer and use it in GitHub Desktop.
Save DreamVB/a876b23ac72e8d35f51fa8d94e822892 to your computer and use it in GitHub Desktop.
Return firefox profile, cache folder locations.
using System;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
namespace ffProfile
{
class GetProfile
{
public enum TCache
{
Cache2 = 0,
JumpListCache,
StartupCache,
OfflineCache
};
private FileInfo fi = null;
[DllImport("kernel32")]
static extern int GetPrivateProfileString(string Section, string Key, string Default, StringBuilder RetVal, int Size, string FilePath);
private string ReadString(string selection, string Key, string vDefault = "")
{
StringBuilder sb = new StringBuilder(256);
//Get ini file.
GetPrivateProfileString(selection, Key, vDefault, sb, 256, fi.FullName);
//Return value.
return sb.ToString();
}
public string Profile()
{
//Get firefox main profile folder.
string basefolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
@"\Mozilla\Firefox\";
string ffFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) +
@"\Mozilla\Firefox\";
string RetStr = string.Empty;
fi = new FileInfo(basefolder + "profiles.ini");
if (fi.Exists)
{
//Get profile folder from profile ini file.
RetStr = ffFolder +
ReadString("Profile0", "Path", string.Empty).Replace("/", "\\");
}
return RetStr;
}
public string GetCache(TCache type)
{
//Return firefox cache folder locations.
string RetStr = string.Empty;
switch (type)
{
case TCache.Cache2:
RetStr = Profile() + @"\cache2\entries\";
break;
case TCache.JumpListCache:
RetStr = Profile() + @"\jumpListCache\";
break;
case TCache.StartupCache:
RetStr = Profile() + @"\startupCache\";
break;
case TCache.OfflineCache:
RetStr = Profile() + @"\OfflineCache\";
break;
}
//Return
return RetStr;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment