分离读取模式文件夹方法,修改为等待子窗口退出后显示

This commit is contained in:
ChsBuffer
2020-08-19 21:47:50 +08:00
parent 8d2890790e
commit 2dfc23bbac
27 changed files with 173 additions and 243 deletions

View File

@@ -99,7 +99,6 @@
this.Name = "AboutForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "About";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.AboutForm_FormClosing);
this.Load += new System.EventHandler(this.AboutForm_Load);
this.SponsorGroupBox.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.SponsorPictureBox)).EndInit();

View File

@@ -19,11 +19,6 @@ namespace Netch.Forms
SponsorGroupBox.Text = i18N.Translate(SponsorGroupBox.Text);
}
private void AboutForm_FormClosing(object sender, FormClosingEventArgs e)
{
Global.MainForm.Show();
}
private void NetchPictureBox_Click(object sender, EventArgs e)
{
Process.Start("https://github.com/NetchX/Netch");

View File

@@ -125,7 +125,6 @@
this.Name = "GlobalBypassIPForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Global Bypass IPs";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.GlobalBypassIPForm_FormClosing);
this.Load += new System.EventHandler(this.GlobalBypassIPForm_Load);
this.IPGroupBox.ResumeLayout(false);
this.IPGroupBox.PerformLayout();

View File

@@ -28,11 +28,6 @@ namespace Netch.Forms
PrefixComboBox.SelectedIndex = 0;
}
private void GlobalBypassIPForm_FormClosing(object sender, FormClosingEventArgs e)
{
Global.SettingForm.Show();
}
private void AddButton_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(IPTextBox.Text))

View File

@@ -153,35 +153,35 @@ namespace Netch.Forms
this.AddSocks5ServerToolStripMenuItem.Name = "AddSocks5ServerToolStripMenuItem";
this.AddSocks5ServerToolStripMenuItem.Size = new System.Drawing.Size(259, 22);
this.AddSocks5ServerToolStripMenuItem.Text = "Add [Socks5] Server";
this.AddSocks5ServerToolStripMenuItem.Click += new System.EventHandler(this.AddSocks5ServerToolStripMenuItem_Click);
this.AddSocks5ServerToolStripMenuItem.Click += new System.EventHandler(this.AddServerToolStripMenuItem_Click);
//
// AddShadowsocksServerToolStripMenuItem
//
this.AddShadowsocksServerToolStripMenuItem.Name = "AddShadowsocksServerToolStripMenuItem";
this.AddShadowsocksServerToolStripMenuItem.Size = new System.Drawing.Size(259, 22);
this.AddShadowsocksServerToolStripMenuItem.Text = "Add [Shadowsocks] Server";
this.AddShadowsocksServerToolStripMenuItem.Click += new System.EventHandler(this.AddShadowsocksServerToolStripMenuItem_Click);
this.AddShadowsocksServerToolStripMenuItem.Click += new System.EventHandler(this.AddServerToolStripMenuItem_Click);
//
// AddShadowsocksRServerToolStripMenuItem
//
this.AddShadowsocksRServerToolStripMenuItem.Name = "AddShadowsocksRServerToolStripMenuItem";
this.AddShadowsocksRServerToolStripMenuItem.Size = new System.Drawing.Size(259, 22);
this.AddShadowsocksRServerToolStripMenuItem.Text = "Add [ShadowsocksR] Server";
this.AddShadowsocksRServerToolStripMenuItem.Click += new System.EventHandler(this.AddShadowsocksRServerToolStripMenuItem_Click);
this.AddShadowsocksRServerToolStripMenuItem.Click += new System.EventHandler(this.AddServerToolStripMenuItem_Click);
//
// AddVMessServerToolStripMenuItem
//
this.AddVMessServerToolStripMenuItem.Name = "AddVMessServerToolStripMenuItem";
this.AddVMessServerToolStripMenuItem.Size = new System.Drawing.Size(259, 22);
this.AddVMessServerToolStripMenuItem.Text = "Add [VMess] Server";
this.AddVMessServerToolStripMenuItem.Click += new System.EventHandler(this.AddVMessServerToolStripMenuItem_Click);
this.AddVMessServerToolStripMenuItem.Click += new System.EventHandler(this.AddServerToolStripMenuItem_Click);
//
// AddTrojanServerToolStripMenuItem
//
this.AddTrojanServerToolStripMenuItem.Name = "AddTrojanServerToolStripMenuItem";
this.AddTrojanServerToolStripMenuItem.Size = new System.Drawing.Size(259, 22);
this.AddTrojanServerToolStripMenuItem.Text = "Add [Trojan] Server";
this.AddTrojanServerToolStripMenuItem.Click += new System.EventHandler(this.AddTrojanServerToolStripMenuItem_Click);
this.AddTrojanServerToolStripMenuItem.Click += new System.EventHandler(this.AddServerToolStripMenuItem_Click);
//
// ModeToolStripMenuItem
//

View File

@@ -47,34 +47,21 @@ namespace Netch.Forms
}
}
private void AddSocks5ServerToolStripMenuItem_Click(object sender, EventArgs e)
private void AddServerToolStripMenuItem_Click(object sender, EventArgs e)
{
new Socks5().Show();
Hide();
}
Form form = ((ToolStripMenuItem) sender).Name switch
{
"AddSocks5ServerToolStripMenuItem" => new Socks5(),
"AddShadowsocksServerToolStripMenuItem" => new Shadowsocks(),
"AddShadowsocksRServerToolStripMenuItem" => new ShadowsocksR(),
"AddVMessServerToolStripMenuItem" => new VMess(),
"AddTrojanServerToolStripMenuItem" => new Trojan(),
_ => null
};
private void AddShadowsocksServerToolStripMenuItem_Click(object sender, EventArgs e)
{
new Shadowsocks().Show();
Hide();
}
private void AddShadowsocksRServerToolStripMenuItem_Click(object sender, EventArgs e)
{
new ShadowsocksR().Show();
Hide();
}
private void AddVMessServerToolStripMenuItem_Click(object sender, EventArgs e)
{
new VMess().Show();
Hide();
}
private void AddTrojanServerToolStripMenuItem_Click(object sender, EventArgs e)
{
new Trojan().Show();
Hide();
form?.ShowDialog();
Show();
}
#endregion
@@ -83,8 +70,9 @@ namespace Netch.Forms
private void CreateProcessModeToolStripButton_Click(object sender, EventArgs e)
{
new Process().Show();
Hide();
new Process().ShowDialog();
Show();
}
private async void ReloadModesToolStripMenuItem_Click(object sender, EventArgs e)
@@ -115,8 +103,10 @@ namespace Netch.Forms
private void ManageSubscribeLinksToolStripMenuItem_Click(object sender, EventArgs e)
{
new SubscribeForm().Show();
Hide();
new SubscribeForm().ShowDialog();
InitServer();
Show();
}
private async void UpdateServersFromSubscribeLinksToolStripMenuItem_Click(object sender, EventArgs e)
@@ -388,8 +378,9 @@ namespace Netch.Forms
private void AboutToolStripButton_Click(object sender, EventArgs e)
{
new AboutForm().Show();
Hide();
new AboutForm().ShowDialog();
Show();
}
#endregion

View File

