Skip to content

Commit

Permalink
up pac
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Dec 13, 2019
1 parent 5cadf59 commit cb07452
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 102 deletions.
19 changes: 13 additions & 6 deletions v2rayN/v2rayN/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
using v2rayN.Base;
using v2rayN.Tool;
using System.Diagnostics;
using v2rayN.Properties;
using Newtonsoft.Json;

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

Expand Down Expand Up @@ -1272,13 +1273,21 @@ private void tsbCheckUpdateCore_Click(object sender, EventArgs e)

private void tsbCheckUpdatePACList_Click(object sender, EventArgs e)
{
DownloadHandle pacListHandle = null;
if (pacListHandle == null)
{
pacListHandle = new PACListHandle();
pacListHandle = new DownloadHandle();
pacListHandle.UpdateCompleted += (sender2, args) =>
{
if (args.Success)
{
var result = args.Msg;
if (Utils.IsNullOrEmpty(result))
{
return;
}
pacListHandle.GenPacFile(result);

AppendText(false, UIRes.I18N("MsgPACUpdateSuccessfully"));
}
else
Expand All @@ -1292,7 +1301,7 @@ private void tsbCheckUpdatePACList_Click(object sender, EventArgs e)
};
}
AppendText(false, UIRes.I18N("MsgStartUpdatingPAC"));
pacListHandle.UpdatePACFromGFWList(config);
pacListHandle.WebDownloadString(config.urlGFWList);
}

private void tsbCheckClearPACList_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -1425,8 +1434,6 @@ private void tsbSubUpdate_Click(object sender, EventArgs e)
downloadHandle3.WebDownloadString(url);
AppendText(false, $"{hashCode}{UIRes.I18N("MsgStartGettingSubscriptions")}");
}


}

#endregion
Expand Down
3 changes: 3 additions & 0 deletions v2rayN/v2rayN/Forms/MainForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,9 @@
<data name="tsbCheckClearPACList.Text" xml:space="preserve">
<value>Simplify PAC (please set Core route)</value>
</data>
<data name="tsbCheckClearPACList.Visible" type="System.Boolean, mscorlib">
<value>False</value>
</data>
<data name="tsbCheckUpdate.ImageTransparentColor" type="System.Drawing.Color, System.Drawing">
<value>Magenta</value>
</data>
Expand Down
2 changes: 1 addition & 1 deletion v2rayN/v2rayN/Forms/MainForm.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@
<value>232, 22</value>
</data>
<data name="tsbCheckUpdatePACList.Text" xml:space="preserve">
<value>检查更新PAC (需要Http代理)</value>
<value>检查更新PAC</value>
</data>
<data name="tsbCheckClearPACList.Size" type="System.Drawing.Size, System.Drawing">
<value>232, 22</value>
Expand Down
47 changes: 46 additions & 1 deletion v2rayN/v2rayN/Handler/DownloadHandle.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using System;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Text;
using v2rayN.Base;
using v2rayN.Mode;
using v2rayN.Properties;

namespace v2rayN.Handler
{
Expand Down Expand Up @@ -289,5 +293,46 @@ private void Ws_DownloadStringCompleted(object sender, DownloadStringCompletedEv
}

#endregion

#region PAC

public string GenPacFile(string result)
{
try
{
File.WriteAllText(Utils.GetTempPath("gfwlist.txt"), result, Encoding.UTF8);
List<string> lines = ParsePacResult(result);
string abpContent = Utils.UnGzip(Resources.abp_js);
abpContent = abpContent.Replace("__RULES__", JsonConvert.SerializeObject(lines, Formatting.Indented));
File.WriteAllText(Utils.GetPath(Global.pacFILE), abpContent, Encoding.UTF8);
}
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
return ex.Message;
}
return string.Empty;
}

private List<string> ParsePacResult(string response)
{
IEnumerable<char> IgnoredLineBegins = new[] { '!', '[' };

byte[] bytes = Convert.FromBase64String(response);
string content = Encoding.UTF8.GetString(bytes);
List<string> valid_lines = new List<string>();
using (var sr = new StringReader(content))
{
foreach (var line in sr.NonWhiteSpaceLines())
{
if (line.BeginWithAny(IgnoredLineBegins))
continue;
valid_lines.Add(line);
}
}
return valid_lines;
}

#endregion
}
}
2 changes: 2 additions & 0 deletions v2rayN/v2rayN/Handler/V2rayConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ private static int outbound(Config config, ref V2rayConfig v2rayConfig)
//远程服务器地址和端口
serversItem.address = config.address();
serversItem.port = config.port();
serversItem.method = null;
serversItem.password = null;

if (!Utils.IsNullOrEmpty(config.security())
&& !Utils.IsNullOrEmpty(config.id()))
Expand Down
93 changes: 0 additions & 93 deletions v2rayN/v2rayN/HttpProxyHandler/PACListHandle.cs

This file was deleted.

1 change: 0 additions & 1 deletion v2rayN/v2rayN/v2rayN.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@
<Compile Include="Base\HttpWebServer.cs" />
<Compile Include="Base\HttpWebServerB.cs" />
<Compile Include="HttpProxyHandler\PrivoxyHandler.cs" />
<Compile Include="HttpProxyHandler\PACListHandle.cs" />
<Compile Include="HttpProxyHandler\PACServerHandle.cs" />
<Compile Include="HttpProxyHandler\ProxySetting.cs" />
<Compile Include="HttpProxyHandler\HttpProxyHandle.cs" />
Expand Down

0 comments on commit cb07452

Please sign in to comment.