From 95be49b49ce9c926685bfc4b94a5a5268b2f13b4 Mon Sep 17 00:00:00 2001 From: RD42 <42702181+dashr9230@users.noreply.github.com> Date: Sun, 12 May 2024 22:51:13 +0800 Subject: [PATCH] [saco] Implement and match `DXUTFindMediaSearchParentDirs(...)` --- saco/d3d9/common/DXUTmisc.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/saco/d3d9/common/DXUTmisc.cpp b/saco/d3d9/common/DXUTmisc.cpp index f00e0e5..7d3f8aa 100644 --- a/saco/d3d9/common/DXUTmisc.cpp +++ b/saco/d3d9/common/DXUTmisc.cpp @@ -289,3 +289,35 @@ bool DXUTFindMediaSearchTypicalDirs( TCHAR* strSearchPath, int cchSearch, LPCTST +//-------------------------------------------------------------------------------------- +// Search parent directories starting at strStartAt, and appending strLeafName +// at each parent directory. It stops at the root directory. +//-------------------------------------------------------------------------------------- +bool DXUTFindMediaSearchParentDirs( TCHAR* strSearchPath, int cchSearch, TCHAR* strStartAt, TCHAR* strLeafName ) +{ + TCHAR strFullPath[MAX_PATH] = {0}; + TCHAR strFullFileName[MAX_PATH] = {0}; + TCHAR strSearch[MAX_PATH] = {0}; + TCHAR* strFilePart = NULL; + + GetFullPathName( strStartAt, MAX_PATH, strFullPath, &strFilePart ); + if( strFilePart == NULL ) + return false; + + while( strFilePart != NULL && *strFilePart != '\0' ) + { + StringCchPrintf( strFullFileName, MAX_PATH, "%s\\%s", strFullPath, strLeafName ); + if( GetFileAttributes( strFullFileName ) != 0xFFFFFFFF ) + { + StringCchCopy( strSearchPath, cchSearch, strFullFileName ); + return true; + } + + StringCchPrintf( strSearch, MAX_PATH, "%s\\..", strFullPath ); + GetFullPathName( strSearch, MAX_PATH, strFullPath, &strFilePart ); + } + + return false; +} + +