1 #pragma once 2 3 #include <atlstr.h> 4 5 #ifdef _M_IX86 6 #define CurrentArchitecture L"x86" 7 #elif defined(_M_AMD64) 8 #define CurrentArchitecture L"amd64" 9 #elif defined(_M_ARM) 10 #define CurrentArchitecture L"arm" 11 #elif defined(_M_ARM64) 12 #define CurrentArchitecture L"arm64" 13 #elif defined(_M_IA64) 14 #define CurrentArchitecture L"ia64" 15 #elif defined(_M_PPC) 16 #define CurrentArchitecture L"ppc" 17 #endif 18 19 static inline UINT 20 ErrorFromHResult(HRESULT hr) 21 { 22 // Attempt to extract the original Win32 error code from the HRESULT 23 if (HIWORD(hr) == HIWORD(HRESULT_FROM_WIN32(!0))) 24 return LOWORD(hr); 25 else 26 return hr >= 0 ? ERROR_SUCCESS : hr; 27 } 28 29 VOID 30 CopyTextToClipboard(LPCWSTR lpszText); 31 VOID 32 ShowPopupMenuEx(HWND hwnd, HWND hwndOwner, UINT MenuID, UINT DefaultItem, POINT *Point = NULL); 33 BOOL 34 StartProcess(const CStringW &Path, BOOL Wait); 35 BOOL 36 GetStorageDirectory(CStringW &lpDirectory); 37 38 VOID 39 InitLogs(); 40 VOID 41 FreeLogs(); 42 BOOL 43 WriteLogMessage(WORD wType, DWORD dwEventID, LPCWSTR lpMsg); 44 BOOL 45 GetInstalledVersion(CStringW *pszVersion, const CStringW &szRegName); 46 47 typedef struct 48 { 49 const CStringW &ItemPath; 50 UINT64 UncompressedSize; 51 UINT FileAttributes; 52 } EXTRACTCALLBACKINFO; 53 typedef BOOL (CALLBACK*EXTRACTCALLBACK)(const EXTRACTCALLBACKINFO &Info, void *Cookie); 54 55 static inline BOOL 56 NotifyFileExtractCallback(const CStringW &ItemPath, UINT64 UncompressedSize, UINT FileAttributes, 57 EXTRACTCALLBACK Callback, void *Cookie) 58 { 59 EXTRACTCALLBACKINFO eci = { ItemPath, UncompressedSize, FileAttributes }; 60 return Callback ? Callback(eci, Cookie) : TRUE; 61 } 62 63 BOOL 64 ExtractFilesFromCab(const CStringW &szCabName, const CStringW &szCabDir, const CStringW &szOutputDir, 65 EXTRACTCALLBACK Callback = NULL, void *Cookie = NULL); 66 BOOL 67 ExtractFilesFromCab(LPCWSTR FullCabPath, const CStringW &szOutputDir, 68 EXTRACTCALLBACK Callback = NULL, void *Cookie = NULL); 69 70 BOOL 71 IsSystem64Bit(); 72 73 INT 74 GetSystemColorDepth(); 75 76 void 77 UnixTimeToFileTime(DWORD dwUnixTime, LPFILETIME pFileTime); 78 79 BOOL 80 SearchPatternMatch(LPCWSTR szHaystack, LPCWSTR szNeedle); 81 82 HRESULT 83 RegKeyHasValues(HKEY hKey, LPCWSTR Path, REGSAM wowsam = 0); 84 LPCWSTR 85 GetRegString(CRegKey &Key, LPCWSTR Name, CStringW &Value); 86 87 bool 88 ExpandEnvStrings(CStringW &Str); 89 90 template <class T> static CStringW 91 BuildPath(const T &Base, LPCWSTR Append) 92 { 93 CStringW path = Base; 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 } 101 102 CStringW 103 SplitFileAndDirectory(LPCWSTR FullPath, CStringW *pDir = NULL); 104 BOOL 105 DeleteDirectoryTree(LPCWSTR Dir, HWND hwnd = NULL); 106 UINT 107 CreateDirectoryTree(LPCWSTR Dir); 108 HRESULT 109 GetSpecialPath(UINT csidl, CStringW &Path, HWND hwnd = NULL); 110 HRESULT 111 GetKnownPath(REFKNOWNFOLDERID kfid, CStringW &Path, DWORD Flags = KF_FLAG_CREATE); 112 HRESULT 113 GetProgramFilesPath(CStringW &Path, BOOL PerUser, HWND hwnd = NULL); 114 115 template <class T> class CLocalPtr : public CHeapPtr<T, CLocalAllocator> 116 { 117 }; 118