@@ -782,7 +782,9 @@ ReadDirLevel(
782782 iNode , dwAttribs , bFullyExpand , szAutoExpand , bPartialSort );
783783 }
784784
785- while (bFound ) {
785+
786+ BOOL bCasePreserved = IsCasePreservedDrive (DRIVEID (szPath ));
787+ while (bFound ) {
786788
787789 if (uYieldCount & (1 <<READDIRLEVEL_YIELDBIT ))
788790 {
@@ -824,7 +826,7 @@ ReadDirLevel(
824826 iParentNode ,
825827 lfndta .fd .cFileName ,
826828 & pNode ,
827- IsCasePreservedDrive ( DRIVEID ( szPath )),
829+ bCasePreserved ,
828830 bPartialSort ,
829831 lfndta .fd .dwFileAttributes );
830832
@@ -1149,7 +1151,13 @@ FillTreeListbox(HWND hwndTC,
11491151 if (bDontSteal || bFullyExpand || !StealTreeData (hwndTC , hwndLB , szDefaultDir )) {
11501152
11511153 drive = DRIVEID (szDefaultDir );
1152- DRIVESET (szTemp , drive );
1154+
1155+ if (drive < OFFSET_UNC ) {
1156+ DRIVESET (szTemp , drive );
1157+ } else {
1158+ lstrcpy (szTemp , aDriveInfo [drive ].szRoot );
1159+ AddBackslash (szTemp );
1160+ }
11531161
11541162 //
11551163 // Hack: if NTFS/HPFS are partially sorted already
@@ -1177,10 +1185,20 @@ FillTreeListbox(HWND hwndTC,
11771185
11781186 if (szDefaultDir ) {
11791187
1180- lstrcpy (szExpand , szDefaultDir + 3 ); // skip "X:\"
1188+ if (drive < OFFSET_UNC )
1189+ // skip "X:\" at the beginning
1190+ lstrcpy (szExpand , szDefaultDir + 3 );
1191+ else {
1192+ // skip the UNC Root + backslash, which is e.g \\myserver\path
1193+ if (_wcsicmp (szDefaultDir , aDriveInfo [drive ].szRoot ))
1194+ lstrcpy (szExpand , szDefaultDir + lstrlen (aDriveInfo [drive ].szRoot ) + 1 );
1195+ else
1196+ * szExpand = CHAR_NULL ;
1197+ }
1198+
11811199 p = szExpand ;
11821200
1183- while (* p ) { // null out all slashes
1201+ while (* p ) { // null out all slashes of a path
11841202
11851203 while (* p && * p != CHAR_BACKSLASH )
11861204 ++ p ;
@@ -1284,6 +1302,47 @@ FillOutTreeList(HWND hwndTC,
12841302}
12851303
12861304
1305+
1306+ //
1307+ // MatchNode()
1308+ //
1309+ // Find the PDNODE and LBIndex for a path element
1310+ //
1311+ // returns:
1312+ // TRUE if found match; FALSE if out of items
1313+ //
1314+ BOOL MatchNode (
1315+ HWND hwndLB ,
1316+ LPTSTR lpszElement ,
1317+ DWORD * dwIndex ,
1318+ DWORD * dwPreviousNode ,
1319+ PDNODE * ppPreviousNode
1320+ )
1321+ {
1322+ PDNODE pNode ;
1323+ BOOL bReturn = TRUE;
1324+
1325+ while (TRUE) {
1326+ // Out of LB items? Not found.
1327+ if (SendMessage (hwndLB , LB_GETTEXT , * dwIndex , (LPARAM )& pNode ) == LB_ERR ) {
1328+ bReturn = FALSE;
1329+ break ;
1330+ }
1331+
1332+ if (pNode -> pParent == * ppPreviousNode ) {
1333+ if (!lstrcmpi (lpszElement , pNode -> szName )) {
1334+ // We've found the element, but we are not at the end of the path
1335+ * dwPreviousNode = * dwIndex ;
1336+ * ppPreviousNode = pNode ;
1337+ break ;
1338+ }
1339+ }
1340+ (* dwIndex )++ ;
1341+ }
1342+
1343+ return bReturn ;
1344+ }
1345+
12871346//
12881347// FindItemFromPath()
12891348//
@@ -1309,106 +1368,95 @@ FindItemFromPath(
13091368 DWORD * pIndex ,
13101369 PDNODE * ppNode )
13111370{
1312- register DWORD i ;
1313- register LPTSTR p ;
1314- PDNODE pNode ;
1315- DWORD iPreviousNode ;
1316- PDNODE pPreviousNode ;
1317- TCHAR szElement [1 + MAXFILENAMELEN + 1 ];
1318-
1319- if (pIndex ) {
1320- * pIndex = (DWORD )- 1 ;
1321- }
1322- if (ppNode ) {
1323- * ppNode = NULL ;
1324- }
1325-
1326- if (!lpszPath || lstrlen (lpszPath ) < 3 || lpszPath [1 ] != CHAR_COLON ) {
1327- return FALSE;
1328- }
1329-
1330- i = 0 ;
1331- iPreviousNode = (DWORD )- 1 ;
1332- pPreviousNode = NULL ;
1371+ DWORD dwIndex ;
1372+ LPTSTR p ;
1373+ PDNODE pNode ;
1374+ DWORD iPreviousNode ;
1375+ PDNODE pPreviousNode ;
1376+ TCHAR szElement [1 + MAXFILENAMELEN + 1 ];
1377+ BOOL bReturn = TRUE;
13331378
1334- while ( * lpszPath )
1335- {
1336- /* NULL out szElement[1] so the backslash hack isn't repeated with
1337- * a first level directory of length 1.
1338- */
1339- szElement [ 1 ] = CHAR_NULL ;
1379+ if ( pIndex ) {
1380+ * pIndex = ( DWORD ) - 1 ;
1381+ }
1382+ if ( ppNode ) {
1383+ * ppNode = NULL ;
1384+ }
13401385
1341- /* Copy the next section of the path into 'szElement' */
1342- p = szElement ;
1386+ if (!lpszPath || lstrlen (lpszPath ) < 3 || !((lpszPath [1 ] == CHAR_COLON ) || lpszPath [1 ] == CHAR_BACKSLASH )) {
1387+ return FALSE;
1388+ }
13431389
1344- while (* lpszPath && * lpszPath != CHAR_BACKSLASH )
1345- * p ++ = * lpszPath ++ ;
1390+ dwIndex = 0 ;
1391+ iPreviousNode = (DWORD )- 1 ;
1392+ pPreviousNode = NULL ;
13461393
1347- /* Add a backslash for the Root directory. */
1394+ // Retrieve the name of the root, which is always on index 0
1395+ if (SendMessage (hwndLB , LB_GETTEXT , 0 , (LPARAM )& pNode ) != LB_ERR ) {
13481396
1349- if (szElement [1 ] == CHAR_COLON )
1350- * p ++ = CHAR_BACKSLASH ;
1397+ // Is the root node a subnode of lpszPath
1398+ if (wcsstr (lpszPath , pNode -> szName )) {
1399+ lstrcpy (szElement , pNode -> szName );
1400+ // move lpszPath at the end of the
1401+ lpszPath += lstrlen (szElement );
13511402
1352- /* NULL terminate 'szElement' */
1353- * p = CHAR_NULL ;
1403+ do {
1404+ bReturn = MatchNode (hwndLB , szElement , & dwIndex , & iPreviousNode , & pPreviousNode );
1405+
1406+ /* NULL out szElement[1] so the backslash hack isn't repeated with
1407+ * a first level directory of length 1.
1408+ */
1409+ szElement [1 ] = CHAR_NULL ;
1410+
1411+ // Copy the next section of the path into 'szElement' and terminate it
1412+ p = szElement ;
1413+ while (* lpszPath && * lpszPath != CHAR_BACKSLASH )
1414+ * p ++ = * lpszPath ++ ;
1415+ * p = CHAR_NULL ;
1416+
1417+ // Skip over the path's next Backslash.
1418+ if (* lpszPath )
1419+ lpszPath ++ ;
1420+ else
1421+ if (bReturnParent ) {
1422+ /* We're at the end of a path which includes a filename. Return
1423+ * the previously found parent.
1424+ */
1425+ if (pIndex ) {
1426+ * pIndex = iPreviousNode ;
1427+ }
1428+ if (ppNode ) {
1429+ * ppNode = pPreviousNode ;
1430+ }
1431+ return TRUE;
1432+ }
13541433
1355- /* Skip over the path's next Backslash. */
1434+ // Break through the loops
1435+ if (!bReturn )
1436+ break ;
13561437
1357- if (* lpszPath )
1358- lpszPath ++ ;
1438+ } while (* lpszPath );
13591439
1360- else if (bReturnParent )
1361- {
1362- /* We're at the end of a path which includes a filename. Return
1363- * the previously found parent.
1364- */
1365- if (pIndex ) {
1366- * pIndex = iPreviousNode ;
1367- }
1368- if (ppNode ) {
1369- * ppNode = pPreviousNode ;
1370- }
1371- return TRUE;
1372- }
1440+ bReturn = MatchNode (hwndLB , szElement , & dwIndex , & iPreviousNode , & pPreviousNode );
1441+ }
1442+ else
1443+ // e.g. drive change, when root node is different than lpszPath
1444+ bReturn = FALSE;
1445+ }
1446+ else
1447+ // uuups no root node. We should never get there
1448+ bReturn = FALSE;
13731449
1374- while (TRUE)
1375- {
1376- /* Out of LB items? Not found. */
1377- if (SendMessage (hwndLB , LB_GETTEXT , i , (LPARAM )& pNode ) == LB_ERR )
1378- {
1379- if (pIndex ) {
1380- * pIndex = iPreviousNode ;
1381- }
1382- if (ppNode ) {
1383- * ppNode = pPreviousNode ;
1384- }
1385- return FALSE;
1386- }
1387-
1388- if (pNode -> pParent == pPreviousNode )
1389- {
1390- if (!lstrcmpi (szElement , pNode -> szName ))
1391- {
1392- /* We've found the element... */
1393- iPreviousNode = i ;
1394- pPreviousNode = pNode ;
1395- break ;
1396- }
1397- }
1398- i ++ ;
1399- }
1400- }
1401- if (pIndex ) {
1402- * pIndex = iPreviousNode ;
1403- }
1404- if (ppNode ) {
1450+ if (pIndex ) {
1451+ * pIndex = iPreviousNode ;
1452+ }
1453+ if (ppNode ) {
14051454 * ppNode = pPreviousNode ;
1406- }
1455+ }
14071456
1408- return TRUE ;
1457+ return bReturn ;
14091458}
14101459
1411-
14121460/*--------------------------------------------------------------------------*/
14131461/* */
14141462/* RectTreeItem() - */
@@ -2264,7 +2312,7 @@ TreeControlWndProc(
22642312
22652313 CharUpperBuff (szPath , 1 ); // make sure
22662314
2267- SetWindowLongPtr (hwndParent , GWL_TYPE , szPath [ 0 ] - TEXT ( 'A' ));
2315+ SetWindowLongPtr (hwndParent , GWL_TYPE , DRIVEID ( szPath ));
22682316
22692317 //
22702318 // resize for new vol label
@@ -3228,11 +3276,11 @@ TreeControlWndProc(
32283276INT
32293277BuildTreeName (LPTSTR lpszPath , INT iLen , INT iSize )
32303278{
3231- DRIVE drive = DRIVEID (lpszPath );
3232-
32333279 if (3 != iLen || CHAR_BACKSLASH != lpszPath [2 ])
32343280 return iLen ;
32353281
3282+ DRIVE drive = DRIVEID (lpszPath );
3283+
32363284 lstrcat (lpszPath , SZ_FILESYSNAMESEP );
32373285 iLen = lstrlen (lpszPath );
32383286
0 commit comments