ReactOS 0.4.15-dev-7918-g2a2556c
entries.cpp File Reference
#include <precomp.h>
Include dependency graph for entries.cpp:

Go to the source code of this file.

Macros

#define USE_MY_SHBINDTOPARENT
 

Enumerations

enum  TYPE_ORDER {
  TO_DIR , TO_DOT , TO_DOTDOT , TO_OTHER_DIR ,
  TO_VIRTUAL_FOLDER , TO_FILE
}
 

Functions

static TYPE_ORDER TypeOrderFromDirname (LPCTSTR name)
 
static int compareType (const Entry *entry1, const Entry *entry2)
 
static int compareNothing (const void *arg1, const void *arg2)
 
static int compareName (const void *arg1, const void *arg2)
 
static int compareExt (const void *arg1, const void *arg2)
 
static int compareSize (const void *arg1, const void *arg2)
 
static int compareDate (const void *arg1, const void *arg2)
 
static HRESULT my_SHBindToParent (LPCITEMIDLIST pidl, REFIID riid, VOID **ppv, LPCITEMIDLIST *ppidlLast)
 

Variables

static int(* sortFunctions [])(const void *arg1, const void *arg2)
 

Macro Definition Documentation

◆ USE_MY_SHBINDTOPARENT

#define USE_MY_SHBINDTOPARENT

Definition at line 517 of file entries.cpp.

Enumeration Type Documentation

◆ TYPE_ORDER

Enumerator
TO_DIR 
TO_DOT 
TO_DOTDOT 
TO_OTHER_DIR 
TO_VIRTUAL_FOLDER 
TO_FILE 

Definition at line 179 of file entries.cpp.

179 {
180 TO_DIR,
181 TO_DOT,
182 TO_DOTDOT,
185 TO_FILE
186};
@ TO_DIR
Definition: entries.cpp:180
@ TO_DOT
Definition: entries.cpp:181
@ TO_OTHER_DIR
Definition: entries.cpp:183
@ TO_DOTDOT
Definition: entries.cpp:182
@ TO_FILE
Definition: entries.cpp:185
@ TO_VIRTUAL_FOLDER
Definition: entries.cpp:184

Function Documentation

◆ compareDate()

static int compareDate ( const void arg1,
const void arg2 
)
static

Definition at line 299 of file entries.cpp.

300{
301 const Entry* entry1 = *(const Entry**)arg1;
302 const Entry* entry2 = *(const Entry**)arg2;
303
304 int cmp = compareType(entry1, entry2);
305 if (cmp)
306 return cmp;
307
308 return CompareFileTime(&entry2->_data.ftLastWriteTime, &entry1->_data.ftLastWriteTime);
309}
LONG WINAPI CompareFileTime(IN CONST FILETIME *lpFileTime1, IN CONST FILETIME *lpFileTime2)
Definition: time.c:106
static int compareType(const Entry *entry1, const Entry *entry2)
Definition: entries.cpp:203
GLuint GLuint GLuint GLuint arg1
Definition: glext.h:9513
GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg2
Definition: glext.h:9514
#define cmp(status, error)
Definition: error.c:114
base of all file and directory entries
Definition: entries.h:83
WIN32_FIND_DATA _data
Definition: entries.h:100

Referenced by TIME_DayLightCompareDate().

◆ compareExt()

static int compareExt ( const void arg1,
const void arg2 
)
static

Definition at line 245 of file entries.cpp.

246{
247 const Entry* entry1 = *(const Entry**)arg1;
248 const Entry* entry2 = *(const Entry**)arg2;
249 const TCHAR *name1, *name2, *ext1, *ext2;
250
251 int cmp = compareType(entry1, entry2);
252 if (cmp)
253 return cmp;
254
255 name1 = entry1->_data.cFileName;
256 name2 = entry2->_data.cFileName;
257
258 ext1 = _tcsrchr(name1, TEXT('.'));
259 ext2 = _tcsrchr(name2, TEXT('.'));
260
261 if (ext1)
262 ++ext1;
263 else
264 ext1 = TEXT("");
265
266 if (ext2)
267 ++ext2;
268 else
269 ext2 = TEXT("");
270
271 cmp = lstrcmpi(ext1, ext2);
272 if (cmp)
273 return cmp;
274
275 return lstrcmpi(name1, name2);
276}
#define TEXT(s)
Definition: k32.h:26
#define _tcsrchr
Definition: utility.h:116
static const BYTE ext1[]
Definition: encode.c:2697
static const BYTE ext2[]
Definition: encode.c:2699
static WCHAR name1[]
Definition: record.c:34
static WCHAR name2[]
Definition: record.c:35
#define lstrcmpi
Definition: winbase.h:3873
char TCHAR
Definition: xmlstorage.h:189

◆ compareName()

static int compareName ( const void arg1,
const void arg2 
)
static

Definition at line 233 of file entries.cpp.

234{
235 const Entry* entry1 = *(const Entry**)arg1;
236 const Entry* entry2 = *(const Entry**)arg2;
237
238 int cmp = compareType(entry1, entry2);
239 if (cmp)
240 return cmp;
241
242 return lstrcmpi(entry1->_data.cFileName, entry2->_data.cFileName);
243}

◆ compareNothing()

static int compareNothing ( const void arg1,
const void arg2 
)
static

Definition at line 228 of file entries.cpp.

229{
230 return -1;
231}

◆ compareSize()

static int compareSize ( const void arg1,
const void arg2 
)
static

Definition at line 278 of file entries.cpp.

