Files
qhmes/yy-admin-master/YY.Admin/Helper/WebView2UserDataFolder.cs

24 lines
959 B
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.IO;
using Microsoft.Web.WebView2.Wpf;
using YY.Admin.Core.Util;
namespace YY.Admin.Helper;
/// <summary>
/// WebView2 默认将用户数据目录放在宿主 exe 旁边;安装在 Program Files 时目录只读会导致初始化失败、预览白屏。
/// 统一到当前用户 LocalAppData 下的可写路径。
/// </summary>
public static class WebView2UserDataFolder
{
/// <summary>
/// 为控件创建 CreationProperties须在首次 EnsureCoreWebView2Async 之前赋值)。
/// </summary>
/// <param name="subFolder">子目录名,避免不同场景争用同一 profile。</param>
public static CoreWebView2CreationProperties CreateCreationProperties(string subFolder)
{
var folder = AppWritablePaths.EnsureDirectoryExists(
Path.Combine(AppWritablePaths.LocalApplicationRoot, "WebView2", subFolder));
return new CoreWebView2CreationProperties { UserDataFolder = folder };
}
}