diff --git a/src/Files.App/Constants.cs b/src/Files.App/Constants.cs index 46e4325eeea5..eb71b9366eb5 100644 --- a/src/Files.App/Constants.cs +++ b/src/Files.App/Constants.cs @@ -240,6 +240,14 @@ public static class UserEnvironmentPaths public static readonly string RecentItemsPath = Environment.GetFolderPath(Environment.SpecialFolder.Recent); + public static readonly string SystemDrivePath; + + static UserEnvironmentPaths() + { + var systemDrive = Environment.GetEnvironmentVariable("SystemDrive"); + SystemDrivePath = !string.IsNullOrEmpty(systemDrive) ? systemDrive : "C:"; + } + public static Dictionary ShellPlaces = new() { 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 () => {