Code clean

pull/4457/head
2dust 2023-11-28 16:07:53 +08:00
parent 81efd25e0a
commit 12be8bda52
14 changed files with 28 additions and 30 deletions

View File

@ -1,9 +1,9 @@
<Application <Application
x:Class="v2rayN.App" x:Class="v2rayN.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:conv="clr-namespace:v2rayN.Converters" xmlns:conv="clr-namespace:v2rayN.Converters"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
ShutdownMode="OnExplicitShutdown" ShutdownMode="OnExplicitShutdown"
StartupUri="Views/MainWindow.xaml"> StartupUri="Views/MainWindow.xaml">
<Application.Resources> <Application.Resources>

View File

@ -177,4 +177,4 @@
#endregion global variable #endregion global variable
} }
} }

View File

@ -205,7 +205,6 @@ namespace v2rayN.Handler
}; };
} }
LazyConfig.Instance.SetConfig(config); LazyConfig.Instance.SetConfig(config);
return 0; return 0;
} }

View File

@ -155,4 +155,4 @@ namespace v2rayN.Handler
return coreConfigV2ray.GenerateClientSpeedtestConfigString(selecteds, out msg); return coreConfigV2ray.GenerateClientSpeedtestConfigString(selecteds, out msg);
} }
} }
} }

View File

@ -62,7 +62,6 @@ namespace v2rayN.Handler
Utils.SaveLog("Tun mode restart the core once"); Utils.SaveLog("Tun mode restart the core once");
} }
} }
}); });
} }
} }

View File

@ -378,4 +378,4 @@ namespace v2rayN.Handler
#endregion Core Type #endregion Core Type
} }
} }

View File

