1 #pragma once
2
3 #include <atlstr.h>
4 #include <atlpath.h>
5 #include <atlsimpcoll.h>
6
7
8 enum LicenseType
9 {
10 LICENSE_NONE,
11 LICENSE_OPENSOURCE = 1,
12 LICENSE_FREEWARE = 2,
13 LICENSE_TRIAL = 3,
14 LICENSE_MIN = LICENSE_NONE,
15 LICENSE_MAX = LICENSE_TRIAL
16 };
17
18 inline BOOL
IsKnownLicenseType(INT x)19 IsKnownLicenseType(INT x)
20 {
21 return (x > LICENSE_NONE && x <= LICENSE_MAX);
22 }
23
24 enum AppsCategories
25 {
26 ENUM_ALL_AVAILABLE,
27 ENUM_CAT_AUDIO,
28 ENUM_CAT_VIDEO,
29 ENUM_CAT_GRAPHICS,
30 ENUM_CAT_GAMES,
31 ENUM_CAT_INTERNET,
32 ENUM_CAT_OFFICE,
33 ENUM_CAT_DEVEL,
34 ENUM_CAT_EDU,
35 ENUM_CAT_ENGINEER,
36 ENUM_CAT_FINANCE,
37 ENUM_CAT_SCIENCE,
38 ENUM_CAT_TOOLS,
39 ENUM_CAT_DRIVERS,
40 ENUM_CAT_LIBS,
41 ENUM_CAT_THEMES,
42 ENUM_CAT_OTHER,
43 ENUM_CAT_SELECTED,
44 ENUM_ALL_INSTALLED = 30,
45 ENUM_INSTALLED_APPLICATIONS,
46 ENUM_UPDATES,
47 ENUM_INVALID,
48 ENUM_INSTALLED_MIN = ENUM_ALL_INSTALLED,
49 ENUM_INSTALLED_MAX = ENUM_UPDATES,
50 ENUM_AVAILABLE_MIN = ENUM_ALL_AVAILABLE,
51 ENUM_AVAILABLE_MAX = ENUM_CAT_SELECTED,
52 };
53
54 inline BOOL
IsAvailableEnum(INT x)55 IsAvailableEnum(INT x)
56 {
57 return (x >= ENUM_AVAILABLE_MIN && x <= ENUM_AVAILABLE_MAX);
58 }
59
60 inline BOOL
IsInstalledEnum(INT x)61 IsInstalledEnum(INT x)
62 {
63 return (x >= ENUM_INSTALLED_MIN && x <= ENUM_INSTALLED_MAX);
64 }
65
66 enum UninstallCommandFlags
67 {
68 UCF_NONE = 0x00,
69 UCF_MODIFY = 0x01,
70 UCF_SILENT = 0x02,
71 };
72
73 enum InstallerType
74 {
75 INSTALLER_UNKNOWN,
76 INSTALLER_GENERATE, // .zip file automatically converted to installer by rapps
77 };
78
79 #define DB_VERSION L"Version"
80 #define DB_CATEGORY L"Category"
81 #define DB_PUBLISHER L"Publisher"
82 #define DB_REGNAME L"RegName"
83 #define DB_INSTALLER L"Installer"
84 #define DB_SCOPE L"Scope" // User or Machine
85
86 #define DB_GENINSTSECTION L"Generate"
87 #define GENERATE_ARPSUBKEY L"RApps" // Our uninstall data is stored here
88
89 class CAppRichEdit;
90 class CConfigParser;
91
92 class CAppInfo
93 {
94 public:
95 CAppInfo(const CStringW &Identifier, AppsCategories Category);
96 virtual ~CAppInfo();
97
98 const CStringW szIdentifier; // PkgName or KeyName
99 const AppsCategories iCategory;
100
101 CStringW szDisplayIcon;
102 CStringW szDisplayName;
103 CStringW szDisplayVersion;
104 CStringW szComments;
105
106 virtual BOOL
107 Valid() const = 0;
108 virtual BOOL
109 CanModify() = 0;
110 virtual BOOL
111 RetrieveIcon(CStringW &Path) const = 0;
112 virtual BOOL
113 RetrieveScreenshot(CStringW &Path) = 0;
114 virtual VOID
115 ShowAppInfo(CAppRichEdit *RichEdit) = 0;
116 virtual VOID
117 GetDownloadInfo(CStringW &Url, CStringW &Sha1, ULONG &SizeInBytes) const = 0;
118 virtual VOID
119 GetDisplayInfo(CStringW &License, CStringW &Size, CStringW &UrlSite, CStringW &UrlDownload) = 0;
120 virtual InstallerType
GetInstallerType()121 GetInstallerType() const { return INSTALLER_UNKNOWN; }
122 virtual BOOL
123 UninstallApplication(UninstallCommandFlags Flags) = 0;
124 };
125
126 class CAvailableApplicationInfo : public CAppInfo
127 {
128 CConfigParser *m_Parser;
129 CSimpleArray<CStringW> m_szScrnshotLocation;
130 bool m_ScrnshotRetrieved;
131 CStringW m_szUrlDownload;
132 CStringW m_szSize;
133 CStringW m_szUrlSite;
134 CSimpleArray<LCID> m_LanguageLCIDs;
135 bool m_LanguagesLoaded;
136
137 VOID
138 InsertVersionInfo(CAppRichEdit *RichEdit);
139 VOID
140 InsertLanguageInfo(CAppRichEdit *RichEdit);
141 VOID
142 RetrieveLanguages();
143 CStringW
144 LicenseString();
145
146 public:
147 CAvailableApplicationInfo(
148 CConfigParser *Parser,
149 const CStringW &PkgName,
150 AppsCategories Category,
151 const CPathW &BasePath);
152 ~CAvailableApplicationInfo();
153
154 CConfigParser *
GetConfigParser()155 GetConfigParser() const { return m_Parser; }
156
157 virtual BOOL
158 Valid() const override;
159 virtual BOOL
160 CanModify() override;
161 virtual BOOL
162 RetrieveIcon(CStringW &Path) const override;
163 virtual BOOL
164 RetrieveScreenshot(CStringW &Path) override;
165 virtual VOID
166 ShowAppInfo(CAppRichEdit *RichEdit) override;
167 virtual VOID
168 GetDownloadInfo(CStringW &Url, CStringW &Sha1, ULONG &SizeInBytes) const override;
169 virtual VOID
170 GetDisplayInfo(CStringW &License, CStringW &Size, CStringW &UrlSite, CStringW &UrlDownload) override;
171 virtual InstallerType
172 GetInstallerType() const override;
173 virtual BOOL
174 UninstallApplication(UninstallCommandFlags Flags) override;
175 };
176
177 class CInstalledApplicationInfo : public CAppInfo
178 {
179 CRegKey m_hKey;
180 CStringW m_szInstallDate;
181 CStringW m_szUninstallString;
182 CStringW m_szModifyString;
183
184 BOOL
185 GetApplicationRegString(LPCWSTR lpKeyName, CStringW &String);
186 BOOL
187 GetApplicationRegDword(LPCWSTR lpKeyName, DWORD *lpValue);
188 VOID
189 AddApplicationRegString(CAppRichEdit *RichEdit, UINT StringID, const CStringW &String, DWORD TextFlags);
190
191 VOID
192 RetrieveInstallDate();
193 VOID
194 RetrieveUninstallStrings();
195
196 public:
197 UINT m_KeyInfo;
198 CInstalledApplicationInfo(HKEY Key, const CStringW &KeyName, AppsCategories Category, UINT KeyInfo);
199 ~CInstalledApplicationInfo();
200
GetRegKey()201 CRegKey& GetRegKey() { return m_hKey; }
202
203 virtual BOOL
204 Valid() const override;
205 virtual BOOL
206 CanModify() override;
207 virtual BOOL
208 RetrieveIcon(CStringW &Path) const override;
209 virtual BOOL
210 RetrieveScreenshot(CStringW &Path) override;
211 virtual VOID
212 ShowAppInfo(CAppRichEdit *RichEdit) override;
213 virtual VOID
214 GetDownloadInfo(CStringW &Url, CStringW &Sha1, ULONG &SizeInBytes) const override;
215 virtual VOID
216 GetDisplayInfo(CStringW &License, CStringW &Size, CStringW &UrlSite, CStringW &UrlDownload) override;
217 virtual InstallerType
218 GetInstallerType() const override;
219 virtual BOOL
220 UninstallApplication(UninstallCommandFlags Flags) override;
221 };
222
223 BOOL
224 UninstallGenerated(CInstalledApplicationInfo &AppInfo, UninstallCommandFlags Flags);
225 BOOL
226 ExtractAndRunGeneratedInstaller(const CAvailableApplicationInfo &AppInfo, LPCWSTR Archive);
227