Files
better-genshin-impact/BetterGenshinImpact/Helpers/SecurityControlHelper.cs

38 lines
1.7 KiB
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;
using System.IO;
using System.Security.AccessControl;
using BetterGenshinImpact.GameTask.Common;
using BetterGenshinImpact.View.Windows;
using Microsoft.Extensions.Logging;
namespace BetterGenshinImpact.Helpers;
public static class SecurityControlHelper
{
public static void AllowFullFolderSecurity(string dirPath)
{
if (!RuntimeHelper.IsElevated)
{
return;
}
try
{
DirectoryInfo dir = new(dirPath);
DirectorySecurity dirSecurity = dir.GetAccessControl(AccessControlSections.All);
InheritanceFlags inherits = InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit;
FileSystemAccessRule everyoneFileSystemAccessRule = new("Everyone", FileSystemRights.FullControl, inherits, PropagationFlags.None, AccessControlType.Allow);
FileSystemAccessRule usersFileSystemAccessRule = new("Users", FileSystemRights.FullControl, inherits, PropagationFlags.None, AccessControlType.Allow);
dirSecurity.ModifyAccessRule(AccessControlModification.Add, everyoneFileSystemAccessRule, out _);
dirSecurity.ModifyAccessRule(AccessControlModification.Add, usersFileSystemAccessRule, out _);
dir.SetAccessControl(dirSecurity);
}
catch (Exception e)
{
TaskControl.Logger.LogError("首次运行自动初始化按键绑定异常:" + e.Source + "\r\n--" + Environment.NewLine + e.StackTrace + "\r\n---" + Environment.NewLine + e.Message);
ThemedMessageBox.Warning("检测到当前 BetterGI 位于C盘尝试修改目录权限失败可能会导致WebView2相关的功能无法使用" + e.Message);
}
}
}