From 217e81833906b88fe56552771e366af70486c273 Mon Sep 17 00:00:00 2001 From: Syrone Wong Date: Wed, 26 Oct 2016 16:48:40 +0800 Subject: [PATCH] Cleanup Signed-off-by: Syrone Wong --- shadowsocks-csharp/Util/SystemProxy/RAS.cs | 27 ++++++++++--------- .../Util/SystemProxy/WinINet.cs | 11 +------- shadowsocks-csharp/Util/Util.cs | 16 +++-------- 3 files changed, 19 insertions(+), 35 deletions(-) diff --git a/shadowsocks-csharp/Util/SystemProxy/RAS.cs b/shadowsocks-csharp/Util/SystemProxy/RAS.cs index 36066a6f..19f6c78b 100644 --- a/shadowsocks-csharp/Util/SystemProxy/RAS.cs +++ b/shadowsocks-csharp/Util/SystemProxy/RAS.cs @@ -1,13 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; +using System.Runtime.InteropServices; namespace Shadowsocks.Util.SystemProxy { - public static class RAS + internal static class RemoteAccessService { private enum RasFieldSizeConstants { @@ -69,22 +64,28 @@ namespace Shadowsocks.Util.SystemProxy #endregion public int dwSize; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst=(int)RasFieldSizeConstants.RAS_MaxEntryName + 1)] public string szEntryName; public int dwFlags; - [MarshalAs(UnmanagedType.ByValTStr,SizeConst=(int)RasFieldSizeConstants.RAS_MaxPath + 1)] + [MarshalAs(UnmanagedType.ByValTStr, SizeConst=(int)RasFieldSizeConstants.RAS_MaxPath + 1)] public string szPhonebookPath; } [DllImport("rasapi32.dll", CharSet = CharSet.Auto)] private static extern uint RasEnumEntries( - string reserved, // reserved, must be NULL - string lpszPhonebook, // pointer to full path and file name of phone-book file - [In, Out] RasEntryName[] lprasentryname, // buffer to receive phone-book entries - ref int lpcb, // size in bytes of buffer - out int lpcEntries // number of entries written to buffer + // reserved, must be NULL + string reserved, + // pointer to full path and file name of phone-book file + string lpszPhonebook, + // buffer to receive phone-book entries + [In, Out] RasEntryName[] lprasentryname, + // size in bytes of buffer + ref int lpcb, + // number of entries written to buffer + out int lpcEntries ); /// diff --git a/shadowsocks-csharp/Util/SystemProxy/WinINet.cs b/shadowsocks-csharp/Util/SystemProxy/WinINet.cs index a24d1197..c5dddee9 100644 --- a/shadowsocks-csharp/Util/SystemProxy/WinINet.cs +++ b/shadowsocks-csharp/Util/SystemProxy/WinINet.cs @@ -136,15 +136,6 @@ namespace Shadowsocks.Util.SystemProxy // Notify the system that the registry settings have been changed and cause // the proxy data to be reread from the registry for a handle. -// bReturn = NativeMethods.InternetSetOption( -// IntPtr.Zero, -// INTERNET_OPTION.INTERNET_OPTION_SETTINGS_CHANGED, -// IntPtr.Zero, 0); -// if ( ! bReturn ) -// { -// Logging.Error("InternetSetOption:INTERNET_OPTION_SETTINGS_CHANGED"); -// } - bReturn = NativeMethods.InternetSetOption( IntPtr.Zero, INTERNET_OPTION.INTERNET_OPTION_PROXY_SETTINGS_CHANGED, @@ -167,7 +158,7 @@ namespace Shadowsocks.Util.SystemProxy public static void SetIEProxy(bool enable, bool global, string proxyServer, string pacURL) { string[] allConnections = null; - var ret = RAS.GetAllConns(ref allConnections); + var ret = RemoteAccessService.GetAllConns(ref allConnections); if (ret == 2) throw new Exception("Cannot get all connections"); diff --git a/shadowsocks-csharp/Util/Util.cs b/shadowsocks-csharp/Util/Util.cs index 60a748e2..9050aeb9 100755 --- a/shadowsocks-csharp/Util/Util.cs +++ b/shadowsocks-csharp/Util/Util.cs @@ -1,11 +1,8 @@ using System; -using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.IO.Compression; -using System.Linq; using System.Runtime.InteropServices; -using System.Security; using System.Windows.Forms; using Microsoft.Win32; using Shadowsocks.Controller; @@ -224,19 +221,14 @@ namespace Shadowsocks.Util .OpenSubKey(name, writable); return userKey; } - catch (UnauthorizedAccessException uae) - { - Logging.LogUsefulException(uae); - return null; - } - catch (SecurityException se) + catch (ArgumentException ae) { - Logging.LogUsefulException(se); + MessageBox.Show("OpenRegKey: " + ae.ToString()); return null; } - catch (ArgumentException ae) + catch (Exception e) { - MessageBox.Show("OpenRegKey: " + ae.ToString()); + Logging.LogUsefulException(e); return null; } }