@ -78,7 +78,7 @@ namespace v2rayN.Handler
if (optionCount > 1) if (optionCount > 1)
{ {
options[1].m_Option = m_Option; options[1].m_Option = m_Option;
options[1].m_Value.m_StringPtr = Marshal.StringToHGlobalAuto(strProxy); // !! remember to deallocate memory 1 options[1].m_Value.m_StringPtr = Marshal.StringToHGlobalAuto(strProxy); // !! remember to deallocate memory 1
// except for these addresses ... // except for these addresses ...
if (optionCount > 2) if (optionCount > 2)
{ {
@ -91,10 +91,10 @@ namespace v2rayN.Handler
list.dwSize = Marshal.SizeOf(list); list.dwSize = Marshal.SizeOf(list);
if (connectionName != null) if (connectionName != null)
{ {
list.szConnection = Marshal.StringToHGlobalAuto(connectionName); // !! remember to deallocate memory 3 list.szConnection = Marshal.StringToHGlobalAuto(connectionName); // !! remember to deallocate memory 3
} }
else else
{ {
list.szConnection = IntPtr.Zero; list.szConnection = IntPtr.Zero;
} }
list.dwOptionCount = options.Length; list.dwOptionCount = options.Length;
@ -141,7 +141,7 @@ namespace v2rayN.Handler
} }
// FREE the data ASAP // FREE the data ASAP
if(list.szConnection != IntPtr.Zero) Marshal.FreeHGlobal(list.szConnection); // release mem 3 if (list.szConnection != IntPtr.Zero) Marshal.FreeHGlobal(list.szConnection); // release mem 3
if (optionCount > 1) if (optionCount > 1)
{ {
Marshal.FreeHGlobal(options[1].m_Value.m_StringPtr); // release mem 1 Marshal.FreeHGlobal(options[1].m_Value.m_StringPtr); // release mem 1
@ -155,7 +155,7 @@ namespace v2rayN.Handler
if (returnvalue != 0) if (returnvalue != 0)
{ {
// throw the error codes, they might be helpful // throw the error codes, they might be helpful
throw new ApplicationException($"Set Internet Proxy failed with error code: {Marshal.GetLastWin32Error()}" ); throw new ApplicationException($"Set Internet Proxy failed with error code: {Marshal.GetLastWin32Error()}");
} }
return true; return true;
@ -256,8 +256,8 @@ namespace v2rayN.Handler
// Constants // Constants
public const int RAS_MaxEntryName = 256; public const int RAS_MaxEntryName = 256;
public const int MAX_PATH = 260; // Standard MAX_PATH value in Windows
public const int MAX_PATH = 260; // Standard MAX_PATH value in Windows
} }
#endregion WinInet structures #endregion WinInet structures
@ -310,6 +310,7 @@ namespace v2rayN.Handler
[DllImport("WinInet.dll", SetLastError = true, CharSet = CharSet.Auto)] [DllImport("WinInet.dll", SetLastError = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool InternetSetOption(IntPtr hInternet, InternetOption dwOption, IntPtr lpBuffer, int dwBufferLength); public static extern bool InternetSetOption(IntPtr hInternet, InternetOption dwOption, IntPtr lpBuffer, int dwBufferLength);
[DllImport("Rasapi32.dll", CharSet = CharSet.Auto)] [DllImport("Rasapi32.dll", CharSet = CharSet.Auto)]
public static extern uint RasEnumEntries( public static extern uint RasEnumEntries(
string? reserved, // Reserved, must be null string? reserved, // Reserved, must be null

View File

@ -1,10 +1,5 @@
using PacLib; using PacLib;
using System.Diagnostics;
using System.IO;
using System.Text;
using v2rayN.Mode; using v2rayN.Mode;
using v2rayN.Properties;
using v2rayN.Tool;
namespace v2rayN.Handler namespace v2rayN.Handler
{ {
@ -33,7 +28,6 @@ namespace v2rayN.Handler
static SysProxyHandle() static SysProxyHandle()
{ {
} }
public static bool UpdateSysProxy(Config config, bool forceDisable) public static bool UpdateSysProxy(Config config, bool forceDisable)

View File

@ -28,7 +28,7 @@
public ConstItem constItem { get; set; } public ConstItem constItem { get; set; }
public SpeedTestItem speedTestItem { get; set; } public SpeedTestItem speedTestItem { get; set; }
public Mux4SboxItem mux4SboxItem { get; set; } public Mux4SboxItem mux4SboxItem { get; set; }
public HysteriaItem hysteriaItem { get; set; } public HysteriaItem hysteriaItem { get; set; }
public List<InItem> inbound { get; set; } public List<InItem> inbound { get; set; }
public List<KeyEventItem> globalHotkeys { get; set; } public List<KeyEventItem> globalHotkeys { get; set; }
public List<CoreTypeItem> coreTypeItem { get; set; } public List<CoreTypeItem> coreTypeItem { get; set; }

View File

@ -16,4 +16,4 @@
hysteria2 = 26, hysteria2 = 26,
v2rayN = 99 v2rayN = 99
} }
} }

View File

@ -89,7 +89,7 @@ namespace v2rayN.ViewModels
public ReactiveCommand<Unit, Unit> AddShadowsocksServerCmd { get; } public ReactiveCommand<Unit, Unit> AddShadowsocksServerCmd { get; }
public ReactiveCommand<Unit, Unit> AddSocksServerCmd { get; } public ReactiveCommand<Unit, Unit> AddSocksServerCmd { get; }
public ReactiveCommand<Unit, Unit> AddTrojanServerCmd { get; } public ReactiveCommand<Unit, Unit> AddTrojanServerCmd { get; }
public ReactiveCommand<Unit, Unit> AddHysteria2ServerCmd { get; } public ReactiveCommand<Unit, Unit> AddHysteria2ServerCmd { get; }
public ReactiveCommand<Unit, Unit> AddCustomServerCmd { get; } public ReactiveCommand<Unit, Unit> AddCustomServerCmd { get; }
public ReactiveCommand<Unit, Unit> AddServerViaClipboardCmd { get; } public ReactiveCommand<Unit, Unit> AddServerViaClipboardCmd { get; }
public ReactiveCommand<Unit, Unit> AddServerViaScanCmd { get; } public ReactiveCommand<Unit, Unit> AddServerViaScanCmd { get; }
@ -148,11 +148,14 @@ namespace v2rayN.ViewModels
public ReactiveCommand<Unit, Unit> CheckUpdateNCmd { get; } public ReactiveCommand<Unit, Unit> CheckUpdateNCmd { get; }
public ReactiveCommand<Unit, Unit> CheckUpdateV2flyCoreCmd { get; } public ReactiveCommand<Unit, Unit> CheckUpdateV2flyCoreCmd { get; }
//public ReactiveCommand<Unit, Unit> CheckUpdateSagerNetCoreCmd { get; } //public ReactiveCommand<Unit, Unit> CheckUpdateSagerNetCoreCmd { get; }
public ReactiveCommand<Unit, Unit> CheckUpdateXrayCoreCmd { get; } public ReactiveCommand<Unit, Unit> CheckUpdateXrayCoreCmd { get; }
//public ReactiveCommand<Unit, Unit> CheckUpdateClashCoreCmd { get; } //public ReactiveCommand<Unit, Unit> CheckUpdateClashCoreCmd { get; }
//public ReactiveCommand<Unit, Unit> CheckUpdateClashMetaCoreCmd { get; } //public ReactiveCommand<Unit, Unit> CheckUpdateClashMetaCoreCmd { get; }
public ReactiveCommand<Unit, Unit> CheckUpdateSingBoxCoreCmd { get; } public ReactiveCommand<Unit, Unit> CheckUpdateSingBoxCoreCmd { get; }
public ReactiveCommand<Unit, Unit> CheckUpdateGeoCmd { get; } public ReactiveCommand<Unit, Unit> CheckUpdateGeoCmd { get; }
public ReactiveCommand<Unit, Unit> ReloadCmd { get; } public ReactiveCommand<Unit, Unit> ReloadCmd { get; }

View File

@ -1,12 +1,12 @@
<reactiveui:ReactiveWindow <reactiveui:ReactiveWindow
x:Class="v2rayN.Views.AddServerWindow" x:Class="v2rayN.Views.AddServerWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:conv="clr-namespace:v2rayN.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:reactiveui="http://reactiveui.net" xmlns:reactiveui="http://reactiveui.net"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:conv="clr-namespace:v2rayN.Converters"
xmlns:resx="clr-namespace:v2rayN.Resx" xmlns:resx="clr-namespace:v2rayN.Resx"
xmlns:vms="clr-namespace:v2rayN.ViewModels" xmlns:vms="clr-namespace:v2rayN.ViewModels"
Title="{x:Static resx:ResUI.menuServers}" Title="{x:Static resx:ResUI.menuServers}"

View File

@ -328,21 +328,27 @@ namespace v2rayN.Views
case Key.V: case Key.V:
ViewModel?.AddServerViaClipboard(); ViewModel?.AddServerViaClipboard();
break; break;
case Key.P: case Key.P:
ViewModel?.ServerSpeedtest(ESpeedActionType.Ping); ViewModel?.ServerSpeedtest(ESpeedActionType.Ping);
break; break;
case Key.O: case Key.O:
ViewModel?.ServerSpeedtest(ESpeedActionType.Tcping); ViewModel?.ServerSpeedtest(ESpeedActionType.Tcping);
break; break;
case Key.R: case Key.R:
ViewModel?.ServerSpeedtest(ESpeedActionType.Realping); ViewModel?.ServerSpeedtest(ESpeedActionType.Realping);
break; break;
case Key.S: case Key.S:
_ = ViewModel?.ScanScreenTaskAsync(); _ = ViewModel?.ScanScreenTaskAsync();
break; break;
case Key.T: case Key.T:
ViewModel?.ServerSpeedtest(ESpeedActionType.Speedtest); ViewModel?.ServerSpeedtest(ESpeedActionType.Speedtest);
break; break;
case Key.E: case Key.E:
ViewModel?.ServerSpeedtest(ESpeedActionType.Mixedtest); ViewModel?.ServerSpeedtest(ESpeedActionType.Mixedtest);
break; break;
@ -652,4 +658,4 @@ namespace v2rayN.Views
#endregion Drag and Drop #endregion Drag and Drop
} }
} }

View File

@ -309,7 +309,6 @@
Margin="{StaticResource SettingItemMargin}" Margin="{StaticResource SettingItemMargin}"
Style="{StaticResource DefComboBox}" /> Style="{StaticResource DefComboBox}" />
<TextBlock <TextBlock
Grid.Row="15" Grid.Row="15"
Grid.Column="0" Grid.Column="0"
@ -335,10 +334,7 @@
Margin="{StaticResource SettingItemMargin}" Margin="{StaticResource SettingItemMargin}"
materialDesign:HintAssist.Hint="Down" materialDesign:HintAssist.Hint="Down"
Style="{StaticResource DefTextBox}" /> Style="{StaticResource DefTextBox}" />
</StackPanel> </StackPanel>
</Grid> </Grid>
</ScrollViewer> </ScrollViewer>
</TabItem> </TabItem>