Skip to content

Commit

Permalink
✨添加语言设置
Browse files Browse the repository at this point in the history
🎨优化电源监听逻辑
  • Loading branch information
AmazingDM committed Jun 3, 2020
1 parent e7daef1 commit 9e8659a
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 50 deletions.
2 changes: 1 addition & 1 deletion Netch/Controllers/UpdateChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class UpdateChecker

public const string Name = @"Netch";
public const string Copyright = @"Copyright © 2019 - 2020";
public const string Version = @"1.4.8";
public const string Version = @"1.4.9";

public async void Check(bool notifyNoFound, bool isPreRelease)
{
Expand Down
28 changes: 15 additions & 13 deletions Netch/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,21 @@ public MainForm()
/// <param name="e"></param>
void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
{
switch (e.Mode)
//不对Netch命令等待状态的电源事件做任何处理
if (!State.Equals(Models.State.Waiting))
{
case PowerModes.Suspend://操作系统即将挂起
Logging.Info("操作系统即将挂起,自动停止===>" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
ControlFun();
break;
case PowerModes.Resume://操作系统即将从挂起状态继续
Logging.Info("操作系统即将从挂起状态继续,自动重启===>" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
ControlFun();
break;
switch (e.Mode)
{
case PowerModes.Suspend://操作系统即将挂起
Logging.Info("操作系统即将挂起,自动停止===>" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
ControlFun();
break;
case PowerModes.Resume://操作系统即将从挂起状态继续
Logging.Info("操作系统即将从挂起状态继续,自动重启===>" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
ControlFun();
break;
}

}
}
private void CheckUpdate()
Expand Down Expand Up @@ -336,9 +341,6 @@ private void ComboBox_DrawItem(object sender, DrawItemEventArgs e)

private void MainForm_Load(object sender, EventArgs e)
{
// 加载配置
Utils.Configuration.Load();

// 加载服务器
InitServer();

Expand Down Expand Up @@ -829,7 +831,7 @@ private void ControlButton_Click(object sender, EventArgs e)
}
public void ControlFun()
{
//聚焦到启动按钮,防止模式选择框变成蓝色:D
//聚焦到启动按钮,防止模式选择框变成蓝色:D,不过好像没啥用
ControlButton.Focus();
SaveConfigs();
if (State == Models.State.Waiting || State == Models.State.Stopped)
Expand Down
48 changes: 36 additions & 12 deletions Netch/Forms/SettingForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 47 additions & 2 deletions Netch/Forms/SettingForm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using System;
using Netch.Models.SSD;
using System;
using System.Globalization;
using System.IO;
using System.Net;
using System.Text;
using System.Windows.Forms;
using TaskScheduler;

Expand Down Expand Up @@ -101,6 +105,10 @@ private void SettingForm_Load(object sender, EventArgs e)
AclLabel.Text = Utils.i18N.Translate(AclLabel.Text);
AclAddr.Text = Global.Settings.ACL.ToString();

LanguageLabel.Text = Utils.i18N.Translate(LanguageLabel.Text);
LanguageComboBox.Items.AddRange(Utils.i18N.GetTranslateList().ToArray());
LanguageComboBox.SelectedItem = Global.Settings.Language;

if (Global.Settings.TUNTAP.DNS.Count > 0)
{
var dns = "";
Expand Down Expand Up @@ -160,7 +168,44 @@ private void ControlButton_Click(object sender, EventArgs e)
Global.Settings.MinimizeWhenStarted = MinimizeWhenStartedCheckBox.Checked;
Global.Settings.RunAtStartup = RunAtStartup.Checked;
Global.Settings.BootShadowsocksFromDLL = BootShadowsocksFromDLLCheckBox.Checked;
Global.Settings.Language = LanguageComboBox.SelectedItem.ToString();

// 加载系统语言
if (Global.Settings.Language.Equals("System"))
{
// 得到当前线程语言代码
var culture = CultureInfo.CurrentCulture.Name;

// 尝试加载内置中文语言
if (culture == "zh-CN")
{
// 加载语言
Utils.i18N.Load(Encoding.UTF8.GetString(Properties.Resources.zh_CN));
}

// 从外置文件中加载语言
if (File.Exists($"i18n\\{culture}"))
{
// 加载语言
Utils.i18N.Load(File.ReadAllText($"i18n\\{culture}"));
}
}

if (Global.Settings.Language.Equals("zh-CN"))
{
// 加载内置中文
Utils.i18N.Load(Encoding.UTF8.GetString(Properties.Resources.zh_CN));
}
else if (Global.Settings.Language.Equals("en-US"))
{
// 加载内置英文
Utils.i18N.Load(Global.Settings.Language);
}
else if (File.Exists($"i18n\\{Global.Settings.Language}"))
{
// 从外置文件中加载语言
Utils.i18N.Load(File.ReadAllText($"i18n\\{Global.Settings.Language}"));
}

// 开机自启判断
TaskSchedulerClass scheduler = new TaskSchedulerClass();
Expand Down Expand Up @@ -388,7 +433,7 @@ private void ControlButton_Click(object sender, EventArgs e)
Global.Settings.TUNTAP.UseFakeDNS = UseFakeDNSCheckBox.Checked;

Utils.Configuration.Save();
MessageBox.Show(Utils.i18N.Translate("Saved"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show(Utils.i18N.Translate("Saved. Modify some settings need to restart the software"), Utils.i18N.Translate("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
Close();
}
}
Expand Down
5 changes: 5 additions & 0 deletions Netch/Models/Setting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,10 @@ public class Setting
/// 是否使用DLL启动Shadowsocks
/// </summary>
public bool BootShadowsocksFromDLL = false;

/// <summary>
/// 语言设置
/// </summary>
public string Language = "System";
}
}
51 changes: 29 additions & 22 deletions Netch/Netch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,42 +49,49 @@ public static void Main(string[] args)
}
}

// 得到当前线程语言代码
var culture = CultureInfo.CurrentCulture.Name;
// 加载配置
Utils.Configuration.Load();

// 如果命令行参数只有一个,且传入有效语言代码,那么覆盖掉已得到的语言代码
if (args.Length == 1)
// 加载系统语言
if (Global.Settings.Language.Equals("System"))
{
try
// 得到当前线程语言代码
var culture = CultureInfo.CurrentCulture.Name;

// 尝试加载内置中文语言
if (culture == "zh-CN")
{
culture = CultureInfo.GetCultureInfo(args[0]).Name;
// 加载语言
Utils.i18N.Load(Encoding.UTF8.GetString(Properties.Resources.zh_CN));
}
catch (CultureNotFoundException)

// 从外置文件中加载语言
if (File.Exists($"i18n\\{culture}"))
{
// 跳过
// 加载语言
Utils.i18N.Load(File.ReadAllText($"i18n\\{culture}"));
}
}

// 记录当前系统语言
Utils.Logging.Info($"当前系统语言:{culture}");

// 尝试加载内置中文语言
if (culture == "zh-CN")
if (Global.Settings.Language.Equals("zh-CN"))
{
// 加载语言
// 加载内置中文
Utils.i18N.Load(Encoding.UTF8.GetString(Properties.Resources.zh_CN));
}

// 记录当前程序语言
Utils.Logging.Info($"当前程序语言:{culture}");

// 从外置文件中加载语言
if (File.Exists($"i18n\\{culture}"))
else if (Global.Settings.Language.Equals("en-US"))
{
// 加载内置英文
Utils.i18N.Load(Global.Settings.Language);
}
else if (File.Exists($"i18n\\{Global.Settings.Language}"))
{
// 加载语言
Utils.i18N.Load(File.ReadAllText($"i18n\\{culture}"));
// 从外置文件中加载语言
Utils.i18N.Load(File.ReadAllText($"i18n\\{Global.Settings.Language}"));
}

// 记录当前系统语言
Utils.Logging.Info($"当前语言:{Global.Settings.Language}");

// 检查是否已经运行
if (!mutex.WaitOne(0, false))
{
Expand Down
2 changes: 2 additions & 0 deletions Netch/Resources/zh-CN
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@
"STUN Server": "STUN 服务器",
"STUN Server Port": "STUN 服务器端口",
"Custom ACL": "自定义 ACL 规则",
"Language": "语言",
"Saved. Modify some settings need to restart the software": "保存成功,修改部分设置需重启软件",

"Profile": "配置名",
"Profiles": "配置",
Expand Down
Loading

0 comments on commit 9e8659a

Please sign in to comment.