This repository has been archived by the owner on Oct 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTools.cs
73 lines (56 loc) · 2 KB
/
Tools.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace FirefoxMissingCertMimeTypePatcher
{
class Tools
{
/*
* Credits for this method for anirugu
* https://gist.github.com/anirugu/7243142
*/
public static string GetFirefoxProfilePath()
{
string apppath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string mozilla = Path.Combine(apppath, "Mozilla");
bool exist = Directory.Exists(mozilla);
if (exist)
{
string firefox = Path.Combine(mozilla, "firefox");
if (Directory.Exists(firefox))
{
string prof_file = Path.Combine(firefox, "profiles.ini");
bool file_exist = File.Exists(prof_file);
if (file_exist)
{
StreamReader rdr = new StreamReader(prof_file);
string resp = rdr.ReadToEnd();
string[] lines = resp.Split(new string[] { "\r\n" }, StringSplitOptions.None);
string location = lines.First(x => x.Contains("Path=")).Split(new string[] { "=" }, StringSplitOptions.None)[1];
string prof_dir = Path.Combine(firefox, location);
return prof_dir;
}
}
}
return "";
}
public static string GetMimeTypesRdfPath()
{
return GetFirefoxProfilePath() + @"\mimeTypes.rdf";
}
public static bool MimeTypesRdfExist()
{
return File.Exists(GetMimeTypesRdfPath());
}
public static string GetMimeTypesRdfText()
{
return File.ReadAllText(GetMimeTypesRdfPath());
}
public static void CreateBackup()
{
File.Copy(GetMimeTypesRdfPath(), GetMimeTypesRdfPath() + ".bak", true);
}
}
}