From f00794678c85ce5e2b0deb34b3603813fb7cdc5f Mon Sep 17 00:00:00 2001 From: database64128 Date: Sun, 8 Nov 2020 22:24:06 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A9=20Enable=20nullable,=20remove=20ho?= =?UTF-8?q?tkey=20and=20clean=20up=20some=20stuff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Shadowsocks.PAC/GeositeUpdater.cs | 6 +- Shadowsocks.PAC/PACServer.cs | 7 +- Shadowsocks.PAC/Shadowsocks.PAC.csproj | 1 + Shadowsocks.WPF/Behaviors/HotkeyReg.cs | 91 --------- .../Behaviors/Hotkeys/HotkeyCallbacks.cs | 114 ----------- Shadowsocks.WPF/Behaviors/Hotkeys/Hotkeys.cs | 174 ---------------- Shadowsocks.WPF/Behaviors/LoggerExtension.cs | 143 ------------- .../PublishProfiles/FolderProfile.pubxml | 2 +- .../Properties/Resources.Designer.cs | 105 ++++++++++ Shadowsocks.WPF/Properties/Resources.resx | 130 ++++++++++++ Shadowsocks.WPF/Shadowsocks.WPF.csproj | 76 ++++++- .../ViewModels/HotkeysViewModel.cs | 189 ------------------ Shadowsocks.WPF/Views/HotkeysView.xaml | 115 ----------- Shadowsocks.WPF/Views/HotkeysView.xaml.cs | 169 ---------------- Shadowsocks/Shadowsocks.csproj | 1 + appveyor.yml | 25 ++- shadowsocks-csharp/shadowsocks-csharp.csproj | 12 +- 17 files changed, 337 insertions(+), 1023 deletions(-) delete mode 100644 Shadowsocks.WPF/Behaviors/HotkeyReg.cs delete mode 100644 Shadowsocks.WPF/Behaviors/Hotkeys/HotkeyCallbacks.cs delete mode 100644 Shadowsocks.WPF/Behaviors/Hotkeys/Hotkeys.cs delete mode 100644 Shadowsocks.WPF/Behaviors/LoggerExtension.cs create mode 100644 Shadowsocks.WPF/Properties/Resources.Designer.cs create mode 100644 Shadowsocks.WPF/Properties/Resources.resx delete mode 100644 Shadowsocks.WPF/ViewModels/HotkeysViewModel.cs delete mode 100644 Shadowsocks.WPF/Views/HotkeysView.xaml delete mode 100644 Shadowsocks.WPF/Views/HotkeysView.xaml.cs diff --git a/Shadowsocks.PAC/GeositeUpdater.cs b/Shadowsocks.PAC/GeositeUpdater.cs index e1de829a..75400e89 100644 --- a/Shadowsocks.PAC/GeositeUpdater.cs +++ b/Shadowsocks.PAC/GeositeUpdater.cs @@ -23,9 +23,9 @@ namespace Shadowsocks.PAC public class GeositeUpdater : IEnableLogger { - public event EventHandler UpdateCompleted; + public event EventHandler? UpdateCompleted; - public event ErrorEventHandler Error; + public event ErrorEventHandler? Error; private readonly string DATABASE_PATH; @@ -230,7 +230,7 @@ var __RULES__ = {JsonSerializer.Serialize(ruleLines, jsonSerializerOptions)}; List valid_lines = new List(); using (var stringReader = new StringReader(content)) { - for (string line = stringReader.ReadLine(); line != null; line = stringReader.ReadLine()) + for (string? line = stringReader.ReadLine(); line != null; line = stringReader.ReadLine()) { if (string.IsNullOrWhiteSpace(line) || line.StartsWith("!") || line.StartsWith("[")) continue; diff --git a/Shadowsocks.PAC/PACServer.cs b/Shadowsocks.PAC/PACServer.cs index 4e8696d4..79c5b3f7 100644 --- a/Shadowsocks.PAC/PACServer.cs +++ b/Shadowsocks.PAC/PACServer.cs @@ -189,13 +189,14 @@ Connection: Close private void SendCallback(IAsyncResult ar) { - Socket conn = (Socket)ar.AsyncState; + Socket? conn = ar.AsyncState as Socket; try { - conn.Shutdown(SocketShutdown.Send); + conn?.Shutdown(SocketShutdown.Send); } catch - { } + { + } } private string GetPACAddress(IPEndPoint localEndPoint, bool useSocks) => $"{(useSocks ? "SOCKS5" : "PROXY")} {localEndPoint};"; diff --git a/Shadowsocks.PAC/Shadowsocks.PAC.csproj b/Shadowsocks.PAC/Shadowsocks.PAC.csproj index 9531d781..24d46a25 100644 --- a/Shadowsocks.PAC/Shadowsocks.PAC.csproj +++ b/Shadowsocks.PAC/Shadowsocks.PAC.csproj @@ -2,6 +2,7 @@ netcoreapp3.1 + enable diff --git a/Shadowsocks.WPF/Behaviors/HotkeyReg.cs b/Shadowsocks.WPF/Behaviors/HotkeyReg.cs deleted file mode 100644 index 7611ee16..00000000 --- a/Shadowsocks.WPF/Behaviors/HotkeyReg.cs +++ /dev/null @@ -1,91 +0,0 @@ -using NLog; -using Shadowsocks.Controller.Hotkeys; -using System; -using System.Windows.Forms; - -namespace Shadowsocks.WPF.Behaviors -{ - static class HotkeyReg - { - private static Logger logger = LogManager.GetCurrentClassLogger(); - public static void RegAllHotkeys() - { - var hotkeyConfig = Program.MainController.GetCurrentConfiguration().hotkey; - - if (hotkeyConfig == null || !hotkeyConfig.RegHotkeysAtStartup) - return; - - // if any of the hotkey reg fail, undo everything - if (RegHotkeyFromString(hotkeyConfig.SwitchSystemProxy, "SwitchSystemProxyCallback") - && RegHotkeyFromString(hotkeyConfig.SwitchSystemProxyMode, "SwitchSystemProxyModeCallback") - && RegHotkeyFromString(hotkeyConfig.SwitchAllowLan, "SwitchAllowLanCallback") - && RegHotkeyFromString(hotkeyConfig.ShowLogs, "ShowLogsCallback") - && RegHotkeyFromString(hotkeyConfig.ServerMoveUp, "ServerMoveUpCallback") - && RegHotkeyFromString(hotkeyConfig.ServerMoveDown, "ServerMoveDownCallback") - ) - { - // success - } - else - { - RegHotkeyFromString("", "SwitchSystemProxyCallback"); - RegHotkeyFromString("", "SwitchSystemProxyModeCallback"); - RegHotkeyFromString("", "SwitchAllowLanCallback"); - RegHotkeyFromString("", "ShowLogsCallback"); - RegHotkeyFromString("", "ServerMoveUpCallback"); - RegHotkeyFromString("", "ServerMoveDownCallback"); - MessageBox.Show(I18N.GetString("Register hotkey failed"), I18N.GetString("Shadowsocks")); - } - } - - public static bool RegHotkeyFromString(string hotkeyStr, string callbackName, Action onComplete = null) - { - var _callback = HotkeyCallbacks.GetCallback(callbackName); - if (_callback == null) - { - throw new Exception($"{callbackName} not found"); - } - - var callback = _callback as HotKeys.HotKeyCallBackHandler; - - if (string.IsNullOrEmpty(hotkeyStr)) - { - HotKeys.UnregExistingHotkey(callback); - onComplete?.Invoke(RegResult.UnregSuccess); - return true; - } - else - { - var hotkey = HotKeys.Str2HotKey(hotkeyStr); - if (hotkey == null) - { - logger.Error($"Cannot parse hotkey: {hotkeyStr}"); - onComplete?.Invoke(RegResult.ParseError); - return false; - } - else - { - bool regResult = (HotKeys.RegHotkey(hotkey, callback)); - if (regResult) - { - onComplete?.Invoke(RegResult.RegSuccess); - } - else - { - onComplete?.Invoke(RegResult.RegFailure); - } - return regResult; - } - } - } - - public enum RegResult - { - RegSuccess, - RegFailure, - ParseError, - UnregSuccess, - //UnregFailure - } - } -} diff --git a/Shadowsocks.WPF/Behaviors/Hotkeys/HotkeyCallbacks.cs b/Shadowsocks.WPF/Behaviors/Hotkeys/HotkeyCallbacks.cs deleted file mode 100644 index 08f15836..00000000 --- a/Shadowsocks.WPF/Behaviors/Hotkeys/HotkeyCallbacks.cs +++ /dev/null @@ -1,114 +0,0 @@ -using System; -using System.Reflection; - -namespace Shadowsocks.Controller.Hotkeys -{ - public class HotkeyCallbacks - { - - public static void InitInstance(ShadowsocksController controller) - { - if (Instance != null) - { - return; - } - - Instance = new HotkeyCallbacks(controller); - } - - /// - /// Create hotkey callback handler delegate based on callback name - /// - /// - /// - public static Delegate GetCallback(string methodname) - { - if (string.IsNullOrEmpty(methodname)) throw new ArgumentException(nameof(methodname)); - MethodInfo dynMethod = typeof(HotkeyCallbacks).GetMethod(methodname, - BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreCase); - return dynMethod == null ? null : Delegate.CreateDelegate(typeof(HotKeys.HotKeyCallBackHandler), Instance, dynMethod); - } - - #region Singleton - - private static HotkeyCallbacks Instance { get; set; } - - private readonly ShadowsocksController _controller; - - private HotkeyCallbacks(ShadowsocksController controller) - { - _controller = controller; - } - - #endregion - - #region Callbacks - - private void SwitchSystemProxyCallback() - { - bool enabled = _controller.GetCurrentConfiguration().enabled; - _controller.ToggleEnable(!enabled); - } - - private void SwitchSystemProxyModeCallback() - { - var config = _controller.GetCurrentConfiguration(); - if (config.enabled) - _controller.ToggleGlobal(!config.global); - } - - private void SwitchAllowLanCallback() - { - var status = _controller.GetCurrentConfiguration().shareOverLan; - _controller.ToggleShareOverLAN(!status); - } - - private void ShowLogsCallback() - { - Program.MenuController.ShowLogForm_HotKey(); - } - - private void ServerMoveUpCallback() - { - int currIndex; - int serverCount; - GetCurrServerInfo(out currIndex, out serverCount); - if (currIndex - 1 < 0) - { - // revert to last server - currIndex = serverCount - 1; - } - else - { - currIndex -= 1; - } - _controller.SelectServerIndex(currIndex); - } - - private void ServerMoveDownCallback() - { - int currIndex; - int serverCount; - GetCurrServerInfo(out currIndex, out serverCount); - if (currIndex + 1 == serverCount) - { - // revert to first server - currIndex = 0; - } - else - { - currIndex += 1; - } - _controller.SelectServerIndex(currIndex); - } - - private void GetCurrServerInfo(out int currIndex, out int serverCount) - { - var currConfig = _controller.GetCurrentConfiguration(); - currIndex = currConfig.index; - serverCount = currConfig.configs.Count; - } - - #endregion - } -} diff --git a/Shadowsocks.WPF/Behaviors/Hotkeys/Hotkeys.cs b/Shadowsocks.WPF/Behaviors/Hotkeys/Hotkeys.cs deleted file mode 100644 index a55591ef..00000000 --- a/Shadowsocks.WPF/Behaviors/Hotkeys/Hotkeys.cs +++ /dev/null @@ -1,174 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Windows.Input; -using GlobalHotKey; - -namespace Shadowsocks.Controller.Hotkeys -{ - public static class HotKeys - { - private static HotKeyManager _hotKeyManager; - - public delegate void HotKeyCallBackHandler(); - // map key and corresponding handler function - private static Dictionary _keymap = new Dictionary(); - - public static void Init(ShadowsocksController controller) - { - _hotKeyManager = new HotKeyManager(); - _hotKeyManager.KeyPressed += HotKeyManagerPressed; - - HotkeyCallbacks.InitInstance(controller); - } - - public static void Destroy() - { - _hotKeyManager.KeyPressed -= HotKeyManagerPressed; - _hotKeyManager.Dispose(); - } - - private static void HotKeyManagerPressed(object sender, KeyPressedEventArgs e) - { - var hotkey = e.HotKey; - HotKeyCallBackHandler callback; - if (_keymap.TryGetValue(hotkey, out callback)) - callback(); - } - - public static bool RegHotkey(HotKey hotkey, HotKeyCallBackHandler callback) - { - UnregExistingHotkey(callback); - return Register(hotkey, callback); - } - - public static bool UnregExistingHotkey(HotKeys.HotKeyCallBackHandler cb) - { - HotKey existingHotKey; - if (IsCallbackExists(cb, out existingHotKey)) - { - // unregister existing one - Unregister(existingHotKey); - return true; - } - else - { - return false; - } - } - - public static bool IsHotkeyExists( HotKey hotKey ) - { - if (hotKey == null) throw new ArgumentNullException(nameof(hotKey)); - return _keymap.Any( v => v.Key.Equals( hotKey ) ); - } - - public static bool IsCallbackExists( HotKeyCallBackHandler cb, out HotKey hotkey) - { - if (cb == null) throw new ArgumentNullException(nameof(cb)); - if (_keymap.Any(v => v.Value == cb)) - { - hotkey = _keymap.First(v => v.Value == cb).Key; - return true; - } - else - { - hotkey = null; - return false; - } - } - - #region Converters - - public static string HotKey2Str( HotKey key ) - { - if (key == null) throw new ArgumentNullException(nameof(key)); - return HotKey2Str( key.Key, key.Modifiers ); - } - - public static string HotKey2Str( Key key, ModifierKeys modifier ) - { - if (!Enum.IsDefined(typeof(Key), key)) - throw new InvalidEnumArgumentException(nameof(key), (int) key, typeof(Key)); - try - { - ModifierKeysConverter mkc = new ModifierKeysConverter(); - var keyStr = Enum.GetName(typeof(Key), key); - var modifierStr = mkc.ConvertToInvariantString(modifier); - - return $"{modifierStr}+{keyStr}"; - } - catch (NotSupportedException) - { - // converter exception - return null; - } - } - - public static HotKey Str2HotKey(string s) - { - try - { - if (string.IsNullOrEmpty(s)) return null; - int offset = s.LastIndexOf("+", StringComparison.OrdinalIgnoreCase); - if (offset <= 0) return null; - string modifierStr = s.Substring(0, offset).Trim(); - string keyStr = s.Substring(offset + 1).Trim(); - - KeyConverter kc = new KeyConverter(); - ModifierKeysConverter mkc = new ModifierKeysConverter(); - Key key = (Key) kc.ConvertFrom(keyStr.ToUpper()); - ModifierKeys modifier = (ModifierKeys) mkc.ConvertFrom(modifierStr.ToUpper()); - - return new HotKey(key, modifier); - } - catch (NotSupportedException) - { - // converter exception - return null; - } - catch (NullReferenceException) - { - return null; - } - } - - #endregion - - private static bool Register(HotKey key, HotKeyCallBackHandler callBack) - { - if (key == null) - throw new ArgumentNullException(nameof(key)); - if (callBack == null) - throw new ArgumentNullException(nameof(callBack)); - try - { - _hotKeyManager.Register(key); - _keymap[key] = callBack; - return true; - } - catch (ArgumentException) - { - // already called this method with the specific hotkey - // return success silently - return true; - } - catch (Win32Exception) - { - // this hotkey already registered by other programs - // notify user to change key - return false; - } - } - - private static void Unregister(HotKey key) - { - if (key == null) - throw new ArgumentNullException(nameof(key)); - _hotKeyManager.Unregister(key); - if(_keymap.ContainsKey(key)) - _keymap.Remove(key); - } - } -} \ No newline at end of file diff --git a/Shadowsocks.WPF/Behaviors/LoggerExtension.cs b/Shadowsocks.WPF/Behaviors/LoggerExtension.cs deleted file mode 100644 index 3f2c99aa..00000000 --- a/Shadowsocks.WPF/Behaviors/LoggerExtension.cs +++ /dev/null @@ -1,143 +0,0 @@ -using Shadowsocks.Net.SystemProxy; - -using System; -using System.ComponentModel; -using System.Net; -using System.Net.Sockets; - -namespace NLog -{ - public static class LoggerExtension - { - // for key, iv, etc... - public static void Dump(this Logger logger, string tag, ReadOnlySpan arr) - { - logger.Dump(tag, arr.ToArray(), arr.Length); - } - public static void Dump(this Logger logger, string tag, byte[] arr, int length = -1) - { - if (arr == null) logger.Trace($@" -{tag}: -(null) - -"); - if (length == -1) length = arr.Length; - - if (!logger.IsTraceEnabled) return; - string hex = BitConverter.ToString(arr.AsSpan(0, Math.Min(arr.Length, length)).ToArray()).Replace("-", ""); - string content = $@" -{tag}: -{hex} - -"; - logger.Trace(content); - } - // for cipher and plain text, so we can use openssl to test - public static void DumpBase64(this Logger logger, string tag, ReadOnlySpan arr) - { - logger.DumpBase64(tag, arr.ToArray(), arr.Length); - } - public static void DumpBase64(this Logger logger, string tag, byte[] arr, int length = -1) - { - if (arr == null) logger.Trace($@" -{tag}: -(null) - -"); - if (length == -1) length = arr.Length; - - if (!logger.IsTraceEnabled) return; - string hex = Convert.ToBase64String(arr.AsSpan(0, Math.Min(arr.Length, length)).ToArray()); - string content = $@" -{tag}: -{hex} - -"; - logger.Trace(content); - } - - public static void Debug(this Logger logger, EndPoint local, EndPoint remote, int len, string header = null, string tailer = null) - { - if (logger.IsDebugEnabled) - { - if (header == null && tailer == null) - logger.Debug($"{local} => {remote} (size={len})"); - else if (header == null && tailer != null) - logger.Debug($"{local} => {remote} (size={len}), {tailer}"); - else if (header != null && tailer == null) - logger.Debug($"{header}: {local} => {remote} (size={len})"); - else - logger.Debug($"{header}: {local} => {remote} (size={len}), {tailer}"); - } - } - - public static void Debug(this Logger logger, Socket sock, int len, string header = null, string tailer = null) - { - if (logger.IsDebugEnabled) - logger.Debug(sock.LocalEndPoint, sock.RemoteEndPoint, len, header, tailer); - - } - - public static void LogUsefulException(this Logger logger, Exception e) - { - // just log useful exceptions, not all of them - if (e is SocketException se) - { - if (se.SocketErrorCode == SocketError.ConnectionAborted) - { - // closed by browser when sending - // normally happens when download is canceled or a tab is closed before page is loaded - } - else if (se.SocketErrorCode == SocketError.ConnectionReset) - { - // received rst - } - else if (se.SocketErrorCode == SocketError.NotConnected) - { - // The application tried to send or receive data, and the System.Net.Sockets.Socket is not connected. - } - else if (se.SocketErrorCode == SocketError.HostUnreachable) - { - // There is no network route to the specified host. - } - else if (se.SocketErrorCode == SocketError.TimedOut) - { - // The connection attempt timed out, or the connected host has failed to respond. - } - else - { - logger.Warn(e); - } - } - else if (e is ObjectDisposedException) - { - } - else if (e is Win32Exception ex) - { - // Win32Exception (0x80004005): A 32 bit processes cannot access modules of a 64 bit process. - if ((uint)ex.ErrorCode != 0x80004005) - logger.Warn(e); - - } - else if (e is ProxyException pe) - { - switch (pe.Type) - { - case ProxyExceptionType.FailToRun: - case ProxyExceptionType.QueryReturnMalformed: - case ProxyExceptionType.SysproxyExitError: - logger.Error($"sysproxy - {pe.Type}:{pe.Message}"); - break; - case ProxyExceptionType.QueryReturnEmpty: - case ProxyExceptionType.Unspecific: - logger.Error($"sysproxy - {pe.Type}"); - break; - } - } - else - { - logger.Warn(e); - } - } - } -} diff --git a/Shadowsocks.WPF/Properties/PublishProfiles/FolderProfile.pubxml b/Shadowsocks.WPF/Properties/PublishProfiles/FolderProfile.pubxml index da619e3e..b2b41941 100644 --- a/Shadowsocks.WPF/Properties/PublishProfiles/FolderProfile.pubxml +++ b/Shadowsocks.WPF/Properties/PublishProfiles/FolderProfile.pubxml @@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121. --> - Debug + Release Any CPU bin\Release\netcoreapp3.1\publish\ FileSystem diff --git a/Shadowsocks.WPF/Properties/Resources.Designer.cs b/Shadowsocks.WPF/Properties/Resources.Designer.cs new file mode 100644 index 00000000..839e0ab0 --- /dev/null +++ b/Shadowsocks.WPF/Properties/Resources.Designer.cs @@ -0,0 +1,105 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Shadowsocks.WPF.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Shadowsocks.WPF.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to <?xml version="1.0" encoding="utf-8" ?> + ///<!-- Warning: Configuration may reset after shadowsocks upgrade. --> + ///<!-- If you messed it up, delete this file and Shadowsocks will create a new one. --> + ///<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + /// <targets> + /// <!-- This line is managed by Shadowsocks. Do not modify it unless you know what you are doing.--> + /// <target name="file" xsi:type="File" fileName="ss_win_temp\shadowsocks [rest of string was truncated]";. + /// + internal static string NLog { + get { + return ResourceManager.GetString("NLog", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to listen-address __PRIVOXY_BIND_IP__:__PRIVOXY_BIND_PORT__ + ///toggle 0 + ///logfile ss_privoxy.log + ///show-on-task-bar 0 + ///activity-animation 0 + ///forward-socks5 / __SOCKS_HOST__:__SOCKS_PORT__ . + ///max-client-connections 2048 + ///hide-console + ///. + /// + internal static string privoxy_conf { + get { + return ResourceManager.GetString("privoxy_conf", resourceCulture); + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] privoxy_exe { + get { + object obj = ResourceManager.GetObject("privoxy_exe", resourceCulture); + return ((byte[])(obj)); + } + } + } +} diff --git a/Shadowsocks.WPF/Properties/Resources.resx b/Shadowsocks.WPF/Properties/Resources.resx new file mode 100644 index 00000000..63ba1758 --- /dev/null +++ b/Shadowsocks.WPF/Properties/Resources.resx @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\NLog.config;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + + ..\Resources\privoxy_conf.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + + ..\Resources\privoxy.exe.gz;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Shadowsocks.WPF/Shadowsocks.WPF.csproj b/Shadowsocks.WPF/Shadowsocks.WPF.csproj index ad7152f3..4c7342d0 100644 --- a/Shadowsocks.WPF/Shadowsocks.WPF.csproj +++ b/Shadowsocks.WPF/Shadowsocks.WPF.csproj @@ -11,15 +11,46 @@ 1.0.0 Assets\shadowsocks.ico true + enable + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + + @@ -31,6 +62,11 @@ True Strings.resx + + True + True + Resources.resx + @@ -38,15 +74,43 @@ ResXFileCodeGenerator Strings.Designer.cs + + ResXFileCodeGenerator + Resources.Designer.cs + - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Shadowsocks.WPF/ViewModels/HotkeysViewModel.cs b/Shadowsocks.WPF/ViewModels/HotkeysViewModel.cs deleted file mode 100644 index fd10fb9b..00000000 --- a/Shadowsocks.WPF/ViewModels/HotkeysViewModel.cs +++ /dev/null @@ -1,189 +0,0 @@ -using ReactiveUI; -using ReactiveUI.Fody.Helpers; -using Shadowsocks.Controller; -using Shadowsocks.Model; -using Shadowsocks.View; -using System.Reactive; -using System.Text; -using System.Windows.Input; - -namespace Shadowsocks.WPF.ViewModels -{ - public class HotkeysViewModel : ReactiveObject - { - public HotkeysViewModel() - { - _config = Program.MainController.GetCurrentConfiguration(); - _controller = Program.MainController; - _menuViewController = Program.MenuController; - - HotkeySystemProxy = _config.hotkey.SwitchSystemProxy; - HotkeyProxyMode = _config.hotkey.SwitchSystemProxyMode; - HotkeyAllowLan = _config.hotkey.SwitchAllowLan; - HotkeyOpenLogs = _config.hotkey.ShowLogs; - HotkeySwitchPrev = _config.hotkey.ServerMoveUp; - HotkeySwitchNext = _config.hotkey.ServerMoveDown; - RegisterAtStartup = _config.hotkey.RegHotkeysAtStartup; - - HotkeySystemProxyStatus = "✔"; - HotkeyProxyModeStatus = "✔"; - HotkeyAllowLanStatus = "✔"; - HotkeyOpenLogsStatus = "✔"; - HotkeySwitchPrevStatus = "✔"; - HotkeySwitchNextStatus = "✔"; - - RegisterAll = ReactiveCommand.Create(() => RegisterAllAndUpdateStatus()); - Save = ReactiveCommand.Create(() => RegisterAllAndUpdateStatus(true)); - Cancel = ReactiveCommand.Create(_menuViewController.CloseHotkeysWindow); - } - - private readonly Configuration _config; - private readonly ShadowsocksController _controller; - private readonly MenuViewController _menuViewController; - - public ReactiveCommand RegisterAll { get; } - public ReactiveCommand Save { get; } - public ReactiveCommand Cancel { get; } - - [Reactive] - public string HotkeySystemProxy { get; set; } - - [Reactive] - public string HotkeyProxyMode { get; set; } - - [Reactive] - public string HotkeyAllowLan { get; set; } - - [Reactive] - public string HotkeyOpenLogs { get; set; } - - [Reactive] - public string HotkeySwitchPrev { get; set; } - - [Reactive] - public string HotkeySwitchNext { get; set; } - - [Reactive] - public bool RegisterAtStartup { get; set; } - - [Reactive] - public string HotkeySystemProxyStatus { get; set; } - - [Reactive] - public string HotkeyProxyModeStatus { get; set; } - - [Reactive] - public string HotkeyAllowLanStatus { get; set; } - - [Reactive] - public string HotkeyOpenLogsStatus { get; set; } - - [Reactive] - public string HotkeySwitchPrevStatus { get; set; } - - [Reactive] - public string HotkeySwitchNextStatus { get; set; } - - public void RecordKeyDown(int hotkeyIndex, KeyEventArgs keyEventArgs) - { - var recordedKeyStringBuilder = new StringBuilder(); - - // record modifiers - if ((Keyboard.Modifiers & ModifierKeys.Control) > 0) - recordedKeyStringBuilder.Append("Ctrl+"); - if ((Keyboard.Modifiers & ModifierKeys.Alt) > 0) - recordedKeyStringBuilder.Append("Alt+"); - if ((Keyboard.Modifiers & ModifierKeys.Shift) > 0) - recordedKeyStringBuilder.Append("Shift+"); - - // record other keys when at least one modifier is pressed - if (recordedKeyStringBuilder.Length > 0 && (keyEventArgs.Key < Key.LeftShift || keyEventArgs.Key > Key.RightAlt)) - recordedKeyStringBuilder.Append(keyEventArgs.Key); - - switch (hotkeyIndex) - { - case 0: - HotkeySystemProxy = recordedKeyStringBuilder.ToString(); - break; - case 1: - HotkeyProxyMode = recordedKeyStringBuilder.ToString(); - break; - case 2: - HotkeyAllowLan = recordedKeyStringBuilder.ToString(); - break; - case 3: - HotkeyOpenLogs = recordedKeyStringBuilder.ToString(); - break; - case 4: - HotkeySwitchPrev = recordedKeyStringBuilder.ToString(); - break; - case 5: - HotkeySwitchNext = recordedKeyStringBuilder.ToString(); - break; - } - } - - public void FinishOnKeyUp(int hotkeyIndex, KeyEventArgs keyEventArgs) - { - switch (hotkeyIndex) - { - case 0: - if (HotkeySystemProxy.EndsWith("+")) - HotkeySystemProxy = ""; - break; - case 1: - if (HotkeyProxyMode.EndsWith("+")) - HotkeyProxyMode = ""; - break; - case 2: - if (HotkeyAllowLan.EndsWith("+")) - HotkeyAllowLan = ""; - break; - case 3: - if (HotkeyOpenLogs.EndsWith("+")) - HotkeyOpenLogs = ""; - break; - case 4: - if (HotkeySwitchPrev.EndsWith("+")) - HotkeySwitchPrev = ""; - break; - case 5: - if (HotkeySwitchNext.EndsWith("+")) - HotkeySwitchNext = ""; - break; - } - } - - private void RegisterAllAndUpdateStatus(bool save = false) - { - HotkeySystemProxyStatus = HotkeyReg.RegHotkeyFromString(HotkeySystemProxy, "SwitchSystemProxyCallback") ? "✔" : "❌"; - HotkeyProxyModeStatus = HotkeyReg.RegHotkeyFromString(HotkeyProxyMode, "SwitchSystemProxyModeCallback") ? "✔" : "❌"; - HotkeyAllowLanStatus = HotkeyReg.RegHotkeyFromString(HotkeyAllowLan, "SwitchAllowLanCallback") ? "✔" : "❌"; - HotkeyOpenLogsStatus = HotkeyReg.RegHotkeyFromString(HotkeyOpenLogs, "ShowLogsCallback") ? "✔" : "❌"; - HotkeySwitchPrevStatus = HotkeyReg.RegHotkeyFromString(HotkeySwitchPrev, "ServerMoveUpCallback") ? "✔" : "❌"; - HotkeySwitchNextStatus = HotkeyReg.RegHotkeyFromString(HotkeySwitchNext, "ServerMoveDownCallback") ? "✔" : "❌"; - - if (HotkeySystemProxyStatus == "✔" && - HotkeyProxyModeStatus == "✔" && - HotkeyAllowLanStatus == "✔" && - HotkeyOpenLogsStatus == "✔" && - HotkeySwitchPrevStatus == "✔" && - HotkeySwitchNextStatus == "✔" && save) - { - _controller.SaveHotkeyConfig(GetHotkeyConfig); - _menuViewController.CloseHotkeysWindow(); - } - } - - private HotkeyConfig GetHotkeyConfig => new HotkeyConfig() - { - SwitchSystemProxy = HotkeySystemProxy, - SwitchSystemProxyMode = HotkeyProxyMode, - SwitchAllowLan = HotkeyAllowLan, - ShowLogs = HotkeyOpenLogs, - ServerMoveUp = HotkeySwitchPrev, - ServerMoveDown = HotkeySwitchNext, - RegHotkeysAtStartup = RegisterAtStartup - }; - } -} diff --git a/Shadowsocks.WPF/Views/HotkeysView.xaml b/Shadowsocks.WPF/Views/HotkeysView.xaml deleted file mode 100644 index a01d5f83..00000000 --- a/Shadowsocks.WPF/Views/HotkeysView.xaml +++ /dev/null @@ -1,115 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -