Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Oct 18, 2019
1 parent 9224ea9 commit d5c69c7
Show file tree
Hide file tree
Showing 21 changed files with 55 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Text;
using System.Threading;

namespace v2rayN.HttpProxyHandler
namespace v2rayN.Base
{
public class HttpWebServer
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System;
using System.Collections;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;

namespace v2rayN.HttpProxyHandler
namespace v2rayN.Base
{
public class HttpWebServerB
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Drawing;
using System.Windows.Forms;

namespace v2rayN.Forms
namespace v2rayN.Base
{
class ListViewFlickerFree : ListView
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.IO;
using System.Linq;

namespace v2rayN
namespace v2rayN.Base
{
static class StringEx
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Net;

namespace v2rayN.HttpProxyHandler
namespace v2rayN.Base
{
class WebClientEx : WebClient
{
Expand Down
4 changes: 2 additions & 2 deletions v2rayN/v2rayN/Forms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 14 additions & 13 deletions v2rayN/v2rayN/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
using v2rayN.Handler;
using v2rayN.HttpProxyHandler;
using v2rayN.Mode;
using v2rayN.Base;

namespace v2rayN.Forms
{
public partial class MainForm : BaseForm
{
private V2rayHandler v2rayHandler;
private PACListHandle pacListHandle;
private V2rayUpdateHandle v2rayUpdateHandle;
private DownloadHandle downloadHandle;
private List<int> lvSelecteds = new List<int>();
private StatisticsHandler statistics = null;

Expand Down Expand Up @@ -1279,10 +1280,10 @@ private void tsbCheckUpdateN_Click(object sender, EventArgs e)

private void tsbCheckUpdateCore_Click(object sender, EventArgs e)
{
if (v2rayUpdateHandle == null)
if (downloadHandle == null)
{
v2rayUpdateHandle = new V2rayUpdateHandle();
v2rayUpdateHandle.AbsoluteCompleted += (sender2, args) =>
downloadHandle = new DownloadHandle();
downloadHandle.AbsoluteCompleted += (sender2, args) =>
{
if (args.Success)
{
Expand All @@ -1298,7 +1299,7 @@ private void tsbCheckUpdateCore_Click(object sender, EventArgs e)
}
else
{
v2rayUpdateHandle.DownloadFileAsync(config, url, false);
downloadHandle.DownloadFileAsync(config, url, false);
}
}));
}
Expand All @@ -1307,7 +1308,7 @@ private void tsbCheckUpdateCore_Click(object sender, EventArgs e)
AppendText(false, args.Msg);
}
};
v2rayUpdateHandle.UpdateCompleted += (sender2, args) =>
downloadHandle.UpdateCompleted += (sender2, args) =>
{
if (args.Success)
{
Expand All @@ -1318,7 +1319,7 @@ private void tsbCheckUpdateCore_Click(object sender, EventArgs e)
{
CloseV2ray();

string fileName = v2rayUpdateHandle.DownloadFileName;
string fileName = downloadHandle.DownloadFileName;
fileName = Utils.GetPath(fileName);
using (ZipArchive archive = ZipFile.OpenRead(fileName))
{
Expand Down Expand Up @@ -1346,14 +1347,14 @@ private void tsbCheckUpdateCore_Click(object sender, EventArgs e)
AppendText(false, args.Msg);
}
};
v2rayUpdateHandle.Error += (sender2, args) =>
downloadHandle.Error += (sender2, args) =>
{
AppendText(true, args.GetException().Message);
};
}

AppendText(false, UIRes.I18N("MsgStartUpdatingV2rayCore"));
v2rayUpdateHandle.AbsoluteV2rayCore(config);
downloadHandle.AbsoluteV2rayCore(config);
}

private void tsbCheckUpdatePACList_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -1473,8 +1474,8 @@ private void tsbSubUpdate_Click(object sender, EventArgs e)
continue;
}

V2rayUpdateHandle v2rayUpdateHandle3 = new V2rayUpdateHandle();
v2rayUpdateHandle3.UpdateCompleted += (sender2, args) =>
DownloadHandle downloadHandle3 = new DownloadHandle();
downloadHandle3.UpdateCompleted += (sender2, args) =>
{
if (args.Success)
{
Expand Down Expand Up @@ -1503,12 +1504,12 @@ private void tsbSubUpdate_Click(object sender, EventArgs e)
AppendText(false, args.Msg);
}
};
v2rayUpdateHandle3.Error += (sender2, args) =>
downloadHandle3.Error += (sender2, args) =>
{
AppendText(true, args.GetException().Message);
};

v2rayUpdateHandle3.WebDownloadString(url);
downloadHandle3.WebDownloadString(url);
AppendText(false, $"{hashCode}{UIRes.I18N("MsgStartGettingSubscriptions")}");
}

Expand Down
9 changes: 5 additions & 4 deletions v2rayN/v2rayN/Forms/OptionSettingForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Windows.Forms;
using v2rayN.Handler;
using v2rayN.Base;

namespace v2rayN.Forms
{
Expand Down Expand Up @@ -381,8 +382,8 @@ private void btnSetDefRountingRule_Click(object sender, EventArgs e)
for (int k = 0; k < lstUrl.Count; k++)
{
var txt = lstTxt[k];
V2rayUpdateHandle v2rayUpdateHandle3 = new V2rayUpdateHandle();
v2rayUpdateHandle3.UpdateCompleted += (sender2, args) =>
DownloadHandle downloadHandle = new DownloadHandle();
downloadHandle.UpdateCompleted += (sender2, args) =>
{
if (args.Success)
{
Expand All @@ -398,12 +399,12 @@ private void btnSetDefRountingRule_Click(object sender, EventArgs e)
AppendText(false, args.Msg);
}
};
v2rayUpdateHandle3.Error += (sender2, args) =>
downloadHandle.Error += (sender2, args) =>
{
AppendText(true, args.GetException().Message);
};

v2rayUpdateHandle3.WebDownloadString(lstUrl[k]);
downloadHandle.WebDownloadString(lstUrl[k]);
}
}
void AppendText(bool notify, string text)
Expand Down
1 change: 1 addition & 0 deletions v2rayN/v2rayN/Forms/SubSettingControl.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Windows.Forms;
using v2rayN.Base;
using v2rayN.Mode;

namespace v2rayN.Forms
Expand Down
1 change: 1 addition & 0 deletions v2rayN/v2rayN/Handler/ConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Net;
using v2rayN.Mode;
using v2rayN.Base;

namespace v2rayN.Handler
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using Newtonsoft.Json;
using v2rayN.Base;
using v2rayN.Mode;
using v2rayN.Properties;
using v2rayN.HttpProxyHandler;
using System.Diagnostics;

namespace v2rayN.Handler
{
/// <summary>
///Update V2ray Core
///Download
/// </summary>
class V2rayUpdateHandle
class DownloadHandle
{
public event EventHandler<ResultEventArgs> AbsoluteCompleted;

Expand Down
12 changes: 6 additions & 6 deletions v2rayN/v2rayN/Handler/SpeedtestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace v2rayN.Handler
{
class SpeedtestHandler
{
private V2rayUpdateHandle v2rayUpdateHandle2;
private DownloadHandle downloadHandle2;
private Config _config;
private V2rayHandler _v2rayHandler;
private List<int> _selecteds;
Expand Down Expand Up @@ -186,10 +186,10 @@ private void RunSpeedTest()

string url = Global.SpeedTestUrl;
testCounter = 0;
if (v2rayUpdateHandle2 == null)
if (downloadHandle2 == null)
{
v2rayUpdateHandle2 = new V2rayUpdateHandle();
v2rayUpdateHandle2.UpdateCompleted += (sender2, args) =>
downloadHandle2 = new DownloadHandle();
downloadHandle2.UpdateCompleted += (sender2, args) =>
{
if (args.Success)
{
Expand All @@ -204,7 +204,7 @@ private void RunSpeedTest()
_updateFunc(ItemIndex, args.Msg);
}
};
v2rayUpdateHandle2.Error += (sender2, args) =>
downloadHandle2.Error += (sender2, args) =>
{
_updateFunc(ItemIndex, args.GetException().Message);
if (ServerSpeedTestSub(testCounter, url) != 0)
Expand Down Expand Up @@ -232,7 +232,7 @@ private int ServerSpeedTestSub(int index, string url)

testCounter++;

v2rayUpdateHandle2.DownloadFileAsync(_config, url,true);
downloadHandle2.DownloadFileAsync(_config, url,true);

return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions v2rayN/v2rayN/Handler/V2rayConfigHandler.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.IO;
using v2rayN.Mode;
using System.Net;
using System.Text;
using System.Linq;
using System.Net;
using v2rayN.Base;
using v2rayN.Mode;

namespace v2rayN.Handler
{
Expand Down
24 changes: 1 addition & 23 deletions v2rayN/v2rayN/HttpProxyHandler/HttpProxyHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,6 @@ namespace v2rayN.HttpProxyHandler
/// </summary>
class HttpProxyHandle
{
private static string GetTimestamp(DateTime value)
{
return value.ToString("MMddHHmmssfff");
}

public static void ReSetPACProxy(Config config)
{
if (config.listenerType == 2)
{
//SysProxyHandle.SetIEProxy(false, false, null, null);
//PACServerHandle.Stop();
}
Update(config, false);
}

public static bool Update(Config config, bool forceDisable)
{
int type = config.listenerType;
Expand All @@ -46,7 +31,6 @@ public static bool Update(Config config, bool forceDisable)
if (type == 1)
{
PACServerHandle.Stop();
PACFileWatcherHandle.StopWatch();
SysProxyHandle.SetIEProxy(true, true, $"{Global.Loopback}:{port}", null);
}
else if (type == 2)
Expand All @@ -55,12 +39,10 @@ public static bool Update(Config config, bool forceDisable)
SysProxyHandle.SetIEProxy(true, false, null, pacUrl);
PACServerHandle.Stop();
PACServerHandle.Init(config);
PACFileWatcherHandle.StartWatch(config);
}
else if (type == 3)
{
PACServerHandle.Stop();
PACFileWatcherHandle.StopWatch();
SysProxyHandle.SetIEProxy(false, false, null, null);
}
else if (type == 4)
Expand All @@ -69,14 +51,12 @@ public static bool Update(Config config, bool forceDisable)
SysProxyHandle.SetIEProxy(false, false, null, null);
PACServerHandle.Stop();
PACServerHandle.Init(config);
PACFileWatcherHandle.StartWatch(config);
}
}
else
{
SysProxyHandle.SetIEProxy(false, false, null, null);
PACServerHandle.Stop();
PACFileWatcherHandle.StopWatch();
}
}
catch (Exception ex)
Expand Down Expand Up @@ -168,9 +148,7 @@ public static bool RestartHttpAgent(Config config, bool forced)

public static string GetPacUrl()
{
string pacUrl = $"http://{Global.Loopback}:{Global.pacPort}/pac/?t={GetTimestamp(DateTime.Now)}";


string pacUrl = $"http://{Global.Loopback}:{Global.pacPort}/pac/?t={ DateTime.Now.ToString("HHmmss")}";
return pacUrl;
}
}
Expand Down
Loading

0 comments on commit d5c69c7

Please sign in to comment.