From ba0744fa437890d1e8e370b6f07e6ab76aea915c Mon Sep 17 00:00:00 2001 From: Space Time <55327009+SpaceTimee@users.noreply.github.com> Date: Tue, 26 Jul 2022 09:18:40 +0800 Subject: [PATCH] =?UTF-8?q?1.1.5=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Commons/Updater.cs | 7 +++--- Pages/AppearancePage.xaml.cs | 12 +++++----- Windows/MainWindow.xaml.cs | 43 ++++++++++++------------------------ 3 files changed, 23 insertions(+), 39 deletions(-) diff --git a/Commons/Updater.cs b/Commons/Updater.cs index 788c096..ab349fb 100644 --- a/Commons/Updater.cs +++ b/Commons/Updater.cs @@ -72,10 +72,9 @@ private async void ReleaseListBox_SelectionChanged(object sender, SelectionChang Title = "正在保存更新"; new DirectoryInfo(Define.CACHE_PATH).Create(); //创建文件夹 - using FileStream fileStream = new( - Path.Combine(Define.CACHE_PATH, (string)ReleaseListBox.SelectedItem), - FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete); - fileStream.Write(ReleaseBytes, 0, ReleaseBytes.Length); + using (FileStream fileStream = new(Path.Combine(Define.CACHE_PATH, (string)ReleaseListBox.SelectedItem), + FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete)) + fileStream.Write(ReleaseBytes, 0, ReleaseBytes.Length); Title = "正在打开更新"; diff --git a/Pages/AppearancePage.xaml.cs b/Pages/AppearancePage.xaml.cs index 120c93b..3ebbeaa 100644 --- a/Pages/AppearancePage.xaml.cs +++ b/Pages/AppearancePage.xaml.cs @@ -78,7 +78,7 @@ private void OpacitySlider_ValueChanged(object sender, RoutedPropertyChangedEven { if (Define.MAIN_WINDOW != null) { - Define.MAIN_WINDOW!.ActiveRightBorder.Opacity = 1 - OpacitySlider.Value / 100; ; + Define.MAIN_WINDOW!.ActiveRightBorder.Opacity = Define.MAIN_WINDOW!.ActiveTopBorder.Opacity = 1 - OpacitySlider.Value / 100; Properties.Settings.Default.MenuOpacity = OpacitySlider.Value; Properties.Settings.Default.Save(); @@ -161,11 +161,11 @@ private void SetButtonContent() Define.MAIN_WINDOW!.ActiveSettingButton.Content = "设置"; Define.MAIN_WINDOW!.ActiveAboutButton.Content = "关于"; - Define.MAIN_WINDOW!.ActiveViewButton.ToolTip = null; - Define.MAIN_WINDOW!.ActiveSearchButton.ToolTip = null; - Define.MAIN_WINDOW!.ActiveDownloadButton.ToolTip = null; - Define.MAIN_WINDOW!.ActiveLuckyButton.ToolTip = null; - Define.MAIN_WINDOW!.ActiveSettingButton.ToolTip = null; + Define.MAIN_WINDOW!.ActiveViewButton.ToolTip = + Define.MAIN_WINDOW!.ActiveSearchButton.ToolTip = + Define.MAIN_WINDOW!.ActiveDownloadButton.ToolTip = + Define.MAIN_WINDOW!.ActiveLuckyButton.ToolTip = + Define.MAIN_WINDOW!.ActiveSettingButton.ToolTip = Define.MAIN_WINDOW!.ActiveAboutButton.ToolTip = null; } } diff --git a/Windows/MainWindow.xaml.cs b/Windows/MainWindow.xaml.cs index 6b799ac..6b6ff3a 100644 --- a/Windows/MainWindow.xaml.cs +++ b/Windows/MainWindow.xaml.cs @@ -426,44 +426,30 @@ private async Task IsKeyWord() Title = "关键词解析完成"; } - //将URL的参数分离成键值对集合 (待优化) + //将URL的参数分离成键值对集合 private static NameValueCollection GetParamCollection(string queryString) { - queryString = queryString.Replace("?", string.Empty); + //去掉开头的'?'字符并在末尾添加一个'&'字符标志结束 + queryString = queryString.Replace("?", string.Empty) + '&'; + + //分离所有参数并记录 NameValueCollection paramCollection = new(StringComparer.OrdinalIgnoreCase); if (!string.IsNullOrWhiteSpace(queryString)) { - for (int i = 0; i < queryString.Length; ++i) + int startIndex = 0, equalIndex = 0; + for (int endIndex = 0; endIndex < queryString.Length; ++endIndex) { - int startIndex = i, index = -1; - while (i < queryString.Length) - { - if (queryString[i] == '=' && index < 0) - index = i; - else if (queryString[i] == '&') - break; - - ++i; - } - - string key; - string value = null!; - if (index >= 0) + if (queryString[endIndex] == '=') + equalIndex = endIndex; + else if (queryString[endIndex] == '&') { - key = queryString[startIndex..index]; - value = queryString.Substring(index + 1, i - index - 1); + paramCollection[HttpUtility.UrlDecode(queryString[startIndex..equalIndex], Encoding.UTF8)] = HttpUtility.UrlDecode(queryString[(equalIndex + 1)..endIndex], Encoding.UTF8); + startIndex = endIndex + 1; } - else - { - key = queryString[startIndex..i]; - } - - paramCollection[HttpUtility.UrlDecode(key, Encoding.UTF8)] = HttpUtility.UrlDecode(value, Encoding.UTF8); - if (i == queryString.Length - 1 && queryString[i] == '&') - paramCollection[key] = string.Empty; } } + //返回包含所有被分离的参数的键值对集合 return paramCollection; } @@ -516,7 +502,7 @@ private async Task GetImage(string imageUri) bitmapImage.BeginInit(); bitmapImage.StreamSource = responseMessage.Content.ReadAsStream(); try { bitmapImage.EndInit(); } - catch (NotSupportedException) { throw new NotSupportedException("文件格式不合法"); } + catch (NotSupportedException) { throw new NotSupportedException("无法显示该结果"); } CURRENT_IMAGE = bitmapImage; @@ -538,7 +524,6 @@ private void SetImage() Title = "正在读取图片"; ImageBehavior.SetAnimatedSource(ShowImage, CURRENT_IMAGE); - SetControlsEnabled(); Title = "图片读取完成";