Code clean

This commit is contained in:
2dust
2023-04-13 20:34:18 +08:00
parent 52dced5a2a
commit e3be6b76ec
83 changed files with 372 additions and 358 deletions

View File

@@ -1,10 +1,9 @@
<Application
x:Class="ClashN.App"
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:conv="clr-namespace:ClashN.Converters"
xmlns:local="clr-namespace:ClashN"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
ShutdownMode="OnExplicitShutdown"
StartupUri="Views/MainWindow.xaml">
<Application.Resources>
@@ -130,7 +129,5 @@
<Setter Property="FontSize" Value="{DynamicResource StdFontSize2}" />
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
</Application>

View File

@@ -30,7 +30,6 @@ namespace ClashN
{
// Locator.CurrentMutable.RegisterViewsForViewModels(Assembly.GetCallingAssembly());
this.DispatcherUnhandledException += App_DispatcherUnhandledException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
@@ -71,6 +70,7 @@ namespace ClashN
return;
}
}
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
Utils.SaveLog("App_DispatcherUnhandledException", e.Exception);
@@ -90,4 +90,4 @@ namespace ClashN
Utils.SaveLog("TaskScheduler_UnobservedTaskException", e.Exception);
}
}
}
}

View File

@@ -7,4 +7,4 @@ using System.Windows;
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
)]

View File

@@ -71,7 +71,6 @@ namespace ClashN.Base
return (await response.Content.ReadAsStringAsync(), response.Headers);
}
public async Task PutAsync(string url, Dictionary<string, string> headers)
{
var myContent = Utils.ToJson(headers);
@@ -91,6 +90,7 @@ namespace ClashN.Base
await httpClient.PatchAsync(url, byteContent);
}
public async Task DeleteAsync(string url)
{
//var myContent = Utils.ToJson(headers);
@@ -157,9 +157,8 @@ namespace ClashN.Base
}
} while (isMoreToRead);
if (canReportProgress)
progress?.Report(101);
}
}
}
}

View File

@@ -2,7 +2,7 @@
namespace ClashN.Base
{
static class StringEx
internal static class StringEx
{
public static bool BeginWithAny(this string? s, IEnumerable<char> chars)
{
@@ -28,4 +28,4 @@ namespace ClashN.Base
return value == null ? string.Empty : value.Trim();
}
}
}
}

View File

@@ -20,4 +20,4 @@ namespace ClashN.Converters
return null;
}
}
}
}

View File

@@ -1,6 +1,6 @@
namespace ClashN
{
class Global
internal class Global
{
#region
@@ -15,6 +15,7 @@
/// SpeedTestUrl
/// </summary>
public const string SpeedTestUrl = @"http://cachefly.cachefly.net/10mb.test";
public const string SpeedPingTestUrl = @"https://www.google.com/generate_204";
public static readonly List<string> SubConvertUrls = new List<string> {
@@ -23,11 +24,11 @@
@"http://127.0.0.1:25500/sub?target=clash&url={0}",
""
};
public static readonly List<string> SubConvertConfig = new List<string> {
@"https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online.ini"
};
/// <summary>
/// PromotionUrl
/// </summary>
@@ -56,6 +57,7 @@
/// http
/// </summary>
public const string httpProtocol = "http://";
/// <summary>
/// https
/// </summary>
@@ -87,12 +89,13 @@
/// Icon
/// </summary>
public const string CustomIconName = "ClashN.ico";
public const int MinFontSize = 10;
public const int MinFontSize = 10;
public const string StatisticLogOverall = "StatisticLogOverall.json";
public const string IEProxyExceptions = "localhost;127.*;10.*;172.16.*;172.17.*;172.18.*;172.19.*;172.20.*;172.21.*;172.22.*;172.23.*;172.24.*;172.25.*;172.26.*;172.27.*;172.28.*;172.29.*;172.30.*;172.31.*;192.168.*";
public static readonly List<string> IEProxyProtocols = new List<string> {
"{ip}:{http_port}",
"socks={ip}:{socks_port}",
@@ -113,7 +116,7 @@
public static readonly List<string> LogLevel = new List<string> { "debug", "info", "warning", "error", "silent" };
#endregion
#endregion
#region
@@ -135,7 +138,6 @@
get; set;
}
#endregion
#endregion
}
}
}

View File

@@ -9,7 +9,7 @@ namespace ClashN.Handler
/// <summary>
/// 本软件配置文件处理类
/// </summary>
class ConfigProc
internal class ConfigProc
{
private static string configRes = Global.ConfigFileName;
private static readonly object objLock = new object();
@@ -23,7 +23,7 @@ namespace ClashN.Handler
/// <returns></returns>
public static int LoadConfig(ref Config? config)
{
//载入配置文件
//载入配置文件
string result = Utils.LoadResource(Utils.GetConfigPath(configRes));
if (!string.IsNullOrEmpty(result))
{
@@ -116,6 +116,7 @@ namespace ClashN.Handler
LazyConfig.Instance.SetConfig(config);
return 0;
}
/// <summary>
/// 保参数
/// </summary>
@@ -162,7 +163,7 @@ namespace ClashN.Handler
}
}
#endregion
#endregion ConfigHandler
#region Profile
@@ -261,6 +262,7 @@ namespace ClashN.Handler
}
return -1;
}
public static ProfileItem? GetDefaultProfile(ref Config config)
{
if (config.ProfileItems.Count <= 0)
@@ -301,46 +303,46 @@ namespace ClashN.Handler
switch (eMove)
{
case MovementTarget.Top:
{
if (index == 0)
{
return 0;
}
lstProfile[index].sort = lstProfile[0].sort - 1;
if (index == 0)
{
return 0;
}
lstProfile[index].sort = lstProfile[0].sort - 1;
break;
}
break;
}
case MovementTarget.Up:
{
if (index == 0)
{
return 0;
}
lstProfile[index].sort = lstProfile[index - 1].sort - 1;
if (index == 0)
{
return 0;
}
lstProfile[index].sort = lstProfile[index - 1].sort - 1;
break;
}
break;
}
case MovementTarget.Down:
{
if (index == count - 1)
{
return 0;
}
lstProfile[index].sort = lstProfile[index + 1].sort + 1;
if (index == count - 1)
{
return 0;
}
lstProfile[index].sort = lstProfile[index + 1].sort + 1;
break;
}
break;
}
case MovementTarget.Bottom:
{
if (index == count - 1)
{
return 0;
}
lstProfile[index].sort = lstProfile[lstProfile.Count - 1].sort + 1;
if (index == count - 1)
{
return 0;
}
lstProfile[index].sort = lstProfile[lstProfile.Count - 1].sort + 1;
break;
}
break;
}
case MovementTarget.Position:
lstProfile[index].sort = pos * 10 + 1;
break;
@@ -435,7 +437,7 @@ namespace ClashN.Handler
AddProfileCommon(ref config, profileItem);
//TODO auto update via url
//TODO auto update via url
//if (!string.IsNullOrEmpty(profileItem.url))
//{
// var httpClient = new HttpClient();
@@ -464,6 +466,7 @@ namespace ClashN.Handler
case EProfileColName.updateTime:
propertyName = name.ToString();
break;
default:
return -1;
}
@@ -625,7 +628,6 @@ namespace ClashN.Handler
if (AddProfileViaContent(ref config, profileItem, clipboardData) == 0)
{
return 0;
}
else
{
@@ -643,7 +645,7 @@ namespace ClashN.Handler
ToJsonFile(config);
}
#endregion
#endregion Profile
}
}
}

View File

@@ -7,7 +7,7 @@ namespace ClashN.Handler
/// <summary>
/// Core配置文件处理类
/// </summary>
class CoreConfigHandler
internal class CoreConfigHandler
{
/// <summary>
/// 生成配置文件
@@ -26,7 +26,6 @@ namespace ClashN.Handler
msg = ResUI.InitialConfiguration;
try
{
//检查GUI设置
@@ -234,7 +233,6 @@ namespace ClashN.Handler
return;
}
if (blPrepend)
{
lstValue.Reverse();
@@ -252,4 +250,4 @@ namespace ClashN.Handler
}
}
}
}
}

View File

@@ -9,12 +9,12 @@ namespace ClashN.Handler
/// <summary>
/// core进程处理类
/// </summary>
class CoreHandler
internal class CoreHandler
{
private static string coreConfigRes = Global.coreConfigFileName;
private CoreInfo coreInfo;
private Process _process;
Action<bool, string> _updateFunc;
private Action<bool, string> _updateFunc;
public CoreHandler(Action<bool, string> update)
{
@@ -47,7 +47,6 @@ namespace ClashN.Handler
return;
}
SetCore(config, item, out bool blChanged);
string fileName = Utils.GetConfigPath(coreConfigRes);
if (CoreConfigHandler.GenerateClientConfig(item, fileName, false, out string msg) != 0)
@@ -71,7 +70,6 @@ namespace ClashN.Handler
}
}
/// <summary>
/// Core重启
/// </summary>
@@ -143,6 +141,7 @@ namespace ClashN.Handler
Utils.SaveLog(ex.Message, ex);
}
}
/// <summary>
/// Core停止
/// </summary>
@@ -294,4 +293,4 @@ namespace ClashN.Handler
return 0;
}
}
}
}

