ReactOS 0.4.17-dev-243-g1369312
misc.h File Reference
#include <atlstr.h>
#include "appinfo.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  Deleter< T >
 
struct  EXTRACTCALLBACKINFO
 
class  CLocalPtr< T >
 
struct  CScopedMutex
 

Typedefs

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

Functions

static HRESULT HResultFromWin32 (UINT Error)
 
static UINT ErrorFromHResult (HRESULT hr)
 
UINT ErrorBox (HWND hOwner, UINT Error=GetLastError())
 
VOID CopyTextToClipboard (LPCWSTR lpszText)
 
VOID ShowPopupMenuEx (HWND hwnd, HWND hwndOwner, UINT MenuID, UINT DefaultItem, POINT *Point=NULL)
 
VOID EmulateDialogReposition (HWND hwnd)
 
UINT ClassifyFile (PCWSTR Path)
 
BOOL OpensWithExplorer (PCWSTR Path)
 
UINT WaitForProcess (HANDLE hProcess)
 
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 ()
 
ULONG GetNTVersion ()
 
INT GetSystemColorDepth ()
 
void UnixTimeToFileTime (DWORD dwUnixTime, LPFILETIME pFileTime)
 
BOOL SearchPatternMatch (LPCWSTR szHaystack, LPCWSTR szNeedle)
 
BOOL IsSameRegKey (HKEY hRoot, LPCWSTR Path1, REGSAM Sam1, LPCWSTR Path2, REGSAM Sam2)
 
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)
 
InstallerType GuessInstallerType (LPCWSTR Installer, UINT &ExtraInfo)
 
BOOL GetSilentInstallParameters (InstallerType InstallerType, UINT ExtraInfo, LPCWSTR Installer, CStringW &Parameters)
 

Typedef Documentation

◆ EXTRACTCALLBACK

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

Definition at line 78 of file misc.h.

Function Documentation

◆ BuildPath()

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

Definition at line 120 of file misc.h.

121{
123 SIZE_T len = path.GetLength();
124 if (len && path[len - 1] != L'\\' && path[len - 1] != L'/')
125 path += L'\\';
126 while (*Append == L'\\' || *Append == L'/')
127 ++Append;
128 return path + Append;
129}
#define L(x)
Definition: resources.c:13
GLenum GLsizei len
Definition: glext.h:6722
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2486
ULONG_PTR SIZE_T
Definition: typedefs.h:80

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

◆ ClassifyFile()

UINT ClassifyFile ( PCWSTR  Path)

Definition at line 127 of file misc.cpp.

128{
132 {
133 BYTE buf[8];
134 DWORD io;
135 if (!ReadFile(hFile, buf, sizeof(buf), &io, NULL) || io != sizeof(buf))
136 buf[0] = 0;
138
139 if (buf[0] == 0xD0 && buf[1] == 0xCF && buf[2] == 0x11 && buf[3] == 0xE0 &&
140 buf[4] == 0xA1 && buf[5] == 0xB1 && buf[6] == 0x1A && buf[7] == 0xE1)
141 {
142 return MAKEWORD('M', PERCEIVED_TYPE_APPLICATION); // MSI
143 }
144 if (buf[0] == 'M' || buf[0] == 'Z')
145 {
146 SHFILEINFO shfi;
147 if (SHGetFileInfoW(Path, 0, &shfi, sizeof(shfi), SHGFI_EXETYPE))
149 }
150 if (buf[0] == 'M' && buf[1] == 'S' && buf[2] == 'C' && buf[3] == 'F')
151 {
152 return MAKEWORD('C', PERCEIVED_TYPE_COMPRESSED); // CAB
153 }
154 }
155
156 if (IsZipFile(Path)) // .zip last because we want to return SFX.exe with higher priority
157 {
159 }
161}
PRTL_UNICODE_STRING_BUFFER Path
BOOL IsZipFile(PCWSTR Path)
Definition: geninst.cpp:51
#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:72
_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:170
@ 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 ExtractArchive(), and CDownloadManager::PerformDownloadAndInstall().

◆ CopyTextToClipboard()

VOID CopyTextToClipboard ( LPCWSTR  lpszText)

Definition at line 30 of file misc.cpp.

