-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Code Qaulity: Improved compatibility mode classes #14473
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
Merged
yaira2
merged 1 commit into
files-community:main
from
0x5bfa:5bfa/Improve-CompatPropsPage
Feb 28, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/Files.App/Data/Contracts/IWindowsCompatibilityService.cs
This file contains hidden or 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,26 @@ | ||
// Copyright (c) 2023 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
namespace Files.App.Data.Contracts | ||
{ | ||
/// <summary> | ||
/// Represents contract for compatibility mode service for Windows. | ||
/// </summary> | ||
public interface IWindowsCompatibilityService | ||
{ | ||
/// <summary> | ||
/// Gets compatibility options for path. | ||
/// </summary> | ||
/// <param name="filePath">The path to get options.</param> | ||
/// <returns>Returns an instance of<see cref="WindowsCompatibilityOptions"/> contains options for the path.</returns> | ||
public WindowsCompatibilityOptions GetCompatibilityOptionsForPath(string filePath); | ||
|
||
/// <summary> | ||
/// Sets compatibility options for path. | ||
/// </summary> | ||
/// <param name="filePath">The path to set options.</param> | ||
/// <param name="options">The options to set.</param> | ||
/// <returns>Returns true if succeed; otherwise, false.</returns> | ||
public bool SetCompatibilityOptionsForPath(string filePath, WindowsCompatibilityOptions options); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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,53 @@ | ||
// Copyright (c) 2023 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
using Microsoft.Win32; | ||
|
||
namespace Files.App.Services | ||
{ | ||
/// <inheritdoc cref="IWindowsCompatibilityService"/> | ||
public class WindowsCompatibilityService : IWindowsCompatibilityService | ||
{ | ||
private readonly string _registrySubPath = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers"; | ||
|
||
/// <inheritdoc/> | ||
public WindowsCompatibilityOptions GetCompatibilityOptionsForPath(string filePath) | ||
{ | ||
try | ||
{ | ||
// Get the key | ||
using var compatKey = Registry.CurrentUser.OpenSubKey(_registrySubPath); | ||
if (compatKey is null) | ||
return new(); | ||
|
||
// Get the value for the specified path | ||
var stringOptions = (string?)compatKey.GetValue(filePath, null); | ||
|
||
return WindowsCompatibilityOptions.FromString(stringOptions); | ||
} | ||
catch (Exception) | ||
{ | ||
return new(); | ||
} | ||
} | ||
|
||
/// <inheritdoc/> | ||
public bool SetCompatibilityOptionsForPath(string filePath, WindowsCompatibilityOptions options) | ||
{ | ||
var stringOptions = options.ToString(); | ||
|
||
// Remove old one if new one is valid | ||
if (string.IsNullOrEmpty(stringOptions) || stringOptions == "~") | ||
{ | ||
return Win32API.RunPowershellCommand( | ||
@$"Remove-ItemProperty -Path 'HKCU:\{_registrySubPath}' -Name '{filePath}' | Out-Null", | ||
true); | ||
} | ||
|
||
// Set the new one | ||
return Win32API.RunPowershellCommand( | ||
@$"New-ItemProperty -Path 'HKCU:\{_registrySubPath}' -Name '{filePath}' -Value '{options}' -PropertyType String -Force | Out-Null", | ||
true); | ||
} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.