View File

@@ -11,11 +11,11 @@ namespace ClashN.Handler
/// <summary>
///Download
/// </summary>
class DownloadHandle
internal class DownloadHandle
{
public event EventHandler<ResultEventArgs>? UpdateCompleted;
public event ErrorEventHandler? Error;
public event ErrorEventHandler? Error;
public class ResultEventArgs : EventArgs
{
@@ -68,7 +68,7 @@ namespace ClashN.Handler
/// <summary>
/// DownloadString
/// </summary>
/// </summary>
/// <param name="url"></param>
public async Task<(string, HttpResponseHeaders)?> DownloadStringAsync(string url, bool blProxy, string userAgent)
{
@@ -174,4 +174,4 @@ namespace ClashN.Handler
return false;
}
}
}
}

View File

@@ -15,16 +15,19 @@ namespace ClashN.Handler
{
get { return _instance.Value; }
}
public void SetConfig(Config config)
{
_config = config;
}
public Config Config => _config;
public void SetProxies(Dictionary<String, ProxiesItem> proxies)
{
_proxies = proxies;
}
public Dictionary<String, ProxiesItem> GetProxies()
{
return _proxies;
@@ -39,7 +42,6 @@ namespace ClashN.Handler
return (CoreKind)profileItem.coreType;
}
return CoreKind.Clash;
}
public CoreInfo GetCoreInfo(CoreKind coreType)
@@ -99,7 +101,6 @@ namespace ClashN.Handler
coreDownloadUrl64 = Global.clashCoreUrl + "/download/{0}/clash-windows-amd64-{0}.zip",
match = "Clash"
});
}
}
}
}

View File

@@ -15,10 +15,12 @@ namespace ClashN.Handler
public sealed class MainFormHandler
{
private static readonly Lazy<MainFormHandler> instance = new Lazy<MainFormHandler>(() => new MainFormHandler());
public static MainFormHandler Instance
{
get { return instance.Value; }
}
public Icon GetNotifyIcon(Config config)
{
try
@@ -35,10 +37,13 @@ namespace ClashN.Handler
{
case 0:
return Properties.Resources.NotifyIcon1;
case 1:
return Properties.Resources.NotifyIcon2;
case 2:
return Properties.Resources.NotifyIcon3;
case 3:
return Properties.Resources.NotifyIcon2;
}
@@ -294,7 +299,6 @@ namespace ClashN.Handler
Utils.RegWriteValue(Global.MyRegPathClasses, "", "URL:clash");
Utils.RegWriteValue(Global.MyRegPathClasses, "URL Protocol", "");
Utils.RegWriteValue($"{Global.MyRegPathClasses}\\shell\\open\\command", "", $"\"{Utils.GetExePath()}\" \"%1\"");
});
}
@@ -362,6 +366,7 @@ namespace ClashN.Handler
Utils.SaveLog(ex.Message, ex);
}
}
public void GetClashConnections(Config config, Action<ClashConnections> update)
{
Task.Run(() => GetClashConnectionsAsync(config, update));

View File

@@ -18,16 +18,16 @@ namespace ClashN.Handler
{
_snackbarMessageQueue?.Enqueue(content);
}
public void SendMessage(string msg)
{
MessageBus.Current.SendMessage(msg, "MsgView");
}
public void SendMessage(string msg, bool time)
{
msg = $"{DateTime.Now} {msg}";
MessageBus.Current.SendMessage(msg, "MsgView");
}
}
}
}

View File

@@ -3,7 +3,7 @@ using System.Runtime.InteropServices;
namespace ClashN.Handler
{
class ProxySetting
internal class ProxySetting
{
public static bool UnsetProxy()
{
@@ -62,7 +62,6 @@ namespace ClashN.Handler
list.dwOptionCount = options.Length;
list.dwOptionError = 0;
int optSize = Marshal.SizeOf(typeof(InternetConnectionOption));
// make a pointer out of all that ...
IntPtr optionsPtr = Marshal.AllocCoTaskMem(optSize * options.Length);
@@ -106,8 +105,8 @@ namespace ClashN.Handler
return (returnvalue < 0);
}
#region WinInet structures
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct InternetPerConnOptionList
{
@@ -115,6 +114,7 @@ namespace ClashN.Handler
public IntPtr szConnection; // connection name to set/query options
public int dwOptionCount; // number of options to set/query
public int dwOptionError; // on error, which option failed
//[MarshalAs(UnmanagedType.)]
public IntPtr options;
};
@@ -122,9 +122,10 @@ namespace ClashN.Handler
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct InternetConnectionOption
{
static readonly int Size;
private static readonly int Size;
public PerConnOption m_Option;
public InternetConnectionOptionValue m_Value;
static InternetConnectionOption()
{
Size = Marshal.SizeOf(typeof(InternetConnectionOption));
@@ -137,15 +138,19 @@ namespace ClashN.Handler
// Fields
[FieldOffset(0)]
public System.Runtime.InteropServices.ComTypes.FILETIME m_FileTime;
[FieldOffset(0)]
public int m_Int;
[FieldOffset(0)]
public IntPtr m_StringPtr;
}
}
#endregion
#endregion WinInet structures
#region WinInet enums
//
// options manifests for Internet{Query|Set}Option
//
@@ -159,11 +164,10 @@ namespace ClashN.Handler
//
public enum PerConnOption
{
INTERNET_PER_CONN_FLAGS = 1, // Sets or retrieves the connection type. The Value member will contain one or more of the values from PerConnFlags
INTERNET_PER_CONN_PROXY_SERVER = 2, // Sets or retrieves a string containing the proxy servers.
INTERNET_PER_CONN_PROXY_BYPASS = 3, // Sets or retrieves a string containing the URLs that do not use the proxy server.
INTERNET_PER_CONN_AUTOCONFIG_URL = 4//, // Sets or retrieves a string containing the URL to the automatic configuration script.
INTERNET_PER_CONN_FLAGS = 1, // Sets or retrieves the connection type. The Value member will contain one or more of the values from PerConnFlags
INTERNET_PER_CONN_PROXY_SERVER = 2, // Sets or retrieves a string containing the proxy servers.
INTERNET_PER_CONN_PROXY_BYPASS = 3, // Sets or retrieves a string containing the URLs that do not use the proxy server.
INTERNET_PER_CONN_AUTOCONFIG_URL = 4//, // Sets or retrieves a string containing the URL to the automatic configuration script.
}
//
@@ -177,7 +181,8 @@ namespace ClashN.Handler
PROXY_TYPE_AUTO_PROXY_URL = 0x00000004, // autoproxy URL
PROXY_TYPE_AUTO_DETECT = 0x00000008 // use autoproxy detection
}
#endregion
#endregion WinInet enums
internal static class NativeMethods
{
@@ -201,6 +206,7 @@ namespace ClashN.Handler
return false;
}
}
//获得代理的IP和端口
public static string GetProxyProxyServer()
{
@@ -208,7 +214,6 @@ namespace ClashN.Handler
string ProxyServer = rk.GetValue("ProxyServer").ToString();
rk.Close();
return ProxyServer;
}
}
}
}

View File

@@ -25,4 +25,4 @@ namespace ClashN.Handler
}
}
}
}
}

View File

@@ -5,12 +5,12 @@ using System.Net.Sockets;
namespace ClashN.Handler
{
class SpeedtestHandler
internal class SpeedtestHandler
{
private Config _config;
private CoreHandler _coreHandler;
private List<ServerTestItem> _selecteds;
Action<string, string> _updateFunc;
private Action<string, string> _updateFunc;
public SpeedtestHandler(ref Config config)
{
@@ -50,7 +50,6 @@ namespace ClashN.Handler
{
foreach (var it in _selecteds)
{
try
{
updateFun(it);
@@ -69,7 +68,6 @@ namespace ClashN.Handler
}
}
private void RunPing()
{
RunPingSub((ServerTestItem it) =>
@@ -90,7 +88,6 @@ namespace ClashN.Handler
});
}
public int RunAvailabilityCheck() // alias: isLive
{
try
@@ -187,6 +184,7 @@ namespace ClashN.Handler
}
return msg;
}
private string FormatOut(object time, string unit)
{
if (time.ToString().Equals("-1"))
@@ -196,4 +194,4 @@ namespace ClashN.Handler
return string.Format("{0}{1}", time, unit).PadLeft(8, ' ');
}
}
}
}

