diff --git a/CHANGELOG.md b/CHANGELOG.md index 4347771..54dd1c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # 更新日志 +## `2023/05/24` v1.5.9 + +* [新增] 下载完成系统提示。 +* [修复] UP主个人空间访问。 + ## `2023/04/30` v1.5.8 * [新增] 视频详情页搜索功能。 diff --git a/src/DownKyi.Core/BiliApi/Sign/WbiSign.cs b/src/DownKyi.Core/BiliApi/Sign/WbiSign.cs new file mode 100644 index 0000000..4d584dc --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Sign/WbiSign.cs @@ -0,0 +1,120 @@ +using DownKyi.Core.Settings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Text.RegularExpressions; + +namespace DownKyi.Core.BiliApi.Sign +{ + public static class WbiSign + { + + /// + /// 打乱重排实时口令 + /// + /// + /// + private static string GetMixinKey(string origin) + { + int[] mixinKeyEncTab = new int[] + { + 46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49, + 33, 9, 42, 19, 29, 28, 14, 39,12, 38, 41, 13, 37, 48, 7, 16, 24, 55, 40, + 61, 26, 17, 0, 1, 60, 51, 30, 4, 22, 25, 54, 21, 56, 59, 6, 63, 57, 62, 11, + 36, 20, 34, 44, 52 + }; + + var temp = new StringBuilder(); + foreach (var i in mixinKeyEncTab) + { + temp.Append(origin[i]); + } + return temp.ToString().Substring(0, 32); + } + + /// + /// 将字典参数转为字符串 + /// + /// + /// + public static string ParametersToQuery(Dictionary parameters) + { + var keys = parameters.Keys.ToList(); + var queryList = new List(); + foreach (var item in keys) + { + var value = parameters[item]; + queryList.Add($"{item}={value}"); + } + return string.Join("&", queryList); + } + + /// + /// Wbi签名,返回所有参数字典 + /// + /// + /// + public static Dictionary EncodeWbi(Dictionary parameters) + { + return EncodeWbi(parameters, GetKey().Item1, GetKey().Item2); + } + + /// + /// Wbi签名,返回所有参数字典 + /// + /// + /// + /// + /// + public static Dictionary EncodeWbi(Dictionary parameters, string imgKey, string subKey) + { + var mixinKey = GetMixinKey(imgKey + subKey); + + var chrFilter = new Regex("[!'()*]"); + + var newParameters = new Dictionary + { + { "wts", (long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds } + }; + + foreach (var para in parameters) + { + var key = para.Key; + var value = para.Value.ToString(); + + var encodedValue = chrFilter.Replace(value, ""); + + newParameters.Add(Uri.EscapeDataString(key), Uri.EscapeDataString(encodedValue)); + } + + var keys = newParameters.Keys.ToList(); + keys.Sort(); + + var queryList = new List(); + foreach (var item in keys) + { + var value = newParameters[item]; + queryList.Add($"{item}={value}"); + } + + var queryString = string.Join("&", queryList); + var md5Hasher = MD5.Create(); + var hashStr = queryString + mixinKey; + var hashedQueryString = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(hashStr)); + var wbiSign = BitConverter.ToString(hashedQueryString).Replace("-", "").ToLower(); + + newParameters.Add("w_rid", wbiSign); + return newParameters; + } + + public static Tuple GetKey() + { + var user = SettingsManager.GetInstance().GetUserInfo(); + + return new Tuple(user.ImgKey, user.SubKey); + } + + } +} \ No newline at end of file diff --git a/src/DownKyi.Core/BiliApi/Users/Models/UserInfoForNavigation.cs b/src/DownKyi.Core/BiliApi/Users/Models/UserInfoForNavigation.cs index 0801dd3..d1256dc 100644 --- a/src/DownKyi.Core/BiliApi/Users/Models/UserInfoForNavigation.cs +++ b/src/DownKyi.Core/BiliApi/Users/Models/UserInfoForNavigation.cs @@ -53,6 +53,9 @@ namespace DownKyi.Core.BiliApi.Users.Models //public int vip_theme_type { get; set; } [JsonProperty("wallet")] public UserInfoWallet Wallet { get; set; } + + [JsonProperty("wbi_img")] + public Wbi Wbi { get; set; } } //public class NavDataLevelInfo @@ -105,4 +108,14 @@ namespace DownKyi.Core.BiliApi.Users.Models [JsonProperty("mid")] public long Mid { get; set; } } + + [JsonObject] + public class Wbi + { + [JsonProperty("img_url")] + public string ImgUrl { get; set; } + [JsonProperty("sub_url")] + public string SubUrl { get; set; } + } + } diff --git a/src/DownKyi.Core/BiliApi/Users/UserInfo.cs b/src/DownKyi.Core/BiliApi/Users/UserInfo.cs index 175f1e3..cafdbb8 100644 --- a/src/DownKyi.Core/BiliApi/Users/UserInfo.cs +++ b/src/DownKyi.Core/BiliApi/Users/UserInfo.cs @@ -1,7 +1,9 @@ -using DownKyi.Core.BiliApi.Users.Models; +using DownKyi.Core.BiliApi.Sign; +using DownKyi.Core.BiliApi.Users.Models; using DownKyi.Core.Logging; using Newtonsoft.Json; using System; +using System.Collections.Generic; namespace DownKyi.Core.BiliApi.Users { @@ -25,8 +27,7 @@ namespace DownKyi.Core.BiliApi.Users UserInfoForNavigationOrigin userInfo = JsonConvert.DeserializeObject(response); if (userInfo == null || userInfo.Data == null) { return null; } - if (userInfo.Data.IsLogin) { return userInfo.Data; } - else { return null; } + return userInfo.Data; } catch (Exception e) { @@ -43,7 +44,12 @@ namespace DownKyi.Core.BiliApi.Users /// public static UserInfoForSpace GetUserInfoForSpace(long mid) { - string url = $"https://api.bilibili.com/x/space/wbi/acc/info?mid={mid}"; + var parameters = new Dictionary + { + { "mid", mid } + }; + string query = WbiSign.ParametersToQuery(WbiSign.EncodeWbi(parameters)); + string url = $"https://api.bilibili.com/x/space/wbi/acc/info?{query}"; string referer = "https://www.bilibili.com"; string response = WebClient.RequestWeb(url, referer); diff --git a/src/DownKyi.Core/BiliApi/Users/UserSpace.cs b/src/DownKyi.Core/BiliApi/Users/UserSpace.cs index c76af60..4072cf1 100644 --- a/src/DownKyi.Core/BiliApi/Users/UserSpace.cs +++ b/src/DownKyi.Core/BiliApi/Users/UserSpace.cs @@ -1,4 +1,5 @@ -using DownKyi.Core.BiliApi.Users.Models; +using DownKyi.Core.BiliApi.Sign; +using DownKyi.Core.BiliApi.Users.Models; using DownKyi.Core.Logging; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -114,7 +115,17 @@ namespace DownKyi.Core.BiliApi.Users /// public static SpacePublicationList GetPublication(long mid, int pn, int ps, long tid = 0, PublicationOrder order = PublicationOrder.PUBDATE, string keyword = "") { - string url = $"https://api.bilibili.com/x/space/wbi/arc/search?mid={mid}&pn={pn}&ps={ps}&order={order.ToString("G").ToLower()}&tid={tid}&keyword={keyword}"; + var parameters = new Dictionary + { + { "mid", mid }, + { "pn", pn }, + { "ps", ps }, + { "order", order.ToString("G").ToLower() }, + { "tid", tid }, + { "keyword", keyword }, + }; + string query = WbiSign.ParametersToQuery(WbiSign.EncodeWbi(parameters)); + string url = $"https://api.bilibili.com/x/space/wbi/arc/search?{query}"; string referer = "https://www.bilibili.com"; string response = WebClient.RequestWeb(url, referer); diff --git a/src/DownKyi.Core/BiliApi/Video/VideoInfo.cs b/src/DownKyi.Core/BiliApi/Video/VideoInfo.cs index ed65ced..5744ccb 100644 --- a/src/DownKyi.Core/BiliApi/Video/VideoInfo.cs +++ b/src/DownKyi.Core/BiliApi/Video/VideoInfo.cs @@ -1,4 +1,5 @@ -using DownKyi.Core.BiliApi.Video.Models; +using DownKyi.Core.BiliApi.Sign; +using DownKyi.Core.BiliApi.Video.Models; using DownKyi.Core.Logging; using Newtonsoft.Json; using System; @@ -17,13 +18,23 @@ namespace DownKyi.Core.BiliApi.Video public static VideoView VideoViewInfo(string bvid = null, long aid = -1) { // https://api.bilibili.com/x/web-interface/view/detail?bvid=BV1Sg411F7cb&aid=969147110&need_operation_card=1&web_rm_repeat=1&need_elec=1&out_referer=https%3A%2F%2Fspace.bilibili.com%2F42018135%2Ffavlist%3Ffid%3D94341835 - string baseUrl = "https://api.bilibili.com/x/web-interface/view"; - string referer = "https://www.bilibili.com"; - string url; - if (bvid != null) { url = $"{baseUrl}?bvid={bvid}"; } - else if (aid > -1) { url = $"{baseUrl}?aid={aid}"; } - else { return null; } + var parameters = new Dictionary(); + if (bvid != null) + { + parameters.Add("bvid", bvid); + } + else if (aid > -1) + { + parameters.Add("aid", aid); + } + else + { + return null; + } + string query = WbiSign.ParametersToQuery(WbiSign.EncodeWbi(parameters)); + string url = $"https://api.bilibili.com/x/web-interface/wbi/view?{query}"; + string referer = "https://www.bilibili.com"; string response = WebClient.RequestWeb(url, referer); try diff --git a/src/DownKyi.Core/BiliApi/VideoStream/VideoStream.cs b/src/DownKyi.Core/BiliApi/VideoStream/VideoStream.cs index 5764fcd..80c6109 100644 --- a/src/DownKyi.Core/BiliApi/VideoStream/VideoStream.cs +++ b/src/DownKyi.Core/BiliApi/VideoStream/VideoStream.cs @@ -1,4 +1,5 @@ using DownKyi.Core.BiliApi.Models.Json; +using DownKyi.Core.BiliApi.Sign; using DownKyi.Core.BiliApi.VideoStream.Models; using DownKyi.Core.Logging; using Newtonsoft.Json; @@ -19,7 +20,14 @@ namespace DownKyi.Core.BiliApi.VideoStream /// public static PlayerV2 PlayerV2(long avid, string bvid, long cid) { - string url = $"https://api.bilibili.com/x/player/v2?cid={cid}&aid={avid}&bvid={bvid}"; + var parameters = new Dictionary + { + { "avid", avid }, + { "bvid", bvid }, + { "cid", cid }, + }; + string query = WbiSign.ParametersToQuery(WbiSign.EncodeWbi(parameters)); + string url = $"https://api.bilibili.com/x/player/wbi/v2?{query}"; string referer = "https://www.bilibili.com"; string response = WebClient.RequestWeb(url, referer); @@ -93,11 +101,30 @@ namespace DownKyi.Core.BiliApi.VideoStream /// public static PlayUrl GetVideoPlayUrl(long avid, string bvid, long cid, int quality = 125) { - string baseUrl = $"https://api.bilibili.com/x/player/playurl?cid={cid}&qn={quality}&fourk=1&fnver=0&fnval=4048"; - string url; - if (bvid != null) { url = $"{baseUrl}&bvid={bvid}"; } - else if (avid > -1) { url = $"{baseUrl}&aid={avid}"; } - else { return null; } + var parameters = new Dictionary + { + { "fourk", 1 }, + { "fnver", 0 }, + { "fnval", 4048 }, + { "cid", cid }, + { "qn", quality }, + }; + + if (bvid != null) + { + parameters.Add("bvid", bvid); + } + else if (avid > -1) + { + parameters.Add("aid", avid); + } + else + { + return null; + } + + string query = WbiSign.ParametersToQuery(WbiSign.EncodeWbi(parameters)); + string url = $"https://api.bilibili.com/x/player/wbi/playurl?{query}"; return GetPlayUrl(url); } diff --git a/src/DownKyi.Core/DownKyi.Core.csproj b/src/DownKyi.Core/DownKyi.Core.csproj index c919ea6..2a9a3fb 100644 --- a/src/DownKyi.Core/DownKyi.Core.csproj +++ b/src/DownKyi.Core/DownKyi.Core.csproj @@ -186,6 +186,7 @@ + diff --git a/src/DownKyi.Core/Properties/AssemblyInfo.cs b/src/DownKyi.Core/Properties/AssemblyInfo.cs index 3c2f21e..6d3cbf8 100644 --- a/src/DownKyi.Core/Properties/AssemblyInfo.cs +++ b/src/DownKyi.Core/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //通过使用 "*",如下所示: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.1.8.0")] -[assembly: AssemblyFileVersion("2.1.8.0")] +[assembly: AssemblyVersion("2.1.9.0")] +[assembly: AssemblyFileVersion("2.1.9.0")] diff --git a/src/DownKyi.Core/Settings/Models/UserInfoSettings.cs b/src/DownKyi.Core/Settings/Models/UserInfoSettings.cs index 774b7ec..63debc7 100644 --- a/src/DownKyi.Core/Settings/Models/UserInfoSettings.cs +++ b/src/DownKyi.Core/Settings/Models/UserInfoSettings.cs @@ -6,5 +6,8 @@ public string Name { get; set; } public bool IsLogin { get; set; } // 是否登录 public bool IsVip { get; set; } // 是否为大会员,未登录时为false + + public string ImgKey { get; set; } + public string SubKey { get; set; } } } diff --git a/src/DownKyi.Core/Settings/SettingsManager.cs b/src/DownKyi.Core/Settings/SettingsManager.cs index f6d19b0..44a16bc 100644 --- a/src/DownKyi.Core/Settings/SettingsManager.cs +++ b/src/DownKyi.Core/Settings/SettingsManager.cs @@ -55,13 +55,23 @@ namespace DownKyi.Core.Settings /// private AppSettings GetSettings() { + if (appSettings != null) { return appSettings; } + try { - FileStream fileStream = new FileStream(settingsName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - StreamReader streamReader = new StreamReader(fileStream, System.Text.Encoding.UTF8); - string jsonWordTemplate = streamReader.ReadToEnd(); - streamReader.Close(); - fileStream.Close(); + //FileStream fileStream = new FileStream(settingsName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + //StreamReader streamReader = new StreamReader(fileStream, System.Text.Encoding.UTF8); + //string jsonWordTemplate = streamReader.ReadToEnd(); + //streamReader.Close(); + //fileStream.Close(); + string jsonWordTemplate = string.Empty; + using (var stream = new FileStream(settingsName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete)) + { + using (var reader = new StreamReader(stream, System.Text.Encoding.UTF8)) + { + jsonWordTemplate = reader.ReadToEnd(); + } + } #if DEBUG #else diff --git a/src/DownKyi.Core/Utils/Format.cs b/src/DownKyi.Core/Utils/Format.cs index fcde0f6..14653ef 100644 --- a/src/DownKyi.Core/Utils/Format.cs +++ b/src/DownKyi.Core/Utils/Format.cs @@ -198,6 +198,12 @@ namespace DownKyi.Core.Utils // 控制字符 destName = Regex.Replace(destName, @"\p{C}+", string.Empty); + // 如果只有空白字符、dot符 + if (destName == " " || destName == ".") + { + return "[empty title]"; + } + // 移除前导和尾部的空白字符、dot符 int i, j; for (i = 0; i < destName.Length; i++) diff --git a/src/DownKyi/Languages/Default.xaml b/src/DownKyi/Languages/Default.xaml index b6ca780..19cebae 100644 --- a/src/DownKyi/Languages/Default.xaml +++ b/src/DownKyi/Languages/Default.xaml @@ -200,7 +200,7 @@ 启用https(若下载器提示SSL错误,则关闭此项) UserAgent: 选择下载器(重启生效): - 内建下载器(测试) + 内建下载器 Aria2下载器 自定义Aria2下载器 Aria服务器地址: diff --git a/src/DownKyi/Models/AppInfo.cs b/src/DownKyi/Models/AppInfo.cs index 9d92d36..b6535c2 100644 --- a/src/DownKyi/Models/AppInfo.cs +++ b/src/DownKyi/Models/AppInfo.cs @@ -11,7 +11,7 @@ namespace DownKyi.Models const int a = 1; const int b = 5; - const int c = 8; + const int c = 9; public AppInfo() { diff --git a/src/DownKyi/Properties/AssemblyInfo.cs b/src/DownKyi/Properties/AssemblyInfo.cs index cbd7d78..1a199a7 100644 --- a/src/DownKyi/Properties/AssemblyInfo.cs +++ b/src/DownKyi/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ using System.Windows; // 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.5.8.0")] -[assembly: AssemblyFileVersion("1.5.8.0")] +[assembly: AssemblyVersion("1.5.9.0")] +[assembly: AssemblyFileVersion("1.5.9.0")] diff --git a/src/DownKyi/Services/AlertService.cs b/src/DownKyi/Services/AlertService.cs index 4b46ecf..910842d 100644 --- a/src/DownKyi/Services/AlertService.cs +++ b/src/DownKyi/Services/AlertService.cs @@ -31,12 +31,13 @@ namespace DownKyi.Services /// 显示一个警告弹窗 /// /// + /// /// - public ButtonResult ShowWarning(string message) + public ButtonResult ShowWarning(string message, int buttonNumber = 1) { VectorImage image = SystemIcon.Instance().Warning; string title = DictionaryResource.GetString("Warning"); - return ShowMessage(image, title, message, 1); + return ShowMessage(image, title, message, buttonNumber); } /// diff --git a/src/DownKyi/Services/Download/DownloadService.cs b/src/DownKyi/Services/Download/DownloadService.cs index acea7a1..8e569b7 100644 --- a/src/DownKyi/Services/Download/DownloadService.cs +++ b/src/DownKyi/Services/Download/DownloadService.cs @@ -20,14 +20,14 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; -using System.Windows; +using System.Windows.Media.Imaging; namespace DownKyi.Services.Download { public abstract class DownloadService { protected string Tag = "DownloadService"; - protected TaskbarIcon _notifyIcon; + protected TaskbarIcon _notifyIcon; protected IDialogService dialogService; protected ObservableCollection downloadingList; protected ObservableCollection downloadedList; @@ -805,6 +805,8 @@ namespace DownKyi.Services.Download tokenSource = new CancellationTokenSource(); cancellationToken = tokenSource.Token; _notifyIcon = new TaskbarIcon(); + _notifyIcon.IconSource = new BitmapImage(new Uri("pack://application:,,,/Resources/favicon.ico")); + workTask = Task.Run(DoWork); } diff --git a/src/DownKyi/ViewModels/DownloadManager/DownloadedItem.cs b/src/DownKyi/ViewModels/DownloadManager/DownloadedItem.cs index 7ddde0b..244459c 100644 --- a/src/DownKyi/ViewModels/DownloadManager/DownloadedItem.cs +++ b/src/DownKyi/ViewModels/DownloadManager/DownloadedItem.cs @@ -155,7 +155,7 @@ namespace DownKyi.ViewModels.DownloadManager private void ExecuteRemoveVideoCommand() { AlertService alertService = new AlertService(DialogService); - ButtonResult result = alertService.ShowWarning(DictionaryResource.GetString("ConfirmDelete")); + ButtonResult result = alertService.ShowWarning(DictionaryResource.GetString("ConfirmDelete"), 2); if (result != ButtonResult.OK) { return; diff --git a/src/DownKyi/ViewModels/DownloadManager/DownloadingItem.cs b/src/DownKyi/ViewModels/DownloadManager/DownloadingItem.cs index 0f090eb..7e54bf2 100644 --- a/src/DownKyi/ViewModels/DownloadManager/DownloadingItem.cs +++ b/src/DownKyi/ViewModels/DownloadManager/DownloadingItem.cs @@ -218,7 +218,7 @@ namespace DownKyi.ViewModels.DownloadManager private void ExecuteDeleteCommand() { AlertService alertService = new AlertService(DialogService); - ButtonResult result = alertService.ShowWarning(DictionaryResource.GetString("ConfirmDelete")); + ButtonResult result = alertService.ShowWarning(DictionaryResource.GetString("ConfirmDelete"), 2); if (result != ButtonResult.OK) { return; diff --git a/src/DownKyi/ViewModels/ViewIndexViewModel.cs b/src/DownKyi/ViewModels/ViewIndexViewModel.cs index 9eaeb10..b78e5c5 100644 --- a/src/DownKyi/ViewModels/ViewIndexViewModel.cs +++ b/src/DownKyi/ViewModels/ViewIndexViewModel.cs @@ -1,4 +1,5 @@ using DownKyi.Core.BiliApi.Users; +using DownKyi.Core.BiliApi.Users.Models; using DownKyi.Core.Logging; using DownKyi.Core.Settings; using DownKyi.Core.Settings.Models; @@ -12,6 +13,7 @@ using Prism.Regions; using Prism.Services.Dialogs; using System; using System.IO; +using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows; @@ -227,15 +229,59 @@ namespace DownKyi.ViewModels InputText = string.Empty; } + private async Task GetUserInfo() + { + UserInfoForNavigation userInfo = null; + await Task.Run(new Action(() => + { + // 获取用户信息 + userInfo = UserInfo.GetUserInfoForNavigation(); + if (userInfo != null) + { + SettingsManager.GetInstance().SetUserInfo(new UserInfoSettings + { + Mid = userInfo.Mid, + Name = userInfo.Name, + IsLogin = userInfo.IsLogin, + IsVip = userInfo.VipStatus == 1, + ImgKey = userInfo.Wbi.ImgUrl.Split('/').ToList().Last().Split('.')[0], + SubKey = userInfo.Wbi.SubUrl.Split('/').ToList().Last().Split('.')[0], + }); + } + else + { + SettingsManager.GetInstance().SetUserInfo(new UserInfoSettings + { + Mid = -1, + Name = "", + IsLogin = false, + IsVip = false, + }); + } + + })); + return userInfo; + } + /// /// 更新用户登录信息 /// - private async void UpdateUserInfo() + private async void UpdateUserInfo(bool isBackgroud = false) { try { + if (isBackgroud) + { + // 获取用户信息 + await GetUserInfo(); + return; + } + LoginPanelVisibility = Visibility.Hidden; + // 获取用户信息 + var userInfo = await GetUserInfo(); + // 检查本地是否存在login文件,没有则说明未登录 if (!File.Exists(StorageManager.GetLogin())) { @@ -245,54 +291,26 @@ namespace DownKyi.ViewModels return; } - await Task.Run(new Action(() => + LoginPanelVisibility = Visibility.Visible; + + if (userInfo != null) { - // 获取用户信息 - var userInfo = UserInfo.GetUserInfoForNavigation(); - if (userInfo != null) + if (userInfo.Face != null) { - SettingsManager.GetInstance().SetUserInfo(new UserInfoSettings - { - Mid = userInfo.Mid, - Name = userInfo.Name, - IsLogin = userInfo.IsLogin, - IsVip = userInfo.VipStatus == 1 - }); + Header = new StorageHeader().GetHeaderThumbnail(userInfo.Mid, userInfo.Name, userInfo.Face, 36, 36); } else { - SettingsManager.GetInstance().SetUserInfo(new UserInfoSettings - { - Mid = -1, - Name = "", - IsLogin = false, - IsVip = false - }); + Header = new BitmapImage(new Uri("pack://application:,,,/Resources/default_header.jpg")); } + UserName = userInfo.Name; + } + else + { + Header = new BitmapImage(new Uri("pack://application:,,,/Resources/default_header.jpg")); + UserName = null; + } - PropertyChangeAsync(new Action(() => - { - LoginPanelVisibility = Visibility.Visible; - - if (userInfo != null) - { - if (userInfo.Face != null) - { - Header = new StorageHeader().GetHeaderThumbnail(userInfo.Mid, userInfo.Name, userInfo.Face, 36, 36); - } - else - { - Header = new BitmapImage(new Uri("pack://application:,,,/Resources/default_header.jpg")); - } - UserName = userInfo.Name; - } - else - { - Header = new BitmapImage(new Uri("pack://application:,,,/Resources/default_header.jpg")); - UserName = null; - } - })); - })); } catch (Exception e) { @@ -316,23 +334,31 @@ namespace DownKyi.ViewModels string parameter = navigationContext.Parameters.GetValue("Parameter"); if (parameter == null) { + // 其他情况只更新设置的用户信息,不更新UI + UpdateUserInfo(true); return; } + // 启动 if (parameter == "start") { UpdateUserInfo(); } // 从登录页面返回 - if (parameter == "login") + else if (parameter == "login") { UpdateUserInfo(); } // 注销 - if (parameter == "logout") + else if (parameter == "logout") { UpdateUserInfo(); } + else + { + // 其他情况只更新设置的用户信息,不更新UI + UpdateUserInfo(true); + } }