31{
32 if (!OpenClipboard(NULL))
33 {
34 return;
35 }
36
37 HRESULT hr;
38 HGLOBAL ClipBuffer;
41
43 cchBuffer = wcslen(lpszText) + 1;
44 ClipBuffer = GlobalAlloc(GMEM_DDESHARE, cchBuffer * sizeof(WCHAR));
45
46 Buffer = (PWCHAR)GlobalLock(ClipBuffer);
47 hr = StringCchCopyW(Buffer, cchBuffer, lpszText);
48 GlobalUnlock(ClipBuffer);
49
50 if (SUCCEEDED(hr))
52
54}
#define CF_UNICODETEXT
Definition: constants.h:408
Definition: bufpool.h:45
HRESULT hr
Definition: delayimp.cpp:582
static DWORD cchBuffer
Definition: fusion.c:85
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2983
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
#define SUCCEEDED(hr)
Definition: intsafe.h:50
static ERESOURCE GlobalLock
Definition: sys_arch.c:8
short WCHAR
Definition: pedump.c:58
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
uint16_t * LPWSTR
Definition: typedefs.h:56
uint16_t * PWCHAR
Definition: typedefs.h:56
#define GMEM_DDESHARE
Definition: winbase.h:322
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

Referenced by CAppInfoDisplay::OnCommand().

◆ CreateDirectoryTree()

UINT CreateDirectoryTree ( LPCWSTR  Dir)

Definition at line 566 of file misc.cpp.

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

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

◆ DeleteDirectoryTree()

BOOL DeleteDirectoryTree ( LPCWSTR  Dir,
HWND  hwnd = NULL 
)

Definition at line 553 of file misc.cpp.

554{
555 CStringW from(Dir);
556 UINT cch = from.GetLength();
557 from.Append(L"00");
558 LPWSTR p = from.GetBuffer();
559 p[cch] = p[cch + 1] = L'\0'; // Double null-terminate
561 SHFILEOPSTRUCT shfos = { hwnd, FO_DELETE, p, NULL, (FILEOP_FLAGS)fof };
562 return SHFileOperationW(&shfos);
563}
GLfloat GLfloat p
Definition: glext.h:8902
_In_ UINT _In_ UINT cch
Definition: shellapi.h:432
#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:2200
CardRegion * from
Definition: spigame.cpp:19
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023

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

◆ EmulateDialogReposition()

VOID EmulateDialogReposition ( HWND  hwnd)

Definition at line 63 of file misc.cpp.

64{
65 static const DWORD DlgTmpl[] = { WS_POPUP | WS_CAPTION | WS_SYSMENU, 0, 0, 0, 0, 0 };
67 if (hDlg)
68 {
69 RECT r;
71 if (SetWindowPos(hDlg, hDlg, r.left, r.top, r.right - r.left, r.bottom - r.top, SWP_NOZORDER | SWP_NOACTIVATE))
72 {
73 SendMessage(hDlg, DM_REPOSITION, 0, 0);
74 if (GetWindowRect(hDlg, &r))
75 SetWindowPos(hwnd, hwnd, r.left, r.top, r.right - r.left, r.bottom - r.top, SWP_NOZORDER | SWP_NOACTIVATE);
76 }
77 SendMessage(hDlg, WM_CLOSE, 0, 0);
78 }
79}
static INT_PTR CALLBACK NothingDlgProc(HWND hDlg, UINT uMsg, WPARAM, LPARAM)
Definition: misc.cpp:57
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:1649
#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:6009
#define CreateDialogIndirectW(h, t, w, f)
Definition: winuser.h:4437
#define SWP_NOZORDER
Definition: winuser.h:1258
#define DM_REPOSITION
Definition: winuser.h:2136

Referenced by CMainWindow::ProcessWindowMessage().

◆ ErrorBox()

UINT ErrorBox ( HWND  hOwner,
UINT  Error = GetLastError() 
)

Definition at line 18 of file misc.cpp.

19{
20 if (!Error)
21 Error = ERROR_INTERNAL_ERROR; // Note: geninst.cpp depends on this
22 WCHAR buf[400];
25 MessageBoxW(hOwner, buf, 0, MB_OK | MB_ICONSTOP);
26 return Error;
27}
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:397
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:400
#define ERROR_INTERNAL_ERROR
Definition: winerror.h:1185
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

◆ ErrorFromHResult()

static UINT ErrorFromHResult ( HRESULT  hr)
inlinestatic

Definition at line 34 of file misc.h.

35{
36 // Attempt to extract the original Win32 error code from the HRESULT
38 return LOWORD(hr);
39 else
40 return hr >= 0 ? ERROR_SUCCESS : hr;
41}
#define ERROR_SUCCESS
Definition: deptool.c:10
#define LOWORD(l)
Definition: pedump.c:82
#define HIWORD(l)
Definition: typedefs.h:247
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210

Referenced by CreateMainShortcut(), and ExtractAndInstallThread().

◆ ExpandEnvStrings()

bool ExpandEnvStrings ( CStringW Str)

Definition at line 527 of file misc.cpp.

528{
531 if (cch)
532 {
533 if (ExpandEnvironmentStringsW(Str, buf.GetBuffer(cch), cch) == cch)
534 {
535 buf.ReleaseBuffer(cch - 1);
536 Str = buf;
537 return true;
538 }
539 }
540 return false;
541}
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:492

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 250 of file cabinet.cpp.