@@ -1,6 +1,7 @@
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using Netch.Utils;
@@ -52,92 +53,15 @@ namespace Netch.Forms
#region Mode
private void InitMode()
public void InitMode()
{
ModeComboBox.Items.Clear();
Global.ModeFiles.Clear();
if (Directory.Exists("mode"))
{
foreach (var name in Directory.GetFiles("mode", "*.txt"))
{
var ok = true;
var mode = new Models.Mode();
Modes.Load();
using (var sr = new StringReader(File.ReadAllText(name)))
{
var i = 0;
string text;
ModeComboBox.Items.AddRange(Global.Modes.ToArray());
while ((text = sr.ReadLine()) != null)
{
if (i == 0)
{
var splited = text.Trim().Substring(1).Split(',');
if (splited.Length == 0)
{
ok = false;
break;
}
if (splited.Length >= 1)
{
mode.Remark = i18N.Translate(splited[0].Trim());
}
if (splited.Length >= 2)
{
if (int.TryParse(splited[1], out var result))
{
mode.Type = result;
}
else
{
ok = false;
break;
}
}
if (splited.Length >= 3)
{
if (int.TryParse(splited[2], out var result))
{
mode.BypassChina = result == 1;
}
else
{
ok = false;
break;
}
}
}
else
{
if (!text.StartsWith("#") && !string.IsNullOrWhiteSpace(text))
{
mode.Rule.Add(text.Trim());
}
}
i++;
}
}
if (ok)
{
mode.FileName = Path.GetFileNameWithoutExtension(name);
Global.ModeFiles.Add(mode);
}
}
var array = Global.ModeFiles.ToArray();
Array.Sort(array, (a, b) => string.Compare(a.Remark, b.Remark, StringComparison.Ordinal));
ModeComboBox.Items.AddRange(array);
SelectLastMode();
}
SelectLastMode();
}
private void SelectLastMode()
@@ -160,20 +84,8 @@ namespace Netch.Forms
public void AddMode(Models.Mode mode)
{
ModeComboBox.Items.Clear();
Global.ModeFiles.Add(mode);
var array = Global.ModeFiles.ToArray();
Array.Sort(array, (a, b) => string.Compare(a.Remark, b.Remark, StringComparison.Ordinal));
ModeComboBox.Items.AddRange(array);
SelectLastMode();
}
public void UpdateMode(Models.Mode NewMode, Models.Mode OldMode)
{
ModeComboBox.Items.Clear();
Global.ModeFiles.Remove(OldMode);
Global.ModeFiles.Add(NewMode);
var array = Global.ModeFiles.ToArray();
Global.Modes.Add(mode);
var array = Global.Modes.ToArray();
Array.Sort(array, (a, b) => string.Compare(a.Remark, b.Remark, StringComparison.Ordinal));
ModeComboBox.Items.AddRange(array);

View File

@@ -162,8 +162,9 @@ namespace Netch.Forms
private void SettingsButton_Click(object sender, EventArgs e)
{
(Global.SettingForm = new SettingForm()).Show();
Hide();
new SettingForm().ShowDialog();
Show();
}
@@ -285,28 +286,19 @@ namespace Netch.Forms
// 当前ServerComboBox中至少有一项
if (ServerComboBox.SelectedIndex != -1)
{
switch (Global.Settings.Server[ServerComboBox.SelectedIndex].Type)
Form server = Global.Settings.Server[ServerComboBox.SelectedIndex].Type switch
{
case "Socks5":
new Socks5(ServerComboBox.SelectedIndex).Show();
break;
case "SS":
new Shadowsocks(ServerComboBox.SelectedIndex).Show();
break;
case "SSR":
new ShadowsocksR(ServerComboBox.SelectedIndex).Show();
break;
case "VMess":
new VMess(ServerComboBox.SelectedIndex).Show();
break;
case "Trojan":
new Trojan(ServerComboBox.SelectedIndex).Show();
break;
default:
return;
}
"Socks5" => new Socks5(ServerComboBox.SelectedIndex),
"SS" => new Shadowsocks(ServerComboBox.SelectedIndex),
"SSR" => new ShadowsocksR(ServerComboBox.SelectedIndex),
"VMess" => new VMess(ServerComboBox.SelectedIndex),
"Trojan" => new Trojan(ServerComboBox.SelectedIndex),
_ => null
};
Hide();
server?.ShowDialog();
InitServer();
Show();
}
else
{
@@ -349,6 +341,11 @@ namespace Netch.Forms
var process = new Process(selectedMode);
process.Show();
Hide();
process.FormClosed += (o, args) =>
{
InitMode();
Show();
};
break;
}
default:
@@ -370,8 +367,8 @@ namespace Netch.Forms
selectedMode.DeleteFile("mode");
ModeComboBox.Items.Clear();
Global.ModeFiles.Remove(selectedMode);
var array = Global.ModeFiles.ToArray();
Global.Modes.Remove(selectedMode);
var array = Global.Modes.ToArray();
Array.Sort(array, (a, b) => string.Compare(a.Remark, b.Remark, StringComparison.Ordinal));
ModeComboBox.Items.AddRange(array);

