ReactOS  0.4.15-dev-1207-g698a8e6
CDirectoryList.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: shell32
3  * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4  * PURPOSE: Shell change notification
5  * COPYRIGHT: Copyright 2020 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
6  */
7 #include "shelldesktop.h"
8 #include "CDirectoryList.h"
9 #include <assert.h> // for assert
10 
12 
14 {
15  assert(!PathIsRelativeW(pszPath));
16 
17  for (INT i = 0; i < m_items.GetSize(); ++i)
18  {
19  if (m_items[i].IsEmpty())
20  continue;
21 
22  if (m_items[i].EqualPath(pszPath))
23  return TRUE; // matched
24  }
25  return FALSE;
26 }
27 
29 {
30  assert(!PathIsRelativeW(pszPath));
31  if (ContainsPath(pszPath))
32  return FALSE;
33  for (INT i = 0; i < m_items.GetSize(); ++i)
34  {
35  if (m_items[i].IsEmpty())
36  {
37  m_items[i].SetPath(pszPath);
38  return TRUE;
39  }
40  }
41  return m_items.Add(pszPath);
42 }
43 
45 {
46  assert(!PathIsRelativeW(pszPath1));
47  assert(!PathIsRelativeW(pszPath2));
48 
49  for (INT i = 0; i < m_items.GetSize(); ++i)
50  {
51  if (m_items[i].EqualPath(pszPath1))
52  {
53  // matched
54  m_items[i].SetPath(pszPath2);
55  return TRUE;
56  }
57  }
58  return FALSE;
59 }
60 
62 {
63  assert(!PathIsRelativeW(pszPath));
64 
65  for (INT i = 0; i < m_items.GetSize(); ++i)
66  {
67  if (m_items[i].EqualPath(pszPath))
68  {
69  // matched
70  m_items[i].SetPath(NULL);
71  return TRUE;
72  }
73  }
74  return FALSE;
75 }
76 
78 {
79  // get the full path
81  lstrcpynW(szPath, pszDirectoryPath, _countof(szPath));
83 
84  // is it a directory?
86  return FALSE;
87 
88  // add the path
89  if (!AddPath(szPath))
90  return FALSE;
91 
92  // enumerate the file items to remember
93  PathAppendW(szPath, L"*");
95  HANDLE hFind = FindFirstFileW(szPath, &find);
96  if (hFind == INVALID_HANDLE_VALUE)
97  {
98  ERR("FindFirstFileW failed\n");
99  return FALSE;
100  }
101 
102  LPWSTR pch;
103  do
104  {
105  // ignore "." and ".."
106  pch = find.cFileName;
107  if (pch[0] == L'.' && (pch[1] == 0 || (pch[1] == L'.' && pch[2] == 0)))
108  continue;
109 
110  // build a path
112  if (lstrlenW(szPath) + lstrlenW(find.cFileName) + 1 > MAX_PATH)
113  {
114  ERR("szPath is too long\n");
115  continue;
116  }
117  PathAppendW(szPath, find.cFileName);
118 
119  // add the path and do recurse
120  if (find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
121  {
122  if (m_fRecursive)
124  else
125  AddPath(szPath);
126  }
127  } while (FindNextFileW(hFind, &find));
128 
129  FindClose(hFind);
130 
131  return TRUE;
132 }
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
BOOL WINAPI PathIsDirectoryW(LPCWSTR lpszPath)
Definition: path.c:1702
BOOL WINAPI PathRemoveFileSpecW(LPWSTR lpszPath)
Definition: path.c:624
BOOL WINAPI PathIsRelativeW(LPCWSTR lpszPath)
Definition: path.c:1558
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define TRUE
Definition: types.h:120
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
#define assert(x)
Definition: debug.h:53
BOOL AddPathsFromDirectory(LPCWSTR pszDirectoryPath)
#define lstrlenW
Definition: compat.h:609
int32_t INT
Definition: typedefs.h:58
WINE_DEFAULT_DEBUG_CHANNEL(shcn)
#define pch(ap)
Definition: match.c:418
BOOL RenamePath(LPCWSTR pszPath1, LPCWSTR pszPath2)
#define lstrcpynW
Definition: compat.h:597
BOOL WINAPI PathAppendW(LPWSTR lpszPath, LPCWSTR lpszAppend)
Definition: path.c:121
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define FALSE
Definition: types.h:117
BOOL AddPath(LPCWSTR pszPath)
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
BOOL ContainsPath(LPCWSTR pszPath) const
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
CSimpleArray< CDirectoryItem > m_items
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:34
static const WCHAR L[]
Definition: oid.c:1250
#define ERR(fmt,...)
Definition: debug.h:110
LPCWSTR szPath
Definition: env.c:35
BOOL DeletePath(LPCWSTR pszPath)
static TAGID TAGID find
Definition: db.cpp:153
WCHAR * LPWSTR
Definition: xmlstorage.h:184
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502