ReactOS 0.4.15-dev-8419-g7f0e8a3
misc.h File Reference
#include <atlstr.h>
Include dependency graph for misc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  EXTRACTCALLBACKINFO
 
class  CLocalPtr< T >
 

Typedefs

typedef BOOL(CALLBACKEXTRACTCALLBACK) (const EXTRACTCALLBACKINFO &Info, void *Cookie)
 

Functions

static UINT ErrorFromHResult (HRESULT hr)
 
VOID CopyTextToClipboard (LPCWSTR lpszText)
 
VOID ShowPopupMenuEx (HWND hwnd, HWND hwndOwner, UINT MenuID, UINT DefaultItem)
 
BOOL StartProcess (const CStringW &Path, BOOL Wait)
 
BOOL GetStorageDirectory (CStringW &lpDirectory)
 
VOID InitLogs ()
 
VOID FreeLogs ()
 
BOOL WriteLogMessage (WORD wType, DWORD dwEventID, LPCWSTR lpMsg)
 
BOOL GetInstalledVersion (CStringW *pszVersion, const CStringW &szRegName)
 
static BOOL NotifyFileExtractCallback (const CStringW &ItemPath, UINT64 UncompressedSize, UINT FileAttributes, EXTRACTCALLBACK Callback, void *Cookie)
 
BOOL ExtractFilesFromCab (const CStringW &szCabName, const CStringW &szCabDir, const CStringW &szOutputDir, EXTRACTCALLBACK Callback=NULL, void *Cookie=NULL)
 
BOOL ExtractFilesFromCab (LPCWSTR FullCabPath, const CStringW &szOutputDir, EXTRACTCALLBACK Callback=NULL, void *Cookie=NULL)
 
BOOL IsSystem64Bit ()
 
INT GetSystemColorDepth ()
 
void UnixTimeToFileTime (DWORD dwUnixTime, LPFILETIME pFileTime)
 
BOOL SearchPatternMatch (LPCWSTR szHaystack, LPCWSTR szNeedle)
 
HRESULT RegKeyHasValues (HKEY hKey, LPCWSTR Path, REGSAM wowsam=0)
 
LPCWSTR GetRegString (CRegKey &Key, LPCWSTR Name, CStringW &Value)
 
bool ExpandEnvStrings (CStringW &Str)
 
template<class T >
static CStringW BuildPath (const T &Base, LPCWSTR Append)
 
CStringW SplitFileAndDirectory (LPCWSTR FullPath, CStringW *pDir=NULL)
 
BOOL DeleteDirectoryTree (LPCWSTR Dir, HWND hwnd=NULL)
 
UINT CreateDirectoryTree (LPCWSTR Dir)
 
HRESULT GetSpecialPath (UINT csidl, CStringW &Path, HWND hwnd=NULL)
 
HRESULT GetKnownPath (REFKNOWNFOLDERID kfid, CStringW &Path, DWORD Flags=KF_FLAG_CREATE)
 
HRESULT GetProgramFilesPath (CStringW &Path, BOOL PerUser, HWND hwnd=NULL)
 

Typedef Documentation

◆ EXTRACTCALLBACK

typedef BOOL(CALLBACK * EXTRACTCALLBACK) (const EXTRACTCALLBACKINFO &Info, void *Cookie)

Definition at line 53 of file misc.h.

Function Documentation

◆ BuildPath()

template<class T >
static CStringW BuildPath ( const T Base,
LPCWSTR  Append 
)
static

Definition at line 91 of file misc.h.

92{
94 SIZE_T len = path.GetLength();
95 if (len && path[len - 1] != L'\\' && path[len - 1] != L'/')
96 path += L'\\';
97 while (*Append == L'\\' || *Append == L'/')
98 ++Append;
99 return path + Append;
100}
GLenum GLsizei len
Definition: glext.h:6722
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2451
#define L(x)
Definition: ntvdm.h:50
ULONG_PTR SIZE_T
Definition: typedefs.h:80

Referenced by CreateShortcut(), ExtractAndInstallThread(), ExtractFilesFromZip(), GetCustomIconPath(), GetLocalizedSMFolderName(), GetProgramFilesPath(), InstallFiles(), and UninstallThread().

◆ CopyTextToClipboard()

VOID CopyTextToClipboard ( LPCWSTR  lpszText)

Definition at line 16 of file misc.cpp.

17{
18 if (!OpenClipboard(NULL))
19 {
20 return;
21 }
22
23 HRESULT hr;
24 HGLOBAL ClipBuffer;
27
29 cchBuffer = wcslen(lpszText) + 1;
30 ClipBuffer = GlobalAlloc(GMEM_DDESHARE, cchBuffer * sizeof(WCHAR));
31
32 Buffer = (PWCHAR)GlobalLock(ClipBuffer);
33 hr = StringCchCopyW(Buffer, cchBuffer, lpszText);
34 GlobalUnlock(ClipBuffer);
35
36 if (SUCCEEDED(hr))
38
40}
#define CF_UNICODETEXT
Definition: constants.h:408
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
static DWORD cchBuffer
Definition: fusion.c:85
unsigned long DWORD
Definition: ntddk_ex.h:95
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define SUCCEEDED(hr)
Definition: intsafe.h:50
HRESULT hr
Definition: shlfolder.c:183
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
uint16_t * PWCHAR
Definition: typedefs.h:56
#define GMEM_DDESHARE
Definition: winbase.h:298
HANDLE WINAPI SetClipboardData(_In_ UINT, _In_opt_ HANDLE)
BOOL WINAPI CloseClipboard(void)
Definition: ntwrapper.h:178
BOOL WINAPI OpenClipboard(_In_opt_ HWND)
BOOL WINAPI EmptyClipboard(void)
Definition: ntwrapper.h:190
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by CAppInfoDisplay::OnCommand().

◆ CreateDirectoryTree()

UINT CreateDirectoryTree ( LPCWSTR  Dir)

Definition at line 431 of file misc.cpp.

432{
434 return err == ERROR_ALREADY_EXISTS ? 0 : err;
435}
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
unsigned int UINT
Definition: ndis.h:50
#define err(...)
int WINAPI SHCreateDirectory(HWND hWnd, LPCWSTR path)
Definition: shlfileop.cpp:847

Referenced by ExtractAndInstallThread(), ExtractFilesFromZip(), and InstallFiles().

◆ DeleteDirectoryTree()

BOOL DeleteDirectoryTree ( LPCWSTR  Dir,
HWND  hwnd = NULL 
)

Definition at line 418 of file misc.cpp.

419{
420 CStringW from(Dir);
421 UINT cch = from.GetLength();
422 from.Append(L"00");
423 LPWSTR p = from.GetBuffer();
424 p[cch] = p[cch + 1] = L'\0'; // Double null-terminate
426 SHFILEOPSTRUCT shfos = { hwnd, FO_DELETE, p, NULL, (FILEOP_FLAGS)fof };
427 return SHFileOperationW(&shfos);
428}
GLfloat GLfloat p
Definition: glext.h:8902
static DWORD DWORD void LPSTR DWORD cch
Definition: str.c:202
#define FO_DELETE
Definition: shellapi.h:138
#define FOF_NOERRORUI
Definition: shellapi.h:151
WORD FILEOP_FLAGS
Definition: shellapi.h:213
#define FOF_NOCONFIRMATION
Definition: shellapi.h:145
#define FOF_SILENT
Definition: shellapi.h:143
int WINAPI SHFileOperationW(LPSHFILEOPSTRUCTW lpFileOp)
Definition: shlfileop.cpp:1987
CardRegion * from
Definition: spigame.cpp:19
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023

Referenced by ExtractAndInstallThread(), and UninstallThread().

◆ ErrorFromHResult()

static UINT ErrorFromHResult ( HRESULT  hr)
inlinestatic

Definition at line 20 of file misc.h.

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}
#define ERROR_SUCCESS
Definition: deptool.c:10
#define LOWORD(l)
Definition: pedump.c:82
#define HIWORD(l)
Definition: typedefs.h:247
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92

Referenced by CreateShortcut(), and ExtractAndInstallThread().

◆ ExpandEnvStrings()

bool ExpandEnvStrings ( CStringW Str)

Definition at line 392 of file misc.cpp.

393{
396 if (cch)
397 {
398 if (ExpandEnvironmentStringsW(Str, buf.GetBuffer(cch), cch) == cch)
399 {
400 buf.ReleaseBuffer(cch - 1);
401 Str = buf;
402 return true;
403 }
404 }
405 return false;
406}
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751

Referenced by ExtractAndInstallThread().

◆ ExtractFilesFromCab() [1/2]

BOOL ExtractFilesFromCab ( const CStringW szCabName,
const CStringW szCabDir,
const CStringW szOutputDir,
EXTRACTCALLBACK  Callback = NULL,
void Cookie = NULL 
)

Definition at line 249 of file cabinet.cpp.

251{
252 HINSTANCE hCabinetDll;
253 HFDI ExtractHandler;
254 ERF ExtractErrors;
255 ATL::CStringA szCabNameUTF8, szCabDirUTF8, szOutputDirUTF8;
256 fnFDICreate pfnFDICreate;
257 fnFDICopy pfnFDICopy;
258 fnFDIDestroy pfnFDIDestroy;
259 BOOL bResult;
260 NotifyData nd = { Callback, Cookie };
261
262 // Load cabinet.dll and extract needed functions
263 hCabinetDll = LoadLibraryW(L"cabinet.dll");
264
265 if (!hCabinetDll)
266 {
267 return FALSE;
268 }
269
270 pfnFDICreate = (fnFDICreate)GetProcAddress(hCabinetDll, "FDICreate");
271 pfnFDICopy = (fnFDICopy)GetProcAddress(hCabinetDll, "FDICopy");
272 pfnFDIDestroy = (fnFDIDestroy)GetProcAddress(hCabinetDll, "FDIDestroy");
273
274 if (!pfnFDICreate || !pfnFDICopy || !pfnFDIDestroy)
275 {
276 FreeLibrary(hCabinetDll);
277 return FALSE;
278 }
279
280 // Create FDI context
281 ExtractHandler = pfnFDICreate(
282 fnMemAlloc, fnMemFree, fnFileOpen, fnFileRead, fnFileWrite, fnFileClose, fnFileSeek, cpuUNKNOWN,
283 &ExtractErrors);
284
285 if (!ExtractHandler)
286 {
287 FreeLibrary(hCabinetDll);
288 return FALSE;
289 }
290
291 // Create output dir
292 bResult = CreateDirectoryW(szOutputDir, NULL);
293
294 if (bResult || GetLastError() == ERROR_ALREADY_EXISTS)
295 {
296 // Convert wide strings to UTF-8
297 bResult = WideToMultiByte(szCabName, szCabNameUTF8, CP_UTF8);
298 bResult &= WideToMultiByte(szCabDir, szCabDirUTF8, CP_UTF8);
299 bResult &= WideToMultiByte(szOutputDir, szOutputDirUTF8, CP_UTF8);
300 }
301
302 // Perform extraction
303 if (bResult)
304 {
305 // Add a slash to cab name as required by the api
306 szCabNameUTF8 = "\\" + szCabNameUTF8;
307
308 nd.OutputDir = szOutputDirUTF8.GetString();
309 bResult = pfnFDICopy(
310 ExtractHandler, (LPSTR)szCabNameUTF8.GetString(), (LPSTR)szCabDirUTF8.GetString(), 0, fnNotify, NULL,
311 (void FAR *)&nd);
312 }
313
314 pfnFDIDestroy(ExtractHandler);
315 FreeLibrary(hCabinetDll);
316 return bResult;
317}
BOOL WideToMultiByte(const CStringW &szSource, CStringA &szDest, UINT Codepage)
Definition: cabinet.cpp:26
HFDI(* fnFDICreate)(PFNALLOC, PFNFREE, PFNOPEN, PFNREAD, PFNWRITE, PFNCLOSE, PFNSEEK, int, PERF)
Definition: cabinet.cpp:239
BOOL(* fnFDICopy)(HFDI, LPSTR, LPSTR, INT, PFNFDINOTIFY, PFNFDIDECRYPT, void FAR *pvUser)
Definition: cabinet.cpp:241
BOOL(* fnFDIDestroy)(HFDI)
Definition: cabinet.cpp:243
PXSTR GetString() noexcept
Definition: atlsimpstr.h:367
#define FALSE
Definition: types.h:117
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define LoadLibraryW(x)
Definition: compat.h:747
#define FAR
Definition: zlib.h:34
BOOL WINAPI CreateDirectoryW(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:90
#define cpuUNKNOWN
Definition: fdi.h:269
unsigned int BOOL
Definition: ntddk_ex.h:94
#define CP_UTF8
Definition: nls.h:20
Definition: fci.h:44
LPCSTR OutputDir
Definition: cabinet.cpp:60
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_opt_ PVOID _Out_ PLARGE_INTEGER Cookie
Definition: cmfuncs.h:14
char * LPSTR
Definition: xmlstorage.h:182

Referenced by ExtractCab(), ExtractFilesFromCab(), and CAppDB::UpdateAvailable().

◆ ExtractFilesFromCab() [2/2]

BOOL ExtractFilesFromCab ( LPCWSTR  FullCabPath,
const CStringW szOutputDir,
EXTRACTCALLBACK  Callback = NULL,
void Cookie = NULL 
)

Definition at line 320 of file cabinet.cpp.

322{
323 CStringW dir, file = SplitFileAndDirectory(FullCabPath, &dir);
324 return ExtractFilesFromCab(file, dir, szOutputDir, Callback, Cookie);
325}
unsigned int dir
Definition: maze.c:112
CStringW SplitFileAndDirectory(LPCWSTR FullPath, CStringW *pDir=NULL)
Definition: misc.cpp:438
BOOL ExtractFilesFromCab(const CStringW &szCabName, const CStringW &szCabDir, const CStringW &szOutputDir, EXTRACTCALLBACK Callback, void *Cookie)
Definition: cabinet.cpp:249
Definition: fci.c:127

◆ FreeLogs()

VOID FreeLogs ( )

Definition at line 215 of file misc.cpp.

216{
217 if (hLog)
218 {
220 }
221}
static HANDLE hLog
Definition: misc.cpp:13
BOOL WINAPI DeregisterEventSource(IN HANDLE hEventLog)
Definition: eventlog.c:473

Referenced by CMainWindow::ProcessWindowMessage(), and wmain().

◆ GetInstalledVersion()

BOOL GetInstalledVersion ( CStringW pszVersion,
const CStringW szRegName 
)

Definition at line 277 of file misc.cpp.

278{
279 return (
280 !szRegName.IsEmpty() && (GetInstalledVersion_WowUser(pszVersion, szRegName, TRUE, KEY_WOW64_32KEY) ||
281 GetInstalledVersion_WowUser(pszVersion, szRegName, FALSE, KEY_WOW64_32KEY) ||
282 GetInstalledVersion_WowUser(pszVersion, szRegName, TRUE, KEY_WOW64_64KEY) ||
283 GetInstalledVersion_WowUser(pszVersion, szRegName, FALSE, KEY_WOW64_64KEY)));
284}
BOOL GetInstalledVersion_WowUser(CStringW *szVersionResult, const CStringW &szRegName, BOOL IsUserKey, REGSAM keyWow)
Definition: misc.cpp:240
bool IsEmpty() const noexcept
Definition: atlsimpstr.h:394
#define TRUE
Definition: types.h:120
#define KEY_WOW64_32KEY
Definition: cmtypes.h:45
#define KEY_WOW64_64KEY
Definition: cmtypes.h:46

Referenced by CAvailableApplicationInfo::InsertVersionInfo().

◆ GetKnownPath()

HRESULT GetKnownPath ( REFKNOWNFOLDERID  kfid,
CStringW Path,
DWORD  Flags = KF_FLAG_CREATE 
)

Definition at line 459 of file misc.cpp.

460{
461 PWSTR p;
462 FARPROC f = GetProcAddress(LoadLibraryW(L"SHELL32"), "SHGetKnownFolderPath");
463 if (!f)
466 if (FAILED(hr))
467 return hr;
468 Path = p;
470 return hr;
471}
PRTL_UNICODE_STRING_BUFFER Path
int(* FARPROC)()
Definition: compat.h:36
GLfloat f
Definition: glext.h:7540
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
#define FAILED(hr)
Definition: intsafe.h:51
#define f
Definition: ke_i.h:83
KNOWNFOLDERID * REFKNOWNFOLDERID
Definition: shtypes.idl:147
uint16_t * PWSTR
Definition: typedefs.h:56
PVOID HANDLE
Definition: typedefs.h:73
#define WINAPI
Definition: msvc.h:6
#define ERROR_OLD_WIN_VERSION
Definition: winerror.h:672
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by GetProgramFilesPath().

◆ GetProgramFilesPath()

HRESULT GetProgramFilesPath ( CStringW Path,
BOOL  PerUser,
HWND  hwnd = NULL 
)

Definition at line 474 of file misc.cpp.

475{
476 if (!PerUser)
478
479 HRESULT hr = GetKnownPath(FOLDERID_UserProgramFiles, Path);
480 if (FAILED(hr))
481 {
483 // Use the correct path on NT6 (on NT5 the path becomes a bit long)
484 if (SUCCEEDED(hr) && LOBYTE(GetVersion()) >= 6)
485 {
486 Path = BuildPath(Path, L"Programs"); // Should not be localized
487 }
488 }
489 return hr;
490}
static CStringW BuildPath(const T &Base, LPCWSTR Append)
Definition: misc.h:91
HRESULT GetKnownPath(REFKNOWNFOLDERID kfid, CStringW &Path, DWORD Flags)
Definition: misc.cpp:459
HRESULT GetSpecialPath(UINT csidl, CStringW &Path, HWND hwnd)
Definition: misc.cpp:450
#define LOBYTE(W)
Definition: jmemdos.c:487
DWORD WINAPI GetVersion()
Definition: redirtest.c:5
#define CSIDL_PROGRAM_FILES
Definition: shlobj.h:2209
#define CSIDL_LOCAL_APPDATA
Definition: shlobj.h:2199

Referenced by ExtractAndInstallThread().

◆ GetRegString()

LPCWSTR GetRegString ( CRegKey Key,
LPCWSTR  Name,
CStringW Value 
)

Definition at line 369 of file misc.cpp.

370{
371 for (;;)
372 {
373 ULONG cb = 0, cch;
374 ULONG err = Key.QueryValue(Name, NULL, NULL, &cb);
375 if (err)
376 break;
377 cch = cb / sizeof(WCHAR);
378 LPWSTR p = Value.GetBuffer(cch + 1);
379 p[cch] = UNICODE_NULL;
380 err = Key.QueryValue(Name, NULL, (BYTE*)p, &cb);
381 if (err == ERROR_MORE_DATA)
382 continue;
383 if (err)
384 break;
385 Value.ReleaseBuffer();
386 return Value.GetString();
387 }
388 return NULL;
389}
#define ERROR_MORE_DATA
Definition: dderror.h:13
static HMODULE MODULEINFO DWORD cb
Definition: module.c:33
#define UNICODE_NULL
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
unsigned char BYTE
Definition: xxhash.c:193

Referenced by GetLocalizedSMFolderName(), and UninstallThread().

◆ GetSpecialPath()

HRESULT GetSpecialPath ( UINT  csidl,
CStringW Path,
HWND  hwnd = NULL 
)

Definition at line 450 of file misc.cpp.

451{
452 if (!SHGetSpecialFolderPathW(hwnd, Path.GetBuffer(MAX_PATH), csidl, TRUE))
453 return E_FAIL;
454 Path.ReleaseBuffer();
455 return S_OK;
456}
#define E_FAIL
Definition: ddrawi.h:102
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI SHGetSpecialFolderPathW(HWND hwndOwner, LPWSTR szPath, int nFolder, BOOL bCreate)
Definition: shellpath.c:3092
#define S_OK
Definition: intsafe.h:52

Referenced by CreateShortcut(), and GetProgramFilesPath().

◆ GetStorageDirectory()

BOOL GetStorageDirectory ( CStringW lpDirectory)

Definition at line 142 of file misc.cpp.

143{
144 static CStringW CachedDirectory;
145 static BOOL CachedDirectoryInitialized = FALSE;
146
147 if (!CachedDirectoryInitialized)
148 {
149 LPWSTR DirectoryStr = CachedDirectory.GetBuffer(MAX_PATH);
150 BOOL bHasPath = SHGetSpecialFolderPathW(NULL, DirectoryStr, CSIDL_LOCAL_APPDATA, TRUE);
151 if (bHasPath)
152 {
153 PathAppendW(DirectoryStr, RAPPS_NAME);
154 }
155 CachedDirectory.ReleaseBuffer();
156
157 if (bHasPath)
158 {
159 if (!CreateDirectoryW(CachedDirectory, NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
160 {
161 CachedDirectory.Empty();
162 }
163 }
164 else
165 {
166 CachedDirectory.Empty();
167 }
168
169 CachedDirectoryInitialized = TRUE;
170 }
171
172 Directory = CachedDirectory;
173 return !Directory.IsEmpty();
174}
#define RAPPS_NAME
Definition: defines.h:34
void ReleaseBuffer(_In_ int nNewLength=-1)
Definition: atlsimpstr.h:387
void Empty() noexcept
Definition: atlsimpstr.h:253
#define PathAppendW
Definition: pathcch.h:309
base for all directory entries
Definition: entries.h:138

Referenced by ParseCmdAndExecute(), CAppInfoDisplay::ProcessWindowMessage(), and CDownloadManager::ThreadFunc().

◆ GetSystemColorDepth()

INT GetSystemColorDepth ( )

Definition at line 300 of file misc.cpp.

301{
302 DEVMODEW pDevMode;
303 INT ColorDepth;
304
305 pDevMode.dmSize = sizeof(pDevMode);
306 pDevMode.dmDriverExtra = 0;
307
309 {
310 /* TODO: Error message */
311 return ILC_COLOR;
312 }
313
314 switch (pDevMode.dmBitsPerPel)
315 {
316 case 32:
317 ColorDepth = ILC_COLOR32;
318 break;
319 case 24:
320 ColorDepth = ILC_COLOR24;
321 break;
322 case 16:
323 ColorDepth = ILC_COLOR16;
324 break;
325 case 8:
326 ColorDepth = ILC_COLOR8;
327 break;
328 case 4:
329 ColorDepth = ILC_COLOR4;
330 break;
331 default:
332 ColorDepth = ILC_COLOR;
333 break;
334 }
335
336 return ColorDepth;
337}
#define ILC_COLOR4
Definition: commctrl.h:354
#define ILC_COLOR16
Definition: commctrl.h:356
#define ILC_COLOR8
Definition: commctrl.h:355
#define ILC_COLOR32
Definition: commctrl.h:358
#define ILC_COLOR24
Definition: commctrl.h:357
#define ILC_COLOR
Definition: commctrl.h:352
DWORD dmBitsPerPel
Definition: wingdi.h:1647
WORD dmDriverExtra
Definition: wingdi.h:1621
WORD dmSize
Definition: wingdi.h:1620
int32_t INT
Definition: typedefs.h:58
BOOL WINAPI EnumDisplaySettingsW(LPCWSTR lpszDeviceName, DWORD iModeNum, LPDEVMODEW lpDevMode)
Definition: display.c:408
#define ENUM_CURRENT_SETTINGS
Definition: winuser.h:179

Referenced by ApplicationPageWndProc(), CMainToolbar::InitImageList(), and CAppsListView::SetDisplayAppType().

◆ InitLogs()

VOID InitLogs ( )

Definition at line 177 of file misc.cpp.

178{
180 {
181 return;
182 }
183
185 DWORD dwCategoryNum = 1;
186 DWORD dwDisp, dwData;
188
189 if (key.Create(
191 L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\ReactOS Application Manager", REG_NONE,
193 {
194 return;
195 }
196
198 {
199 return;
200 }
201
203
204 if ((key.SetStringValue(L"EventMessageFile", szPath, REG_EXPAND_SZ) == ERROR_SUCCESS) &&
205 (key.SetStringValue(L"CategoryMessageFile", szPath, REG_EXPAND_SZ) == ERROR_SUCCESS) &&
206 (key.SetDWORDValue(L"TypesSupported", dwData) == ERROR_SUCCESS) &&
207 (key.SetDWORDValue(L"CategoryCount", dwCategoryNum) == ERROR_SUCCESS))
208
209 {
210 hLog = RegisterEventSourceW(NULL, L"ReactOS Application Manager");
211 }
212}
SETTINGS_INFO SettingsInfo
Definition: winmain.cpp:20
HANDLE WINAPI RegisterEventSourceW(IN LPCWSTR lpUNCServerName, IN LPCWSTR lpSourceName)
Definition: eventlog.c:1295
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
LPCWSTR szPath
Definition: env.c:37
static HANDLE ULONG_PTR dwData
Definition: file.c:35
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
#define REG_NONE
Definition: nt_native.h:1492
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
#define _countof(array)
Definition: sndvol32.h:70
BOOL bLogEnabled
Definition: settings.h:9
Definition: copy.c:22
#define EVENTLOG_ERROR_TYPE
Definition: winnt_old.h:2834
#define EVENTLOG_INFORMATION_TYPE
Definition: winnt_old.h:2836
#define EVENTLOG_WARNING_TYPE
Definition: winnt_old.h:2835
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by wmain(), and wWinMain().

◆ IsSystem64Bit()

BOOL IsSystem64Bit ( )

Definition at line 287 of file misc.cpp.

288{
289#ifdef _WIN64
290 return TRUE;
291#else
292 static UINT cache = 0;
293 if (!cache)
294 cache = 1 + (IsOS(OS_WOW6432) != FALSE);
295 return cache - 1;
296#endif
297}
BOOL WINAPI IsOS(DWORD feature)
Definition: ordinal.c:4091
#define OS_WOW6432
Definition: shlwapi.h:2046
Definition: cache.c:49

Referenced by CAppDB::EnumInstalledRootKey(), and ExtractAndInstallThread().

◆ NotifyFileExtractCallback()

static BOOL NotifyFileExtractCallback ( const CStringW ItemPath,
UINT64  UncompressedSize,
UINT  FileAttributes,
EXTRACTCALLBACK  Callback,
void Cookie 
)
inlinestatic

Definition at line 56 of file misc.h.

58{
59 EXTRACTCALLBACKINFO eci = { ItemPath, UncompressedSize, FileAttributes };
60 return Callback ? Callback(eci, Cookie) : TRUE;
61}
_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

Referenced by ExtractFilesFromZip(), and FNFDINOTIFY().

◆ RegKeyHasValues()

HRESULT RegKeyHasValues ( HKEY  hKey,
LPCWSTR  Path,
REGSAM  wowsam = 0 
)

Definition at line 351 of file misc.cpp.

352{
353 CRegKey key;
354 LONG err = key.Open(hKey, Path, KEY_QUERY_VALUE | wowsam);
355 if (err == ERROR_SUCCESS)
356 {
357 WCHAR name[1];
358 DWORD cchname = _countof(name), cbsize = 0;
359 err = RegEnumValueW(key, 0, name, &cchname, NULL, NULL, NULL, &cbsize);
361 return S_FALSE;
362 if (err == ERROR_MORE_DATA)
364 }
365 return HRESULT_FROM_WIN32(err);
366}
LONG WINAPI RegEnumValueW(_In_ HKEY hKey, _In_ DWORD index, _Out_ LPWSTR value, _Inout_ PDWORD val_count, _Reserved_ PDWORD reserved, _Out_opt_ PDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ PDWORD count)
Definition: reg.c:2830
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
FxAutoRegKey hKey
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
long LONG
Definition: pedump.c:60
Definition: name.c:39
#define S_FALSE
Definition: winerror.h:2357

Referenced by UninstallThread().

◆ SearchPatternMatch()

BOOL SearchPatternMatch ( LPCWSTR  szHaystack,
LPCWSTR  szNeedle 
)

Definition at line 409 of file misc.cpp.

410{
411 if (!*szNeedle)
412 return TRUE;
413 /* TODO: Improve pattern search beyond a simple case-insensitive substring search. */
414 return StrStrIW(szHaystack, szNeedle) != NULL;
415}
LPWSTR WINAPI StrStrIW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
Definition: string.c:384

Referenced by CMainWindow::AddApplicationsToView(), HandleFindCommand(), and SearchForAppWithDisplayName().

◆ ShowPopupMenuEx()

VOID ShowPopupMenuEx ( HWND  hwnd,
HWND  hwndOwner,
UINT  MenuID,
UINT  DefaultItem 
)

Definition at line 43 of file misc.cpp.

44{
45 HMENU hMenu = NULL;
46 HMENU hPopupMenu;
47 MENUITEMINFO ItemInfo;
48 POINT pt;
49
50 if (MenuID)
51 {
52 hMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(MenuID));
53 hPopupMenu = GetSubMenu(hMenu, 0);
54 }
55 else
56 {
57 hPopupMenu = GetMenu(hwnd);
58 }
59
60 ZeroMemory(&ItemInfo, sizeof(ItemInfo));
61 ItemInfo.cbSize = sizeof(ItemInfo);
62 ItemInfo.fMask = MIIM_STATE;
63
64 GetMenuItemInfoW(hPopupMenu, DefaultItem, FALSE, &ItemInfo);
65
66 if (!(ItemInfo.fState & MFS_GRAYED))
67 {
68 SetMenuDefaultItem(hPopupMenu, DefaultItem, FALSE);
69 }
70
72
74 TrackPopupMenu(hPopupMenu, 0, pt.x, pt.y, 0, hwndOwner, NULL);
75
76 if (hMenu)
77 {
78 DestroyMenu(hMenu);
79 }
80}
#define pt(x, y)
Definition: drawing.c:79
HINSTANCE hInst
Definition: dxdiag.c:13
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
#define ZeroMemory
Definition: winbase.h:1712
BOOL WINAPI SetMenuDefaultItem(_In_ HMENU, _In_ UINT, _In_ UINT)
BOOL WINAPI SetForegroundWindow(_In_ HWND)
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2714
#define MIIM_STATE
Definition: winuser.h:721
HMENU WINAPI GetSubMenu(_In_ HMENU, _In_ int)
#define MFS_GRAYED
Definition: winuser.h:751
BOOL WINAPI DestroyMenu(_In_ HMENU)
BOOL WINAPI GetMenuItemInfoW(_In_ HMENU, _In_ UINT, _In_ BOOL, _Inout_ LPMENUITEMINFOW)
BOOL WINAPI TrackPopupMenu(_In_ HMENU, _In_ UINT, _In_ int, _In_ int, _Reserved_ int, _In_ HWND, _Reserved_ LPCRECT)
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
HMENU WINAPI LoadMenuW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
HMENU WINAPI GetMenu(_In_ HWND)

Referenced by CAppInfoDisplay::OnLink(), and CApplicationView::ProcessWindowMessage().

◆ SplitFileAndDirectory()

CStringW SplitFileAndDirectory ( LPCWSTR  FullPath,
CStringW pDir = NULL 
)

Definition at line 438 of file misc.cpp.

439{
440 CPathW dir = FullPath;
441 //int win = dir.ReverseFind(L'\\'), nix = dir.ReverseFind(L'/'), sep = max(win, nix);
442 int sep = dir.FindFileName();
443 CStringW file = dir.m_strPath.Mid(sep);
444 if (pDir)
445 *pDir = sep == -1 ? L"" : dir.m_strPath.Left(sep - 1);
446 return file;
447}

Referenced by CreateShortcut(), ExtractAndInstallThread(), ExtractFilesFromCab(), ExtractFilesFromZip(), InstallFiles(), and UninstallThread().

◆ StartProcess()

BOOL StartProcess ( const CStringW Path,
BOOL  Wait 
)

Definition at line 83 of file misc.cpp.

84{
86 STARTUPINFOW si;
87 DWORD dwRet;
88 MSG msg;
89
90 ZeroMemory(&si, sizeof(si));
91 si.cb = sizeof(si);
94
95 // The Unicode version of CreateProcess can modify the contents of this string.
96 CStringW Tmp = Path;
97 BOOL fSuccess = CreateProcessW(NULL, Tmp.GetBuffer(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
98 Tmp.ReleaseBuffer();
99 if (!fSuccess)
100 {
101 return FALSE;
102 }
103
104 CloseHandle(pi.hThread);
105
106 if (Wait)
107 {
109 }
110
111 while (Wait)
112 {
113 dwRet = MsgWaitForMultipleObjects(1, &pi.hProcess, FALSE, INFINITE, QS_ALLEVENTS);
114 if (dwRet == WAIT_OBJECT_0 + 1)
115 {
116 while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
117 {
120 }
121 }
122 else
123 {
124 if (dwRet == WAIT_OBJECT_0 || dwRet == WAIT_FAILED)
125 break;
126 }
127 }
128
129 CloseHandle(pi.hProcess);
130
131 if (Wait)
132 {
136 }
137
138 return TRUE;
139}
#define msg(x)
Definition: auth_time.c:54
#define CloseHandle
Definition: compat.h:739
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4592
#define INFINITE
Definition: serial.h:102
HWND hMainWnd
Definition: magnifier.c:32
static refpint_t pi[]
Definition: server.c:96
DWORD cb
Definition: winbase.h:852
DWORD dwFlags
Definition: winbase.h:863
WORD wShowWindow
Definition: winbase.h:864
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:170
#define STARTF_USESHOWWINDOW
Definition: winbase.h:491
#define WAIT_OBJECT_0
Definition: winbase.h:406
#define WAIT_FAILED
Definition: winbase.h:413
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define QS_ALLEVENTS
Definition: winuser.h:902
DWORD WINAPI MsgWaitForMultipleObjects(_In_ DWORD nCount, _In_reads_opt_(nCount) CONST HANDLE *pHandles, _In_ BOOL fWaitAll, _In_ DWORD dwMilliseconds, _In_ DWORD dwWakeMask)
HWND WINAPI SetFocus(_In_opt_ HWND)
BOOL WINAPI PeekMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT, _In_ UINT)
#define PM_REMOVE
Definition: winuser.h:1196
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
#define SW_SHOW
Definition: winuser.h:775

Referenced by CInstalledApplicationInfo::UninstallApplication().

◆ UnixTimeToFileTime()

void UnixTimeToFileTime ( DWORD  dwUnixTime,
LPFILETIME  pFileTime 
)

Definition at line 340 of file misc.cpp.

341{
342 // Note that LONGLONG is a 64-bit value
343 LONGLONG ll;
344
345 ll = Int32x32To64(dwUnixTime, 10000000) + 116444736000000000;
346 pFileTime->dwLowDateTime = (DWORD)ll;
347 pFileTime->dwHighDateTime = ll >> 32;
348}
w ll
Definition: byte_order.h:167
#define DWORD
Definition: nt_native.h:44
#define Int32x32To64(a, b)
DWORD dwHighDateTime
Definition: mapidefs.h:66
DWORD dwLowDateTime
Definition: mapidefs.h:65
int64_t LONGLONG
Definition: typedefs.h:68

Referenced by CInstalledApplicationInfo::RetrieveInstallDate().

◆ WriteLogMessage()

BOOL WriteLogMessage ( WORD  wType,
DWORD  dwEventID,
LPCWSTR  lpMsg 
)

Definition at line 224 of file misc.cpp.

225{
227 {
228 return TRUE;
229 }
230
231 if (!ReportEventW(hLog, wType, 0, dwEventID, NULL, 1, 0, &lpMsg, NULL))
232 {
233 return FALSE;
234 }
235
236 return TRUE;
237}
BOOL WINAPI ReportEventW(IN HANDLE hEventLog, IN WORD wType, IN WORD wCategory, IN DWORD dwEventID, IN PSID lpUserSid, IN WORD wNumStrings, IN DWORD dwDataSize, IN LPCWSTR *lpStrings, IN LPVOID lpRawData)
Definition: eventlog.c:1516

Referenced by CDownloadManager::ThreadFunc(), and CInstalledApplicationInfo::UninstallApplication().