diff --git a/MoeLoaderDelta/MainWindow.xaml.cs b/MoeLoaderDelta/MainWindow.xaml.cs
index b7de7bf..987c03f 100644
--- a/MoeLoaderDelta/MainWindow.xaml.cs
+++ b/MoeLoaderDelta/MainWindow.xaml.cs
@@ -1051,14 +1051,9 @@ private void Button_Click(object sender, RoutedEventArgs e)
//prefetch
string pageString = PreFetcher.Fetcher.GetPreFetchedPage(
realPage, realNum, Uri.EscapeDataString(SearchWord), SiteManager.Instance.Sites[nowSelectedIndex]);
- if (pageString != null)
- {
- imgList = SiteManager.Instance.Sites[nowSelectedIndex].GetImages(pageString, WebProxy);
- }
- else
- {
- imgList = SiteManager.Instance.Sites[nowSelectedIndex].GetImages(realPage, realNum, Uri.EscapeDataString(SearchWord), WebProxy);
- }
+ imgList = !string.IsNullOrWhiteSpace(pageString)
+ ? SiteManager.Instance.Sites[nowSelectedIndex].GetImages(pageString, WebProxy)
+ : SiteManager.Instance.Sites[nowSelectedIndex].GetImages(realPage, realNum, Uri.EscapeDataString(SearchWord), WebProxy);
//过滤图片列表
imgList = SiteManager.Instance.Sites[nowSelectedIndex].FilterImg(
@@ -1071,7 +1066,7 @@ private void Button_Click(object sender, RoutedEventArgs e)
{
Dispatcher.Invoke(new VoidDel(() =>
{
- MessageBox.Show(this, "获取图片遇到错误: " + ex.Message,
+ MessageBox.Show(this, $"获取图片:{SearchWord}\r\n错误:{ex.Message}",
ProgramName, MessageBoxButton.OK, MessageBoxImage.Warning);
}));
}
diff --git a/MoeLoaderDelta/Properties/AssemblyInfo.cs b/MoeLoaderDelta/Properties/AssemblyInfo.cs
index d34c4b7..79ab542 100644
--- a/MoeLoaderDelta/Properties/AssemblyInfo.cs
+++ b/MoeLoaderDelta/Properties/AssemblyInfo.cs
@@ -51,6 +51,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("7.0.6.91")]
-[assembly: AssemblyFileVersion("7.0.6.91")]
+[assembly: AssemblyVersion("7.0.7.0")]
+[assembly: AssemblyFileVersion("7.0.7.0")]
[assembly: GuidAttribute("e1b87586-4b7e-4f4a-be97-55d3349ed5a6")]
\ No newline at end of file
diff --git a/MoeSite/Properties/AssemblyInfo.cs b/MoeSite/Properties/AssemblyInfo.cs
index d9e8be0..6393151 100644
--- a/MoeSite/Properties/AssemblyInfo.cs
+++ b/MoeSite/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.3.3.9")]
-[assembly: AssemblyFileVersion("1.3.3.9")]
+[assembly: AssemblyVersion("1.3.4.0")]
+[assembly: AssemblyFileVersion("1.3.4.0")]
diff --git a/MoeSite/SiteManager.cs b/MoeSite/SiteManager.cs
index 709a63f..14ff930 100644
--- a/MoeSite/SiteManager.cs
+++ b/MoeSite/SiteManager.cs
@@ -9,7 +9,7 @@ namespace MoeLoaderDelta
{
///
/// 管理站点定义
- /// Last 20190824
+ /// Last 20190918
///
public class SiteManager
{
@@ -59,7 +59,7 @@ private SiteManager()
}
catch (Exception ex)
{
- echoErrLog("站点载入过程", ex);
+ EchoErrLog("站点载入过程", ex);
}
}
}
@@ -101,6 +101,7 @@ public static bool LoginSite(ImageSite imageSite, ref string cookie, string Logg
if (result)
{
+ shc.Timeout = shc.Timeout * 2;
shc.Set("Cookie", tmp_cookie);
try
{
@@ -124,7 +125,7 @@ public static bool LoginSite(ImageSite imageSite, ref string cookie, string Logg
cookie = string.Empty;
}
}
-
+
return result;
}
@@ -151,7 +152,7 @@ public static bool LoginSite(ImageSite imageSite, ref string cookie, string Logg
/// 附加错误信息
/// 不显示信息
/// 不记录Log
- public static void echoErrLog(string SiteShortName, Exception ex = null, string extra_info = null, bool NoShow = false, bool NoLog = false)
+ public static void EchoErrLog(string SiteShortName, Exception ex = null, string extra_info = null, bool NoShow = false, bool NoLog = false)
{
int maxlog = 4096;
bool exisnull = ex == null;
@@ -172,20 +173,23 @@ public static void echoErrLog(string SiteShortName, Exception ex = null, string
}
if (!NoShow)
{
- MessageBox.Show((string.IsNullOrWhiteSpace(extra_info) ? ex.Message : extra_info), $"{SiteShortName} 错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ MessageBox.Show(string.IsNullOrWhiteSpace(extra_info) ? ex.Message : extra_info, $"{SiteShortName} 错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
//压缩记录
- if (new FileInfo(logPath).Length > maxlog)
+ long sourceLength = new FileInfo(logPath).Length;
+ if (sourceLength > maxlog)
{
- char[] a = new char[maxlog];
- using (FileStream fs = new FileStream(logPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
+ byte[] buffer = new byte[maxlog];
+ using (FileStream fs = new FileStream(logPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
{
- using (StreamReader sr = new StreamReader(fs))
- {
- sr.ReadBlock(a, 0, maxlog);
- }
+ int newleng = (int)sourceLength - maxlog;
+ newleng = newleng > maxlog ? maxlog : newleng;
+ fs.Seek(newleng, SeekOrigin.Begin);
+ fs.Read(buffer, 0, maxlog);
+ fs.Seek(0, SeekOrigin.Begin);
+ fs.SetLength(0);
+ fs.Write(buffer, 0, maxlog);
}
- File.WriteAllText(logPath, new string(a));
}
}
@@ -194,9 +198,9 @@ public static void echoErrLog(string SiteShortName, Exception ex = null, string
///
/// 站点短名
/// 附加错误信息
- public static void echoErrLog(string SiteShortName, string extra_info, bool NoShow = false, bool NoLog = false)
+ public static void EchoErrLog(string SiteShortName, string extra_info, bool NoShow = false, bool NoLog = false)
{
- echoErrLog(SiteShortName, null, extra_info, NoShow, NoLog);
+ EchoErrLog(SiteShortName, null, extra_info, NoShow, NoLog);
}
}
}
diff --git a/SitePack/Properties/AssemblyInfo.cs b/SitePack/Properties/AssemblyInfo.cs
index 1da9ab4..befb7c4 100644
--- a/SitePack/Properties/AssemblyInfo.cs
+++ b/SitePack/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.7.9")]
-[assembly: AssemblyFileVersion("1.0.7.9")]
+[assembly: AssemblyVersion("1.0.8.0")]
+[assembly: AssemblyFileVersion("1.0.8.0")]
diff --git a/SitePack/SiteATFBooru.cs b/SitePack/SiteATFBooru.cs
index fce9116..3054957 100644
--- a/SitePack/SiteATFBooru.cs
+++ b/SitePack/SiteATFBooru.cs
@@ -100,7 +100,7 @@ private void Login(IWebProxy proxy)
token = hdoc.DocumentNode.SelectSingleNode("//meta[@name='csrf-token']").Attributes["content"].Value;
if (token.Length < 9)
{
- SiteManager.echoErrLog(SiteName, "自动登录失败[1] ");
+ SiteManager.EchoErrLog(SiteName, "自动登录失败[1] ");
return;
}
@@ -111,7 +111,7 @@ private void Login(IWebProxy proxy)
if (!pagedata.Contains("setUserId"))
{
- SiteManager.echoErrLog(SiteName, $"{SiteName} 自动登录失败");
+ SiteManager.EchoErrLog(SiteName, $"{SiteName} 自动登录失败");
}
else
{
@@ -123,7 +123,7 @@ private void Login(IWebProxy proxy)
}
catch (Exception e)
{
- SiteManager.echoErrLog(SiteName, e, e.Message.Contains("IP") ? e.Message : "可能无法连接到服务器");
+ SiteManager.EchoErrLog(SiteName, e, e.Message.Contains("IP") ? e.Message : "可能无法连接到服务器");
}
}
}
@@ -155,7 +155,7 @@ private bool IELogin()
}
else if (startLogin)
{
- SiteManager.echoErrLog(SiteName, "用户未登录或登录失败 ");
+ SiteManager.EchoErrLog(SiteName, "用户未登录或登录失败 ");
}
return result;
diff --git a/SitePack/SitePack.csproj b/SitePack/SitePack.csproj
index aa2c9d8..8807327 100644
--- a/SitePack/SitePack.csproj
+++ b/SitePack/SitePack.csproj
@@ -63,6 +63,7 @@
+
diff --git a/SitePack/SitePixiv.cs b/SitePack/SitePixiv.cs
index e4686e2..84b6ea6 100644
--- a/SitePack/SitePixiv.cs
+++ b/SitePack/SitePixiv.cs
@@ -7,14 +7,16 @@
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
+using System.Threading;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
+using System.Windows.Forms;
namespace SitePack
{
///
/// PIXIV
- /// Last change 190905
+ /// Last change 190918
///
public class SitePixiv : AbstractImageSite
@@ -117,8 +119,8 @@ public override bool IsSupportCount //fixed 20
private int count = 1;
private string keyWord = null;
private static string cookie = string.Empty, nowUser = null;
- private string[] user = { "moe1user", "moe3user", "a-rin-a" };
- private string[] pass = { "630489372", "1515817701", "2422093014" };
+ private readonly string[] user = { "moe1user", "moe3user", "a-rin-a" };
+ private readonly string[] pass = { "630489372", "1515817701", "2422093014" };
private static int startLogin = 0;
private static string tempPage = null;
private Random rand = new Random();
@@ -155,6 +157,7 @@ public override string GetPageString(int page, int count, string keyWord, IWebPr
{
if (!Login(proxy))
{
+ this.keyWord = keyWord;
return string.Empty;
}
//if (page > 1000) throw new Exception("页码过大,若需浏览更多图片请使用关键词限定范围");
@@ -162,12 +165,12 @@ public override string GetPageString(int page, int count, string keyWord, IWebPr
string url = null;
this.page = page;
this.count = count;
- this.keyWord = keyWord;
+
if (srcType == PixivSrcType.Pid || srcType == PixivSrcType.PidPlus)
{
if (keyWord.Length > 0 && int.TryParse(keyWord.Trim(), out memberId))
{
- url = SiteUrl + "/member_illust.php?mode=medium&illust_id=" + memberId;
+ url = $"{SiteUrl}/member_illust.php?mode=medium&illust_id={memberId}";
}
else
{
@@ -176,15 +179,15 @@ public override string GetPageString(int page, int count, string keyWord, IWebPr
}
else
{
- //http://www.pixiv.net/new_illust.php?p=2
- url = SiteUrl + "/new_illust.php?p=" + page;
-
if (keyWord.Length > 0)
{
//http://www.pixiv.net/search.php?s_mode=s_tag&word=hatsune&order=date_d&p=2
- url = SiteUrl + "/search.php?s_mode=s_tag"
- + (srcType == PixivSrcType.TagFull ? "_full" : "")
- + "&word=" + keyWord + "&order=date_d&p=" + page;
+ url = $"{SiteUrl}/search.php?s_mode=s_tag{(srcType == PixivSrcType.TagFull ? "_full" : "")}&word={keyWord}&order=date_d&p={page}";
+ }
+ else
+ {
+ //http://www.pixiv.net/new_illust.php?p=2
+ url = $"{SiteUrl}/new_illust.php?p={page}";
}
memberId = 0;
@@ -198,7 +201,7 @@ public override string GetPageString(int page, int count, string keyWord, IWebPr
//url = SiteUrl + "/member_illust.php?id=" + memberId + "&p=" + page;
//https://www.pixiv.net/ajax/user/212801/profile/all
//https://www.pixiv.net/ajax/user/212801/profile/illusts?ids%5B%5D=70095905&ids%5B%5D=69446164&is_manga_top=0
- url = SiteUrl + "/ajax/user/" + memberId + "/profile/all";
+ url = $"{SiteUrl}/ajax/user/{memberId}/profile/all";
}
else if (srcType == PixivSrcType.Day)
{
@@ -219,11 +222,6 @@ public override string GetPageString(int page, int count, string keyWord, IWebPr
shc.Remove("X-Requested-With");
shc.Remove("Accept-Ranges");
shc.ContentType = SessionHeadersValue.AcceptTextHtml;
- // 如果cookie丢失则还原
- if(string.IsNullOrWhiteSpace(cookie))
- {
- CookieRestore();
- }
shc.Set("Cookie", cookie);
string pageString = Sweb.Get(url, proxy, shc);
if (srcType == PixivSrcType.PidPlus)
@@ -231,7 +229,7 @@ public override string GetPageString(int page, int count, string keyWord, IWebPr
//相关作品json信息
//https://www.pixiv.net/ajax/illust/70575612/recommend/init?limit=18
shc.ContentType = SessionHeadersValue.AcceptAppJson;
- tempPage = Sweb.Get($"{ SiteUrl}/ajax/illust/{keyWord}/recommend/init?limit=18", proxy, shc);
+ tempPage = Sweb.Get($"{SiteUrl}/ajax/illust/{keyWord}/recommend/init?limit=18", proxy, shc);
}
return pageString;
}
@@ -240,7 +238,7 @@ public override List GetImages(string pageString, IWebProxy proxy)
{
List imgs = new List();
- HtmlDocument doc = new HtmlDocument();
+ HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(pageString);
//retrieve all elements via xpath
@@ -473,7 +471,7 @@ public override List GetImages(string pageString, IWebProxy proxy)
}
catch (Exception ex)
{
- SiteManager.echoErrLog(SiteName, ex);
+ SiteManager.EchoErrLog(SiteName, ex, $"获取 [{Uri.UnescapeDataString(keyWord)}] 失败", true);
throw new Exception("没有找到图片哦~ .=ω=");
}
@@ -629,8 +627,8 @@ private Img GenerateImg(string detailUrl, string sample_url, string id)
Match regDesc = new Regex(@"illustTitle"":""(.*?)""").Match(page),
regAuthor = new Regex(@"userName"":""(.*?)""").Match(page);
- HtmlDocument doc = new HtmlDocument();
- HtmlDocument ds = new HtmlDocument();
+ HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
+ HtmlAgilityPack.HtmlDocument ds = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(page);
Pcount = Regex.Match(i.SampleUrl, @"(?<=_p)\d+(?=_)").Value;
@@ -847,39 +845,53 @@ private bool Login(IWebProxy proxy)
shc.Remove("Accept-Ranges");
shc.Remove("Cookie");
shc.ContentType = SessionHeadersValue.AcceptTextHtml;
- HtmlDocument hdoc = new HtmlDocument();
+ HtmlAgilityPack.HtmlDocument hdoc = new HtmlAgilityPack.HtmlDocument();
- //请求1 获取post_key
+ //请求1 获取登录参数post_key
data = Sweb.Get(LoginURL, proxy, shc);
hdoc.LoadHtml(data);
post_key = hdoc.DocumentNode.SelectSingleNode("//input[@name='post_key']").Attributes["value"].Value;
if (post_key.Length < 9)
{
- SiteManager.echoErrLog(SiteName, "自动登录失败 ", startLogin < 2);
+ SiteManager.EchoErrLog(SiteName, "自动登录失败 ", startLogin < 2);
return false;
}
//请求2 POST取登录Cookie
shc.ContentType = SessionHeadersValue.ContentTypeFormUrlencoded;
- data = "pixiv_id=" + user[index]
- + "&captcha=&g_recaptcha_response="
- + "&password=" + pass[index]
- + "&post_key=" + post_key
- + "&source=pc&ref=&return_to=https%3A%2F%2Fwww.pixiv.net%2F";
+ data = $@"&captcha=&g_recaptcha_response=
+&password={pass[index]}
+&pixiv_id={user[index]}
+&post_key={post_key}
+&source=accounts&ref=&return_to=https%3A%2F%2Fwww.pixiv.net%2F";
data = Sweb.Post(loginpost, data, proxy, shc);
cookie = Sweb.GetURLCookies(SiteUrl);
if (!data.Contains("success"))
{
- if (data.Contains("locked"))
+ if (startLogin > 1)
{
- SiteManager.echoErrLog(SiteName,
- $"登录Pixiv时IP被封锁,剩余时间:{Regex.Match(data, "lockout_time_by_ip\":\"(\\d+)\"").Groups[1].Value}", startLogin < 2);
+ if (data.Contains("locked"))
+ {
+ ShowMessage($"登录Pixiv时IP被封锁,剩余时间:{Regex.Match(data, "lockout_time_by_ip\":\"(\\d+)\"").Groups[1].Value}");
+ }
+ else if (cookie.Length < 9)
+ {
+ ShowMessage("自动登录失败 ");
+ }
+ else
+ {
+ string errinfo = $"自动登录失败 {Regex.Unescape(data)}";
+ errinfo = IsLoginSite ? errinfo : $"{errinfo}\r\n\r\n请使用右键菜单[ 登录站点 ]登录\r\n" +
+ $"账号:{user[index]}\r\n密码:{pass[index]}\r\n或使用自己的账号登录\r\n\r\n点击 [确定] 复制内置账号";
+ if (MessageBox.Show(errinfo, ShortName, MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK)
+ {
+ Thread newThread = new Thread(() => Clipboard.SetText($"{user[index]} {pass[index]}"));
+ newThread.SetApartmentState(ApartmentState.STA);
+ newThread.Start();
+ }
+ }
}
- else if (cookie.Length < 9)
- SiteManager.echoErrLog(SiteName, "自动登录失败 ", startLogin < 2);
- else
- SiteManager.echoErrLog(SiteName, $"自动登录失败 {data}", startLogin < 2);
}
else
{
@@ -893,7 +905,7 @@ private bool Login(IWebProxy proxy)
}
catch (Exception e)
{
- SiteManager.echoErrLog(SiteName, e, e.Message.Contains("IP") ? e.Message : "可能无法连接到服务器", startLogin < 2);
+ SiteManager.EchoErrLog(SiteName, e, e.Message.Contains("IP") ? e.Message : "可能无法连接到服务器", startLogin < 2);
return false;
}
}
@@ -910,22 +922,27 @@ private bool IELogin()
bool result = SiteManager.LoginSite(this, ref cookie, "/logout", ref Sweb, ref shc);
if (result && !string.IsNullOrWhiteSpace(cookie))
- {
+ {
nowUser = "你的账号";
cookie = $"pixiv;{cookie}";
}
else if (string.IsNullOrWhiteSpace(cookie))
{
- nowUser = "你的账号";
- result = IsLoginSite = true;
+ nowUser = null;
+ result = IsLoginSite = false;
}
else
{
- SiteManager.echoErrLog(SiteName, "用户登录失败 ", startLogin < 2);
+ SiteManager.EchoErrLog(SiteName, "用户登录失败 ", startLogin < 2);
}
return result;
}
+ private void ShowMessage(string text)
+ {
+ MessageBox.Show(text, ShortName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
+ }
+
}
}
\ No newline at end of file
diff --git a/SitePack/SiteSankaku.cs b/SitePack/SiteSankaku.cs
index 34c2cc2..b9eae8f 100644
--- a/SitePack/SiteSankaku.cs
+++ b/SitePack/SiteSankaku.cs
@@ -170,7 +170,7 @@ private int SetLogin()
}
catch
{
- SiteManager.echoErrLog(ShortName, "搜索之前必须先登录站点、从右键菜单中登录站点", false, true);
+ SiteManager.EchoErrLog(ShortName, "搜索之前必须先登录站点、从右键菜单中登录站点", false, true);
return 0;
}
}
@@ -222,7 +222,7 @@ private void Login(IWebProxy proxy)
{
IsLoginSite = 0;
nowUser = nowPwd = null;
- SiteManager.echoErrLog(ShortName, $"登录失败 - {post}");
+ SiteManager.EchoErrLog(ShortName, $"登录失败 - {post}");
return;
}
@@ -236,7 +236,7 @@ private void Login(IWebProxy proxy)
{
IsLoginSite = 0;
nowUser = nowPwd = null;
- SiteManager.echoErrLog(ShortName, "登录失败 - 验证账号错误");
+ SiteManager.EchoErrLog(ShortName, "登录失败 - 验证账号错误");
return;
}
@@ -252,7 +252,7 @@ private void Login(IWebProxy proxy)
{
IsLoginSite = 0;
nowUser = nowPwd = null;
- SiteManager.echoErrLog(ShortName, e, "登录失败 - 内部错误");
+ SiteManager.EchoErrLog(ShortName, e, "登录失败 - 内部错误");
}
}
@@ -292,7 +292,7 @@ private void Login(IWebProxy proxy)
{
IsLoginSite = 0;
nowUser = nowPwd = null;
- SiteManager.echoErrLog(ShortName, $"登录失败 - {post}");
+ SiteManager.EchoErrLog(ShortName, $"登录失败 - {post}");
return;
}
else
@@ -313,7 +313,7 @@ private void Login(IWebProxy proxy)
{
IsLoginSite = 0;
nowUser = nowPwd = null;
- SiteManager.echoErrLog(ShortName, e, "登录失败 - 内部错误");
+ SiteManager.EchoErrLog(ShortName, e, "登录失败 - 内部错误");
}
}