Skip to content

Commit

Permalink
Code clean
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Apr 13, 2023
1 parent 52dced5 commit e3be6b7
Show file tree
Hide file tree
Showing 83 changed files with 371 additions and 357 deletions.
7 changes: 2 additions & 5 deletions clashN/clashN/App.xaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<Application
x:Class="ClashN.App"
xmlns="http:https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:materialDesign="http:https://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:x="http:https://schemas.microsoft.com/winfx/2006/xaml"
xmlns:conv="clr-namespace:ClashN.Converters"
xmlns:local="clr-namespace:ClashN"
xmlns:materialDesign="http:https://materialdesigninxaml.net/winfx/xaml/themes"
ShutdownMode="OnExplicitShutdown"
StartupUri="Views/MainWindow.xaml">
<Application.Resources>
Expand Down Expand Up @@ -130,7 +129,5 @@
<Setter Property="FontSize" Value="{DynamicResource StdFontSize2}" />
</Style>
</ResourceDictionary>

</Application.Resources>

</Application>
</Application>
4 changes: 2 additions & 2 deletions clashN/clashN/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public App()
{
// Locator.CurrentMutable.RegisterViewsForViewModels(Assembly.GetCallingAssembly());


this.DispatcherUnhandledException += App_DispatcherUnhandledException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
Expand Down Expand Up @@ -71,6 +70,7 @@ private void Init()
return;
}
}

private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
Utils.SaveLog("App_DispatcherUnhandledException", e.Exception);
Expand All @@ -90,4 +90,4 @@ private void TaskScheduler_UnobservedTaskException(object? sender, UnobservedTas
Utils.SaveLog("TaskScheduler_UnobservedTaskException", e.Exception);
}
}
}
}
2 changes: 1 addition & 1 deletion clashN/clashN/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
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)
)]
)]
5 changes: 2 additions & 3 deletions clashN/clashN/Base/HttpClientHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public async Task<(string, HttpResponseHeaders)> GetAsync(HttpClient client, str
return (await response.Content.ReadAsStringAsync(), response.Headers);
}


public async Task PutAsync(string url, Dictionary<string, string> headers)
{
var myContent = Utils.ToJson(headers);
Expand All @@ -91,6 +90,7 @@ public async Task PatchAsync(string url, Dictionary<string, string> headers)

await httpClient.PatchAsync(url, byteContent);
}

public async Task DeleteAsync(string url)
{
//var myContent = Utils.ToJson(headers);
Expand Down Expand Up @@ -157,9 +157,8 @@ public async Task DownloadFileAsync(HttpClient client, string url, string fileNa
}
} while (isMoreToRead);


if (canReportProgress)
progress?.Report(101);
}
}
}
}
4 changes: 2 additions & 2 deletions clashN/clashN/Base/StringEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ClashN.Base
{
static class StringEx
internal static class StringEx
{
public static bool BeginWithAny(this string? s, IEnumerable<char> chars)
{
Expand All @@ -28,4 +28,4 @@ public static string TrimEx(this string? value)
return value == null ? string.Empty : value.Trim();
}
}
}
}
2 changes: 1 addition & 1 deletion clashN/clashN/Converters/DelayColorConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ public object ConvertBack(object value, Type targetType, object parameter, Syste
return null;
}
}
}
}
16 changes: 9 additions & 7 deletions clashN/clashN/Global.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace ClashN
{
class Global
internal class Global
{
#region 常量

Expand All @@ -15,6 +15,7 @@ class Global
/// SpeedTestUrl
/// </summary>
public const string SpeedTestUrl = @"http:https://cachefly.cachefly.net/10mb.test";

public const string SpeedPingTestUrl = @"https://www.google.com/generate_204";

public static readonly List<string> SubConvertUrls = new List<string> {
Expand All @@ -23,11 +24,11 @@ class Global
@"http:https://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>
Expand Down Expand Up @@ -56,6 +57,7 @@ class Global
/// http
/// </summary>
public const string httpProtocol = "http:https://";

/// <summary>
/// https
/// </summary>
Expand Down Expand Up @@ -87,12 +89,13 @@ class Global
/// 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}",
Expand All @@ -113,7 +116,7 @@ class Global

public static readonly List<string> LogLevel = new List<string> { "debug", "info", "warning", "error", "silent" };

#endregion
#endregion 常量

#region 全局变量

Expand All @@ -135,7 +138,6 @@ public static bool ShowInTaskbar
get; set;
}

#endregion

#endregion 全局变量
}
}
}
72 changes: 37 additions & 35 deletions clashN/clashN/Handler/ConfigProc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -23,7 +23,7 @@ class ConfigProc
/// <returns></returns>
public static int LoadConfig(ref Config? config)
{
//载入配置文件
//载入配置文件
string result = Utils.LoadResource(Utils.GetConfigPath(configRes));
if (!string.IsNullOrEmpty(result))
{
Expand Down Expand Up @@ -116,6 +116,7 @@ public static int LoadConfig(ref Config? config)
LazyConfig.Instance.SetConfig(config);
return 0;
}

/// <summary>
/// 保参数
/// </summary>
Expand Down Expand Up @@ -162,7 +163,7 @@ private static void ToJsonFile(Config config)
}
}

#endregion
#endregion ConfigHandler

#region Profile

Expand Down Expand Up @@ -261,6 +262,7 @@ public static int SetDefaultProfile(Config config, List<ProfileItem> lstProfile)
}
return -1;
}

public static ProfileItem? GetDefaultProfile(ref Config config)
{
if (config.ProfileItems.Count <= 0)
Expand Down Expand Up @@ -301,46 +303,46 @@ public static int MoveProfile(ref Config config, int index, MovementTarget eMove
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;
Expand Down Expand Up @@ -435,7 +437,7 @@ public static int EditProfile(ref Config config, ProfileItem profileItem)

AddProfileCommon(ref config, profileItem);

//TODO auto update via url
//TODO auto update via url
//if (!string.IsNullOrEmpty(profileItem.url))
//{
// var httpClient = new HttpClient();
Expand Down Expand Up @@ -464,6 +466,7 @@ public static int SortProfiles(ref Config config, ref List<ProfileItem> lstProfi
case EProfileColName.updateTime:
propertyName = name.ToString();
break;

default:
return -1;
}
Expand Down Expand Up @@ -625,7 +628,6 @@ public static int AddBatchProfiles(ref Config config, string clipboardData, stri
if (AddProfileViaContent(ref config, profileItem, clipboardData) == 0)
{
return 0;

}
else
{
Expand All @@ -643,7 +645,7 @@ public static void ClearAllServerStatistics(ref Config config)

ToJsonFile(config);
}
#endregion

#endregion Profile
}
}
}
6 changes: 2 additions & 4 deletions clashN/clashN/Handler/CoreConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace ClashN.Handler
/// <summary>
/// Core配置文件处理类
/// </summary>
class CoreConfigHandler
internal class CoreConfigHandler
{
/// <summary>
/// 生成配置文件
Expand All @@ -26,7 +26,6 @@ public static int GenerateClientConfig(ProfileItem node, string fileName, bool b

msg = ResUI.InitialConfiguration;


try
{
//检查GUI设置
Expand Down Expand Up @@ -234,7 +233,6 @@ private static void ModifyContentMerge(Dictionary<string, object> fileContent, s
return;
}


if (blPrepend)
{
lstValue.Reverse();
Expand All @@ -252,4 +250,4 @@ private static void ModifyContentMerge(Dictionary<string, object> fileContent, s
}
}
}
}
}
Loading

0 comments on commit e3be6b7

Please sign in to comment.