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
ErrorFromHResult(HRESULT hr)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 VOID
34 EmulateDialogReposition(HWND hwnd);
35 BOOL
36 StartProcess(const CStringW &Path, BOOL Wait);
37 BOOL
38 GetStorageDirectory(CStringW &lpDirectory);
39
40 VOID
41 InitLogs();
42 VOID
43 FreeLogs();
44 BOOL
45 WriteLogMessage(WORD wType, DWORD dwEventID, LPCWSTR lpMsg);
46 BOOL
47 GetInstalledVersion(CStringW *pszVersion, const CStringW &szRegName);
48
49 typedef struct
50 {
51 const CStringW &ItemPath;
52 UINT64 UncompressedSize;
53 UINT FileAttributes;
54 } EXTRACTCALLBACKINFO;
55 typedef BOOL (CALLBACK*EXTRACTCALLBACK)(const EXTRACTCALLBACKINFO &Info, void *Cookie);
56
57 static inline BOOL
NotifyFileExtractCallback(const CStringW & ItemPath,UINT64 UncompressedSize,UINT FileAttributes,EXTRACTCALLBACK Callback,void * Cookie)58 NotifyFileExtractCallback(const CStringW &ItemPath, UINT64 UncompressedSize, UINT FileAttributes,
59 EXTRACTCALLBACK Callback, void *Cookie)
60 {
61 EXTRACTCALLBACKINFO eci = { ItemPath, UncompressedSize, FileAttributes };
62 return Callback ? Callback(eci, Cookie) : TRUE;
63 }
64
65 BOOL
66 ExtractFilesFromCab(const CStringW &szCabName, const CStringW &szCabDir, const CStringW &szOutputDir,
67 EXTRACTCALLBACK Callback = NULL, void *Cookie = NULL);
68 BOOL
69 ExtractFilesFromCab(LPCWSTR FullCabPath, const CStringW &szOutputDir,
70 EXTRACTCALLBACK Callback = NULL, void *Cookie = NULL);
71
72 BOOL
73 IsSystem64Bit();
74
75 INT
76 GetSystemColorDepth();
77
78 void
79 UnixTimeToFileTime(DWORD dwUnixTime, LPFILETIME pFileTime);
80
81 BOOL
82 SearchPatternMatch(LPCWSTR szHaystack, LPCWSTR szNeedle);
83
84 HRESULT
85 RegKeyHasValues(HKEY hKey, LPCWSTR Path, REGSAM wowsam = 0);
86 LPCWSTR
87 GetRegString(CRegKey &Key, LPCWSTR Name, CStringW &Value);
88
89 bool
90 ExpandEnvStrings(CStringW &Str);
91
92 template <class T> static CStringW
BuildPath(const T & Base,LPCWSTR Append)93 BuildPath(const T &Base, LPCWSTR Append)
94 {
95 CStringW path = Base;
96 SIZE_T len = path.GetLength();
97 if (len && path[len - 1] != L'\\' && path[len - 1] != L'/')
98 path += L'\\';
99 while (*Append == L'\\' || *Append == L'/')
100 ++Append;
101 return path + Append;
102 }
103
104 CStringW
105 SplitFileAndDirectory(LPCWSTR FullPath, CStringW *pDir = NULL);
106 BOOL
107 DeleteDirectoryTree(LPCWSTR Dir, HWND hwnd = NULL);
108 UINT
109 CreateDirectoryTree(LPCWSTR Dir);
110 HRESULT
111 GetSpecialPath(UINT csidl, CStringW &Path, HWND hwnd = NULL);
112 HRESULT
113 GetKnownPath(REFKNOWNFOLDERID kfid, CStringW &Path, DWORD Flags = KF_FLAG_CREATE);
114 HRESULT
115 GetProgramFilesPath(CStringW &Path, BOOL PerUser, HWND hwnd = NULL);
116
117 template <class T> class CLocalPtr : public CHeapPtr<T, CLocalAllocator>
118 {
119 };
120