View File

@@ -198,7 +198,6 @@ namespace Netch.Forms.Mode
this.Name = "Process";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Create Process Mode";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ModeForm_FormClosing);
this.Load += new System.EventHandler(this.ModeForm_Load);
this.ConfigurationGroupBox.ResumeLayout(false);
this.ConfigurationGroupBox.PerformLayout();
@@ -212,7 +211,7 @@ namespace Netch.Forms.Mode
private System.Windows.Forms.ContextMenuStrip contextMenuStrip;
private System.Windows.Forms.ToolStripMenuItem DeleteToolStripMenuItem;
private System.Windows.Forms.GroupBox ConfigurationGroupBox;
public System.Windows.Forms.GroupBox ConfigurationGroupBox;
private System.Windows.Forms.Label RemarkLabel;
private System.Windows.Forms.GroupBox ProcessGroupBox;
private System.Windows.Forms.ListBox RuleListBox;
@@ -220,7 +219,7 @@ namespace Netch.Forms.Mode
private System.Windows.Forms.TextBox ProcessNameTextBox;
private System.Windows.Forms.Button AddButton;
private System.Windows.Forms.Button ScanButton;
private System.Windows.Forms.Button ControlButton;
public System.Windows.Forms.Button ControlButton;
private System.Windows.Forms.Label FilenameLabel;
private System.Windows.Forms.TextBox FilenameTextBox;
private System.Windows.Forms.CheckBox UseCustomFilenameBox;

View File

