mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-09 00:34:14 +08:00
38 lines
1.7 KiB
C#
38 lines
1.7 KiB
C#
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);
|
||
}
|
||
}
|
||
}
|