diff --git a/MoeLoaderP.Core/DownloadItem.cs b/MoeLoaderP.Core/DownloadItem.cs index 465ab22..306762b 100644 --- a/MoeLoaderP.Core/DownloadItem.cs +++ b/MoeLoaderP.Core/DownloadItem.cs @@ -1,4 +1,6 @@ -using System; +using ImageMagick; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; @@ -7,8 +9,6 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -using ImageMagick; -using Newtonsoft.Json; namespace MoeLoaderP.Core { @@ -52,26 +52,8 @@ public string DownloadStatusIconText { get { - switch (Status) - { - case DownloadStatusEnum.WaitForDownload: - return ""; - case DownloadStatusEnum.Success: - return ""; - case DownloadStatusEnum.Cancel: - return ""; - case DownloadStatusEnum.IsExist: - return ""; - case DownloadStatusEnum.Failed: - return ""; - case DownloadStatusEnum.Downloading: - return ""; - case DownloadStatusEnum.Skip: - return ""; - case DownloadStatusEnum.Stop: - return WebUtility.HtmlDecode(""); - } - return null; + var strings = new[] {"", "", "", WebUtility.HtmlDecode(""), "", "", ""}; + return strings[(int) Status]; } } @@ -105,7 +87,7 @@ public DownloadItem(Settings set, dynamic bitimg, MoeItem item, int subindex = 0 CurrentMoeItem = item; SubIndex = subindex; OriginFileName = Path.GetFileName(item.DownloadUrlInfo.Url); - OriginFileName = Path.GetFileNameWithoutExtension(item.DownloadUrlInfo.Url); + OriginFileNameWithoutExt = Path.GetFileNameWithoutExtension(item.DownloadUrlInfo.Url).ToDecodedUrl(); var father = subindex == 0 ? null : fatheritem; GenFileNameWithoutExt(father); GenLocalFileFullPath(father); @@ -120,19 +102,22 @@ public async Task DownloadFileAsync() if (SubItems.Count > 0) { Status = DownloadStatusEnum.Downloading; + var b = Set.DownloadFirstSeveralCount < SubItems.Count && Set.IsDownloadFirstSeveral; + var count = b ? Set.DownloadFirstSeveralCount : SubItems.Count; for (var i = 0; i < SubItems.Count; i++) { + + StatusText = $"正在下载 {i+1} / {count} 张"; if (i < Set.DownloadFirstSeveralCount || Set.IsDownloadFirstSeveral == false) { var item = SubItems[i]; await item.DownloadFileAsync(); } - - var count = Set.DownloadFirstSeveralCount < SubItems.Count ? Set.DownloadFirstSeveralCount : SubItems.Count; + Progress = (i + 1d) / count * 100d; } Status = DownloadStatusEnum.Success; - StatusText = "下载完成"; + StatusText = $"{count} 张下载完成"; } else { @@ -158,7 +143,7 @@ public async Task DownloadFileAsync() else { Status = DownloadStatusEnum.Skip; - StatusText = "跳过"; + StatusText = "已存在,跳过"; return; } @@ -176,19 +161,18 @@ public async Task DownloadFileAsync() if (File.Exists(LocalFileFullPath)) { Status = DownloadStatusEnum.Skip; - StatusText = "跳过"; + StatusText = "已存在,跳过"; return; } Status = DownloadStatusEnum.Downloading; var data = await net.Client.GetAsync(url.Url, token); var bytes = await data.Content.ReadAsByteArrayAsync(); - + var dir = Path.GetDirectoryName(LocalFileFullPath); if (!Directory.Exists(dir)) Directory.CreateDirectory(dir ?? throw new InvalidOperationException()); using (var fs = new FileStream(LocalFileFullPath, FileMode.Create)) { await fs.WriteAsync(bytes, 0, bytes.Length, token); - } if (CurrentMoeItem.ExtraFile != null) @@ -197,7 +181,7 @@ public async Task DownloadFileAsync() File.WriteAllText(path, CurrentMoeItem.ExtraFile.Content); } - if (url.IsPixivGifZip && CurrentMoeItem.ExtraFile!=null) + if (url.IsPixivGifZip && CurrentMoeItem.ExtraFile != null) { dynamic json = JsonConvert.DeserializeObject(CurrentMoeItem.ExtraFile.Content); var list = json.body.frames; @@ -237,9 +221,9 @@ await Task.Run(() => } } - public void ConvertPixivZipToGif(Stream stream,dynamic frames,FileInfo fi) + public void ConvertPixivZipToGif(Stream stream, dynamic frames, FileInfo fi) { - var delayList= new List(); + var delayList = new List(); using (var images = new MagickImageCollection()) { foreach (var frame in frames) @@ -289,7 +273,7 @@ public void GenLocalFileFullPath(MoeItem father = null) public void GenFileNameWithoutExt(MoeItem father = null) { var img = father ?? CurrentMoeItem; - + var format = Set.SaveFileNameFormat; if (format.IsNaN()) { @@ -302,7 +286,7 @@ public void GenFileNameWithoutExt(MoeItem father = null) LocalFileShortNameWithoutExt = SubIndex > 0 ? $"{sb} p{SubIndex}" : $"{sb}"; } - public string FormatText(string format,MoeItem img,bool isFolder=false) + public string FormatText(string format, MoeItem img, bool isFolder = false) { var sb = new StringBuilder(format); sb.Replace("%site", img.Site.ShortName); @@ -326,29 +310,28 @@ public string FormatText(string format,MoeItem img,bool isFolder=false) sb.Replace("%copyright", img.Copyright ?? "no-copyright"); foreach (var c in Path.GetInvalidFileNameChars()) { - if(c == '\\' && isFolder) continue; + if (c == '\\' && isFolder) continue; sb.Replace($"{c}", ""); } return sb.ToString(); } - public string AutoRenameFullPath() { - var oldf = LocalFileFullPath; - var ext = Path.GetExtension(oldf); - var dir = Path.GetDirectoryName(oldf); - var file = Path.GetFileNameWithoutExtension(oldf); + var oldF = LocalFileFullPath; + var ext = Path.GetExtension(oldF); + var dir = Path.GetDirectoryName(oldF); + var file = Path.GetFileNameWithoutExtension(oldF); var i = 2; - var newf = $"{dir}\\{file}{-i}{ext}"; - while (File.Exists(newf)) + var newF = $"{dir}\\{file}{-i}{ext}"; + while (File.Exists(newF)) { i++; - newf = $"{dir}{-i}{ext}"; + newF = $"{dir}{-i}{ext}"; } - return newf; + return newF; } } @@ -357,6 +340,6 @@ public class DownloadItems : ObservableCollection { } public enum DownloadStatusEnum { - Success, Failed, Cancel, IsExist, Stop, Downloading, WaitForDownload, Skip + Success, Failed, Cancel, Stop, Downloading, WaitForDownload, Skip } } \ No newline at end of file diff --git a/MoeLoaderP.Core/Extend.cs b/MoeLoaderP.Core/Extend.cs index 76a3c47..67d2c92 100644 --- a/MoeLoaderP.Core/Extend.cs +++ b/MoeLoaderP.Core/Extend.cs @@ -28,9 +28,9 @@ public static string ToPairsString(this Pairs pairs) var query = string.Empty; var i = 0; if (pairs == null) return query; - foreach (var para in pairs.Where(para => !string.IsNullOrEmpty(para.Value))) + foreach (var para in pairs.Where(para => !para.Value.IsNaN())) { - query += string.Format("{2}{0}={1}", para.Key, para.Value, i > 0 ? "&" : "?"); + query += $"{(i > 0 ? "&" : "?")}{para.Key}={para.Value}"; i++; } @@ -38,13 +38,11 @@ public static string ToPairsString(this Pairs pairs) } public static dynamic CheckListNull(dynamic dyObj) => dyObj ?? new List(); - public static bool IsNaN(this string text) - { - return string.IsNullOrWhiteSpace(text); - } + public static bool IsNaN(this string text) => string.IsNullOrWhiteSpace(text); + public static DateTime? ToDateTime(this string dateTime) { - if (string.IsNullOrWhiteSpace(dateTime)) return null; + if (dateTime.IsNaN()) return null; var timeInt = dateTime.ToLong(); if (timeInt != 0) { @@ -70,19 +68,13 @@ public static long ToLong(this string idStr) return id; } - public static string ToEncodedUrl(this string orgstr) - { - return HttpUtility.UrlEncode(orgstr, Encoding.UTF8); - } + public static string ToEncodedUrl(this string orgStr) => HttpUtility.UrlEncode(orgStr, Encoding.UTF8); - public static string ToDecodedUrl(this string orgstr) - { - return HttpUtility.UrlDecode(orgstr, Encoding.UTF8); - } + public static string ToDecodedUrl(this string orgStr) => HttpUtility.UrlDecode(orgStr, Encoding.UTF8); public static void GoUrl(this string url) { - if (string.IsNullOrWhiteSpace(url)) return; + if (url.IsNaN()) return; try { Process.Start(url); diff --git a/MoeLoaderP.Core/MoeItem.cs b/MoeLoaderP.Core/MoeItem.cs index d7d2948..a1c8002 100644 --- a/MoeLoaderP.Core/MoeItem.cs +++ b/MoeLoaderP.Core/MoeItem.cs @@ -22,7 +22,7 @@ public class MoeItem : BindingObject public string DateString { - get => string.IsNullOrWhiteSpace(_dateString) ? Date?.ToString("G", new CultureInfo("zh-CN")) : _dateString; + get => _dateString.IsNaN() ? Date?.ToString("G", new CultureInfo("zh-CN")) : _dateString; set => _dateString = value; } @@ -35,7 +35,16 @@ public string DateString /// 上传用户ID /// public string UploaderId { get; set; } - public double Score { get; set; } + + public double Score + { + get => _score; + set + { + _score = value; OnPropertyChanged(nameof(Score)); + } + } + public int Rank { get; set; } public bool TipHighLight { get; set; } @@ -112,6 +121,7 @@ public string ResolutionText private int _imageCount; private string _dateString; private string _tip; + private double _score; public int ImagesCount { @@ -198,8 +208,9 @@ public UrlInfo(int priority, string url, string referer = null) public string GetFileExtFromUrl() { - if (string.IsNullOrEmpty(Url)) return null; - var type = Path.GetExtension(Url).Replace(".", "").ToUpper(); + if (Url.IsNaN()) return null; + var type = Path.GetExtension(Url)?.Replace(".", "").ToUpper(); + if (type == null) return null; if (type.Contains("?")) { type = type.Split('?')[0]; diff --git a/MoeLoaderP.Core/NetDocker.cs b/MoeLoaderP.Core/NetDocker.cs index c32a062..79fca6a 100644 --- a/MoeLoaderP.Core/NetDocker.cs +++ b/MoeLoaderP.Core/NetDocker.cs @@ -1,4 +1,6 @@ -using System; +using HtmlAgilityPack; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Net; using System.Net.Http; @@ -6,8 +8,6 @@ using System.Threading; using System.Threading.Tasks; using System.Xml; -using HtmlAgilityPack; -using Newtonsoft.Json; namespace MoeLoaderP.Core { @@ -48,7 +48,7 @@ public NetDocker(Settings settings, string cookieurl = null) public void SetReferer(string rfurl) { - if (string.IsNullOrWhiteSpace(rfurl)) return; + if (rfurl.IsNaN()) return; Client.DefaultRequestHeaders.Referrer = new Uri(rfurl); } @@ -153,7 +153,7 @@ public IWebProxy Proxy } return xml; } - + } diff --git a/MoeLoaderP.Core/SearchSession.cs b/MoeLoaderP.Core/SearchSession.cs index 4fafa6c..81174bd 100644 --- a/MoeLoaderP.Core/SearchSession.cs +++ b/MoeLoaderP.Core/SearchSession.cs @@ -1,11 +1,11 @@ -using System; +using MoeLoaderP.Core.Sites; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; -using MoeLoaderP.Core.Sites; namespace MoeLoaderP.Core { @@ -44,7 +44,7 @@ public async Task TrySearchNextPageAsync() } catch (Exception ex) { - Extend.ShowMessage(ex.Message,ex.ToString(), Extend.MessagePos.Window); + Extend.ShowMessage(ex.Message, ex.ToString(), Extend.MessagePos.Window); Extend.Log(ex.Message, ex.StackTrace); } @@ -68,12 +68,12 @@ public async Task SearchNextPageAsync(CancellationToken token) // 搜索起始页的所有图片(若网站查询参数有支持的条件过滤,则在搜索时就已自动过滤相关条件) var sb = new StringBuilder(); sb.AppendLine($"正在搜索站点 {tempPara.Site.DisplayName} 第 {tempPara.PageIndex} 页图片"); - sb.Append($"(参数:kw:{(!string.IsNullOrWhiteSpace(tempPara.Keyword) ? tempPara.Keyword : "N/A")},num:{tempPara.Count})"); + sb.Append($"(参数:kw:{(!tempPara.Keyword.IsNaN() ? tempPara.Keyword : "N/A")},num:{tempPara.Count})"); Extend.ShowMessage(sb.ToString(), null, Extend.MessagePos.Searching); var imagesOrg = await tempPara.Site.GetRealPageImagesAsync(tempPara, token); if (imagesOrg == null || imagesOrg.Count == 0) { - Extend.ShowMessage("无搜索结果",null, Extend.MessagePos.Searching); + Extend.ShowMessage("无搜索结果", null, Extend.MessagePos.Searching); return; } for (var i = 0; i < imagesOrg.Count; i++) @@ -123,7 +123,7 @@ public async Task SearchNextPageAsync(CancellationToken token) var sb = new StringBuilder(); sb.AppendLine($"正在搜索站点 {tempPara.Site.DisplayName} 第 {tempPara.PageIndex} 页图片"); sb.AppendLine($"已获取第{tempPara.PageIndex - 1}页{images.Count}张图片,还需{tempPara.Count - images.Count}张"); - sb.Append($"(参数:kw:{(!string.IsNullOrWhiteSpace(tempPara.Keyword) ? tempPara.Keyword : "N/A")},num:{tempPara.Count})"); + sb.Append($"(参数:kw:{(!tempPara.Keyword.IsNaN() ? tempPara.Keyword : "N/A")},num:{tempPara.Count})"); Extend.ShowMessage(sb.ToString(), null, Extend.MessagePos.Searching); var imagesNextRPage = await tempPara.Site.GetRealPageImagesAsync(tempPara, token); // 搜索下一页(真)的所有图片 if (imagesNextRPage == null || imagesNextRPage.Count == 0) // 当下一页(真)的搜索到的未进行本地过滤图片数量为0时,表示已经搜索完了 @@ -135,7 +135,7 @@ public async Task SearchNextPageAsync(CancellationToken token) else // 当下一页(真)未过滤图片数量不为0时 { Filter(imagesNextRPage); // 本地过滤下一页(真) - + foreach (var item in imagesNextRPage) { if (images.Count < tempPara.Count) images.Add(item); // 添加图片数量直到够参数设定的图片数量为止 @@ -149,8 +149,8 @@ public async Task SearchNextPageAsync(CancellationToken token) // Load end newVPage.ImageItems = images; LoadedPages.Add(newVPage); - if(images.Message!=null) Extend.ShowMessage(images.Message); - if(images.Ex!=null) Extend.ShowMessage(images.Ex.Message,images.Ex.ToString(), Extend.MessagePos.Window); + if (images.Message != null) Extend.ShowMessage(images.Message); + if (images.Ex != null) Extend.ShowMessage(images.Ex.Message, images.Ex.ToString(), Extend.MessagePos.Window); Extend.ShowMessage("搜索完毕", null, Extend.MessagePos.Searching); } @@ -189,9 +189,9 @@ public void Filter(MoeItems items) } if (para.IsFilterFileType) // 过滤图片扩展名 { - foreach (var s in para.FilterFileTpyeText.Split(';')) + foreach (var s in para.FilterFileTypeText.Split(';')) { - if (string.IsNullOrWhiteSpace(s)) continue; + if (s.IsNaN()) continue; if (string.Equals(item.FileType, s, StringComparison.CurrentCultureIgnoreCase)) { if (!para.IsFileTypeShowSpecificOnly) del = true; @@ -203,10 +203,6 @@ public void Filter(MoeItems items) } } - // 过滤重复图片 - // 去除与上一页重复的 - // if (LoadedPages.Any() && LoadedPages.Last().ImageItems.Has(item)) del = true; - if (!del) continue; items.RemoveAt(i); i--; @@ -244,7 +240,7 @@ public string GetCurrentSearchStateText() } } - if (!string.IsNullOrWhiteSpace(para.Keyword)) sb += $"→\"{para.Keyword}\""; + if (!para.Keyword.IsNaN()) sb += $"→\"{para.Keyword}\""; return sb; } } @@ -270,7 +266,6 @@ public class SearchPara public MoeSite Site { get; set; } public SearchSession CurrentSearch { get; set; } public string Keyword { get; set; } - public bool HasKeyword => !string.IsNullOrWhiteSpace(Keyword); public int PageIndex { get; set; } public int LastId { get; set; } public int Count { get; set; } @@ -283,7 +278,7 @@ public class SearchPara public int MinHeight { get; set; } public bool IsFilterFileType { get; set; } - public string FilterFileTpyeText { get; set; } + public string FilterFileTypeText { get; set; } public bool IsFileTypeShowSpecificOnly { get; set; } public ImageOrientation Orientation { get; set; } = ImageOrientation.None; diff --git a/MoeLoaderP.Core/Settings.cs b/MoeLoaderP.Core/Settings.cs index aaa9123..29bd7fa 100644 --- a/MoeLoaderP.Core/Settings.cs +++ b/MoeLoaderP.Core/Settings.cs @@ -213,9 +213,7 @@ public bool IsCustomSiteMode } #endregion - - - + public void Save(string jsonPath) { var json = JsonConvert.SerializeObject(this); @@ -247,17 +245,20 @@ public static Settings Load(string jsonPath) } } - public class MoeSiteSetting + public class MoeSiteSetting : BindingObject { - public string LonginCookie { get; set; } - } - - + private string _loginCookie; + public string LoginCookie + { + get => _loginCookie; + set => SetField(ref _loginCookie, value, nameof(LoginCookie)); + } + } + public class CustomSiteSetting { public string DisplayName { get; set; } - } public class CustomSiteSettingList : List { } diff --git a/MoeLoaderP.Core/SiteManager.cs b/MoeLoaderP.Core/SiteManager.cs index 5f41193..fb8b3fc 100644 --- a/MoeLoaderP.Core/SiteManager.cs +++ b/MoeLoaderP.Core/SiteManager.cs @@ -9,15 +9,14 @@ namespace MoeLoaderP.Core public class SiteManager { public Settings Settings { get; set; } - public MoeSites Sites { get; set; } = new MoeSites(); + public MoeSites Sites { get; set; } public SiteManager(Settings settings) { Settings = settings; - Sites.Settings = settings; + Sites = new MoeSites(settings); settings.PropertyChanged += SettingsOnPropertyChanged; SetDefaultSiteList(); - } private void SettingsOnPropertyChanged(object sender, PropertyChangedEventArgs e) diff --git a/MoeLoaderP.Core/Sites/AnimePicsSite.cs b/MoeLoaderP.Core/Sites/AnimePicsSite.cs index 1c8243b..f4bc482 100644 --- a/MoeLoaderP.Core/Sites/AnimePicsSite.cs +++ b/MoeLoaderP.Core/Sites/AnimePicsSite.cs @@ -85,7 +85,7 @@ public override async Task GetRealPageImagesAsync(SearchPara para, Can var reg = Regex.Replace(idattr, @"[^0-9]+", ""); img.Id = reg.ToInt(); var src = imgnode.GetAttributeValue("src", ""); - if (!string.IsNullOrWhiteSpace(src)) img.Urls.Add(new UrlInfo( 1, $"{pre}{src}", url)); + if (!src.IsNaN()) img.Urls.Add(new UrlInfo( 1, $"{pre}{src}", url)); var resstrs = node.SelectSingleNode("div[@class='img_block_text']/a")?.InnerText.Trim().Split('x'); if (resstrs?.Length == 2) { @@ -96,7 +96,7 @@ public override async Task GetRealPageImagesAsync(SearchPara para, Can var match = Regex.Replace(scorestr ?? "0", @"[^0-9]+", ""); img.Score = match.ToInt(); var detail = node.SelectSingleNode("a").GetAttributeValue("href", ""); - if (!string.IsNullOrWhiteSpace(detail)) + if (!detail.IsNaN()) { img.DetailUrl = $"{HomeUrl}{detail}"; img.GetDetailTaskFunc = async () => await GetDetailTask(img); @@ -125,7 +125,7 @@ public async Task GetDetailTask(MoeItem img) { foreach (var tagnode in tagnodes) { - if (!string.IsNullOrWhiteSpace(tagnode.InnerText)) img.Tags.Add(tagnode.InnerText); + if (!tagnode.InnerText.IsNaN()) img.Tags.Add(tagnode.InnerText); } } } diff --git a/MoeLoaderP.Core/Sites/BilibiliSite.cs b/MoeLoaderP.Core/Sites/BilibiliSite.cs index d6bba22..1994d86 100644 --- a/MoeLoaderP.Core/Sites/BilibiliSite.cs +++ b/MoeLoaderP.Core/Sites/BilibiliSite.cs @@ -22,15 +22,26 @@ public BilibiliSite() SubMenu.Add("摄影(COS)", sub); SubMenu.Add("摄影(私服)", sub); - SupportState.IsSupportKeyword = false; - SupportState.IsSupportScore = false; SupportState.IsSupportRating = false; DownloadTypes.Add("原图", 4); - MenuFunc.ShowKeyword = false; } public override async Task GetRealPageImagesAsync(SearchPara para, CancellationToken token) + { + var imgs = new MoeItems(); + if (para.Keyword.IsNaN()) + { + await SearchByNewOrHot(para, token, imgs); + } + else + { + await SearchByKeyword(para, token, imgs); + } + return imgs; + } + + public async Task SearchByNewOrHot(SearchPara para, CancellationToken token, MoeItems imgs) { const string api = "https://api.vc.bilibili.com/link_draw/v2"; var type = para.Lv3MenuIndex == 0 ? "new" : "hot"; @@ -55,7 +66,7 @@ public override async Task GetRealPageImagesAsync(SearchPara para, Can {"page_size", $"{count}"} }); - var imgs = new MoeItems(); + foreach (var item in Extend.CheckListNull(json?.data?.items)) { var cat = para.SubMenuIndex == 0 ? "/d" : "/p"; @@ -69,7 +80,7 @@ public override async Task GetRealPageImagesAsync(SearchPara para, Can img.Width = $"{i0?.img_width}".ToInt(); img.Height = $"{i0?.img_height}".ToInt(); img.Date = $"{item.item?.upload_time}".ToDateTime(); - img.Urls.Add(1, $"{i0?.img_src}@320w_320h.jpg", HomeUrl + cat); + img.Urls.Add(1, $"{i0?.img_src}@336w_336h_1e_1c.jpg", HomeUrl + cat); img.Urls.Add(4, $"{i0?.img_src}"); img.Title = $"{item.item?.title}"; var list = item.item?.pictures as JArray; @@ -78,20 +89,110 @@ public override async Task GetRealPageImagesAsync(SearchPara para, Can foreach (var pic in item.item.pictures) { var child = new MoeItem(this, para); - child.Urls.Add(1, $"{pic.img_src}@512w_512h_1e", HomeUrl + cat); + child.Urls.Add(1, $"{pic.img_src}@336w_336h_1e_1c.jpg", HomeUrl + cat); child.Urls.Add(4, $"{pic.img_src}"); child.Width = $"{pic.img_width}".ToInt(); child.Height = $"{pic.img_height}".ToInt(); img.ChildrenItems.Add(child); } } + img.GetDetailTaskFunc = async () => await GetSearchByNewOrHotDetailTask(img, token, para); img.OriginString = $"{item}"; imgs.Add(img); } var c = $"{json?.data.total_count}".ToInt(); - Extend.ShowMessage($"共搜索到{c}张,已加载至{para.PageIndex}页,共{c/para.Count}页", null, Extend.MessagePos.InfoBar); - return imgs; + Extend.ShowMessage($"共搜索到{c}张,已加载至{para.PageIndex}页,共{c / para.Count}页", null, Extend.MessagePos.InfoBar); + } + + public async Task SearchByKeyword(SearchPara para, CancellationToken token, MoeItems imgs) + { + const string api = "https://api.bilibili.com/x/web-interface/search/type"; + var newOrHotOrder = para.Lv3MenuIndex == 0? "pubdate" : "stow"; + var drawOrPhotoCatId = para.SubMenuIndex == 0 ? "1" : "2"; + var pairs = new Pairs + { + {"search_type", "photo"}, + {"page",$"{para.PageIndex}" }, + {"order",newOrHotOrder }, + {"keyword",para.Keyword.ToEncodedUrl() }, + {"category_id",drawOrPhotoCatId }, + }; + var net = new NetDocker(Settings); + var json = await net.GetJsonAsync(api, token, pairs); + if(json == null) return; + foreach (var item in Extend.CheckListNull(json.data?.result)) + { + var img = new MoeItem(this,para); + img.Urls.Add(1,$"{item.cover}@336w_336h_1e_1c.jpg"); + img.Urls.Add(4, $"{item.cover}"); + img.Id = $"{item.id}".ToInt(); + img.Score = $"{item.like}".ToInt(); + img.Rank = $"{item.rank_offset}".ToInt(); + img.Title = $"{item.title}"; + img.Uploader = $"{item.uname}"; + img.GetDetailTaskFunc = async () => await GetSearchByKeywordDetailTask(img, token, para); + img.DetailUrl = $"https://h.bilibili.com/{img.Id}"; + img.OriginString = $"{item}"; + imgs.Add(img); + } + + var c = $"{json.data?.numResults}".ToInt(); + Extend.ShowMessage($"共搜索到{c}张,已加载至{para.PageIndex}页,共{c / para.Count}页", null, Extend.MessagePos.InfoBar); + } + + public async Task GetSearchByKeywordDetailTask(MoeItem img,CancellationToken token,SearchPara para) + { + var query = $"https://api.vc.bilibili.com/link_draw/v1/doc/detail?doc_id={img.Id}"; + var json = await new NetDocker(Settings).GetJsonAsync(query,token); + var item = json.data?.item; + if (item == null )return; + if ((item.pictures as JArray)?.Count > 1) + { + var i = 0; + foreach (var pic in Extend.CheckListNull(item.pictures)) + { + var child = new MoeItem(this, para); + child.Urls.Add(1, $"{pic.img_src}@336w_336h_1e_1c.jpg"); + child.Urls.Add(4,$"{pic.img_src}"); + if (i == 0) + { + img.Width = $"{pic.img_width}".ToInt(); + img.Height = $"{pic.img_height}".ToInt(); + } + img.ChildrenItems.Add(child); + i++; + } + } + else if((item.pictures as JArray)?.Count == 1) + { + var pic = json.data?.item?.pictures[0]; + img.Width = $"{pic?.img_width}".ToInt(); + img.Height = $"{pic?.img_height}".ToInt(); + img.Urls.Add(4, $"{pic?.img_src}"); + } + + foreach (var tag in Extend.CheckListNull(item.tags)) + { + img.Tags.Add($"{tag.name}"); + } + + img.Date = $"{json.data?.item?.upload_time}".ToDateTime(); + if (img.Date == null) img.DateString = $"{item.upload_time}"; + } + + public async Task GetSearchByNewOrHotDetailTask(MoeItem img, CancellationToken token, SearchPara para) + { + var query = $"https://api.vc.bilibili.com/link_draw/v1/doc/detail?doc_id={img.Id}"; + var json = await new NetDocker(Settings).GetJsonAsync(query, token); + var item = json.data?.item; + if (item == null) return; + foreach (var tag in Extend.CheckListNull(item.tags)) + { + img.Tags.Add($"{tag.name}"); + } + + img.Score = $"{item.vote_count}".ToInt(); } } } diff --git a/MoeLoaderP.Core/Sites/BooruSite.cs b/MoeLoaderP.Core/Sites/BooruSite.cs index 710e9ed..83b6756 100644 --- a/MoeLoaderP.Core/Sites/BooruSite.cs +++ b/MoeLoaderP.Core/Sites/BooruSite.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Xml; @@ -63,6 +64,8 @@ public override async Task GetAutoHintItemsAsync(SearchPara para, public abstract string GetPageQuery(SearchPara para); + public virtual Func GetDetailTaskFunc { get; set; } + public override async Task GetRealPageImagesAsync(SearchPara para, CancellationToken token) { switch (SiteType) @@ -75,7 +78,6 @@ public override async Task GetRealPageImagesAsync(SearchPara para, Can public async Task GetRealPageImagesAsyncFromXml(SearchPara para, CancellationToken token) { - var client = new NetDocker(Settings).Client; var query = GetPageQuery(para); var xmlRes = await client.GetAsync(query, token); @@ -108,6 +110,10 @@ public async Task GetRealPageImagesAsyncFromXml(SearchPara para, Cance img.Urls.Add(3, $"{UrlPre}{post.Attribute("jpeg_url")?.Value}", GetThumbnailReferer(img)); img.Urls.Add(4, $"{UrlPre}{post.Attribute("file_url")?.Value}", img.DetailUrl); img.OriginString = $"{post}"; + if (GetDetailTaskFunc != null) + { + img.GetDetailTaskFunc = async () => await GetDetailTaskFunc(img, para,token); + } imageItems.Add(img); } @@ -150,7 +156,11 @@ public async Task GetRealPageImagesAsyncFromJson(SearchPara para, Canc img.Copyright = $"{item.tag_string_copyright}"; img.Character = $"{item.tag_string_character}"; img.Artist = $"{item.tag_string_artist}"; - img.OriginString = $"{item}"; + img.OriginString = $"{item}"; + if (GetDetailTaskFunc != null) + { + img.GetDetailTaskFunc = async () => await GetDetailTaskFunc(img, para,token); + } imageItems.Add(img); } diff --git a/MoeLoaderP.Core/Sites/BooruSites.cs b/MoeLoaderP.Core/Sites/BooruSites.cs index d02fac3..bffc47b 100644 --- a/MoeLoaderP.Core/Sites/BooruSites.cs +++ b/MoeLoaderP.Core/Sites/BooruSites.cs @@ -164,31 +164,5 @@ public override string GetPageQuery(SearchPara para) => $"{HomeUrl}/index.php?page=dapi&s=post&q=index&pid={para.PageIndex - 1}&limit={para.Count}&tags={para.Keyword.ToEncodedUrl()}"; } - public class GelbooruSite : BooruSite - { - public override string HomeUrl => "https://gelbooru.com"; - public override string DisplayName => "Gelbooru"; - public override string ShortName => "gelbooru"; - - public override string GetDetailPageUrl(MoeItem item) => $"{HomeUrl}/index.php?page=post&s=view&id={item.Id}"; - - public override string GetHintQuery(SearchPara para) - => $"{HomeUrl}/index.php?page=autocomplete&term={para.Keyword}"; - - public override string GetPageQuery(SearchPara para) - => $"{HomeUrl}/index.php?page=dapi&s=post&q=index&pid={para.PageIndex - 1}&limit={para.Count}&tags={para.Keyword.ToEncodedUrl()}"; - public override async Task GetAutoHintItemsAsync(SearchPara para, CancellationToken token) - { - var ahis = new AutoHintItems(); - var jsonlist = await new NetDocker(Settings).GetJsonAsync(GetHintQuery(para),token); - foreach (var item in jsonlist) - { - ahis.Add(new AutoHintItem - { - Word = $"{item}".Replace("\"",""), - }); - } - return ahis; - } - } + } diff --git a/MoeLoaderP.Core/Sites/EshuuSite.cs b/MoeLoaderP.Core/Sites/EshuuSite.cs index 48b78db..630e6ee 100644 --- a/MoeLoaderP.Core/Sites/EshuuSite.cs +++ b/MoeLoaderP.Core/Sites/EshuuSite.cs @@ -79,7 +79,7 @@ public override async Task GetRealPageImagesAsync(SearchPara para, Can var fileUrl = imgHref.Attributes["href"].Value; if (fileUrl.StartsWith("/")) fileUrl = $"{HomeUrl}{fileUrl}"; var previewUrl = imgHref.SelectSingleNode("img").Attributes["src"].Value; - if (previewUrl.StartsWith("/")) previewUrl = HomeUrl + previewUrl; + if (previewUrl.StartsWith("/")) previewUrl = $"{HomeUrl}{previewUrl}"; img.Urls.Add(1, previewUrl, HomeUrl); var meta = imgNode.SelectSingleNode(".//div[@class='meta']"); img.Date = meta.SelectSingleNode(".//dd[2]").InnerText.ToDateTime(); diff --git a/MoeLoaderP.Core/Sites/GelbooruSite.cs b/MoeLoaderP.Core/Sites/GelbooruSite.cs new file mode 100644 index 0000000..8796374 --- /dev/null +++ b/MoeLoaderP.Core/Sites/GelbooruSite.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace MoeLoaderP.Core.Sites +{ + public class GelbooruSite : BooruSite + { + public override string HomeUrl => "https://gelbooru.com"; + public override string DisplayName => "Gelbooru"; + public override string ShortName => "gelbooru"; + + public override string GetDetailPageUrl(MoeItem item) => $"{HomeUrl}/index.php?page=post&s=view&id={item.Id}"; + + public override string GetHintQuery(SearchPara para) + => $"{HomeUrl}/index.php?page=autocomplete&term={para.Keyword}"; + + public override string GetPageQuery(SearchPara para) + => $"{HomeUrl}/index.php?page=dapi&s=post&q=index&pid={para.PageIndex - 1}&limit={para.Count}&tags={para.Keyword.ToEncodedUrl()}"; + public override async Task GetAutoHintItemsAsync(SearchPara para, CancellationToken token) + { + var ahis = new AutoHintItems(); + var jsonlist = await new NetDocker(Settings).GetJsonAsync(GetHintQuery(para), token); + foreach (var item in jsonlist) + { + ahis.Add(new AutoHintItem + { + Word = $"{item}".Replace("\"", "") + }); + } + return ahis; + } + + public override Func GetDetailTaskFunc { get; set; } = GetDetailTask; + + public static async Task GetDetailTask(MoeItem img, SearchPara para, CancellationToken token) + { + var url = img.DetailUrl; + var net = new NetDocker(img.Site.Settings); + var html = await net.GetHtmlAsync(url,token); + if(html == null )return; + var nodes = html.DocumentNode; + img.Artist = nodes.SelectSingleNode("*//li[@class='tag-type-artist']/a[2]")?.InnerText.Trim(); + img.Character = nodes.SelectSingleNode("*//li[@class='tag-type-character']/a[2]")?.InnerText.Trim(); + img.Copyright = nodes.SelectSingleNode("*//li[@class='tag-type-copyright']/a[2]")?.InnerText.Trim(); + } + + } +} diff --git a/MoeLoaderP.Core/Sites/MiniTokyoSite.cs b/MoeLoaderP.Core/Sites/MiniTokyoSite.cs index 699d6de..2db6b9b 100644 --- a/MoeLoaderP.Core/Sites/MiniTokyoSite.cs +++ b/MoeLoaderP.Core/Sites/MiniTokyoSite.cs @@ -25,32 +25,14 @@ public class MiniTokyoSite : MoeSite public string GetSort(SearchPara para) { - switch (para.SubMenuIndex) - { - default: - return ""; - case 0: - return "wallpapers"; - case 1: - return "scans"; - case 2: - return "mobile"; - case 3: - return "indy-art"; - } + var sorts = new[] {"wallpapers", "scans", "mobile", "indy-art"}; + return sorts[para.SubMenuIndex]; } public string GetOrder(SearchPara para) { - switch (para.Lv3MenuIndex) - { - default: - return ""; - case 0: - return "id"; - case 1: - return "favorites"; - } + var orders = new [] {"id", "favorites"}; + return orders[para.Lv3MenuIndex]; } public MiniTokyoSite() @@ -113,7 +95,8 @@ public override async Task GetRealPageImagesAsync(SearchPara para, Can var url = tabnodes[1].Attributes["href"]?.Value; var reg = new Regex(@"(?:^|\?|&)tid=(\d*)(?:&|$)"); var tid = reg.Match(url ?? "").Groups[0].Value; - query = $"{HomeBrowseUrl}/gallery{tid}index={(para.SubMenuIndex == 0 ? 1 : (para.SubMenuIndex == 1 ? 3 : (para.SubMenuIndex == 3 ? 2 : 1)))}&order={GetOrder(para)}&display=thumbnails"; + var indexs = new [] {1, 3, 1, 2}; + query = $"{HomeBrowseUrl}/gallery{tid}index={indexs[para.SubMenuIndex]}&order={GetOrder(para)}&display=thumbnails"; } @@ -123,10 +106,7 @@ public override async Task GetRealPageImagesAsync(SearchPara para, Can if (empty == "no items to display") return imgs; var wallNode = docnode.SelectSingleNode("*//ul[@class='scans']"); var imgNodes = wallNode.SelectNodes(".//li"); - if (imgNodes == null) - { - return imgs; - } + if (imgNodes == null) return imgs; foreach (var node in imgNodes) { @@ -140,8 +120,10 @@ public override async Task GetRealPageImagesAsync(SearchPara para, Can //http://static2.minitokyo.net/thumbs/24/25/583774.jpg preview //http://static2.minitokyo.net/view/24/25/583774.jpg sample //http://static.minitokyo.net/downloads/24/25/583774.jpg full - var previewUrl = $"http://static2.minitokyo.net/view{sampleUrl.Substring(sampleUrl.IndexOf('/', sampleUrl.IndexOf(".net/", StringComparison.Ordinal) + 5))}"; - var fileUrl = $"http://static.minitokyo.net/downloads{previewUrl.Substring(previewUrl.IndexOf('/', previewUrl.IndexOf(".net/", StringComparison.Ordinal) + 5))}"; + const string api2 = "http://static2.minitokyo.net"; + const string api = "http://static.minitokyo.net"; + var previewUrl = $"{api2}/view{sampleUrl.Substring(sampleUrl.IndexOf('/', sampleUrl.IndexOf(".net/", StringComparison.Ordinal) + 5))}"; + var fileUrl = $"{api}t/downloads{previewUrl.Substring(previewUrl.IndexOf('/', previewUrl.IndexOf(".net/", StringComparison.Ordinal) + 5))}"; img.Urls.Add(4, fileUrl, HomeUrl); img.Title = node.SelectSingleNode("./p/a").InnerText.Trim(); img.Uploader = node.SelectSingleNode("./p").InnerText.Delete("by ").Trim(); @@ -168,13 +150,8 @@ public override async Task GetAutoHintItemsAsync(SearchPara para, var lines = txt.Split('\n'); for (var i = 0; i < lines.Length && i < 8; i++) { - if (lines[i].Trim().Length > 0) - { - items.Add(new AutoHintItem - { - Word = lines[i].Substring(0, lines[i].IndexOf('|')).Trim() - }); - } + if (lines[i].IsNaN()) continue; + items.Add(lines[i].Substring(0, lines[i].IndexOf('|')).Trim()); } return items; } diff --git a/MoeLoaderP.Core/Sites/MoeSite.cs b/MoeLoaderP.Core/Sites/MoeSite.cs index 471edc3..080b610 100644 --- a/MoeLoaderP.Core/Sites/MoeSite.cs +++ b/MoeLoaderP.Core/Sites/MoeSite.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.Net; using System.Threading; @@ -27,38 +28,43 @@ public abstract class MoeSite : BindingObject public abstract string ShortName { get; } public string LoginPageUrl { get; set; } - public MoeMenuItems SubMenu { get; set; } =new MoeMenuItems(); - private string _loginCookies; + public MoeMenuItems SubMenu { get; set; } = new MoeMenuItems(); public virtual CookieContainer GetCookies() => null; public virtual bool VerifyCookie(string cookieStr) => false; - public string LoginCookies - { - get => _loginCookies; - set => SetField(ref _loginCookies, value, nameof(LoginCookies)); - } - /// /// 站点支持的功能情况 /// public MoeSiteSupportState SupportState { get; set; } = new MoeSiteSupportState(); public MoeSiteFuncSupportState FuncSupportState { get; set; } = new MoeSiteFuncSupportState(); public MenuItemFunc MenuFunc { get; set; } = new MenuItemFunc(); - + public virtual NetDocker Net { get; set; } - + /// /// 异步获取图片列表,开发者需实现该功能 /// public abstract Task GetRealPageImagesAsync(SearchPara para, CancellationToken token); - + /// /// 获取关键词自动提示列表 /// public virtual Task GetAutoHintItemsAsync(SearchPara para, CancellationToken token) => null; - + public Settings Settings { get; set; } + public MoeSiteSetting CurrentSiteSetting + { + get + { + if (Settings?.MoeSiteSettings?.ContainsKey(ShortName) == true) return Settings.MoeSiteSettings[ShortName]; + if (Settings == null) return null; + if(Settings.MoeSiteSettings == null) Settings.MoeSiteSettings = new Dictionary(); + Settings.MoeSiteSettings.Add(ShortName, new MoeSiteSetting()); + return Settings.MoeSiteSettings[ShortName]; + } + } + public DownloadTypes DownloadTypes { get; set; } = new DownloadTypes(); } @@ -75,7 +81,8 @@ public void Add(string name, int pr) { Add(new DownloadType { - Name = name,Priority = pr + Name = name, + Priority = pr }); } } @@ -102,7 +109,7 @@ public class MoeSiteSupportState /// 是否支持分辨率,若为false则不可按分辨率过滤图片 /// public bool IsSupportResolution { get; set; } = true; - + /// /// 是否支持搜索框自动提示,若为false则输入关键词时无自动提示 /// @@ -130,14 +137,17 @@ public class MoeSites : ObservableCollection public new void Add(MoeSite site) { site.Settings = Settings; - if (Settings.MoeSiteSettings?.ContainsKey(site.ShortName) == true) - { - site.LoginCookies = Settings.MoeSiteSettings[site.ShortName].LonginCookie; - } base.Add(site); } + + public MoeSites(Settings set) + { + Settings = set; + } } + + /// /// 自动提示列表中的一项 /// @@ -151,24 +161,30 @@ public class AutoHintItem public class AutoHintItems : ObservableCollection { - public void AddHistory(string keyword,Settings settings) + public void AddHistory(string keyword, Settings settings) { - if (string.IsNullOrWhiteSpace(keyword)) return; + if (keyword.IsNaN()) return; foreach (var item in this) { if (item.Word == keyword) return; } - var aitem = new AutoHintItem + var hintItem = new AutoHintItem { IsHistory = true, Word = keyword }; - if (Count>=settings.HistoryKeywordsMaxCount)RemoveAt(Count-1); - Insert(0,aitem); + if (Count >= settings.HistoryKeywordsMaxCount) RemoveAt(Count - 1); + Insert(0, hintItem); + } + + public void Add(string word, string count = null) + { + var item = new AutoHintItem {Word = word, Count = count}; + Add(item); } } - public class MoeMenuItem + public class MoeMenuItem { public MoeMenuItem() { } public MoeMenuItem(string name, MoeMenuItems menu = null) @@ -178,7 +194,7 @@ public MoeMenuItem(string name, MoeMenuItems menu = null) } public string MenuItemName { get; set; } - public MenuItemFunc Func { get; set; } =new MenuItemFunc(); + public MenuItemFunc Func { get; set; } = new MenuItemFunc(); public MoeMenuItems SubMenu { get; set; } = new MoeMenuItems(); @@ -190,7 +206,7 @@ public class MenuItemFunc public bool? ShowDatePicker { get; set; } = false; } - public class MoeMenuItems : List + public class MoeMenuItems : List { public void Add(string name, MoeMenuItems subMenu) { @@ -217,11 +233,11 @@ public MoeMenuItems(params MoeMenuItem[] items) } } - public MoeMenuItems(MoeMenuItems submenu,params string[] itemsNames) + public MoeMenuItems(MoeMenuItems submenu, params string[] itemsNames) { foreach (var name in itemsNames) { - Add(new MoeMenuItem(name,submenu)); + Add(new MoeMenuItem(name, submenu)); } } diff --git a/MoeLoaderP.Core/Sites/PixivSite.cs b/MoeLoaderP.Core/Sites/PixivSite.cs index b911540..45ea720 100644 --- a/MoeLoaderP.Core/Sites/PixivSite.cs +++ b/MoeLoaderP.Core/Sites/PixivSite.cs @@ -11,7 +11,7 @@ namespace MoeLoaderP.Core.Sites { /// - /// pixiv.net fixed 20200414 + /// pixiv.net fixed 20200424 /// public class PixivSite : MoeSite { @@ -44,9 +44,10 @@ public PixivSite() var ranSubMenu = IsR18 ? new MoeMenuItems(rankLv4Menu, "今日", "本周", "最受男性欢迎", "最受女性欢迎") : new MoeMenuItems(rankLv4Menu, "今日", "本周", "本月", "新人", "原创", "最受男性欢迎", "最受女性欢迎"); - var rankingMiten = new MoeMenuItem("排行", ranSubMenu); - rankingMiten.Func.ShowDatePicker = true; - rankingMiten.Func.ShowKeyword = false; + var rankingMiten = new MoeMenuItem("排行", ranSubMenu) + { + Func = { ShowDatePicker = true, ShowKeyword = false } + }; SubMenu.Add(rankingMiten); // 2 SupportState.IsSupportAccount = true; @@ -64,8 +65,9 @@ public PixivSite() public override CookieContainer GetCookies() { - if (LoginCookies.IsNaN()) return null; - var cookies = LoginCookies.Split(';'); + var cookieStr = CurrentSiteSetting.LoginCookie; + if (cookieStr.IsNaN()) return null; + var cookies = cookieStr.Split(';'); var cc = new CookieContainer(); foreach (var cookie in cookies) { @@ -76,23 +78,32 @@ public override CookieContainer GetCookies() cc.Add(new Cookie(values[1], values[2], "/", values[0])); } } + + if (cc.Count == 0) + { + CurrentSiteSetting.LoginCookie = null; + return null; + } return cc; } - public override bool VerifyCookie(string cookieStr) - { - if (cookieStr.Contains("device_token")) return true; - return false; - } + public override bool VerifyCookie(string cookieStr) => cookieStr.Contains("device_token"); public override async Task GetRealPageImagesAsync(SearchPara para, CancellationToken token) { - if (Net == null) + if (Net?.HttpClientHandler?.CookieContainer == null) { Net = new NetDocker(Settings, HomeUrl); Net.HttpClientHandler.AllowAutoRedirect = true; Net.HttpClientHandler.UseCookies = true; - Net.HttpClientHandler.CookieContainer = GetCookies(); + var cc = GetCookies(); + if (cc == null) + { + Extend.ShowMessage("需要重新登录Pixiv站点", null, Extend.MessagePos.Window); + Net = null; + return null; + } + Net.HttpClientHandler.CookieContainer = cc; Net.SetTimeOut(40); } else @@ -122,8 +133,7 @@ public override async Task GetRealPageImagesAsync(SearchPara para, Can public async Task SearchByNewOrTag(MoeItems imgs, SearchPara para, CancellationToken token) { - string referer, api; - Pairs pairs; + string referer, api; Pairs pairs; var isIllust = para.Lv3MenuIndex == 0; if (para.Keyword.IsNaN()) // new { @@ -131,7 +141,6 @@ public async Task SearchByNewOrTag(MoeItems imgs, SearchPara para, CancellationT referer = isIllust ? $"{HomeUrl}/new_illust.php" : $"{HomeUrl}/new_illust.php?type=manga"; pairs = new Pairs { - //{"page", $"{para.PageIndex}"}, {"lastId", para.LastId == 0 ? "" : $"{para.LastId}"}, {"limit", $"{para.Count}"}, {"type", isIllust ? "illust" : "manga"}, @@ -155,27 +164,10 @@ public async Task SearchByNewOrTag(MoeItems imgs, SearchPara para, CancellationT Net.SetReferer(referer); var json = await Net.GetJsonAsync(api, token, pairs); - if (IsR18) - { - if ($"{json?.error}".ToLower() == "true") - { - Extend.ShowMessage("搜索错误", null, Extend.MessagePos.Window); - return; - } - } - else - { - if ($"{json?.body?.error}" == "true") - { - Extend.ShowMessage($"搜索错误{json?.body?.message}", null, Extend.MessagePos.Window); - return; - } - } - - var list = para.Keyword.IsNaN() ? (json?.body?.illusts) + var list = para.Keyword.IsNaN() + ? (json?.body?.illusts) : (isIllust ? (json?.body?.illust?.data) : (json?.body?.manga?.data)); - foreach (var illus in Extend.CheckListNull(list)) { var img = new MoeItem(this, para) { Site = this, Net = Net.CloneWithOldCookie(), Id = $"{illus.illustId}".ToInt() }; @@ -187,28 +179,17 @@ public async Task SearchByNewOrTag(MoeItems imgs, SearchPara para, CancellationT img.Height = $"{illus.height}".ToInt(); img.DetailUrl = $"{HomeUrl}/artworks/{img.Id}"; img.ImagesCount = $"{illus.pageCount}".ToInt(); - foreach (var tag in Extend.CheckListNull(illus.tags)) - { - img.Tags.Add($"{tag}"); - } - + foreach (var tag in Extend.CheckListNull(illus.tags)) img.Tags.Add($"{tag}"); img.Date = GetDateFromUrl($"{illus.url}"); - if ($"{illus.illustType}" == "2") - { - img.GetDetailTaskFunc = async () => await GetUgoiraDetailPageTask(img); - } - else - { - img.GetDetailTaskFunc = async () => await GetDetailPageTask(img, para); - } - + if ($"{illus.illustType}" == "2") img.GetDetailTaskFunc = async () => await GetUgoiraDetailPageTask(img); + else img.GetDetailTaskFunc = async () => await GetDetailPageTask(img, para); img.OriginString = $"{illus}"; imgs.Add(img); } if (!para.Keyword.IsNaN() && json != null) { var count = $"{json?.body?.illust?.total}".ToInt(); - Extend.ShowMessage($"共搜索到{count}张图片,当前已加载至第{para.PageIndex}页,共{count/60}页", null, Extend.MessagePos.InfoBar); + Extend.ShowMessage($"共搜索到{count}张图片,当前已加载至第{para.PageIndex}页,共{count / 60}页", null, Extend.MessagePos.InfoBar); } } @@ -221,19 +202,16 @@ public DateTime GetDateFromUrl(string url) var ifp = new CultureInfo("zh-CN", true); DateTime.TryParseExact(str, "yyyy/MM/dd/HH/mm/ss", ifp, DateTimeStyles.None, out var time); return time; - } catch (Exception e) { Extend.Log(e.Message, e.StackTrace); return DateTime.MinValue; } - } public async Task SearchByAuthor(MoeItems imgs, string uid, SearchPara para, CancellationToken token) { - // test id: 890269 var isIorM = para.Lv3MenuIndex == 0; var mi = isIorM ? "illustrations" : "manga"; var mi2 = isIorM ? "illusts" : "manga"; @@ -247,64 +225,38 @@ public async Task SearchByAuthor(MoeItems imgs, string uid, SearchPara para, Can } var picIds = new List(); var arts = isIorM ? allJson?.body?.illusts : allJson?.body?.manga; - if (arts != null) - { - foreach (var ill in arts) - { - var property = (JProperty)ill; - picIds.Add(property.Name); - } - } + foreach (var ill in Extend.CheckListNull(arts)) picIds.Add((ill as JProperty)?.Name); var picCurrentPage = picIds.OrderByDescending(i => i.ToInt()).Skip((para.PageIndex - 1) * para.Count).Take(para.Count).ToList(); if (!picCurrentPage.Any()) return; var pairs = new Pairs(); - foreach (var pic in picCurrentPage) - { - pairs.Add("ids[]".ToEncodedUrl(), pic); - } + foreach (var pic in picCurrentPage) pairs.Add("ids[]".ToEncodedUrl(), pic); pairs.Add("work_category", mi2); pairs.Add("is_first_page", "1"); var picsJson = await Net.GetJsonAsync($"{HomeUrl}/ajax/user/{uid}/profile/illusts", token, pairs); var works = picsJson?.body?.works; - if (works != null) + foreach (var item in Extend.CheckListNull(works)) { - foreach (var item in works) - { - var jp = (JProperty)item; - dynamic illus = jp.Value; - var img = new MoeItem(this, para) - { - Site = this, - Net = Net.CloneWithOldCookie(), - Id = $"{illus.illustId}".ToInt() - }; - img.Urls.Add(1, $"{illus.url}", $"{HomeUrl}/users/{uid}/{mi}"); - img.Title = $"{illus.illustTitle}"; - img.Uploader = $"{illus.userName}"; - img.UploaderId = $"{illus.userId}"; - img.Width = $"{illus.width}".ToInt(); - img.Height = $"{illus.height}".ToInt(); - img.DetailUrl = $"{HomeUrl}/artworks/{img.Id}"; - img.ImagesCount = $"{illus.pageCount}".ToInt(); - foreach (var tag in Extend.CheckListNull(illus.tags)) - { - img.Tags.Add($"{tag}"); - } - img.Date = GetDateFromUrl($"{illus.url}"); - if ($"{illus.illustType}" == "2") - { - img.GetDetailTaskFunc = async () => await GetUgoiraDetailPageTask(img); - } - else - { - img.GetDetailTaskFunc = async () => await GetDetailPageTask(img, para); - } - - img.OriginString = $"{item}"; - imgs.Add(img); - } + dynamic illus = (item as JProperty)?.Value; + if (illus == null) continue; + var img = new MoeItem(this, para); + img.Urls.Add(1, $"{illus.url}", $"{HomeUrl}/users/{uid}/{mi}"); + img.Id = $"{illus.illustId}".ToInt(); + img.Net = Net.CloneWithOldCookie(); + img.Title = $"{illus.illustTitle}"; + img.Uploader = $"{illus.userName}"; + img.UploaderId = $"{illus.userId}"; + img.Width = $"{illus.width}".ToInt(); + img.Height = $"{illus.height}".ToInt(); + img.DetailUrl = $"{HomeUrl}/artworks/{img.Id}"; + img.ImagesCount = $"{illus.pageCount}".ToInt(); + foreach (var tag in Extend.CheckListNull(illus.tags)) img.Tags.Add($"{tag}"); + img.Date = GetDateFromUrl($"{illus.url}"); + if ($"{illus.illustType}" == "2") img.GetDetailTaskFunc = async () => await GetUgoiraDetailPageTask(img); + else img.GetDetailTaskFunc = async () => await GetDetailPageTask(img, para); + img.OriginString = $"{item}"; + imgs.Add(img); } - Extend.ShowMessage($"该作者共有{mi3}{picIds.Count}张,当前第{para.Count * (para.PageIndex-1)+1}张", null , Extend.MessagePos.InfoBar); + Extend.ShowMessage($"该作者共有{mi3}{picIds.Count}张,当前第{para.Count * (para.PageIndex - 1) + 1}张", null, Extend.MessagePos.InfoBar); } public async Task SearchByRank(MoeItems imgs, SearchPara para, CancellationToken token) @@ -313,7 +265,8 @@ public async Task SearchByRank(MoeItems imgs, SearchPara para, CancellationToken var modes = new[] { "daily", "weekly", "monthly", "rookie,", "original", "male", "female" }; var mode = IsR18 ? modesR18[para.Lv3MenuIndex] : modes[para.Lv3MenuIndex]; if (IsR18) mode += "_r18"; - var content = para.Lv4MenuIndex == 0 ? "all" : (para.Lv4MenuIndex == 1 ? "illust" : (para.Lv4MenuIndex == 2 ? "manga" : "ugoira")); + var contents = new[] { "all", "illust", "manga", "ugoira" }; + var content = contents[para.Lv4MenuIndex]; var referer = $"{HomeUrl}/ranking.php?mode={mode}&content={content}"; Net.SetReferer(referer); var q = $"{HomeUrl}/ranking.php"; @@ -349,7 +302,7 @@ public async Task SearchByRank(MoeItems imgs, SearchPara para, CancellationToken img.Tip = yes == 0 ? "首次登场" : $"之前#{yes}"; if (yes == 0) img.TipHighLight = true; } - foreach (var tag in Extend.CheckListNull(illus.tags)) img.Tags.Add($"{tag}"); + foreach (var tag in Extend.CheckListNull(illus.tags)) img.Tags.Add($"{tag}"); img.Date = GetDateFromUrl($"{illus.url}"); if ($"{illus.illust_type}" == "2") img.GetDetailTaskFunc = async () => await GetUgoiraDetailPageTask(img); @@ -360,7 +313,7 @@ public async Task SearchByRank(MoeItems imgs, SearchPara para, CancellationToken } var count = $"{json?.rank_total}".ToInt(); - Extend.ShowMessage($"共{count}张,当前日期:{json?.date}", null , Extend.MessagePos.InfoBar); + Extend.ShowMessage($"共{count}张,当前日期:{json?.date}", null, Extend.MessagePos.InfoBar); } public async Task GetDetailPageTask(MoeItem img, SearchPara para) @@ -380,11 +333,11 @@ public async Task GetDetailPageTask(MoeItem img, SearchPara para) { foreach (var item in json.body) { - var imgitem = new MoeItem(this, para); - imgitem.Urls.Add(2, $"{img1?.urls.small}", refer); - imgitem.Urls.Add(3, $"{img1?.urls.regular}", refer); - imgitem.Urls.Add(4, $"{item?.urls?.original}", refer); - img.ChildrenItems.Add(imgitem); + var imgItem = new MoeItem(this, para); + imgItem.Urls.Add(2, $"{img1?.urls.small}", refer); + imgItem.Urls.Add(3, $"{img1?.urls.regular}", refer); + imgItem.Urls.Add(4, $"{item?.urls?.original}", refer); + img.ChildrenItems.Add(imgItem); } } } @@ -401,9 +354,9 @@ public async Task GetUgoiraDetailPageTask(MoeItem img) var refer = $"{HomeUrl}/artworks/{img.Id}"; if (img1 != null) { - img.Urls.Add(2, $"{img1.src}", refer,true); - img.Urls.Add(3, $"{img1.src}", refer,true); - img.Urls.Add(4, $"{img1.originalSrc}", refer,true); + img.Urls.Add(2, $"{img1.src}", refer, true); + img.Urls.Add(3, $"{img1.src}", refer, true); + img.Urls.Add(4, $"{img1.originalSrc}", refer, true); img.ExtraFile = new TextFileInfo { FileExt = "json", Content = jsonStr }; } } @@ -416,17 +369,12 @@ public override async Task GetAutoHintItemsAsync(SearchPara para, AutoHintNet = new NetDocker(Settings, HomeUrl); AutoHintNet.SetReferer(HomeUrl); } - var re = new AutoHintItems(); - - if (para.SubMenuIndex != 0 && para.SubMenuIndex != 5) return re; + var items = new AutoHintItems(); + if (para.SubMenuIndex != 0 && para.SubMenuIndex != 5) return items; var url = $"{HomeUrl}/rpc/cps.php?keyword={para.Keyword}"; - var jlist = await AutoHintNet.GetJsonAsync(url, token); - foreach (var obj in Extend.CheckListNull(jlist?.candidates)) - { - var item = new AutoHintItem { Word = $"{obj.tag_name}" }; - re.Add(item); - } - return re; + var jList = await AutoHintNet.GetJsonAsync(url, token); + foreach (var obj in Extend.CheckListNull(jList?.candidates)) items.Add($"{obj.tag_name}"); + return items; } } diff --git a/MoeLoaderP.Core/Sites/WCosplaySite.cs b/MoeLoaderP.Core/Sites/WCosplaySite.cs index bddcabe..2833cde 100644 --- a/MoeLoaderP.Core/Sites/WCosplaySite.cs +++ b/MoeLoaderP.Core/Sites/WCosplaySite.cs @@ -32,7 +32,7 @@ public override async Task GetRealPageImagesAsync(SearchPara para, Can {"direction","descend" } }; - if (para.HasKeyword) + if (!para.Keyword.IsNaN()) { //http://worldcosplay.net/api/photo/search?page=2&rows=48&q=%E5%90%8A%E5%B8%A6%E8%A2%9C%E5%A4%A9%E4%BD%BF url = $"{HomeUrl}/api/photo/search"; diff --git a/MoeLoaderP.Wpf/App.xaml.cs b/MoeLoaderP.Wpf/App.xaml.cs index 27856ea..1fdc459 100644 --- a/MoeLoaderP.Wpf/App.xaml.cs +++ b/MoeLoaderP.Wpf/App.xaml.cs @@ -53,7 +53,7 @@ protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); var settings = Settings.Load(SettingJsonFilePath); - if (string.IsNullOrWhiteSpace(settings.ImageSavePath)) settings.ImageSavePath = MoePicFolder; + if (settings.ImageSavePath.IsNaN()) settings.ImageSavePath = MoePicFolder; var mainWin = new MainWindow(); mainWin.Init(settings); mainWin.Show(); diff --git a/MoeLoaderP.Wpf/Assets/MoeResource.xaml b/MoeLoaderP.Wpf/Assets/MoeResource.xaml index ed3b355..397e77f 100644 --- a/MoeLoaderP.Wpf/Assets/MoeResource.xaml +++ b/MoeLoaderP.Wpf/Assets/MoeResource.xaml @@ -18,6 +18,7 @@ + MoeLoader +1s /MoeLoaderP;component/Assets/#Font Awesome 5 Free Solid @@ -170,11 +171,15 @@ - + - + + + + + @@ -189,7 +194,11 @@ - + + + + + @@ -198,11 +207,17 @@ - + + + + + + + - + @@ -210,14 +225,18 @@ - + - + + + + + - + - - + + @@ -1145,7 +1164,7 @@ - + diff --git a/MoeLoaderP.Wpf/ControlParts/DownloaderControl.xaml b/MoeLoaderP.Wpf/ControlParts/DownloaderControl.xaml index 6c738ce..12d1b5a 100644 --- a/MoeLoaderP.Wpf/ControlParts/DownloaderControl.xaml +++ b/MoeLoaderP.Wpf/ControlParts/DownloaderControl.xaml @@ -51,7 +51,7 @@ - - - - - - - - - - - - - - - - + diff --git a/MoeLoaderP.Wpf/ControlParts/MoeExplorerControl.xaml.cs b/MoeLoaderP.Wpf/ControlParts/MoeExplorerControl.xaml.cs index 891d10d..f4a72f7 100644 --- a/MoeLoaderP.Wpf/ControlParts/MoeExplorerControl.xaml.cs +++ b/MoeLoaderP.Wpf/ControlParts/MoeExplorerControl.xaml.cs @@ -1,4 +1,6 @@ -using System; +using MoeLoaderP.Core; +using MoeLoaderP.Core.Sites; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; @@ -8,8 +10,6 @@ using System.Windows.Input; using System.Windows.Media; using System.Windows.Threading; -using MoeLoaderP.Core; -using MoeLoaderP.Core.Sites; namespace MoeLoaderP.Wpf.ControlParts { @@ -48,7 +48,7 @@ public MoeExplorerControl() Extend.ShowMessageAction += ShowMessageAction; } - private void ShowMessageAction(string arg1, string arg2,Extend.MessagePos arg3) + private void ShowMessageAction(string arg1, string arg2, Extend.MessagePos arg3) { switch (arg3) { @@ -205,16 +205,16 @@ private void ContextSelectAllButtonOnClick(object sender, RoutedEventArgs e) /// /// 生成右键菜单中的小标题TextBlock /// - public TextBlock GetTitieTextBlock(string text) + public TextBlock GetTitleTextBlock(string text) { - var textblock = new TextBlock + var textBlock = new TextBlock { Text = text, Margin = new Thickness(2), FontSize = 10, VerticalAlignment = VerticalAlignment.Center }; - return textblock; + return textBlock; } /// @@ -225,7 +225,7 @@ private void ImageItemsScrollViewerOnMouseRightButtonDown(object sender, MouseBu if (MouseOnImageControl == null) return; ContextMenuPopup.IsOpen = true; ContextMenuPopupGrid.EnlargeShowSb().Begin(); - + LoadExtFunc(); LoadImgInfo(); } @@ -240,7 +240,7 @@ public void LoadExtFunc() // load choose 首次登场图片 if (site.FuncSupportState.IsSupportSelectPixivRankNew && para.SubMenuIndex == 2) { - + var b = GetSpButton("全选首次登场图片"); b.Click += (o, args) => { @@ -253,14 +253,14 @@ public void LoadExtFunc() }; SpPanel.Children.Add(b); } - + // load search by author id if (site.FuncSupportState.IsSupportSearchByAuthorId) { var b = GetSpButton($"搜索该作者{cimg.Uploader}的所有作品"); b.Click += (sender, args) => { - SearchByAuthorIdAction?.Invoke(site,cimg.UploaderId); + SearchByAuthorIdAction?.Invoke(site, cimg.UploaderId); ContextMenuPopup.IsOpen = false; }; SpPanel.Children.Add(b); @@ -272,78 +272,30 @@ public void LoadExtFunc() public void LoadImgInfo() { var item = MouseOnImageControl.ImageItem; - // load id - var id = item.Id; - if (id > 0) - { - IdWrapPanel.Visibility = Visibility.Visible; - IdWrapPanel.Children.Clear(); - IdWrapPanel.Children.Add(GetTitieTextBlock("Id:")); - IdWrapPanel.Children.Add(GetTagButton($"{id}")); - } - else - { - IdWrapPanel.Visibility = Visibility.Collapsed; - } - - // load Uploader - if (!string.IsNullOrWhiteSpace(item.Uploader)) - { - AuthorWrapPanel.Visibility = Visibility.Visible; - AuthorWrapPanel.Children.Clear(); - AuthorWrapPanel.Children.Add(GetTitieTextBlock("Uploader:")); - AuthorWrapPanel.Children.Add(GetTagButton(item.Uploader)); - if (!string.IsNullOrWhiteSpace(item.UploaderId)) - { - AuthorWrapPanel.Children.Add(GetTitieTextBlock("UpID:")); - AuthorWrapPanel.Children.Add(GetTagButton(item.UploaderId)); - } - } - - // load title info - if (!string.IsNullOrWhiteSpace(item.Title)) - { - TitleWrapPanel.Visibility = Visibility.Visible; - TitleWrapPanel.Children.Clear(); - TitleWrapPanel.Children.Add(GetTitieTextBlock("Title:")); - TitleWrapPanel.Children.Add(GetTagButton(item.Title)); - } - else - { - TitleWrapPanel.Visibility = Visibility.Collapsed; - } - - // load date info - if (!string.IsNullOrWhiteSpace(item.DateString)) - { - DateWrapPanel.Visibility = Visibility.Visible; - DateWrapPanel.Children.Clear(); - DateWrapPanel.Children.Add(GetTitieTextBlock("Date:")); - DateWrapPanel.Children.Add(GetTagButton(item.DateString)); - } - else + ContextMenuImageInfoStackPanel.Children.Clear(); + if (item.Id > 0) GenImageInfoVisual("ID:", $"{item.Id}"); + if (!item.Uploader.IsNaN()) { - DateWrapPanel.Visibility = Visibility.Collapsed; + GenImageInfoVisual("Uploader:", item.Uploader); + if (!item.UploaderId.IsNaN()) GenImageInfoVisual("UpID:", item.UploaderId); } + if (!item.Title.IsNaN()) GenImageInfoVisual("Title:", item.Title); + if (!item.DateString.IsNaN()) GenImageInfoVisual("Date:", item.DateString); + if (MouseOnImageControl.ImageItem.Tags.Count > 0) GenImageInfoVisual("Tags:", item.Tags.ToArray()); + if(!item.Artist.IsNaN()) GenImageInfoVisual("Artist:",item.Artist); + if(!item.Character.IsNaN()) GenImageInfoVisual("Character:", item.Character); + if(!item.Copyright.IsNaN()) GenImageInfoVisual("Copyright:", item.Copyright); + } - // load tag info - if (MouseOnImageControl.ImageItem.Tags.Count > 0) - { - TagsWrapPanel.Visibility = Visibility.Visible; - TagsWrapPanel.Children.Clear(); - - TagsWrapPanel.Children.Add(GetTitieTextBlock("Tags:")); - foreach (var tag in MouseOnImageControl.ImageItem.Tags) - { - var button = GetTagButton(tag); - button.Click += (o, args) => { ContextMenuTagButtonClicked?.Invoke(MouseOnImageControl.ImageItem, tag); }; - TagsWrapPanel.Children.Add(button); - } - } - else + public void GenImageInfoVisual(string title, params string[] buttons) + { + var p = new WrapPanel { Margin = new Thickness(2, 4, 2, 2) }; + p.Children.Add(GetTitleTextBlock(title)); + foreach (var button in buttons) { - TagsWrapPanel.Visibility = Visibility.Collapsed; + p.Children.Add(GetTagButton(button)); } + ContextMenuImageInfoStackPanel.Children.Add(p); } private Button GetTagButton(string text) @@ -362,7 +314,7 @@ private Button GetTagButton(string text) Margin = new Thickness(1), ToolTip = text }; - button.MouseRightButtonUp += (o, args) => text.CopyToClipboard(); + button.Click += (o, args) => text.CopyToClipboard(); return button; } @@ -376,11 +328,11 @@ private Button GetSpButton(string text) Text = text }; - var grid = new Grid {VerticalAlignment = VerticalAlignment.Center}; + var grid = new Grid { VerticalAlignment = VerticalAlignment.Center }; grid.Children.Add(textBlock); var button = new Button { - Template = (ControlTemplate)FindResource("MoeContextMunuButtonControlTemplate"), + Template = (ControlTemplate)FindResource("MoeContextMenuButtonControlTemplate"), Content = grid, Margin = new Thickness(1), Height = 32, @@ -404,14 +356,15 @@ private void OnKeyDown(object sender, KeyEventArgs e) } } - public void AddImages(MoeItems imgs) { foreach (var img in imgs) { var itemCtrl = new ImageControl(Settings, img); - - itemCtrl.DownloadButton.Click += (sender, args) => ImageItemDownloadButtonClicked?.Invoke(itemCtrl.ImageItem, itemCtrl.PreviewImage.Source); + itemCtrl.DownloadButton.Click += (sender, args) => + { + ImageItemDownloadButtonClicked?.Invoke(itemCtrl.ImageItem, itemCtrl.PreviewImage.Source); + }; itemCtrl.MouseEnter += (sender, args) => MouseOnImageControl = itemCtrl; itemCtrl.ImageCheckBox.Checked += (sender, args) => SelectedImageControls.Add(itemCtrl); itemCtrl.ImageCheckBox.Unchecked += (sender, args) => SelectedImageControls.Remove(itemCtrl); @@ -471,16 +424,6 @@ public void StartDownloadShowImages() private void ItemOnImageLoaded(ImageControl obj) { ImageLoadingPool.Remove(obj); - if (ImageLoadingPool.Count == 0) // all image loaded - { - // Extend.ShowMessage("图片加载完毕", null, Extend.MessagePos.InfoBar); - } - else - { - var remain = ImageLoadingPool.Count + ImageWaitForLoadingPool.Count; - //Extend.ShowMessage($"剩余 {remain} 张图片等待加载", null, Extend.MessagePos.InfoBar); - } - if (ImageWaitForLoadingPool.Any()) { var item = ImageWaitForLoadingPool[0]; diff --git a/MoeLoaderP.Wpf/ControlParts/SearchControl.xaml b/MoeLoaderP.Wpf/ControlParts/SearchControl.xaml index 1e40aba..d098c87 100644 --- a/MoeLoaderP.Wpf/ControlParts/SearchControl.xaml +++ b/MoeLoaderP.Wpf/ControlParts/SearchControl.xaml @@ -235,7 +235,7 @@ diff --git a/MoeLoaderP.Wpf/ControlParts/SearchControl.xaml.cs b/MoeLoaderP.Wpf/ControlParts/SearchControl.xaml.cs index 475cb9d..9baf163 100644 --- a/MoeLoaderP.Wpf/ControlParts/SearchControl.xaml.cs +++ b/MoeLoaderP.Wpf/ControlParts/SearchControl.xaml.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; +using System.Windows.Input; namespace MoeLoaderP.Wpf.ControlParts { @@ -19,9 +20,20 @@ namespace MoeLoaderP.Wpf.ControlParts /// public partial class SearchControl : INotifyPropertyChanged { + private MoeSite _currentSelectedSite; public SiteManager SiteManager { get; set; } - public MoeSite CurrentSelectedSite { get; set; } + + public MoeSite CurrentSelectedSite + { + get => _currentSelectedSite; + set + { + _currentSelectedSite = value; + OnPropertyChanged(nameof(CurrentSelectedSite)); + } + } + public Settings Settings { get; set; } public AutoHintItems CurrentHintItems { get; set; } = new AutoHintItems(); @@ -53,7 +65,13 @@ public void Init(SiteManager manager, Settings settings) MoeSitesLv4ComboBox.SelectionChanged += MoeSitesLv4ComboBoxOnSelectionChanged;// 四级菜单选择改变 MoeSitesLv1ComboBox.SelectedIndex = 0; + AccountButton.MouseRightButtonUp += AccountButtonOnMouseRightButtonUp; + } + private void AccountButtonOnMouseRightButtonUp(object sender, MouseButtonEventArgs e) + { + CurrentSelectedSite.CurrentSiteSetting.LoginCookie = null; + Extend.ShowMessage("已清除登录信息!"); } private void SitesOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) @@ -191,7 +209,7 @@ public void InitSearch() CurrentHintItems.Clear(); AddHistoryItems(); MoeDatePicker.SelectedDate = null; - + } private CancellationTokenSource CurrentHintTaskCts { get; set; } @@ -242,7 +260,7 @@ public SearchPara GetSearchPara() MinHeight = FilterMinHeightBox.NumCount, Orientation = (ImageOrientation)OrientationComboBox.SelectedIndex, IsFilterFileType = FilterFileTypeCheckBox.IsChecked == true, - FilterFileTpyeText = FilterFileTypeTextBox.Text, + FilterFileTypeText = FilterFileTypeTextBox.Text, IsFileTypeShowSpecificOnly = FileTypeShowSpecificOnlyComboBox.SelectedIndex == 1, DownloadType = CurrentSelectedSite.DownloadTypes[DownloadTypeComboBox.SelectedIndex], Date = MoeDatePicker.SelectedDate, diff --git a/MoeLoaderP.Wpf/ControlParts/SettingsControl.xaml b/MoeLoaderP.Wpf/ControlParts/SettingsControl.xaml index 70a6c62..602d54e 100644 --- a/MoeLoaderP.Wpf/ControlParts/SettingsControl.xaml +++ b/MoeLoaderP.Wpf/ControlParts/SettingsControl.xaml @@ -99,7 +99,7 @@ - + diff --git a/MoeLoaderP.Wpf/Converters.cs b/MoeLoaderP.Wpf/Converters.cs index 9b539a7..f0a96b9 100644 --- a/MoeLoaderP.Wpf/Converters.cs +++ b/MoeLoaderP.Wpf/Converters.cs @@ -8,6 +8,20 @@ namespace MoeLoaderP.Wpf { + public class DoubleToRectConvertor : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (!(value is double width)) return Rect.Empty; + return Rect.Parse($"0,0,{width},{width}"); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } + public class ImageSavePathNullConvertor : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) @@ -153,11 +167,12 @@ public class StringToVisibilityConverter : IValueConverter public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var text = (string)value; - if (parameter is string para) + if ((parameter as string) == "reverse") { - if(para == "reverse") return !string.IsNullOrWhiteSpace(text) ? Visibility.Collapsed : Visibility.Visible; + return text.IsNaN() ? Visibility.Visible : Visibility.Collapsed; } - return string.IsNullOrWhiteSpace(text) ? Visibility.Collapsed : Visibility.Visible; + + return text.IsNaN() ? Visibility.Collapsed : Visibility.Visible; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => null; diff --git a/MoeLoaderP.Wpf/LoginWindow.xaml.cs b/MoeLoaderP.Wpf/LoginWindow.xaml.cs index a83a7ee..09b8bb3 100644 --- a/MoeLoaderP.Wpf/LoginWindow.xaml.cs +++ b/MoeLoaderP.Wpf/LoginWindow.xaml.cs @@ -1,11 +1,10 @@ -using System; +using CefSharp; +using MoeLoaderP.Core; +using MoeLoaderP.Core.Sites; +using System; using System.Collections.Generic; using System.Threading.Tasks; using System.Windows; -using System.Windows.Controls; -using CefSharp; -using MoeLoaderP.Core; -using MoeLoaderP.Core.Sites; using Cookie = CefSharp.Cookie; namespace MoeLoaderP.Wpf @@ -23,7 +22,7 @@ public LoginWindow() { InitializeComponent(); this.GoState(nameof(HideChromeState)); - + } public void Init(Settings setting, MoeSite site) @@ -67,21 +66,7 @@ private async void AuthButtonOnClick(object sender, RoutedEventArgs e) return; } AuthMesTextBlock.Text = "认证成功,4秒后将关闭窗口"; - Site.LoginCookies = _cookies; - var sitesets = Setting.MoeSiteSettings ?? new Dictionary(); - var siteset = new MoeSiteSetting - { - LonginCookie = _cookies - }; - if (sitesets.ContainsKey(Site.ShortName)) - { - sitesets[Site.ShortName] = siteset; - } - else - { - sitesets.Add(Site.ShortName, siteset); - } - + Site.CurrentSiteSetting.LoginCookie = _cookies; await Task.Delay(4000); Close(); })); @@ -103,7 +88,7 @@ private void MainBrowerOnIsBrowserInitializedChanged(object sender, DependencyPr {"mode", "fixed_servers"} }; var add = Setting.ProxySetting; - if(Setting.ProxyMode == Settings.ProxyModeEnum.Custom) dict.Add("server", add); + if (Setting.ProxyMode == Settings.ProxyModeEnum.Custom) dict.Add("server", add); //设置代理 rc.SetPreference("proxy", dict, out var error); //如果 error 不为空则表示设置失败。 diff --git a/MoeLoaderP.Wpf/Properties/AssemblyInfo.cs b/MoeLoaderP.Wpf/Properties/AssemblyInfo.cs index afd77db..d3a7b79 100644 --- a/MoeLoaderP.Wpf/Properties/AssemblyInfo.cs +++ b/MoeLoaderP.Wpf/Properties/AssemblyInfo.cs @@ -49,6 +49,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("9.4.5.0")] -[assembly: AssemblyFileVersion("9.4.5.0")] +[assembly: AssemblyVersion("9.4.6.0")] +[assembly: AssemblyFileVersion("9.4.6.0")] [assembly: Guid("8745D9BE-87F2-4425-9748-AAA4BCC232A3")] \ No newline at end of file