252{
253 HINSTANCE hCabinetDll;
254 HFDI ExtractHandler;
255 ERF ExtractErrors;
256 ATL::CStringA szCabNameUTF8, szCabDirUTF8, szOutputDirUTF8;
257 fnFDICreate pfnFDICreate;
258 fnFDICopy pfnFDICopy;
259 fnFDIDestroy pfnFDIDestroy;
260 BOOL bResult;
261 NotifyData nd = { Callback, Cookie };
262
263 // Load cabinet.dll and extract needed functions
264 hCabinetDll = LoadLibraryW(L"cabinet.dll");
265
266 if (!hCabinetDll)
267 {
268 return FALSE;
269 }
270
271 pfnFDICreate = (fnFDICreate)GetProcAddress(hCabinetDll, "FDICreate");
272 pfnFDICopy = (fnFDICopy)GetProcAddress(hCabinetDll, "FDICopy");
273 pfnFDIDestroy = (fnFDIDestroy)GetProcAddress(hCabinetDll, "FDIDestroy");
274
275 if (!pfnFDICreate || !pfnFDICopy || !pfnFDIDestroy)
276 {
277 FreeLibrary(hCabinetDll);
278 return FALSE;
279 }
280
281 // Create FDI context
282 ExtractHandler = pfnFDICreate(
283 fnMemAlloc, fnMemFree, fnFileOpen, fnFileRead, fnFileWrite, fnFileClose, fnFileSeek, cpuUNKNOWN,
284 &ExtractErrors);
285
286 if (!ExtractHandler)
287 {
288 FreeLibrary(hCabinetDll);
289 return FALSE;
290 }
291
292 // Create output dir
293 bResult = CreateDirectoryW(szOutputDir, NULL);
294
295 if (bResult || GetLastError() == ERROR_ALREADY_EXISTS)
296 {
297 // Convert wide strings to UTF-8
298 bResult = WideToMultiByte(szCabName, szCabNameUTF8, CP_UTF8);
299 bResult &= WideToMultiByte(szCabDir, szCabDirUTF8, CP_UTF8);
300 bResult &= WideToMultiByte(szOutputDir, szOutputDirUTF8, CP_UTF8);
301 }
302
303 // Perform extraction
304 if (bResult)
305 {
306 // Add a slash to cab name as required by the api
307 szCabNameUTF8 = "\\" + szCabNameUTF8;
308
309 nd.OutputDir = szOutputDirUTF8.GetString();
310 bResult = pfnFDICopy(
311 ExtractHandler, (LPSTR)szCabNameUTF8.GetString(), (LPSTR)szCabDirUTF8.GetString(), 0, fnNotify, NULL,
312 (void FAR *)&nd);
313 }
314
315 pfnFDIDestroy(ExtractHandler);
316 FreeLibrary(hCabinetDll);
317 return bResult;
318}
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:240
BOOL(* fnFDICopy)(HFDI, LPSTR, LPSTR, INT, PFNFDINOTIFY, PFNFDIDECRYPT, void FAR *pvUser)
Definition: cabinet.cpp:242
BOOL(* fnFDIDestroy)(HFDI)
Definition: cabinet.cpp:244
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:58
#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
char * LPSTR
Definition: typedefs.h:51
_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

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 321 of file cabinet.cpp.

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

◆ FreeLogs()

VOID FreeLogs ( )

Definition at line 314 of file misc.cpp.

315{
316 if (hLog)
317 {
319 }
320}
static HANDLE hLog
Definition: misc.cpp:15
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 376 of file misc.cpp.

377{
378 return (
379 !szRegName.IsEmpty() && (GetInstalledVersion_WowUser(pszVersion, szRegName, TRUE, KEY_WOW64_32KEY) ||
380 GetInstalledVersion_WowUser(pszVersion, szRegName, FALSE, KEY_WOW64_32KEY) ||
381 GetInstalledVersion_WowUser(pszVersion, szRegName, TRUE, KEY_WOW64_64KEY) ||
382 GetInstalledVersion_WowUser(pszVersion, szRegName, FALSE, KEY_WOW64_64KEY)));
383}
BOOL GetInstalledVersion_WowUser(CStringW *szVersionResult, const CStringW &szRegName, BOOL IsUserKey, REGSAM keyWow)
Definition: misc.cpp:339
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(), and CAvailableApplicationInfo::IsInstalled().

◆ GetKnownPath()

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

Definition at line 594 of file misc.cpp.

595{
596 PWSTR p;
597 FARPROC f = GetProcAddress(LoadLibraryW(L"SHELL32"), "SHGetKnownFolderPath");
598 if (!f)
601 if (FAILED(hr))
602 return hr;
603 Path = p;
605 return hr;
606}
int(* FARPROC)()
Definition: compat.h:36
GLfloat f
Definition: glext.h:7540
#define FAILED(hr)
Definition: intsafe.h:51
#define f
Definition: ke_i.h:83
void WINAPI CoTaskMemFree(void *ptr)
Definition: malloc.c:389
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:996
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by GetProgramFilesPath().

