mirror of
https://github.com/netchx/netch.git
synced 2026-03-18 18:13:21 +08:00
Reduce Reference and cleanup
This commit is contained in:
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@@ -28,7 +28,7 @@ jobs:
|
||||
- name: Restore NuGet Package
|
||||
run: nuget restore Netch.sln
|
||||
|
||||
- name: Build .NET 4.8
|
||||
- name: Build Solution
|
||||
shell: pwsh
|
||||
run: |
|
||||
.\BUILD.ps1
|
||||
@@ -37,7 +37,7 @@ jobs:
|
||||
echo "::set-env name=Netch_SHA256::$(.\GetSHA256.ps1 C:\builtfiles\Netch.zip)"
|
||||
echo "::set-env name=Netch_EXE_SHA256::$(.\GetSHA256.ps1 Netch\bin\x64\Release\win-x64\Netch.exe)"
|
||||
|
||||
- name: Upload
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: Netch
|
||||
|
||||
@@ -66,22 +66,34 @@ namespace Netch.Controllers
|
||||
|
||||
private new void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(e.Data))
|
||||
if (string.IsNullOrEmpty(e.Data)) return;
|
||||
var str = e.Data.Split(':');
|
||||
if (str.Length < 2)
|
||||
return;
|
||||
str[1] = str[1].Trim();
|
||||
switch (str[0])
|
||||
{
|
||||
if (e.Data.StartsWith("Other address is: "))
|
||||
_Other_address = e.Data.Split(':')[1].Trim();
|
||||
if (e.Data.StartsWith("Binding test: "))
|
||||
_Binding_test = e.Data.Split(':')[1].Trim();
|
||||
if (e.Data.StartsWith("Local address: "))
|
||||
_Local_address = e.Data.Split(':')[1].Trim();
|
||||
if (e.Data.StartsWith("Mapped address: "))
|
||||
_Mapped_address = e.Data.Split(':')[1].Trim();
|
||||
if (e.Data.StartsWith("Nat mapping behavior: "))
|
||||
_Nat_mapping_behavior = e.Data.Split(':')[1].Trim();
|
||||
if (e.Data.StartsWith("Nat filtering behavior: "))
|
||||
_Nat_filtering_behavior = e.Data.Split(':')[1].Trim();
|
||||
if (e.Data.StartsWith("result: "))
|
||||
_lastResult = e.Data.Split(':')[1].Trim();
|
||||
case "Other address is":
|
||||
_Other_address = str[1];
|
||||
break;
|
||||
case "Binding test":
|
||||
_Binding_test = str[1];
|
||||
break;
|
||||
case "Local address":
|
||||
_Local_address = str[1];
|
||||
break;
|
||||
case "Mapped address":
|
||||
_Mapped_address = str[1];
|
||||
break;
|
||||
case "Nat mapping behavior":
|
||||
_Nat_mapping_behavior = str[1];
|
||||
break;
|
||||
case "Nat filtering behavior":
|
||||
_Nat_filtering_behavior = str[1];
|
||||
break;
|
||||
case "result":
|
||||
_lastResult = str[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Microsoft.WindowsAPICodePack.Dialogs;
|
||||
using Netch.Utils;
|
||||
|
||||
namespace Netch.Forms.Mode
|
||||
@@ -169,18 +168,10 @@ namespace Netch.Forms.Mode
|
||||
|
||||
private void ScanButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var dialog = new CommonOpenFileDialog
|
||||
var dialog = new FolderBrowserDialog();
|
||||
if (dialog.ShowDialog(this) == DialogResult.OK)
|
||||
{
|
||||
IsFolderPicker = true,
|
||||
Multiselect = false,
|
||||
Title = i18N.Translate("Select a folder"),
|
||||
AddToMostRecentlyUsedList = false,
|
||||
EnsurePathExists = true,
|
||||
NavigateToShortcut = true
|
||||
};
|
||||
if (dialog.ShowDialog(Win32Native.GetForegroundWindow()) == CommonFileDialogResult.Ok)
|
||||
{
|
||||
ScanDirectory(dialog.FileName);
|
||||
ScanDirectory(dialog.SelectedPath);
|
||||
MessageBoxX.Show(i18N.Translate("Scan completed"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ namespace Netch.Forms
|
||||
var stuns = File.ReadLines("bin\\stun.txt");
|
||||
STUN_ServerComboBox.Items.AddRange(stuns.ToArray());
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
|
||||
@@ -57,13 +57,10 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ini-parser" Version="2.5.2" />
|
||||
<PackageReference Include="IPNetwork2" Version="2.5.211" />
|
||||
<PackageReference Include="MaxMind.GeoIP2" Version="3.2.0" />
|
||||
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="2.0.56" />
|
||||
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="2.0.58" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="System.Buffers" Version="4.5.1" />
|
||||
<PackageReference Include="WindowsAPICodePack-Shell" Version="1.1.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -13,76 +13,65 @@ namespace NetchUpdater
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var updaterDirectory = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
|
||||
string zipFile, netchDir;
|
||||
int port;
|
||||
|
||||
var result = false;
|
||||
try
|
||||
{
|
||||
var currentProcess = Process.GetCurrentProcess();
|
||||
if (currentProcess.MainModule == null)
|
||||
{
|
||||
Console.WriteLine("Current Process MainModule is null");
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Length != 3)
|
||||
{
|
||||
Console.WriteLine("The program is not user-oriented\n此程序不是面向用户的");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
// arg0 port
|
||||
if (!int.TryParse(args[0], out var port))
|
||||
{
|
||||
var portParseResult = int.TryParse(args[0], out port);
|
||||
if (!portParseResult)
|
||||
{
|
||||
Console.WriteLine("arg0 Port Parse failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (IndexOutOfRangeException)
|
||||
{
|
||||
Console.WriteLine("arg0 Port not specified");
|
||||
Console.WriteLine("arg0 Port Parse failed");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
// arg1 zipFile
|
||||
string zipFile;
|
||||
if (!File.Exists(zipFile = Path.GetFullPath(args[1])))
|
||||
{
|
||||
var zipFileParseResult = File.Exists(zipFile = Path.GetFullPath(args[1]));
|
||||
if (!zipFileParseResult)
|
||||
{
|
||||
Console.WriteLine("arg1 Zip file Not found");
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (IndexOutOfRangeException)
|
||||
{
|
||||
Console.Write("arg1 Zip file not specified");
|
||||
Console.WriteLine("arg1 Zip file Not found");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
// arg2 target Directory
|
||||
string targetDir;
|
||||
if (!File.Exists(Path.Combine(targetDir = Path.GetFullPath(args[2]), "Netch.exe")))
|
||||
{
|
||||
var netchDirParseResult = !File.Exists(Path.Combine(netchDir = Path.GetFullPath(args[2]), "Netch.exe"));
|
||||
if (netchDirParseResult)
|
||||
{
|
||||
Console.Write("arg2 Netch Directory doesn't seems right");
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (IndexOutOfRangeException)
|
||||
{
|
||||
Console.Write("arg2 Netch Directory not specified");
|
||||
Console.Write("arg2 Netch Directory doesn't seems right");
|
||||
return;
|
||||
}
|
||||
|
||||
// check updater directory
|
||||
var updaterFullName = currentProcess.MainModule.FileName;
|
||||
var updaterDirectory = Path.GetDirectoryName(updaterFullName);
|
||||
var updaterFriendlyName = Path.GetFileName(updaterFullName);
|
||||
|
||||
if (File.Exists(Path.Combine(updaterDirectory, "Netch.exe")))
|
||||
{
|
||||
// Updater 在目标目录下
|
||||
// 将程序复制到临时目录,传递参数
|
||||
var tempPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
|
||||
var newUpdaterPath = Path.Combine(tempPath, updaterFriendlyName);
|
||||
Directory.CreateDirectory(tempPath);
|
||||
File.Copy(Process.GetCurrentProcess().MainModule.FileName,
|
||||
Path.Combine(tempPath, AppDomain.CurrentDomain.FriendlyName));
|
||||
File.Copy(updaterFullName, newUpdaterPath);
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = Path.Combine(tempPath, AppDomain.CurrentDomain.FriendlyName),
|
||||
FileName = newUpdaterPath,
|
||||
Arguments = $"{args[0]} {args[1]} {args[2]}",
|
||||
UseShellExecute = false
|
||||
});
|
||||
|
||||
result = true;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -92,6 +81,7 @@ namespace NetchUpdater
|
||||
Thread.Sleep(1000);
|
||||
}*/
|
||||
|
||||
// Let Netch Exit
|
||||
Process[] _;
|
||||
if ((_ = Process.GetProcessesByName("Netch")).Any())
|
||||
{
|
||||
@@ -108,7 +98,6 @@ namespace NetchUpdater
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
foreach (var proc in _)
|
||||
{
|
||||
try
|
||||
@@ -121,28 +110,39 @@ namespace NetchUpdater
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Thread.Sleep(500);
|
||||
|
||||
// Extract ZIP
|
||||
Console.WriteLine("Extract Zip");
|
||||
ExtractToDirectory(zipFile, netchDir, true);
|
||||
ExtractToDirectory(zipFile, targetDir, true);
|
||||
|
||||
// Start Netch
|
||||
Console.WriteLine("Start Netch");
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = Path.Combine(netchDir, "Netch.exe"),
|
||||
FileName = Path.Combine(targetDir, "Netch.exe"),
|
||||
UseShellExecute = true,
|
||||
});
|
||||
result = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (e is InvalidDataException)
|
||||
Console.WriteLine("Zip file Broken");
|
||||
Console.WriteLine(e.ToString());
|
||||
Console.WriteLine("Press any key to exit...");
|
||||
Console.Read();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (!result)
|
||||
{
|
||||
Console.WriteLine("Press any key to exit...");
|
||||
Console.Read();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void ExtractToDirectory(string archiveFileName, string destinationDirectoryName, bool overwrite)
|
||||
private static void ExtractToDirectory(string archiveFileName, string destinationDirectoryName, bool overwrite)
|
||||
{
|
||||
if (!overwrite)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user