View File

@@ -4,15 +4,17 @@ using System.Text;
namespace ClashN.Handler
{
class StatisticsHandler
internal class StatisticsHandler
{
private Config config_;
//private ServerStatistics serverStatistics_;
private bool exitFlag_;
private ClientWebSocket webSocket = null;
string url = string.Empty;
Action<ulong, ulong> updateFunc_;
private ClientWebSocket webSocket = null;
private string url = string.Empty;
private Action<ulong, ulong> updateFunc_;
private bool Enable
{
@@ -45,18 +47,15 @@ namespace ClashN.Handler
try
{
url = $"ws://{Global.Loopback}:{config_.ApiPort}/traffic";
if (webSocket == null)
{
webSocket = new ClientWebSocket();
await webSocket.ConnectAsync(new Uri(url), CancellationToken.None);
}
}
catch { }
}
public void Close()
@@ -244,6 +243,5 @@ namespace ClashN.Handler
//Utils.SaveLog(ex.Message, ex);
}
}
}
}
}

View File

@@ -10,7 +10,7 @@ namespace ClashN.Handler
{
public static class SysProxyHandle
{
enum RET_ERRORS : int
private enum RET_ERRORS : int
{
RET_NO_ERROR = 0,
INVALID_FORMAT = 1,
@@ -33,7 +33,6 @@ namespace ClashN.Handler
}
}
public static bool UpdateSysProxy(Config config, bool forceDisable)
{
var type = config.SysProxyType;
@@ -219,7 +218,5 @@ namespace ClashN.Handler
}
}
}
}
}
}

View File

@@ -11,9 +11,9 @@ using System.Windows.Forms;
namespace ClashN.Handler
{
class UpdateHandle
internal class UpdateHandle
{
Action<bool, string> _updateFunc;
private Action<bool, string> _updateFunc;
private Config _config;
public event EventHandler<ResultEventArgs> AbsoluteCompleted;
@@ -100,7 +100,6 @@ namespace ClashN.Handler
CheckUpdateAsync(CoreKind.ClashN);
}
public void CheckUpdateCore(CoreKind type, Config config, Action<bool, string> update)
{
_config = config;
@@ -156,7 +155,6 @@ namespace ClashN.Handler
CheckUpdateAsync(type);
}
public void UpdateSubscriptionProcess(Config config, bool blProxy, List<ProfileItem> profileItems, Action<bool, string> update)
{
_config = config;
@@ -277,7 +275,6 @@ namespace ClashN.Handler
}
}
_updateFunc(false, $"-------------------------------------------------------");
}
//restore system proxy
//if (bSysProxyType)
@@ -288,6 +285,7 @@ namespace ClashN.Handler
_updateFunc(true, $"{ResUI.MsgUpdateSubscriptionEnd}");
});
}
private ulong ParseRemoteInfo(Dictionary<string, string> dicInfo, string key)
{
return dicInfo.ContainsKey(key) ? Convert.ToUInt64(dicInfo?[key]) : 0;
@@ -420,6 +418,7 @@ namespace ClashN.Handler
return "";
}
}
private void responseHandler(CoreKind type, string redirectUrl)
{
try
@@ -507,6 +506,7 @@ namespace ClashN.Handler
var statistics = new SpeedtestHandler(ref _config);
return statistics.RunAvailabilityCheck();
}
#endregion
#endregion private
}
}
}

View File

@@ -14,6 +14,7 @@
public string now { get; set; }
public int delay { get; set; }
}
public class HistoryItem
{
public string time { get; set; }

View File

@@ -1,8 +1,8 @@
namespace ClashN.Mode
{
class ComboItem
internal class ComboItem
{
public int ID { get; set; }
public string Text { get; set; }
}
}
}

View File

@@ -9,6 +9,7 @@ namespace ClashN.Mode
public class Config
{
#region property
public int MixedPort { get; set; } = 7888;
public int HttpPort { get; set; } = 7890;
@@ -49,7 +50,7 @@ namespace ClashN.Mode
public bool EnableTun { get; set; }
#endregion
#endregion property
#region other entities
@@ -61,9 +62,9 @@ namespace ClashN.Mode
public List<KeyShortcut> globalHotkeys { get; } = new List<KeyShortcut>();
#endregion
#endregion other entities
#region function
#region function
public int FindIndexId(string id)
{
@@ -92,8 +93,7 @@ namespace ClashN.Mode
return false;
}
#endregion
#endregion function
}
[Serializable]
@@ -113,13 +113,14 @@ namespace ClashN.Mode
}
#region function
public string GetSummary()
{
string summary = string.Format("{0}", remarks);
return summary;
}
#endregion
#endregion function
public string indexId { get; set; }
@@ -167,7 +168,6 @@ namespace ClashN.Mode
public int connectionsSorting { get; set; }
public bool connectionsAutoRefresh { get; set; }
}
[Serializable]
@@ -178,4 +178,4 @@ namespace ClashN.Mode
public string speedPingTestUrl { get; set; } = string.Empty;
public string defIEProxyExceptions { get; set; } = string.Empty;
}
}
}

View File

@@ -2,7 +2,6 @@
{
public class ConnectionModel
{
public string id { get; set; }
public string network { get; set; }
public string type { get; set; }
@@ -15,4 +14,4 @@
public string elapsed { get; set; }
public string chain { get; set; }
}
}
}

View File

@@ -19,4 +19,4 @@
public string match { get; set; }
}
}
}

View File

@@ -1,5 +1,4 @@

namespace ClashN.Mode
namespace ClashN.Mode
{
public enum CoreKind
{
@@ -8,4 +7,4 @@ namespace ClashN.Mode
ClashPremium = 3,
ClashN = 99
}
}
}

View File

@@ -1,5 +1,4 @@

namespace ClashN.Mode
namespace ClashN.Mode
{
public enum EProfileColName
{

View File

@@ -1,5 +1,4 @@

namespace ClashN.Mode
namespace ClashN.Mode
{
public enum ERuleMode
{
@@ -8,4 +7,4 @@ namespace ClashN.Mode
Direct = 2,
Unchanged = 3
}
}
}

View File

@@ -1,5 +1,4 @@

namespace ClashN.Mode
namespace ClashN.Mode
{
public enum ESpeedActionType
{
@@ -8,4 +7,4 @@ namespace ClashN.Mode
Realping,
Speedtest
}
}
}

View File

@@ -1,5 +1,4 @@

namespace ClashN.Mode
namespace ClashN.Mode
{
public enum GlobalHotkeyAction
{
@@ -9,4 +8,4 @@ namespace ClashN.Mode
SystemProxyUnchanged = 3,
SystemProxyPac = 4,
}
}
}

View File

@@ -15,4 +15,4 @@ namespace ClashN.Mode
public Keys? KeyCode { get; set; }
}
}
}

View File

@@ -1,5 +1,4 @@

namespace ClashN.Mode
namespace ClashN.Mode
{
public enum MovementTarget
{
@@ -9,4 +8,4 @@ namespace ClashN.Mode
Bottom = 4,
Position = 5
}
}
}

View File

@@ -1,12 +1,11 @@
using ClashN.Base;
namespace ClashN.Mode
namespace ClashN.Mode
{
public class ProfileItemModel : ProfileItem
{
public bool IsActive { get; set; }
public bool HasUrl => !string.IsNullOrEmpty(url);
public bool HasAddress => !string.IsNullOrEmpty(address);
public string StrUpdateTime
{
get
@@ -19,8 +18,10 @@ namespace ClashN.Mode
return dateTime.AddSeconds(updateTime).ToLocalTime().ToString("MM-dd HH:mm");
}
}
public string TrafficUsed => Utils.HumanFy(uploadRemote + downloadRemote);
public string TrafficTotal => totalRemote <= 0 ? "∞" : Utils.HumanFy(totalRemote);
public string StrExpireTime
{
get
@@ -34,4 +35,4 @@ namespace ClashN.Mode
}
}
}
}
}

View File

@@ -7,16 +7,20 @@ namespace ClashN.Mode
{
[Reactive]
public string name { get; set; }
[Reactive]
public string type { get; set; }
[Reactive]
public string now { get; set; }
[Reactive]
public int delay { get; set; }
[Reactive]
public string delayName { get; set; }
[Reactive]
public bool isActive { get; set; }
}
}

View File

@@ -16,22 +16,27 @@
{
get; set;
}
public ulong totalUp
{
get; set;
}
public ulong totalDown
{
get; set;
}
public ulong todayUp
{
get; set;
}
public ulong todayDown
{
get; set;
}
public long dateNow
{
get; set;
@@ -45,9 +50,10 @@
{
get; set;
}
public ulong down
{
get; set;
}
}
}
}