◆ GetNTVersion()

ULONG GetNTVersion ( )

Definition at line 399 of file misc.cpp.

400{
402 osvi.dwOSVersionInfoSize = sizeof(osvi);
404
405 return (osvi.dwMajorVersion << 8) | (osvi.dwMinorVersion);
406}
NTSTATUS NTAPI RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
Definition: version.c:182
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:237
ULONG dwMajorVersion
Definition: rtltypes.h:238
ULONG dwMinorVersion
Definition: rtltypes.h:239
OSVERSIONINFO osvi
Definition: ver.c:28

◆ GetProgramFilesPath()

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

Definition at line 609 of file misc.cpp.

610{
611 if (!PerUser)
613
614 HRESULT hr = GetKnownPath(FOLDERID_UserProgramFiles, Path);
615 if (FAILED(hr))
616 {
618 // Use the correct path on NT6 (on NT5 the path becomes a bit long)
619 if (SUCCEEDED(hr) && LOBYTE(GetVersion()) >= 6)
620 {
621 Path = BuildPath(Path, L"Programs"); // Should not be localized
622 }
623 }
624 return hr;
625}
static CStringW BuildPath(const T &Base, LPCWSTR Append)
Definition: misc.h:120
HRESULT GetKnownPath(REFKNOWNFOLDERID kfid, CStringW &Path, DWORD Flags)
Definition: misc.cpp:594
HRESULT GetSpecialPath(UINT csidl, CStringW &Path, HWND hwnd)
Definition: misc.cpp:585
DWORD WINAPI GetVersion(void)
Definition: version.c:1458
#define LOBYTE(W)
Definition: jmemdos.c:487
#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 504 of file misc.cpp.

505{
506 for (;;)
507 {
508 ULONG cb = 0, cch;
509 ULONG err = Key.QueryValue(Name, NULL, NULL, &cb);
510 if (err)
511 break;
512 cch = cb / sizeof(WCHAR);
513 LPWSTR p = Value.GetBuffer(cch + 1);
514 p[cch] = UNICODE_NULL;
515 err = Key.QueryValue(Name, NULL, (BYTE*)p, &cb);
516 if (err == ERROR_MORE_DATA)
517 continue;
518 if (err)
519 break;
520 Value.ReleaseBuffer();
521 return Value.GetString();
522 }
523 return NULL;
524}
#define ERROR_MORE_DATA
Definition: dderror.h:13
LPWSTR Name
Definition: desk.c:124
static MonoProfilerRuntimeShutdownBeginCallback cb
Definition: metahost.c:118
#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

Referenced by CRegTreeOptions::AddItemsFromRegistry(), GetLocalizedSMFolderName(), CRegTreeOptions::GetSetState(), and UninstallThread().

◆ GetSilentInstallParameters()

BOOL GetSilentInstallParameters ( InstallerType  InstallerType,
UINT  ExtraInfo,
LPCWSTR  Installer,
CStringW Parameters 
)

Definition at line 714 of file misc.cpp.

715{
716 switch (InstallerType)
717 {
718 case INSTALLER_MSI:
719 {
720 Parameters.Format(L"/i \"%s\" /qn", Installer);
721 return TRUE;
722 }
723
724 case INSTALLER_INNO:
725 {
726 LPCWSTR pszInnoParams = L"/SILENT /VERYSILENT /SP-";
727 if (ExtraInfo)
728 Parameters.Format(L"%s", pszInnoParams);
729 else
730 Parameters.Format(L"%s /SUPPRESSMSGBOXES", pszInnoParams); // https://jrsoftware.org/files/is5.5-whatsnew.htm
731 return TRUE;
732 }
733
734 case INSTALLER_NSIS:
735 {
736 Parameters = L"/S";
737 return TRUE;
738 }
739
740 default:
741 {
742 return FALSE;
743 }
744 }
745}
InstallerType
Definition: appinfo.h:82
@ INSTALLER_NSIS
Definition: appinfo.h:88
@ INSTALLER_INNO
Definition: appinfo.h:87
@ INSTALLER_MSI
Definition: appinfo.h:86
const uint16_t * LPCWSTR
Definition: typedefs.h:57
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:869

Referenced by CDownloadManager::PerformDownloadAndInstall().

◆ GetSpecialPath()

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

Definition at line 585 of file misc.cpp.

586{
587 if (!SHGetSpecialFolderPathW(hwnd, Path.GetBuffer(MAX_PATH), csidl, TRUE))
588 return E_FAIL;
589 Path.ReleaseBuffer();
590 return S_OK;
591}
#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:3219
#define S_OK
Definition: intsafe.h:52

