- Sync with trunk up to r46941.
[reactos.git] / base / applications / rapps / available.c
1 /*
2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/rapps/available.c
5 * PURPOSE: Functions for working with availabled applications
6 * PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org)
7 */
8
9 #include "rapps.h"
10
11
12 BOOL
13 ShowAvailableAppInfo(INT Index)
14 {
15 PAPPLICATION_INFO Info = (PAPPLICATION_INFO) ListViewGetlParam(Index);
16 WCHAR szText[MAX_STR_LEN];
17
18 if (!Info) return FALSE;
19
20 NewRichEditText(Info->szName, CFE_BOLD);
21
22 InsertRichEditText(L"\n", 0);
23
24 #define ADD_TEXT(a, b, c, d) \
25 if (b[0] != '\0') \
26 { \
27 LoadStringW(hInst, a, szText, sizeof(szText) / sizeof(WCHAR)); \
28 InsertRichEditText(szText, c); \
29 InsertRichEditText(b, d); \
30 } \
31
32 ADD_TEXT(IDS_AINFO_VERSION, Info->szVersion, CFE_BOLD, 0);
33 ADD_TEXT(IDS_AINFO_LICENCE, Info->szLicence, CFE_BOLD, 0);
34 ADD_TEXT(IDS_AINFO_SIZE, Info->szSize, CFE_BOLD, 0);
35 ADD_TEXT(IDS_AINFO_URLSITE, Info->szUrlSite, CFE_BOLD, CFE_LINK);
36 ADD_TEXT(IDS_AINFO_DESCRIPTION, Info->szDesc, CFE_BOLD, 0);
37
38 return TRUE;
39 }
40
41 static BOOL
42 DeleteCurrentAppsDB(VOID)
43 {
44 HANDLE hFind = INVALID_HANDLE_VALUE;
45 WIN32_FIND_DATAW FindFileData;
46 WCHAR szCabPath[MAX_PATH];
47 WCHAR szSearchPath[MAX_PATH];
48 WCHAR szPath[MAX_PATH];
49 WCHAR szTmp[MAX_PATH];
50
51 if (!GetCurrentDirectoryW(MAX_PATH, szPath))
52 return FALSE;
53
54 swprintf(szCabPath, L"%s\\rappmgr.cab", szPath);
55
56 if (GetFileAttributesW(szCabPath) != INVALID_FILE_ATTRIBUTES)
57 {
58 if (!DeleteFileW(szCabPath))
59 return FALSE;
60 }
61
62 wcscat(szPath, L"\\rapps\\");
63 swprintf(szSearchPath, L"%s*.txt", szPath);
64
65 hFind = FindFirstFileW(szSearchPath, &FindFileData);
66 if (hFind == INVALID_HANDLE_VALUE)
67 return TRUE;
68
69 do
70 {
71 swprintf(szTmp, L"%s%s", szPath, FindFileData.cFileName);
72 if (!DeleteFileW(szTmp))
73 {
74 FindClose(hFind);
75 return FALSE;
76 }
77 }
78 while (FindNextFileW(hFind, &FindFileData) != 0);
79
80 FindClose(hFind);
81
82 return TRUE;
83 }
84
85
86 BOOL
87 UpdateAppsDB(VOID)
88 {
89 WCHAR szPath[MAX_PATH];
90 WCHAR szAppsPath[MAX_PATH];
91 WCHAR szCabPath[MAX_PATH];
92
93 if (!DeleteCurrentAppsDB())
94 return FALSE;
95
96 DownloadApplicationsDB(APPLICATION_DATEBASE_URL);
97
98 if (!GetCurrentDirectoryW(MAX_PATH, szPath))
99 return FALSE;
100
101 swprintf(szCabPath, L"%s\\rappmgr.cab", szPath);
102
103 wcscat(szPath, L"\\rapps\\");
104 wcscpy(szAppsPath, szPath);
105
106 ExtractFilesFromCab(szCabPath, szAppsPath);
107
108 return TRUE;
109 }
110
111
112 BOOL
113 EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc)
114 {
115 HANDLE hFind = INVALID_HANDLE_VALUE;
116 WIN32_FIND_DATAW FindFileData;
117 WCHAR szPath[MAX_PATH];
118 WCHAR szAppsPath[MAX_PATH];
119 WCHAR szSectionLocale[MAX_PATH] = L"Section.";
120 WCHAR szCabPath[MAX_PATH];
121 WCHAR szLocale[4 + 1];
122 APPLICATION_INFO Info;
123
124 if (!GetCurrentDirectoryW(MAX_PATH, szPath))
125 {
126 return FALSE;
127 }
128
129 swprintf(szCabPath, L"%s\\rappmgr.cab", szPath);
130
131 wcscat(szPath, L"\\rapps\\");
132 wcscpy(szAppsPath, szPath);
133
134 if (!CreateDirectory(szPath, NULL) &&
135 GetLastError() != ERROR_ALREADY_EXISTS)
136 {
137 return FALSE;
138 }
139
140 GetLocaleInfoW(GetUserDefaultLCID(), LOCALE_ILANGUAGE, szLocale, sizeof(szLocale) / sizeof(WCHAR));
141 wcscat(szSectionLocale, szLocale);
142
143 wcscat(szPath, L"*.txt");
144
145 hFind = FindFirstFileW(szPath, &FindFileData);
146 if (hFind == INVALID_HANDLE_VALUE)
147 {
148 if (GetFileAttributesW(szCabPath) == INVALID_FILE_ATTRIBUTES)
149 DownloadApplicationsDB(APPLICATION_DATEBASE_URL);
150
151 ExtractFilesFromCab(szCabPath, szAppsPath);
152 hFind = FindFirstFileW(szPath, &FindFileData);
153 if (hFind == INVALID_HANDLE_VALUE)
154 return FALSE;
155 }
156
157 #define GET_STRING1(a, b) \
158 if (!ParserGetString(szSectionLocale, a, b, MAX_PATH, FindFileData.cFileName)) \
159 if (!ParserGetString(L"Section", a, b, MAX_PATH, FindFileData.cFileName)) \
160 continue;
161
162 #define GET_STRING2(a, b) \
163 if (!ParserGetString(szSectionLocale, a, b, MAX_PATH, FindFileData.cFileName)) \
164 if (!ParserGetString(L"Section", a, b, MAX_PATH, FindFileData.cFileName)) \
165 b[0] = '\0';
166
167 do
168 {
169 Info.Category = ParserGetInt(szSectionLocale, L"Category", FindFileData.cFileName);
170 if (Info.Category == -1)
171 {
172 Info.Category = ParserGetInt(L"Section", L"Category", FindFileData.cFileName);
173 if (Info.Category == -1)
174 continue;
175 }
176
177 if (EnumType != Info.Category && EnumType != ENUM_ALL_AVAILABLE) continue;
178
179 GET_STRING1(L"Name", Info.szName);
180 GET_STRING1(L"URLDownload", Info.szUrlDownload);
181
182 GET_STRING2(L"RegName", Info.szRegName);
183 GET_STRING2(L"Version", Info.szVersion);
184 GET_STRING2(L"Licence", Info.szLicence);
185 GET_STRING2(L"Description", Info.szDesc);
186 GET_STRING2(L"Size", Info.szSize);
187 GET_STRING2(L"URLSite", Info.szUrlSite);
188 GET_STRING2(L"CDPath", Info.szCDPath);
189
190 if (!lpEnumProc(Info)) break;
191 }
192 while (FindNextFileW(hFind, &FindFileData) != 0);
193
194 FindClose(hFind);
195
196 return TRUE;
197 }