ReactOS  0.4.12-dev-75-g00dd17e
fileutils.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  __tagQUERY_FILES_TABLE
 

Macros

#define QUERY_FILES_TABLE_ROUTINE(fnName)
 

Typedefs

typedef LRESULT(* PQUERY_FILES_TABLE_ROUTINE) (IN LPCWSTR Path, IN LPCWSTR FileNamesQuery, IN LPCWSTR ExpandedFileNamesQuery, IN PWIN32_FIND_DATAW pfind_data, IN PVOID Context, IN PVOID EntryContext)
 
typedef struct __tagQUERY_FILES_TABLE QUERY_FILES_TABLE
 
typedef struct __tagQUERY_FILES_TABLEPQUERY_FILES_TABLE
 

Functions

BOOL MyFileExists (IN LPCWSTR lpszFilePath, OUT PWIN32_FIND_DATAW pFindData OPTIONAL)
 
LRESULT FileQueryFiles (IN LPCWSTR Path, IN LPCWSTR FileNamesQuery, IN PQUERY_FILES_TABLE QueryTable, IN PVOID Context)
 
BOOL BackupIniFile (IN LPCWSTR lpszIniFile)
 

Macro Definition Documentation

◆ QUERY_FILES_TABLE_ROUTINE

#define QUERY_FILES_TABLE_ROUTINE (   fnName)
Value:
LRESULT (fnName)(IN LPCWSTR Path, \
IN LPCWSTR FileNamesQuery, \
IN LPCWSTR ExpandedFileNamesQuery, \
IN PWIN32_FIND_DATAW pfind_data, \
IN PVOID Context, \
#define IN
Definition: typedefs.h:38
#define LRESULT
Definition: msvc.h:49
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
_In_ PCWSTR _Inout_ _At_ QueryTable EntryContext
Definition: rtlfuncs.h:3988
PRTL_UNICODE_STRING_BUFFER Path
struct tagContext Context
Definition: acpixf.h:1027

Definition at line 35 of file fileutils.h.

Typedef Documentation

◆ PQUERY_FILES_TABLE

◆ PQUERY_FILES_TABLE_ROUTINE

typedef LRESULT(* PQUERY_FILES_TABLE_ROUTINE) (IN LPCWSTR Path, IN LPCWSTR FileNamesQuery, IN LPCWSTR ExpandedFileNamesQuery, IN PWIN32_FIND_DATAW pfind_data, IN PVOID Context, IN PVOID EntryContext)

Definition at line 28 of file fileutils.h.

◆ QUERY_FILES_TABLE

Function Documentation

◆ BackupIniFile()

BOOL BackupIniFile ( IN LPCWSTR  lpszIniFile)

Definition at line 93 of file fileutils.c.

Referenced by CreatePropSheet().

94 {
95  BOOL Success = FALSE;
96  DWORD dwNumOfChars = 0;
97  LPWSTR SourceFile, DestFile;
98  LPWSTR lpName, lpPath;
99 
100  dwNumOfChars = ExpandEnvironmentStringsW(lpszIniFile, NULL, 0);
101  SourceFile = (LPWSTR)MemAlloc(0, dwNumOfChars * sizeof(WCHAR));
102  ExpandEnvironmentStringsW(lpszIniFile, SourceFile, dwNumOfChars);
103 
104  lpName = wcsrchr(SourceFile, L'\\');
105  lpName = (lpName ? lpName + 1 : SourceFile);
106  dwNumOfChars = wcslen(L"%SystemRoot%\\pss\\") + wcslen(lpName) + 7 + 1;
107  lpPath = (LPWSTR)MemAlloc(0, dwNumOfChars * sizeof(WCHAR));
108  wcscpy(lpPath, L"%SystemRoot%\\pss\\");
109  wcscat(lpPath, lpName);
110  wcscat(lpPath, L".backup");
111 
112  dwNumOfChars = ExpandEnvironmentStringsW(lpPath, NULL, 0);
113  DestFile = (LPWSTR)MemAlloc(0, dwNumOfChars * sizeof(WCHAR));
114  ExpandEnvironmentStringsW(lpPath, DestFile, dwNumOfChars);
115  MemFree(lpPath);
116 
117  Success = CopyFileW(SourceFile, DestFile, TRUE /* don't overwrite */ /* FALSE */ /* overwrite */);
118 
119  MemFree(DestFile);
120  MemFree(SourceFile);
121 
122  return Success;
123 }
#define TRUE
Definition: types.h:120
BOOL MemFree(IN PVOID lpMem)
Definition: utils.c:26
__wchar_t WCHAR
Definition: xmlstorage.h:180
PVOID MemAlloc(IN DWORD dwFlags, IN DWORD dwBytes)
Definition: utils.c:33
_In_ LPCSTR lpName
Definition: winbase.h:2729
smooth NULL
Definition: ftsmooth.c:416
_Check_return_ _CRTIMP _CONST_RETURN wchar_t *__cdecl wcsrchr(_In_z_ const wchar_t *_Str, _In_ wchar_t _Ch)
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI CopyFileW(IN LPCWSTR lpExistingFileName, IN LPCWSTR lpNewFileName, IN BOOL bFailIfExists)
Definition: copy.c:439
unsigned long DWORD
Definition: ntddk_ex.h:95
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1087
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
WCHAR * LPWSTR
Definition: xmlstorage.h:184
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

◆ FileQueryFiles()

LRESULT FileQueryFiles ( IN LPCWSTR  Path,
IN LPCWSTR  FileNamesQuery,
IN PQUERY_FILES_TABLE  QueryTable,
IN PVOID  Context 
)

Definition at line 46 of file fileutils.c.

50 {
53 
54  LPWSTR lpszQuery;
55  DWORD dwNumOfChars;
56  LPWSTR lpszExpandedQuery;
57  HANDLE search;
58 
59  dwNumOfChars = wcslen(Path) + 1 + wcslen(FileNamesQuery) + 1;
60  lpszQuery = (LPWSTR)MemAlloc(0, dwNumOfChars * sizeof(WCHAR));
61  wcscpy(lpszQuery, Path);
62  wcscat(lpszQuery, L"\\");
63  wcscat(lpszQuery, FileNamesQuery);
64 
65  dwNumOfChars = ExpandEnvironmentStringsW(lpszQuery, NULL, 0);
66  lpszExpandedQuery = (LPWSTR)MemAlloc(0, dwNumOfChars * sizeof(WCHAR));
67  ExpandEnvironmentStringsW(lpszQuery, lpszExpandedQuery, dwNumOfChars);
68  MemFree(lpszQuery);
69 
70  search = FindFirstFileW(lpszExpandedQuery, &find_data);
71  if (search != INVALID_HANDLE_VALUE)
72  {
73  do
74  {
76  while (pTable && pTable->QueryRoutine)
77  {
78  pTable->QueryRoutine(Path, FileNamesQuery, lpszExpandedQuery, &find_data, Context, pTable->EntryContext);
79  ++pTable;
80  }
81  } while (/*res = */ FindNextFileW(search, &find_data));
82  }
83  else
84  res = ERROR_NO_MORE_FILES;
85 
86  FindClose(search);
87 
88  MemFree(lpszExpandedQuery);
89 
90  return res;
91 }
static short search(int val, const short *table, int size)
Definition: msg711.c:259
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
_In_ PCWSTR _Inout_ _At_ QueryTable _Pre_unknown_ PRTL_QUERY_REGISTRY_TABLE QueryTable
Definition: rtlfuncs.h:3988
BOOL MemFree(IN PVOID lpMem)
Definition: utils.c:26
#define ERROR_SUCCESS
Definition: deptool.c:10
__wchar_t WCHAR
Definition: xmlstorage.h:180
PVOID MemAlloc(IN DWORD dwFlags, IN DWORD dwBytes)
Definition: utils.c:33
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
PQUERY_FILES_TABLE_ROUTINE QueryRoutine
Definition: fileutils.h:45
static int find_data(const struct Vector *v, const BYTE *pData, int size)
Definition: filtermapper.c:162
smooth NULL
Definition: ftsmooth.c:416
#define ERROR_NO_MORE_FILES
Definition: winerror.h:121
unsigned long DWORD
Definition: ntddk_ex.h:95
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1087
PRTL_UNICODE_STRING_BUFFER Path
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
GLuint res
Definition: glext.h:9613
static const EHCI_PERIOD pTable[]
Definition: usbehci.c:29
WCHAR * LPWSTR
Definition: xmlstorage.h:184
LONG_PTR LRESULT
Definition: windef.h:209
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502

◆ MyFileExists()

BOOL MyFileExists ( IN LPCWSTR  lpszFilePath,
OUT PWIN32_FIND_DATAW pFindData  OPTIONAL 
)

Definition at line 18 of file fileutils.c.

Referenced by CreatePropSheet(), and GeneralPageWndProc().

20 {
21  BOOL bIsFound = FALSE;
23 
24  DWORD dwNumOfChars;
25  LPWSTR lpszCmdLine;
26  HANDLE search;
27 
28  dwNumOfChars = ExpandEnvironmentStringsW(lpszFilePath, NULL, 0);
29  lpszCmdLine = (LPWSTR)MemAlloc(0, dwNumOfChars * sizeof(WCHAR));
30  ExpandEnvironmentStringsW(lpszFilePath, lpszCmdLine, dwNumOfChars);
31 
32  search = FindFirstFileW(lpszCmdLine, &find_data);
33  MemFree(lpszCmdLine);
34 
35  bIsFound = (search != INVALID_HANDLE_VALUE);
36 
37  FindClose(search);
38 
39  if (bIsFound && pFindData)
40  *pFindData = find_data;
41 
42  return bIsFound;
43 }
static short search(int val, const short *table, int size)
Definition: msg711.c:259
BOOL MemFree(IN PVOID lpMem)
Definition: utils.c:26
__wchar_t WCHAR
Definition: xmlstorage.h:180
PVOID MemAlloc(IN DWORD dwFlags, IN DWORD dwBytes)
Definition: utils.c:33
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
static int find_data(const struct Vector *v, const BYTE *pData, int size)
Definition: filtermapper.c:162
smooth NULL
Definition: ftsmooth.c:416
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
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