Referenced by CreateMainShortcut(), and GetProgramFilesPath().

◆ GetStorageDirectory()

BOOL GetStorageDirectory ( CStringW lpDirectory)

Definition at line 241 of file misc.cpp.

242{
243 static CStringW CachedDirectory;
244 static BOOL CachedDirectoryInitialized = FALSE;
245
246 if (!CachedDirectoryInitialized)
247 {
248 LPWSTR DirectoryStr = CachedDirectory.GetBuffer(MAX_PATH);
249 BOOL bHasPath = SHGetSpecialFolderPathW(NULL, DirectoryStr, CSIDL_LOCAL_APPDATA, TRUE);
250 if (bHasPath)
251 {
252 PathAppendW(DirectoryStr, RAPPS_NAME);
253 }
254 CachedDirectory.ReleaseBuffer();
255
256 if (bHasPath)
257 {
258 if (!CreateDirectoryW(CachedDirectory, NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
259 {
260 CachedDirectory.Empty();
261 }
262 }
263 else
264 {
265 CachedDirectory.Empty();
266 }
267
268 CachedDirectoryInitialized = TRUE;
269 }
270
271 Directory = CachedDirectory;
272 return !Directory.IsEmpty();
273}
#define RAPPS_NAME
Definition: defines.h:34
void ReleaseBuffer(_In_ int nNewLength=-1)
Definition: atlsimpstr.h:387
void Empty() noexcept
Definition: atlsimpstr.h:253
_In_ BOOLEAN _In_ USHORT Directory
Definition: rtlfuncs.h:3942
#define PathAppendW
Definition: pathcch.h:310

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

◆ GetSystemColorDepth()

INT GetSystemColorDepth ( )

Definition at line 409 of file misc.cpp.

410{
411 DEVMODEW pDevMode;
412 INT ColorDepth;
413
414 pDevMode.dmSize = sizeof(pDevMode);
415 pDevMode.dmDriverExtra = 0;
416
418 {
419 /* TODO: Error message */
420 return ILC_COLOR;
421 }
422
423 switch (pDevMode.dmBitsPerPel)
424 {
425 case 32:
426 ColorDepth = ILC_COLOR32;
427 break;
428 case 24:
429 ColorDepth = ILC_COLOR24;
430 break;
431 case 16:
432 ColorDepth = ILC_COLOR16;
433 break;
434 case 8:
435 ColorDepth = ILC_COLOR8;
436 break;
437 case 4:
438 ColorDepth = ILC_COLOR4;
439 break;
440 default:
441 ColorDepth = ILC_COLOR;
442 break;
443 }
444
445 return ColorDepth;
446}
#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:2093
WORD dmDriverExtra
Definition: wingdi.h:2067
WORD dmSize
Definition: wingdi.h:2066
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().

◆ GuessInstallerType()

InstallerType GuessInstallerType ( LPCWSTR  Installer,
UINT ExtraInfo 
)

Definition at line 637 of file misc.cpp.

638{
639 ExtraInfo = 0;
641
644 return it;
645
646 BYTE buf[0x30 + 12];
647 if (!ReadAt(hFile, 0, buf, sizeof(buf)))
648 goto done;
649
650 if (buf[0] == 0xD0 && buf[1] == 0xCF && buf[2] == 0x11 && buf[3] == 0xE0)
651 {
652 if (!StrCmpIW(L".msi", PathFindExtensionW(Installer)))
653 {
654 it = INSTALLER_MSI;
655 goto done;
656 }
657 }
658
659 if (buf[0] != 'M' || buf[1] != 'Z')
660 goto done;
661
662 // <= Inno 5.1.4
663 {
664 UINT sig[3];
665 C_ASSERT(sizeof(buf) >= 0x30 + sizeof(sig));
666 CopyMemory(sig, buf + 0x30, sizeof(sig));
667 if (sig[0] == 0x6F6E6E49 && sig[1] == ~sig[2])
668 {
669 it = INSTALLER_INNO;
670 ExtraInfo = 1;
671 goto done;
672 }
673 }
674
675 // NSIS 1.6+
676 {
677 UINT nsis[1+1+3+1+1], nsisskip = 512;
678 for (UINT nsisoffset = nsisskip * 20; nsisoffset < 1024 * 1024 * 50; nsisoffset += nsisskip)
679 {
680 if (ReadAt(hFile, nsisoffset, nsis, sizeof(nsis)) && nsis[1] == 0xDEADBEEF)
681 {
682 if (nsis[2] == 0x6C6C754E && nsis[3] == 0x74666F73 && nsis[4] == 0x74736E49)
683 {
684 it = INSTALLER_NSIS;
685 goto done;
686 }
687 }
688 }
689 }
690
691 if (HMODULE hMod = LoadLibraryEx(Installer, NULL, LOAD_LIBRARY_AS_DATAFILE))
692 {
693 // Inno
694 enum { INNORCSETUPLDR = 11111 };
695 HGLOBAL hGlob;
696 HRSRC hRsrc = FindResourceW(hMod, MAKEINTRESOURCE(INNORCSETUPLDR), RT_RCDATA);
697 if (hRsrc && (hGlob = LoadResource(hMod, hRsrc)) != NULL)
698 {
699 if (BYTE *p = (BYTE*)LockResource(hGlob))
700 {
701 if (p[0] == 'r' && p[1] == 'D' && p[2] == 'l' && p[3] == 'P' && p[4] == 't' && p[5] == 'S')
702 it = INSTALLER_INNO;
703 UnlockResource((void*)p);
704 }
705 }
706 FreeLibrary(hMod);
707 }
708done:
710 return it;
711}
@ INSTALLER_UNKNOWN
Definition: appinfo.h:83
static BOOL ReadAt(HANDLE Handle, UINT Offset, LPVOID Buffer, UINT Size)
Definition: misc.cpp:628
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
LPWSTR WINAPI PathFindExtensionW(const WCHAR *path)
Definition: path.c:1274
int WINAPI StrCmpIW(const WCHAR *str, const WCHAR *comp)
Definition: string.c:456
#define C_ASSERT(e)
Definition: intsafe.h:73
#define CopyMemory
Definition: minwinbase.h:29
#define MAKEINTRESOURCE(i)
Definition: ntverrsrc.c:25
#define RT_RCDATA
Definition: pedump.c:372
#define LoadLibraryEx
Definition: winbase.h:3612
#define LOAD_LIBRARY_AS_DATAFILE
Definition: winbase.h:338
#define UnlockResource(handle)
Definition: winbase.h:3125

Referenced by CDownloadManager::PerformDownloadAndInstall().

◆ HResultFromWin32()

static HRESULT HResultFromWin32 ( UINT  Error)
inlinestatic

Definition at line 28 of file misc.h.

29{
31}

◆ InitLogs()

VOID InitLogs ( )

Definition at line 276 of file misc.cpp.

277{
279 {
280 return;
281 }
282
284 DWORD dwCategoryNum = 1;
285 DWORD dwDisp, dwData;
287
288 if (key.Create(
290 L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\ReactOS Application Manager", REG_NONE,
292 {
293 return;
294 }
295
297 {
298 return;
299 }
300
302
303 if ((key.SetStringValue(L"EventMessageFile", szPath, REG_EXPAND_SZ) == ERROR_SUCCESS) &&
304 (key.SetStringValue(L"CategoryMessageFile", szPath, REG_EXPAND_SZ) == ERROR_SUCCESS) &&
305 (key.SetDWORDValue(L"TypesSupported", dwData) == ERROR_SUCCESS) &&
306 (key.SetDWORDValue(L"CategoryCount", dwCategoryNum) == ERROR_SUCCESS))
307
308 {
309 hLog = RegisterEventSourceW(NULL, L"ReactOS Application Manager");
310 }
311}
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
LPCWSTR szPath
Definition: env.c:37
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1060
#define KEY_WRITE
Definition: nt_native.h:1034
#define REG_NONE
Definition: nt_native.h:1495
#define REG_EXPAND_SZ
Definition: nt_native.h:1497
static HANDLE ULONG_PTR dwData
Definition: pipe.c:111
BOOL bLogEnabled
Definition: settings.h:9
Definition: copy.c:22
#define EVENTLOG_ERROR_TYPE
Definition: winnt_old.h:3075
#define EVENTLOG_INFORMATION_TYPE
Definition: winnt_old.h:3077
#define EVENTLOG_WARNING_TYPE
Definition: winnt_old.h:3076
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by wmain(), and wWinMain().

◆ IsSameRegKey()

BOOL IsSameRegKey ( HKEY  hRoot,
LPCWSTR  Path1,
REGSAM  Sam1,
LPCWSTR  Path2,
REGSAM  Sam2 
)

Definition at line 476 of file misc.cpp.

477{
479 CRegKey key1, key2;
480 return key1.Open(hRoot, Path1, MAXIMUM_ALLOWED | (Sam1 & WowMask)) == ERROR_SUCCESS &&
481 key2.Open(hRoot, Path2, MAXIMUM_ALLOWED | (Sam2 & WowMask)) == ERROR_SUCCESS &&
482 IsSameRegKey(key1, key2);
483}
static BOOL IsSameRegKey(HKEY hKey1, HKEY hKey2)
Definition: misc.cpp:460
LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired=KEY_READ|KEY_WRITE) noexcept
Definition: atlbase.h:1173
GLuint64EXT GLuint GLuint GLenum GLenum GLuint GLuint GLenum GLuint GLuint key1
Definition: glext.h:10608
static HTREEITEM hRoot
Definition: treeview.c:383
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
ACCESS_MASK REGSAM
Definition: winreg.h:76

Referenced by CEnumInstalledRootKey::CEnumInstalledRootKey().

◆ IsSystem64Bit()

BOOL IsSystem64Bit ( )

Definition at line 386 of file misc.cpp.

387{
388#ifdef _WIN64
389 return TRUE;
390#else
391 static UINT cache = 0;
392 if (!cache)
393 cache = 1 + (IsOS(OS_WOW6432) != FALSE);
394 return cache - 1;
395#endif
396}
BOOL WINAPI IsOS(DWORD feature)
Definition: ordinal.c:4230
#define OS_WOW6432
Definition: shlwapi.h:256
Definition: cache.c:49

Referenced by ExtractAndInstallThread().

◆ NotifyFileExtractCallback()

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

Definition at line 81 of file misc.h.

83{
84 EXTRACTCALLBACKINFO eci = { ItemPath, UncompressedSize, FileAttributes };
85 return Callback ? Callback(eci, Cookie) : TRUE;
86}
_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().

◆ OpensWithExplorer()

BOOL OpensWithExplorer ( PCWSTR  Path)

Definition at line 164 of file misc.cpp.

165{
166 WCHAR szCmd[MAX_PATH * 2];
167 DWORD cch = _countof(szCmd);
170 ASSOCSTR_COMMAND, pszExt, NULL, szCmd, &cch);
171 if (SUCCEEDED(hr) && StrStrIW(szCmd, L" zipfldr.dll,")) // .zip
172 return TRUE;
173 PathRemoveArgsW(szCmd);
174 return SUCCEEDED(hr) && !StrCmpIW(PathFindFileNameW(szCmd), L"explorer.exe"); // .cab
175}
LPWSTR WINAPI StrStrIW(LPCWSTR lpszStr, LPCWSTR lpszSearch)
Definition: string.c:380
WCHAR *WINAPI PathFindFileNameW(const WCHAR *path)
Definition: path.c:1701
HRESULT WINAPI AssocQueryStringW(ASSOCF cfFlags, ASSOCSTR str, LPCWSTR pszAssoc, LPCWSTR pszExtra, LPWSTR pszOut, DWORD *pcchOut)
Definition: assoc.c:441
void WINAPI PathRemoveArgsW(LPWSTR lpszPath)
Definition: path.c:782
@ ASSOCF_INIT_IGNOREUNKNOWN
Definition: shlwapi.h:870
@ ASSOCF_NOTRUNCATE
Definition: shlwapi.h:865
@ ASSOCSTR_COMMAND
Definition: shlwapi.h:886
const uint16_t * PCWSTR
Definition: typedefs.h:57

Referenced by CDownloadManager::PerformDownloadAndInstall().

◆ RegKeyHasValues()

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

Definition at line 486 of file misc.cpp.

487{
488 CRegKey key;
489 LONG err = key.Open(hKey, Path, KEY_QUERY_VALUE | wowsam);
490 if (err == ERROR_SUCCESS)
491 {
492 WCHAR name[1];
493 DWORD cchname = _countof(name), cbsize = 0;
494 err = RegEnumValueW(key, 0, name, &cchname, NULL, NULL, NULL, &cbsize);
496 return S_FALSE;
497 if (err == ERROR_MORE_DATA)
499 }
500 return HRESULT_FROM_WIN32(err);
501}
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:1019
long LONG
Definition: pedump.c:60
Definition: name.c:39
#define S_FALSE
Definition: winerror.h:3451

Referenced by UninstallThread().

◆ SearchPatternMatch()

BOOL SearchPatternMatch ( LPCWSTR  szHaystack,
LPCWSTR  szNeedle 
)

Definition at line 544 of file misc.cpp.

545{
546 if (!*szNeedle)
547 return TRUE;
548 /* TODO: Improve pattern search beyond a simple case-insensitive substring search. */
549 return StrStrIW(szHaystack, szNeedle) != NULL;
550}

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

◆ ShowPopupMenuEx()

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

Definition at line 82 of file misc.cpp.

83{
84 HMENU hMenu = NULL;
85 HMENU hPopupMenu;
86 MENUITEMINFO ItemInfo;
87 POINT pt;
88
89 if (MenuID)
90 {
91 hMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(MenuID));
92 hPopupMenu = GetSubMenu(hMenu, 0);
93 }
94 else
95 {
96 hPopupMenu = GetMenu(hwnd);
97 }
98
99 ZeroMemory(&ItemInfo, sizeof(ItemInfo));
100 ItemInfo.cbSize = sizeof(ItemInfo);
101 ItemInfo.fMask = MIIM_STATE;
102
103 GetMenuItemInfoW(hPopupMenu, DefaultItem, FALSE, &ItemInfo);
104
105 if (!(ItemInfo.fState & MFS_GRAYED))
106 {
107 SetMenuDefaultItem(hPopupMenu, DefaultItem, FALSE);
108 }
109
110 if (!Point)
111 {
113 }
114
116 TrackPopupMenu(hPopupMenu, 0, Point->x, Point->y, 0, hwndOwner, NULL);
117
118 if (hMenu)
119 {
120 DestroyMenu(hMenu);
121 }
122}
#define pt(x, y)
Definition: drawing.c:79
HINSTANCE hInst
Definition: dxdiag.c:13
#define ZeroMemory
Definition: minwinbase.h:31
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
BOOL WINAPI SetMenuDefaultItem(_In_ HMENU, _In_ UINT, _In_ UINT)
BOOL WINAPI SetForegroundWindow(_In_ HWND)
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:3064
#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 = NULL 
)

