ReactOS 0.4.16-dev-736-g28b802b
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 UINT
21{
22 // Attempt to extract the original Win32 error code from the HRESULT
24 return LOWORD(hr);
25 else
26 return hr >= 0 ? ERROR_SUCCESS : hr;
27}
28
29VOID
31VOID
32ShowPopupMenuEx(HWND hwnd, HWND hwndOwner, UINT MenuID, UINT DefaultItem, POINT *Point = NULL);
33VOID
35BOOL
37BOOL
39
40VOID
41InitLogs();
42VOID
43FreeLogs();
44BOOL
45WriteLogMessage(WORD wType, DWORD dwEventID, LPCWSTR lpMsg);
46BOOL
47GetInstalledVersion(CStringW *pszVersion, const CStringW &szRegName);
48
49typedef struct
50{
56
57static inline BOOL
58NotifyFileExtractCallback(const CStringW &ItemPath, UINT64 UncompressedSize, UINT FileAttributes,
60{
61 EXTRACTCALLBACKINFO eci = { ItemPath, UncompressedSize, FileAttributes };
62 return Callback ? Callback(eci, Cookie) : TRUE;
63}
64
65BOOL
66ExtractFilesFromCab(const CStringW &szCabName, const CStringW &szCabDir, const CStringW &szOutputDir,
68BOOL
69ExtractFilesFromCab(LPCWSTR FullCabPath, const CStringW &szOutputDir,
71
72BOOL
74
75INT
77
78void
79UnixTimeToFileTime(DWORD dwUnixTime, LPFILETIME pFileTime);
80
81BOOL
82SearchPatternMatch(LPCWSTR szHaystack, LPCWSTR szNeedle);
83
88
89bool
91
92template <class T> static CStringW
93BuildPath(const T &Base, LPCWSTR Append)
94{
96 SIZE_T len = path.GetLength();
97 if (len && path[len - 1] != L'\\' && path[len - 1] != L'/')
98 path += L'\\';
99 while (*Append == L'\\' || *Append == L'/')
100 ++Append;
101 return path + Append;
102}
103
105SplitFileAndDirectory(LPCWSTR FullPath, CStringW *pDir = NULL);
106BOOL
108UINT
116
117template <class T> class CLocalPtr : public CHeapPtr<T, CLocalAllocator>
118{
119};
120
122{
124
126 {
128 if (m_hMutex && !InitialOwner)
129 {
131 if (wait != WAIT_OBJECT_0 && wait != WAIT_ABANDONED)
132 {
134 m_hMutex = NULL;
135 }
136 }
137 }
139 {
140 if (m_hMutex)
141 {
144 }
145 }
146
147 bool Acquired() const { return m_hMutex != NULL; }
148};
unsigned long long UINT64
PRTL_UNICODE_STRING_BUFFER Path
HRESULT GetKnownPath(REFKNOWNFOLDERID kfid, CStringW &Path, DWORD Flags=KF_FLAG_CREATE)
Definition: misc.cpp:489
BOOL(CALLBACK * EXTRACTCALLBACK)(const EXTRACTCALLBACKINFO &Info, void *Cookie)
Definition: misc.h:55
BOOL WriteLogMessage(WORD wType, DWORD dwEventID, LPCWSTR lpMsg)
Definition: misc.cpp:254
bool ExpandEnvStrings(CStringW &Str)
Definition: misc.cpp:422
HRESULT GetSpecialPath(UINT csidl, CStringW &Path, HWND hwnd=NULL)
Definition: misc.cpp:480
static CStringW BuildPath(const T &Base, LPCWSTR Append)
Definition: misc.h:93
BOOL StartProcess(const CStringW &Path, BOOL Wait)
Definition: misc.cpp:111
BOOL GetStorageDirectory(CStringW &lpDirectory)
Definition: misc.cpp:172
BOOL GetInstalledVersion(CStringW *pszVersion, const CStringW &szRegName)
Definition: misc.cpp:307
VOID EmulateDialogReposition(HWND hwnd)
Definition: misc.cpp:49
BOOL DeleteDirectoryTree(LPCWSTR Dir, HWND hwnd=NULL)
Definition: misc.cpp:448
UINT CreateDirectoryTree(LPCWSTR Dir)
Definition: misc.cpp:461
static BOOL NotifyFileExtractCallback(const CStringW &ItemPath, UINT64 UncompressedSize, UINT FileAttributes, EXTRACTCALLBACK Callback, void *Cookie)
Definition: misc.h:58
HRESULT RegKeyHasValues(HKEY hKey, LPCWSTR Path, REGSAM wowsam=0)
Definition: misc.cpp:381
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:68
VOID InitLogs()
Definition: misc.cpp:207
VOID FreeLogs()
Definition: misc.cpp:245
static UINT ErrorFromHResult(HRESULT hr)
Definition: misc.h:20
INT GetSystemColorDepth()
Definition: misc.cpp:330
VOID CopyTextToClipboard(LPCWSTR lpszText)
Definition: misc.cpp:16
BOOL SearchPatternMatch(LPCWSTR szHaystack, LPCWSTR szNeedle)
Definition: misc.cpp:439
LPCWSTR GetRegString(CRegKey &Key, LPCWSTR Name, CStringW &Value)
Definition: misc.cpp:399
HRESULT GetProgramFilesPath(CStringW &Path, BOOL PerUser, HWND hwnd=NULL)
Definition: misc.cpp:504
CStringW SplitFileAndDirectory(LPCWSTR FullPath, CStringW *pDir=NULL)
Definition: misc.cpp:468
BOOL IsSystem64Bit()
Definition: misc.cpp:317
void UnixTimeToFileTime(DWORD dwUnixTime, LPFILETIME pFileTime)
Definition: misc.cpp:370
#define ERROR_SUCCESS
Definition: deptool.c:10
#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
unsigned int UINT
Definition: ndis.h:50
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2451
#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:485
HRESULT hr
Definition: shlfolder.c:183
@ KF_FLAG_CREATE
Definition: shlobj.h:106
~CScopedMutex()
Definition: misc.h:138
CScopedMutex(LPCWSTR Name, UINT Timeout=INFINITE, BOOL InitialOwner=FALSE)
Definition: misc.h:125
bool Acquired() const
Definition: misc.h:147
HANDLE m_hMutex
Definition: misc.h:123
const CStringW & ItemPath
Definition: misc.h:51
UINT64 UncompressedSize
Definition: misc.h:52
UINT FileAttributes
Definition: misc.h:53
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
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
#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