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