View File

@@ -1,11 +1,11 @@
namespace ClashN.Mode
{
[Serializable]
class ServerTestItem
internal class ServerTestItem
{
public string IndexId { get; set; }
public string Address { get; set; }
public int Port { get; set; }
public bool AllowTest { get; set; }
}
}
}

View File

@@ -1,5 +1,4 @@

namespace ClashN.Mode
namespace ClashN.Mode
{
public enum SysProxyType
{
@@ -8,4 +7,4 @@ namespace ClashN.Mode
Unchanged = 2,
Pac = 3
}
}
}

View File

@@ -67,6 +67,7 @@ namespace ClashN.Tool
throw ex;
}
}
public static bool ZipExtractToFile(string fileName, string toPath, string ignoredName)
{
try
@@ -128,4 +129,4 @@ namespace ClashN.Tool
return true;
}
}
}
}

View File

@@ -1,13 +1,13 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace ClashN
{
/*
* See:
* http://stackoverflow.com/questions/6266820/working-example-of-createjobobject-setinformationjobobject-pinvoke-in-net
*/
public class Job : IDisposable
{
private IntPtr handle = IntPtr.Zero;
@@ -95,7 +95,7 @@ namespace ClashN
Dispose(false);
}
#endregion
#endregion IDisposable
#region Interop
@@ -112,13 +112,13 @@ namespace ClashN
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool CloseHandle(IntPtr hObject);
#endregion
#endregion Interop
}
#region Helper classes
[StructLayout(LayoutKind.Sequential)]
struct IO_COUNTERS
internal struct IO_COUNTERS
{
public UInt64 ReadOperationCount;
public UInt64 WriteOperationCount;
@@ -128,9 +128,8 @@ namespace ClashN
public UInt64 OtherTransferCount;
}
[StructLayout(LayoutKind.Sequential)]
struct JOBOBJECT_BASIC_LIMIT_INFORMATION
internal struct JOBOBJECT_BASIC_LIMIT_INFORMATION
{
public Int64 PerProcessUserTimeLimit;
public Int64 PerJobUserTimeLimit;
@@ -152,7 +151,7 @@ namespace ClashN
}
[StructLayout(LayoutKind.Sequential)]
struct JOBOBJECT_EXTENDED_LIMIT_INFORMATION
internal struct JOBOBJECT_EXTENDED_LIMIT_INFORMATION
{
public JOBOBJECT_BASIC_LIMIT_INFORMATION BasicLimitInformation;
public IO_COUNTERS IoInfo;
@@ -173,5 +172,5 @@ namespace ClashN
GroupInformation = 11
}
#endregion
}
#endregion Helper classes
}

View File

@@ -44,4 +44,4 @@ namespace ClashN.Tool
});
}
}
}
}

View File

@@ -15,8 +15,7 @@ namespace ClashN.Tool
return OrderBy<T>(query, propertyName, true);
}
static IOrderedQueryable<T> OrderBy<T>(IQueryable<T> query, string propertyName, bool isDesc)
private static IOrderedQueryable<T> OrderBy<T>(IQueryable<T> query, string propertyName, bool isDesc)
{
string methodname = (isDesc) ? "OrderByDescendingInternal" : "OrderByInternal";
@@ -38,7 +37,7 @@ namespace ClashN.Tool
return query.OrderByDescending(GetLambda<T, TProp>(memberProperty));
}
static Expression<Func<T, TProp>> GetLambda<T, TProp>(PropertyInfo memberProperty)
private static Expression<Func<T, TProp>> GetLambda<T, TProp>(PropertyInfo memberProperty)
{
if (memberProperty.PropertyType != typeof(TProp))
throw new Exception();
@@ -49,4 +48,4 @@ namespace ClashN.Tool
return lamba;
}
}
}
}

View File

@@ -2,16 +2,18 @@
namespace ClashN
{
class UI
internal class UI
{
public static void Show(string msg)
{
MessageBox.Show(msg, "ClashN", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
public static void ShowWarning(string msg)
{
MessageBox.Show(msg, "ClashN", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
public static void ShowError(string msg)
{
MessageBox.Show(msg, "ClashN", MessageBoxButtons.OK, MessageBoxIcon.Error);
@@ -38,8 +40,5 @@ namespace ClashN
// return Common.ResourceManager.GetString(key, cultureInfo);
// }
//}
}
}
}

View File

@@ -29,9 +29,8 @@ using ZXing.Windows.Compatibility;
namespace ClashN
{
static class Utils
internal static class Utils
{
#region Json操作
/// <summary>
@@ -59,7 +58,6 @@ namespace ClashN
return result;
}
/// <summary>
/// 取得存储资源
/// </summary>
@@ -171,7 +169,8 @@ namespace ClashN
return null;
}
}
#endregion
#endregion Json操作
#region
@@ -203,6 +202,7 @@ namespace ClashN
return string.Empty;
}
}
/// <summary>
/// 逗号分隔的字符串,转List<string>
/// </summary>
@@ -288,6 +288,7 @@ namespace ClashN
return 0;
}
}
public static bool ToBool(object obj)
{
try
@@ -369,18 +370,17 @@ namespace ClashN
return $"{string.Format("{0:f1}", result)} {unit}";
}
public static string UrlEncode(string url)
{
return Uri.EscapeDataString(url);
}
public static string UrlDecode(string url)
{
return HttpUtility.UrlDecode(url);
}
#endregion
#endregion
#region
@@ -424,7 +424,7 @@ namespace ClashN
/// <summary>
/// 验证IP地址是否合法
/// </summary>
/// <param name="ip"></param>
/// <param name="ip"></param>
public static bool IsIP(string ip)
{
//如果为空
@@ -449,7 +449,6 @@ namespace ClashN
}
}
//模式字符串
string pattern = @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$";
@@ -460,7 +459,7 @@ namespace ClashN
/// <summary>
/// 验证Domain地址是否合法
/// </summary>
/// <param name="domain"></param>
/// <param name="domain"></param>
public static bool IsDomain(string domain)
{
//如果为空
@@ -483,7 +482,7 @@ namespace ClashN
/// 验证输入字符串是否与模式字符串匹配匹配返回true
/// </summary>
/// <param name="input">输入字符串</param>
/// <param name="pattern">模式字符串</param>
/// <param name="pattern">模式字符串</param>
public static bool IsMatch(string input, string pattern)
{
return Regex.IsMatch(input, pattern, RegexOptions.IgnoreCase);
@@ -498,8 +497,10 @@ namespace ClashN
{
case AddressFamily.InterNetwork:
return false;
case AddressFamily.InterNetworkV6:
return true;
default:
return false;
}
@@ -507,11 +508,12 @@ namespace ClashN
return false;
}
#endregion
#endregion
#region
private static string autoRunName = "clashNAutoRun";
private static string autoRunRegPath
{
get
@@ -729,7 +731,7 @@ namespace ClashN
}
}
#endregion
#endregion
#region
@@ -832,7 +834,8 @@ namespace ClashN
}
return inUse;
}
#endregion
#endregion
#region
@@ -895,7 +898,6 @@ namespace ClashN
string? strData = null;
try
{
IDataObject data = Clipboard.GetDataObject();
if (data.GetDataPresent(DataFormats.UnicodeText))
{
@@ -931,7 +933,6 @@ namespace ClashN
{
if (IsNullOrEmpty(strData))
{
Clipboard.Clear();
}
else
@@ -1042,7 +1043,7 @@ namespace ClashN
DwmSetWindowAttribute(hWnd, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, ref attribute, attributeSize);
}
#endregion
#endregion
#region TempPath
@@ -1085,6 +1086,7 @@ namespace ClashN
}
return Path.Combine(_tempPath, filename);
}
public static string GetConfigPath(string filename = "")
{
string _tempPath = Path.Combine(StartupPath(), "guiConfigs");
@@ -1119,6 +1121,7 @@ namespace ClashN
}
return Path.Combine(_tempPath, filename);
}
public static string GetFontsPath(string filename = "")
{
string _tempPath = Path.Combine(StartupPath(), "guiFonts");
@@ -1135,7 +1138,8 @@ namespace ClashN
return Path.Combine(_tempPath, filename);
}
}
#endregion
#endregion TempPath
#region Log
@@ -1144,6 +1148,7 @@ namespace ClashN
var logger = LogManager.GetLogger("Log1");
logger.Info(strContent);
}
public static void SaveLog(string strTitle, Exception ex)
{
var logger = LogManager.GetLogger("Log2");
@@ -1155,8 +1160,7 @@ namespace ClashN
}
}
#endregion
#endregion Log
#region scan screen
@@ -1213,7 +1217,7 @@ namespace ClashN
return string.Empty;
}
#endregion
#endregion scan screen
#region YAML
@@ -1262,7 +1266,8 @@ namespace ClashN
}
return result;
}
#endregion
#endregion YAML
#region Interop
@@ -1276,7 +1281,7 @@ namespace ClashN
[DllImport("dwmapi.dll")]
public static extern int DwmSetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE attribute, ref int attributeValue, uint attributeSize);
#endregion
#endregion Interop
public static System.Windows.Forms.IWin32Window WpfWindow2WinFormWin32Window(this System.Windows.Window wpfWindow)
{
@@ -1294,4 +1299,4 @@ namespace ClashN
public IntPtr Handle { get; }
}
}
}
}