279{
280 const Entry* entry1 = *(const Entry**)arg1;
281 const Entry* entry2 = *(const Entry**)arg2;
282
283 int cmp = compareType(entry1, entry2);
284 if (cmp)
285 return cmp;
286
287 cmp = entry2->_data.nFileSizeHigh - entry1->_data.nFileSizeHigh;
288
289 if (cmp < 0)
290 return -1;
291 else if (cmp > 0)
292 return 1;
293
294 cmp = entry2->_data.nFileSizeLow - entry1->_data.nFileSizeLow;
295
296 return cmp<0? -1: cmp>0? 1: 0;
297}

◆ compareType()

static int compareType ( const Entry entry1,
const Entry entry2 
)
static

Definition at line 203 of file entries.cpp.

204{
205 const WIN32_FIND_DATA* fd1 = &entry1->_data;
206 const WIN32_FIND_DATA* fd2 = &entry2->_data;
207
208 TYPE_ORDER order1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
209 TYPE_ORDER order2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
210
211 // Handle "." and ".." as special case and move them at the very first beginning.
212 if (order1==TO_DIR && order2==TO_DIR) {
213 order1 = TypeOrderFromDirname(fd1->cFileName);
214 order2 = TypeOrderFromDirname(fd2->cFileName);
215
216 // Move virtual folders after physical folders
217 if (!(entry1->_shell_attribs & SFGAO_FILESYSTEM))
218 order1 = TO_VIRTUAL_FOLDER;
219
220 if (!(entry2->_shell_attribs & SFGAO_FILESYSTEM))
221 order2 = TO_VIRTUAL_FOLDER;
222 }
223
224 return order2==order1? 0: order1<order2? -1: 1;
225}
static TYPE_ORDER TypeOrderFromDirname(LPCTSTR name)
Definition: entries.cpp:189
TYPE_ORDER
Definition: entries.cpp:179
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
SFGAOF _shell_attribs
Definition: entries.h:102

Referenced by compareDate(), compareExt(), compareName(), and compareSize().

◆ my_SHBindToParent()

static HRESULT my_SHBindToParent ( LPCITEMIDLIST  pidl,
REFIID  riid,
VOID **  ppv,
LPCITEMIDLIST ppidlLast 
)
static

Definition at line 460 of file entries.cpp.

461{
462 HRESULT hr;
463
464 if (!ppv)
465 return E_POINTER;
466
467 // There must be at least one item ID.
468 if (!pidl || !pidl->mkid.cb)
469 return E_INVALIDARG;
470
471 // Get the desktop folder as root.
472 ShellFolder desktop;
473/* IShellFolderPtr desktop;
474 hr = SHGetDesktopFolder(&desktop);
475 if (FAILED(hr))
476 return hr; */
477
478 // Walk to the penultimate item ID.
479 LPCITEMIDLIST marker = pidl;
480 for (;;)
481 {
482 LPCITEMIDLIST next = reinterpret_cast<LPCITEMIDLIST>(
483 marker->mkid.abID - sizeof(marker->mkid.cb) + marker->mkid.cb);
484 if (!next->mkid.cb)
485 break;
486 marker = next;
487 }
488
489 if (marker == pidl)
490 {
491 // There was only a single item ID, so bind to the root folder.
492 hr = desktop->QueryInterface(riid, ppv);
493 }
494 else
495 {
496 // Copy the ID list, truncating the last item.
497 int length = marker->mkid.abID - pidl->mkid.abID;
498 if (LPITEMIDLIST parent_id = reinterpret_cast<LPITEMIDLIST>(
499 malloc(length + sizeof(pidl->mkid.cb))))
500 {
501 LPBYTE raw_data = reinterpret_cast<LPBYTE>(parent_id);
502 memcpy(raw_data, pidl, length);
503 memset(raw_data + length, 0, sizeof(pidl->mkid.cb));
504 hr = desktop->BindToObject(parent_id, 0, riid, ppv);
506 }
507 else
508 return E_OUTOFMEMORY;
509 }
510
511 // Return a pointer to the last item ID.
512 if (ppidlLast)
513 *ppidlLast = marker;
514
515 return hr;
516}
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
int marker
Definition: jpeglib.h:1030
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static DWORD parent_id
Definition: cursoricon.c:2270
static unsigned __int64 next
Definition: rand_nt.c:6
#define memset(x, y, z)
Definition: compat.h:39
HRESULT hr
Definition: shlfolder.c:183
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
HRESULT QueryInterface(REFIID riid, I *p)
Definition: shellclasses.h:417
IShellFolder smart pointer.
Definition: shellclasses.h:594
unsigned char * LPBYTE
Definition: typedefs.h:53
#define E_POINTER
Definition: winerror.h:2365

Referenced by Entry::do_context_menu().

◆ TypeOrderFromDirname()

static TYPE_ORDER TypeOrderFromDirname ( LPCTSTR  name)
static

Definition at line 189 of file entries.cpp.

190{
191 if (name[0] == '.') {
192 if (name[1] == '\0')
193 return TO_DOT; // "."
194
195 if (name[1]=='.' && name[2]=='\0')
196 return TO_DOTDOT; // ".."
197 }
198
199 return TO_OTHER_DIR; // any other directory
200}
Definition: name.c:39

Referenced by compareType().

Variable Documentation

◆ sortFunctions

int(* sortFunctions[])(const void *arg1, const void *arg2) ( const void arg1,
const void arg2 
)
static
Initial value:
= {
}
static int compareExt(const void *arg1, const void *arg2)
Definition: entries.cpp:245
static int compareNothing(const void *arg1, const void *arg2)
Definition: entries.cpp:228
static int compareName(const void *arg1, const void *arg2)
Definition: entries.cpp:233
static int compareDate(const void *arg1, const void *arg2)
Definition: entries.cpp:299
static int compareSize(const void *arg1, const void *arg2)
Definition: entries.cpp:278

Definition at line 312 of file entries.cpp.

Referenced by Entry::sort_directory().