-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code Quality: Disable drag & drop when running as admin (#15795)
Co-authored-by: Yair <[email protected]>
- Loading branch information
Showing
11 changed files
with
107 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
// Copyright (c) 2024 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
using System.ComponentModel; | ||
|
||
namespace Files.App.Data.Contexts | ||
{ | ||
public interface IWindowContext : INotifyPropertyChanged | ||
{ | ||
bool IsCompactOverlay { get; } | ||
|
||
/// <inheritdoc cref="IWindowsSecurityService.IsAppElevated"/> | ||
bool IsRunningAsAdmin { get; } | ||
|
||
/// <inheritdoc cref="IWindowsSecurityService.CanDragAndDrop"/> | ||
bool CanDragAndDrop { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) 2024 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
namespace Files.App.Data.Contracts | ||
{ | ||
/// <summary> | ||
/// Provides service for security APIs on Windows. | ||
/// </summary> | ||
public interface IWindowsSecurityService | ||
{ | ||
/// <summary> | ||
/// Gets a value that indicates whether the application is elevated. | ||
/// </summary> | ||
/// <returns>Returns true if the application is elevated; otherwise, false.</returns> | ||
bool IsAppElevated(); | ||
|
||
/// <summary> | ||
/// Gets a value that indicates whether the application can drag & drop. | ||
/// </summary> | ||
/// <remarks> | ||
/// Drag & drop onto an elevated app is not allowed (just crashes) due to UIPI. | ||
/// <br/> | ||
/// <br/> | ||
/// For more info, visit: | ||
/// <br/> | ||
/// <a href="https://github.com/files-community/Files/issues/12390"/> | ||
/// <br/> | ||
/// <a href="https://github.com/microsoft/terminal/issues/12017#issuecomment-1004129669"/> | ||
/// </remarks> | ||
/// <returns>Returns true if the application can drag & drop; otherwise, false.</returns> | ||
bool CanDragAndDrop(); | ||
|
||
/// <summary> | ||
/// Gets a value that indicates whether the application needs to be elevated for some operations. | ||
/// </summary> | ||
/// <param name="path"></param> | ||
/// <returns>True if the application needs to be elevated for some operations; otherwise, false.</returns> | ||
bool IsElevationRequired(string path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) 2024 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
namespace Files.App.Services | ||
{ | ||
/// <inheritdoc cref="IWindowsSecurityService"/> | ||
public sealed class WindowsSecurityService : IWindowsSecurityService | ||
{ | ||
/// <inheritdoc/> | ||
public unsafe bool IsAppElevated() | ||
{ | ||
var identity = System.Security.Principal.WindowsIdentity.GetCurrent(); | ||
var principal = new System.Security.Principal.WindowsPrincipal(identity); | ||
return principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public unsafe bool CanDragAndDrop() | ||
{ | ||
return !IsAppElevated(); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public bool IsElevationRequired(string path) | ||
{ | ||
if (string.IsNullOrEmpty(path)) | ||
return false; | ||
|
||
return Win32PInvoke.IsElevationRequired(path); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters