Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Titanium-Web-Proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Titanium-Web-Proxy
Commits
636ea836
Commit
636ea836
authored
Jun 10, 2017
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Save and clear AutoConfigURL registry value when enable system proxy
parent
d1e90a21
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
31 deletions
+44
-31
SystemProxy.cs
Titanium.Web.Proxy/Helpers/SystemProxy.cs
+44
-31
No files found.
Titanium.Web.Proxy/Helpers/SystemProxy.cs
View file @
636ea836
...
@@ -81,10 +81,16 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -81,10 +81,16 @@ namespace Titanium.Web.Proxy.Helpers
/// </summary>
/// </summary>
internal
class
SystemProxyManager
internal
class
SystemProxyManager
{
{
private
const
string
regKeyInternetSettings
=
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"
;
private
const
string
regAutoConfigUrl
=
"AutoConfigURL"
;
private
const
string
regProxyEnable
=
"ProxyEnable"
;
private
const
string
regProxyServer
=
"ProxyServer"
;
internal
const
int
InternetOptionSettingsChanged
=
39
;
internal
const
int
InternetOptionSettingsChanged
=
39
;
internal
const
int
InternetOptionRefresh
=
37
;
internal
const
int
InternetOptionRefresh
=
37
;
private
bool
originalValuesLoaded
;
private
bool
originalValuesLoaded
;
private
string
originalAutoConfigUrl
;
private
int
?
originalProxyEnable
;
private
int
?
originalProxyEnable
;
private
string
originalProxyServer
;
private
string
originalProxyServer
;
...
@@ -117,15 +123,14 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -117,15 +123,14 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="protocolType"></param>
/// <param name="protocolType"></param>
internal
void
SetProxy
(
string
hostname
,
int
port
,
ProxyProtocolType
protocolType
)
internal
void
SetProxy
(
string
hostname
,
int
port
,
ProxyProtocolType
protocolType
)
{
{
var
reg
=
Registry
.
CurrentUser
.
OpenSubKey
(
var
reg
=
Registry
.
CurrentUser
.
OpenSubKey
(
regKeyInternetSettings
,
true
);
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"
,
true
);
if
(
reg
!=
null
)
if
(
reg
!=
null
)
{
{
SaveOriginalProxyConfiguration
(
reg
);
SaveOriginalProxyConfiguration
(
reg
);
PrepareRegistry
(
reg
);
PrepareRegistry
(
reg
);
var
exisitingContent
=
reg
.
GetValue
(
"ProxyServer"
)
as
string
;
var
exisitingContent
=
reg
.
GetValue
(
regProxyServer
)
as
string
;
var
existingSystemProxyValues
=
GetSystemProxyValues
(
exisitingContent
);
var
existingSystemProxyValues
=
GetSystemProxyValues
(
exisitingContent
);
existingSystemProxyValues
.
RemoveAll
(
x
=>
(
protocolType
&
x
.
ProtocolType
)
!=
0
);
existingSystemProxyValues
.
RemoveAll
(
x
=>
(
protocolType
&
x
.
ProtocolType
)
!=
0
);
if
((
protocolType
&
ProxyProtocolType
.
Http
)
!=
0
)
if
((
protocolType
&
ProxyProtocolType
.
Http
)
!=
0
)
...
@@ -148,8 +153,9 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -148,8 +153,9 @@ namespace Titanium.Web.Proxy.Helpers
});
});
}
}
reg
.
SetValue
(
"ProxyEnable"
,
1
);
reg
.
DeleteValue
(
regAutoConfigUrl
,
false
);
reg
.
SetValue
(
"ProxyServer"
,
string
.
Join
(
";"
,
existingSystemProxyValues
.
Select
(
x
=>
x
.
ToString
()).
ToArray
()));
reg
.
SetValue
(
regProxyEnable
,
1
);
reg
.
SetValue
(
regProxyServer
,
string
.
Join
(
";"
,
existingSystemProxyValues
.
Select
(
x
=>
x
.
ToString
()).
ToArray
()));
Refresh
();
Refresh
();
}
}
...
@@ -160,28 +166,27 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -160,28 +166,27 @@ namespace Titanium.Web.Proxy.Helpers
/// </summary>
/// </summary>
internal
void
RemoveProxy
(
ProxyProtocolType
protocolType
)
internal
void
RemoveProxy
(
ProxyProtocolType
protocolType
)
{
{
var
reg
=
Registry
.
CurrentUser
.
OpenSubKey
(
var
reg
=
Registry
.
CurrentUser
.
OpenSubKey
(
regKeyInternetSettings
,
true
);
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"
,
true
);
if
(
reg
!=
null
)
if
(
reg
!=
null
)
{
{
SaveOriginalProxyConfiguration
(
reg
);
SaveOriginalProxyConfiguration
(
reg
);
if
(
reg
.
GetValue
(
"ProxyServer"
)
!=
null
)
if
(
reg
.
GetValue
(
regProxyServer
)
!=
null
)
{
{
var
exisitingContent
=
reg
.
GetValue
(
"ProxyServer"
)
as
string
;
var
exisitingContent
=
reg
.
GetValue
(
regProxyServer
)
as
string
;
var
existingSystemProxyValues
=
GetSystemProxyValues
(
exisitingContent
);
var
existingSystemProxyValues
=
GetSystemProxyValues
(
exisitingContent
);
existingSystemProxyValues
.
RemoveAll
(
x
=>
(
protocolType
&
x
.
ProtocolType
)
!=
0
);
existingSystemProxyValues
.
RemoveAll
(
x
=>
(
protocolType
&
x
.
ProtocolType
)
!=
0
);
if
(
existingSystemProxyValues
.
Count
!=
0
)
if
(
existingSystemProxyValues
.
Count
!=
0
)
{
{
reg
.
SetValue
(
"ProxyEnable"
,
1
);
reg
.
SetValue
(
regProxyEnable
,
1
);
reg
.
SetValue
(
"ProxyServer"
,
string
.
Join
(
";"
,
existingSystemProxyValues
.
Select
(
x
=>
x
.
ToString
()).
ToArray
()));
reg
.
SetValue
(
regProxyServer
,
string
.
Join
(
";"
,
existingSystemProxyValues
.
Select
(
x
=>
x
.
ToString
()).
ToArray
()));
}
}
else
else
{
{
reg
.
SetValue
(
"ProxyEnable"
,
0
);
reg
.
SetValue
(
regProxyEnable
,
0
);
reg
.
SetValue
(
"ProxyServer"
,
string
.
Empty
);
reg
.
SetValue
(
regProxyServer
,
string
.
Empty
);
}
}
}
}
...
@@ -194,15 +199,14 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -194,15 +199,14 @@ namespace Titanium.Web.Proxy.Helpers
/// </summary>
/// </summary>
internal
void
DisableAllProxy
()
internal
void
DisableAllProxy
()
{
{
var
reg
=
Registry
.
CurrentUser
.
OpenSubKey
(
var
reg
=
Registry
.
CurrentUser
.
OpenSubKey
(
regKeyInternetSettings
,
true
);
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"
,
true
);
if
(
reg
!=
null
)
if
(
reg
!=
null
)
{
{
SaveOriginalProxyConfiguration
(
reg
);
SaveOriginalProxyConfiguration
(
reg
);
reg
.
SetValue
(
"ProxyEnable"
,
0
);
reg
.
SetValue
(
regProxyEnable
,
0
);
reg
.
SetValue
(
"ProxyServer"
,
string
.
Empty
);
reg
.
SetValue
(
regProxyServer
,
string
.
Empty
);
Refresh
();
Refresh
();
}
}
...
@@ -215,27 +219,35 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -215,27 +219,35 @@ namespace Titanium.Web.Proxy.Helpers
return
;
return
;
}
}
var
reg
=
Registry
.
CurrentUser
.
OpenSubKey
(
var
reg
=
Registry
.
CurrentUser
.
OpenSubKey
(
regKeyInternetSettings
,
true
);
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"
,
true
);
if
(
reg
!=
null
)
if
(
reg
!=
null
)
{
{
if
(
originalAutoConfigUrl
!=
null
)
{
reg
.
SetValue
(
regAutoConfigUrl
,
originalAutoConfigUrl
);
}
else
{
reg
.
DeleteValue
(
regAutoConfigUrl
,
false
);
}
if
(
originalProxyEnable
.
HasValue
)
if
(
originalProxyEnable
.
HasValue
)
{
{
reg
.
SetValue
(
"ProxyEnable"
,
originalProxyEnable
.
Value
);
reg
.
SetValue
(
regProxyEnable
,
originalProxyEnable
.
Value
);
}
}
else
if
(
reg
.
GetValue
(
"ProxyEnable"
)
!=
null
)
else
{
{
reg
.
DeleteValue
(
"ProxyEnable"
);
reg
.
DeleteValue
(
regProxyEnable
,
false
);
}
}
if
(
originalProxyServer
!=
null
)
if
(
originalProxyServer
!=
null
)
{
{
reg
.
SetValue
(
"ProxyServer"
,
originalProxyServer
);
reg
.
SetValue
(
regProxyServer
,
originalProxyServer
);
}
}
else
if
(
reg
.
GetValue
(
"ProxyServer"
)
!=
null
)
else
{
{
reg
.
DeleteValue
(
"ProxyServer"
);
reg
.
DeleteValue
(
regProxyServer
,
false
);
}
}
originalValuesLoaded
=
false
;
originalValuesLoaded
=
false
;
...
@@ -245,8 +257,9 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -245,8 +257,9 @@ namespace Titanium.Web.Proxy.Helpers
private
void
SaveOriginalProxyConfiguration
(
RegistryKey
reg
)
private
void
SaveOriginalProxyConfiguration
(
RegistryKey
reg
)
{
{
originalProxyServer
=
reg
.
GetValue
(
"ProxyServer"
)
as
string
;
originalAutoConfigUrl
=
reg
.
GetValue
(
regAutoConfigUrl
)
as
string
;
originalProxyEnable
=
reg
.
GetValue
(
"ProxyEnable"
)
as
int
?;
originalProxyServer
=
reg
.
GetValue
(
regProxyServer
)
as
string
;
originalProxyEnable
=
reg
.
GetValue
(
regProxyEnable
)
as
int
?;
originalValuesLoaded
=
true
;
originalValuesLoaded
=
true
;
}
}
...
@@ -322,14 +335,14 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -322,14 +335,14 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="reg"></param>
/// <param name="reg"></param>
private
static
void
PrepareRegistry
(
RegistryKey
reg
)
private
static
void
PrepareRegistry
(
RegistryKey
reg
)
{
{
if
(
reg
.
GetValue
(
"ProxyEnable"
)
==
null
)
if
(
reg
.
GetValue
(
regProxyEnable
)
==
null
)
{
{
reg
.
SetValue
(
"ProxyEnable"
,
0
);
reg
.
SetValue
(
regProxyEnable
,
0
);
}
}
if
(
reg
.
GetValue
(
"ProxyServer"
)
==
null
||
reg
.
GetValue
(
"ProxyEnable"
)
as
int
?
==
0
)
if
(
reg
.
GetValue
(
regProxyServer
)
==
null
||
reg
.
GetValue
(
regProxyEnable
)
as
int
?
==
0
)
{
{
reg
.
SetValue
(
"ProxyServer"
,
string
.
Empty
);
reg
.
SetValue
(
regProxyServer
,
string
.
Empty
);
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment