Skip to content

Commit

Permalink
Fixed some issues in thumbnail & file permission
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxb711 committed May 10, 2022
1 parent 1ce2623 commit 5083de8
Show file tree
Hide file tree
Showing 7 changed files with 327 additions and 194 deletions.
68 changes: 49 additions & 19 deletions FullTrustProcess/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2200,7 +2200,7 @@ static FileAttributes ConvertAttribute(MediaFileAttributes Attributes)
string PartialVariable = CommandValue["PartialVariable"];


IEnumerable<KeyValuePair<string,string>> AllEnvironmentVariables = Environment.GetEnvironmentVariables().Cast<DictionaryEntry>()
IEnumerable<KeyValuePair<string, string>> AllEnvironmentVariables = Environment.GetEnvironmentVariables().Cast<DictionaryEntry>()
.Select((Pair) => new KeyValuePair<string, string>(Convert.ToString(Pair.Key), Path.GetFullPath(Convert.ToString(Pair.Value))))
.Where((Pair) => Directory.Exists(Pair.Value));

Expand Down Expand Up @@ -2740,11 +2740,12 @@ static FileAttributes ConvertAttribute(MediaFileAttributes Attributes)
switch (HelperProcess.ExitCode)
{
case 0:
case 1:
{
Value.Add("Success", string.Empty);
break;
}
case 1:
case 2:
{
Value.Add("Error", "Registry checking failed in SystemLaunchHelper");
break;
Expand Down Expand Up @@ -2778,11 +2779,12 @@ static FileAttributes ConvertAttribute(MediaFileAttributes Attributes)
switch (HelperProcess.ExitCode)
{
case 0:
case 1:
{
Value.Add("Success", string.Empty);
break;
}
case 1:
case 2:
{
Value.Add("Error", "Registry checking failed in SystemLaunchHelper");
break;
Expand All @@ -2799,33 +2801,47 @@ static FileAttributes ConvertAttribute(MediaFileAttributes Attributes)
}
case CommandType.RestoreFolderInterception:
{
string SystemLaunchHelperTargetBaseFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "RX-Explorer_Launch_Helper");
string SystemLaunchHelperOriginBaseFolder = Path.Combine(Package.Current.InstalledPath, "SystemLaunchHelper");
string SystemLaunchHelperTargetBaseFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "RX-Explorer_Launch_Helper");
string SystemLaunchHelperOriginExecutable = Path.Combine(SystemLaunchHelperOriginBaseFolder, "SystemLaunchHelper.exe");
string SystemLaunchHelperTargetExecutable = Path.Combine(SystemLaunchHelperTargetBaseFolder, "SystemLaunchHelper.exe");

Helper.CopyTo(SystemLaunchHelperOriginBaseFolder, SystemLaunchHelperTargetBaseFolder);

using (Process HelperProcess = Process.Start(new ProcessStartInfo
ProcessStartInfo ProcessInfo = new ProcessStartInfo
{
FileName = Path.Combine(SystemLaunchHelperTargetBaseFolder, "SystemLaunchHelper.exe"),
UseShellExecute = false,
Arguments = "-Command RestoreFolder",
}))
};

if (File.Exists(SystemLaunchHelperTargetExecutable))
{
ProcessInfo.FileName = SystemLaunchHelperTargetExecutable;
}
else
{
ProcessInfo.FileName = SystemLaunchHelperOriginExecutable;
}

using (Process HelperProcess = Process.Start(ProcessInfo))
{
HelperProcess.WaitForExit();

switch (HelperProcess.ExitCode)
{
case 0:
{
if (!Convert.ToBoolean(Windows.Storage.ApplicationData.Current.LocalSettings.Values["InterceptWindowsE"]))
if (Directory.Exists(SystemLaunchHelperTargetBaseFolder))
{
Directory.Delete(SystemLaunchHelperTargetBaseFolder, true);
}

goto case 1;
}
case 1:
{
Value.Add("Success", string.Empty);
break;
}
case 1:
case 2:
{
Value.Add("Error", "Registry checking failed in SystemLaunchHelper");
break;
Expand All @@ -2842,33 +2858,47 @@ static FileAttributes ConvertAttribute(MediaFileAttributes Attributes)
}
case CommandType.RestoreWinEInterception:
{
string SystemLaunchHelperTargetBaseFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "RX-Explorer_Launch_Helper");
string SystemLaunchHelperOriginBaseFolder = Path.Combine(Package.Current.InstalledPath, "SystemLaunchHelper");
string SystemLaunchHelperTargetBaseFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "RX-Explorer_Launch_Helper");
string SystemLaunchHelperOriginExecutable = Path.Combine(SystemLaunchHelperOriginBaseFolder, "SystemLaunchHelper.exe");
string SystemLaunchHelperTargetExecutable = Path.Combine(SystemLaunchHelperTargetBaseFolder, "SystemLaunchHelper.exe");

Helper.CopyTo(SystemLaunchHelperOriginBaseFolder, SystemLaunchHelperTargetBaseFolder);

using (Process HelperProcess = Process.Start(new ProcessStartInfo
ProcessStartInfo ProcessInfo = new ProcessStartInfo
{
FileName = Path.Combine(SystemLaunchHelperTargetBaseFolder, "SystemLaunchHelper.exe"),
UseShellExecute = false,
Arguments = "-Command RestoreWinE",
}))
};

if (File.Exists(SystemLaunchHelperTargetExecutable))
{
ProcessInfo.FileName = SystemLaunchHelperTargetExecutable;
}
else
{
ProcessInfo.FileName = SystemLaunchHelperOriginExecutable;
}

using (Process HelperProcess = Process.Start(ProcessInfo))
{
HelperProcess.WaitForExit();

switch (HelperProcess.ExitCode)
{
case 0:
{
if (!Convert.ToBoolean(Windows.Storage.ApplicationData.Current.LocalSettings.Values["InterceptDesktopFolder"]))
if (Directory.Exists(SystemLaunchHelperTargetBaseFolder))
{
Directory.Delete(SystemLaunchHelperTargetBaseFolder, true);
}

goto case 1;
}
case 1:
{
Value.Add("Success", string.Empty);
break;
}
case 1:
case 2:
{
Value.Add("Error", "Registry checking failed in SystemLaunchHelper");
break;
Expand Down
81 changes: 45 additions & 36 deletions FullTrustProcess/StorageItemController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ static bool CheckPermissionCore(IEnumerable<FileSystemAccessRule> Rules, FileSys
HashSet<string> WellKnownSID = new HashSet<string>(8)
{
"S-1-1-0",
"S-1-3-0",
"S-1-5-11",
"S-1-5-18",
"S-1-5-32-544",
Expand All @@ -245,53 +246,61 @@ static bool CheckPermissionCore(IEnumerable<FileSystemAccessRule> Rules, FileSys
foreach (IGrouping<IdentityReference, FileSystemAccessRule> RuleGroupByAccount in Security.GetAccessRules(true, true, typeof(NTAccount)).Cast<FileSystemAccessRule>()
.GroupBy((Rule) => Rule.IdentityReference))
{
SecurityIdentifier SecurityId = new SecurityIdentifier(RuleGroupByAccount.Key.Translate(typeof(SecurityIdentifier)).Value);
byte[] SidBuffer = new byte[SecurityId.BinaryLength];
SecurityId.GetBinaryForm(SidBuffer, 0);
try
{
SecurityIdentifier SecurityId = new SecurityIdentifier(RuleGroupByAccount.Key.Translate(typeof(SecurityIdentifier)).Value);

int CchName = 256;
int CchRefDomainName = 256;
StringBuilder Name = new StringBuilder(CchName);
StringBuilder Domain = new StringBuilder(CchRefDomainName);
AccountType Type = AccountType.Unknown;
byte[] SidBuffer = new byte[SecurityId.BinaryLength];
SecurityId.GetBinaryForm(SidBuffer, 0);

if (AdvApi32.LookupAccountSid(null, SidBuffer, Name, ref CchName, Domain, ref CchRefDomainName, out AdvApi32.SID_NAME_USE SidType))
{
switch (SidType)
int CchName = 256;
int CchRefDomainName = 256;
StringBuilder Name = new StringBuilder(CchName);
StringBuilder Domain = new StringBuilder(CchRefDomainName);
AccountType Type = AccountType.Unknown;

if (AdvApi32.LookupAccountSid(null, SidBuffer, Name, ref CchName, Domain, ref CchRefDomainName, out AdvApi32.SID_NAME_USE SidType))
{
case AdvApi32.SID_NAME_USE.SidTypeGroup:
case AdvApi32.SID_NAME_USE.SidTypeWellKnownGroup:
case AdvApi32.SID_NAME_USE.SidTypeAlias:
{
Type = AccountType.Group;
break;
}
case AdvApi32.SID_NAME_USE.SidTypeUser:
{
Type = AccountType.User;
break;
}
switch (SidType)
{
case AdvApi32.SID_NAME_USE.SidTypeGroup:
case AdvApi32.SID_NAME_USE.SidTypeWellKnownGroup:
case AdvApi32.SID_NAME_USE.SidTypeAlias:
{
Type = AccountType.Group;
break;
}
case AdvApi32.SID_NAME_USE.SidTypeUser:
{
Type = AccountType.User;
break;
}
}
}
}

PermissionsResult.Add(new PermissionDataPackage
(
Type switch
{
AccountType.User or AccountType.Group => WellKnownSID.Contains(SecurityId.Value) ? Name.ToString() : $"{Domain}\\{Name}",
_ => RuleGroupByAccount.Key.Value
},
Type,
new Dictionary<Permissions, bool>
{
PermissionsResult.Add(new PermissionDataPackage
(
Type switch
{
AccountType.User or AccountType.Group => (WellKnownSID.Contains(SecurityId.Value) || string.IsNullOrEmpty(Domain.ToString())) ? Name.ToString() : $"{Domain}\\{Name}",
_ => RuleGroupByAccount.Key.Value
},
Type,
new Dictionary<Permissions, bool>
{
{ Permissions.FullControl, CheckPermissionCore(RuleGroupByAccount, FileSystemRights.FullControl) },
{ Permissions.Modify, CheckPermissionCore(RuleGroupByAccount, FileSystemRights.Modify) },
{ Permissions.ListDirectory, CheckPermissionCore(RuleGroupByAccount, FileSystemRights.ListDirectory) },
{ Permissions.ReadAndExecute, CheckPermissionCore(RuleGroupByAccount, FileSystemRights.ReadAndExecute) },
{ Permissions.Read, CheckPermissionCore(RuleGroupByAccount, FileSystemRights.Read) },
{ Permissions.Write, CheckPermissionCore(RuleGroupByAccount, FileSystemRights.Write) },
}
));
}
));
}
catch (Exception ex)
{
LogTracer.Log(ex, $"Could not load the permission of {RuleGroupByAccount.Key.Value}");
}
}

return PermissionsResult;
Expand Down
11 changes: 9 additions & 2 deletions RX_Explorer/Class/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,13 @@ public static async Task<BitmapImage> GetThumbnailBitmapAsync(this IStorageItem
{
try
{
uint RequestSize = Mode switch
{
ThumbnailMode.ListView => 100,
ThumbnailMode.SingleItem => 240,
_ => 160
};

using (CancellationTokenSource Cancellation = new CancellationTokenSource())
{
Task<StorageItemThumbnail> GetThumbnailTask;
Expand All @@ -1184,7 +1191,7 @@ public static async Task<BitmapImage> GetThumbnailBitmapAsync(this IStorageItem
{
case StorageFolder Folder:
{
GetThumbnailTask = Folder.GetThumbnailAsync(Mode, 96, ThumbnailOptions.UseCurrentScale)
GetThumbnailTask = Folder.GetThumbnailAsync(Mode, RequestSize, ThumbnailOptions.UseCurrentScale)
.AsTask()
.ContinueWith((PreviousTask) =>
{
Expand All @@ -1210,7 +1217,7 @@ public static async Task<BitmapImage> GetThumbnailBitmapAsync(this IStorageItem
}
case StorageFile File:
{
GetThumbnailTask = File.GetThumbnailAsync(Mode, 96, ThumbnailOptions.UseCurrentScale)
GetThumbnailTask = File.GetThumbnailAsync(Mode, RequestSize, ThumbnailOptions.UseCurrentScale)
.AsTask()
.ContinueWith((PreviousTask) =>
{
Expand Down
Loading

0 comments on commit 5083de8

Please sign in to comment.