-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Clean up some code in ANCM #49718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean up some code in ANCM #49718
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,30 +11,23 @@ | |
HRESULT | ||
FILE_UTILITY::IsPathUnc( | ||
__in LPCWSTR pszPath, | ||
__out BOOL * pfIsUnc | ||
__out bool* pfIsUnc | ||
) | ||
{ | ||
HRESULT hr = S_OK; | ||
STRU strTempPath; | ||
|
||
if ( pszPath == NULL || pfIsUnc == NULL ) | ||
if (pszPath == nullptr || pfIsUnc == nullptr) | ||
{ | ||
hr = E_INVALIDARG; | ||
goto Finished; | ||
return E_INVALIDARG; | ||
} | ||
|
||
hr = MakePathCanonicalizationProof( (LPWSTR) pszPath, &strTempPath ); | ||
if ( FAILED(hr) ) | ||
STRU strTempPath; | ||
HRESULT hr = MakePathCanonicalizationProof(pszPath, &strTempPath ); | ||
if (FAILED(hr)) | ||
{ | ||
goto Finished; | ||
return hr; | ||
} | ||
|
||
// | ||
// MakePathCanonicalizationProof will map \\?\UNC, \\.\UNC and \\ to \\?\UNC | ||
// | ||
(*pfIsUnc) = ( _wcsnicmp( strTempPath.QueryStr(), L"\\\\?\\UNC\\", 8 /* sizeof \\?\UNC\ */) == 0 ); | ||
|
||
Finished: | ||
// MakePathCanonicalizationProof will map \\?\UNC, \\.\UNC and \\ to \\?\UNC (which is 8 characters) | ||
*pfIsUnc = (_wcsnicmp(strTempPath.QueryStr(), L"\\\\?\\UNC\\", 8) == 0); | ||
|
||
return hr; | ||
} | ||
|
@@ -103,69 +96,57 @@ FILE_UTILITY::ConvertPathToFullPath( | |
return hr; | ||
} | ||
|
||
// Ensures that the specified directory path exists, creating it if necessary. If any part of the directory | ||
// creation fails and the directory does not already exist, it returns an error obtained from GetLastError. | ||
// If all directories are successfully created or already exist, it returns S_OK. | ||
HRESULT | ||
FILE_UTILITY::EnsureDirectoryPathExist( | ||
_In_ LPCWSTR pszPath | ||
FILE_UTILITY::EnsureDirectoryPathExists( | ||
_In_ const LPCWSTR pszPath | ||
) | ||
{ | ||
HRESULT hr = S_OK; | ||
STRU struPath; | ||
DWORD dwPosition = 0; | ||
BOOL fDone = FALSE; | ||
BOOL fUnc = FALSE; | ||
|
||
STRU struPath; | ||
struPath.Copy(pszPath); | ||
hr = IsPathUnc(pszPath, &fUnc); | ||
|
||
bool isUnc = false; | ||
HRESULT hr = IsPathUnc(pszPath, &isUnc); | ||
if (FAILED(hr)) | ||
{ | ||
goto Finished; | ||
} | ||
if (fUnc) | ||
{ | ||
// "\\?\UNC\" | ||
dwPosition = 8; | ||
return hr; | ||
} | ||
else if (struPath.IndexOf(L'?', 0) != -1) | ||
{ | ||
// sceanrio "\\?\" | ||
dwPosition = 4; | ||
} | ||
while (!fDone) | ||
|
||
// Initialize position based on the type of the path. | ||
DWORD position = isUnc ? 8 // Skip "\\?\UNC\" | ||
: (struPath.IndexOf(L'?', 0) != -1) ? 4 // Skip "\\?\" | ||
: 0; // Skip nothing | ||
|
||
// Traverse the path string, creating directories as we go. | ||
while (true) | ||
{ | ||
dwPosition = struPath.IndexOf(L'\\', dwPosition + 1); | ||
if (dwPosition == -1) | ||
{ | ||
// not found '/' | ||
fDone = TRUE; | ||
goto Finished; | ||
} | ||
else if (dwPosition ==0) | ||
position = struPath.IndexOf(L'\\', position + 1); | ||
if (position == -1) | ||
{ | ||
hr = ERROR_INTERNAL_ERROR; | ||
goto Finished; | ||
// Didn't find a path separator, so we're done. | ||
return S_OK; | ||
} | ||
else if (struPath.QueryStr()[dwPosition-1] == L':') | ||
|
||
// position is >= 1 here since we started searching at position + 1 | ||
if (struPath.QueryStr()[position - 1] == L':') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You removed the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed it because it can never be 0. Can it? Even in the case where we start at 0, the STRU::IndexOf is given the start offset of position+1 to search from, and it will either return -1 (if not found) or a position >=1. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I guess. Probably add a comment then since it wasn't obvious from first glance |
||
{ | ||
// skip volume case | ||
// Skip the volume case | ||
continue; | ||
} | ||
else | ||
{ | ||
struPath.QueryStr()[dwPosition] = L'\0'; | ||
} | ||
|
||
if (!CreateDirectory(struPath.QueryStr(), NULL) && | ||
ERROR_ALREADY_EXISTS != GetLastError()) | ||
// Temporarily terminate the string at the current path separator | ||
struPath.QueryStr()[position] = L'\0'; | ||
if (!CreateDirectory(struPath.QueryStr(), nullptr) && GetLastError() != ERROR_ALREADY_EXISTS) | ||
{ | ||
hr = HRESULT_FROM_WIN32(GetLastError()); | ||
fDone = TRUE; | ||
goto Finished; | ||
// Unable to create directory and it doesn't already exist | ||
return HRESULT_FROM_WIN32(GetLastError()); | ||
} | ||
struPath.QueryStr()[dwPosition] = L'\\'; | ||
} | ||
|
||
Finished: | ||
return hr; | ||
// Restore the path separator | ||
struPath.QueryStr()[position] = L'\\'; | ||
} | ||
} | ||
|
||
std::string FILE_UTILITY::GetHtml(HMODULE module, int page, USHORT statusCode, USHORT subStatusCode, const std::string& specificReasonPhrase, const std::string& solution) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to change the header and caller
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I used the VS refactor thing and forgot to save the other modified files 😆