View File

@@ -1,4 +1,3 @@
using ClashN.Base;
using ClashN.Handler;
using ClashN.Mode;
using DynamicData;
@@ -21,8 +20,6 @@ namespace ClashN.ViewModels
_config = LazyConfig.Instance.Config;
}
private NoticeHandler? _noticeHandler;
private IObservableCollection<ConnectionModel> _connectionItems = new ObservableCollectionExtended<ConnectionModel>();
@@ -30,11 +27,13 @@ namespace ClashN.ViewModels
[Reactive]
public ConnectionModel SelectedSource { get; set; }
public ReactiveCommand<Unit, Unit> ConnectionCloseCmd { get; }
public ReactiveCommand<Unit, Unit> ConnectionCloseAllCmd { get; }
[Reactive]
public int SortingSelected { get; set; }
[Reactive]
public bool AutoRefresh { get; set; }
@@ -75,7 +74,7 @@ namespace ClashN.ViewModels
Init();
}
void DoSortingSelected(bool c)
private void DoSortingSelected(bool c)
{
if (!c)
{
@@ -100,7 +99,6 @@ namespace ClashN.ViewModels
}
});
//Task.Run(() =>
//{
// while (true)
@@ -164,18 +162,23 @@ namespace ClashN.ViewModels
case 0:
lstModel = lstModel.OrderBy(t => t.upload / t.time).ToList();
break;
case 1:
lstModel = lstModel.OrderBy(t => t.download / t.time).ToList();
break;
case 2:
lstModel = lstModel.OrderBy(t => t.upload).ToList();
break;
case 3:
lstModel = lstModel.OrderBy(t => t.download).ToList();
break;
case 4:
lstModel = lstModel.OrderBy(t => t.time).ToList();
break;
case 5:
lstModel = lstModel.OrderBy(t => t.host).ToList();
break;

View File

@@ -6,7 +6,6 @@ namespace ClashN.ViewModels
{
public DashboardViewModel()
{
}
}
}
}

View File

@@ -48,6 +48,7 @@ namespace ClashN.ViewModels
};
(new UpdateHandle()).CheckUpdateGuiN(_config, _updateUI);
}
private void CheckUpdateCore(CoreKind type)
{
void _updateUI(bool success, string msg)
@@ -76,7 +77,6 @@ namespace ClashN.ViewModels
}
};
(new UpdateHandle()).CheckUpdateCore(type, _config, _updateUI);
}
}
}
}

View File

@@ -7,10 +7,13 @@ namespace ClashN.ViewModels
{
[Reactive]
public int SortingSelected { get; set; }
[Reactive]
public bool AutoRefresh { get; set; }
[Reactive]
public string MsgFilter { get; set; }
[Reactive]
public int LineCount { get; set; }
@@ -21,4 +24,4 @@ namespace ClashN.ViewModels
LineCount = 1000;
}
}
}
}

View File

@@ -1,4 +1,3 @@
using ClashN.Base;
using ClashN.Handler;
using ClashN.Mode;
using ClashN.Views;
@@ -29,8 +28,10 @@ namespace ClashN.ViewModels
private bool blFirst = true;
#region Views
//public DashboardView GetDashboardView { get; }
public ProxiesView GetProxyView { get; }
public ProfilesView GetProfilesView { get; }
public LogsView GetLogsView { get; }
public ConnectionsView GetConnectionsView { get; }
@@ -40,43 +41,57 @@ namespace ClashN.ViewModels
[Reactive]
public string SpeedUpload { get; set; } = "0.00";
[Reactive]
public string SpeedDownload { get; set; } = "0.00";
#endregion
#endregion Views
#region System Proxy
#region System Proxy
[Reactive]
public bool BlSystemProxyClear { get; set; }
[Reactive]
public bool BlSystemProxySet { get; set; }
[Reactive]
public bool BlSystemProxyNothing { get; set; }
[Reactive]
public bool BlSystemProxyPac { get; set; }
public ReactiveCommand<Unit, Unit> SystemProxyClearCmd { get; }
public ReactiveCommand<Unit, Unit> SystemProxySetCmd { get; }
public ReactiveCommand<Unit, Unit> SystemProxyNothingCmd { get; }
public ReactiveCommand<Unit, Unit> SystemProxyPacCmd { get; }
#endregion
#endregion System Proxy
#region Rule mode
[Reactive]
public bool BlModeRule { get; set; }
[Reactive]
public bool BlModeGlobal { get; set; }
[Reactive]
public bool BlModeDirect { get; set; }
[Reactive]
public bool BlModeNothing { get; set; }
public ReactiveCommand<Unit, Unit> ModeRuleCmd { get; }
public ReactiveCommand<Unit, Unit> ModeGlobalCmd { get; }
public ReactiveCommand<Unit, Unit> ModeDirectCmd { get; }
public ReactiveCommand<Unit, Unit> ModeNothingCmd { get; }
#endregion
#endregion Rule mode
#region Other
public ReactiveCommand<Unit, Unit> AddProfileViaScanCmd { get; }
public ReactiveCommand<Unit, Unit> SubUpdateCmd { get; }
public ReactiveCommand<Unit, Unit> SubUpdateViaProxyCmd { get; }
@@ -84,9 +99,11 @@ namespace ClashN.ViewModels
public ReactiveCommand<Unit, Unit> ReloadCmd { get; }
public ReactiveCommand<Unit, Unit> NotifyLeftClickCmd { get; }
[Reactive]
public Icon NotifyIcon { get; set; }
#endregion
#endregion Other
#region Init
@@ -191,6 +208,7 @@ namespace ClashN.ViewModels
Global.ShowInTaskbar = true;//Application.Current.MainWindow.ShowInTaskbar;
}
private void OnProgramStarted(object state, bool timeout)
{
Application.Current.Dispatcher.Invoke((Action)(() =>
@@ -247,15 +265,19 @@ namespace ClashN.ViewModels
case (int)GlobalHotkeyAction.ShowForm:
ShowHideWindow(null);
break;
case (int)GlobalHotkeyAction.SystemProxyClear:
SetListenerType(SysProxyType.ForcedClear);
break;
case (int)GlobalHotkeyAction.SystemProxySet:
SetListenerType(SysProxyType.ForcedChange);
break;
case (int)GlobalHotkeyAction.SystemProxyUnchanged:
SetListenerType(SysProxyType.Unchanged);
break;
case (int)GlobalHotkeyAction.SystemProxyPac:
SetListenerType(SysProxyType.Pac);
break;
@@ -265,8 +287,6 @@ namespace ClashN.ViewModels
private void Init()
{
MainFormHandler.Instance.BackupGuiNConfig(_config, true);
MainFormHandler.Instance.InitRegister(_config);
@@ -283,7 +303,6 @@ namespace ClashN.ViewModels
OnProgramStarted("shown", true);
_ = LoadCore();
}
private void UpdateHandler(bool notify, string msg)
@@ -298,6 +317,7 @@ namespace ClashN.ViewModels
_noticeHandler?.SendMessage(msg);
}
}
private async void UpdateTaskHandler(bool success, string msg)
{
_noticeHandler?.SendMessage(msg);
@@ -307,6 +327,7 @@ namespace ClashN.ViewModels
await LoadCore();
}
}
private void UpdateStatisticsHandler(ulong up, ulong down)
{
try
@@ -327,7 +348,8 @@ namespace ClashN.ViewModels
Utils.SaveLog(ex.Message, ex);
}
}
#endregion
#endregion Init
#region Core
@@ -365,7 +387,8 @@ namespace ClashN.ViewModels
coreHandler.CoreStop();
}
#endregion
#endregion Core
#region System proxy and Rule mode
@@ -430,7 +453,8 @@ namespace ClashN.ViewModels
MainFormHandler.Instance.ClashConfigUpdate(headers);
}
}
#endregion
#endregion System proxy and Rule mode
#region UI
@@ -493,6 +517,7 @@ namespace ClashN.ViewModels
Application.Current.MainWindow.Height = SystemInformation.WorkingArea.Height * 96 / g.DpiY;
}
}
private void StorageUI()
{
_config.UiItem.mainWidth = Application.Current.MainWindow.Width;
@@ -508,6 +533,7 @@ namespace ClashN.ViewModels
Utils.SetDarkBorder(Application.Current.MainWindow, isDarkTheme);
}
public void ChangePrimaryColor(System.Windows.Media.Color color)
{
// var Swatches = new SwatchesProvider().Swatches;
@@ -521,6 +547,6 @@ namespace ClashN.ViewModels
_paletteHelper.SetTheme(theme);
}
#endregion
#endregion UI
}
}
}

