winefile sync with ReactOS

Martin Fuchs martin-fuchs at gmx.net
Wed Sep 22 05:50:25 CDT 2004


> You need to check that cFileName[2] == 0 too; but I'd suggest getting
> rid of the ?: operator abuse first, otherwise this is going to become
> totally unreadable.

I don't call this abuse. But OK - here is the readable version.

Changelog:
- Handle "." and ".." as special case and move them at the very first beginning of directory listings
- remove unused variable wStringTableOffset


Index: winefile.c
===================================================================
RCS file: /home/wine/wine/programs/winefile/winefile.c,v
retrieving revision 1.18
diff -u -p -d -r1.18 winefile.c
--- winefile.c	24 Aug 2004 18:33:01 -0000	1.18
+++ winefile.c	22 Sep 2004 11:00:59 -0000
@@ -987,13 +987,42 @@ static void read_directory_shell(Entry* 
 #endif /* _SHELL_FOLDERS */
 
 
+/* sort order for different directory/file types */
+enum TYPE_ORDER {
+	TO_DIR = 0,
+	TO_DOT = 1,
+	TO_DOTDOT = 2,
+	TO_OTHER_DIR = 3,
+	TO_FILE = 4
+};
+
+/* distinguish between ".", ".." and any other directory names */
+static int TypeOrderFromDirname(LPCTSTR name)
+{
+	if (name[0] == '.') {
+		if (name[1] == '\0')
+			return TO_DOT;	/* "." */
+
+		if (name[1]=='.' && name[2]=='\0')
+			return TO_DOTDOT;	/* ".." */
+	}
+
+	return TO_OTHER_DIR;	/* anything else */
+}
+
 /* directories first... */
 static int compareType(const WIN32_FIND_DATA* fd1, const WIN32_FIND_DATA* fd2)
 {
-	int dir1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
-	int dir2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
+	int order1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
+	int order2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
 
-	return dir2==dir1? 0: dir2<dir1? -1: 1;
+	/* Handle "." and ".." as special case and move them at the very first beginning. */
+	if (order1==TO_DIR && order2==TO_DIR) {
+		order1 = TypeOrderFromDirname(fd1->cFileName);
+		order2 = TypeOrderFromDirname(fd2->cFileName);
+	}
+
+	return order2==order1? 0: order1<order2? -1: 1;
 }
 
 
Index: winefile.h
===================================================================
RCS file: /home/wine/wine/programs/winefile/winefile.h,v
retrieving revision 1.6
diff -u -p -d -r1.6 winefile.h
--- winefile.h	13 Aug 2003 01:18:37 -0000	1.6
+++ winefile.h	22 Sep 2004 11:00:59 -0000
@@ -143,8 +143,6 @@ typedef struct
   TCHAR		drives[BUFFER_LEN];
   BOOL		prescan_node;	/*TODO*/
 
-  UINT		wStringTableOffset;
-
 #ifdef _SHELL_FOLDERS
   IShellFolder*	iDesktop;
   IMalloc*		iMalloc;





More information about the wine-patches mailing list