[RAPPS]
[reactos.git] / reactos / base / applications / rapps / rapps.h
1 #pragma once
2
3 #ifndef _RAPPS_H
4 #define _RAPPS_H
5
6 #include <tchar.h>
7 #include <stdarg.h>
8
9 #define WIN32_NO_STATUS
10 #define _INC_WINDOWS
11 #define COM_NO_WINDOWS_H
12 #define COBJMACROS
13
14 #include <windef.h>
15 #include <winbase.h>
16 #include <winreg.h>
17 #include <wingdi.h>
18 #include <winnls.h>
19 #include <winuser.h>
20 #include <wincon.h>
21 #include <richedit.h>
22 #include <shellapi.h>
23 #include <shlobj.h>
24 #include <shlwapi.h>
25 #include <stdio.h>
26 #include <strsafe.h>
27 #include <ndk/rtlfuncs.h>
28 #include <atlcoll.h>
29 #include <atlsimpcoll.h>
30 #include <atlstr.h>
31 #include <rappsmsg.h>
32
33 #include "resource.h"
34
35 #ifdef USE_CERT_PINNING
36 #define CERT_ISSUER_INFO "BE\r\nGlobalSign nv-sa\r\nGlobalSign Domain Validation CA - SHA256 - G2"
37 #define CERT_SUBJECT_INFO "Domain Control Validated\r\n*.reactos.org"
38 #endif
39
40 #define APPLICATION_DATABASE_URL L"https://svn.reactos.org/packages/rappmgr.cab"
41
42 #define SPLIT_WIDTH 4
43 #define MAX_STR_LEN 256
44 #define LISTVIEW_ICON_SIZE 24
45 #define TREEVIEW_ICON_SIZE 24
46
47 /* EnumType flags for EnumInstalledApplications */
48 #define ENUM_ALL_COMPONENTS 30
49 #define ENUM_APPLICATIONS 31
50 #define ENUM_UPDATES 32
51 /* EnumType flags for EnumAvailableApplications */
52 #define ENUM_ALL_AVAILABLE 0
53 #define ENUM_CAT_AUDIO 1
54 #define ENUM_CAT_VIDEO 2
55 #define ENUM_CAT_GRAPHICS 3
56 #define ENUM_CAT_GAMES 4
57 #define ENUM_CAT_INTERNET 5
58 #define ENUM_CAT_OFFICE 6
59 #define ENUM_CAT_DEVEL 7
60 #define ENUM_CAT_EDU 8
61 #define ENUM_CAT_ENGINEER 9
62 #define ENUM_CAT_FINANCE 10
63 #define ENUM_CAT_SCIENCE 11
64 #define ENUM_CAT_TOOLS 12
65 #define ENUM_CAT_DRIVERS 13
66 #define ENUM_CAT_LIBS 14
67 #define ENUM_CAT_OTHER 15
68
69 #define ENUM_INSTALLED_MIN ENUM_ALL_COMPONENTS
70 #define ENUM_INSTALLED_MAX ENUM_UPDATES
71 #define ENUM_AVAILABLE_MIN ENUM_ALL_AVAILABLE
72 #define ENUM_AVAILABLE_MAX ENUM_CAT_OTHER
73
74 #define IS_INSTALLED_ENUM(a) (a >= ENUM_INSTALLED_MIN && a <= ENUM_INSTALLED_MAX)
75 #define IS_AVAILABLE_ENUM(a) (a >= ENUM_AVAILABLE_MIN && a <= ENUM_AVAILABLE_MAX)
76
77 typedef enum
78 {
79 None,
80 OpenSource,
81 Freeware,
82 Trial,
83 Max = Trial,
84 Min = None
85 } LICENSE_TYPE, *PLICENSE_TYPE;
86
87 /* aboutdlg.cpp */
88 VOID ShowAboutDialog(VOID);
89
90 /* available.cpp */
91 typedef struct
92 {
93 INT Category;
94 LICENSE_TYPE LicenseType;
95 ATL::CStringW szName;
96 ATL::CStringW szRegName;
97 ATL::CStringW szVersion;
98 ATL::CStringW szLicense;
99 ATL::CStringW szDesc;
100 ATL::CStringW szSize;
101 ATL::CStringW szUrlSite;
102 ATL::CStringW szUrlDownload;
103 ATL::CStringW szCDPath;
104 ATL::CSimpleArray<LCID> Languages;
105
106 /* caching mechanism related entries */
107 ATL::CStringW sFileName;
108 FILETIME ftCacheStamp;
109
110 /* optional integrity checks (SHA-1 digests are 160 bit = 40 characters in hex string form) */
111 ATL::CStringW szSHA1;
112
113 } APPLICATION_INFO, *PAPPLICATION_INFO;
114
115 extern ATL::CAtlList<PAPPLICATION_INFO> InfoList;
116
117 typedef struct
118 {
119 HKEY hRootKey;
120 HKEY hSubKey;
121 ATL::CStringW szKeyName;
122
123 } INSTALLED_INFO, *PINSTALLED_INFO;
124
125 typedef struct
126 {
127 BOOL bSaveWndPos;
128 BOOL bUpdateAtStart;
129 BOOL bLogEnabled;
130 WCHAR szDownloadDir[MAX_PATH];
131 BOOL bDelInstaller;
132 /* Window Pos */
133 BOOL Maximized;
134 INT Left;
135 INT Top;
136 INT Width;
137 INT Height;
138 /* Proxy settings */
139 INT Proxy;
140 WCHAR szProxyServer[MAX_PATH];
141 WCHAR szNoProxyFor[MAX_PATH];
142
143 } SETTINGS_INFO, *PSETTINGS_INFO;
144
145 /* available.cpp */
146 class CConfigParser
147 {
148 // Loacale names cache
149 static ATL::CStringW m_szLocaleID;
150 const static INT m_cchLocaleSize = 5;
151 static ATL::CStringW m_szCachedINISectionLocale;
152 static ATL::CStringW m_szCachedINISectionLocaleNeutral;
153
154 const LPCWSTR STR_VERSION_CURRENT = L"CURRENT";
155 const ATL::CStringW szConfigPath;
156
157 static ATL::CStringW GetINIFullPath(const ATL::CStringW& FileName);
158 static VOID CacheINILocaleLazy();
159
160 public:
161 static const ATL::CStringW& GetLocale();
162 static INT CConfigParser::GetLocaleSize();
163
164 CConfigParser(const ATL::CStringW& FileName);
165
166 UINT GetString(const ATL::CStringW& KeyName, ATL::CStringW& ResultString);
167 UINT GetInt(const ATL::CStringW& KeyName);
168 };
169
170 typedef BOOL (CALLBACK *AVAILENUMPROC)(PAPPLICATION_INFO Info, LPCWSTR szFolderPath);
171 struct CAvailableApplicationInfo : public APPLICATION_INFO
172 {
173 ATL::CStringW szInstalledVersion;
174 CAvailableApplicationInfo(const ATL::CStringW& sFileNameParam);
175
176 // Load all info from the file
177 VOID RefreshAppInfo();
178 BOOL HasLanguageInfo() const;
179 BOOL HasNativeLanguage() const;
180 BOOL HasEnglishLanguage() const;
181 BOOL IsInstalled() const;
182 BOOL HasInstalledVersion() const;
183 BOOL HasUpdate() const;
184
185 // Set a timestamp
186 VOID SetLastWriteTime(FILETIME* ftTime);
187
188 private:
189 BOOL m_IsInstalled = FALSE;
190 BOOL m_HasLanguageInfo = FALSE;
191 BOOL m_HasInstalledVersion = FALSE;
192 CConfigParser m_Parser;
193
194 inline BOOL GetString(LPCWSTR lpKeyName,
195 ATL::CStringW& ReturnedString);
196
197 // Lazily load general info from the file
198 VOID RetrieveGeneralInfo();
199 VOID RetrieveInstalledStatus();
200 VOID RetrieveInstalledVersion();
201 VOID RetrieveLanguages();
202 VOID RetrieveLicenseType();
203 inline BOOL FindInLanguages(LCID what) const;
204 };
205
206 class CAvailableApps
207 {
208 ATL::CAtlList<CAvailableApplicationInfo*> m_InfoList;
209 ATL::CStringW m_szPath;
210 ATL::CStringW m_szCabPath;
211 ATL::CStringW m_szAppsPath;
212 ATL::CStringW m_szSearchPath;
213
214 public:
215 CAvailableApps();
216 VOID FreeCachedEntries();
217 BOOL DeleteCurrentAppsDB();
218 BOOL UpdateAppsDB();
219 BOOL EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc);
220 const ATL::CStringW& GetFolderPath();
221 const ATL::CStringW& GetAppPath();
222 const ATL::CStringW& GetCabPath();
223 const LPCWSTR GetFolderPathString();
224 const LPCWSTR GetAppPathString();
225 const LPCWSTR GetCabPathString();
226 };
227
228 /* installdlg.cpp */
229 //BOOL InstallApplication(INT Index);
230
231 /* installed.cpp */
232 typedef BOOL (CALLBACK *APPENUMPROC)(INT ItemIndex, ATL::CStringW &lpName, PINSTALLED_INFO Info);
233 BOOL EnumInstalledApplications(INT EnumType, BOOL IsUserKey, APPENUMPROC lpEnumProc);
234 BOOL GetApplicationString(HKEY hKey, LPCWSTR lpKeyName, LPWSTR szString);
235 BOOL GetApplicationString(HKEY hKey, LPCWSTR RegName, ATL::CStringW& String);
236
237 BOOL ShowInstalledAppInfo(INT Index);
238 BOOL UninstallApplication(INT Index, BOOL bModify);
239 VOID RemoveAppFromRegistry(INT Index);
240
241 BOOL GetInstalledVersion(ATL::CStringW* pszVersion, const ATL::CStringW& szRegName);
242
243 /* winmain.cpp */
244 extern HWND hMainWnd;
245 extern HINSTANCE hInst;
246 extern INT SelectedEnumType;
247 extern SETTINGS_INFO SettingsInfo;
248 VOID SaveSettings(HWND hwnd);
249 VOID FillDefaultSettings(PSETTINGS_INFO pSettingsInfo);
250
251 /* loaddlg.cpp */
252
253 class DownloadManager
254 {
255 static PAPPLICATION_INFO AppInfo;
256 public:
257
258 static INT_PTR CALLBACK DownloadDlgProc(HWND Dlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
259 static LRESULT CALLBACK DownloadProgressProc(HWND hWnd,
260 UINT uMsg,
261 WPARAM wParam,
262 LPARAM lParam,
263 UINT_PTR uIdSubclass,
264 DWORD_PTR dwRefData);
265
266 static DWORD WINAPI ThreadFunc(LPVOID Context);
267 static BOOL DownloadListOfApplications(const ATL::CSimpleArray<PAPPLICATION_INFO>& AppsList);
268 static BOOL DownloadApplication(PAPPLICATION_INFO pAppInfo);
269 static VOID DownloadApplicationsDB(LPCWSTR lpUrl);
270 static VOID LaunchDownloadDialog();
271 };
272
273 /* misc.cpp */
274 INT GetSystemColorDepth(VOID);
275 int GetWindowWidth(HWND hwnd);
276 int GetWindowHeight(HWND hwnd);
277 int GetClientWindowWidth(HWND hwnd);
278 int GetClientWindowHeight(HWND hwnd);
279 VOID CopyTextToClipboard(LPCWSTR lpszText);
280 VOID SetWelcomeText(VOID);
281 VOID ShowPopupMenu(HWND hwnd, UINT MenuID, UINT DefaultItem);
282 BOOL StartProcess(ATL::CStringW & Path, BOOL Wait);
283 BOOL StartProcess(LPWSTR lpPath, BOOL Wait);
284 BOOL GetStorageDirectory(ATL::CStringW &lpDirectory);
285 BOOL ExtractFilesFromCab(LPCWSTR lpCabName, LPCWSTR lpOutputPath);
286 VOID InitLogs(VOID);
287 VOID FreeLogs(VOID);
288 BOOL WriteLogMessage(WORD wType, DWORD dwEventID, LPCWSTR lpMsg);
289
290 /* settingsdlg.cpp */
291 VOID CreateSettingsDlg(HWND hwnd);
292
293 /* gui.cpp */
294 HWND CreateMainWindow();
295 DWORD_PTR ListViewGetlParam(INT item);
296 INT ListViewAddItem(INT ItemIndex, INT IconIndex, LPWSTR lpName, LPARAM lParam);
297 VOID SetStatusBarText(LPCWSTR szText);
298 VOID NewRichEditText(LPCWSTR szText, DWORD flags);
299 VOID InsertRichEditText(LPCWSTR szText, DWORD flags);
300
301 VOID SetStatusBarText(const ATL::CStringW& szText);
302 INT ListViewAddItem(INT ItemIndex, INT IconIndex, ATL::CStringW & Name, LPARAM lParam);
303 VOID NewRichEditText(const ATL::CStringW& szText, DWORD flags);
304 VOID InsertRichEditText(const ATL::CStringW& szText, DWORD flags);
305 CAvailableApps * GetAvailableApps();
306 extern HWND hListView;
307 extern ATL::CStringW szSearchPattern;
308
309 /* integrity.cpp */
310 BOOL VerifyInteg(LPCWSTR lpSHA1Hash, LPCWSTR lpFileName);
311
312 //extern HWND hTreeView;
313 //BOOL CreateTreeView(HWND hwnd);
314 //HTREEITEM TreeViewAddItem(HTREEITEM hParent, LPWSTR lpText, INT Image, INT SelectedImage, LPARAM lParam);
315
316 #endif /* _RAPPS_H */