Skip to content

Commit 1359aa4

Browse files
authored
Remove OpenProtectedFileForRead function (#10285)
1 parent 63a9f44 commit 1359aa4

File tree

3 files changed

+5
-31
lines changed

3 files changed

+5
-31
lines changed

src/Files.App/Filesystem/StorageItems/ZipStorageFile.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -462,16 +462,16 @@ private async Task<BaseBasicProperties> GetBasicProperties()
462462
: new ZipFileBasicProperties(entry);
463463
}
464464

465-
private IAsyncOperation<SevenZipExtractor> OpenZipFileAsync(bool openProtected = false)
465+
private IAsyncOperation<SevenZipExtractor> OpenZipFileAsync()
466466
{
467467
return AsyncInfo.Run<SevenZipExtractor>(async (cancellationToken) =>
468468
{
469-
var zipFile = await OpenZipFileAsync(FileAccessMode.Read, openProtected);
469+
var zipFile = await OpenZipFileAsync(FileAccessMode.Read);
470470
return zipFile is not null ? new SevenZipExtractor(zipFile) : null;
471471
});
472472
}
473473

474-
private IAsyncOperation<Stream> OpenZipFileAsync(FileAccessMode accessMode, bool openProtected = false)
474+
private IAsyncOperation<Stream> OpenZipFileAsync(FileAccessMode accessMode)
475475
{
476476
return AsyncInfo.Run<Stream>(async (cancellationToken) =>
477477
{
@@ -482,9 +482,7 @@ private IAsyncOperation<Stream> OpenZipFileAsync(FileAccessMode accessMode, bool
482482
}
483483
else
484484
{
485-
var hFile = openProtected ?
486-
NativeFileOperationsHelper.OpenProtectedFileForRead(containerPath) :
487-
NativeFileOperationsHelper.OpenFileForRead(containerPath, readWrite);
485+
var hFile = NativeFileOperationsHelper.OpenFileForRead(containerPath, readWrite);
488486
if (hFile.IsInvalid)
489487
{
490488
return null;
@@ -500,9 +498,7 @@ private StreamedFileDataRequestedHandler ZipDataStreamingHandler(string name)
500498
{
501499
try
502500
{
503-
// If called from here it fails with Access Denied?!
504-
//var hFile = NativeFileOperationsHelper.OpenFileForRead(ContainerPath);
505-
using SevenZipExtractor zipFile = await OpenZipFileAsync(openProtected: true);
501+
using SevenZipExtractor zipFile = await OpenZipFileAsync();
506502
if (zipFile == null || zipFile.ArchiveFileData == null)
507503
{
508504
request.FailAndClose(StreamedFileFailureMode.CurrentlyUnavailable);

src/Files.App/Helpers/FileOperationsHelpers.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,6 @@ public class FileOperationsHelpers
3131
{
3232
private static readonly ProgressHandler progressHandler = new();
3333

34-
public static long? GetFileHandle(string filePath, bool readWrite, int processId)
35-
{
36-
using var hFile = Kernel32.CreateFile(filePath, Kernel32.FileAccess.GENERIC_READ | (readWrite ? Kernel32.FileAccess.GENERIC_WRITE : 0), FileShare.ReadWrite, null, FileMode.Open, FileFlagsAndAttributes.FILE_ATTRIBUTE_NORMAL);
37-
38-
if (hFile.IsInvalid)
39-
return null;
40-
41-
using var uwpProces = System.Diagnostics.Process.GetProcessById(processId);
42-
43-
if (!Kernel32.DuplicateHandle(Kernel32.GetCurrentProcess(), hFile.DangerousGetHandle(), uwpProces.Handle, out var targetHandle, 0, false, Kernel32.DUPLICATE_HANDLE_OPTIONS.DUPLICATE_SAME_ACCESS))
44-
return null;
45-
46-
return targetHandle.ToInt64();
47-
}
48-
4934
public static Task SetClipboard(string[] filesToCopy, DataPackageOperation operation)
5035
{
5136
return Win32API.StartSTATask(() =>

src/Files.App/Helpers/NativeFileOperationsHelper.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -465,13 +465,6 @@ public static bool WriteBufferToFileWithProgress(string filePath, byte[] buffer,
465465
return null;
466466
}
467467

468-
public static SafeFileHandle OpenProtectedFileForRead(string filePath, bool readWrite = false)
469-
{
470-
var handle = FileOperationsHelpers.GetFileHandle(filePath, readWrite, System.Diagnostics.Process.GetCurrentProcess().Id);
471-
472-
return new SafeFileHandle(new IntPtr(handle ?? -1), true);
473-
}
474-
475468
// https://github.com/rad1oactive/BetterExplorer/blob/master/Windows%20API%20Code%20Pack%201.1/source/WindowsAPICodePack/Shell/ReparsePoint.cs
476469
public static string ParseSymLink(string path)
477470
{

0 commit comments

Comments
 (0)