Skip to content

Commit f3fda44

Browse files
0x5bfayaira2
authored andcommitted
Initial commit
1 parent 83132c9 commit f3fda44

File tree

12 files changed

+345
-395
lines changed

12 files changed

+345
-395
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2023 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
namespace Files.App.Data.Contracts
5+
{
6+
/// <summary>
7+
/// Represents contract for compatibility mode service for Windows.
8+
/// </summary>
9+
public interface IWindowsCompatibilityService
10+
{
11+
/// <summary>
12+
/// Gets compatibility options for path.
13+
/// </summary>
14+
/// <param name="filePath">The path to get options.</param>
15+
/// <returns>Returns an instance of<see cref="WindowsCompatibilityOptions"/> contains options for the path.</returns>
16+
public WindowsCompatibilityOptions GetCompatibilityOptionsForPath(string filePath);
17+
18+
/// <summary>
19+
/// Sets compatibility options for path.
20+
/// </summary>
21+
/// <param name="filePath">The path to set options.</param>
22+
/// <param name="options">The options to set.</param>
23+
/// <returns>Returns true if succeed; otherwise, false.</returns>
24+
public bool SetCompatibilityOptionsForPath(string filePath, WindowsCompatibilityOptions options);
25+
}
26+
}

src/Files.App/Helpers/Application/AppLifecycleHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ public static IHost ConfigureHost()
186186
.AddSingleton<IRemovableDrivesService, RemovableDrivesService>()
187187
.AddSingleton<INetworkDrivesService, NetworkDrivesService>()
188188
.AddSingleton<IStartMenuService, StartMenuService>()
189+
.AddSingleton<IWindowsCompatibilityService, WindowsCompatibilityService>()
189190
// ViewModels
190191
.AddSingleton<MainPageViewModel>()
191192
.AddSingleton<InfoPaneViewModel>()