@@ -11,10 +11,12 @@ namespace Netch.Forms.Mode
public partial class Process : Form
{
//用于判断当前窗口是否为编辑模式
private bool EditMode;
public readonly bool IsEditing;
//被编辑模式坐标
private Models.Mode EditMode_Old;
//被编辑模式
public readonly Models.Mode EditingMode;
public bool IsEdited { get; private set; } = false;
/// <summary>
/// 编辑模式
@@ -23,15 +25,14 @@ namespace Netch.Forms.Mode
public Process(Models.Mode mode)
{
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;
EditMode_Old = mode;
EditingMode = mode;
Text = "Edit Process Mode";
//循环填充已有规则
mode.Rule.ForEach(i => RuleListBox.Items.Add(i));
EditMode = true;
IsEditing = true;
RemarkTextBox.TextChanged -= RemarkTextBox_TextChanged;
FilenameTextBox.Enabled = false;
FilenameLabel.Enabled = false;
@@ -44,11 +45,13 @@ namespace Netch.Forms.Mode
public Process()
{
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;
EditMode = false;
EditMode_Old = null;
EditingMode = null;
FilenameTextBox.Enabled = false;
FilenameLabel.Enabled = false;
IsEditing = false;
}
/// <summary>
@@ -88,6 +91,7 @@ namespace Netch.Forms.Mode
if (FileChildInfo.Name.EndsWith(".exe") && !RuleListBox.Items.Contains(FileChildInfo.Name))
{
RuleListBox.Items.Add(FileChildInfo.Name);
IsEdited = true;
}
}
}
@@ -98,7 +102,7 @@ namespace Netch.Forms.Mode
}
}
private void ModeForm_Load(object sender, EventArgs e)
public void ModeForm_Load(object sender, EventArgs e)
{
Text = i18N.Translate(Text);
ConfigurationGroupBox.Text = i18N.Translate(ConfigurationGroupBox.Text);
@@ -109,14 +113,6 @@ namespace Netch.Forms.Mode
ScanButton.Text = i18N.Translate(ScanButton.Text);
ControlButton.Text = i18N.Translate(ControlButton.Text);
DeleteToolStripMenuItem.Text = i18N.Translate(DeleteToolStripMenuItem.Text);
FilenameTextBox.Enabled = false;
FilenameLabel.Enabled = false;
}
private void ModeForm_FormClosing(object sender, FormClosingEventArgs e)
{
Global.MainForm.Show();
}
/// <summary>
@@ -137,6 +133,7 @@ namespace Netch.Forms.Mode
{
if (RuleListBox.SelectedIndex == -1) return;
RuleListBox.Items.RemoveAt(RuleListBox.SelectedIndex);
IsEdited = true;
}
private async void AddButton_Click(object sender, EventArgs e)
@@ -156,6 +153,7 @@ namespace Netch.Forms.Mode
RuleListBox.Items.Add(process);
}
IsEdited = true;
RuleListBox.SelectedIndex = RuleListBox.Items.IndexOf(process);
ProcessNameTextBox.Text = string.Empty;
}
@@ -176,26 +174,24 @@ namespace Netch.Forms.Mode
}
}
private void ControlButton_Click(object sender, EventArgs e)
public void ControlButton_Click(object sender, EventArgs e)
{
if (EditMode)
if (IsEditing)
{
// 编辑模式
if (RuleListBox.Items.Count != 0)
{
var mode = new Models.Mode
{
BypassChina = false,
FileName = FilenameTextBox.Text,
Type = 0,
Remark = RemarkTextBox.Text
};
EditingMode.BypassChina = false;
EditingMode.FileName = FilenameTextBox.Text;
EditingMode.Type = 0;
EditingMode.Remark = RemarkTextBox.Text;
EditingMode.Rule.Clear();
var text = $"# {RemarkTextBox.Text}, 0\r\n";
foreach (var item in RuleListBox.Items)
{
var process = item as string;
mode.Rule.Add(process);
EditingMode.Rule.Add(process);
text += process + "\r\n";
}
@@ -210,7 +206,7 @@ namespace Netch.Forms.Mode
MessageBoxX.Show(i18N.Translate("Mode updated successfully"));
Global.MainForm.UpdateMode(mode, EditMode_Old);
IsEdited = false;
Close();
}
else

View File

@@ -218,7 +218,6 @@
this.Name = "Shadowsocks";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Shadowsocks";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Shadowsocks_FormClosing);
this.Load += new System.EventHandler(this.Shadowsocks_Load);
this.ConfigurationGroupBox.ResumeLayout(false);
this.ConfigurationGroupBox.PerformLayout();

View File

@@ -48,11 +48,6 @@ namespace Netch.Forms.Server
PluginOptionsTextBox.Text = _server.PluginOption;
}
private void Shadowsocks_FormClosing(object sender, FormClosingEventArgs e)
{
Global.MainForm.Show();
}
private void ComboBox_DrawItem(object sender, DrawItemEventArgs e)
{
if (sender is ComboBox cbx)

View File

@@ -266,7 +266,6 @@
this.Name = "ShadowsocksR";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "ShadowsocksR";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ShadowsocksR_FormClosing);
this.Load += new System.EventHandler(this.ShadowsocksR_Load);
this.ConfigurationGroupBox.ResumeLayout(false);
this.ConfigurationGroupBox.PerformLayout();

View File

@@ -56,11 +56,6 @@ namespace Netch.Forms.Server
OBFSOptionParamTextBox.Text = _server.OBFSParam;
}
private void ShadowsocksR_FormClosing(object sender, FormClosingEventArgs e)
{
Global.MainForm.Show();
}
private void ComboBox_DrawItem(object sender, DrawItemEventArgs e)
{
if (sender is ComboBox cbx)

View File

@@ -173,7 +173,6 @@
this.Name = "Socks5";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Socks5";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Shadowsocks_FormClosing);
this.Load += new System.EventHandler(this.Shadowsocks_Load);
this.ConfigurationGroupBox.ResumeLayout(false);
this.ConfigurationGroupBox.PerformLayout();

View File

@@ -42,11 +42,6 @@ namespace Netch.Forms.Server
PasswordTextBox.Text = _server.Password;
}
private void Shadowsocks_FormClosing(object sender, FormClosingEventArgs e)
{
Global.MainForm.Show();
}
private void ComboBox_DrawItem(object sender, DrawItemEventArgs e)
{
if (sender is ComboBox cbx)

View File

@@ -152,7 +152,6 @@
this.Name = "Trojan";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Trojan";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Trojan_FormClosing);
this.Load += new System.EventHandler(this.Trojan_Load);
this.ConfigurationGroupBox.ResumeLayout(false);
this.ConfigurationGroupBox.PerformLayout();

View File

@@ -37,11 +37,6 @@ namespace Netch.Forms.Server
PasswordTextBox.Text = _server.Password;
}
private void Trojan_FormClosing(object sender, FormClosingEventArgs e)
{
Global.MainForm.Show();
}
private void ComboBox_DrawItem(object sender, DrawItemEventArgs e)
{
if (sender is ComboBox cbx)

View File

@@ -385,7 +385,6 @@
this.Name = "VMess";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "VMess";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.VMess_FormClosing);
this.Load += new System.EventHandler(this.VMess_Load);
this.ConfigurationGroupBox.ResumeLayout(false);
this.ConfigurationGroupBox.PerformLayout();

