The MinGW.org Installation Manager Tool
Révision | dffa416377776180fa00a201d5dec4b367d531d5 (tree) |
---|---|
l'heure | 2009-01-05 08:21:29 |
Auteur | John E. <tdragon@user...> |
Commiter | John E. |
Source restructuring
* Moved major GUI components into their own source files
* Removed a couple of dead files
@@ -0,0 +1,62 @@ | ||
1 | +/** \file categorytree.c | |
2 | + * | |
3 | + * Created: JohnE, 2009-01-03 | |
4 | + */ | |
5 | + | |
6 | + | |
7 | +#include "categorytree.hh" | |
8 | + | |
9 | +#define WIN32_LEAN_AND_MEAN | |
10 | +#include <windows.h> | |
11 | +#include <commctrl.h> | |
12 | +#include "mainwnd.hh" | |
13 | +#include "packagelist.hh" | |
14 | +#include "pkgindex.hh" | |
15 | +#include "resource.h" | |
16 | + | |
17 | + | |
18 | +void CategoryTree_Reload() | |
19 | +{ | |
20 | + TreeView_DeleteAllItems(GetDlgItem(g_hmainwnd, IDC_CATLIST)); | |
21 | + | |
22 | + TVINSERTSTRUCT tvins; | |
23 | + tvins.item.mask = TVIF_TEXT | TVIF_PARAM; | |
24 | + tvins.item.pszText = (CHAR*)"All Packages"; | |
25 | + tvins.item.cchTextMax = 199; | |
26 | + tvins.item.lParam = 0; | |
27 | + tvins.hInsertAfter = TVI_LAST; | |
28 | + tvins.hParent = TVI_ROOT; | |
29 | + SendMessage( | |
30 | + GetDlgItem(g_hmainwnd, IDC_CATLIST), | |
31 | + TVM_INSERTITEM, | |
32 | + 0, | |
33 | + (LPARAM)(LPTVINSERTSTRUCT)&tvins | |
34 | + ); | |
35 | + | |
36 | + int i; | |
37 | + for (i = 0; i < PkgIndex_NumHeadings(); ++i) | |
38 | + { | |
39 | + tvins.item.pszText = (CHAR*)PkgIndex_GetHeading(i); | |
40 | + tvins.item.cchTextMax = 199; | |
41 | + tvins.item.lParam = -1; | |
42 | + tvins.hInsertAfter = TVI_LAST; | |
43 | + tvins.hParent = TVI_ROOT; | |
44 | + HTREEITEM hitem = (HTREEITEM)SendMessage( | |
45 | + GetDlgItem(g_hmainwnd, IDC_CATLIST), TVM_INSERTITEM, 0, | |
46 | + (LPARAM)(LPTVINSERTSTRUCT)&tvins | |
47 | + ); | |
48 | + const int* j; | |
49 | + for (j = PkgIndex_GetHeadingChildren(i); *j != -1; ++j) | |
50 | + { | |
51 | + tvins.item.pszText = (CHAR*)PkgIndex_GetCategory(*j); | |
52 | + tvins.item.cchTextMax = 199; | |
53 | + tvins.item.lParam = *j + 1; | |
54 | + tvins.hInsertAfter = TVI_LAST; | |
55 | + tvins.hParent = hitem; | |
56 | + SendMessage(GetDlgItem(g_hmainwnd, IDC_CATLIST), TVM_INSERTITEM, | |
57 | + 0, (LPARAM)(LPTVINSERTSTRUCT)&tvins); | |
58 | + } | |
59 | + } | |
60 | + int cats[] = {0, -1}; | |
61 | + PackageList_SetCategories(cats); | |
62 | +} |
@@ -0,0 +1,22 @@ | ||
1 | +/** \file categorytree.hh | |
2 | + * | |
3 | + * Created: JohnE, 2009-01-03 | |
4 | + */ | |
5 | +#ifndef CATEGORYTREE_HH_INC | |
6 | +#define CATEGORYTREE_HH_INC | |
7 | + | |
8 | + | |
9 | +#ifdef __cplusplus | |
10 | +extern "C" { | |
11 | +#endif | |
12 | + | |
13 | + | |
14 | +void CategoryTree_Reload(); | |
15 | + | |
16 | + | |
17 | +#ifdef __cplusplus | |
18 | +} //extern "C" | |
19 | +#endif | |
20 | + | |
21 | + | |
22 | +#endif // CATEGORYTREE_HH_INC |
@@ -1,14 +0,0 @@ | ||
1 | - | |
2 | -#include <curl/curl.h> | |
3 | - | |
4 | -static struct CurlInit | |
5 | -{ | |
6 | - CurlInit() | |
7 | - { | |
8 | - curl_global_init(CURL_GLOBAL_ALL); | |
9 | - } | |
10 | - ~CurlInit() | |
11 | - { | |
12 | - curl_global_cleanup(); | |
13 | - } | |
14 | -} curl_init; |
@@ -9,12 +9,13 @@ | ||
9 | 9 | #include <ole2.h> |
10 | 10 | #include "resource.h" |
11 | 11 | #include "pkg_const.h" |
12 | -#include "package.hh" | |
13 | 12 | #include "selectinst.hh" |
14 | -#include "ui.hh" | |
15 | 13 | #include "sashwnd.hh" |
16 | 14 | #include "winmain.hh" |
17 | 15 | #include "editreposdlg.hh" |
16 | +#include "ui_general.hh" | |
17 | +#include "pkgindex.hh" | |
18 | +#include "packagelist.hh" | |
18 | 19 | |
19 | 20 | |
20 | 21 | HWND g_hmainwnd = 0; |
@@ -66,44 +67,14 @@ void NewHorzSashPos(int pos) | ||
66 | 67 | } |
67 | 68 | |
68 | 69 | |
69 | -static void InsertColumn | |
70 | - (HWND hlv, | |
71 | - const char* txt, | |
72 | - int index, | |
73 | - int fmt, | |
74 | - int width) | |
75 | -{ | |
76 | - int tlen = strlen(txt); | |
77 | - if (tlen >= 200) | |
78 | - return; | |
79 | - char* tcopy = malloc(tlen + 1); | |
80 | - strcpy(tcopy, txt); | |
81 | - LVCOLUMN lvc; | |
82 | - lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT; | |
83 | - lvc.fmt = fmt; | |
84 | - if (width > 0) | |
85 | - lvc.cx = width; | |
86 | - else | |
87 | - { | |
88 | - SIZE sz; | |
89 | - if (GetTextExtentPoint32(GetDC(hlv), tcopy, tlen, &sz)) | |
90 | - lvc.cx = sz.cx + 15; | |
91 | - else | |
92 | - lvc.cx = 100; | |
93 | - } | |
94 | - lvc.pszText = tcopy; | |
95 | - lvc.cchTextMax = tlen; | |
96 | - ListView_InsertColumn(hlv, index, &lvc); | |
97 | - free(tcopy); | |
98 | -} | |
99 | - | |
100 | - | |
101 | -static BOOL CALLBACK MainWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) | |
70 | +BOOL CALLBACK MainWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) | |
102 | 71 | { |
103 | 72 | switch(uMsg) |
104 | 73 | { |
105 | 74 | case WM_INITDIALOG: |
106 | 75 | { |
76 | + g_hmainwnd = hwndDlg; | |
77 | + | |
107 | 78 | HWND htb = GetDlgItem(hwndDlg, IDC_MAINTOOLBAR); |
108 | 79 | HIMAGELIST il = |
109 | 80 | ImageList_Create(24, 24, ILC_COLOR32 | ILC_MASK, 6, 0); |
@@ -133,9 +104,6 @@ static BOOL CALLBACK MainWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM | ||
133 | 104 | SendMessage(hcb, CB_ADDSTRING, 0, (LPARAM)"Release Status"); |
134 | 105 | SendMessage(hcb, CB_SETCURSEL, 0, 0); |
135 | 106 | |
136 | - //HWND hcl = GetDlgItem(hwndDlg, IDC_CATLIST); | |
137 | - //SendMessage(hcl, LB_ADDSTRING, 0, (LPARAM)"All"); | |
138 | - //SendMessage(hcl, LB_SETCURSEL, 0, 0); | |
139 | 107 | TVINSERTSTRUCT tvins; |
140 | 108 | tvins.item.mask = TVIF_TEXT | TVIF_PARAM; |
141 | 109 | tvins.item.pszText = (CHAR*)"All Packages"; |
@@ -150,26 +118,7 @@ static BOOL CALLBACK MainWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM | ||
150 | 118 | (LPARAM)(LPTVINSERTSTRUCT)&tvins |
151 | 119 | ); |
152 | 120 | |
153 | - HWND hlv = GetDlgItem(hwndDlg, IDC_COMPLIST); | |
154 | - ListView_SetExtendedListViewStyle(hlv, | |
155 | - LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP); | |
156 | - il = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 10, 0); | |
157 | - HBITMAP buttonsbmp = | |
158 | - LoadBitmap(g_hinstance, MAKEINTRESOURCE(IDB_STATES)); | |
159 | - ImageList_AddMasked(il, buttonsbmp, RGB(255, 0, 255)); | |
160 | - DeleteObject(buttonsbmp); | |
161 | - (void)ListView_SetImageList(hlv, il, LVSIL_SMALL); | |
162 | - SIZE sz; | |
163 | - sz.cx = 100; | |
164 | - HDC lvdc = GetDC(hlv); | |
165 | - GetTextExtentPoint32(lvdc, "sample string", 13, &sz); | |
166 | - ReleaseDC(hlv, lvdc); | |
167 | - InsertColumn(hlv, "", 0, LVCFMT_LEFT, 25); | |
168 | - InsertColumn(hlv, "Package", 1, LVCFMT_LEFT, sz.cx); | |
169 | - InsertColumn(hlv, "Installed Version", 2, LVCFMT_LEFT, 0); | |
170 | - InsertColumn(hlv, "Latest Version", 3, LVCFMT_LEFT, 0); | |
171 | - InsertColumn(hlv, "Size", 4, LVCFMT_RIGHT, 0); | |
172 | - InsertColumn(hlv, "Description", 5, LVCFMT_LEFT, sz.cx * 1.8); | |
121 | + PackageList_Create(); | |
173 | 122 | |
174 | 123 | HFONT hFont = (HFONT)SendMessage(hwndDlg, WM_GETFONT, 0, 0); |
175 | 124 | LOGFONT lf = {0}; |
@@ -223,17 +172,19 @@ static BOOL CALLBACK MainWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM | ||
223 | 172 | case LVN_GETDISPINFO: |
224 | 173 | { |
225 | 174 | ((NMLVDISPINFO*)lParam)->item.pszText = |
226 | - (char*)Pkg_GetSubItemText(((NMLVDISPINFO*)lParam)->item.lParam, | |
227 | - ((NMLVDISPINFO*)lParam)->item.iSubItem); | |
175 | + (char*)PkgIndex_PackageGetSubItemText( | |
176 | + ((NMLVDISPINFO*)lParam)->item.lParam, | |
177 | + ((NMLVDISPINFO*)lParam)->item.iSubItem | |
178 | + ); | |
228 | 179 | } |
229 | 180 | return 0; |
230 | 181 | case LVN_COLUMNCLICK: |
231 | - UI_SortListView(((LPNMLISTVIEW)lParam)->iSubItem); | |
182 | + PackageList_Sort(((LPNMLISTVIEW)lParam)->iSubItem); | |
232 | 183 | return 0; |
233 | 184 | case LVN_ITEMCHANGED: |
234 | 185 | if ((((LPNMLISTVIEW)lParam)->uChanged & LVIF_STATE) |
235 | 186 | && (((LPNMLISTVIEW)lParam)->uNewState & LVIS_SELECTED)) |
236 | - UI_OnListViewSelect(((LPNMLISTVIEW)lParam)->iItem); | |
187 | + PackageList_OnSelect(((LPNMLISTVIEW)lParam)->iItem); | |
237 | 188 | return 0; |
238 | 189 | case NM_CLICK: |
239 | 190 | { |
@@ -247,7 +198,7 @@ static BOOL CALLBACK MainWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM | ||
247 | 198 | if ((lvhti.flags & LVHT_ONITEMICON) |
248 | 199 | && !(lvhti.flags & LVHT_ONITEMLABEL) |
249 | 200 | && lvhti.iItem >= 0) |
250 | - UI_OnStateCycle(lvhti.iItem); | |
201 | + PackageList_OnStateCycle(lvhti.iItem); | |
251 | 202 | } |
252 | 203 | return 0; |
253 | 204 | case NM_RCLICK: |
@@ -268,12 +219,13 @@ static BOOL CALLBACK MainWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM | ||
268 | 219 | lvitem.mask = LVIF_PARAM; |
269 | 220 | ListView_GetItem(((LPNMHDR)lParam)->hwndFrom, &lvitem); |
270 | 221 | const char* instv = |
271 | - Pkg_GetInstalledVersion(lvitem.lParam); | |
222 | + PkgIndex_PackageGetInstalledVersion(lvitem.lParam); | |
272 | 223 | if (instv) |
273 | 224 | AppendMenu(menu, MF_SEPARATOR, -1, 0); |
274 | 225 | else |
275 | 226 | { |
276 | - int act = Pkg_GetSelectedAction(lvitem.lParam); | |
227 | + int act = | |
228 | + PkgIndex_PackageGetSelectedAction(lvitem.lParam); | |
277 | 229 | if (act != ACT_NO_CHANGE) |
278 | 230 | { |
279 | 231 | AppendMenu(menu, MF_STRING, |
@@ -296,15 +248,16 @@ static BOOL CALLBACK MainWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM | ||
296 | 248 | switch (ret) |
297 | 249 | { |
298 | 250 | case 10000 + ACT_INSTALL_VERSION: |
299 | - Pkg_SelectAction(lvitem.lParam, | |
251 | + PkgIndex_PackageSelectAction(lvitem.lParam, | |
300 | 252 | ACT_INSTALL_VERSION); |
301 | 253 | break; |
302 | 254 | case 10000 + ACT_NO_CHANGE: |
303 | - Pkg_SelectAction(lvitem.lParam, ACT_NO_CHANGE); | |
255 | + PkgIndex_PackageSelectAction(lvitem.lParam, | |
256 | + ACT_NO_CHANGE); | |
304 | 257 | break; |
305 | 258 | } |
306 | 259 | lvitem.mask = LVIF_IMAGE; |
307 | - lvitem.iImage = Pkg_GetStateImage(lvitem.lParam); | |
260 | + lvitem.iImage = PkgIndex_PackageGetStateImage(lvitem.lParam); | |
308 | 261 | ListView_SetItem(((LPNMHDR)lParam)->hwndFrom, &lvitem); |
309 | 262 | } |
310 | 263 | } |
@@ -145,6 +145,10 @@ | ||
145 | 145 | <Unit filename="bzip2\randtable.c"> |
146 | 146 | <Option compilerVar="CC" /> |
147 | 147 | </Unit> |
148 | + <Unit filename="categorytree.c"> | |
149 | + <Option compilerVar="CC" /> | |
150 | + </Unit> | |
151 | + <Unit filename="categorytree.hh" /> | |
148 | 152 | <Unit filename="download.c"> |
149 | 153 | <Option compilerVar="CC" /> |
150 | 154 | </Unit> |
@@ -170,15 +174,25 @@ | ||
170 | 174 | <Option compilerVar="CC" /> |
171 | 175 | </Unit> |
172 | 176 | <Unit filename="multiuser.hh" /> |
173 | - <Unit filename="package.cpp" /> | |
174 | - <Unit filename="package.hh" /> | |
177 | + <Unit filename="packagelist.c"> | |
178 | + <Option compilerVar="CC" /> | |
179 | + </Unit> | |
180 | + <Unit filename="packagelist.hh" /> | |
181 | + <Unit filename="packageview.c"> | |
182 | + <Option compilerVar="CC" /> | |
183 | + </Unit> | |
184 | + <Unit filename="packageview.hh" /> | |
175 | 185 | <Unit filename="pkg_const.h" /> |
176 | 186 | <Unit filename="pkgindex.cpp" /> |
177 | - <Unit filename="pkgindex.hpp" /> | |
187 | + <Unit filename="pkgindex.hh" /> | |
178 | 188 | <Unit filename="previnstalls.c"> |
179 | 189 | <Option compilerVar="CC" /> |
180 | 190 | </Unit> |
181 | 191 | <Unit filename="previnstalls.hh" /> |
192 | + <Unit filename="progressthread.c"> | |
193 | + <Option compilerVar="CC" /> | |
194 | + </Unit> | |
195 | + <Unit filename="progressthread.hh" /> | |
182 | 196 | <Unit filename="ref.hpp" /> |
183 | 197 | <Unit filename="resource.h" /> |
184 | 198 | <Unit filename="resource.rc"> |
@@ -201,13 +215,17 @@ | ||
201 | 215 | <Unit filename="tinyxml\tinyxmlparser.cpp" /> |
202 | 216 | <Unit filename="tracked_install.cpp" /> |
203 | 217 | <Unit filename="tracked_install.hpp" /> |
204 | - <Unit filename="ui.cpp" /> | |
205 | - <Unit filename="ui.hh" /> | |
218 | + <Unit filename="ui_general.c"> | |
219 | + <Option compilerVar="CC" /> | |
220 | + </Unit> | |
221 | + <Unit filename="ui_general.hh" /> | |
206 | 222 | <Unit filename="versioncompare.c"> |
207 | 223 | <Option compilerVar="CC" /> |
208 | 224 | </Unit> |
209 | 225 | <Unit filename="versioncompare.hh" /> |
210 | - <Unit filename="winmain.cpp" /> | |
226 | + <Unit filename="winmain.c"> | |
227 | + <Option compilerVar="CC" /> | |
228 | + </Unit> | |
211 | 229 | <Unit filename="winmain.hh" /> |
212 | 230 | <Unit filename="zlib\MODIFIED_ZLIB.txt" /> |
213 | 231 | <Unit filename="zlib\adler32.c"> |
@@ -1,159 +0,0 @@ | ||
1 | - | |
2 | -#include "package.hh" | |
3 | - | |
4 | -#define WIN32_LEAN_AND_MEAN | |
5 | -#include <windows.h> | |
6 | -#include "pkgindex.hpp" | |
7 | -#include "pkg_const.h" | |
8 | -#include "versioncompare.hh" | |
9 | - | |
10 | - | |
11 | -extern "C" const char* Pkg_GetSubItemText(LPARAM lv_lparam, int index) | |
12 | -{ | |
13 | - static std::string vstr; | |
14 | - | |
15 | - Package* pkg = reinterpret_cast< Package* >(lv_lparam); | |
16 | - switch (index) | |
17 | - { | |
18 | - case 1: | |
19 | - return pkg->m_id.c_str(); | |
20 | - case 2: | |
21 | - return pkg->m_installed_version.c_str(); | |
22 | - case 3: | |
23 | - if (pkg->m_versions.size() > 0) | |
24 | - return pkg->m_versions.front()->m_version.c_str(); | |
25 | - break; | |
26 | - case 5: | |
27 | - return pkg->m_title.c_str(); | |
28 | - default: | |
29 | - break; | |
30 | - } | |
31 | - return ""; | |
32 | -} | |
33 | - | |
34 | - | |
35 | -extern "C" const char* Pkg_GetInstalledVersion(LPARAM lv_lparam) | |
36 | -{ | |
37 | - Package* pkg = reinterpret_cast< Package* >(lv_lparam); | |
38 | - if (pkg->m_installed_version.length() > 0) | |
39 | - return pkg->m_installed_version.c_str(); | |
40 | - return 0; | |
41 | -} | |
42 | - | |
43 | - | |
44 | -extern "C" int Pkg_GetStateImage(LPARAM lv_lparam) | |
45 | -{ | |
46 | - return reinterpret_cast< Package* >(lv_lparam)->GetStateImage(); | |
47 | -} | |
48 | - | |
49 | - | |
50 | -extern "C" int Pkg_GetSelectedAction(LPARAM lv_lparam) | |
51 | -{ | |
52 | - return reinterpret_cast< Package* >(lv_lparam)->m_selected_action; | |
53 | -} | |
54 | - | |
55 | - | |
56 | -extern "C" void Pkg_SelectAction(LPARAM lv_lparam, int action) | |
57 | -{ | |
58 | - reinterpret_cast< Package* >(lv_lparam)->m_selected_action = action; | |
59 | -} | |
60 | - | |
61 | - | |
62 | -PkgVersion::PkgVersion(const char* ver, int status) | |
63 | - : m_version(ver), | |
64 | - m_status(status) | |
65 | -{ | |
66 | -} | |
67 | - | |
68 | - | |
69 | -static bool PkgVersionOrder | |
70 | - (const PkgVersion::Ref& p1, | |
71 | - const PkgVersion::Ref& p2) | |
72 | -{ | |
73 | - if (p1->m_status != p2->m_status) | |
74 | - return (p1->m_status > p2->m_status); | |
75 | - return (VersionCompare(p1->m_version.c_str(), p2->m_version.c_str()) > 0); | |
76 | -} | |
77 | - | |
78 | - | |
79 | -Package::Package(const char* id, const TiXmlElement* pack_el) | |
80 | - : m_id(id), | |
81 | - m_selected_action(ACT_NO_CHANGE), | |
82 | - m_selected_version(-1) | |
83 | -{ | |
84 | - for (const TiXmlElement* aff_el = pack_el->FirstChildElement("affiliate"); | |
85 | - aff_el; | |
86 | - aff_el = aff_el->NextSiblingElement("affiliate")) | |
87 | - { | |
88 | - const char* aff_id = aff_el->Attribute("id"); | |
89 | - if (aff_id && aff_id[0]) | |
90 | - { | |
91 | - int cat = PkgIndex::CategoryIndex(aff_id); | |
92 | - if (cat >= 0) | |
93 | - m_categories.insert(cat); | |
94 | - } | |
95 | - } | |
96 | - const TiXmlElement* desc_el = pack_el->FirstChildElement("description"); | |
97 | - if (desc_el) | |
98 | - { | |
99 | - const char* title = desc_el->Attribute("title"); | |
100 | - if (title && title[0]) | |
101 | - m_title = title; | |
102 | - for (const TiXmlNode* node = desc_el->FirstChild(); | |
103 | - node; | |
104 | - node = node->NextSibling()) | |
105 | - { | |
106 | - if (node->ToText()) | |
107 | - m_description += node->Value(); | |
108 | - else if (node->ToElement() && strcmp(node->Value(), "p") == 0) | |
109 | - m_description += "\r\n\r\n"; | |
110 | - } | |
111 | - } | |
112 | - for (const TiXmlElement* rel_el = pack_el->FirstChildElement("release"); | |
113 | - rel_el; | |
114 | - rel_el = rel_el->NextSiblingElement("release")) | |
115 | - { | |
116 | - const char* ver = rel_el->Attribute("version"); | |
117 | - if (ver && ver[0]) | |
118 | - { | |
119 | - int status = PSTATUS_STABLE; | |
120 | - const char* stat = rel_el->Attribute("status"); | |
121 | - if (stat) | |
122 | - { | |
123 | - if (strcmp(stat, "alpha") == 0) | |
124 | - status = PSTATUS_ALPHA; | |
125 | - } | |
126 | - m_versions.push_back(PkgVersion::Ref(new PkgVersion(ver, status))); | |
127 | - } | |
128 | - } | |
129 | - if (m_versions.size() > 0) | |
130 | - std::sort(m_versions.begin(), m_versions.end(), PkgVersionOrder); | |
131 | -} | |
132 | - | |
133 | - | |
134 | -int Package::GetStateImage() const | |
135 | -{ | |
136 | - const char* sel_ver = ""; | |
137 | - if (m_selected_version >= 0) | |
138 | - sel_ver = m_versions[m_selected_version]->m_version.c_str(); | |
139 | - if (m_installed_version.length() <= 0) | |
140 | - { | |
141 | - if (m_selected_action == ACT_NO_CHANGE) | |
142 | - return 1; | |
143 | - else if (m_selected_action == ACT_INSTALL_VERSION) | |
144 | - return 5; | |
145 | - } | |
146 | - else | |
147 | - { | |
148 | - if (m_selected_action == ACT_NO_CHANGE) | |
149 | - return 2; | |
150 | - else if (m_selected_action == ACT_INSTALL_VERSION) | |
151 | - return (VersionCompare(m_installed_version.c_str(), sel_ver) < 0) | |
152 | - ? 7 : 8; | |
153 | - else if (m_selected_action == ACT_REMOVE) | |
154 | - return 9; | |
155 | - else if (m_selected_action == ACT_REINSTALL) | |
156 | - return 6; | |
157 | - } | |
158 | - return 0; | |
159 | -} |
@@ -1,64 +0,0 @@ | ||
1 | -#ifndef PACKAGE_HH_INC | |
2 | -#define PACKAGE_HH_INC | |
3 | - | |
4 | - | |
5 | -#define WIN32_LEAN_AND_MEAN | |
6 | -#include <windows.h> | |
7 | - | |
8 | - | |
9 | -#ifdef __cplusplus | |
10 | - | |
11 | -#include <string> | |
12 | -#include <set> | |
13 | -#include <vector> | |
14 | -#include "ref.hpp" | |
15 | -#include "tinyxml/tinyxml.h" | |
16 | - | |
17 | - | |
18 | -struct PkgVersion | |
19 | -{ | |
20 | - typedef RefType< PkgVersion >::Ref Ref; | |
21 | - | |
22 | - std::string m_version; | |
23 | - int m_status; | |
24 | - | |
25 | - PkgVersion(const char* ver, int status); | |
26 | -}; | |
27 | - | |
28 | - | |
29 | -struct Package | |
30 | -{ | |
31 | - typedef RefType< Package >::Ref Ref; | |
32 | - | |
33 | - std::string m_id; | |
34 | - std::set< int > m_categories; | |
35 | - std::string m_installed_version; | |
36 | - std::string m_title; | |
37 | - std::string m_description; | |
38 | - int m_selected_action; | |
39 | - std::vector< PkgVersion::Ref > m_versions; | |
40 | - int m_selected_version; | |
41 | - | |
42 | - Package(const char* id, const TiXmlElement* pack_el); | |
43 | - | |
44 | - int GetStateImage() const; | |
45 | -}; | |
46 | - | |
47 | - | |
48 | -extern "C" { | |
49 | -#endif // defined __cplusplus | |
50 | - | |
51 | - | |
52 | -int Pkg_GetSelectedAction(LPARAM lv_lparam); | |
53 | -const char* Pkg_GetInstalledVersion(LPARAM lv_lparam); | |
54 | -const char* Pkg_GetSubItemText(LPARAM lv_lparam, int index); | |
55 | -void Pkg_SelectAction(LPARAM lv_lparam, int action); | |
56 | -int Pkg_GetStateImage(LPARAM lv_lparam); | |
57 | - | |
58 | - | |
59 | -#ifdef __cplusplus | |
60 | -} //extern "C" | |
61 | -#endif | |
62 | - | |
63 | - | |
64 | -#endif // PACKAGE_HH_INC |
@@ -0,0 +1,224 @@ | ||
1 | +/** \file packagelist.c | |
2 | + * | |
3 | + * Created: JohnE, 2009-01-03 | |
4 | + */ | |
5 | + | |
6 | + | |
7 | +#include "packagelist.hh" | |
8 | + | |
9 | +#define WIN32_LEAN_AND_MEAN | |
10 | +#include <windows.h> | |
11 | +#include <commctrl.h> | |
12 | +#include <malloc.h> | |
13 | +#include <limits.h> | |
14 | +#include "pkgindex.hh" | |
15 | +#include "packageview.hh" | |
16 | +#include "mainwnd.hh" | |
17 | +#include "winmain.hh" | |
18 | +#include "versioncompare.hh" | |
19 | +#include "pkg_const.h" | |
20 | +#include "resource.h" | |
21 | + | |
22 | + | |
23 | +static HWND g_hpackagelist = 0; | |
24 | + | |
25 | + | |
26 | +static void InsertColumn | |
27 | + (HWND hlv, | |
28 | + const char* txt, | |
29 | + int index, | |
30 | + int fmt, | |
31 | + int width) | |
32 | +{ | |
33 | + int tlen = strlen(txt); | |
34 | + if (tlen >= 200) | |
35 | + return; | |
36 | + char* tcopy = malloc(tlen + 1); | |
37 | + strcpy(tcopy, txt); | |
38 | + LVCOLUMN lvc; | |
39 | + lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT; | |
40 | + lvc.fmt = fmt; | |
41 | + if (width > 0) | |
42 | + lvc.cx = width; | |
43 | + else | |
44 | + { | |
45 | + SIZE sz; | |
46 | + if (GetTextExtentPoint32(GetDC(hlv), tcopy, tlen, &sz)) | |
47 | + lvc.cx = sz.cx + 15; | |
48 | + else | |
49 | + lvc.cx = 100; | |
50 | + } | |
51 | + lvc.pszText = tcopy; | |
52 | + lvc.cchTextMax = tlen; | |
53 | + ListView_InsertColumn(hlv, index, &lvc); | |
54 | + free(tcopy); | |
55 | +} | |
56 | + | |
57 | + | |
58 | +void PackageList_Create() | |
59 | +{ | |
60 | + g_hpackagelist = GetDlgItem(g_hmainwnd, IDC_COMPLIST); | |
61 | + ListView_SetExtendedListViewStyle(g_hpackagelist, | |
62 | + LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP); | |
63 | + HIMAGELIST il = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 10, 0); | |
64 | + HBITMAP buttonsbmp = | |
65 | + LoadBitmap(g_hinstance, MAKEINTRESOURCE(IDB_STATES)); | |
66 | + ImageList_AddMasked(il, buttonsbmp, RGB(255, 0, 255)); | |
67 | + DeleteObject(buttonsbmp); | |
68 | + (void)ListView_SetImageList(g_hpackagelist, il, LVSIL_SMALL); | |
69 | + SIZE sz; | |
70 | + sz.cx = 100; | |
71 | + HDC lvdc = GetDC(g_hpackagelist); | |
72 | + GetTextExtentPoint32(lvdc, "sample string", 13, &sz); | |
73 | + ReleaseDC(g_hpackagelist, lvdc); | |
74 | + InsertColumn(g_hpackagelist, "", 0, LVCFMT_LEFT, 25); | |
75 | + InsertColumn(g_hpackagelist, "Package", 1, LVCFMT_LEFT, sz.cx); | |
76 | + InsertColumn(g_hpackagelist, "Installed Version", 2, LVCFMT_LEFT, 0); | |
77 | + InsertColumn(g_hpackagelist, "Latest Version", 3, LVCFMT_LEFT, 0); | |
78 | + InsertColumn(g_hpackagelist, "Size", 4, LVCFMT_RIGHT, 0); | |
79 | + InsertColumn(g_hpackagelist, "Description", 5, LVCFMT_LEFT, sz.cx * 1.8); | |
80 | +} | |
81 | + | |
82 | + | |
83 | +struct PackageListSorter | |
84 | +{ | |
85 | + short field; | |
86 | + short reverse; | |
87 | +}; | |
88 | + | |
89 | +int CALLBACK PackageListSortCompare(LPARAM lp1, LPARAM lp2, LPARAM lpsort) | |
90 | +{ | |
91 | + struct PackageListSorter* sort = (struct PackageListSorter*)lpsort; | |
92 | + int ret = 0; | |
93 | + switch (sort->field) | |
94 | + { | |
95 | + case 1: | |
96 | + ret = strcmp(PkgIndex_PackageGetID(lp1), PkgIndex_PackageGetID(lp2)); | |
97 | + break; | |
98 | + case 2: | |
99 | + ret = VersionCompare(PkgIndex_PackageGetInstalledVersion(lp1), | |
100 | + PkgIndex_PackageGetInstalledVersion(lp2)); | |
101 | + break; | |
102 | + case 3: | |
103 | + ret = VersionCompare(PkgIndex_PackageGetLatestVersion(lp1), | |
104 | + PkgIndex_PackageGetLatestVersion(lp2)); | |
105 | + break; | |
106 | + case 5: | |
107 | + ret = stricmp(PkgIndex_PackageGetTitle(lp1), | |
108 | + PkgIndex_PackageGetTitle(lp2)); | |
109 | + break; | |
110 | + }; | |
111 | + return ret * sort->reverse; | |
112 | +}; | |
113 | + | |
114 | +void PackageList_Sort(int column) | |
115 | +{ | |
116 | + static int cur_column = 0; | |
117 | + | |
118 | + if (cur_column == column) | |
119 | + cur_column = column + 6; | |
120 | + else | |
121 | + cur_column = column; | |
122 | + | |
123 | + struct PackageListSorter sort; | |
124 | + sort.field = cur_column % 6; | |
125 | + sort.reverse = (cur_column >= 6) ? -1 : 1; | |
126 | + ListView_SortItems(g_hpackagelist, PackageListSortCompare, (LPARAM)&sort); | |
127 | +} | |
128 | + | |
129 | + | |
130 | +void PackageList_OnSelect(int sel) | |
131 | +{ | |
132 | + LVITEM lvitem; | |
133 | + lvitem.iItem = sel; | |
134 | + lvitem.iSubItem = 0; | |
135 | + lvitem.mask = LVIF_PARAM; | |
136 | + ListView_GetItem(g_hpackagelist, &lvitem); | |
137 | + PackageView_SetPackage(lvitem.lParam); | |
138 | +} | |
139 | + | |
140 | + | |
141 | +void PackageList_OnStateCycle(int sel) | |
142 | +{ | |
143 | + LVITEM lvitem; | |
144 | + lvitem.iItem = sel; | |
145 | + lvitem.iSubItem = 0; | |
146 | + lvitem.mask = LVIF_PARAM; | |
147 | + ListView_GetItem(g_hpackagelist, &lvitem); | |
148 | + if (PkgIndex_PackageGetSelectedAction(lvitem.lParam) == ACT_INSTALL_VERSION) | |
149 | + PkgIndex_PackageSelectAction(lvitem.lParam, ACT_NO_CHANGE); | |
150 | + else | |
151 | + PkgIndex_PackageSelectAction(lvitem.lParam, ACT_INSTALL_VERSION); | |
152 | + lvitem.mask = LVIF_IMAGE; | |
153 | + lvitem.iImage = PkgIndex_PackageGetStateImage(lvitem.lParam); | |
154 | + ListView_SetItem(g_hpackagelist, &lvitem); | |
155 | +} | |
156 | + | |
157 | + | |
158 | +static void AddPackage(int package) | |
159 | +{ | |
160 | + LVITEM lvi; | |
161 | + lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; | |
162 | + lvi.iItem = INT_MAX; | |
163 | + lvi.iSubItem = 0; | |
164 | + char emptystr = 0; | |
165 | + lvi.pszText = &emptystr; | |
166 | + lvi.iImage = PkgIndex_PackageGetStateImage(package); | |
167 | + lvi.lParam = package; | |
168 | + lvi.iItem = ListView_InsertItem(g_hpackagelist, &lvi); | |
169 | + lvi.mask = LVIF_TEXT; | |
170 | + lvi.pszText = LPSTR_TEXTCALLBACK; | |
171 | + int i; | |
172 | + for (i = 1; i <= 5; ++i) | |
173 | + { | |
174 | + lvi.iSubItem = i; | |
175 | + ListView_SetItem(g_hpackagelist, &lvi); | |
176 | + } | |
177 | + if (lvi.iItem == 0) | |
178 | + { | |
179 | + ListView_SetItemState(g_hpackagelist, 0, | |
180 | + LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); | |
181 | + } | |
182 | +} | |
183 | + | |
184 | + | |
185 | +void PackageList_SetCategories(const int* categories) | |
186 | +{ | |
187 | + ListView_DeleteAllItems(g_hpackagelist); | |
188 | + | |
189 | + if (*categories == -1) | |
190 | + { | |
191 | + PackageView_SetPackage(-1); | |
192 | + return; | |
193 | + } | |
194 | + | |
195 | + int have_item = 0; | |
196 | + if (*categories == 0) | |
197 | + { | |
198 | + int i = 0; | |
199 | + for (; i < PkgIndex_NumPackages(); ++i) | |
200 | + AddPackage(i); | |
201 | + have_item = (i > 0); | |
202 | + } | |
203 | + else | |
204 | + { | |
205 | + int i = 0; | |
206 | + for (; i < PkgIndex_NumPackages(); ++i) | |
207 | + { | |
208 | + if (PkgIndex_PackageInAnyOf(i, categories)) | |
209 | + { | |
210 | + AddPackage(i); | |
211 | + if (!have_item) | |
212 | + have_item = 1; | |
213 | + } | |
214 | + } | |
215 | + } | |
216 | + | |
217 | + if (have_item) | |
218 | + { | |
219 | + ListView_SetItemState(g_hpackagelist, 0, LVIS_SELECTED | LVIS_FOCUSED, | |
220 | + LVIS_SELECTED | LVIS_FOCUSED); | |
221 | + } | |
222 | + else | |
223 | + PackageView_SetPackage(-1); | |
224 | +} |
@@ -0,0 +1,26 @@ | ||
1 | +/** \file packagelist.hh | |
2 | + * | |
3 | + * Created: JohnE, 2009-01-03 | |
4 | + */ | |
5 | +#ifndef PACKAGELIST_HH_INC | |
6 | +#define PACKAGELIST_HH_INC | |
7 | + | |
8 | + | |
9 | +#ifdef __cplusplus | |
10 | +extern "C" { | |
11 | +#endif | |
12 | + | |
13 | + | |
14 | +void PackageList_Create(); | |
15 | +void PackageList_Sort(int column); | |
16 | +void PackageList_OnSelect(int sel); | |
17 | +void PackageList_OnStateCycle(int sel); | |
18 | +void PackageList_SetCategories(const int* categories); | |
19 | + | |
20 | + | |
21 | +#ifdef __cplusplus | |
22 | +} //extern "C" | |
23 | +#endif | |
24 | + | |
25 | + | |
26 | +#endif // PACKAGELIST_HH_INC |
@@ -0,0 +1,64 @@ | ||
1 | +/** \file packageview.c | |
2 | + * | |
3 | + * Created: JohnE, 2009-01-03 | |
4 | + */ | |
5 | + | |
6 | + | |
7 | +#include "packageview.hh" | |
8 | + | |
9 | +#define WIN32_LEAN_AND_MEAN | |
10 | +#include <windows.h> | |
11 | +#include <windowsx.h> | |
12 | +#include <stdio.h> | |
13 | +#include "mainwnd.hh" | |
14 | +#include "pkgindex.hh" | |
15 | +#include "pkg_const.h" | |
16 | +#include "resource.h" | |
17 | + | |
18 | + | |
19 | +void PackageView_SetPackage(int package) | |
20 | +{ | |
21 | + if (package < 0) | |
22 | + { | |
23 | + Static_SetText(GetDlgItem(g_hmainwnd, IDC_DESCTITLE), ""); | |
24 | + Edit_SetText(GetDlgItem(g_hmainwnd, IDC_FULLDESC), ""); | |
25 | + (void)ComboBox_ResetContent(GetDlgItem(g_hmainwnd, IDC_INSTVERSION)); | |
26 | + EnableWindow(GetDlgItem(g_hmainwnd, IDC_INSTVERSION), FALSE); | |
27 | + EnableWindow(GetDlgItem(g_hmainwnd, IDC_FULLDESC), FALSE); | |
28 | + return; | |
29 | + } | |
30 | + | |
31 | + Edit_SetText(GetDlgItem(g_hmainwnd, IDC_FULLDESC), | |
32 | + PkgIndex_PackageGetDescription(package)); | |
33 | + EnableWindow(GetDlgItem(g_hmainwnd, IDC_FULLDESC), TRUE); | |
34 | + Static_SetText(GetDlgItem(g_hmainwnd, IDC_DESCTITLE), | |
35 | + PkgIndex_PackageGetTitle(package)); | |
36 | + (void)ComboBox_ResetContent(GetDlgItem(g_hmainwnd, IDC_INSTVERSION)); | |
37 | + char vstr[1024]; | |
38 | + int i; | |
39 | + for (i = 0; i < PkgIndex_PackageNumVersions(package); ++i) | |
40 | + { | |
41 | + if (PkgIndex_PackageVersionGetStatus(package, i) == PSTATUS_ALPHA) | |
42 | + { | |
43 | + snprintf(vstr, 1024, "Alpha: %s", | |
44 | + PkgIndex_PackageVersionGetString(package, i)); | |
45 | + } | |
46 | + else | |
47 | + { | |
48 | + snprintf(vstr, 1024, "Stable: %s", | |
49 | + PkgIndex_PackageVersionGetString(package, i)); | |
50 | + } | |
51 | + (void)ComboBox_AddString(GetDlgItem(g_hmainwnd, IDC_INSTVERSION), vstr); | |
52 | + } | |
53 | + if (i > 0) | |
54 | + { | |
55 | + EnableWindow(GetDlgItem(g_hmainwnd, IDC_INSTVERSION), TRUE); | |
56 | + (void)ComboBox_SetCurSel(GetDlgItem(g_hmainwnd, IDC_INSTVERSION), 0); | |
57 | + PkgIndex_PackageSetSelectedVersion(package, 0); | |
58 | + } | |
59 | + else | |
60 | + { | |
61 | + EnableWindow(GetDlgItem(g_hmainwnd, IDC_INSTVERSION), FALSE); | |
62 | + PkgIndex_PackageSetSelectedVersion(package, -1); | |
63 | + } | |
64 | +} |
@@ -0,0 +1,22 @@ | ||
1 | +/** \file packageview.hh | |
2 | + * | |
3 | + * Created: JohnE, 2009-01-03 | |
4 | + */ | |
5 | +#ifndef PACKAGEVIEW_HH_INC | |
6 | +#define PACKAGEVIEW_HH_INC | |
7 | + | |
8 | + | |
9 | +#ifdef __cplusplus | |
10 | +extern "C" { | |
11 | +#endif | |
12 | + | |
13 | + | |
14 | +void PackageView_SetPackage(int package); | |
15 | + | |
16 | + | |
17 | +#ifdef __cplusplus | |
18 | +} //extern "C" | |
19 | +#endif | |
20 | + | |
21 | + | |
22 | +#endif // PACKAGEVIEW_HH_INC |
@@ -4,97 +4,142 @@ | ||
4 | 4 | */ |
5 | 5 | |
6 | 6 | |
7 | -#include "pkgindex.hpp" | |
7 | +#include "pkgindex.hh" | |
8 | 8 | |
9 | +#include <vector> | |
9 | 10 | #include <string> |
10 | -#include <cstdarg> | |
11 | +#include <map> | |
12 | +#include <set> | |
13 | +#include <algorithm> | |
11 | 14 | #include "tinyxml/tinyxml.h" |
12 | -#include "package.hh" | |
13 | -#include "error.hh" | |
14 | 15 | #include "getbindir.hh" |
16 | +#include "error.hh" | |
17 | +#include "versioncompare.hh" | |
18 | +#include "pkg_const.h" | |
15 | 19 | |
16 | 20 | |
17 | -std::vector< std::string > PkgIndex::sm_index_categories; | |
18 | -PkgIndex::StringIntMap PkgIndex::sm_id_categories; | |
19 | -PkgIndex::StringPackageMap PkgIndex::sm_id_packages; | |
20 | -std::vector< std::pair< std::string, std::list< int > > > PkgIndex::sm_headings; | |
21 | - | |
22 | - | |
23 | -static const char* NonEmptyAttribute(const TiXmlElement* el, const char* name) | |
24 | -{ | |
25 | - const char* attr = el->Attribute(name); | |
26 | - if (attr && attr[0]) | |
27 | - return attr; | |
28 | - return 0; | |
29 | -} | |
30 | - | |
31 | - | |
32 | -int PkgIndex::NumCategories() | |
33 | -{ | |
34 | - return sm_index_categories.size(); | |
35 | -} | |
21 | +typedef std::map< std::string, int > StringIntMap; | |
36 | 22 | |
37 | 23 | |
38 | -const char* PkgIndex::GetCategory(int cat) | |
24 | +struct PkgVersion | |
39 | 25 | { |
40 | - return sm_index_categories[cat].c_str(); | |
41 | -} | |
42 | - | |
43 | - | |
44 | -int PkgIndex::CategoryIndex(const char* cat_id) | |
45 | -{ | |
46 | - StringIntMap::iterator found = sm_id_categories.find(cat_id); | |
47 | - if (found == sm_id_categories.end()) | |
48 | - return -1; | |
49 | - return found->second; | |
50 | -} | |
26 | + std::string version; | |
27 | + int status; | |
51 | 28 | |
29 | + PkgVersion(const char* ver, int stat) | |
30 | + : version(ver), | |
31 | + status(stat) | |
32 | + { | |
33 | + } | |
34 | +}; | |
52 | 35 | |
53 | -int PkgIndex::NumHeadings() | |
36 | +struct Package | |
54 | 37 | { |
55 | - return sm_headings.size(); | |
56 | -} | |
57 | - | |
58 | - | |
59 | -char const* PkgIndex::GetHeading(int heading) | |
38 | + std::string id; | |
39 | + std::set< int > categories; | |
40 | + std::string installed_version; | |
41 | + std::string title; | |
42 | + std::string description; | |
43 | + int selected_action; | |
44 | + std::vector< PkgVersion > versions; | |
45 | + int selected_version; | |
46 | + | |
47 | + Package(const char* pid, const TiXmlElement* pack_el); | |
48 | +}; | |
49 | + | |
50 | +static bool PkgVersionOrder | |
51 | + (const PkgVersion& p1, | |
52 | + const PkgVersion& p2) | |
60 | 53 | { |
61 | - return sm_headings[heading].first.c_str(); | |
54 | + if (p1.status != p2.status) | |
55 | + return (p1.status > p2.status); | |
56 | + return (VersionCompare(p1.version.c_str(), p2.version.c_str()) > 0); | |
62 | 57 | } |
63 | 58 | |
64 | 59 | |
65 | -std::list< int >::const_iterator PkgIndex::HeadingChildren_Begin(int heading) | |
60 | +static struct PkgIndex | |
66 | 61 | { |
67 | - return sm_headings[heading].second.begin(); | |
68 | -} | |
62 | + std::vector< std::pair< std::string, std::vector< int > > > headings; | |
63 | + std::vector< std::pair< std::string, std::string > > categories; | |
64 | + StringIntMap category_ids; | |
65 | + std::vector< Package > packages; | |
66 | + StringIntMap package_ids; | |
67 | +} g_pkgindex; | |
69 | 68 | |
70 | 69 | |
71 | -std::list< int >::const_iterator PkgIndex::HeadingChildren_End(int heading) | |
70 | +static const char* NonEmptyAttribute(const TiXmlElement* el, const char* name) | |
72 | 71 | { |
73 | - return sm_headings[heading].second.end(); | |
72 | + const char* attr = el->Attribute(name); | |
73 | + return (attr && attr[0]) ? attr : 0; | |
74 | 74 | } |
75 | 75 | |
76 | 76 | |
77 | -PkgIndex::PackageIter PkgIndex::Packages_Begin() | |
77 | +Package::Package(const char* pid, const TiXmlElement* pack_el) | |
78 | + : id(pid), | |
79 | + selected_action(ACT_NO_CHANGE), | |
80 | + selected_version(-1) | |
78 | 81 | { |
79 | - return sm_id_packages.begin(); | |
82 | + for (const TiXmlElement* aff_el = pack_el->FirstChildElement("affiliate"); | |
83 | + aff_el; | |
84 | + aff_el = aff_el->NextSiblingElement("affiliate")) | |
85 | + { | |
86 | + const char* aff_id = aff_el->Attribute("id"); | |
87 | + if (aff_id && aff_id[0]) | |
88 | + { | |
89 | + StringIntMap::const_iterator found = | |
90 | + g_pkgindex.category_ids.find(aff_id); | |
91 | + if (found != g_pkgindex.category_ids.end()) | |
92 | + categories.insert(found->second); | |
93 | + } | |
94 | + } | |
95 | + const TiXmlElement* desc_el = pack_el->FirstChildElement("description"); | |
96 | + if (desc_el) | |
97 | + { | |
98 | + const char* ptitle = desc_el->Attribute("title"); | |
99 | + if (ptitle && ptitle[0]) | |
100 | + title = ptitle; | |
101 | + for (const TiXmlNode* node = desc_el->FirstChild(); | |
102 | + node; | |
103 | + node = node->NextSibling()) | |
104 | + { | |
105 | + if (node->ToText()) | |
106 | + description += node->Value(); | |
107 | + else if (node->ToElement() && strcmp(node->Value(), "p") == 0) | |
108 | + description += "\r\n\r\n"; | |
109 | + } | |
110 | + } | |
111 | + for (const TiXmlElement* rel_el = pack_el->FirstChildElement("release"); | |
112 | + rel_el; | |
113 | + rel_el = rel_el->NextSiblingElement("release")) | |
114 | + { | |
115 | + const char* ver = rel_el->Attribute("version"); | |
116 | + if (ver && ver[0]) | |
117 | + { | |
118 | + int status = PSTATUS_STABLE; | |
119 | + const char* stat = rel_el->Attribute("status"); | |
120 | + if (stat) | |
121 | + { | |
122 | + if (strcmp(stat, "alpha") == 0) | |
123 | + status = PSTATUS_ALPHA; | |
124 | + } | |
125 | + versions.push_back(PkgVersion(ver, status)); | |
126 | + } | |
127 | + } | |
128 | + if (versions.size() > 0) | |
129 | + std::sort(versions.begin(), versions.end(), PkgVersionOrder); | |
80 | 130 | } |
81 | 131 | |
82 | 132 | |
83 | -PkgIndex::PackageIter PkgIndex::Packages_End() | |
133 | +extern "C" int PkgIndex_Load() | |
84 | 134 | { |
85 | - return sm_id_packages.end(); | |
86 | -} | |
135 | + PkgIndex_Clear(); | |
87 | 136 | |
88 | - | |
89 | -bool PkgIndex::LoadIndex() | |
90 | -{ | |
91 | - Clear(); | |
92 | 137 | std::string mfile = std::string(GetBinDir()) + "\\mingw_avail.mft"; |
93 | 138 | TiXmlDocument doc(mfile.c_str()); |
94 | 139 | if (!doc.LoadFile()) |
95 | 140 | { |
96 | 141 | MGError("Couldn't load '%s' as XML", mfile.c_str()); |
97 | - return false; | |
142 | + return 0; | |
98 | 143 | } |
99 | 144 | |
100 | 145 | for (TiXmlElement* heading_el = |
@@ -106,8 +151,8 @@ bool PkgIndex::LoadIndex() | ||
106 | 151 | char const* name = NonEmptyAttribute(heading_el, "name"); |
107 | 152 | if (!name) |
108 | 153 | continue; |
109 | - sm_headings.push_back(std::make_pair(std::string(name), | |
110 | - std::list< int >())); | |
154 | + g_pkgindex.headings.push_back(std::make_pair(std::string(name), | |
155 | + std::vector< int >())); | |
111 | 156 | for (TiXmlElement* cat_el = heading_el->FirstChildElement("category"); |
112 | 157 | cat_el; |
113 | 158 | cat_el = cat_el->NextSiblingElement("category")) |
@@ -118,10 +163,14 @@ bool PkgIndex::LoadIndex() | ||
118 | 163 | const char* name = NonEmptyAttribute(cat_el, "name"); |
119 | 164 | if (!name) |
120 | 165 | continue; |
121 | - sm_headings.back().second.push_back(sm_index_categories.size()); | |
122 | - sm_id_categories[id] = sm_index_categories.size(); | |
123 | - sm_index_categories.push_back(name); | |
166 | + g_pkgindex.headings.back().second.push_back( | |
167 | + g_pkgindex.categories.size() | |
168 | + ); | |
169 | + g_pkgindex.category_ids[id] = g_pkgindex.categories.size(); | |
170 | + g_pkgindex.categories.push_back(std::make_pair(std::string(id), | |
171 | + std::string(name))); | |
124 | 172 | } |
173 | + g_pkgindex.headings.back().second.push_back(-1); | |
125 | 174 | } |
126 | 175 | |
127 | 176 | for (TiXmlElement* package_el = |
@@ -133,26 +182,178 @@ bool PkgIndex::LoadIndex() | ||
133 | 182 | const char* id = NonEmptyAttribute(package_el, "id"); |
134 | 183 | if (!id) |
135 | 184 | continue; |
136 | - StringPackageMap::iterator found = sm_id_packages.find(id); | |
137 | - if (found != sm_id_packages.end()) | |
185 | + StringIntMap::const_iterator found = g_pkgindex.package_ids.find(id); | |
186 | + if (found != g_pkgindex.package_ids.end()) | |
138 | 187 | continue; |
139 | - Package::Ref newpkg(new Package(id, package_el)); | |
140 | - InsertPackage(newpkg); | |
188 | + g_pkgindex.packages.push_back(Package(id, package_el)); | |
189 | + } | |
190 | + | |
191 | + return 1; | |
192 | +} | |
193 | + | |
194 | + | |
195 | +extern "C" void PkgIndex_Clear() | |
196 | +{ | |
197 | + g_pkgindex.headings.clear(); | |
198 | + g_pkgindex.categories.clear(); | |
199 | + g_pkgindex.packages.clear(); | |
200 | + g_pkgindex.package_ids.clear(); | |
201 | +} | |
202 | + | |
203 | + | |
204 | +extern "C" int PkgIndex_NumHeadings() | |
205 | +{ | |
206 | + return g_pkgindex.headings.size(); | |
207 | +} | |
208 | + | |
209 | + | |
210 | +extern "C" const char* PkgIndex_GetHeading(int heading) | |
211 | +{ | |
212 | + return g_pkgindex.headings[heading].first.c_str(); | |
213 | +} | |
214 | + | |
215 | + | |
216 | +extern "C" const int* PkgIndex_GetHeadingChildren(int heading) | |
217 | +{ | |
218 | + return &g_pkgindex.headings[heading].second.front(); | |
219 | +} | |
220 | + | |
221 | + | |
222 | +extern "C" const char* PkgIndex_GetCategory(int category) | |
223 | +{ | |
224 | + return g_pkgindex.categories[category].second.c_str(); | |
225 | +} | |
226 | + | |
227 | + | |
228 | +extern "C" int PkgIndex_NumPackages() | |
229 | +{ | |
230 | + return g_pkgindex.packages.size(); | |
231 | +} | |
232 | + | |
233 | + | |
234 | +extern "C" int PkgIndex_PackageInAnyOf(int package, const int* categories) | |
235 | +{ | |
236 | + for (const int* cat_it = categories; *cat_it != -1; ++cat_it) | |
237 | + { | |
238 | + if (g_pkgindex.packages[package].categories.count(*cat_it) > 0) | |
239 | + return 1; | |
141 | 240 | } |
142 | - return true; | |
241 | + return 0; | |
242 | +} | |
243 | + | |
244 | + | |
245 | +extern "C" const char* PkgIndex_PackageGetID(int package) | |
246 | +{ | |
247 | + return g_pkgindex.packages[package].id.c_str(); | |
248 | +} | |
249 | + | |
250 | + | |
251 | +extern "C" const char* PkgIndex_PackageGetSubItemText(int package, int subitem) | |
252 | +{ | |
253 | + switch (subitem) | |
254 | + { | |
255 | + case 1: | |
256 | + return g_pkgindex.packages[package].id.c_str(); | |
257 | + case 2: | |
258 | + return g_pkgindex.packages[package].installed_version.c_str(); | |
259 | + case 3: | |
260 | + if (g_pkgindex.packages[package].versions.size() > 0) | |
261 | + return g_pkgindex.packages[package].versions.front().version.c_str(); | |
262 | + break; | |
263 | + case 5: | |
264 | + return g_pkgindex.packages[package].title.c_str(); | |
265 | + } | |
266 | + return ""; | |
267 | +} | |
268 | + | |
269 | + | |
270 | +extern "C" const char* PkgIndex_PackageGetTitle(int package) | |
271 | +{ | |
272 | + return g_pkgindex.packages[package].title.c_str(); | |
273 | +} | |
274 | + | |
275 | + | |
276 | +extern "C" const char* PkgIndex_PackageGetDescription(int package) | |
277 | +{ | |
278 | + return g_pkgindex.packages[package].description.c_str(); | |
279 | +} | |
280 | + | |
281 | + | |
282 | +extern "C" const char* PkgIndex_PackageGetInstalledVersion(int package) | |
283 | +{ | |
284 | + return g_pkgindex.packages[package].installed_version.c_str(); | |
285 | +} | |
286 | + | |
287 | + | |
288 | +extern "C" const char* PkgIndex_PackageGetLatestVersion(int package) | |
289 | +{ | |
290 | + return (g_pkgindex.packages[package].versions.empty()) ? | |
291 | + "" : g_pkgindex.packages[package].versions.front().version.c_str(); | |
292 | +} | |
293 | + | |
294 | + | |
295 | +extern "C" int PkgIndex_PackageNumVersions(int package) | |
296 | +{ | |
297 | + return g_pkgindex.packages[package].versions.size(); | |
298 | +} | |
299 | + | |
300 | + | |
301 | +extern "C" const char* PkgIndex_PackageVersionGetString | |
302 | + (int package, | |
303 | + int version) | |
304 | +{ | |
305 | + return g_pkgindex.packages[package].versions[version].version.c_str(); | |
143 | 306 | } |
144 | 307 | |
145 | 308 | |
146 | -void PkgIndex::Clear() | |
309 | +extern "C" void PkgIndex_PackageSetSelectedVersion(int package, int version) | |
147 | 310 | { |
148 | - sm_index_categories.clear(); | |
149 | - sm_id_categories.clear(); | |
150 | - sm_id_packages.clear(); | |
151 | - sm_headings.clear(); | |
311 | + g_pkgindex.packages[package].selected_version = version; | |
152 | 312 | } |
153 | 313 | |
154 | 314 | |
155 | -void PkgIndex::InsertPackage(Package::Ref ins) | |
315 | +extern "C" int PkgIndex_PackageVersionGetStatus(int package, int version) | |
156 | 316 | { |
157 | - sm_id_packages.insert(std::make_pair(ins->m_id, ins)); | |
317 | + return g_pkgindex.packages[package].versions[version].status; | |
318 | +} | |
319 | + | |
320 | + | |
321 | +extern "C" int PkgIndex_PackageGetSelectedAction(int package) | |
322 | +{ | |
323 | + return g_pkgindex.packages[package].selected_action; | |
324 | +} | |
325 | + | |
326 | + | |
327 | +extern "C" void PkgIndex_PackageSelectAction(int package, int action) | |
328 | +{ | |
329 | + g_pkgindex.packages[package].selected_action = action; | |
330 | +} | |
331 | + | |
332 | + | |
333 | +extern "C" int PkgIndex_PackageGetStateImage(int package) | |
334 | +{ | |
335 | + const Package& pkg = g_pkgindex.packages[package]; | |
336 | + const char* sel_ver = ""; | |
337 | + if (pkg.selected_version >= 0) | |
338 | + sel_ver = pkg.versions[pkg.selected_version].version.c_str(); | |
339 | + if (pkg.installed_version.length() <= 0) | |
340 | + { | |
341 | + if (pkg.selected_action == ACT_NO_CHANGE) | |
342 | + return 1; | |
343 | + else if (pkg.selected_action == ACT_INSTALL_VERSION) | |
344 | + return 5; | |
345 | + } | |
346 | + else | |
347 | + { | |
348 | + if (pkg.selected_action == ACT_NO_CHANGE) | |
349 | + return 2; | |
350 | + else if (pkg.selected_action == ACT_INSTALL_VERSION) | |
351 | + return (VersionCompare(pkg.installed_version.c_str(), sel_ver) < 0) | |
352 | + ? 7 : 8; | |
353 | + else if (pkg.selected_action == ACT_REMOVE) | |
354 | + return 9; | |
355 | + else if (pkg.selected_action == ACT_REINSTALL) | |
356 | + return 6; | |
357 | + } | |
358 | + return 0; | |
158 | 359 | } |
@@ -0,0 +1,45 @@ | ||
1 | +/** \file pkgindex.hh | |
2 | + * | |
3 | + * Created: JohnE, 2009-01-03 | |
4 | + */ | |
5 | +#ifndef PKGINDEX_HH_INC | |
6 | +#define PKGINDEX_HH_INC | |
7 | + | |
8 | + | |
9 | +#ifdef __cplusplus | |
10 | +extern "C" { | |
11 | +#endif | |
12 | + | |
13 | + | |
14 | +int PkgIndex_Load(); | |
15 | +void PkgIndex_Clear(); | |
16 | + | |
17 | +int PkgIndex_NumHeadings(); | |
18 | +const char* PkgIndex_GetHeading(int heading); | |
19 | +const int* PkgIndex_GetHeadingChildren(int heading); | |
20 | + | |
21 | +const char* PkgIndex_GetCategory(int category); | |
22 | + | |
23 | +int PkgIndex_NumPackages(); | |
24 | +int PkgIndex_PackageInAnyOf(int package, const int* categories); | |
25 | +const char* PkgIndex_PackageGetID(int package); | |
26 | +const char* PkgIndex_PackageGetSubItemText(int package, int subitem); | |
27 | +const char* PkgIndex_PackageGetTitle(int package); | |
28 | +const char* PkgIndex_PackageGetDescription(int package); | |
29 | +const char* PkgIndex_PackageGetInstalledVersion(int package); | |
30 | +const char* PkgIndex_PackageGetLatestVersion(int package); | |
31 | +int PkgIndex_PackageNumVersions(int package); | |
32 | +const char* PkgIndex_PackageVersionGetString(int package, int version); | |
33 | +void PkgIndex_PackageSetSelectedVersion(int package, int version); | |
34 | +int PkgIndex_PackageVersionGetStatus(int package, int version); | |
35 | +int PkgIndex_PackageGetSelectedAction(int package); | |
36 | +void PkgIndex_PackageSelectAction(int package, int action); | |
37 | +int PkgIndex_PackageGetStateImage(int package); | |
38 | + | |
39 | + | |
40 | +#ifdef __cplusplus | |
41 | +} //extern "C" | |
42 | +#endif | |
43 | + | |
44 | + | |
45 | +#endif // PKGINDEX_HH_INC |
@@ -1,51 +0,0 @@ | ||
1 | -/** \file pkgindex.hpp | |
2 | - * | |
3 | - * Created: JohnE, 2008-10-09 | |
4 | - */ | |
5 | -#ifndef PKGINDEX_HPP_INC | |
6 | -#define PKGINDEX_HPP_INC | |
7 | - | |
8 | - | |
9 | -#include <list> | |
10 | -#include <map> | |
11 | -#include <vector> | |
12 | -#include "ref.hpp" | |
13 | - | |
14 | - | |
15 | -struct Package; | |
16 | - | |
17 | - | |
18 | -class PkgIndex | |
19 | -{ | |
20 | -public: | |
21 | - static void Clear(); | |
22 | - static bool LoadIndex(); | |
23 | - | |
24 | - static int NumCategories(); | |
25 | - static const char* GetCategory(int cat); | |
26 | - static int CategoryIndex(const char* cat_id); | |
27 | - | |
28 | - static int NumHeadings(); | |
29 | - static char const* GetHeading(int heading); | |
30 | - static std::list< int >::const_iterator HeadingChildren_Begin(int heading); | |
31 | - static std::list< int >::const_iterator HeadingChildren_End(int heading); | |
32 | - | |
33 | - typedef std::map< std::string, RefType< Package >::Ref > StringPackageMap; | |
34 | - typedef StringPackageMap::const_iterator PackageIter; | |
35 | - static PackageIter Packages_Begin(); | |
36 | - static PackageIter Packages_End(); | |
37 | - | |
38 | -private: | |
39 | - static void InsertPackage(RefType< Package >::Ref ins); | |
40 | - | |
41 | - static std::vector< std::string > sm_index_categories; | |
42 | - typedef std::map< std::string, int > StringIntMap; | |
43 | - static StringIntMap sm_id_categories; | |
44 | - static StringPackageMap sm_id_packages; | |
45 | - | |
46 | - static std::vector< std::pair< std::string, std::list< int > > > | |
47 | - sm_headings; | |
48 | -}; | |
49 | - | |
50 | - | |
51 | -#endif // PKGINDEX_HPP_INC |
@@ -0,0 +1,194 @@ | ||
1 | +/** \file progressthread.c | |
2 | + * | |
3 | + * Created: JohnE, 2009-01-03 | |
4 | + */ | |
5 | + | |
6 | + | |
7 | +#include "progressthread.hh" | |
8 | + | |
9 | +#define WIN32_LEAN_AND_MEAN | |
10 | +#include <windows.h> | |
11 | +#include <windowsx.h> | |
12 | +#include <stdio.h> | |
13 | +#include "resource.h" | |
14 | +#include "error.hh" | |
15 | +#include "mainwnd.hh" | |
16 | +#include "winmain.hh" | |
17 | + | |
18 | + | |
19 | +struct ProgressThreadInfoStruct | |
20 | +{ | |
21 | + HWND hprogressdlg; | |
22 | + const char* dlgtitle; | |
23 | + int (*thread_func)(ProgressThreadInfo*, void*); | |
24 | + void* thread_func_param; | |
25 | + int finished; | |
26 | + int result; | |
27 | + int cancel_signal; | |
28 | +}; | |
29 | + | |
30 | + | |
31 | +DWORD WINAPI ProgressThreadFunc(LPVOID param) | |
32 | +{ | |
33 | + int result = ((ProgressThreadInfo*)param)->thread_func(param, | |
34 | + ((ProgressThreadInfo*)param)->thread_func_param); | |
35 | + PostMessage(((ProgressThreadInfo*)param)->hprogressdlg, WM_USER + 2012, 0, | |
36 | + result); | |
37 | + return 0; | |
38 | +} | |
39 | + | |
40 | + | |
41 | +static BOOL CALLBACK ProgressThreadDlgProc | |
42 | + (HWND hwndDlg, | |
43 | + UINT uMsg, | |
44 | + WPARAM wParam, | |
45 | + LPARAM lParam) | |
46 | +{ | |
47 | + switch (uMsg) | |
48 | + { | |
49 | + case WM_INITDIALOG: | |
50 | + { | |
51 | + SetWindowLong(hwndDlg, GWL_USERDATA, lParam); | |
52 | + ProgressThreadInfo* info = (ProgressThreadInfo*)lParam; | |
53 | + SetWindowText(hwndDlg, info->dlgtitle); | |
54 | + ShowWindow(GetDlgItem(hwndDlg, IDC_ACTIONLIST), FALSE); | |
55 | + info->hprogressdlg = hwndDlg; | |
56 | + info->finished = 0; | |
57 | + info->cancel_signal = 0; | |
58 | + HANDLE hthread = CreateThread(0, 0, ProgressThreadFunc, info, 0, 0); | |
59 | + if (hthread) | |
60 | + CloseHandle(hthread); | |
61 | + else | |
62 | + { | |
63 | + MGError("Failed to create worker thread"); | |
64 | + EndDialog(hwndDlg, -1); | |
65 | + } | |
66 | + } | |
67 | + return TRUE; | |
68 | + | |
69 | + case WM_COMMAND: | |
70 | + switch (LOWORD(wParam)) | |
71 | + { | |
72 | + case IDC_SHOWDETAILS: | |
73 | + { | |
74 | + RECT wrc, crc; | |
75 | + GetWindowRect(hwndDlg, &wrc); | |
76 | + GetClientRect(hwndDlg, &crc); | |
77 | + ShowWindow(GetDlgItem(hwndDlg, IDC_ACTIONTEXT), FALSE); | |
78 | + ShowWindow(GetDlgItem(hwndDlg, IDC_ACTIONLIST), TRUE); | |
79 | + ShowWindow(GetDlgItem(hwndDlg, IDC_SHOWDETAILS), FALSE); | |
80 | + MoveWindow(hwndDlg, wrc.left, wrc.top, wrc.right - wrc.left, | |
81 | + ((float)(crc.bottom - crc.top) / 45.0f) * 150 + wrc.bottom - wrc.top - crc.bottom + crc.top, | |
82 | + TRUE); | |
83 | + SetFocus(GetDlgItem(hwndDlg, IDC_PROGRESSEND)); | |
84 | + } | |
85 | + return TRUE; | |
86 | + case IDC_PROGRESSEND: | |
87 | + { | |
88 | + ProgressThreadInfo* info = | |
89 | + (ProgressThreadInfo*)GetWindowLong(hwndDlg, GWL_USERDATA); | |
90 | + if (info->finished) | |
91 | + EndDialog(hwndDlg, info->result); | |
92 | + else | |
93 | + { | |
94 | + EnableWindow(GetDlgItem(hwndDlg, IDC_PROGRESSEND), FALSE); | |
95 | + Button_SetText(GetDlgItem(hwndDlg, IDC_PROGRESSEND), | |
96 | + "Please wait..."); | |
97 | + info->cancel_signal = 1; | |
98 | + } | |
99 | + } | |
100 | + return TRUE; | |
101 | + } | |
102 | + break; | |
103 | + | |
104 | + case WM_USER + 2012: | |
105 | + { | |
106 | + ProgressThreadInfo* info = | |
107 | + (ProgressThreadInfo*)GetWindowLong(hwndDlg, GWL_USERDATA); | |
108 | + if (info->cancel_signal) | |
109 | + EndDialog(hwndDlg, lParam); | |
110 | + else | |
111 | + { | |
112 | + Button_SetText(GetDlgItem(hwndDlg, IDC_PROGRESSEND), "&OK"); | |
113 | + info->result = lParam; | |
114 | + info->finished = 1; | |
115 | + if (lParam == 0) | |
116 | + ProgressThread_NewStatus(info, "Finished."); | |
117 | + else | |
118 | + { | |
119 | + char status[1024]; | |
120 | + int i = 0; | |
121 | + for (; MGGetErrors()[i]; ++i) | |
122 | + { | |
123 | + snprintf(status, 1024, "[Error] %s", MGGetErrors()[i]); | |
124 | + ProgressThread_NewStatus(info, status); | |
125 | + } | |
126 | + MGClearErrors(); | |
127 | + } | |
128 | + } | |
129 | + } | |
130 | + return TRUE; | |
131 | + | |
132 | + case WM_SIZE: | |
133 | + { | |
134 | + int cli_height = HIWORD(lParam); | |
135 | + | |
136 | + RECT btnrc; | |
137 | + GetWindowRect(GetDlgItem(hwndDlg, IDC_PROGRESSEND), &btnrc); | |
138 | + TransToClient(hwndDlg, &btnrc); | |
139 | + MoveWindow(GetDlgItem(hwndDlg, IDC_PROGRESSEND), btnrc.left, | |
140 | + cli_height - (btnrc.bottom - btnrc.top) - 4, | |
141 | + btnrc.right - btnrc.left, btnrc.bottom - btnrc.top, TRUE); | |
142 | + | |
143 | + GetWindowRect(GetDlgItem(hwndDlg, IDC_SHOWDETAILS), &btnrc); | |
144 | + TransToClient(hwndDlg, &btnrc); | |
145 | + MoveWindow(GetDlgItem(hwndDlg, IDC_SHOWDETAILS), btnrc.left, | |
146 | + cli_height - (btnrc.bottom - btnrc.top) - 4, | |
147 | + btnrc.right - btnrc.left, btnrc.bottom - btnrc.top, TRUE); | |
148 | + | |
149 | + RECT rc; | |
150 | + GetWindowRect(GetDlgItem(hwndDlg, IDC_ACTIONLIST), &rc); | |
151 | + TransToClient(hwndDlg, &rc); | |
152 | + MoveWindow(GetDlgItem(hwndDlg, IDC_ACTIONLIST), rc.left, rc.top, | |
153 | + rc.right - rc.left, | |
154 | + cli_height - (btnrc.bottom - btnrc.top) - rc.top - 16, TRUE); | |
155 | + | |
156 | + GetWindowRect(GetDlgItem(hwndDlg, IDC_STATUSGRP), &rc); | |
157 | + TransToClient(hwndDlg, &rc); | |
158 | + MoveWindow(GetDlgItem(hwndDlg, IDC_STATUSGRP), rc.left, rc.top, | |
159 | + rc.right - rc.left, | |
160 | + cli_height - (btnrc.bottom - btnrc.top) - rc.top - 10, TRUE); | |
161 | + } | |
162 | + return TRUE; | |
163 | + } | |
164 | + | |
165 | + return FALSE; | |
166 | +} | |
167 | + | |
168 | + | |
169 | +int ProgressThread | |
170 | + (const char* dialog_title, | |
171 | + int (*thread_func)(ProgressThreadInfo*, void*), | |
172 | + void* thread_func_param) | |
173 | +{ | |
174 | + ProgressThreadInfo info; | |
175 | + info.dlgtitle = (dialog_title) ? dialog_title : "Caption"; | |
176 | + info.thread_func = thread_func; | |
177 | + info.thread_func_param = thread_func_param; | |
178 | + return DialogBoxParam(g_hinstance, MAKEINTRESOURCE(IDD_PROGRESSDLG), | |
179 | + g_hmainwnd, ProgressThreadDlgProc, (LPARAM)&info); | |
180 | +} | |
181 | + | |
182 | + | |
183 | +void ProgressThread_NewStatus(ProgressThreadInfo* info, const char* status) | |
184 | +{ | |
185 | + Static_SetText(GetDlgItem(info->hprogressdlg, IDC_ACTIONTEXT), status); | |
186 | + (void)ListBox_AddString(GetDlgItem(info->hprogressdlg, IDC_ACTIONLIST), | |
187 | + status); | |
188 | +} | |
189 | + | |
190 | + | |
191 | +int ProgressThread_IsCancelled(ProgressThreadInfo* info) | |
192 | +{ | |
193 | + return info->cancel_signal; | |
194 | +} |
@@ -0,0 +1,31 @@ | ||
1 | +/** \file progressthread.hh | |
2 | + * | |
3 | + * Created: JohnE, 2009-01-03 | |
4 | + */ | |
5 | +#ifndef PROGRESSTHREAD_HH_INC | |
6 | +#define PROGRESSTHREAD_HH_INC | |
7 | + | |
8 | + | |
9 | +#ifdef __cplusplus | |
10 | +extern "C" { | |
11 | +#endif | |
12 | + | |
13 | + | |
14 | +typedef struct ProgressThreadInfoStruct ProgressThreadInfo; | |
15 | + | |
16 | + | |
17 | +int ProgressThread | |
18 | + (const char* dialog_title, | |
19 | + int (*thread_func)(ProgressThreadInfo*, void*), | |
20 | + void* thread_func_param); | |
21 | + | |
22 | +void ProgressThread_NewStatus(ProgressThreadInfo* info, const char* status); | |
23 | +int ProgressThread_IsCancelled(ProgressThreadInfo* info); | |
24 | + | |
25 | + | |
26 | +#ifdef __cplusplus | |
27 | +} //extern "C" | |
28 | +#endif | |
29 | + | |
30 | + | |
31 | +#endif // PROGRESSTHREAD_HH_INC |
@@ -10,9 +10,9 @@ | ||
10 | 10 | #include "error.hh" |
11 | 11 | #include "instmanager.hpp" |
12 | 12 | #include "previnstalls.hh" |
13 | -#include "ui.hh" | |
14 | 13 | #include "winmain.hh" |
15 | 14 | #include "mainwnd.hh" |
15 | +#include "ui_general.hh" | |
16 | 16 | |
17 | 17 | |
18 | 18 | char g_inst_loc[MAX_PATH] = {0}; |
@@ -1,468 +0,0 @@ | ||
1 | -/** \file ui.cpp | |
2 | - * | |
3 | - * Created: JohnE, 2008-10-11 | |
4 | - */ | |
5 | - | |
6 | - | |
7 | -#include "ui.hh" | |
8 | - | |
9 | -#define WIN32_LEAN_AND_MEAN | |
10 | -#include <windows.h> | |
11 | -#include <windowsx.h> | |
12 | -#include <commctrl.h> | |
13 | -#include <climits> | |
14 | -#include "package.hh" | |
15 | -#include "pkgindex.hpp" | |
16 | -#include "pkg_const.h" | |
17 | -#include "resource.h" | |
18 | -#include "error.hh" | |
19 | -#include "mainwnd.hh" | |
20 | -#include "winmain.hh" | |
21 | -#include "getbindir.hh" | |
22 | -#include "download.hh" | |
23 | -#include "versioncompare.hh" | |
24 | - | |
25 | - | |
26 | -static void LVAddPackage(HWND hlist, const Package& pkg) | |
27 | -{ | |
28 | - LVITEM lvi; | |
29 | - lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; | |
30 | - lvi.iItem = INT_MAX; | |
31 | - lvi.iSubItem = 0; | |
32 | - char emptystr = 0; | |
33 | - lvi.pszText = &emptystr; | |
34 | - lvi.iImage = pkg.GetStateImage(); | |
35 | - lvi.lParam = reinterpret_cast< LPARAM >(&pkg); | |
36 | - lvi.iItem = ListView_InsertItem(hlist, &lvi); | |
37 | - lvi.mask = LVIF_TEXT; | |
38 | - lvi.pszText = LPSTR_TEXTCALLBACK; | |
39 | - for (int i = 1; i <= 5; ++i) | |
40 | - { | |
41 | - lvi.iSubItem = i; | |
42 | - ListView_SetItem(hlist, &lvi); | |
43 | - } | |
44 | - if (lvi.iItem == 0) | |
45 | - { | |
46 | - ListView_SetItemState(hlist, 0, | |
47 | - LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); | |
48 | - } | |
49 | -} | |
50 | - | |
51 | - | |
52 | -extern "C" void UI_OnCategoryChange(int const* categories) | |
53 | -{ | |
54 | - ListView_DeleteAllItems(GetDlgItem(g_hmainwnd, IDC_COMPLIST)); | |
55 | - bool have_item = false; | |
56 | - | |
57 | - if (*categories == 0) | |
58 | - { | |
59 | - for (PkgIndex::PackageIter it = PkgIndex::Packages_Begin(); | |
60 | - it != PkgIndex::Packages_End(); | |
61 | - ++it) | |
62 | - { | |
63 | - LVAddPackage(GetDlgItem(g_hmainwnd, IDC_COMPLIST), *it->second); | |
64 | - have_item = true; | |
65 | - } | |
66 | - } | |
67 | - else | |
68 | - { | |
69 | - for (PkgIndex::PackageIter it = PkgIndex::Packages_Begin(); | |
70 | - it != PkgIndex::Packages_End(); | |
71 | - ++it) | |
72 | - { | |
73 | - for (int const* cat_it = categories; *cat_it != -1; ++cat_it) | |
74 | - { | |
75 | - if (it->second->m_categories.count(*cat_it - 1) > 0) | |
76 | - { | |
77 | - LVAddPackage(GetDlgItem(g_hmainwnd, IDC_COMPLIST), | |
78 | - *it->second); | |
79 | - have_item = true; | |
80 | - } | |
81 | - } | |
82 | - } | |
83 | - } | |
84 | - if (have_item) | |
85 | - { | |
86 | - ListView_SetItemState(GetDlgItem(g_hmainwnd, IDC_COMPLIST), 0, | |
87 | - LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); | |
88 | - } | |
89 | - else | |
90 | - { | |
91 | - Static_SetText(GetDlgItem(g_hmainwnd, IDC_DESCTITLE), ""); | |
92 | - Edit_SetText(GetDlgItem(g_hmainwnd, IDC_FULLDESC), ""); | |
93 | - ComboBox_ResetContent(GetDlgItem(g_hmainwnd, IDC_INSTVERSION)); | |
94 | - EnableWindow(GetDlgItem(g_hmainwnd, IDC_INSTVERSION), FALSE); | |
95 | - EnableWindow(GetDlgItem(g_hmainwnd, IDC_FULLDESC), FALSE); | |
96 | - } | |
97 | -} | |
98 | - | |
99 | - | |
100 | -extern "C" void UI_OnListViewSelect(int sel) | |
101 | -{ | |
102 | - LVITEM lvitem; | |
103 | - lvitem.iItem = sel; | |
104 | - lvitem.iSubItem = 0; | |
105 | - lvitem.mask = LVIF_PARAM; | |
106 | - ListView_GetItem(GetDlgItem(g_hmainwnd, IDC_COMPLIST), &lvitem); | |
107 | - Package* pkg = reinterpret_cast< Package* >(lvitem.lParam); | |
108 | - Edit_SetText(GetDlgItem(g_hmainwnd, IDC_FULLDESC), | |
109 | - pkg->m_description.c_str()); | |
110 | - EnableWindow(GetDlgItem(g_hmainwnd, IDC_FULLDESC), TRUE); | |
111 | - Static_SetText(GetDlgItem(g_hmainwnd, IDC_DESCTITLE), | |
112 | - pkg->m_title.c_str()); | |
113 | - ComboBox_ResetContent(GetDlgItem(g_hmainwnd, IDC_INSTVERSION)); | |
114 | - if (pkg->m_versions.size() > 0) | |
115 | - { | |
116 | - EnableWindow(GetDlgItem(g_hmainwnd, IDC_INSTVERSION), TRUE); | |
117 | - std::string vstr; | |
118 | - for (std::vector< PkgVersion::Ref >::const_iterator it = pkg->m_versions.begin(); | |
119 | - it != pkg->m_versions.end(); | |
120 | - ++it) | |
121 | - { | |
122 | - if ((*it)->m_status == PSTATUS_ALPHA) | |
123 | - vstr = "Alpha: "; | |
124 | - else | |
125 | - vstr = "Stable: "; | |
126 | - vstr += (*it)->m_version; | |
127 | - ComboBox_AddString(GetDlgItem(g_hmainwnd, IDC_INSTVERSION), | |
128 | - vstr.c_str()); | |
129 | - } | |
130 | - pkg->m_selected_version = 0; | |
131 | - ComboBox_SetCurSel(GetDlgItem(g_hmainwnd, IDC_INSTVERSION), 0); | |
132 | - } | |
133 | - else | |
134 | - { | |
135 | - pkg->m_selected_version = -1; | |
136 | - EnableWindow(GetDlgItem(g_hmainwnd, IDC_INSTVERSION), FALSE); | |
137 | - } | |
138 | -} | |
139 | - | |
140 | - | |
141 | -extern "C" void UI_OnStateCycle(int sel) | |
142 | -{ | |
143 | - LVITEM lvitem; | |
144 | - lvitem.iItem = sel; | |
145 | - lvitem.iSubItem = 0; | |
146 | - lvitem.mask = LVIF_PARAM; | |
147 | - ListView_GetItem(GetDlgItem(g_hmainwnd, IDC_COMPLIST), &lvitem); | |
148 | - Package* pkg = reinterpret_cast< Package* >(lvitem.lParam); | |
149 | - if (pkg->m_installed_version.length() > 0) | |
150 | - { | |
151 | - if (pkg->m_selected_action == ACT_INSTALL_VERSION) | |
152 | - pkg->m_selected_action = ACT_NO_CHANGE; | |
153 | - else | |
154 | - pkg->m_selected_action = ACT_INSTALL_VERSION; | |
155 | - } | |
156 | - else | |
157 | - { | |
158 | - if (pkg->m_selected_action == ACT_INSTALL_VERSION) | |
159 | - pkg->m_selected_action = ACT_NO_CHANGE; | |
160 | - else | |
161 | - pkg->m_selected_action = ACT_INSTALL_VERSION; | |
162 | - } | |
163 | - lvitem.mask = LVIF_IMAGE; | |
164 | - lvitem.iImage = pkg->GetStateImage(); | |
165 | - ListView_SetItem(GetDlgItem(g_hmainwnd, IDC_COMPLIST), &lvitem); | |
166 | -} | |
167 | - | |
168 | - | |
169 | -struct LVSortType | |
170 | -{ | |
171 | - int m_field; | |
172 | - int m_reverse; | |
173 | - | |
174 | - LVSortType(int field, bool reverse) | |
175 | - : m_field(field), | |
176 | - m_reverse(reverse ? -1 : 1) | |
177 | - { | |
178 | - } | |
179 | -}; | |
180 | - | |
181 | - | |
182 | -int CALLBACK LVSortCompare(LPARAM lp1, LPARAM lp2, LPARAM lpsort) | |
183 | -{ | |
184 | - LVSortType* st = reinterpret_cast< LVSortType* >(lpsort); | |
185 | - int ret = 0; | |
186 | - switch (st->m_field) | |
187 | - { | |
188 | - case 1: | |
189 | - ret = strcmp(reinterpret_cast< Package* >(lp1)->m_id.c_str(), | |
190 | - reinterpret_cast< Package* >(lp2)->m_id.c_str()); | |
191 | - break; | |
192 | - case 2: | |
193 | - ret = VersionCompare( | |
194 | - reinterpret_cast< Package* >(lp1)->m_installed_version.c_str(), | |
195 | - reinterpret_cast< Package* >(lp2)->m_installed_version.c_str() | |
196 | - ); | |
197 | - break; | |
198 | - case 3: | |
199 | - { | |
200 | - const Package& p1 = *(reinterpret_cast< Package* >(lp1)); | |
201 | - const Package& p2 = *(reinterpret_cast< Package* >(lp2)); | |
202 | - const char* p1v = (p1.m_versions.size() > 0) | |
203 | - ? p1.m_versions.front()->m_version.c_str() : ""; | |
204 | - const char* p2v = (p2.m_versions.size() > 0) | |
205 | - ? p2.m_versions.front()->m_version.c_str() : ""; | |
206 | - ret = VersionCompare(p1v, p2v); | |
207 | - } | |
208 | - break; | |
209 | - case 5: | |
210 | - ret = stricmp(reinterpret_cast< Package* >(lp1)->m_title.c_str(), | |
211 | - reinterpret_cast< Package* >(lp2)->m_title.c_str()); | |
212 | - break; | |
213 | - }; | |
214 | - return ret * st->m_reverse; | |
215 | -}; | |
216 | - | |
217 | - | |
218 | -extern "C" void UI_SortListView(int column) | |
219 | -{ | |
220 | - static int cur_column = 0; | |
221 | - | |
222 | - if (cur_column == column) | |
223 | - cur_column = column + 6; | |
224 | - else | |
225 | - cur_column = column; | |
226 | - | |
227 | - LVSortType st(cur_column % 6, (cur_column >= 6)); | |
228 | - ListView_SortItems(GetDlgItem(g_hmainwnd, IDC_COMPLIST), LVSortCompare, | |
229 | - reinterpret_cast< LPARAM >(&st)); | |
230 | -} | |
231 | - | |
232 | - | |
233 | -extern "C" void UI_RefreshCategoryList() | |
234 | -{ | |
235 | - ListView_DeleteAllItems(GetDlgItem(g_hmainwnd, IDC_COMPLIST)); | |
236 | - TreeView_DeleteAllItems(GetDlgItem(g_hmainwnd, IDC_CATLIST)); | |
237 | - TVINSERTSTRUCT tvins; | |
238 | - tvins.item.mask = TVIF_TEXT | TVIF_PARAM; | |
239 | - tvins.item.pszText = const_cast< CHAR* >("All Packages"); | |
240 | - tvins.item.cchTextMax = 199; | |
241 | - tvins.item.lParam = 0; | |
242 | - tvins.hInsertAfter = TVI_LAST; | |
243 | - tvins.hParent = TVI_ROOT; | |
244 | - SendMessage( | |
245 | - GetDlgItem(g_hmainwnd, IDC_CATLIST), | |
246 | - TVM_INSERTITEM, | |
247 | - 0, | |
248 | - (LPARAM)(LPTVINSERTSTRUCT)&tvins | |
249 | - ); | |
250 | - for (int i = 0; i < PkgIndex::NumCategories(); ++i) | |
251 | - { | |
252 | - tvins.item.mask = TVIF_TEXT | TVIF_PARAM; | |
253 | - tvins.item.pszText = const_cast< CHAR* >(PkgIndex::GetCategory(i)); | |
254 | - tvins.item.cchTextMax = 199; | |
255 | - tvins.item.lParam = i + 1; | |
256 | - tvins.hInsertAfter = TVI_LAST; | |
257 | - tvins.hParent = TVI_ROOT; | |
258 | - SendMessage( | |
259 | - GetDlgItem(g_hmainwnd, IDC_CATLIST), | |
260 | - TVM_INSERTITEM, | |
261 | - 0, | |
262 | - (LPARAM)(LPTVINSERTSTRUCT)&tvins | |
263 | - ); | |
264 | - } | |
265 | - int cats[] = {0, -1}; | |
266 | - UI_OnCategoryChange(cats); | |
267 | -} | |
268 | - | |
269 | - | |
270 | -extern "C" void LastError_MsgBox(const char* title) | |
271 | -{ | |
272 | - MessageBox(g_hmainwnd, MGGetErrors()[0], title, MB_OK | MB_ICONERROR); | |
273 | - MGClearErrors(); | |
274 | -} | |
275 | - | |
276 | - | |
277 | -struct ProgressUIInfo | |
278 | -{ | |
279 | - HWND m_hprogressdlg; | |
280 | - bool m_cancelsignal; | |
281 | - bool m_finished; | |
282 | - int m_result; | |
283 | - const char* m_dlgtitle; | |
284 | - int (*m_thread_func)(); | |
285 | -} g_progressinfo; | |
286 | - | |
287 | -static DWORD WINAPI UIProgressThread(LPVOID param) | |
288 | -{ | |
289 | - int result = ((int (*)())param)(); | |
290 | - PostMessage(g_progressinfo.m_hprogressdlg, WM_USER + 2012, 0, result); | |
291 | - return 0; | |
292 | -} | |
293 | - | |
294 | -extern "C" void UI_ProgressThread_NewLine(const char* txt) | |
295 | -{ | |
296 | - Static_SetText(GetDlgItem(g_progressinfo.m_hprogressdlg, IDC_ACTIONTEXT), | |
297 | - txt); | |
298 | - ListBox_AddString(GetDlgItem(g_progressinfo.m_hprogressdlg, IDC_ACTIONLIST), | |
299 | - txt); | |
300 | -} | |
301 | - | |
302 | -static BOOL CALLBACK ProgressDlgProc | |
303 | - (HWND hwndDlg, | |
304 | - UINT uMsg, | |
305 | - WPARAM wParam, | |
306 | - LPARAM lParam) | |
307 | -{ | |
308 | - switch (uMsg) | |
309 | - { | |
310 | - case WM_INITDIALOG: | |
311 | - { | |
312 | - SetWindowText(hwndDlg, g_progressinfo.m_dlgtitle); | |
313 | - ShowWindow(GetDlgItem(hwndDlg, IDC_ACTIONLIST), FALSE); | |
314 | - g_progressinfo.m_hprogressdlg = hwndDlg; | |
315 | - g_progressinfo.m_cancelsignal = false; | |
316 | - g_progressinfo.m_finished = false; | |
317 | - HANDLE hthread = CreateThread(0, 0, UIProgressThread, | |
318 | - (void*)g_progressinfo.m_thread_func, 0, 0); | |
319 | - if (hthread) | |
320 | - CloseHandle(hthread); | |
321 | - else | |
322 | - { | |
323 | - MGError("Failed to create worker thread"); | |
324 | - EndDialog(hwndDlg, -1); | |
325 | - } | |
326 | - } | |
327 | - return TRUE; | |
328 | - | |
329 | - case WM_COMMAND: | |
330 | - switch (LOWORD(wParam)) | |
331 | - { | |
332 | - case IDC_SHOWDETAILS: | |
333 | - { | |
334 | - RECT wrc, crc; | |
335 | - GetWindowRect(hwndDlg, &wrc); | |
336 | - GetClientRect(hwndDlg, &crc); | |
337 | - ShowWindow(GetDlgItem(hwndDlg, IDC_ACTIONTEXT), FALSE); | |
338 | - ShowWindow(GetDlgItem(hwndDlg, IDC_ACTIONLIST), TRUE); | |
339 | - ShowWindow(GetDlgItem(hwndDlg, IDC_SHOWDETAILS), FALSE); | |
340 | - MoveWindow(hwndDlg, wrc.left, wrc.top, wrc.right - wrc.left, | |
341 | - (static_cast< float >((crc.bottom - crc.top)) / 45.0f) * 150 + wrc.bottom - wrc.top - crc.bottom + crc.top, | |
342 | - TRUE); | |
343 | - SetFocus(GetDlgItem(hwndDlg, IDC_PROGRESSEND)); | |
344 | - } | |
345 | - return TRUE; | |
346 | - case IDC_PROGRESSEND: | |
347 | - if (g_progressinfo.m_finished) | |
348 | - EndDialog(hwndDlg, g_progressinfo.m_result); | |
349 | - else | |
350 | - { | |
351 | - EnableWindow(GetDlgItem(hwndDlg, IDC_PROGRESSEND), FALSE); | |
352 | - Button_SetText(GetDlgItem(hwndDlg, IDC_PROGRESSEND), | |
353 | - "Please wait..."); | |
354 | - g_progressinfo.m_cancelsignal = true; | |
355 | - } | |
356 | - return TRUE; | |
357 | - } | |
358 | - break; | |
359 | - | |
360 | - case WM_USER + 2012: | |
361 | - if (g_progressinfo.m_cancelsignal) | |
362 | - EndDialog(hwndDlg, lParam); | |
363 | - else | |
364 | - { | |
365 | - Button_SetText(GetDlgItem(hwndDlg, IDC_PROGRESSEND), "&OK"); | |
366 | - g_progressinfo.m_result = lParam; | |
367 | - g_progressinfo.m_finished = true; | |
368 | - if (lParam == 0) | |
369 | - UI_ProgressThread_NewLine("Finished."); | |
370 | - else | |
371 | - { | |
372 | - for (int i = 0; MGGetErrors()[i]; ++i) | |
373 | - { | |
374 | - UI_ProgressThread_NewLine( | |
375 | - (std::string("[Error] ") + MGGetErrors()[i]).c_str() | |
376 | - ); | |
377 | - } | |
378 | - MGClearErrors(); | |
379 | - } | |
380 | - } | |
381 | - return TRUE; | |
382 | - | |
383 | - case WM_SIZE: | |
384 | - { | |
385 | - int cli_height = HIWORD(lParam); | |
386 | - | |
387 | - RECT btnrc; | |
388 | - GetWindowRect(GetDlgItem(hwndDlg, IDC_PROGRESSEND), &btnrc); | |
389 | - TransToClient(hwndDlg, &btnrc); | |
390 | - MoveWindow(GetDlgItem(hwndDlg, IDC_PROGRESSEND), btnrc.left, | |
391 | - cli_height - (btnrc.bottom - btnrc.top) - 4, | |
392 | - btnrc.right - btnrc.left, btnrc.bottom - btnrc.top, TRUE); | |
393 | - | |
394 | - GetWindowRect(GetDlgItem(hwndDlg, IDC_SHOWDETAILS), &btnrc); | |
395 | - TransToClient(hwndDlg, &btnrc); | |
396 | - MoveWindow(GetDlgItem(hwndDlg, IDC_SHOWDETAILS), btnrc.left, | |
397 | - cli_height - (btnrc.bottom - btnrc.top) - 4, | |
398 | - btnrc.right - btnrc.left, btnrc.bottom - btnrc.top, TRUE); | |
399 | - | |
400 | - RECT rc; | |
401 | - GetWindowRect(GetDlgItem(hwndDlg, IDC_ACTIONLIST), &rc); | |
402 | - TransToClient(hwndDlg, &rc); | |
403 | - MoveWindow(GetDlgItem(hwndDlg, IDC_ACTIONLIST), rc.left, rc.top, | |
404 | - rc.right - rc.left, | |
405 | - cli_height - (btnrc.bottom - btnrc.top) - rc.top - 16, TRUE); | |
406 | - | |
407 | - GetWindowRect(GetDlgItem(hwndDlg, IDC_STATUSGRP), &rc); | |
408 | - TransToClient(hwndDlg, &rc); | |
409 | - MoveWindow(GetDlgItem(hwndDlg, IDC_STATUSGRP), rc.left, rc.top, | |
410 | - rc.right - rc.left, | |
411 | - cli_height - (btnrc.bottom - btnrc.top) - rc.top - 10, TRUE); | |
412 | - } | |
413 | - return TRUE; | |
414 | - } | |
415 | - | |
416 | - return FALSE; | |
417 | -} | |
418 | - | |
419 | -extern "C" int UI_ThreadWithProgress | |
420 | - (int (*thread_func)(), | |
421 | - const char* dialog_title) | |
422 | -{ | |
423 | - if (dialog_title) | |
424 | - g_progressinfo.m_dlgtitle = dialog_title; | |
425 | - g_progressinfo.m_thread_func = thread_func; | |
426 | - int result = DialogBox(g_hinstance, MAKEINTRESOURCE(IDD_PROGRESSDLG), | |
427 | - g_hmainwnd, ProgressDlgProc); | |
428 | - g_progressinfo.m_dlgtitle = "Caption"; | |
429 | - return result; | |
430 | -} | |
431 | - | |
432 | -extern "C" int UI_ProgressThread_IsCancelled() | |
433 | -{ | |
434 | - return (g_progressinfo.m_cancelsignal) ? 1 : 0; | |
435 | -} | |
436 | - | |
437 | - | |
438 | -static int ListDownloadCallback(size_t total, size_t current) | |
439 | -{ | |
440 | - return UI_ProgressThread_IsCancelled() ? 1 : 0; | |
441 | -} | |
442 | - | |
443 | -static int UpdateListThread() | |
444 | -{ | |
445 | - UI_ProgressThread_NewLine("Downloading updated manifest..."); | |
446 | - int dlresult = DownloadFile( | |
447 | - "http://localhost:1330/mingwinst/mingw_avail.mft", | |
448 | - (std::string(GetBinDir()) + "\\mingw_avail.mft").c_str(), | |
449 | - ListDownloadCallback | |
450 | - ); | |
451 | - if (dlresult != 0) | |
452 | - { | |
453 | - if (dlresult > 0 && dlresult != 2) | |
454 | - dlresult = -dlresult; | |
455 | - return dlresult; | |
456 | - } | |
457 | - return 0; | |
458 | -} | |
459 | - | |
460 | -extern "C" void UI_UpdateLists() | |
461 | -{ | |
462 | - if (UI_ThreadWithProgress(UpdateListThread, "Download Updated Lists") != 0) | |
463 | - return; | |
464 | - if (!PkgIndex::LoadIndex()) | |
465 | - return; | |
466 | - UI_RefreshCategoryList(); | |
467 | - return; | |
468 | -} |
@@ -0,0 +1,65 @@ | ||
1 | +/** \file ui.cpp | |
2 | + * | |
3 | + * Created: JohnE, 2008-10-11 | |
4 | + */ | |
5 | + | |
6 | + | |
7 | +#include "ui_general.hh" | |
8 | + | |
9 | +#define WIN32_LEAN_AND_MEAN | |
10 | +#include <windows.h> | |
11 | +#include <limits.h> | |
12 | +#include <stdio.h> | |
13 | +#include "progressthread.hh" | |
14 | +#include "mainwnd.hh" | |
15 | +#include "error.hh" | |
16 | +#include "getbindir.hh" | |
17 | +#include "download.hh" | |
18 | +#include "pkgindex.hh" | |
19 | +#include "categorytree.hh" | |
20 | + | |
21 | + | |
22 | +ProgressThreadInfo* g_dlthreadinfo = 0; | |
23 | + | |
24 | + | |
25 | +void LastError_MsgBox(const char* title) | |
26 | +{ | |
27 | + MessageBox(g_hmainwnd, MGGetErrors()[0], title, MB_OK | MB_ICONERROR); | |
28 | + MGClearErrors(); | |
29 | +} | |
30 | + | |
31 | + | |
32 | +int ListDownloadCallback(size_t total, size_t current) | |
33 | +{ | |
34 | + return ProgressThread_IsCancelled(g_dlthreadinfo) ? 1 : 0; | |
35 | +} | |
36 | + | |
37 | +int UpdateListThread(ProgressThreadInfo* info, void* param) | |
38 | +{ | |
39 | + g_dlthreadinfo = info; | |
40 | + | |
41 | + ProgressThread_NewStatus(info, "Downloading updated manifest..."); | |
42 | + | |
43 | + char localpath[PATH_MAX + 1]; | |
44 | + snprintf(localpath, PATH_MAX + 1, "%s\\mingw_avail.mft", GetBinDir()); | |
45 | + int dlresult = DownloadFile( | |
46 | + "http://localhost:1330/mingwinst/mingw_avail.mft", localpath, | |
47 | + ListDownloadCallback | |
48 | + ); | |
49 | + | |
50 | + g_dlthreadinfo = 0; | |
51 | + | |
52 | + if (dlresult > 0 && dlresult != 2) | |
53 | + dlresult = -dlresult; | |
54 | + return dlresult; | |
55 | +} | |
56 | + | |
57 | +void UI_UpdateLists() | |
58 | +{ | |
59 | + if (ProgressThread("Download Updated Lists", UpdateListThread, 0) != 0) | |
60 | + return; | |
61 | + if (!PkgIndex_Load()) | |
62 | + return; | |
63 | + CategoryTree_Reload(); | |
64 | + return; | |
65 | +} |
@@ -12,12 +12,8 @@ extern "C" { | ||
12 | 12 | |
13 | 13 | |
14 | 14 | void UI_UpdateLists(); |
15 | -void UI_OnCategoryChange(int const* categories); | |
16 | -void UI_SortListView(int column); | |
17 | -void UI_OnListViewSelect(int sel); | |
18 | -void UI_OnStateCycle(int sel); | |
15 | + | |
19 | 16 | void LastError_MsgBox(const char* title); |
20 | -void UI_RefreshCategoryList(); | |
21 | 17 | |
22 | 18 | |
23 | 19 | #ifdef __cplusplus |
@@ -0,0 +1,33 @@ | ||
1 | + | |
2 | +#define WIN32_LEAN_AND_MEAN | |
3 | +#include <windows.h> | |
4 | +#include <curl/curl.h> | |
5 | +#include "mainwnd.hh" | |
6 | +#include "selectinst.hh" | |
7 | +#include "categorytree.hh" | |
8 | +#include "pkgindex.hh" | |
9 | + | |
10 | + | |
11 | +HINSTANCE g_hinstance; | |
12 | + | |
13 | + | |
14 | +int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) | |
15 | +{ | |
16 | + g_hinstance = hInstance; | |
17 | + | |
18 | + curl_global_init(CURL_GLOBAL_ALL); | |
19 | + | |
20 | + if (!CreateMainWnd()) | |
21 | + return 1; | |
22 | + | |
23 | + PkgIndex_Load(); | |
24 | + CategoryTree_Reload(); | |
25 | + | |
26 | + SelectInstallation(); | |
27 | + | |
28 | + int ret = MainMessageLoop(); | |
29 | + | |
30 | + curl_global_cleanup(); | |
31 | + | |
32 | + return ret; | |
33 | +} |
@@ -2,11 +2,12 @@ | ||
2 | 2 | #define WIN32_LEAN_AND_MEAN |
3 | 3 | #include <windows.h> |
4 | 4 | #include <string> |
5 | -#include "pkgindex.hpp" | |
6 | 5 | #include <curl/curl.h> |
7 | 6 | #include "mainwnd.hh" |
8 | 7 | #include "ui.hh" |
9 | 8 | #include "selectinst.hh" |
9 | +#include "categorytree.hh" | |
10 | +#include "pkgindex.hh" | |
10 | 11 | |
11 | 12 | |
12 | 13 | HINSTANCE g_hinstance; |
@@ -21,8 +22,8 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi | ||
21 | 22 | if (!CreateMainWnd()) |
22 | 23 | return 1; |
23 | 24 | |
24 | - PkgIndex::LoadIndex(); | |
25 | - UI_RefreshCategoryList(); | |
25 | + PkgIndex_Load(); | |
26 | + CategoryTree_Reload(); | |
26 | 27 | |
27 | 28 | SelectInstallation(); |
28 | 29 |