Definition at line 573 of file misc.cpp.

574{
575 CPathW dir = FullPath;
576 //int win = dir.ReverseFind(L'\\'), nix = dir.ReverseFind(L'/'), sep = max(win, nix);
577 int sep = dir.FindFileName();
578 CStringW file = dir.m_strPath.Mid(sep);
579 if (pDir)
580 *pDir = sep == -1 ? L"" : dir.m_strPath.Left(sep - 1);
581 return file;
582}

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

◆ StartProcess()

BOOL StartProcess ( const CStringW Path,
BOOL  Wait 
)

Definition at line 203 of file misc.cpp.

204{
207
208 ZeroMemory(&si, sizeof(si));
209 si.cb = sizeof(si);
210 si.dwFlags = STARTF_USESHOWWINDOW;
211 si.wShowWindow = SW_SHOW;
212
213 // The Unicode version of CreateProcess can modify the contents of this string.
214 CStringW Tmp = Path;
215 BOOL fSuccess = CreateProcessW(NULL, Tmp.GetBuffer(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
216 Tmp.ReleaseBuffer();
217 if (!fSuccess)
218 {
219 return FALSE;
220 }
221
223
224 if (Wait)
225 {
227
229
232 // We got the real activation message during MsgWaitForMultipleObjects while
233 // we were disabled, we need to set the focus again now.
235 }
237 return TRUE;
238}
UINT WaitForProcess(HANDLE hProcess)
Definition: misc.cpp:178
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:4441
HWND hMainWnd
Definition: magnifier.c:32
static PROCESS_INFORMATION pi
Definition: debugger.c:2303
static SYSTEM_INFO si
Definition: virtual.c:39
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:170
#define STARTF_USESHOWWINDOW
Definition: winbase.h:468
HWND WINAPI SetFocus(_In_opt_ HWND)
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define SW_SHOW
Definition: winuser.h:786

Referenced by CInstalledApplicationInfo::UninstallApplication().

◆ UnixTimeToFileTime()

void UnixTimeToFileTime ( DWORD  dwUnixTime,
LPFILETIME  pFileTime 
)

Definition at line 449 of file misc.cpp.

450{
451 // Note that LONGLONG is a 64-bit value
452 LONGLONG ll;
453
454 ll = Int32x32To64(dwUnixTime, 10000000) + 116444736000000000;
455 pFileTime->dwLowDateTime = (DWORD)ll;
456 pFileTime->dwHighDateTime = ll >> 32;
457}
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().

◆ WaitForProcess()

UINT WaitForProcess ( HANDLE  hProcess)

Definition at line 178 of file misc.cpp.

179{
181 for (;;)
182 {
184 if (wait == WAIT_OBJECT_0 + 1)
185 {
186 MSG msg;
187 while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
188 {
191 }
192 }
193 else
194 {
195 // TODO: if (wait == WAIT_OBJECT_0) GetExitCodeProcess for MSI reboot codes
196 break;
197 }
198 }
199 return code;
200}
#define msg(x)
Definition: auth_time.c:54
#define INFINITE
Definition: serial.h:102
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:71
#define STILL_ACTIVE
Definition: minwinbase.h:43
Definition: inflate.c:139
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define WAIT_OBJECT_0
Definition: winbase.h:383
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)
BOOL WINAPI PeekMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT, _In_ UINT)
#define PM_REMOVE
Definition: winuser.h:1207
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)

Referenced by StartProcess().

◆ WriteLogMessage()

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

Definition at line 323 of file misc.cpp.

324{
326 {
327 return TRUE;
328 }
329
330 if (!ReportEventW(hLog, wType, 0, dwEventID, NULL, 1, 0, &lpMsg, NULL))
331 {
332 return FALSE;
333 }
334
335 return TRUE;
336}
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().