Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ALL_APP_PACKAGES work on other languages #20

Merged
merged 1 commit into from
Jun 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions ZenovaLauncher/Utils/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Security.AccessControl;
using System.Security.Cryptography;
using System.Security.Principal;
Expand Down Expand Up @@ -73,13 +71,16 @@ public static IEnumerable<Package> FindPackages(string familyName)
return IsElevated ? new PackageManager().FindPackages(familyName) : new PackageManager().FindPackagesForUser(string.Empty, familyName);
}

private static readonly SecurityIdentifier ALL_APP_PACKAGES_SID = new SecurityIdentifier("S-1-15-2-1");
private static readonly FileSystemRights DefaultRights = FileSystemRights.FullControl;

public static void AddSecurityToFile(string filePath)
{
FileInfo fileInfo = new FileInfo(filePath);
if (fileInfo.Exists)
{
FileSecurity fileSecurity = fileInfo.GetAccessControl();
fileSecurity.AddAccessRule(new FileSystemAccessRule("ALL APPLICATION PACKAGES", FileSystemRights.FullControl, AccessControlType.Allow));
fileSecurity.AddAccessRule(new FileSystemAccessRule(ALL_APP_PACKAGES_SID, DefaultRights, AccessControlType.Allow));
fileInfo.SetAccessControl(fileSecurity);
}
}
Expand All @@ -91,8 +92,8 @@ public static void AddSecurityToDirectory(string dirPath)
{
DirectorySecurity dirSecurity = dirInfo.GetAccessControl();
dirSecurity.AddAccessRule(new FileSystemAccessRule(
"ALL APPLICATION PACKAGES",
FileSystemRights.FullControl,
ALL_APP_PACKAGES_SID,
DefaultRights,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None,
AccessControlType.Allow));
Expand Down