ReactOS 0.4.16-dev-1059-gb1cf981
misc.h
Go to the documentation of this file.
1#pragma once
2
3#include <atlstr.h>
4
5#ifdef _M_IX86
6#define CurrentArchitecture L"x86"
7#elif defined(_M_AMD64)
8#define CurrentArchitecture L"amd64"
9#elif defined(_M_ARM)
10#define CurrentArchitecture L"arm"
11#elif defined(_M_ARM64)
12#define CurrentArchitecture L"arm64"
13#elif defined(_M_IA64)
14#define CurrentArchitecture L"ia64"
15#elif defined(_M_PPC)
16#define CurrentArchitecture L"ppc"
17#endif
18
19static inline HRESULT
21{
23}
24
25static inline UINT
27{
28 // Attempt to extract the original Win32 error code from the HRESULT
30 return LOWORD(hr);
31 else
32 return hr >= 0 ? ERROR_SUCCESS : hr;
33}
34
35UINT
37
38VOID
40VOID
41ShowPopupMenuEx(HWND hwnd, HWND hwndOwner, UINT MenuID, UINT DefaultItem, POINT *Point = NULL);
42VOID
44UINT
46BOOL
48BOOL
50BOOL
52
53VOID
54InitLogs();
55VOID
56FreeLogs();
57BOOL
58WriteLogMessage(WORD wType, DWORD dwEventID, LPCWSTR lpMsg);
59BOOL
60GetInstalledVersion(CStringW *pszVersion, const CStringW &szRegName);
61
62typedef struct
63{
69
70static inline BOOL
71NotifyFileExtractCallback(const CStringW &ItemPath, UINT64 UncompressedSize, UINT FileAttributes,
73{
74 EXTRACTCALLBACKINFO eci = { ItemPath, UncompressedSize, FileAttributes };
75 return Callback ? Callback(eci, Cookie) : TRUE;
76}
77
78BOOL
79ExtractFilesFromCab(const CStringW &szCabName, const CStringW &szCabDir, const CStringW &szOutputDir,
81BOOL
82ExtractFilesFromCab(LPCWSTR FullCabPath, const CStringW &szOutputDir,
84
85BOOL
87
88INT
90
91void
92UnixTimeToFileTime(DWORD dwUnixTime, LPFILETIME pFileTime);
93
94BOOL
95SearchPatternMatch(LPCWSTR szHaystack, LPCWSTR szNeedle);
96
101
102bool
104
105template <class T> static CStringW
106BuildPath(const T &Base, LPCWSTR Append)
107{
109 SIZE_T len = path.GetLength();
110 if (len && path[len - 1] != L'\\' && path[len - 1] != L'/')
111 path += L'\\';
112 while (*Append == L'\\' || *Append == L'/')
113 ++Append;
114 return path + Append;
115}
116
118SplitFileAndDirectory(LPCWSTR FullPath, CStringW *pDir = NULL);
119BOOL
121UINT
129
130template <class T> class CLocalPtr : public CHeapPtr<T, CLocalAllocator>
131{
132};
133
135{
137
139 {
141 if (m_hMutex && !InitialOwner)
142 {
144 if (wait != WAIT_OBJECT_0 && wait != WAIT_ABANDONED)
145 {
147 m_hMutex = NULL;
148 }
149 }
150 }
152 {
153 if (m_hMutex)
154 {
157 }
158 }
159
160 bool Acquired() const { return m_hMutex != NULL; }
161};
unsigned long long UINT64
PRTL_UNICODE_STRING_BUFFER Path
HRESULT GetKnownPath(REFKNOWNFOLDERID kfid, CStringW &Path, DWORD Flags=KF_FLAG_CREATE)
Definition: misc.cpp:554
BOOL(CALLBACK * EXTRACTCALLBACK)(const EXTRACTCALLBACKINFO &Info, void *Cookie)
Definition: misc.h:68
BOOL WriteLogMessage(WORD wType, DWORD dwEventID, LPCWSTR lpMsg)
Definition: misc.cpp:319
bool ExpandEnvStrings(CStringW &Str)
Definition: misc.cpp:487
HRESULT GetSpecialPath(UINT csidl, CStringW &Path, HWND hwnd=NULL)
Definition: misc.cpp:545
static CStringW BuildPath(const T &Base, LPCWSTR Append)
Definition: misc.h:106
BOOL StartProcess(const CStringW &Path, BOOL Wait)
Definition: misc.cpp:176
BOOL GetStorageDirectory(CStringW &lpDirectory)
Definition: misc.cpp:237
BOOL GetInstalledVersion(CStringW *pszVersion, const CStringW &szRegName)
Definition: misc.cpp:372
BOOL OpensWithExplorer(PCWSTR Path)
Definition: misc.cpp:162
VOID EmulateDialogReposition(HWND hwnd)
Definition: misc.cpp:61
BOOL DeleteDirectoryTree(LPCWSTR Dir, HWND hwnd=NULL)
Definition: misc.cpp:513
UINT ClassifyFile(PCWSTR Path)
Definition: misc.cpp:125
UINT CreateDirectoryTree(LPCWSTR Dir)
Definition: misc.cpp:526
static BOOL NotifyFileExtractCallback(const CStringW &ItemPath, UINT64 UncompressedSize, UINT FileAttributes, EXTRACTCALLBACK Callback, void *Cookie)
Definition: misc.h:71
HRESULT RegKeyHasValues(HKEY hKey, LPCWSTR Path, REGSAM wowsam=0)
Definition: misc.cpp:446
BOOL ExtractFilesFromCab(const CStringW &szCabName, const CStringW &szCabDir, const CStringW &szOutputDir, EXTRACTCALLBACK Callback=NULL, void *Cookie=NULL)
Definition: cabinet.cpp:250
VOID ShowPopupMenuEx(HWND hwnd, HWND hwndOwner, UINT MenuID, UINT DefaultItem, POINT *Point=NULL)
Definition: misc.cpp:80
VOID InitLogs()
Definition: misc.cpp:272
VOID FreeLogs()
Definition: misc.cpp:310
static UINT ErrorFromHResult(HRESULT hr)
Definition: misc.h:26
INT GetSystemColorDepth()
Definition: misc.cpp:395
VOID CopyTextToClipboard(LPCWSTR lpszText)
Definition: misc.cpp:28
BOOL SearchPatternMatch(LPCWSTR szHaystack, LPCWSTR szNeedle)
Definition: misc.cpp:504
LPCWSTR GetRegString(CRegKey &Key, LPCWSTR Name, CStringW &Value)
Definition: misc.cpp:464
HRESULT GetProgramFilesPath(CStringW &Path, BOOL PerUser, HWND hwnd=NULL)
Definition: misc.cpp:569
CStringW SplitFileAndDirectory(LPCWSTR FullPath, CStringW *pDir=NULL)
Definition: misc.cpp:533
BOOL IsSystem64Bit()
Definition: misc.cpp:382
void UnixTimeToFileTime(DWORD dwUnixTime, LPFILETIME pFileTime)
Definition: misc.cpp:435
UINT ErrorBox(HWND hOwner, UINT Error=GetLastError())
Definition: misc.cpp:16
BOOL Error
Definition: chkdsk.c:66
#define ERROR_SUCCESS
Definition: deptool.c:10
LPWSTR Name
Definition: desk.c:124
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define CALLBACK
Definition: compat.h:35
#define INFINITE
Definition: serial.h:102
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE _In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG FileAttributes
Definition: fltkernel.h:1236
FxAutoRegKey hKey
GLenum GLsizei len
Definition: glext.h:6722
#define HResultFromWin32
Definition: loader.cpp:14
unsigned int UINT
Definition: ndis.h:50
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2478
#define BOOL
Definition: nt_native.h:43
#define L(x)
Definition: ntvdm.h:50
#define LOWORD(l)
Definition: pedump.c:82
static ULONG Timeout
Definition: ping.c:61
_In_opt_ LPCSTR lpDirectory
Definition: shellapi.h:497
HRESULT hr
Definition: shlfolder.c:183
@ KF_FLAG_CREATE
Definition: shlobj.h:106
~CScopedMutex()
Definition: misc.h:151
CScopedMutex(LPCWSTR Name, UINT Timeout=INFINITE, BOOL InitialOwner=FALSE)
Definition: misc.h:138
bool Acquired() const
Definition: misc.h:160
HANDLE m_hMutex
Definition: misc.h:136
const CStringW & ItemPath
Definition: misc.h:64
UINT64 UncompressedSize
Definition: misc.h:65
UINT FileAttributes
Definition: misc.h:66
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexW(IN LPSECURITY_ATTRIBUTES lpMutexAttributes OPTIONAL, IN BOOL bInitialOwner, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:576
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseMutex(IN HANDLE hMutex)
Definition: synch.c:618
const uint16_t * PCWSTR
Definition: typedefs.h:57
ULONG_PTR SIZE_T
Definition: typedefs.h:80
int32_t INT
Definition: typedefs.h:58
#define HIWORD(l)
Definition: typedefs.h:247
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:170
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
#define WAIT_ABANDONED
Definition: winbase.h:438
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WAIT_OBJECT_0
Definition: winbase.h:432
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
ACCESS_MASK REGSAM
Definition: winreg.h:69
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_In_opt_ PVOID _Out_ PLARGE_INTEGER Cookie
Definition: cmfuncs.h:14
_In_ BOOLEAN InitialOwner
Definition: kefuncs.h:565
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185