View File

@@ -1,4 +1,3 @@
using ClashN.Base;
using ClashN.Handler;
using ClashN.Mode;
using ClashN.Resx;
@@ -21,10 +20,10 @@ namespace ClashN.ViewModels
[Reactive]
public ProfileItem SelectedSource { get; set; }
[Reactive]
public string CoreType { get; set; }
public ReactiveCommand<Unit, Unit> BrowseProfileCmd { get; }
public ReactiveCommand<Unit, Unit> EditProfileCmd { get; }
public ReactiveCommand<Unit, Unit> SaveProfileCmd { get; }
@@ -169,4 +168,4 @@ namespace ClashN.ViewModels
}
}
}
}
}

View File

@@ -1,4 +1,3 @@
using ClashN.Base;
using ClashN.Handler;
using ClashN.Mode;
using ClashN.Resx;
@@ -9,7 +8,6 @@ using MaterialDesignThemes.Wpf;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Splat;
using System;
using System.IO;
using System.Reactive;
using System.Windows.Forms;
@@ -45,7 +43,6 @@ namespace ClashN.ViewModels
public ReactiveCommand<Unit, Unit> ProfileReloadCmd { get; }
public ReactiveCommand<Unit, Unit> ProfileQrcodeCmd { get; }
[Reactive]
public ProfileItemModel SelectedSource { get; set; }
@@ -95,22 +92,18 @@ namespace ClashN.ViewModels
SubUpdateCmd = ReactiveCommand.Create(() =>
{
UpdateSubscriptionProcess(false, false);
});
SubUpdateSelectedCmd = ReactiveCommand.Create(() =>
{
UpdateSubscriptionProcess(false, true);
}, canEditRemove);
SubUpdateViaProxyCmd = ReactiveCommand.Create(() =>
{
UpdateSubscriptionProcess(true, false);
});
SubUpdateSelectedViaProxyCmd = ReactiveCommand.Create(() =>
{
UpdateSubscriptionProcess(true, true);
}, canEditRemove);
//Profile other
@@ -217,6 +210,7 @@ namespace ClashN.ViewModels
}
}
}
public void AddProfilesViaClipboard(bool bClear)
{
string? clipboardData = Utils.GetClipboardData();
@@ -295,6 +289,7 @@ namespace ClashN.ViewModels
Locator.Current.GetService<MainWindowViewModel>()?.LoadCore();
}
private void CloneProfile()
{
var item = _config.GetProfileItem(SelectedSource.indexId);
@@ -308,6 +303,7 @@ namespace ClashN.ViewModels
RefreshProfiles();
}
}
public void SetDefaultProfile()
{
if (string.IsNullOrEmpty(SelectedSource?.indexId))
@@ -351,7 +347,6 @@ namespace ClashN.ViewModels
_profileItems.Clear();
_profileItems.AddRange(lstModel);
}));
}
public void MoveProfile(int startIndex, ProfileItemModel targetItem)
@@ -380,12 +375,11 @@ namespace ClashN.ViewModels
var img = QRCodeHelper.GetQRCode(item.url);
var dialog = new ProfileQrcodeView()
{
imgQrcode = { Source = img } ,
imgQrcode = { Source = img },
txtContent = { Text = item.url },
};
await DialogHost.Show(dialog, "RootDialog");
}
}
}
}

View File

@@ -6,7 +6,6 @@ namespace ClashN.ViewModels
{
public PromotionViewModel()
{
}
}
}
}

View File

@@ -1,4 +1,3 @@
using ClashN.Base;
using ClashN.Handler;
using ClashN.Mode;
using ClashN.Resx;
@@ -31,6 +30,7 @@ namespace ClashN.ViewModels
[Reactive]
public ProxyModel SelectedGroup { get; set; }
[Reactive]
public ProxyModel SelectedDetail { get; set; }
@@ -41,16 +41,19 @@ namespace ClashN.ViewModels
[Reactive]
public int SystemProxySelected { get; set; }
[Reactive]
public int RuleModeSelected { get; set; }
[Reactive]
public int SortingSelected { get; set; }
[Reactive]
public bool AutoRefresh { get; set; }
[Reactive]
public bool EnableTun { get; set; }
public ProxiesViewModel()
{
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
@@ -117,7 +120,7 @@ namespace ClashN.ViewModels
DelayTestTask();
}
void DoSystemProxySelected(bool c)
private void DoSystemProxySelected(bool c)
{
if (!c)
{
@@ -129,7 +132,8 @@ namespace ClashN.ViewModels
}
Locator.Current.GetService<MainWindowViewModel>()?.SetListenerType((SysProxyType)SystemProxySelected);
}
void DoRulemodeSelected(bool c)
private void DoRulemodeSelected(bool c)
{
if (!c)
{
@@ -142,7 +146,7 @@ namespace ClashN.ViewModels
Locator.Current.GetService<MainWindowViewModel>()?.SetRuleModeCheck((ERuleMode)RuleModeSelected);
}
void DoSortingSelected(bool c)
private void DoSortingSelected(bool c)
{
if (!c)
{
@@ -156,7 +160,7 @@ namespace ClashN.ViewModels
RefreshProxyDetails(c);
}
void UpdateHandler(bool notify, string msg)
private void UpdateHandler(bool notify, string msg)
{
_noticeHandler?.SendMessage(msg, true);
}
@@ -184,16 +188,18 @@ namespace ClashN.ViewModels
{
ProxiesDelayTest(true);
}
public void ReloadSystemProxySelected()
{
SystemProxySelected = (int)_config.SysProxyType;
}
public void ReloadRulemodeSelected()
{
RuleModeSelected = (int)_config.ruleMode;
}
void DoEnableTun(bool c)
private void DoEnableTun(bool c)
{
if (_config.EnableTun != EnableTun)
{
@@ -202,13 +208,13 @@ namespace ClashN.ViewModels
}
}
void TunModeSwitch()
private void TunModeSwitch()
{
Global.reloadCore = true;
_ = Locator.Current.GetService<MainWindowViewModel>()?.LoadCore();
}
#region proxy function
#region proxy function
private void GetClashProxies(bool refreshUI)
{
@@ -281,7 +287,6 @@ namespace ClashN.ViewModels
});
}
if (_proxyGroups != null && _proxyGroups.Count > 0)
{
if (selectedName != null && _proxyGroups.Any(t => t.name == selectedName))
@@ -298,6 +303,7 @@ namespace ClashN.ViewModels
SelectedGroup = new();
}
}
private void RefreshProxyDetails(bool c)
{
_proxyDetails.Clear();
@@ -351,9 +357,11 @@ namespace ClashN.ViewModels
case 0:
lstDetails = lstDetails.OrderBy(t => t.delay).ToList();
break;
case 1:
lstDetails = lstDetails.OrderBy(t => t.name).ToList();
break;
default:
break;
}
@@ -425,7 +433,7 @@ namespace ClashN.ViewModels
SelectedGroup = group2;
//var index = _proxyGroups.IndexOf(group);
//_proxyGroups.Remove(group);
//_proxyGroups.Remove(group);
//_proxyGroups.Insert(index, group);
}
_noticeHandler?.Enqueue(ResUI.OperationSuccess);
@@ -476,7 +484,8 @@ namespace ClashN.ViewModels
}));
});
}
#endregion
#endregion proxy function
#region task
@@ -531,6 +540,6 @@ namespace ClashN.ViewModels
//);
}
#endregion
#endregion task
}
}
}

View File