src/Files.App/Helpers/LocalizedEnumHelper.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) 2023 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
using Microsoft.Win32;
5+
6+
namespace Files.App.Services
7+
{
8+
/// <inheritdoc cref="IWindowsCompatibilityService"/>
9+
public class WindowsCompatibilityService : IWindowsCompatibilityService
10+
{
11+
private readonly string _registrySubPath = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers";
12+
13+
/// <inheritdoc/>
14+
public WindowsCompatibilityOptions GetCompatibilityOptionsForPath(string filePath)
15+
{
16+
try
17+
{
18+
// Get the key
19+
using var compatKey = Registry.CurrentUser.OpenSubKey(_registrySubPath);
20+
if (compatKey is null)
21+
return new();
22+
23+
// Get the value for the specified path
24+
var stringOptions = (string?)compatKey.GetValue(filePath, null);
25+
26+
return WindowsCompatibilityOptions.FromString(stringOptions);
27+
}
28+
catch (Exception)
29+
{
30+
return new();
31+
}
32+
}
33+
34+
/// <inheritdoc/>
35+
public bool SetCompatibilityOptionsForPath(string filePath, WindowsCompatibilityOptions options)
36+
{
37+
var stringOptions = options.ToString();
38+
39+
// Remove old one if new one is valid
40+
if (string.IsNullOrEmpty(stringOptions) || stringOptions == "~")
41+
{
42+
return Win32API.RunPowershellCommand(
43+
@$"Remove-ItemProperty -Path 'HKCU:\{_registrySubPath}' -Name '{filePath}' | Out-Null",
44+
true);
45+
}
46+
47+
// Set the new one
48+
return Win32API.RunPowershellCommand(
49+
@$"New-ItemProperty -Path 'HKCU:\{_registrySubPath}' -Name '{filePath}' -Value '{options}' -PropertyType String -Force | Out-Null",
50+
true);
51+
}
52+
}
53+
}

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,66 +1797,60 @@
17971797
<data name="None" xml:space="preserve">
17981798
<value>None</value>
17991799
</data>
1800-
<data name="HighDpiOption_UseDPIOnLogin" xml:space="preserve">
1800+
<data name="CompatibilityOnWindowsLogin" xml:space="preserve">
18011801
<value>On Windows login</value>
18021802
</data>
1803-
<data name="HighDpiOption_UseDPIOnProgramStart" xml:space="preserve">
1804-
<value>On program start</value>
1803+
<data name="CompatibilityOnProgramStart" xml:space="preserve">
1804+
<value>On this program start</value>
18051805
</data>
1806-
<data name="HighDpiOverride_System" xml:space="preserve">
1806+
<data name="System" xml:space="preserve">
18071807
<value>System</value>
18081808
</data>
1809-
<data name="HighDpiOverride_SystemAdvanced" xml:space="preserve">
1810-
<value>System (advanced)</value>
1809+
<data name="CompatibilitySystemEnhanced" xml:space="preserve">
1810+
<value>System (Enhanced)</value>
18111811
</data>
1812-
<data name="OSCompatibility_Windows7" xml:space="preserve">
1813-
<value>Windows 7</value>
1812+
<data name="CompatibilityReducedColorModeColor16bit" xml:space="preserve">
1813+
<value>16-bit (65536) color</value>
18141814
</data>
1815-
<data name="OSCompatibility_Windows8" xml:space="preserve">
1816-
<value>Windows 8</value>
1815+
<data name="CompatibilityReducedColorModeColor8bit" xml:space="preserve">
1816+
<value>8-bit (256) color</value>
18171817
</data>
1818-
<data name="OSCompatibility_WindowsVista" xml:space="preserve">
1819-
<value>Windows Vista</value>
1818+
<data name="CompatibilityDisableFullscreenOptimizations" xml:space="preserve">
1819+
<value>Disable full-screen optimizations</value>
18201820
</data>
1821-
<data name="OSCompatibility_WindowsVistaSP1" xml:space="preserve">
1822-
<value>Windows Vista SP1</value>
1821+
<data name="CompatibilityRunIn640x480Resolution" xml:space="preserve">
1822+
<value>Run in 640 x 480 screen resolution</value>
18231823
</data>
1824-
<data name="OSCompatibility_WindowsVistaSP2" xml:space="preserve">
1825-
<value>Windows Vista SP2</value>
1824+
<data name="CompatibilityOverrideHighDPIBehavior" xml:space="preserve">
1825+
<value>Override high DPI scaling behavior</value>
18261826
</data>
1827-
<data name="ReducedColorMode_Color16Bit" xml:space="preserve">
1828-
<value>16 Bit Colors (65536)</value>
1829-
</data>
1830-
<data name="ReducedColorMode_Color8Bit" xml:space="preserve">
1831-
<value>8 Bit Colors (256)</value>
1832-
</data>
1833-
<data name="CompatibilityMode" xml:space="preserve">
1834-
<value>Compatibility mode</value>
1835-
</data>
1836-
<data name="DisableFullscreenOptimizations" xml:space="preserve">
1837-
<value>Disable fullscreen optimizations</value>
1838-
</data>
1839-
<data name="ExecuteAt640X480" xml:space="preserve">
1840-
<value>Run at 640 x 480 screen resolution</value>
1841-
</data>
1842-
<data name="OverrideDPIScalingBehaviour" xml:space="preserve">
1843-
<value>Override high DPI scaling behaviour</value>
1844-
</data>
1845-
<data name="ReducedColorMode" xml:space="preserve">
1827+
<data name="CompatibilityReducedColorMode" xml:space="preserve">
18461828
<value>Reduced color mode</value>
18471829
</data>
1848-
<data name="RegisterForRestart" xml:space="preserve">
1849-
<value>Register for restart</value>
1830+
<data name="CompatibilityRegisterThisProgramForRestart" xml:space="preserve">
1831+
<value>Register this program for restart</value>
18501832
</data>
18511833
<data name="RunAsAdministrator" xml:space="preserve">
18521834
<value>Run as administrator</value>
18531835
</data>
1854-
<data name="RunCompatibilityTroubleShooter" xml:space="preserve">
1836+
<data name="CompatibilityRunTroubleshooter" xml:space="preserve">
18551837
<value>Run compatibility troubleshooter</value>
18561838
</data>
1857-
<data name="UseMainMonitorDPISettings" xml:space="preserve">
1839+
<data name="CompatibilityUseDPISettings" xml:space="preserve">
18581840
<value>Use DPI settings of the main monitor</value>
18591841
</data>
1842+
<data name="CompatibilityDoNotAdjustDPI" xml:space="preserve">
1843+
<value>Do not adjust DPI</value>
1844+
</data>
1845+
<data name="CompatibilityDoNotOverrideDPI" xml:space="preserve">
1846+
<value>Do not override DPI</value>
1847+
</data>
1848+
<data name="CompatibilityMode" xml:space="preserve">
1849+
<value>Compatibility mode</value>
1850+
</data>
1851+
<data name="CompatibilityNoReducedColor" xml:space="preserve">
1852+
<value>No reduced color</value>
1853+
</data>
18601854
<data name="ThirdPartyLicenses" xml:space="preserve">
18611855
<value>Third party licenses</value>
18621856
</data>
@@ -3722,4 +3716,4 @@
37223716
<value>Extra large</value>
37233717
<comment>Used to describe layout sizes</comment>
37243718
</data>
3725-
</root>
3719+
</root>

src/Files.App/Utils/Storage/Operations/FileOperationsHelpers.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -816,27 +816,6 @@ public static bool SetLinkIcon(string filePath, string iconFile, int iconIndex)
816816
});
817817
}
818818

819-
public static string? ReadCompatOptions(string filePath)
820-
=> SafetyExtensions.IgnoreExceptions(() =>
821-
{
822-
using var compatKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers");
823-
if (compatKey is null)
824-
{
825-
return null;
826-
}
827-
return (string?)compatKey.GetValue(filePath, null);
828-
}, App.Logger);
829-
830-
public static bool SetCompatOptions(string filePath, string options)
831-
{
832-
if (string.IsNullOrEmpty(options) || options == "~")
833-
{
834-
return Win32API.RunPowershellCommand(@$"Remove-ItemProperty -Path 'HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers' -Name '{filePath}' | Out-Null", true);
835-
}
836-
837-
return Win32API.RunPowershellCommand(@$"New-ItemProperty -Path 'HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers' -Name '{filePath}' -Value '{options}' -PropertyType String -Force | Out-Null", true);
838-
}
839-
840819
private static ShellItem? GetFirstFile(ShellItem shi)
841820
{
842821
if (!shi.IsFolder || shi.Attributes.HasFlag(ShellItemAttribute.Stream))

0 commit comments

Comments
 (0)