Skip to content

Commit 38fe3fb

Browse files
authored
Code Quality: Use %SYSTEMDRIVE% environment variable instead of C: (#15805)
1 parent 9165920 commit 38fe3fb

File tree

12 files changed

+25
-16
lines changed

12 files changed

+25
-16
lines changed

src/Files.App.Launcher/FilesLauncher.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
6565
LocalFree(szArglist);
6666

6767
WCHAR szBuf[MAX_PATH];
68-
ExpandEnvironmentStrings(L"%LOCALAPPDATA%\\Microsoft\\WindowsApps\\files.exe", szBuf, MAX_PATH - 1);
68+
ExpandEnvironmentStringsW(L"%LOCALAPPDATA%\\Microsoft\\WindowsApps\\files.exe", szBuf, MAX_PATH - 1);
6969
std::wcout << szBuf << std::endl;
7070
if (_waccess(szBuf, 0) == -1)
7171
{

src/Files.App.OpenDialog/FilesOpenDialog.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ using std::endl;
2121

2222
CComPtr<IFileOpenDialog> GetSystemDialog()
2323
{
24-
HINSTANCE lib = CoLoadLibrary(L"C:\\Windows\\System32\\comdlg32.dll", false);
24+
WCHAR comdlg32Path[MAX_PATH];
25+
ExpandEnvironmentStringsW(L"%WINDIR%\\System32\\comdlg32.dll", comdlg32Path, MAX_PATH - 1);
26+
27+
HINSTANCE lib = CoLoadLibrary(comdlg32Path, false);
2528
BOOL(WINAPI* dllGetClassObject)(REFCLSID, REFIID, LPVOID*) =
2629
(BOOL(WINAPI*)(REFCLSID, REFIID, LPVOID*))GetProcAddress(lib, "DllGetClassObject");
2730
CComPtr<IClassFactory> pClassFactory;
@@ -159,7 +162,7 @@ STDAPICALL CFilesOpenDialog::Show(HWND hwndOwner)
159162
PWSTR pszPath = NULL;
160163
WCHAR szBuf[MAX_PATH];
161164
TCHAR args[1024] = { 0 };
162-
ExpandEnvironmentStrings(L"%LOCALAPPDATA%\\Microsoft\\WindowsApps\\files.exe", szBuf, MAX_PATH - 1);
165+
ExpandEnvironmentStringsW(L"%LOCALAPPDATA%\\Microsoft\\WindowsApps\\files.exe", szBuf, MAX_PATH - 1);
163166

164167
HANDLE closeEvent = CreateEvent(NULL, FALSE, FALSE, TEXT("FILEDIALOG"));
165168

src/Files.App.SaveDialog/FilesSaveDialog.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ using std::endl;
2020

2121
CComPtr<IFileSaveDialog> GetSystemDialog()
2222
{
23-
HINSTANCE lib = CoLoadLibrary(L"C:\\Windows\\System32\\comdlg32.dll", false);
23+
WCHAR comdlg32Path[MAX_PATH];
24+
ExpandEnvironmentStringsW(L"%WINDIR%\\System32\\comdlg32.dll", comdlg32Path, MAX_PATH - 1);
25+
26+
HINSTANCE lib = CoLoadLibrary(comdlg32Path, false);
2427
BOOL(WINAPI* dllGetClassObject)(REFCLSID, REFIID, LPVOID*) =
2528
(BOOL(WINAPI*)(REFCLSID, REFIID, LPVOID*))GetProcAddress(lib, "DllGetClassObject");
2629
CComPtr<IClassFactory> pClassFactory;
@@ -435,7 +438,7 @@ HRESULT __stdcall CFilesSaveDialog::Show(HWND hwndOwner)
435438
PWSTR pszPath = NULL;
436439
WCHAR szBuf[MAX_PATH];
437440
TCHAR args[1024] = { 0 };
438-
ExpandEnvironmentStrings(L"%LOCALAPPDATA%\\Microsoft\\WindowsApps\\files.exe", szBuf, MAX_PATH - 1);
441+
ExpandEnvironmentStringsW(L"%LOCALAPPDATA%\\Microsoft\\WindowsApps\\files.exe", szBuf, MAX_PATH - 1);
439442

440443
HANDLE closeEvent = CreateEvent(NULL, FALSE, FALSE, TEXT("FILEDIALOG"));
441444

src/Files.App/Data/Items/DriveItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public static async Task<DriveItem> CreateFromPropertiesAsync(StorageFolder root
239239
IsLocationItem = true,
240240
ShowEjectDevice = item.IsRemovable,
241241
ShowShellItems = true,
242-
ShowFormatDrive = !(item.Type == DriveType.Network || string.Equals(root.Path, "C:\\", StringComparison.OrdinalIgnoreCase)),
242+
ShowFormatDrive = !(item.Type == DriveType.Network || string.Equals(root.Path, $@"{Environment.GetEnvironmentVariable("SystemDrive")}\", StringComparison.OrdinalIgnoreCase)),
243243
ShowProperties = true
244244
};
245245
item.Path = string.IsNullOrEmpty(root.Path) ? $"\\\\?\\{root.Name}\\" : root.Path;

src/Files.App/Dialogs/CreateShortcutDialog.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
Grid.Row="2"
5151
Grid.Column="0"
5252
HorizontalAlignment="Stretch"
53-
PlaceholderText="C:\Users\"
53+
PlaceholderText="{x:Bind ViewModel.DestinationPlaceholder, Mode=OneWay}"
5454
Text="{x:Bind ViewModel.DestinationItemPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
5555
<TextBox.Resources>
5656
<TeachingTip

src/Files.App/Services/Storage/StorageDevicesService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public async IAsyncEnumerable<ILocatableFolder> GetDrivesAsync()
5555

5656
public async Task<ILocatableFolder> GetPrimaryDriveAsync()
5757
{
58-
string cDrivePath = @"C:\";
58+
string cDrivePath = $@"{Environment.GetEnvironmentVariable("SystemDrive")}\";
5959
return new WindowsStorageFolder(await StorageFolder.GetFolderFromPathAsync(cDrivePath));
6060
}
6161

src/Files.App/Utils/Cloud/Detector/LucidLinkCloudDetector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected override async IAsyncEnumerable<ICloudProvider> GetProviders()
2828
string syncFolder = inner.GetProperty("filespaceName").GetString();
2929

3030
string[] orgNameFilespaceName = syncFolder.Split(".");
31-
string path = Path.Combine(@"C:\Volumes", orgNameFilespaceName[1], orgNameFilespaceName[0]);
31+
string path = Path.Combine($@"{Environment.GetEnvironmentVariable("SystemDrive")}\Volumes", orgNameFilespaceName[1], orgNameFilespaceName[0]);
3232
string filespaceName = orgNameFilespaceName[0];
3333

3434
string iconPath = Path.Combine(Environment.GetEnvironmentVariable("ProgramFiles"), "Lucid", "resources", "Logo.ico");

src/Files.App/Utils/Shell/ContextMenu.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public async Task<bool> InvokeItem(int itemID)
174174

175175
public static async Task WarmUpQueryContextMenuAsync()
176176
{
177-
using var cMenu = await GetContextMenuForFiles(new string[] { "C:\\" }, Shell32.CMF.CMF_NORMAL);
177+
using var cMenu = await GetContextMenuForFiles(new string[] { $@"{Environment.GetEnvironmentVariable("SystemDrive")}\" }, Shell32.CMF.CMF_NORMAL);
178178
}
179179

180180
private void EnumMenuItems(HMENU hMenu, List<Win32ContextMenuItem> menuItemsResult, bool loadSubenus = false)

src/Files.App/Utils/Storage/Helpers/StorageSenseHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ internal sealed class StorageSenseHelper
1010
{
1111
public static async Task OpenStorageSenseAsync(string path)
1212
{
13-
if (!path.StartsWith("C:", StringComparison.OrdinalIgnoreCase)
13+
if (!path.StartsWith(Environment.GetEnvironmentVariable("SystemDrive"), StringComparison.OrdinalIgnoreCase)
1414
&& ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8))
1515
{
1616
LaunchHelper.LaunchSettings("page=SettingsPageStorageSenseStorageOverview&target=SystemSettings_StorageSense_VolumeListLink");

src/Files.App/ViewModels/Dialogs/CreateShortcutDialogViewModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public sealed class CreateShortcutDialogViewModel : ObservableObject
1414
// User's working directory
1515
public readonly string WorkingDirectory;
1616

17+
// Placeholder text of destination path textbox
18+
public readonly string DestinationPlaceholder = $@"{Environment.GetEnvironmentVariable("SystemDrive")}\Users\";
19+
1720
// Tells whether destination path exists
1821
public bool DestinationPathExists { get; set; }
1922

0 commit comments

Comments
 (0)