@@ -1,4 +1,3 @@
using ClashN.Base;
using ClashN.Handler;
using ClashN.Mode;
using ClashN.Resx;
@@ -22,75 +21,100 @@ namespace ClashN.ViewModels
private static Config _config;
#region Core
[Reactive]
public int MixedPort { get; set; }
[Reactive]
public int SocksPort { get; set; }
[Reactive]
public int HttpPort { get; set; }
[Reactive]
public int APIPort { get; set; }
[Reactive]
public bool AllowLANConn { get; set; }
[Reactive]
public bool EnableIpv6 { get; set; }
[Reactive]
public string LogLevel { get; set; }
[Reactive]
public bool EnableMixinContent { get; set; }
public ReactiveCommand<Unit, Unit> EditMixinContentCmd { get; }
#endregion
#endregion Core
#region ClashN
[Reactive]
public bool AutoRun { get; set; }
[Reactive]
public bool EnableStatistics { get; set; }
[Reactive]
public bool EnableSecurityProtocolTls13 { get; set; }
[Reactive]
public int autoUpdateSubInterval { get; set; }
[Reactive]
public int autoDelayTestInterval { get; set; }
[Reactive]
public string SubConvertUrl { get; set; }
[Reactive]
public string currentFontFamily { get; set; }
[Reactive]
public bool AutoHideStartup { get; set; }
public ReactiveCommand<Unit, Unit> SetLoopbackCmd { get; }
public ReactiveCommand<Unit, Unit> SetGlobalHotkeyCmd { get; }
#endregion
#region System proxy
#endregion ClashN
#region System proxy
[Reactive]
public string systemProxyExceptions { get; set; }
[Reactive]
public string systemProxyAdvancedProtocol { get; set; }
[Reactive]
public int PacPort { get; set; }
#endregion
#endregion System proxy
#region UI
private IObservableCollection<Swatch> _swatches = new ObservableCollectionExtended<Swatch>();
public IObservableCollection<Swatch> Swatches => _swatches;
[Reactive]
public Swatch SelectedSwatch { get; set; }
[Reactive]
public bool ColorModeDark { get; set; }
[Reactive]
public string CurrentLanguage { get; set; }
[Reactive]
public int CurrentFontSize { get; set; }
#endregion
#endregion UI
public ReactiveCommand<Unit, Unit> SaveCommand { get; }
public SettingsViewModel()
{
_config = LazyConfig.Instance.Config;
@@ -109,7 +133,7 @@ namespace ClashN.ViewModels
EditMixinContent();
}, this.IsValid());
//ClashN
//ClashN
AutoRun = _config.AutoRun;
EnableStatistics = _config.EnableStatistics;
EnableSecurityProtocolTls13 = _config.EnableSecurityProtocolTls13;
@@ -229,10 +253,9 @@ namespace ClashN.ViewModels
{
SaveConfig();
}, this.IsValid());
}
void SaveConfig()
private void SaveConfig()
{
//Core
_config.MixedPort = MixedPort;
@@ -244,7 +267,7 @@ namespace ClashN.ViewModels
_config.LogLevel = LogLevel;
_config.EnableMixinContent = EnableMixinContent;
//ClashN
//ClashN
Utils.SetAutoRun(AutoRun);
_config.AutoRun = AutoRun;
_config.EnableStatistics = EnableStatistics;
@@ -271,7 +294,6 @@ namespace ClashN.ViewModels
}
}
private void EditMixinContent()
{
var address = Utils.GetConfigPath(Global.mixinConfigFileName);

View File

@@ -118,9 +118,7 @@
Width="100"
Binding="{Binding elapsed}"
Header="{x:Static resx:ResUI.TbSortingTime}" />
</DataGrid.Columns>
</DataGrid>
</DockPanel>
</reactiveui:ReactiveUserControl>
</reactiveui:ReactiveUserControl>

View File

@@ -20,7 +20,6 @@ namespace ClashN.Views
this.Bind(ViewModel, vm => vm.SelectedSource, v => v.lstConnections.SelectedItem).DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.ConnectionItems.Count, v => v.chipCount.Content).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ConnectionCloseCmd, v => v.menuConnectionClose).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ConnectionCloseAllCmd, v => v.menuConnectionCloseAll).DisposeWith(disposables);
@@ -35,4 +34,4 @@ namespace ClashN.Views
ViewModel?.ClashConnectionClose(false);
}
}
}
}

View File

@@ -34,4 +34,4 @@
</TextBlock>
</Grid>
</ScrollViewer>
</reactiveui:ReactiveUserControl>
</reactiveui:ReactiveUserControl>

View File

@@ -12,8 +12,7 @@ namespace ClashN.Views
InitializeComponent();
this.WhenActivated(disposables =>
{
});
}
}
}
}

View File

@@ -180,4 +180,4 @@
</Grid>
</Grid>
</ScrollViewer>
</reactiveui:ReactiveWindow>
</reactiveui:ReactiveWindow>

View File

@@ -14,7 +14,7 @@ namespace ClashN.Views
public partial class GlobalHotkeySettingWindow
{
private static Config _config;
List<KeyShortcut> lstKey;
private List<KeyShortcut> lstKey;
public GlobalHotkeySettingWindow()
{
@@ -51,7 +51,6 @@ namespace ClashN.Views
Utils.SetDarkBorder(this, _config.UiItem.colorModeDark);
}
private void TxtGlobalHotkey_KeyDown(object sender, KeyEventArgs e)
{
var txt = ((TextBox)sender);
@@ -145,6 +144,7 @@ namespace ClashN.Views
}
BindingData(-1);
}
private void SetText(string name, string txt)
{
foreach (UIElement element in gridText.Children)
@@ -167,4 +167,4 @@ namespace ClashN.Views
}
}
}
}
}

View File

@@ -171,6 +171,5 @@
</materialDesign:Card>
</WrapPanel>
</ScrollViewer>
</DockPanel>
</reactiveui:ReactiveUserControl>
</reactiveui:ReactiveUserControl>

View File

@@ -2,7 +2,6 @@ using ClashN.ViewModels;
using ReactiveUI;
using System.Reactive.Disposables;
namespace ClashN.Views
{
/// <summary>
@@ -17,11 +16,9 @@ namespace ClashN.Views
this.WhenActivated(disposables =>
{
this.BindCommand(ViewModel, vm => vm.CheckUpdateCmd, v => v.btnCheckUpdateN).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.CheckUpdateClashCoreCmd, v => v.btnCheckUpdateClashCore).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.CheckUpdateClashMetaCoreCmd, v => v.btnCheckUpdateClashMetaCore).DisposeWith(disposables);
});
}
@@ -30,4 +27,4 @@ namespace ClashN.Views
Utils.ProcessStart(Global.AboutUrl);
}
}
}
}

View File

@@ -80,5 +80,4 @@
TextWrapping="Wrap"
VerticalScrollBarVisibility="Visible" />
</DockPanel>
</reactiveui:ReactiveUserControl>
</reactiveui:ReactiveUserControl>

View File

@@ -12,7 +12,6 @@ namespace ClashN.Views
/// </summary>
public partial class LogsView
{
public LogsView()
{
InitializeComponent();
@@ -28,8 +27,7 @@ namespace ClashN.Views
});
}
void DelegateAppendText(string msg)
private void DelegateAppendText(string msg)
{
Dispatcher.BeginInvoke(new Action<string>(AppendText), DispatcherPriority.Send, msg);
}
@@ -79,4 +77,4 @@ namespace ClashN.Views
ClearMsg();
}
}
}
}

View File

@@ -202,8 +202,6 @@
</StackPanel>
</TabItem.Header>
</TabItem>
</TabControl>
<tb:TaskbarIcon
@@ -316,9 +314,7 @@
</tb:TaskbarIcon.ContextMenu>
</tb:TaskbarIcon>
<materialDesign:Snackbar x:Name="MainSnackbar" MessageQueue="{materialDesign:MessageQueue}" />
</Grid>
</Grid>
</materialDesign:DialogHost>
</reactiveui:ReactiveWindow>
</reactiveui:ReactiveWindow>

View File

@@ -45,7 +45,6 @@ namespace ClashN.Views
this.BindCommand(ViewModel, vm => vm.SystemProxyPacCmd, v => v.menuSystemProxyPac).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.SystemProxyNothingCmd, v => v.menuSystemProxyNothing).DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.BlModeRule, v => v.menuModeRule2.Visibility, conversionHint: BooleanToVisibilityHint.UseHidden, vmToViewConverterOverride: new BooleanToVisibilityTypeConverter()).DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.BlModeGlobal, v => v.menuModeGlobal2.Visibility, conversionHint: BooleanToVisibilityHint.UseHidden, vmToViewConverterOverride: new BooleanToVisibilityTypeConverter()).DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.BlModeDirect, v => v.menuModeDirect2.Visibility, conversionHint: BooleanToVisibilityHint.UseHidden, vmToViewConverterOverride: new BooleanToVisibilityTypeConverter()).DisposeWith(disposables);
@@ -66,7 +65,6 @@ namespace ClashN.Views
this.OneWayBind(ViewModel, vm => vm.NotifyLeftClickCmd, v => v.tbNotify.LeftClickCommand).DisposeWith(disposables);
});
this.Title = $"{Utils.GetVersion()} - {(Utils.IsAdministrator() ? ResUI.RunAsAdmin : ResUI.NotRunAsAdmin)}";
}
@@ -88,4 +86,4 @@ namespace ClashN.Views
ViewModel?.MyAppExit(true);
}
}
}
}

