Commit 4f8a2170 authored by justcoding121's avatar justcoding121

cleanup firefox

parent 2bfb116c
...@@ -11,7 +11,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -11,7 +11,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <summary> /// <summary>
/// Add Firefox settings. /// Add Firefox settings.
/// </summary> /// </summary>
internal void AddFirefox() internal void UseSystemProxy()
{ {
try try
{ {
...@@ -19,48 +19,30 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -19,48 +19,30 @@ namespace Titanium.Web.Proxy.Helpers
new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
"\\Mozilla\\Firefox\\Profiles\\").GetDirectories("*.default"); "\\Mozilla\\Firefox\\Profiles\\").GetDirectories("*.default");
var myFfPrefFile = myProfileDirectory[0].FullName + "\\prefs.js"; var myFfPrefFile = myProfileDirectory[0].FullName + "\\prefs.js";
if (!File.Exists(myFfPrefFile)) return; if (!File.Exists(myFfPrefFile))
// We have a pref file so let''s make sure it has the proxy setting {
var myReader = new StreamReader(myFfPrefFile); return;
var myPrefContents = myReader.ReadToEnd(); }
myReader.Close();
if (!myPrefContents.Contains("user_pref(\"network.proxy.type\", 0);")) return;
// Add the proxy enable line and write it back to the file
myPrefContents = myPrefContents.Replace("user_pref(\"network.proxy.type\", 0);", "");
File.Delete(myFfPrefFile);
File.WriteAllText(myFfPrefFile, myPrefContents);
}
catch (Exception)
{
// Only exception should be a read/write error because the user opened up FireFox so they can be ignored.
}
}
/// <summary>
/// Remove firefox settings.
/// </summary>
internal void RemoveFirefox()
{
try
{
var myProfileDirectory =
new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
"\\Mozilla\\Firefox\\Profiles\\").GetDirectories("*.default");
var myFfPrefFile = myProfileDirectory[0].FullName + "\\prefs.js";
if (!File.Exists(myFfPrefFile)) return;
// We have a pref file so let''s make sure it has the proxy setting // We have a pref file so let''s make sure it has the proxy setting
var myReader = new StreamReader(myFfPrefFile); var myReader = new StreamReader(myFfPrefFile);
var myPrefContents = myReader.ReadToEnd(); var myPrefContents = myReader.ReadToEnd();
myReader.Close(); myReader.Close();
if (!myPrefContents.Contains("user_pref(\"network.proxy.type\", 0);"))
for (int i = 0; i <= 4; i++)
{ {
// Add the proxy enable line and write it back to the file var searchStr = $"user_pref(\"network.proxy.type\", {i});";
myPrefContents = myPrefContents + "\n\r" + "user_pref(\"network.proxy.type\", 0);";
File.Delete(myFfPrefFile); if (myPrefContents.Contains(searchStr))
File.WriteAllText(myFfPrefFile, myPrefContents); {
// Add the proxy enable line and write it back to the file
myPrefContents = myPrefContents.Replace(searchStr,
"user_pref(\"network.proxy.type\", 5);");
}
} }
File.Delete(myFfPrefFile);
File.WriteAllText(myFfPrefFile, myPrefContents);
} }
catch (Exception) catch (Exception)
{ {
......
...@@ -61,12 +61,13 @@ namespace Titanium.Web.Proxy ...@@ -61,12 +61,13 @@ namespace Titanium.Web.Proxy
/// </summary> /// </summary>
private SystemProxyManager systemProxySettingsManager { get; } private SystemProxyManager systemProxySettingsManager { get; }
#if !DEBUG
/// <summary> /// <summary>
/// Set firefox to use default system proxy /// Set firefox to use default system proxy
/// </summary> /// </summary>
private FireFoxProxySettingsManager firefoxProxySettingsManager = new FireFoxProxySettingsManager(); private FireFoxProxySettingsManager firefoxProxySettingsManager
#endif = new FireFoxProxySettingsManager();
/// <summary> /// <summary>
/// Buffer size used throughout this proxy /// Buffer size used throughout this proxy
...@@ -287,9 +288,7 @@ namespace Titanium.Web.Proxy ...@@ -287,9 +288,7 @@ namespace Titanium.Web.Proxy
ProxyEndPoints = new List<ProxyEndPoint>(); ProxyEndPoints = new List<ProxyEndPoint>();
tcpConnectionFactory = new TcpConnectionFactory(); tcpConnectionFactory = new TcpConnectionFactory();
systemProxySettingsManager = new SystemProxyManager(); systemProxySettingsManager = new SystemProxyManager();
#if !DEBUG
new FireFoxProxySettingsManager();
#endif
CertificateManager = new CertificateManager(ExceptionFunc); CertificateManager = new CertificateManager(ExceptionFunc);
if (rootCertificateName != null) if (rootCertificateName != null)
...@@ -363,9 +362,9 @@ namespace Titanium.Web.Proxy ...@@ -363,9 +362,9 @@ namespace Titanium.Web.Proxy
Equals(endPoint.IpAddress, IPAddress.Any) | Equals(endPoint.IpAddress, IPAddress.Loopback) ? "127.0.0.1" : endPoint.IpAddress.ToString(), endPoint.Port); Equals(endPoint.IpAddress, IPAddress.Any) | Equals(endPoint.IpAddress, IPAddress.Loopback) ? "127.0.0.1" : endPoint.IpAddress.ToString(), endPoint.Port);
endPoint.IsSystemHttpProxy = true; endPoint.IsSystemHttpProxy = true;
#if !DEBUG
firefoxProxySettingsManager.AddFirefox(); firefoxProxySettingsManager.UseSystemProxy();
#endif
Console.WriteLine("Set endpoint at Ip {0} and port: {1} as System HTTP Proxy", endPoint.IpAddress, endPoint.Port); Console.WriteLine("Set endpoint at Ip {0} and port: {1} as System HTTP Proxy", endPoint.IpAddress, endPoint.Port);
} }
...@@ -407,9 +406,8 @@ namespace Titanium.Web.Proxy ...@@ -407,9 +406,8 @@ namespace Titanium.Web.Proxy
endPoint.IsSystemHttpsProxy = true; endPoint.IsSystemHttpsProxy = true;
#if !DEBUG firefoxProxySettingsManager.UseSystemProxy();
firefoxProxySettingsManager.AddFirefox();
#endif
Console.WriteLine("Set endpoint at Ip {0} and port: {1} as System HTTPS Proxy", endPoint.IpAddress, endPoint.Port); Console.WriteLine("Set endpoint at Ip {0} and port: {1} as System HTTPS Proxy", endPoint.IpAddress, endPoint.Port);
} }
...@@ -500,9 +498,6 @@ namespace Titanium.Web.Proxy ...@@ -500,9 +498,6 @@ namespace Titanium.Web.Proxy
if (setAsSystemProxy) if (setAsSystemProxy)
{ {
systemProxySettingsManager.DisableAllProxy(); systemProxySettingsManager.DisableAllProxy();
#if !DEBUG
firefoxProxySettingsManager.RemoveFirefox();
#endif
} }
foreach (var endPoint in ProxyEndPoints) foreach (var endPoint in ProxyEndPoints)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment