ReactOS 0.4.16-dev-1049-g378a335
misc.cpp File Reference
#include "rapps.h"
#include "misc.h"
Include dependency graph for misc.cpp:

Go to the source code of this file.

Functions

UINT ErrorBox (HWND hOwner, UINT Error)
 
VOID CopyTextToClipboard (LPCWSTR lpszText)
 
static INT_PTR CALLBACK NothingDlgProc (HWND hDlg, UINT uMsg, WPARAM, LPARAM)
 
VOID EmulateDialogReposition (HWND hwnd)
 
VOID ShowPopupMenuEx (HWND hwnd, HWND hwndOwner, UINT MenuID, UINT DefaultItem, POINT *Point)
 
BOOL IsZipFile (PCWSTR Path)
 
UINT ClassifyFile (PCWSTR Path)
 
BOOL OpensWithExplorer (PCWSTR Path)
 
BOOL StartProcess (const CStringW &Path, BOOL Wait)
 
BOOL GetStorageDirectory (CStringW &Directory)
 
VOID InitLogs ()
 
VOID FreeLogs ()
 
BOOL WriteLogMessage (WORD wType, DWORD dwEventID, LPCWSTR lpMsg)
 
BOOL GetInstalledVersion_WowUser (CStringW *szVersionResult, const CStringW &szRegName, BOOL IsUserKey, REGSAM keyWow)
 
BOOL GetInstalledVersion (CStringW *pszVersion, const CStringW &szRegName)
 
BOOL IsSystem64Bit ()
 
INT GetSystemColorDepth ()
 
void UnixTimeToFileTime (DWORD dwUnixTime, LPFILETIME pFileTime)
 
HRESULT RegKeyHasValues (HKEY hKey, LPCWSTR Path, REGSAM wowsam)
 
LPCWSTR GetRegString (CRegKey &Key, LPCWSTR Name, CStringW &Value)
 
bool ExpandEnvStrings (CStringW &Str)
 
BOOL SearchPatternMatch (LPCWSTR szHaystack, LPCWSTR szNeedle)
 
BOOL DeleteDirectoryTree (LPCWSTR Dir, HWND hwnd)
 
UINT CreateDirectoryTree (LPCWSTR Dir)
 
CStringW SplitFileAndDirectory (LPCWSTR FullPath, CStringW *pDir)
 
HRESULT GetSpecialPath (UINT csidl, CStringW &Path, HWND hwnd)
 
HRESULT GetKnownPath (REFKNOWNFOLDERID kfid, CStringW &Path, DWORD Flags)
 
HRESULT GetProgramFilesPath (CStringW &Path, BOOL PerUser, HWND hwnd)
 

Variables

static HANDLE hLog = NULL
 

Function Documentation

◆ ClassifyFile()

UINT ClassifyFile ( PCWSTR  Path)

Definition at line 125 of file misc.cpp.

126{
130 {
131 BYTE buf[8];
132 DWORD io;
133 if (!ReadFile(hFile, buf, sizeof(buf), &io, NULL) || io != sizeof(buf))
134 buf[0] = 0;
136
137 if (buf[0] == 0xD0 && buf[1] == 0xCF && buf[2] == 0x11 && buf[3] == 0xE0 &&
138 buf[4] == 0xA1 && buf[5] == 0xB1 && buf[6] == 0x1A && buf[7] == 0xE1)
139 {
140 return MAKEWORD('M', PERCEIVED_TYPE_APPLICATION); // MSI
141 }
142 if (buf[0] == 'M' || buf[0] == 'Z')
143 {
144 SHFILEINFO shfi;
145 if (SHGetFileInfoW(Path, 0, &shfi, sizeof(shfi), SHGFI_EXETYPE))
147 }
148 if (buf[0] == 'M' && buf[1] == 'S' && buf[2] == 'C' && buf[3] == 'F')
149 {
150 return MAKEWORD('C', PERCEIVED_TYPE_COMPRESSED); // CAB
151 }
152 }
153
154 if (IsZipFile(Path)) // .zip last because we want to return SFX.exe with higher priority
155 {
157 }
159}
PRTL_UNICODE_STRING_BUFFER Path
BOOL IsZipFile(PCWSTR Path)
Definition: geninst.cpp:50
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define CreateFileW
Definition: compat.h:741
#define FILE_SHARE_READ
Definition: compat.h:136
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
static HANDLE PIO_APC_ROUTINE PVOID PIO_STATUS_BLOCK io
Definition: file.c:100
_In_ HANDLE hFile
Definition: mswsock.h:90
unsigned int UINT
Definition: ndis.h:50
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path, DWORD dwFileAttributes, SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags)
Definition: shell32_main.c:430
#define SHGFI_EXETYPE
Definition: shellapi.h:171
@ PERCEIVED_TYPE_COMPRESSED
Definition: shtypes.idl:177
@ PERCEIVED_TYPE_UNKNOWN
Definition: shtypes.idl:172
@ PERCEIVED_TYPE_APPLICATION
Definition: shtypes.idl:180
#define MAKEWORD(a, b)
Definition: typedefs.h:248
unsigned char BYTE
Definition: xxhash.c:193

Referenced by ExtractAndInstallThread(), and CDownloadManager::PerformDownloadAndInstall().

◆ CopyTextToClipboard()

VOID CopyTextToClipboard ( LPCWSTR  lpszText)

Definition at line 28 of file misc.cpp.

29{
30 if (!OpenClipboard(NULL))
31 {
32 return;
33 }
34
35 HRESULT hr;
36 HGLOBAL ClipBuffer;
39
41 cchBuffer = wcslen(lpszText) + 1;
42 ClipBuffer = GlobalAlloc(GMEM_DDESHARE, cchBuffer * sizeof(WCHAR));
43
44 Buffer = (PWCHAR)GlobalLock(ClipBuffer);
45 hr = StringCchCopyW(Buffer, cchBuffer, lpszText);
46 GlobalUnlock(ClipBuffer);
47
48 if (SUCCEEDED(hr))
50
52}
#define CF_UNICODETEXT
Definition: constants.h:408
Definition: bufpool.h:45
static DWORD cchBuffer
Definition: fusion.c:85
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:324
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 526 of file misc.cpp.

527{
529 return err == ERROR_ALREADY_EXISTS ? 0 : err;
530}
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
#define err(...)
int WINAPI SHCreateDirectory(HWND hWnd, LPCWSTR path)
Definition: shlfileop.cpp:948

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

◆ DeleteDirectoryTree()

BOOL DeleteDirectoryTree ( LPCWSTR  Dir,
HWND  hwnd 
)

Definition at line 513 of file misc.cpp.

514{
515 CStringW from(Dir);
516 UINT cch = from.GetLength();
517 from.Append(L"00");
518 LPWSTR p = from.GetBuffer();
519 p[cch] = p[cch + 1] = L'\0'; // Double null-terminate
521 SHFILEOPSTRUCT shfos = { hwnd, FO_DELETE, p, NULL, (FILEOP_FLAGS)fof };
522 return SHFileOperationW(&shfos);
523}
GLfloat GLfloat p
Definition: glext.h:8902
static DWORD DWORD void LPSTR DWORD cch
Definition: str.c:202
#define L(x)
Definition: ntvdm.h:50
#define FO_DELETE
Definition: shellapi.h:139
#define FOF_NOERRORUI
Definition: shellapi.h:152
WORD FILEOP_FLAGS
Definition: shellapi.h:214
#define FOF_NOCONFIRMATION
Definition: shellapi.h:146
#define FOF_SILENT
Definition: shellapi.h:144
int WINAPI SHFileOperationW(LPSHFILEOPSTRUCTW lpFileOp)
Definition: shlfileop.cpp:2200
CardRegion * from
Definition: spigame.cpp:19
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023

Referenced by ExtractAndInstallThread(), and UninstallThread().

◆ EmulateDialogReposition()

VOID EmulateDialogReposition ( HWND  hwnd)

Definition at line 61 of file misc.cpp.

62{
63 static const DWORD DlgTmpl[] = { WS_POPUP | WS_CAPTION | WS_SYSMENU, 0, 0, 0, 0, 0 };
65 if (hDlg)
66 {
67 RECT r;
69 if (SetWindowPos(hDlg, hDlg, r.left, r.top, r.right - r.left, r.bottom - r.top, SWP_NOZORDER | SWP_NOACTIVATE))
70 {
71 SendMessage(hDlg, DM_REPOSITION, 0, 0);
72 if (GetWindowRect(hDlg, &r))
73 SetWindowPos(hwnd, hwnd, r.left, r.top, r.right - r.left, r.bottom - r.top, SWP_NOZORDER | SWP_NOACTIVATE);
74 }
75 SendMessage(hDlg, WM_CLOSE, 0, 0);
76 }
77}
static INT_PTR CALLBACK NothingDlgProc(HWND hDlg, UINT uMsg, WPARAM, LPARAM)
Definition: misc.cpp:55
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define WS_CAPTION
Definition: pedump.c:624
#define WS_SYSMENU
Definition: pedump.c:629
#define WS_POPUP
Definition: pedump.c:616
#define WM_CLOSE
Definition: winuser.h:1632
#define SWP_NOACTIVATE
Definition: winuser.h:1253
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define SendMessage
Definition: winuser.h:5863
#define CreateDialogIndirectW(h, t, w, f)
Definition: winuser.h:4294
#define SWP_NOZORDER
Definition: winuser.h:1258
#define DM_REPOSITION
Definition: winuser.h:2111

Referenced by CMainWindow::ProcessWindowMessage().

◆ ErrorBox()

UINT ErrorBox ( HWND  hOwner,
UINT  Error 
)

Definition at line 16 of file misc.cpp.

17{
18 if (!Error)
19 Error = ERROR_INTERNAL_ERROR; // Note: geninst.cpp depends on this
20 WCHAR buf[400];
23 MessageBoxW(hOwner, buf, 0, MB_OK | MB_ICONSTOP);
24 return Error;
25}
BOOL Error
Definition: chkdsk.c:66
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
#define _countof(array)
Definition: sndvol32.h:70
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:446
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:449
#define ERROR_INTERNAL_ERROR
Definition: winerror.h:840
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
#define MB_OK
Definition: winuser.h:801
#define MB_ICONSTOP
Definition: winuser.h:814

◆ ExpandEnvStrings()

bool ExpandEnvStrings ( CStringW Str)

Definition at line 487 of file misc.cpp.

488{
491 if (cch)
492 {
493 if (ExpandEnvironmentStringsW(Str, buf.GetBuffer(cch), cch) == cch)
494 {
495 buf.ReleaseBuffer(cch - 1);
496 Str = buf;
497 return true;
498 }
499 }
500 return false;
501}
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519

Referenced by ExtractAndInstallThread().

◆ FreeLogs()

VOID FreeLogs ( )

Definition at line 310 of file misc.cpp.

311{
312 if (hLog)
313 {
315 }
316}
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 372 of file misc.cpp.

373{
374 return (
375 !szRegName.IsEmpty() && (GetInstalledVersion_WowUser(pszVersion, szRegName, TRUE, KEY_WOW64_32KEY) ||
376 GetInstalledVersion_WowUser(pszVersion, szRegName, FALSE, KEY_WOW64_32KEY) ||
377 GetInstalledVersion_WowUser(pszVersion, szRegName, TRUE, KEY_WOW64_64KEY) ||
378 GetInstalledVersion_WowUser(pszVersion, szRegName, FALSE, KEY_WOW64_64KEY)));
379}
BOOL GetInstalledVersion_WowUser(CStringW *szVersionResult, const CStringW &szRegName, BOOL IsUserKey, REGSAM keyWow)
Definition: misc.cpp:335
bool IsEmpty() const noexcept
Definition: atlsimpstr.h:394
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define KEY_WOW64_32KEY
Definition: cmtypes.h:45
#define KEY_WOW64_64KEY
Definition: cmtypes.h:46

Referenced by CAvailableApplicationInfo::InsertVersionInfo().

◆ GetInstalledVersion_WowUser()

BOOL GetInstalledVersion_WowUser ( CStringW szVersionResult,
const CStringW szRegName,
BOOL  IsUserKey,
REGSAM  keyWow 
)

Definition at line 335 of file misc.cpp.

336{
337 BOOL bHasSucceded = FALSE;
340 CStringW szPath = CStringW(L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\") + szRegName;
341
342 if (key.Open(IsUserKey ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, szPath.GetString(), keyWow | KEY_READ) !=
344 {
345 return FALSE;
346 }
347
348 if (szVersionResult != NULL)
349 {
350 ULONG dwSize = MAX_PATH * sizeof(WCHAR);
351
352 if (key.QueryStringValue(L"DisplayVersion", szVersion.GetBuffer(MAX_PATH), &dwSize) == ERROR_SUCCESS)
353 {
354 szVersion.ReleaseBuffer();
355 *szVersionResult = szVersion;
356 bHasSucceded = TRUE;
357 }
358 else
359 {
360 szVersion.ReleaseBuffer();
361 }
362 }
363 else
364 {
365 bHasSucceded = TRUE;
366 }
367
368 return bHasSucceded;
369}
#define ERROR_SUCCESS
Definition: deptool.c:10
#define MAX_PATH
Definition: compat.h:34
unsigned int BOOL
Definition: ntddk_ex.h:94
LPCWSTR szPath
Definition: env.c:37
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
static LPCWSTR szVersion
Definition: asmcache.c:748
CAtlStringW CStringW
Definition: atlstr.h:130
#define KEY_READ
Definition: nt_native.h:1023
Definition: copy.c:22
uint32_t ULONG
Definition: typedefs.h:59
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define HKEY_CURRENT_USER
Definition: winreg.h:11

Referenced by GetInstalledVersion().

◆ GetKnownPath()

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

Definition at line 554 of file misc.cpp.

555{
556 PWSTR p;
557 FARPROC f = GetProcAddress(LoadLibraryW(L"SHELL32"), "SHGetKnownFolderPath");
558 if (!f)
561 if (FAILED(hr))
562 return hr;
563 Path = p;
565 return hr;
566}
int(* FARPROC)()
Definition: compat.h:36
#define GetProcAddress(x, y)
Definition: compat.h:753
#define LoadLibraryW(x)
Definition: compat.h:747
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 HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
#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 
)

Definition at line 569 of file misc.cpp.

570{
571 if (!PerUser)
573
574 HRESULT hr = GetKnownPath(FOLDERID_UserProgramFiles, Path);
575 if (FAILED(hr))
576 {
578 // Use the correct path on NT6 (on NT5 the path becomes a bit long)
579 if (SUCCEEDED(hr) && LOBYTE(GetVersion()) >= 6)
580 {
581 Path = BuildPath(Path, L"Programs"); // Should not be localized
582 }
583 }
584 return hr;
585}
static CStringW BuildPath(const T &Base, LPCWSTR Append)
Definition: misc.h:100
HRESULT GetKnownPath(REFKNOWNFOLDERID kfid, CStringW &Path, DWORD Flags)
Definition: misc.cpp:554
HRESULT GetSpecialPath(UINT csidl, CStringW &Path, HWND hwnd)
Definition: misc.cpp:545
#define LOBYTE(W)
Definition: jmemdos.c:487
DWORD WINAPI GetVersion()
Definition: redirtest.c:5
#define CSIDL_PROGRAM_FILES
Definition: shlobj.h:2218
#define CSIDL_LOCAL_APPDATA
Definition: shlobj.h:2208

Referenced by ExtractAndInstallThread().

◆ GetRegString()

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

Definition at line 464 of file misc.cpp.

465{
466 for (;;)
467 {
468 ULONG cb = 0, cch;
469 ULONG err = Key.QueryValue(Name, NULL, NULL, &cb);
470 if (err)
471 break;
472 cch = cb / sizeof(WCHAR);
473 LPWSTR p = Value.GetBuffer(cch + 1);
474 p[cch] = UNICODE_NULL;
475 err = Key.QueryValue(Name, NULL, (BYTE*)p, &cb);
476 if (err == ERROR_MORE_DATA)
477 continue;
478 if (err)
479 break;
480 Value.ReleaseBuffer();
481 return Value.GetString();
482 }
483 return NULL;
484}
#define ERROR_MORE_DATA
Definition: dderror.h:13
LPWSTR Name
Definition: desk.c:124
static HMODULE MODULEINFO DWORD cb
Definition: module.c:33
#define UNICODE_NULL
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by GetLocalizedSMFolderName(), and UninstallThread().

◆ GetSpecialPath()

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

Definition at line 545 of file misc.cpp.

546{
547 if (!SHGetSpecialFolderPathW(hwnd, Path.GetBuffer(MAX_PATH), csidl, TRUE))
548 return E_FAIL;
549 Path.ReleaseBuffer();
550 return S_OK;
551}
#define E_FAIL
Definition: ddrawi.h:102
BOOL WINAPI SHGetSpecialFolderPathW(HWND hwndOwner, LPWSTR szPath, int nFolder, BOOL bCreate)
Definition: shellpath.c:3219
#define S_OK
Definition: intsafe.h:52

Referenced by CreateMainShortcut(), and GetProgramFilesPath().

◆ GetStorageDirectory()

BOOL GetStorageDirectory ( CStringW Directory)

Definition at line 237 of file misc.cpp.

238{
239 static CStringW CachedDirectory;
240 static BOOL CachedDirectoryInitialized = FALSE;
241
242 if (!CachedDirectoryInitialized)
243 {
244 LPWSTR DirectoryStr = CachedDirectory.GetBuffer(MAX_PATH);
245 BOOL bHasPath = SHGetSpecialFolderPathW(NULL, DirectoryStr, CSIDL_LOCAL_APPDATA, TRUE);
246 if (bHasPath)
247 {
248 PathAppendW(DirectoryStr, RAPPS_NAME);
249 }
250 CachedDirectory.ReleaseBuffer();
251
252 if (bHasPath)
253 {
254 if (!CreateDirectoryW(CachedDirectory, NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
255 {
256 CachedDirectory.Empty();
257 }
258 }
259 else
260 {
261 CachedDirectory.Empty();
262 }
263
264 CachedDirectoryInitialized = TRUE;
265 }
266
267 Directory = CachedDirectory;
268 return !Directory.IsEmpty();
269}
#define RAPPS_NAME
Definition: defines.h:34
void ReleaseBuffer(_In_ int nNewLength=-1)
Definition: atlsimpstr.h:387
void Empty() noexcept
Definition: atlsimpstr.h:253
BOOL WINAPI CreateDirectoryW(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:90
#define PathAppendW
Definition: pathcch.h:309
base for all directory entries
Definition: entries.h:138
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

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

◆ GetSystemColorDepth()

INT GetSystemColorDepth ( )

Definition at line 395 of file misc.cpp.

396{
397 DEVMODEW pDevMode;
398 INT ColorDepth;
399
400 pDevMode.dmSize = sizeof(pDevMode);
401 pDevMode.dmDriverExtra = 0;
402
404 {
405 /* TODO: Error message */
406 return ILC_COLOR;
407 }
408
409 switch (pDevMode.dmBitsPerPel)
410 {
411 case 32:
412 ColorDepth = ILC_COLOR32;
413 break;
414 case 24:
415 ColorDepth = ILC_COLOR24;
416 break;
417 case 16:
418 ColorDepth = ILC_COLOR16;
419 break;
420 case 8:
421 ColorDepth = ILC_COLOR8;
422 break;
423 case 4:
424 ColorDepth = ILC_COLOR4;
425 break;
426 default:
427 ColorDepth = ILC_COLOR;
428 break;
429 }
430
431 return ColorDepth;
432}
#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 272 of file misc.cpp.

273{
275 {
276 return;
277 }
278
280 DWORD dwCategoryNum = 1;
281 DWORD dwDisp, dwData;
283
284 if (key.Create(
286 L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\ReactOS Application Manager", REG_NONE,
288 {
289 return;
290 }
291
293 {
294 return;
295 }
296
298
299 if ((key.SetStringValue(L"EventMessageFile", szPath, REG_EXPAND_SZ) == ERROR_SUCCESS) &&
300 (key.SetStringValue(L"CategoryMessageFile", szPath, REG_EXPAND_SZ) == ERROR_SUCCESS) &&
301 (key.SetDWORDValue(L"TypesSupported", dwData) == ERROR_SUCCESS) &&
302 (key.SetDWORDValue(L"CategoryCount", dwCategoryNum) == ERROR_SUCCESS))
303
304 {
305 hLog = RegisterEventSourceW(NULL, L"ReactOS Application Manager");
306 }
307}
SETTINGS_INFO SettingsInfo
Definition: winmain.cpp:21
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
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
BOOL bLogEnabled
Definition: settings.h:9
#define EVENTLOG_ERROR_TYPE
Definition: winnt_old.h:2871
#define EVENTLOG_INFORMATION_TYPE
Definition: winnt_old.h:2873
#define EVENTLOG_WARNING_TYPE
Definition: winnt_old.h:2872

Referenced by wmain(), and wWinMain().

◆ IsSystem64Bit()

BOOL IsSystem64Bit ( )

Definition at line 382 of file misc.cpp.

383{
384#ifdef _WIN64
385 return TRUE;
386#else
387 static UINT cache = 0;
388 if (!cache)
389 cache = 1 + (IsOS(OS_WOW6432) != FALSE);
390 return cache - 1;
391#endif
392}
BOOL WINAPI IsOS(DWORD feature)
Definition: ordinal.c:4107
#define OS_WOW6432
Definition: shlwapi.h:2091
Definition: cache.c:49

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

◆ IsZipFile()

BOOL IsZipFile ( PCWSTR  Path)

Definition at line 50 of file geninst.cpp.

51{
54 unzFile hzf = unzOpen2_64(Path, &zff);
55 if (!hzf)
56 return FALSE;
57 unzClose(hzf);
58 return TRUE;
59}
void fill_win32_filefunc64W(zlib_filefunc64_def *pzlib_filefunc_def)
Definition: iowin32.c:457
unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def)
Definition: unzip.c:783
int ZEXPORT unzClose(unzFile file)
Definition: unzip.c:813
voidp unzFile
Definition: unzip.h:70

Referenced by ClassifyFile().

◆ NothingDlgProc()

static INT_PTR CALLBACK NothingDlgProc ( HWND  hDlg,
UINT  uMsg,
WPARAM  ,
LPARAM   
)
static

Definition at line 55 of file misc.cpp.

56{
57 return uMsg == WM_CLOSE ? DestroyWindow(hDlg) : FALSE;
58}
BOOL WINAPI DestroyWindow(_In_ HWND)

Referenced by EmulateDialogReposition().

◆ OpensWithExplorer()

BOOL OpensWithExplorer ( PCWSTR  Path)

Definition at line 162 of file misc.cpp.

163{
164 WCHAR szCmd[MAX_PATH * 2];
165 DWORD cch = _countof(szCmd);
168 ASSOCSTR_COMMAND, pszExt, NULL, szCmd, &cch);
169 if (SUCCEEDED(hr) && StrStrIW(szCmd, L" zipfldr.dll,")) // .zip
170 return TRUE;
171 PathRemoveArgsW(szCmd);
172 return SUCCEEDED(hr) && !StrCmpIW(PathFindFileNameW(szCmd), L"explorer.exe"); // .cab
173}
LPWSTR WINAPI StrStrIW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
Definition: string.c:380
HRESULT WINAPI AssocQueryStringW(ASSOCF cfFlags, ASSOCSTR str, LPCWSTR pszAssoc, LPCWSTR pszExtra, LPWSTR pszOut, DWORD *pcchOut)
Definition: assoc.c:436
void WINAPI PathRemoveArgsW(LPWSTR lpszPath)
Definition: path.c:779
LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
Definition: path.c:394
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:447
int WINAPI StrCmpIW(LPCWSTR lpszStr, LPCWSTR lpszComp)
Definition: string.c:353
@ ASSOCSTR_COMMAND
Definition: shlwapi.h:612
@ ASSOCF_INIT_IGNOREUNKNOWN
Definition: shlwapi.h:602
@ ASSOCF_NOTRUNCATE
Definition: shlwapi.h:597
const uint16_t * PCWSTR
Definition: typedefs.h:57

Referenced by CDownloadManager::PerformDownloadAndInstall().

◆ RegKeyHasValues()

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

Definition at line 446 of file misc.cpp.

447{
448 CRegKey key;
449 LONG err = key.Open(hKey, Path, KEY_QUERY_VALUE | wowsam);
450 if (err == ERROR_SUCCESS)
451 {
452 WCHAR name[1];
453 DWORD cchname = _countof(name), cbsize = 0;
454 err = RegEnumValueW(key, 0, name, &cchname, NULL, NULL, NULL, &cbsize);
456 return S_FALSE;
457 if (err == ERROR_MORE_DATA)
459 }
460 return HRESULT_FROM_WIN32(err);
461}
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 504 of file misc.cpp.

505{
506 if (!*szNeedle)
507 return TRUE;
508 /* TODO: Improve pattern search beyond a simple case-insensitive substring search. */
509 return StrStrIW(szHaystack, szNeedle) != NULL;
510}

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

◆ ShowPopupMenuEx()

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

Definition at line 80 of file misc.cpp.

81{
82 HMENU hMenu = NULL;
83 HMENU hPopupMenu;
84 MENUITEMINFO ItemInfo;
85 POINT pt;
86
87 if (MenuID)
88 {
89 hMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(MenuID));
90 hPopupMenu = GetSubMenu(hMenu, 0);
91 }
92 else
93 {
94 hPopupMenu = GetMenu(hwnd);
95 }
96
97 ZeroMemory(&ItemInfo, sizeof(ItemInfo));
98 ItemInfo.cbSize = sizeof(ItemInfo);
99 ItemInfo.fMask = MIIM_STATE;
100
101 GetMenuItemInfoW(hPopupMenu, DefaultItem, FALSE, &ItemInfo);
102
103 if (!(ItemInfo.fState & MFS_GRAYED))
104 {
105 SetMenuDefaultItem(hPopupMenu, DefaultItem, FALSE);
106 }
107
108 if (!Point)
109 {
111 }
112
114 TrackPopupMenu(hPopupMenu, 0, Point->x, Point->y, 0, hwndOwner, NULL);
115
116 if (hMenu)
117 {
118 DestroyMenu(hMenu);
119 }
120}
#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:1743
BOOL WINAPI SetMenuDefaultItem(_In_ HMENU, _In_ UINT, _In_ UINT)
BOOL WINAPI SetForegroundWindow(_In_ HWND)
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:3032
#define MIIM_STATE
Definition: winuser.h:732
HMENU WINAPI GetSubMenu(_In_ HMENU, _In_ int)
#define MFS_GRAYED
Definition: winuser.h:762
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 
)

Definition at line 533 of file misc.cpp.

534{
535 CPathW dir = FullPath;
536 //int win = dir.ReverseFind(L'\\'), nix = dir.ReverseFind(L'/'), sep = max(win, nix);
537 int sep = dir.FindFileName();
538 CStringW file = dir.m_strPath.Mid(sep);
539 if (pDir)
540 *pDir = sep == -1 ? L"" : dir.m_strPath.Left(sep - 1);
541 return file;
542}
unsigned int dir
Definition: maze.c:112
Definition: fci.c:127

Referenced by CreateMainShortcut(), ExtractFilesFromCab(), ExtractFilesFromZip(), InstallFiles(), and UninstallThread().

◆ StartProcess()

BOOL StartProcess ( const CStringW Path,
BOOL  Wait 
)

Definition at line 176 of file misc.cpp.

177{
179 STARTUPINFOW si;
180 DWORD dwRet;
181 MSG msg;
182
183 ZeroMemory(&si, sizeof(si));
184 si.cb = sizeof(si);
186 si.wShowWindow = SW_SHOW;
187
188 // The Unicode version of CreateProcess can modify the contents of this string.
189 CStringW Tmp = Path;
190 BOOL fSuccess = CreateProcessW(NULL, Tmp.GetBuffer(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
191 Tmp.ReleaseBuffer();
192 if (!fSuccess)
193 {
194 return FALSE;
195 }
196
197 CloseHandle(pi.hThread);
198
199 if (Wait)
200 {
202 }
203
204 while (Wait)
205 {
206 dwRet = MsgWaitForMultipleObjects(1, &pi.hProcess, FALSE, INFINITE, QS_ALLEVENTS);
207 if (dwRet == WAIT_OBJECT_0 + 1)
208 {
209 while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
210 {
213 }
214 }
215 else
216 {
217 if (dwRet == WAIT_OBJECT_0 || dwRet == WAIT_FAILED)
218 break;
219 }
220 }
221
222 CloseHandle(pi.hProcess);
223
224 if (Wait)
225 {
228 // We got the real activation message during MsgWaitForMultipleObjects while
229 // we were disabled, we need to set the focus again now.
231 }
232
233 return TRUE;
234}
#define msg(x)
Definition: auth_time.c:54
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:4598
#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:877
DWORD dwFlags
Definition: winbase.h:888
WORD wShowWindow
Definition: winbase.h:889
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:517
#define WAIT_OBJECT_0
Definition: winbase.h:432
#define WAIT_FAILED
Definition: winbase.h:439
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define QS_ALLEVENTS
Definition: winuser.h:913
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:1207
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
#define SW_SHOW
Definition: winuser.h:786

Referenced by CInstalledApplicationInfo::UninstallApplication().

◆ UnixTimeToFileTime()

void UnixTimeToFileTime ( DWORD  dwUnixTime,
LPFILETIME  pFileTime 
)

Definition at line 435 of file misc.cpp.

436{
437 // Note that LONGLONG is a 64-bit value
438 LONGLONG ll;
439
440 ll = Int32x32To64(dwUnixTime, 10000000) + 116444736000000000;
441 pFileTime->dwLowDateTime = (DWORD)ll;
442 pFileTime->dwHighDateTime = ll >> 32;
443}
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 319 of file misc.cpp.

320{
322 {
323 return TRUE;
324 }
325
326 if (!ReportEventW(hLog, wType, 0, dwEventID, NULL, 1, 0, &lpMsg, NULL))
327 {
328 return FALSE;
329 }
330
331 return TRUE;
332}
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::PerformDownloadAndInstall(), and CInstalledApplicationInfo::UninstallApplication().

Variable Documentation

◆ hLog