[SETUPLIB][USETUP] Move IsValidPath() back into setuplib for reusability (#7186)

Reverts the IsValidPath() move done in commit 9c64b57dc.

- Turn IsValidPath() into a IsValidInstallDirectory() helper function
  available in the setuplib, so that it can also be used in the GUI setup.

- Introduce a IS_VALID_INSTALL_PATH_CHAR() macro.
This commit is contained in:
Hermès Bélusca-Maïto 2024-07-25 18:57:23 +02:00
parent a532a68d40
commit 785cc21598
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
3 changed files with 58 additions and 49 deletions

View file

@ -712,6 +712,51 @@ InitSystemPartition(
return TRUE;
}
BOOLEAN
IsValidInstallDirectory(
_In_ PCWSTR InstallDir)
{
UINT i, Length;
Length = wcslen(InstallDir);
// TODO: Add check for 8.3 too.
/* Path must be at least 2 characters long */
// if (Length < 2)
// return FALSE;
/* Path must start with a backslash */
// if (InstallDir[0] != L'\\')
// return FALSE;
/* Path must not end with a backslash */
if (InstallDir[Length - 1] == L'\\')
return FALSE;
/* Path must not contain whitespace characters */
for (i = 0; i < Length; i++)
{
if (iswspace(InstallDir[i]))
return FALSE;
}
/* Path component must not end with a dot */
for (i = 0; i < Length; i++)
{
if (InstallDir[i] == L'\\' && i > 0)
{
if (InstallDir[i - 1] == L'.')
return FALSE;
}
}
if (InstallDir[Length - 1] == L'.')
return FALSE;
return TRUE;
}
NTSTATUS
InitDestinationPaths(
IN OUT PUSETUP_DATA pSetupData,