diff --git a/document/new_version.json b/document/new_version.json
index aa9499b7..c3bb7a5c 100644
--- a/document/new_version.json
+++ b/document/new_version.json
@@ -1,7 +1,7 @@
{
- "version": "4.5.3",
- "version_num": 40503,
- "version_desc": "更新内容:\r\n\r\n* 支持视频详情页右侧标题可右键复制\r\n\r\n* 修复少部分视频打不开问题\r\n\r\n\r\n 如果无法打开下载地址,请访问:https://github.com/ywmoyue/biliuwp-lite/releases",
+ "version": "4.5.4",
+ "version_num": 40504,
+ "version_desc": "更新内容:\r\n\r\n* 首页推荐视频同时显示标签和up主名字\r\n\r\n* 添加搜索建议\r\n\r\n* 优化日志输出\r\n\r\n\r\n 如果无法打开下载地址,请访问:https://github.com/ywmoyue/biliuwp-lite/releases",
"url": "https://github.com/ywmoyue/biliuwp-lite/releases",
"download_url": "https://github.com/ywmoyue/biliuwp-lite/releases"
}
\ No newline at end of file
diff --git a/src/BiliLite.Packages/Package.appxmanifest b/src/BiliLite.Packages/Package.appxmanifest
index 85ed108e..95ac0afe 100644
--- a/src/BiliLite.Packages/Package.appxmanifest
+++ b/src/BiliLite.Packages/Package.appxmanifest
@@ -14,7 +14,7 @@
+ Version="4.5.4.0" />
diff --git a/src/BiliLite.UWP/App.xaml.cs b/src/BiliLite.UWP/App.xaml.cs
index 0a9d930e..2a5d732a 100644
--- a/src/BiliLite.UWP/App.xaml.cs
+++ b/src/BiliLite.UWP/App.xaml.cs
@@ -49,6 +49,7 @@ public App()
FFmpegInteropLogging.SetLogLevel(LogLevel.Info);
FFmpegInteropLogging.SetLogProvider(this);
SqlHelper.InitDB();
+ LogHelper.Init();
this.Suspending += OnSuspending;
}
private void RegisterExceptionHandlingSynchronizationContext()
diff --git a/src/BiliLite.UWP/Assets/Text/help.md b/src/BiliLite.UWP/Assets/Text/help.md
index 00c14a10..b2e3fbb8 100644
--- a/src/BiliLite.UWP/Assets/Text/help.md
+++ b/src/BiliLite.UWP/Assets/Text/help.md
@@ -131,8 +131,8 @@ Webp图片扩展安装地址:[ms-windows-store://pdp/?productid=9PG2DK419DRG](ms
### 日志文件
-路径:`%USERPROFILE%\AppData\Local\Packages\5421.502643927C6AD_wp9dg7z2zqgtj\LocalState\log`
+路径:`%USERPROFILE%\AppData\Local\Packages\5422.502643927C6AD_vn31kc91nth4r\LocalState\log`
-为了你的账号安全,发送日志时请一定要移除access_key=...里的内容
+为了你的账号安全,发送日志时请一定要确保access_key/access_token/csrf=...里的内容已清除或已经被修改为{hasValue}
[点击打开日志存放目录](OpenLog)
diff --git a/src/BiliLite.UWP/BiliLite.UWP.csproj b/src/BiliLite.UWP/BiliLite.UWP.csproj
index 59529e4c..ef5946a8 100644
--- a/src/BiliLite.UWP/BiliLite.UWP.csproj
+++ b/src/BiliLite.UWP/BiliLite.UWP.csproj
@@ -129,7 +129,9 @@
+
+
@@ -144,6 +146,7 @@
+
@@ -277,6 +280,7 @@
+
@@ -476,6 +480,7 @@
+
@@ -596,6 +601,9 @@
Designer
+
+ PreserveNewest
+
@@ -876,6 +884,9 @@
3.19.4
+
+ 2.0.15
+
6.2.10
diff --git a/src/BiliLite.UWP/Extensions/ExceptionExtensions.cs b/src/BiliLite.UWP/Extensions/ExceptionExtensions.cs
new file mode 100644
index 00000000..50c185b3
--- /dev/null
+++ b/src/BiliLite.UWP/Extensions/ExceptionExtensions.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BiliLite.Extensions
+{
+ public static class ExceptionExtensions
+ {
+ public static bool IsNetworkError(this Exception ex)
+ {
+ return ex.HResult == -2147012867 || ex.HResult == -2147012889;
+ }
+ }
+}
diff --git a/src/BiliLite.UWP/Extensions/ObservableCollectionExtension.cs b/src/BiliLite.UWP/Extensions/ObservableCollectionExtension.cs
new file mode 100644
index 00000000..d7dd6256
--- /dev/null
+++ b/src/BiliLite.UWP/Extensions/ObservableCollectionExtension.cs
@@ -0,0 +1,27 @@
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+
+namespace BiliLite.Extensions
+{
+ public static class ObservableCollectionExtension
+ {
+ public static void AddRange(this ObservableCollection collection, IEnumerable range)
+ {
+ if (range == null) return;
+ foreach (var item in range)
+ {
+ collection.Add(item);
+ }
+ }
+
+ public static void ReplaceRange(this ObservableCollection collection, IEnumerable range)
+ {
+ if (range == null) return;
+ collection.Clear();
+ foreach (var item in range)
+ {
+ collection.Add(item);
+ }
+ }
+ }
+}
diff --git a/src/BiliLite.UWP/Extensions/StringExtensions.cs b/src/BiliLite.UWP/Extensions/StringExtensions.cs
index 71d34522..02947331 100644
--- a/src/BiliLite.UWP/Extensions/StringExtensions.cs
+++ b/src/BiliLite.UWP/Extensions/StringExtensions.cs
@@ -143,6 +143,17 @@ public static RichTextBlock ToRichTextBlock(this string txt, JObject emote)
}
}
+ public static string ProtectValues(this string url, params string[] keys)
+ {
+ foreach (string key in keys)
+ {
+ string pattern = $@"({key}=)([^&]*)";
+ string replacement = $"$1{{hasValue}}";
+ url = Regex.Replace(url, pattern, replacement);
+ }
+ return url;
+ }
+
#region Private methods
///
diff --git a/src/BiliLite.UWP/Helpers/SettingHelper.cs b/src/BiliLite.UWP/Helpers/SettingHelper.cs
index 6bd462f4..64c1548a 100644
--- a/src/BiliLite.UWP/Helpers/SettingHelper.cs
+++ b/src/BiliLite.UWP/Helpers/SettingHelper.cs
@@ -535,5 +535,23 @@ public class Download
public const string DEFAULT_VIDEO_TYPE = "DownloadDefaultVideoType";
}
+
+ public class Other
+ {
+ ///
+ /// 自动清理日志文件
+ ///
+ public const string AUTO_CLEAR_LOG_FILE = "autoClearLogFile";
+
+ ///
+ /// 自动清理多少天前的日志文件
+ ///
+ public const string AUTO_CLEAR_LOG_FILE_DAY = "autoClearLogFileDay";
+
+ ///
+ /// 保护日志敏感信息
+ ///
+ public const string PROTECT_LOG_INFO = "protectLogInfo";
+ }
}
}
diff --git a/src/BiliLite.UWP/MainPage.xaml.cs b/src/BiliLite.UWP/MainPage.xaml.cs
index 76a1a660..b99d0e03 100644
--- a/src/BiliLite.UWP/MainPage.xaml.cs
+++ b/src/BiliLite.UWP/MainPage.xaml.cs
@@ -65,9 +65,9 @@ protected async override void OnNavigatedTo(NavigationEventArgs e)
Utils.ShowMessageToast("无法打开链接:" + e.Parameter.ToString());
}
}
-//#if !DEBUG
+#if !DEBUG
await Utils.CheckVersion();
-//#endif
+#endif
}
private void MessageCenter_ChangeTitleEvent(object sender, string e)
diff --git a/src/BiliLite.UWP/Models/Requests/Api/SearchAPI.cs b/src/BiliLite.UWP/Models/Requests/Api/SearchAPI.cs
index 78865c0f..ff0ba24a 100644
--- a/src/BiliLite.UWP/Models/Requests/Api/SearchAPI.cs
+++ b/src/BiliLite.UWP/Models/Requests/Api/SearchAPI.cs
@@ -183,5 +183,16 @@ public ApiModel WebSearchTopic(string keyword, int pn = 1, string area = "")
}
return api;
}
+
+ public ApiModel SearchSuggest(string content)
+ {
+ var api = new ApiModel()
+ {
+ method = RestSharp.Method.Get,
+ baseUrl = $"https://s.search.bilibili.com/main/suggest",
+ parameter = $"term={content}&main_ver=v1"
+ };
+ return api;
+ }
}
}
diff --git a/src/BiliLite.UWP/Models/Requests/BiliRequest.cs b/src/BiliLite.UWP/Models/Requests/BiliRequest.cs
index 2db18089..dfba6b27 100644
--- a/src/BiliLite.UWP/Models/Requests/BiliRequest.cs
+++ b/src/BiliLite.UWP/Models/Requests/BiliRequest.cs
@@ -143,13 +143,21 @@ private HttpResults ConstructRedirectResults(IFlurlResponse response)
return httpResults;
}
+ private async Task LogRequest()
+ {
+ var body = "";
+ if (m_body != null)
+ body = await m_body?.ReadAsStringAsync();
+ LogHelper.Log($"http request: [{m_method}]{m_url} {body}", LogType.INFO);
+ }
+
public async Task Send()
{
+ await LogRequest();
IFlurlResponse response = null;
HttpResults httpResults;
try
{
-
if (m_method == HttpMethod.Get)
{
response = await m_request.GetAsync();
diff --git a/src/BiliLite.UWP/Models/Responses/SearchSuggestResponse.cs b/src/BiliLite.UWP/Models/Responses/SearchSuggestResponse.cs
new file mode 100644
index 00000000..d089d690
--- /dev/null
+++ b/src/BiliLite.UWP/Models/Responses/SearchSuggestResponse.cs
@@ -0,0 +1,14 @@
+using System.Collections.Generic;
+
+namespace BiliLite.Models.Responses
+{
+ public class SearchSuggestResponse
+ {
+ public List Tag { get; set; }
+ }
+
+ public class SearchSuggestResponseTag
+ {
+ public string Value { get; set; }
+ }
+}
diff --git a/src/BiliLite.UWP/Modules/Home/HomeVM.cs b/src/BiliLite.UWP/Modules/Home/HomeVM.cs
index 8ee7d303..e36b35a9 100644
--- a/src/BiliLite.UWP/Modules/Home/HomeVM.cs
+++ b/src/BiliLite.UWP/Modules/Home/HomeVM.cs
@@ -1,12 +1,8 @@
using BiliLite.Helpers;
-using BiliLite.Models;
using FontAwesome5;
using System;
-using System.Collections.Generic;
using System.Linq;
-using System.Text;
using System.Threading.Tasks;
-using Windows.UI.Xaml.Controls;
using System.Collections.ObjectModel;
namespace BiliLite.Modules
@@ -170,6 +166,16 @@ public async Task LoginUserCard()
}
+ private ObservableCollection m_suggestSearchContents;
+
+ public ObservableCollection SuggestSearchContents
+ {
+ get => m_suggestSearchContents;
+ set {
+ m_suggestSearchContents = value;
+ DoPropertyChanged("SuggestSearchContents");
+ }
+ }
}
public class HomeNavItem : IModules
{
diff --git a/src/BiliLite.UWP/Modules/Home/RecommendVM.cs b/src/BiliLite.UWP/Modules/Home/RecommendVM.cs
index 08a50a23..df982fc6 100644
--- a/src/BiliLite.UWP/Modules/Home/RecommendVM.cs
+++ b/src/BiliLite.UWP/Modules/Home/RecommendVM.cs
@@ -349,11 +349,7 @@ public string bottomText
{
return desc_button.text;
}
- if (card_goto=="live")
- {
- return args.up_name;
- }
- return "";
+ return args.up_name;
}
}
diff --git a/src/BiliLite.UWP/Modules/IModules.cs b/src/BiliLite.UWP/Modules/IModules.cs
index 53b8bb9c..0d411cad 100644
--- a/src/BiliLite.UWP/Modules/IModules.cs
+++ b/src/BiliLite.UWP/Modules/IModules.cs
@@ -1,13 +1,9 @@
-using BiliLite.Models;
+using BiliLite.Extensions;
+using BiliLite.Models;
using BiliLite.Models.Common;
using BiliLite.Services;
using System;
-using System.Collections.Generic;
using System.ComponentModel;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Windows.UI.Xaml.Controls;
namespace BiliLite.Modules
{
@@ -15,7 +11,7 @@ public class IModules : INotifyPropertyChanged
{
public virtual ReturnModel HandelError(Exception ex)
{
- if (LogHelper.IsNetworkError(ex))
+ if (ex.IsNetworkError())
{
return new ReturnModel()
{
diff --git a/src/BiliLite.UWP/Modules/Player/Playurl/BiliPayUrlRequest.cs b/src/BiliLite.UWP/Modules/Player/Playurl/BiliPayUrlRequest.cs
index 78d1f3bb..b1375ca7 100644
--- a/src/BiliLite.UWP/Modules/Player/Playurl/BiliPayUrlRequest.cs
+++ b/src/BiliLite.UWP/Modules/Player/Playurl/BiliPayUrlRequest.cs
@@ -14,6 +14,7 @@
using BiliLite.gRPC.Api;
using Proto.Reply;
using BiliLite.Models.Requests.Api;
+using BiliLite.Services;
namespace BiliLite.Modules.Player.Playurl
{
@@ -688,7 +689,6 @@ private async Task GetPlayUrlUseWebApi(PlayInfo playInf
}
catch (Exception ex)
{
-
return BiliPlayUrlQualitesInfo.Failure(ex.Message);
}
diff --git a/src/BiliLite.UWP/Modules/SearchVM.cs b/src/BiliLite.UWP/Modules/SearchVM.cs
index b49540a8..196bcd2b 100644
--- a/src/BiliLite.UWP/Modules/SearchVM.cs
+++ b/src/BiliLite.UWP/Modules/SearchVM.cs
@@ -60,6 +60,7 @@ public bool ShowLoadMore
get { return _ShowLoadMore; }
set { _ShowLoadMore = value; DoPropertyChanged("ShowLoadMore"); }
}
+
public async virtual void Refresh()
{
HasData = false;
@@ -161,6 +162,17 @@ public ISearchVM SelectItem
set { _SelectItem = value; }
}
+ private ObservableCollection m_suggestSearchContents;
+
+ public ObservableCollection SuggestSearchContents
+ {
+ get => m_suggestSearchContents;
+ set
+ {
+ m_suggestSearchContents = value;
+ DoPropertyChanged("SuggestSearchContents");
+ }
+ }
}
public class SearchVideoVM : ISearchVM
{
diff --git a/src/BiliLite.UWP/Pages/HomePage.xaml b/src/BiliLite.UWP/Pages/HomePage.xaml
index 0e42cf64..baeff87f 100644
--- a/src/BiliLite.UWP/Pages/HomePage.xaml
+++ b/src/BiliLite.UWP/Pages/HomePage.xaml
@@ -25,7 +25,13 @@
PaneDisplayMode="Top"
IsBackButtonVisible="Collapsed" >
-
+
diff --git a/src/BiliLite.UWP/Pages/HomePage.xaml.cs b/src/BiliLite.UWP/Pages/HomePage.xaml.cs
index 26e1364a..72827f09 100644
--- a/src/BiliLite.UWP/Pages/HomePage.xaml.cs
+++ b/src/BiliLite.UWP/Pages/HomePage.xaml.cs
@@ -1,24 +1,12 @@
-using BiliLite.Helpers;
+using BiliLite.Extensions;
+using BiliLite.Helpers;
using BiliLite.Models.Common;
using BiliLite.Modules;
-using BiliLite.Pages.Home;
using BiliLite.Services;
using Microsoft.Toolkit.Uwp.Connectivity;
using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Runtime.InteropServices.WindowsRuntime;
-using Windows.ApplicationModel;
-using Windows.Foundation;
-using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
-using Windows.UI.Xaml.Controls.Primitives;
-using Windows.UI.Xaml.Data;
-using Windows.UI.Xaml.Input;
-using Windows.UI.Xaml.Media;
-using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
// https://go.microsoft.com/fwlink/?LinkId=234238 上介绍了“空白页”项模板
@@ -169,7 +157,7 @@ private async void SearchBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBo
return;
}
- if (await MessageCenter.HandelUrl(SearchBox.Text))
+ if (await MessageCenter.HandelUrl(args.QueryText))
{
return;
}
@@ -178,10 +166,10 @@ private async void SearchBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBo
{
icon = Symbol.Find,
page = typeof(SearchPage),
- title = "搜索:" + SearchBox.Text,
+ title = "搜索:" + args.QueryText,
parameters = new SearchParameter()
{
- keyword = SearchBox.Text,
+ keyword = args.QueryText,
searchType = SearchType.Video
}
});
@@ -318,5 +306,20 @@ private void btnOpenDynamic_Click(object sender, RoutedEventArgs e)
}
});
}
+
+ private async void SearchBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
+ {
+ if (args.Reason != AutoSuggestionBoxTextChangeReason.UserInput) return;
+ var text = sender.Text;
+ var suggestSearchContents = await new SearchService().GetSearchSuggestContents(text);
+ if (homeVM.SuggestSearchContents == null)
+ {
+ homeVM.SuggestSearchContents = new System.Collections.ObjectModel.ObservableCollection(suggestSearchContents);
+ }
+ else
+ {
+ homeVM.SuggestSearchContents.ReplaceRange(suggestSearchContents);
+ }
+ }
}
}
diff --git a/src/BiliLite.UWP/Pages/SearchPage.xaml b/src/BiliLite.UWP/Pages/SearchPage.xaml
index 2a6e6119..febf3f3f 100644
--- a/src/BiliLite.UWP/Pages/SearchPage.xaml
+++ b/src/BiliLite.UWP/Pages/SearchPage.xaml
@@ -401,7 +401,15 @@
香港地区
台湾地区
-
+
diff --git a/src/BiliLite.UWP/Pages/SearchPage.xaml.cs b/src/BiliLite.UWP/Pages/SearchPage.xaml.cs
index b0979fa5..7f56014f 100644
--- a/src/BiliLite.UWP/Pages/SearchPage.xaml.cs
+++ b/src/BiliLite.UWP/Pages/SearchPage.xaml.cs
@@ -4,19 +4,9 @@
using BiliLite.Modules;
using BiliLite.Services;
using Microsoft.UI.Xaml.Controls;
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Runtime.InteropServices.WindowsRuntime;
-using Windows.Foundation;
-using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
-using Windows.UI.Xaml.Controls.Primitives;
-using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
-using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// https://go.microsoft.com/fwlink/?LinkId=234238 上介绍了“空白页”项模板
@@ -96,29 +86,32 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
}
pivot.SelectedIndex = (int)par.searchType;
}
+
private async void txtKeyword_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
{
- if (string.IsNullOrEmpty( txtKeyword.Text))
+ var queryText = args.QueryText;
+ if (string.IsNullOrEmpty(queryText))
{
Utils.ShowMessageToast("关键字不能为空啊,喂(#`O′)");
return;
}
- if (await MessageCenter.HandelUrl(txtKeyword.Text))
+ if (await MessageCenter.HandelUrl(queryText))
{
return;
}
- txtKeyword.Text = txtKeyword.Text.TrimStart('@');
+ queryText = queryText.TrimStart('@');
foreach (var item in searchVM.SearchItems)
{
- item.Keyword = txtKeyword.Text;
- item.Area= searchVM.Area.area;
+ item.Keyword = queryText;
+ item.Area = searchVM.Area.area;
item.Page = 1;
item.HasData = false;
}
searchVM.SelectItem.Refresh();
- ChangeTitle("搜索:"+txtKeyword.Text);
+ ChangeTitle("搜索:" + queryText);
}
+
public void ChangeTitle(string title)
{
if ((this.Parent as Frame).Parent is TabViewItem)
@@ -262,6 +255,21 @@ private void cbArea_SelectionChanged(object sender, SelectionChangedEventArgs e)
searchVM.SelectItem.Refresh();
}
}
+
+ private async void txtKeyword_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
+ {
+ if (args.Reason != AutoSuggestionBoxTextChangeReason.UserInput) return;
+ var text = sender.Text;
+ var suggestSearchContents = await new SearchService().GetSearchSuggestContents(text);
+ if (searchVM.SuggestSearchContents == null)
+ {
+ searchVM.SuggestSearchContents = new System.Collections.ObjectModel.ObservableCollection(suggestSearchContents);
+ }
+ else
+ {
+ searchVM.SuggestSearchContents.ReplaceRange(suggestSearchContents);
+ }
+ }
}
public class SearchDataTemplateSelector : DataTemplateSelector
{
diff --git a/src/BiliLite.UWP/Pages/SettingPage.xaml b/src/BiliLite.UWP/Pages/SettingPage.xaml
index b42965b4..961b6e5e 100644
--- a/src/BiliLite.UWP/Pages/SettingPage.xaml
+++ b/src/BiliLite.UWP/Pages/SettingPage.xaml
@@ -516,6 +516,21 @@
+
+
+ 其他
+
+
+
+ 自动清理日志文件
+
+ 自动清理几天前的日志
+
+ 保护日志中敏感信息
+
+
+
+
帮助
@@ -538,6 +553,7 @@
Logo绘制 : xiaoyaomengo
反馈
Github Discussions : https://github.com/ywmoyue/biliuwp-lite/discussions
+ 邮箱(请在发邮件时附带Github Discussion贴子链接) : ruamuyan@outlook.com
说明
这是一个第三方客户端,应用所有数据来源均来自哔哩哔哩。
本程序仅供学习交流编程技术使用。
diff --git a/src/BiliLite.UWP/Pages/SettingPage.xaml.cs b/src/BiliLite.UWP/Pages/SettingPage.xaml.cs
index a823e03f..1eac0c46 100644
--- a/src/BiliLite.UWP/Pages/SettingPage.xaml.cs
+++ b/src/BiliLite.UWP/Pages/SettingPage.xaml.cs
@@ -39,6 +39,7 @@ public SettingPage()
LoadDanmu();
LoadLiveDanmu();
LoadDownlaod();
+ LoadOther();
}
private void LoadUI()
{
@@ -651,6 +652,28 @@ private void LoadDownlaod()
});
}
+ private void LoadOther()
+ {
+ //自动清理日志文件
+ swAutoClearLogFile.IsOn = SettingHelper.GetValue(SettingHelper.Other.AUTO_CLEAR_LOG_FILE, true);
+ swAutoClearLogFile.Toggled += new RoutedEventHandler((e, args) =>
+ {
+ SettingHelper.SetValue(SettingHelper.Other.AUTO_CLEAR_LOG_FILE, swAutoClearLogFile.IsOn);
+ });
+ //自动清理多少天前的日志文件
+ numAutoClearLogDay.Value = SettingHelper.GetValue(SettingHelper.Other.AUTO_CLEAR_LOG_FILE_DAY, 7);
+ numAutoClearLogDay.ValueChanged += ((e, args) =>
+ {
+ SettingHelper.SetValue(SettingHelper.Other.AUTO_CLEAR_LOG_FILE_DAY, numAutoClearLogDay.Value);
+ });
+ //保护日志敏感信息
+ swProtectLogInfo.IsOn = SettingHelper.GetValue(SettingHelper.Other.PROTECT_LOG_INFO, true);
+ swProtectLogInfo.Toggled += ((e, args) =>
+ {
+ SettingHelper.SetValue(SettingHelper.Other.PROTECT_LOG_INFO, swProtectLogInfo.IsOn);
+ });
+ }
+
private void ExceptHomeNavItems()
{
List list = new List();
diff --git a/src/BiliLite.UWP/Services/LogHelper.cs b/src/BiliLite.UWP/Services/LogHelper.cs
index 51624712..b389f7a4 100644
--- a/src/BiliLite.UWP/Services/LogHelper.cs
+++ b/src/BiliLite.UWP/Services/LogHelper.cs
@@ -1,13 +1,15 @@
-using BiliLite.Models.Common;
+using BiliLite.Extensions;
+using BiliLite.Helpers;
+using BiliLite.Models.Common;
using NLog;
using NLog.Config;
using System;
-using System.Collections.Generic;
using System.Diagnostics;
-using System.Linq;
-using System.Text;
+using System.Globalization;
+using System.IO;
+using System.Runtime.CompilerServices;
using System.Threading.Tasks;
-
+using Windows.Storage;
namespace BiliLite.Services
{
@@ -15,26 +17,62 @@ public class LogHelper
{
public static LoggingConfiguration config;
public static Logger logger = LogManager.GetCurrentClassLogger();
- public static void Log(string message, LogType type, Exception ex = null)
+
+ private static bool IsAutoClearLogFile => SettingHelper.GetValue(SettingHelper.Other.AUTO_CLEAR_LOG_FILE, true);
+ private static int AutoClearLogFileDay => SettingHelper.GetValue(SettingHelper.Other.AUTO_CLEAR_LOG_FILE_DAY, 7);
+ private static bool IsProtectLogInfo => SettingHelper.GetValue(SettingHelper.Other.PROTECT_LOG_INFO, true);
+
+ public static void Init()
{
- if (config == null)
+ config = new LoggingConfiguration();
+ Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
+ var logfile = new NLog.Targets.FileTarget()
+ {
+ Name = "logfile",
+ CreateDirs = true,
+ FileName = storageFolder.Path + @"\log\" + DateTime.Now.ToString("yyyyMMdd") + ".log",
+ Layout = "${longdate}|${level:uppercase=true}|${logger}|${threadid}|${message}|${exception:format=Message,StackTrace}"
+ };
+ config.AddRule(LogLevel.Info, LogLevel.Info, logfile);
+ config.AddRule(LogLevel.Debug, LogLevel.Debug, logfile);
+ config.AddRule(LogLevel.Error, LogLevel.Error, logfile);
+ config.AddRule(LogLevel.Fatal, LogLevel.Fatal, logfile);
+ LogManager.Configuration = config;
+ if (IsAutoClearLogFile)
+ {
+ // todo: add await
+ DeleteFile(storageFolder.Path + @"\log\");
+ }
+ }
+
+ public static async Task DeleteFile(string path)
+ {
+ string pattern = "yyyyMMdd";
+ int days = AutoClearLogFileDay;
+ var folder = await StorageFolder.GetFolderFromPathAsync(path);
+
+ var files = await folder.GetFilesAsync();
+
+ foreach (var file in files)
{
- config = new LoggingConfiguration();
- Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
- var logfile = new NLog.Targets.FileTarget()
+ var fileName = file.DisplayName;
+ if (!DateTimeOffset.TryParseExact(fileName, pattern, CultureInfo.InvariantCulture, DateTimeStyles.None, out var fileDate))
{
- Name = "logfile",
- CreateDirs = true,
- FileName = storageFolder.Path + @"\log\" + DateTime.Now.ToString("yyyyMMdd") + ".log",
- Layout = "${longdate}|${level:uppercase=true}|${logger}|${threadid}|${message}|${exception:format=Message,StackTrace}"
- };
- config.AddRule(LogLevel.Info, LogLevel.Info, logfile);
- config.AddRule(LogLevel.Debug, LogLevel.Debug, logfile);
- config.AddRule(LogLevel.Error, LogLevel.Error, logfile);
- config.AddRule(LogLevel.Fatal, LogLevel.Fatal, logfile);
- LogManager.Configuration = config;
+ continue;
+ }
+ if (fileDate < DateTimeOffset.Now.AddDays(-days))
+ {
+ File.Delete(file.Path);
+ }
}
+ }
+
+ public static void Log(string message, LogType type, Exception ex = null, [CallerMemberName] string methodName = null)
+ {
Debug.WriteLine("[" + LogType.INFO.ToString() + "]" + message);
+ message = $"[{methodName}]{message}";
+ if(IsProtectLogInfo)
+ message = message.ProtectValues("access_key", "csrf", "access_token");
switch (type)
{
case LogType.INFO:
@@ -53,16 +91,5 @@ public static void Log(string message, LogType type, Exception ex = null)
break;
}
}
- public static bool IsNetworkError(Exception ex)
- {
- if (ex.HResult == -2147012867 || ex.HResult == -2147012889)
- {
- return true;
- }
- {
- return false;
- }
- }
-
}
}
diff --git a/src/BiliLite.UWP/Services/LogService.cs b/src/BiliLite.UWP/Services/LogService.cs
new file mode 100644
index 00000000..de57766e
--- /dev/null
+++ b/src/BiliLite.UWP/Services/LogService.cs
@@ -0,0 +1,49 @@
+using BiliLite.Models.Common;
+using log4net;
+using log4net.Config;
+using System;
+using System.Diagnostics;
+using System.IO;
+using System.Runtime.CompilerServices;
+
+namespace BiliLite.Services
+{
+ public class LogService
+ {
+ public static ILog logger = LogManager.GetLogger(typeof(LogHelper));
+
+ public static void Log(string message, LogType type, Exception ex = null, [CallerMemberName] string methodName = null)
+ {
+ if (!LogManager.GetRepository().Configured)
+ {
+ var logRepository = LogManager.GetRepository(System.Reflection.Assembly.GetEntryAssembly());
+ XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
+ }
+
+ Debug.WriteLine("[" + LogType.INFO.ToString() + "]" + message);
+
+ switch (type)
+ {
+ case LogType.INFO:
+ logger.Info(message);
+ break;
+ case LogType.DEBUG:
+ logger.Debug(message);
+ break;
+ case LogType.ERROR:
+ logger.Error(message, ex);
+ break;
+ case LogType.FATAL:
+ logger.Fatal(message, ex);
+ break;
+ default:
+ break;
+ }
+ }
+ public static void Init()
+ {
+ var logRepository = LogManager.GetRepository(System.Reflection.Assembly.GetEntryAssembly());
+ XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/BiliLite.UWP/Services/SearchService.cs b/src/BiliLite.UWP/Services/SearchService.cs
new file mode 100644
index 00000000..7356e049
--- /dev/null
+++ b/src/BiliLite.UWP/Services/SearchService.cs
@@ -0,0 +1,23 @@
+using BiliLite.Extensions;
+using BiliLite.Models.Requests.Api;
+using BiliLite.Models.Responses;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace BiliLite.Services
+{
+ public class SearchService
+ {
+ public async Task> GetSearchSuggestContents(string text)
+ {
+ if (string.IsNullOrWhiteSpace(text)) return null;
+ var suggestSearchResult = await new SearchAPI().SearchSuggest(text).Request();
+ if (!suggestSearchResult.status) return null;
+ var suggestSearch = await suggestSearchResult.GetResult();
+ if (suggestSearch == null) return null;
+ var suggestSearchContent = suggestSearch.result.Tag.Select(x => x.Value);
+ return suggestSearchContent.ToList();
+ }
+ }
+}
diff --git a/src/BiliLite.UWP/log4net.config b/src/BiliLite.UWP/log4net.config
new file mode 100644
index 00000000..fc5c393e
--- /dev/null
+++ b/src/BiliLite.UWP/log4net.config
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file