ReactOS  0.4.14-dev-49-gfb4591c
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, TO_DIR = 0, TO_DOT = 1,
  TO_DOTDOT = 2, TO_OTHER_DIR = 3, TO_FILE = 4
}
 

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 
TO_DIR 
TO_DOT 
TO_DOTDOT 
TO_OTHER_DIR 
TO_FILE 

Definition at line 179 of file entries.cpp.

179  {
180  TO_DIR,
181  TO_DOT,
182  TO_DOTDOT,
183  TO_OTHER_DIR,
185  TO_FILE
186 };

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 }
WIN32_FIND_DATA _data
Definition: entries.h:100
static int compareType(const Entry *entry1, const Entry *entry2)
Definition: entries.cpp:203
#define cmp(status, error)
Definition: error.c:114
GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg2
Definition: glext.h:9514
GLuint GLuint GLuint GLuint arg1
Definition: glext.h:9513
LONG WINAPI CompareFileTime(IN CONST FILETIME *lpFileTime1, IN CONST FILETIME *lpFileTime2)
Definition: time.c:106
base of all file and directory entries
Definition: entries.h:82

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 lstrcmpi
Definition: winbase.h:3690
WIN32_FIND_DATA _data
Definition: entries.h:100
static int compareType(const Entry *entry1, const Entry *entry2)
Definition: entries.cpp:203
#define cmp(status, error)
Definition: error.c:114
static WCHAR name1[]
Definition: record.c:34
GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg2
Definition: glext.h:9514
GLuint GLuint GLuint GLuint arg1
Definition: glext.h:9513
char TCHAR
Definition: xmlstorage.h:189
static const BYTE ext1[]
Definition: encode.c:2697
static const BYTE ext2[]
Definition: encode.c:2699
#define TEXT(s)
Definition: k32.h:26
_TCHAR * _tcsrchr(const _TCHAR *s, _XINT c)
Definition: tcsrchr.h:4
static WCHAR name2[]
Definition: record.c:35
base of all file and directory entries
Definition: entries.h:82

◆ 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 }
#define lstrcmpi
Definition: winbase.h:3690
WIN32_FIND_DATA _data
Definition: entries.h:100
static int compareType(const Entry *entry1, const Entry *entry2)
Definition: entries.cpp:203
#define cmp(status, error)
Definition: error.c:114
GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg2
Definition: glext.h:9514
GLuint GLuint GLuint GLuint arg1
Definition: glext.h:9513
base of all file and directory entries
Definition: entries.h:82

◆ 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 }
WIN32_FIND_DATA _data
Definition: entries.h:100
static int compareType(const Entry *entry1, const Entry *entry2)
Definition: entries.cpp:203
#define cmp(status, error)
Definition: error.c:114
GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg2
Definition: glext.h:9514
GLuint GLuint GLuint GLuint arg1
Definition: glext.h:9513
base of all file and directory entries
Definition: entries.h:82

◆ 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 }
WIN32_FIND_DATA _data
Definition: entries.h:100
TYPE_ORDER
Definition: entries.cpp:179
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
SFGAOF _shell_attribs
Definition: entries.h:102
static TYPE_ORDER TypeOrderFromDirname(LPCTSTR name)
Definition: entries.cpp:189

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);
505  free(parent_id);
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 }
HRESULT hr
Definition: shlfolder.c:183
REFIID riid
Definition: precomp.h:44
#define free
Definition: debug_ros.c:5
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
REFIID LPVOID * ppv
Definition: atlbase.h:39
IShellFolder smart pointer.
Definition: shellclasses.h:593
unsigned char * LPBYTE
Definition: typedefs.h:52
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
static DWORD parent_id
Definition: cursoricon.c:2153
#define E_INVALIDARG
Definition: ddrawi.h:101
int marker
Definition: jpeglib.h:1027
LONG HRESULT
Definition: typedefs.h:77
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
HRESULT QueryInterface(REFIID riid, I *p)
Definition: shellclasses.h:417
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static unsigned __int64 next
Definition: rand_nt.c:6
#define malloc
Definition: debug_ros.c:4
#define E_POINTER
Definition: winerror.h:2365
#define memset(x, y, z)
Definition: compat.h:39
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41

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:36

Referenced by compareType().

Variable Documentation

◆ sortFunctions

int(* sortFunctions[])(const void *arg1, const void *arg2)
static
Initial value:
= {
}
static int compareDate(const void *arg1, const void *arg2)
Definition: entries.cpp:299
static int compareName(const void *arg1, const void *arg2)
Definition: entries.cpp:233
static int compareNothing(const void *arg1, const void *arg2)
Definition: entries.cpp:228
static int compareExt(const void *arg1, const void *arg2)
Definition: entries.cpp:245
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().