View File

@@ -28,4 +28,4 @@
IsDefault="True"
Style="{StaticResource MaterialDesignFlatButton}" />
</Grid>
</UserControl>
</UserControl>

View File

@@ -12,4 +12,4 @@ namespace ClashN.Views
InitializeComponent();
}
}
}
}

View File

@@ -26,7 +26,5 @@
IsReadOnly="True"
TextWrapping="Wrap"
VerticalScrollBarVisibility="Visible" />
</DockPanel>
</UserControl>
</UserControl>

View File

@@ -15,7 +15,7 @@ namespace ClashN.Views
MessageBus.Current.Listen<string>("MsgView").Subscribe(x => DelegateAppendText(x));
}
void DelegateAppendText(string msg)
private void DelegateAppendText(string msg)
{
Dispatcher.BeginInvoke(new Action<string>(AppendText), DispatcherPriority.Send, msg);
}
@@ -54,6 +54,5 @@ namespace ClashN.Views
txtMsg.Clear();
}));
}
}
}

View File

@@ -168,7 +168,6 @@
FontSize="{DynamicResource StdFontSize2}"
Style="{StaticResource MaterialDesignOutlinedComboBox}" />
<TextBlock
Grid.Row="7"
Grid.Column="0"
@@ -196,7 +195,6 @@
Grid.Column="1"
Margin="4"
HorizontalAlignment="Left" />
</Grid>
<Grid
Grid.Row="1"
@@ -220,9 +218,6 @@
Content="{x:Static resx:ResUI.TbCancel}"
Style="{StaticResource DefButton}" />
</Grid>
</Grid>
</ScrollViewer>
</reactiveui:ReactiveWindow>

View File

@@ -30,11 +30,9 @@ namespace ClashN.Views
this.Bind(ViewModel, vm => vm.SelectedSource.enabled, v => v.togEnabled.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.enableConvert, v => v.togEnableConvert.IsChecked).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.BrowseProfileCmd, v => v.btnBrowse).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.EditProfileCmd, v => v.btnEdit).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.SaveProfileCmd, v => v.btnSave).DisposeWith(disposables);
});
}
@@ -51,6 +49,4 @@ namespace ClashN.Views
}
}
}
}
}

View File

@@ -44,6 +44,5 @@
IsCancel="True"
IsDefault="True"
Style="{StaticResource MaterialDesignFlatButton}" />
</Grid>
</UserControl>
</UserControl>

View File

@@ -12,4 +12,4 @@ namespace ClashN.Views
InitializeComponent();
}
}
}
}

View File

@@ -174,7 +174,6 @@
Style="{StaticResource ListItemCheckBox}" />
<TextBlock Style="{StaticResource ListItemSubTitle}" Text="{Binding StrUpdateTime}" />
</StackPanel>
<Separator Grid.Row="3" Style="{StaticResource MaterialDesignLightSeparator}" />
@@ -205,7 +204,6 @@
Padding="4,0,4,0"
Style="{StaticResource ListItemSubTitle}"
Text="{Binding StrExpireTime}" />
</StackPanel>
</Grid>
</DockPanel>
@@ -214,6 +212,4 @@
</ListView.ItemTemplate>
</ListView>
</DockPanel>
</reactiveui:ReactiveUserControl>
</reactiveui:ReactiveUserControl>

View File

@@ -33,7 +33,6 @@ namespace ClashN.Views
this.Bind(ViewModel, vm => vm.SelectedSource, v => v.lstProfiles.SelectedItem).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.EditLocalFileCmd, v => v.menuEditLocalFile).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.EditProfileCmd, v => v.menuEditProfile).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.AddProfileCmd, v => v.menuAddProfile).DisposeWith(disposables);
@@ -61,7 +60,6 @@ namespace ClashN.Views
this.BindCommand(ViewModel, vm => vm.EditProfileCmd, v => v.btnEditProfile).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.SetDefaultProfileCmd, v => v.btnSetDefaultProfile).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.ProfileQrcodeCmd, v => v.btnProfileQrcode).DisposeWith(disposables);
});
}
@@ -126,12 +124,12 @@ namespace ClashN.Views
return null;
}
private void LstProfiles_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
// Get current mouse position
startPoint = e.GetPosition(null);
}
private void LstProfiles_MouseMove(object sender, MouseEventArgs e)
{
// Get the current mouse position
@@ -182,7 +180,7 @@ namespace ClashN.Views
// Find the data behind the ListViewItem
ProfileItemModel item = (ProfileItemModel)listView.ItemContainerGenerator.ItemFromContainer(listViewItem);
if (item == null) return;
// Move item into observable collection
// Move item into observable collection
// (this will be automatically reflected to lstView.ItemsSource)
e.Effects = DragDropEffects.Move;
@@ -192,7 +190,6 @@ namespace ClashN.Views
}
}
#endregion
#endregion Drag and Drop
}
}
}

View File

@@ -74,4 +74,4 @@
</materialDesign:Card>
</Grid>
</ScrollViewer>
</reactiveui:ReactiveUserControl>
</reactiveui:ReactiveUserControl>

View File

@@ -13,14 +13,12 @@ namespace ClashN.Views
InitializeComponent();
this.WhenActivated(disposables =>
{
});
}
private void btnPromotion_Click(object sender, RoutedEventArgs e)
{
Utils.ProcessStart($"{Utils.Base64Decode(Global.PromotionUrl)}?t={DateTime.Now.Ticks}");
}
}
}
}

View File

@@ -200,8 +200,6 @@
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</DockPanel>
</DockPanel>
</reactiveui:ReactiveUserControl>
</reactiveui:ReactiveUserControl>

View File

@@ -38,8 +38,6 @@ namespace ClashN.Views
this.Bind(ViewModel, vm => vm.AutoRefresh, v => v.togAutoRefresh.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.EnableTun, v => v.togEnableTun.IsChecked).DisposeWith(disposables);
});
}
private void ProxiesView_KeyDown(object sender, KeyEventArgs e)
@@ -49,6 +47,7 @@ namespace ClashN.Views
case Key.F5:
ViewModel?.ProxiesReload();
break;
case Key.Enter:
ViewModel?.SetActiveProxy();
break;
@@ -59,6 +58,5 @@ namespace ClashN.Views
{
ViewModel?.SetActiveProxy();
}
}
}
}

View File

@@ -63,8 +63,6 @@
Width="100"
Margin="8"
Style="{StaticResource DefComboBox}" />
</ToolBar>
</ToolBarTray>
<TextBlock
@@ -395,7 +393,6 @@
Margin="8"
Content="{x:Static resx:ResUI.TbGlobalHotkeySetting}"
Style="{StaticResource DefButton}" />
</Grid>
</ScrollViewer>
</TabItem>
@@ -470,6 +467,5 @@
</ScrollViewer>
</TabItem>
</TabControl>
</DockPanel>
</reactiveui:ReactiveUserControl>
</reactiveui:ReactiveUserControl>

View File

@@ -114,14 +114,12 @@ namespace ClashN.Views
this.BindCommand(ViewModel, vm => vm.SetLoopbackCmd, v => v.btnSetLoopback).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.SetGlobalHotkeyCmd, v => v.btnSetGlobalHotkey).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.systemProxyExceptions, v => v.txtsystemProxyExceptions.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.systemProxyAdvancedProtocol, v => v.cmbsystemProxyAdvancedProtocol.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.PacPort, v => v.txtPacPort.Text).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.SaveCommand, v => v.btnSave).DisposeWith(disposables);
});
}
}
}
}

View File

@@ -22,6 +22,7 @@ namespace clashUpgrade
fileName = HttpUtility.UrlDecode(fileName);
}
}
private void showWarn(string message)
{
MessageBox.Show(message, "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
@@ -69,7 +70,6 @@ namespace clashUpgrade
File.Delete(thisAppOldFile);
string startKey = "clashN/";
using (ZipArchive archive = ZipFile.OpenRead(fileName))
{
foreach (ZipArchiveEntry entry in archive.Entries)
@@ -135,6 +135,7 @@ namespace clashUpgrade
{
return Application.StartupPath;
}
public static string GetPath(string fileName)
{
string startupPath = StartupPath();
@@ -145,4 +146,4 @@ namespace clashUpgrade
return Path.Combine(startupPath, fileName);
}
}
}
}

View File

@@ -3,13 +3,13 @@ using System.Windows.Forms;
namespace clashUpgrade
{
static class Program
internal static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
private static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetHighDpiMode(HighDpiMode.SystemAware);
@@ -17,4 +17,4 @@ namespace clashUpgrade
Application.Run(new MainForm(args));
}
}
}
}