@@ -359,6 +359,7 @@ namespace Shadowsocks.Controller | |||
public void SaveLogViewerConfig(LogViewerConfig newConfig) | |||
{ | |||
_config.logViewer = newConfig; | |||
newConfig.SaveSize(); | |||
Configuration.Save(_config); | |||
if (ConfigChanged != null) | |||
{ | |||
@@ -65,10 +65,8 @@ namespace Shadowsocks.Model | |||
if (config.hotkey == null) | |||
config.hotkey = new HotkeyConfig(); | |||
if (config.proxy.proxyType < ProxyConfig.PROXY_SOCKS5 || config.proxy.proxyType > ProxyConfig.PROXY_HTTP) | |||
{ | |||
config.proxy.proxyType = ProxyConfig.PROXY_SOCKS5; | |||
} | |||
config.proxy.CheckConfig(); | |||
return config; | |||
} | |||
catch (Exception e) | |||
@@ -1,105 +1,94 @@ | |||
using Shadowsocks.View; | |||
using System; | |||
using System; | |||
using System.Drawing; | |||
using System.Windows.Forms; | |||
using Newtonsoft.Json; | |||
namespace Shadowsocks.Model | |||
{ | |||
[Serializable] | |||
public class LogViewerConfig | |||
{ | |||
public string fontName; | |||
public float fontSize; | |||
public string bgColor; | |||
public string textColor; | |||
public bool topMost; | |||
public bool wrapText; | |||
public bool toolbarShown; | |||
public int width; | |||
public int height; | |||
public int top; | |||
public int left; | |||
public bool maximized; | |||
public Font Font { get; set; } = new Font("Console", 8F); | |||
public Color BackgroundColor { get; set; } = Color.Black; | |||
public Color TextColor { get; set; } = Color.White; | |||
public LogViewerConfig() | |||
{ | |||
fontName = "Consolas"; | |||
fontSize = 8; | |||
bgColor = "black"; | |||
textColor = "white"; | |||
topMost = false; | |||
wrapText = false; | |||
toolbarShown = false; | |||
width = 600; | |||
height = 400; | |||
left = GetBestLeft(); | |||
top = GetBestTop(); | |||
maximized = true; | |||
} | |||
// Use GetBestTop() and GetBestLeft() to ensure the log viwer form can be always display IN screen. | |||
public int GetBestLeft() | |||
#region Size | |||
public void SaveSize() | |||
{ | |||
width = (width >= 400) ? width : 400; // set up the minimum size | |||
return Screen.PrimaryScreen.WorkingArea.Width - width; | |||
Properties.Settings.Default.Save(); | |||
} | |||
public int GetBestTop() | |||
[JsonIgnore] | |||
public int Width | |||
{ | |||
height = (height >= 200) ? height : 200; // set up the minimum size | |||
return Screen.PrimaryScreen.WorkingArea.Height - height; | |||
get { return Properties.Settings.Default.LogViewerWidth; } | |||
set { Properties.Settings.Default.LogViewerWidth = value; } | |||
} | |||
public Font GetFont() | |||
[JsonIgnore] | |||
public int Height | |||
{ | |||
try | |||
{ | |||
return new Font(fontName, fontSize, FontStyle.Regular); | |||
} | |||
catch (Exception) | |||
{ | |||
return new Font("Console", 8F); | |||
} | |||
get { return Properties.Settings.Default.LogViewerHeight; } | |||
set { Properties.Settings.Default.LogViewerHeight = value; } | |||
} | |||
public void SetFont(Font font) | |||
[JsonIgnore] | |||
public int Top | |||
{ | |||
fontName = font.Name; | |||
fontSize = font.Size; | |||
get { return Properties.Settings.Default.LogViewerTop; } | |||
set { Properties.Settings.Default.LogViewerTop = value; } | |||
} | |||
public Color GetBackgroundColor() | |||
[JsonIgnore] | |||
public int Left | |||
{ | |||
try | |||
{ | |||
return ColorTranslator.FromHtml(bgColor); | |||
} | |||
catch (Exception) | |||
{ | |||
return ColorTranslator.FromHtml("black"); | |||
} | |||
get { return Properties.Settings.Default.LogViewerLeft; } | |||
set { Properties.Settings.Default.LogViewerLeft = value; } | |||
} | |||
public void SetBackgroundColor(Color color) | |||
[JsonIgnore] | |||
public bool Maximized | |||
{ | |||
bgColor = ColorTranslator.ToHtml(color); | |||
get { return Properties.Settings.Default.LogViewerMaximized; } | |||
set { Properties.Settings.Default.LogViewerMaximized = value; } | |||
} | |||
public Color GetTextColor() | |||
[JsonIgnore] | |||
// Use GetBestTop() and GetBestLeft() to ensure the log viwer form can be always display IN screen. | |||
public int BestLeft | |||
{ | |||
try | |||
get | |||
{ | |||
return ColorTranslator.FromHtml(textColor); | |||
} | |||
catch (Exception) | |||
{ | |||
return ColorTranslator.FromHtml("white"); | |||
int width = Width; | |||
width = (width >= 400) ? width : 400; // set up the minimum size | |||
return Screen.PrimaryScreen.WorkingArea.Width - width; | |||
} | |||
} | |||
public void SetTextColor(Color color) | |||
[JsonIgnore] | |||
public int BestTop | |||
{ | |||
textColor = ColorTranslator.ToHtml(color); | |||
get | |||
{ | |||
int height = Height; | |||
height = (height >= 200) ? height : 200; // set up the minimum size | |||
return Screen.PrimaryScreen.WorkingArea.Height - height; | |||
} | |||
} | |||
#endregion | |||
} | |||
} |
@@ -25,5 +25,13 @@ namespace Shadowsocks.Model | |||
proxyPort = 0; | |||
proxyTimeout = DefaultProxyTimeoutSec; | |||
} | |||
public void CheckConfig() | |||
{ | |||
if (proxyType < PROXY_SOCKS5 || proxyType > PROXY_HTTP) | |||
{ | |||
proxyType = PROXY_SOCKS5; | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,86 @@ | |||
//------------------------------------------------------------------------------ | |||
// <auto-generated> | |||
// 此代码由工具生成。 | |||
// 运行时版本:4.0.30319.42000 | |||
// | |||
// 对此文件的更改可能会导致不正确的行为,并且如果 | |||
// 重新生成代码,这些更改将会丢失。 | |||
// </auto-generated> | |||
//------------------------------------------------------------------------------ | |||
namespace Shadowsocks.Properties { | |||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] | |||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] | |||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { | |||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); | |||
public static Settings Default { | |||
get { | |||
return defaultInstance; | |||
} | |||
} | |||
[global::System.Configuration.UserScopedSettingAttribute()] | |||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] | |||
[global::System.Configuration.DefaultSettingValueAttribute("600")] | |||
public int LogViewerWidth { | |||
get { | |||
return ((int)(this["LogViewerWidth"])); | |||
} | |||
set { | |||
this["LogViewerWidth"] = value; | |||
} | |||
} | |||
[global::System.Configuration.UserScopedSettingAttribute()] | |||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] | |||
[global::System.Configuration.DefaultSettingValueAttribute("400")] | |||
public int LogViewerHeight { | |||
get { | |||
return ((int)(this["LogViewerHeight"])); | |||
} | |||
set { | |||
this["LogViewerHeight"] = value; | |||
} | |||
} | |||
[global::System.Configuration.UserScopedSettingAttribute()] | |||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] | |||
[global::System.Configuration.DefaultSettingValueAttribute("True")] | |||
public bool LogViewerMaximized { | |||
get { | |||
return ((bool)(this["LogViewerMaximized"])); | |||
} | |||
set { | |||
this["LogViewerMaximized"] = value; | |||
} | |||
} | |||
[global::System.Configuration.UserScopedSettingAttribute()] | |||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] | |||
[global::System.Configuration.DefaultSettingValueAttribute("0")] | |||
public int LogViewerTop { | |||
get { | |||
return ((int)(this["LogViewerTop"])); | |||
} | |||
set { | |||
this["LogViewerTop"] = value; | |||
} | |||
} | |||
[global::System.Configuration.UserScopedSettingAttribute()] | |||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] | |||
[global::System.Configuration.DefaultSettingValueAttribute("0")] | |||
public int LogViewerLeft { | |||
get { | |||
return ((int)(this["LogViewerLeft"])); | |||
} | |||
set { | |||
this["LogViewerLeft"] = value; | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,21 @@ | |||
<?xml version='1.0' encoding='utf-8'?> | |||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="Shadowsocks.Properties" GeneratedClassName="Settings"> | |||
<Profiles /> | |||
<Settings> | |||
<Setting Name="LogViewerWidth" Type="System.Int32" Scope="User"> | |||
<Value Profile="(Default)">600</Value> | |||
</Setting> | |||
<Setting Name="LogViewerHeight" Type="System.Int32" Scope="User"> | |||
<Value Profile="(Default)">400</Value> | |||
</Setting> | |||
<Setting Name="LogViewerMaximized" Type="System.Boolean" Scope="User"> | |||
<Value Profile="(Default)">True</Value> | |||
</Setting> | |||
<Setting Name="LogViewerTop" Type="System.Int32" Scope="User"> | |||
<Value Profile="(Default)">0</Value> | |||
</Setting> | |||
<Setting Name="LogViewerLeft" Type="System.Int32" Scope="User"> | |||
<Value Profile="(Default)">0</Value> | |||
</Setting> | |||
</Settings> | |||
</SettingsFile> |
@@ -0,0 +1,28 @@ | |||
namespace Shadowsocks.Properties { | |||
// 通过此类可以处理设置类的特定事件: | |||
// 在更改某个设置的值之前将引发 SettingChanging 事件。 | |||
// 在更改某个设置的值之后将引发 PropertyChanged 事件。 | |||
// 在加载设置值之后将引发 SettingsLoaded 事件。 | |||
// 在保存设置值之前将引发 SettingsSaving 事件。 | |||
internal sealed partial class Settings { | |||
public Settings() { | |||
// // 若要为保存和更改设置添加事件处理程序,请取消注释下列行: | |||
// | |||
// this.SettingChanging += this.SettingChangingEventHandler; | |||
// | |||
// this.SettingsSaving += this.SettingsSavingEventHandler; | |||
// | |||
} | |||
private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) { | |||
// 在此处添加用于处理 SettingChangingEvent 事件的代码。 | |||
} | |||
private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) { | |||
// 在此处添加用于处理 SettingsSaving 事件的代码。 | |||
} | |||
} | |||
} |
@@ -54,9 +54,9 @@ namespace Shadowsocks.View | |||
topMostTrigger = config.topMost; | |||
wrapTextTrigger = config.wrapText; | |||
toolbarTrigger = config.toolbarShown; | |||
LogMessageTextBox.BackColor = config.GetBackgroundColor(); | |||
LogMessageTextBox.ForeColor = config.GetTextColor(); | |||
LogMessageTextBox.Font = config.GetFont(); | |||
LogMessageTextBox.BackColor = config.BackgroundColor; | |||
LogMessageTextBox.ForeColor = config.TextColor; | |||
LogMessageTextBox.Font = config.Font; | |||
controller.TrafficChanged += controller_TrafficChanged; | |||
@@ -229,11 +229,11 @@ namespace Shadowsocks.View | |||
LogViewerConfig config = controller.GetConfigurationCopy().logViewer; | |||
Height = config.height; | |||
Width = config.width; | |||
Top = config.GetBestTop(); | |||
Left = config.GetBestLeft(); | |||
if (config.maximized) | |||
Height = config.Height; | |||
Width = config.Width; | |||
Top = config.BestTop; | |||
Left = config.BestLeft; | |||
if (config.Maximized) | |||
{ | |||
WindowState = FormWindowState.Maximized; | |||
} | |||
@@ -258,15 +258,15 @@ namespace Shadowsocks.View | |||
config.topMost = topMostTrigger; | |||
config.wrapText = wrapTextTrigger; | |||
config.toolbarShown = toolbarTrigger; | |||
config.SetFont(LogMessageTextBox.Font); | |||
config.SetBackgroundColor(LogMessageTextBox.BackColor); | |||
config.SetTextColor(LogMessageTextBox.ForeColor); | |||
if (WindowState != FormWindowState.Minimized && !(config.maximized = WindowState == FormWindowState.Maximized)) | |||
config.Font=LogMessageTextBox.Font; | |||
config.BackgroundColor=LogMessageTextBox.BackColor; | |||
config.TextColor=LogMessageTextBox.ForeColor; | |||
if (WindowState != FormWindowState.Minimized && !(config.Maximized = WindowState == FormWindowState.Maximized)) | |||
{ | |||
config.top = Top; | |||
config.left = Left; | |||
config.height = Height; | |||
config.width = Width; | |||
config.Top = Top; | |||
config.Left = Left; | |||
config.Height = Height; | |||
config.Width = Width; | |||
} | |||
controller.SaveLogViewerConfig(config); | |||
} | |||
@@ -1,5 +1,10 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<configuration> | |||
<configSections> | |||
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > | |||
<section name="Shadowsocks.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> | |||
</sectionGroup> | |||
</configSections> | |||
<startup> | |||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/> | |||
</startup> | |||
@@ -15,4 +20,23 @@ | |||
</dependentAssembly> | |||
</assemblyBinding> | |||
</runtime> | |||
<userSettings> | |||
<Shadowsocks.Properties.Settings> | |||
<setting name="LogViewerWidth" serializeAs="String"> | |||
<value>600</value> | |||
</setting> | |||
<setting name="LogViewerHeight" serializeAs="String"> | |||
<value>400</value> | |||
</setting> | |||
<setting name="LogViewerMaximized" serializeAs="String"> | |||
<value>True</value> | |||
</setting> | |||
<setting name="LogViewerTop" serializeAs="String"> | |||
<value>0</value> | |||
</setting> | |||
<setting name="LogViewerLeft" serializeAs="String"> | |||
<value>0</value> | |||
</setting> | |||
</Shadowsocks.Properties.Settings> | |||
</userSettings> | |||
</configuration> |
@@ -141,6 +141,11 @@ | |||
<Compile Include="3rd\zxing\WriterException.cs" /> | |||
<Compile Include="Model\HotKeyConfig.cs" /> | |||
<Compile Include="Model\ProxyConfig.cs" /> | |||
<Compile Include="Properties\Settings.Designer.cs"> | |||
<AutoGen>True</AutoGen> | |||
<DesignTimeSharedInput>True</DesignTimeSharedInput> | |||
<DependentUpon>Settings.settings</DependentUpon> | |||
</Compile> | |||
<Compile Include="Proxy\DirectConnect.cs" /> | |||
<Compile Include="Proxy\HttpProxy.cs" /> | |||
<Compile Include="Proxy\IProxy.cs" /> | |||
@@ -179,6 +184,7 @@ | |||
<Compile Include="Controller\Strategy\StrategyManager.cs" /> | |||
<Compile Include="Controller\Strategy\IStrategy.cs" /> | |||
<Compile Include="Proxy\Socks5Proxy.cs" /> | |||
<Compile Include="Settings.cs" /> | |||
<Compile Include="StringEx.cs" /> | |||
<Compile Include="Util\Hotkeys.cs" /> | |||
<Compile Include="Util\ProcessManagement\Job.cs" /> | |||
@@ -287,6 +293,10 @@ | |||
<ItemGroup> | |||
<None Include="packages.config" /> | |||
<None Include="Properties\DataSources\Shadowsocks.Model.StatisticsStrategyConfiguration.datasource" /> | |||
<None Include="Properties\Settings.settings"> | |||
<Generator>SettingsSingleFileGenerator</Generator> | |||
<LastGenOutput>Settings.Designer.cs</LastGenOutput> | |||
</None> | |||
<None Include="Resources\ss20.png" /> | |||
<None Include="Resources\ss16.png" /> | |||
<None Include="Resources\ss24.png" /> | |||