fix issues

This commit is contained in:
DismissedLight
2023-10-15 12:30:44 +08:00
parent 579173d464
commit 1bd6023e0a
8 changed files with 56 additions and 6 deletions

View File

@@ -49,7 +49,14 @@ internal sealed partial class ShellLinkInterop : IShellLinkInterop
string target = Path.Combine(desktop, $"{SH.AppNameAndVersion.Format(runtimeOptions.Version)}.lnk");
IPersistFile persistFile = (IPersistFile)shellLink;
persistFile.Save(target, false);
try
{
persistFile.Save(target, false);
}
catch (UnauthorizedAccessException)
{
return false;
}
return true;
}

View File

@@ -3786,6 +3786,15 @@ namespace Snap.Hutao.Resource.Localization {
}
}
/// <summary>
/// 查找类似 保存游戏路径失败 的本地化字符串。
/// </summary>
internal static string ViewModelSettingSetGamePathDatabaseFailedTitle {
get {
return ResourceManager.GetString("ViewModelSettingSetGamePathDatabaseFailedTitle", resourceCulture);
}
}
/// <summary>
/// 查找类似 用户 [{0}] 添加成功 的本地化字符串。
/// </summary>

View File

@@ -1415,6 +1415,9 @@
<data name="ViewModelSettingSetDataFolderSuccess" xml:space="preserve">
<value>设置数据目录成功,重启以应用更改</value>
</data>
<data name="ViewModelSettingSetGamePathDatabaseFailedTitle" xml:space="preserve">
<value>保存游戏路径失败</value>
</data>
<data name="ViewModelUserAdded" xml:space="preserve">
<value>用户 [{0}] 添加成功</value>
</data>

View File

@@ -132,7 +132,10 @@ internal sealed partial class AnnouncementContentViewer : UserControl
private void OnUnloaded(object sender, RoutedEventArgs e)
{
WebView.CoreWebView2.WebMessageReceived -= webMessageReceivedHandler;
if (WebView is { CoreWebView2: CoreWebView2 coreWebView2 })
{
coreWebView2.WebMessageReceived -= webMessageReceivedHandler;
}
}
private async ValueTask LoadAnnouncementAsync()

View File

@@ -1,6 +1,7 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.UI.Xaml.Controls;
using Microsoft.Windows.AppLifecycle;
@@ -126,7 +127,15 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
if (isOk)
{
await taskContext.SwitchToMainThreadAsync();
Options.GamePath = path;
try
{
Options.GamePath = path;
}
catch (SqliteException ex)
{
// 文件夹权限不足,无法写入数据库
infoBarService.Error(ex, SH.ViewModelSettingSetGamePathDatabaseFailedTitle);
}
}
}

View File

@@ -375,14 +375,18 @@ internal class MiHoYoJSInterface
await taskContext.SwitchToMainThreadAsync();
try
{
return await webView.ExecuteScriptAsync(js);
if (webView is not null)
{
return await webView.ExecuteScriptAsync(js);
}
}
catch (COMException)
{
// COMException (0x8007139F): 组或资源的状态不是执行请求操作的正确状态。 (0x8007139F)
// webview is disposing or disposed
return string.Empty;
}
return string.Empty;
}
private async void OnWebMessageReceived(CoreWebView2 webView2, CoreWebView2WebMessageReceivedEventArgs args)

View File

@@ -22,7 +22,17 @@ internal sealed partial class HomaGeetestClient
{
string template = appOptions.GeetestCustomCompositeUrl;
if (string.IsNullOrEmpty(template) || !Uri.TryCreate(template.Format(gt, challenge), UriKind.Absolute, out Uri? uri))
string url;
try
{
url = template.Format(gt, challenge);
}
catch (FormatException)
{
return GeetestResponse.InternalFailure;
}
if (string.IsNullOrEmpty(template) || !Uri.TryCreate(url, UriKind.Absolute, out Uri? uri))
{
return GeetestResponse.InternalFailure;
}

View File

@@ -33,6 +33,11 @@ internal static class HttpRequestMessageBuilderExtension
logger.LogWarning(ex, RequestErrorMessage);
return default;
}
catch (HttpContentSerializationException ex)
{
logger.LogWarning(ex, RequestErrorMessage);
return default;
}
catch (SocketException ex)
{
logger.LogWarning(ex, RequestErrorMessage);