View File

@@ -87,11 +87,6 @@ namespace Netch.Forms.Server
UseMuxCheckBox.Checked = server.UseMux;
}
private void VMess_FormClosing(object sender, FormClosingEventArgs e)
{
Global.MainForm.Show();
}
private void ControlButton_Click(object sender, EventArgs e)
{
if (!int.TryParse(PortTextBox.Text, out var port))

View File

@@ -535,7 +535,6 @@
this.Name = "SettingForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Settings";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.SettingForm_FormClosing);
this.Load += new System.EventHandler(this.SettingForm_Load);
this.PortGroupBox.ResumeLayout(false);
this.PortGroupBox.PerformLayout();

View File

@@ -172,15 +172,11 @@ namespace Netch.Forms
InitValue();
}
private void SettingForm_FormClosing(object sender, FormClosingEventArgs e)
{
Global.MainForm.Show();
}
private void GlobalBypassIPsButton_Click(object sender, EventArgs e)
{
new GlobalBypassIPForm().Show();
Hide();
new GlobalBypassIPForm().ShowDialog();
Show();
}
private void ControlButton_Click(object sender, EventArgs e)

View File

@@ -63,9 +63,6 @@ namespace Netch.Forms
{
Configuration.Save();
Global.Settings.UseProxyToUpdateSubscription = UseSelectedServerCheckBox.Checked;
Global.MainForm.InitServer();
Global.MainForm.Show();
}
private void CopyLinkToolStripMenuItem_Click(object sender, EventArgs e)

View File

@@ -21,11 +21,6 @@ namespace Netch
/// </summary>
public static Forms.MainForm MainForm;
/// <summary>
/// 设置窗体
/// </summary>
public static Forms.SettingForm SettingForm;
/// <summary>
/// SS/SSR 加密方式
/// </summary>
@@ -206,8 +201,8 @@ namespace Netch
public static Models.Setting Settings = new Models.Setting();
/// <summary>
/// 用于存储模式文件内容
/// 用于存储模式
/// </summary>
public static List<Models.Mode> ModeFiles = new List<Models.Mode>();
public static readonly List<Models.Mode> Modes = new List<Models.Mode>();
}
}

View File

@@ -11,6 +11,11 @@ namespace Netch.Models
/// </summary>
public string Remark;
/// <summary>
/// 文件相对路径
/// </summary>
public string RelativePath;
/// <summary>
/// 无后缀文件名
/// </summary>

View File

