ReactOS 0.4.16-dev-2206-gc56950d
misc.h
Go to the documentation of this file.
1#pragma once
2
3#include <atlstr.h>
4#include "appinfo.h"
5
6#ifdef _M_IX86
7#define CurrentArchitecture L"x86"
8#elif defined(_M_AMD64)
9#define CurrentArchitecture L"amd64"
10#elif defined(_M_ARM)
11#define CurrentArchitecture L"arm"
12#elif defined(_M_ARM64)
13#define CurrentArchitecture L"arm64"
14#elif defined(_M_IA64)
15#define CurrentArchitecture L"ia64"
16#elif defined(_M_PPC)
17#define CurrentArchitecture L"ppc"
18#endif
19
20static inline HRESULT
22{
24}
25
26static inline UINT
28{
29 // Attempt to extract the original Win32 error code from the HRESULT
31 return LOWORD(hr);
32 else
33 return hr >= 0 ? ERROR_SUCCESS : hr;
34}
35
36UINT
38
39VOID
41VOID
42ShowPopupMenuEx(HWND hwnd, HWND hwndOwner, UINT MenuID, UINT DefaultItem, POINT *Point = NULL);
43VOID
45UINT
47BOOL
49BOOL
51BOOL
53
54VOID
55InitLogs();
56VOID
57FreeLogs();
58BOOL
59WriteLogMessage(WORD wType, DWORD dwEventID, LPCWSTR lpMsg);
60BOOL
61GetInstalledVersion(CStringW *pszVersion, const CStringW &szRegName);
62
63typedef struct
64{
70
71static inline BOOL
72NotifyFileExtractCallback(const CStringW &ItemPath, UINT64 UncompressedSize, UINT FileAttributes,
74{
75 EXTRACTCALLBACKINFO eci = { ItemPath, UncompressedSize, FileAttributes };
76 return Callback ? Callback(eci, Cookie) : TRUE;
77}
78
79BOOL
80ExtractFilesFromCab(const CStringW &szCabName, const CStringW &szCabDir, const CStringW &szOutputDir,
82BOOL
83ExtractFilesFromCab(LPCWSTR FullCabPath, const CStringW &szOutputDir,
85
86BOOL
90
91INT
93
94void
95UnixTimeToFileTime(DWORD dwUnixTime, LPFILETIME pFileTime);
96
97BOOL
98SearchPatternMatch(LPCWSTR szHaystack, LPCWSTR szNeedle);
99
104
105bool
107
108template <class T> static CStringW
109BuildPath(const T &Base, LPCWSTR Append)
110{
112 SIZE_T len = path.GetLength();
113 if (len && path[len - 1] != L'\\' && path[len - 1] != L'/')
114 path += L'\\';
115 while (*Append == L'\\' || *Append == L'/')
116 ++Append;
117 return path + Append;
118}
119
121SplitFileAndDirectory(LPCWSTR FullPath, CStringW *pDir = NULL);
122BOOL
124UINT
132
133template <class T> class CLocalPtr : public CHeapPtr<T, CLocalAllocator>
134{
135};
136
138{
140
142 {
144 if (m_hMutex && !InitialOwner)
145 {
147 if (wait != WAIT_OBJECT_0 && wait != WAIT_ABANDONED)
148 {
150 m_hMutex = NULL;
151 }
152 }
153 }
155 {
156 if (m_hMutex)
157 {
160 }
161 }
162
163 bool Acquired() const { return m_hMutex != NULL; }
164};
165
167GuessInstallerType(LPCWSTR Installer, UINT &ExtraInfo);
168
169BOOL
unsigned long long UINT64
PRTL_UNICODE_STRING_BUFFER Path
InstallerType
Definition: appinfo.h:82
HRESULT GetKnownPath(REFKNOWNFOLDERID kfid, CStringW &Path, DWORD Flags=KF_FLAG_CREATE)
Definition: misc.cpp:564
BOOL(CALLBACK * EXTRACTCALLBACK)(const EXTRACTCALLBACKINFO &Info, void *Cookie)
Definition: misc.h:69
BOOL WriteLogMessage(WORD wType, DWORD dwEventID, LPCWSTR lpMsg)
Definition: misc.cpp:319
bool ExpandEnvStrings(CStringW &Str)
Definition: misc.cpp:497
HRESULT GetSpecialPath(UINT csidl, CStringW &Path, HWND hwnd=NULL)
Definition: misc.cpp:555
static CStringW BuildPath(const T &Base, LPCWSTR Append)
Definition: misc.h:109
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 GetSilentInstallParameters(InstallerType InstallerType, UINT ExtraInfo, LPCWSTR Installer, CStringW &Parameters)
Definition: misc.cpp:684
BOOL DeleteDirectoryTree(LPCWSTR Dir, HWND hwnd=NULL)
Definition: misc.cpp:523
UINT ClassifyFile(PCWSTR Path)
Definition: misc.cpp:125
UINT CreateDirectoryTree(LPCWSTR Dir)
Definition: misc.cpp:536
static BOOL NotifyFileExtractCallback(const CStringW &ItemPath, UINT64 UncompressedSize, UINT FileAttributes, EXTRACTCALLBACK Callback, void *Cookie)
Definition: misc.h:72
HRESULT RegKeyHasValues(HKEY hKey, LPCWSTR Path, REGSAM wowsam=0)
Definition: misc.cpp:456
InstallerType GuessInstallerType(LPCWSTR Installer, UINT &ExtraInfo)
Definition: misc.cpp:607
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:27
INT GetSystemColorDepth()
Definition: misc.cpp:405
VOID CopyTextToClipboard(LPCWSTR lpszText)
Definition: misc.cpp:28
BOOL SearchPatternMatch(LPCWSTR szHaystack, LPCWSTR szNeedle)
Definition: misc.cpp:514
LPCWSTR GetRegString(CRegKey &Key, LPCWSTR Name, CStringW &Value)
Definition: misc.cpp:474
HRESULT GetProgramFilesPath(CStringW &Path, BOOL PerUser, HWND hwnd=NULL)
Definition: misc.cpp:579
CStringW SplitFileAndDirectory(LPCWSTR FullPath, CStringW *pDir=NULL)
Definition: misc.cpp:543
BOOL IsSystem64Bit()
Definition: misc.cpp:382
ULONG GetNTVersion()
Definition: misc.cpp:395
void UnixTimeToFileTime(DWORD dwUnixTime, LPFILETIME pFileTime)
Definition: misc.cpp:445
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 L(x)
Definition: resources.c:13
#define INFINITE
Definition: serial.h:102
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
_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:2486
#define BOOL
Definition: nt_native.h:43
#define LOWORD(l)
Definition: pedump.c:82
static ULONG Timeout
Definition: ping.c:61
_In_opt_ LPCSTR lpDirectory
Definition: shellapi.h:496
HRESULT hr
Definition: shlfolder.c:183
@ KF_FLAG_CREATE
Definition: shlobj.h:106
~CScopedMutex()
Definition: misc.h:154
CScopedMutex(LPCWSTR Name, UINT Timeout=INFINITE, BOOL InitialOwner=FALSE)
Definition: misc.h:141
bool Acquired() const
Definition: misc.h:163
HANDLE m_hMutex
Definition: misc.h:139
const CStringW & ItemPath
Definition: misc.h:65
UINT64 UncompressedSize
Definition: misc.h:66
UINT FileAttributes
Definition: misc.h:67
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
uint32_t ULONG
Definition: typedefs.h:59
#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_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:869
_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:389
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WAIT_OBJECT_0
Definition: winbase.h:383
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
ACCESS_MASK REGSAM
Definition: winreg.h:76
_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