From cb64917bab3633fe301ec13d4c438df0d9188d36 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Mon, 22 Jul 2024 12:02:38 -0400 Subject: [PATCH 1/5] Code Quality: Fallback to "C:\" if var doesn't work --- src/Files.App/Constants.cs | 2 ++ src/Files.App/Data/Items/DriveItem.cs | 2 +- src/Files.App/Services/Storage/StorageDevicesService.cs | 2 +- src/Files.App/Utils/Cloud/Detector/LucidLinkCloudDetector.cs | 2 +- src/Files.App/Utils/Shell/ContextMenu.cs | 2 +- src/Files.App/Utils/Storage/Helpers/StorageSenseHelper.cs | 2 +- .../ViewModels/Dialogs/CreateShortcutDialogViewModel.cs | 2 +- src/Files.App/ViewModels/Properties/BasePropertiesPage.cs | 2 +- 8 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Files.App/Constants.cs b/src/Files.App/Constants.cs index 46e4325eeea5..d0fc071ee596 100644 --- a/src/Files.App/Constants.cs +++ b/src/Files.App/Constants.cs @@ -234,6 +234,8 @@ public static class UserEnvironmentPaths public static readonly string TempPath = Environment.GetEnvironmentVariable("TEMP") ?? ""; + public static readonly string SystemDrivePath = $@"{Constants.UserEnvironmentPaths.SystemDrivePath}\" ?? @"C:\"; + public static readonly string HomePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); public static readonly string SystemRootPath = Environment.GetFolderPath(Environment.SpecialFolder.Windows); diff --git a/src/Files.App/Data/Items/DriveItem.cs b/src/Files.App/Data/Items/DriveItem.cs index 342597d87ca2..25e5a840bc38 100644 --- a/src/Files.App/Data/Items/DriveItem.cs +++ b/src/Files.App/Data/Items/DriveItem.cs @@ -239,7 +239,7 @@ public static async Task CreateFromPropertiesAsync(StorageFolder root IsLocationItem = true, ShowEjectDevice = item.IsRemovable, ShowShellItems = true, - ShowFormatDrive = !(item.Type == DriveType.Network || string.Equals(root.Path, $@"{Environment.GetEnvironmentVariable("SystemDrive")}\", StringComparison.OrdinalIgnoreCase)), + ShowFormatDrive = !(item.Type == DriveType.Network || string.Equals(root.Path, $@"{Constants.UserEnvironmentPaths.SystemDrivePath}\", StringComparison.OrdinalIgnoreCase)), ShowProperties = true }; item.Path = string.IsNullOrEmpty(root.Path) ? $"\\\\?\\{root.Name}\\" : root.Path; diff --git a/src/Files.App/Services/Storage/StorageDevicesService.cs b/src/Files.App/Services/Storage/StorageDevicesService.cs index a8b355b143ec..e415b0a9fb09 100644 --- a/src/Files.App/Services/Storage/StorageDevicesService.cs +++ b/src/Files.App/Services/Storage/StorageDevicesService.cs @@ -55,7 +55,7 @@ public async IAsyncEnumerable GetDrivesAsync() public async Task GetPrimaryDriveAsync() { - string cDrivePath = $@"{Environment.GetEnvironmentVariable("SystemDrive")}\"; + string cDrivePath = $@"{Constants.UserEnvironmentPaths.SystemDrivePath}\"; return new WindowsStorageFolder(await StorageFolder.GetFolderFromPathAsync(cDrivePath)); } diff --git a/src/Files.App/Utils/Cloud/Detector/LucidLinkCloudDetector.cs b/src/Files.App/Utils/Cloud/Detector/LucidLinkCloudDetector.cs index 49a5f83a3224..74ccb39f5dcb 100644 --- a/src/Files.App/Utils/Cloud/Detector/LucidLinkCloudDetector.cs +++ b/src/Files.App/Utils/Cloud/Detector/LucidLinkCloudDetector.cs @@ -28,7 +28,7 @@ protected override async IAsyncEnumerable GetProviders() string syncFolder = inner.GetProperty("filespaceName").GetString(); string[] orgNameFilespaceName = syncFolder.Split("."); - string path = Path.Combine($@"{Environment.GetEnvironmentVariable("SystemDrive")}\Volumes", orgNameFilespaceName[1], orgNameFilespaceName[0]); + string path = Path.Combine($@"{Constants.UserEnvironmentPaths.SystemDrivePath}\Volumes", orgNameFilespaceName[1], orgNameFilespaceName[0]); string filespaceName = orgNameFilespaceName[0]; string iconPath = Path.Combine(Environment.GetEnvironmentVariable("ProgramFiles"), "Lucid", "resources", "Logo.ico"); diff --git a/src/Files.App/Utils/Shell/ContextMenu.cs b/src/Files.App/Utils/Shell/ContextMenu.cs index 01354324a24e..dbef74c3696c 100644 --- a/src/Files.App/Utils/Shell/ContextMenu.cs +++ b/src/Files.App/Utils/Shell/ContextMenu.cs @@ -174,7 +174,7 @@ public async Task InvokeItem(int itemID) public static async Task WarmUpQueryContextMenuAsync() { - using var cMenu = await GetContextMenuForFiles(new string[] { $@"{Environment.GetEnvironmentVariable("SystemDrive")}\" }, Shell32.CMF.CMF_NORMAL); + using var cMenu = await GetContextMenuForFiles(new string[] { $@"{Constants.UserEnvironmentPaths.SystemDrivePath}\" }, Shell32.CMF.CMF_NORMAL); } private void EnumMenuItems(HMENU hMenu, List menuItemsResult, bool loadSubenus = false) diff --git a/src/Files.App/Utils/Storage/Helpers/StorageSenseHelper.cs b/src/Files.App/Utils/Storage/Helpers/StorageSenseHelper.cs index 0299f7570cba..4679ee851af2 100644 --- a/src/Files.App/Utils/Storage/Helpers/StorageSenseHelper.cs +++ b/src/Files.App/Utils/Storage/Helpers/StorageSenseHelper.cs @@ -10,7 +10,7 @@ internal sealed class StorageSenseHelper { public static async Task OpenStorageSenseAsync(string path) { - if (!path.StartsWith(Environment.GetEnvironmentVariable("SystemDrive"), StringComparison.OrdinalIgnoreCase) + if (!path.StartsWith(Constants.UserEnvironmentPaths.SystemDrivePath, StringComparison.OrdinalIgnoreCase) && ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8)) { LaunchHelper.LaunchSettings("page=SettingsPageStorageSenseStorageOverview&target=SystemSettings_StorageSense_VolumeListLink"); diff --git a/src/Files.App/ViewModels/Dialogs/CreateShortcutDialogViewModel.cs b/src/Files.App/ViewModels/Dialogs/CreateShortcutDialogViewModel.cs index 3ddfc8b8f7db..f8012b42c568 100644 --- a/src/Files.App/ViewModels/Dialogs/CreateShortcutDialogViewModel.cs +++ b/src/Files.App/ViewModels/Dialogs/CreateShortcutDialogViewModel.cs @@ -15,7 +15,7 @@ public sealed class CreateShortcutDialogViewModel : ObservableObject public readonly string WorkingDirectory; // Placeholder text of destination path textbox - public readonly string DestinationPlaceholder = $@"{Environment.GetEnvironmentVariable("SystemDrive")}\Users\"; + public readonly string DestinationPlaceholder = $@"{Constants.UserEnvironmentPaths.SystemDrivePath}\Users\"; // Tells whether destination path exists public bool DestinationPathExists { get; set; } diff --git a/src/Files.App/ViewModels/Properties/BasePropertiesPage.cs b/src/Files.App/ViewModels/Properties/BasePropertiesPage.cs index ab81ba6ece79..5524d9e5bc24 100644 --- a/src/Files.App/ViewModels/Properties/BasePropertiesPage.cs +++ b/src/Files.App/ViewModels/Properties/BasePropertiesPage.cs @@ -40,7 +40,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e) BaseProperties = props; ViewModel.CleanupVisibility = props.Drive.Type != DriveType.Network; - ViewModel.FormatVisibility = !(props.Drive.Type == DriveType.Network || string.Equals(props.Drive.Path, $@"{Environment.GetEnvironmentVariable("SystemDrive")}\", StringComparison.OrdinalIgnoreCase)); + ViewModel.FormatVisibility = !(props.Drive.Type == DriveType.Network || string.Equals(props.Drive.Path, $@"{Constants.UserEnvironmentPaths.SystemDrivePath}\", StringComparison.OrdinalIgnoreCase)); ViewModel.CleanupDriveCommand = new AsyncRelayCommand(() => StorageSenseHelper.OpenStorageSenseAsync(props.Drive.Path)); ViewModel.FormatDriveCommand = new RelayCommand(async () => { From 28ebfb9241b4898ee67bcc5016e7a1a6dac560b4 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Tue, 23 Jul 2024 01:37:00 -0400 Subject: [PATCH 2/5] Update Constants.cs --- src/Files.App/Constants.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/Constants.cs b/src/Files.App/Constants.cs index d0fc071ee596..592ebed99e8a 100644 --- a/src/Files.App/Constants.cs +++ b/src/Files.App/Constants.cs @@ -234,7 +234,7 @@ public static class UserEnvironmentPaths public static readonly string TempPath = Environment.GetEnvironmentVariable("TEMP") ?? ""; - public static readonly string SystemDrivePath = $@"{Constants.UserEnvironmentPaths.SystemDrivePath}\" ?? @"C:\"; + public static readonly string SystemDrivePath = Constants.UserEnvironmentPaths.SystemDrivePath ?? "C:"; public static readonly string HomePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); From 7041c98ff404e7fb809b89a1e14b2faff202c2f8 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Tue, 23 Jul 2024 01:37:34 -0400 Subject: [PATCH 3/5] Update Constants.cs --- src/Files.App/Constants.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/Constants.cs b/src/Files.App/Constants.cs index 592ebed99e8a..021d3658cffa 100644 --- a/src/Files.App/Constants.cs +++ b/src/Files.App/Constants.cs @@ -234,7 +234,7 @@ public static class UserEnvironmentPaths public static readonly string TempPath = Environment.GetEnvironmentVariable("TEMP") ?? ""; - public static readonly string SystemDrivePath = Constants.UserEnvironmentPaths.SystemDrivePath ?? "C:"; + public static readonly string SystemDrivePath = Environment.GetEnvironmentVariable("SystemDrive") ?? "C:"; public static readonly string HomePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); From 8512bc47c239528a7bf1d6f59148cafb75fb489e Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Tue, 23 Jul 2024 12:07:24 -0400 Subject: [PATCH 4/5] Update Constants.cs --- src/Files.App/Constants.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Files.App/Constants.cs b/src/Files.App/Constants.cs index 021d3658cffa..35eeba0bc86b 100644 --- a/src/Files.App/Constants.cs +++ b/src/Files.App/Constants.cs @@ -234,14 +234,21 @@ public static class UserEnvironmentPaths public static readonly string TempPath = Environment.GetEnvironmentVariable("TEMP") ?? ""; - public static readonly string SystemDrivePath = Environment.GetEnvironmentVariable("SystemDrive") ?? "C:"; - public static readonly string HomePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); public static readonly string SystemRootPath = Environment.GetFolderPath(Environment.SpecialFolder.Windows); public static readonly string RecentItemsPath = Environment.GetFolderPath(Environment.SpecialFolder.Recent); + public static string SystemDrivePath + { + get + { + var systemDrive = Environment.GetEnvironmentVariable("SystemDrive"); + return !string.IsNullOrEmpty(systemDrive) ? systemDrive : "C:"; + } + } + public static Dictionary ShellPlaces = new() { From fcd7483511523bae8dcdd738b9ad355bb15b7600 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Tue, 23 Jul 2024 20:00:16 -0400 Subject: [PATCH 5/5] Update src/Files.App/Constants.cs Co-authored-by: hishitetsu <66369541+hishitetsu@users.noreply.github.com> --- src/Files.App/Constants.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Files.App/Constants.cs b/src/Files.App/Constants.cs index 35eeba0bc86b..eb71b9366eb5 100644 --- a/src/Files.App/Constants.cs +++ b/src/Files.App/Constants.cs @@ -240,13 +240,12 @@ public static class UserEnvironmentPaths public static readonly string RecentItemsPath = Environment.GetFolderPath(Environment.SpecialFolder.Recent); - public static string SystemDrivePath + public static readonly string SystemDrivePath; + + static UserEnvironmentPaths() { - get - { - var systemDrive = Environment.GetEnvironmentVariable("SystemDrive"); - return !string.IsNullOrEmpty(systemDrive) ? systemDrive : "C:"; - } + var systemDrive = Environment.GetEnvironmentVariable("SystemDrive"); + SystemDrivePath = !string.IsNullOrEmpty(systemDrive) ? systemDrive : "C:"; } public static Dictionary ShellPlaces =