@@ -107,6 +107,6 @@
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties /></VisualStudio></ProjectExtensions>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="@ECHO OFF&#xD;&#xA;RD /S /Q $(TargetDir)bin &#x3E;NUL 2&#x3E;&#x26;1&#xD;&#xA;RD /S /Q $(TargetDir)i18n &#x3E;NUL 2&#x3E;&#x26;1&#xD;&#xA;RD /S /Q $(TargetDir)mode &#x3E;NUL 2&#x3E;&#x26;1&#xD;&#xA;&#xD;&#xA;XCOPY /s /Y $(SolutionDir)binaries $(TargetDir)bin\ &#x3E;NUL&#xD;&#xA;XCOPY /s /Y $(SolutionDir)translations\i18n $(TargetDir)i18n\ &#x3E;NUL&#xD;&#xA;XCOPY /s /Y $(SolutionDir)modes\mode $(TargetDir)mode\ &#x3E;NUL&#xD;&#xA;&#xD;&#xA;DEL /f $(TargetDir)*.config &#x3E;NUL 2&#x3E;&#x26;1&#xD;&#xA;DEL /f $(TargetDir)*.pdb &#x3E;NUL 2&#x3E;&#x26;1&#xD;&#xA;RD /s /Q $(TargetDir)x86 &#x3E;NUL 2&#x3E;&#x26;1" />
<Exec Command="@ECHO OFF&#xD;&#xA;RD /S /Q $(TargetDir)bin &gt;NUL 2&gt;&amp;1&#xD;&#xA;RD /S /Q $(TargetDir)i18n &gt;NUL 2&gt;&amp;1&#xD;&#xA;RD /S /Q $(TargetDir)mode &gt;NUL 2&gt;&amp;1&#xD;&#xA;&#xD;&#xA;XCOPY /s /Y $(SolutionDir)binaries $(TargetDir)bin\ &gt;NUL&#xD;&#xA;XCOPY /s /Y $(SolutionDir)translations\i18n $(TargetDir)i18n\ &gt;NUL&#xD;&#xA;XCOPY /s /Y $(SolutionDir)modes\mode $(TargetDir)mode\ &gt;NUL&#xD;&#xA;&#xD;&#xA;DEL /f $(TargetDir)*.config &gt;NUL 2&gt;&amp;1&#xD;&#xA;DEL /f $(TargetDir)*.pdb &gt;NUL 2&gt;&amp;1&#xD;&#xA;RD /s /Q $(TargetDir)x86 &gt;NUL 2&gt;&amp;1" />
</Target>
</Project>

85
Netch/Utils/Modes.cs Normal file
View File

@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Netch.Models;
namespace Netch.Utils
{
public static class Modes
{
private static readonly string ModeDirectory = Path.Combine(Global.NetchDir, "mode\\");
public static void Load()
{
Global.Modes.Clear();
if (!Directory.Exists("mode")) return;
var stack = new Stack<string>();
stack.Push("mode");
while (stack.Count > 0)
{
var dirInfo = new DirectoryInfo(stack.Pop());
try
{
foreach (var childDirInfo in dirInfo.GetDirectories())
stack.Push(childDirInfo.FullName);
foreach (var childFileInfo in dirInfo.GetFiles().Where(info => info.Name.EndsWith(".txt")))
LoadModeFile(childFileInfo.FullName);
}
catch
{
// ignored
}
}
Global.Modes.Sort((a, b) => string.Compare(a.Remark, b.Remark, StringComparison.Ordinal));
}
private static void LoadModeFile(string path)
{
var mode = new Mode
{
FileName = Path.GetFileNameWithoutExtension(path),
RelativePath = path.Substring(ModeDirectory.Length)
};
var content = File.ReadAllLines(path);
if (content.Length == 0) return;
for (var i = 0; i < content.Length; i++)
{
var text = content[i];
if (i == 0)
{
var splited = text.Substring(text.IndexOf('#') + 1).Split(',').Select(s => s.Trim()).ToArray();
try
{
string tmp;
if ((tmp = splited.ElementAtOrDefault(0)) != null)
mode.Remark = i18N.Translate(tmp);
if ((tmp = splited.ElementAtOrDefault(1)) != null)
mode.Type = int.Parse(tmp);
if ((tmp = splited.ElementAtOrDefault(2)) != null)
mode.BypassChina = int.Parse(tmp) == 1;
}
catch
{
return;
}
}
else
{
if (!text.StartsWith("#") && !string.IsNullOrWhiteSpace(text))
mode.Rule.Add(text.Trim());
}
}
Global.Modes.Add(mode);
}
}
}