The MinGW.org Installation Manager Tool
Révision | 9b1e7fdd6ec29ba4cef95665722de7684c75b355 (tree) |
---|---|
l'heure | 2009-05-01 23:23:51 |
Auteur | John E. <tdragon@user...> |
Commiter | John E. |
Preserve file attributes in archives, UI code modularization
@@ -73,7 +73,9 @@ int ArchiveRead_ExtractEntryToBase | ||
73 | 73 | (ArchiveReader* reader, |
74 | 74 | char const* base_path) |
75 | 75 | { |
76 | - return ((ArchiveReaderStruct*)reader)->internal_extract_entry_to_base(reader, base_path); | |
76 | + return ((ArchiveReaderStruct*)reader)->internal_extract_entry_to_base( | |
77 | + reader, base_path | |
78 | + ); | |
77 | 79 | } |
78 | 80 | |
79 | 81 |
@@ -109,76 +109,81 @@ int ArchiveRead7z_ExtractEntryToBase | ||
109 | 109 | READER7Z(reader)->db.Database.Files[READER7Z(reader)->entry].Name); |
110 | 110 | |
111 | 111 | if (ArchiveRead7z_EntryIsDirectory(reader)) |
112 | - return ArchiveRead_EnsureDirectory(fullpath, strlen(base_path)); | |
113 | - | |
114 | - int rmostsep = strlen(fullpath) - 1; | |
115 | - while (rmostsep > 0 | |
116 | - && fullpath[rmostsep] != '/' && fullpath[rmostsep] != '\\') | |
117 | - --rmostsep; | |
118 | - if (rmostsep > 0) | |
119 | 112 | { |
120 | - char save = fullpath[rmostsep]; | |
121 | - fullpath[rmostsep] = 0; | |
122 | 113 | if (!ArchiveRead_EnsureDirectory(fullpath, strlen(base_path))) |
123 | - { | |
124 | - ArchiveRead_SetError((ArchiveReaderStruct*)reader, | |
125 | - "Failed to create directory '%s' for extraction", fullpath); | |
126 | 114 | return 0; |
127 | - } | |
128 | - fullpath[rmostsep] = save; | |
129 | 115 | } |
130 | - | |
131 | - if (!READER7Z(reader)->instream.filep) | |
116 | + else | |
132 | 117 | { |
133 | - READER7Z(reader)->instream.filep = | |
134 | - fopen(READER7Z(reader)->path, "rb"); | |
118 | + int rmostsep = strlen(fullpath) - 1; | |
119 | + while (rmostsep > 0 | |
120 | + && fullpath[rmostsep] != '/' && fullpath[rmostsep] != '\\') | |
121 | + --rmostsep; | |
122 | + if (rmostsep > 0) | |
123 | + { | |
124 | + char save = fullpath[rmostsep]; | |
125 | + fullpath[rmostsep] = 0; | |
126 | + if (!ArchiveRead_EnsureDirectory(fullpath, strlen(base_path))) | |
127 | + { | |
128 | + ArchiveRead_SetError((ArchiveReaderStruct*)reader, | |
129 | + "Failed to create directory '%s' for extraction", fullpath); | |
130 | + return 0; | |
131 | + } | |
132 | + fullpath[rmostsep] = save; | |
133 | + } | |
134 | + | |
135 | 135 | if (!READER7Z(reader)->instream.filep) |
136 | 136 | { |
137 | + READER7Z(reader)->instream.filep = | |
138 | + fopen(READER7Z(reader)->path, "rb"); | |
139 | + if (!READER7Z(reader)->instream.filep) | |
140 | + { | |
141 | + ArchiveRead_SetError((ArchiveReaderStruct*)reader, | |
142 | + "Failed to reopen file '%s' for entry extraction", | |
143 | + READER7Z(reader)->path); | |
144 | + return 0; | |
145 | + } | |
146 | + } | |
147 | + | |
148 | + size_t offset, outSizeProcessed; | |
149 | + SZ_RESULT res = SzExtract(&(READER7Z(reader)->instream.sz_stream), | |
150 | + &(READER7Z(reader)->db), READER7Z(reader)->entry, | |
151 | + &(READER7Z(reader)->blockIndex), | |
152 | + &(READER7Z(reader)->outBuffer), | |
153 | + &(READER7Z(reader)->outBufferSize), &offset, &outSizeProcessed, | |
154 | + &g_allocImp, &g_allocTempImp); | |
155 | + if (res == SZE_CRC_ERROR) | |
156 | + { | |
137 | 157 | ArchiveRead_SetError((ArchiveReaderStruct*)reader, |
138 | - "Failed to reopen file '%s' for entry extraction", | |
139 | - READER7Z(reader)->path); | |
158 | + "Bad CRC for entry '%s'", | |
159 | + READER7Z(reader)->db.Database.Files[READER7Z(reader)->entry].Name); | |
160 | + return 0; | |
161 | + } | |
162 | + else if (res != SZ_OK) | |
163 | + { | |
164 | + ArchiveRead_SetError((ArchiveReaderStruct*)reader, | |
165 | + "7zlib failed to unpack entry '%s'", | |
166 | + READER7Z(reader)->db.Database.Files[READER7Z(reader)->entry].Name); | |
140 | 167 | return 0; |
141 | 168 | } |
142 | - } | |
143 | 169 | |
144 | - size_t offset, outSizeProcessed; | |
145 | - SZ_RESULT res = SzExtract(&(READER7Z(reader)->instream.sz_stream), | |
146 | - &(READER7Z(reader)->db), READER7Z(reader)->entry, | |
147 | - &(READER7Z(reader)->blockIndex), | |
148 | - &(READER7Z(reader)->outBuffer), | |
149 | - &(READER7Z(reader)->outBufferSize), &offset, &outSizeProcessed, | |
150 | - &g_allocImp, &g_allocTempImp); | |
151 | - if (res == SZE_CRC_ERROR) | |
152 | - { | |
153 | - ArchiveRead_SetError((ArchiveReaderStruct*)reader, | |
154 | - "Bad CRC for entry '%s'", | |
155 | - READER7Z(reader)->db.Database.Files[READER7Z(reader)->entry].Name); | |
156 | - return 0; | |
157 | - } | |
158 | - else if (res != SZ_OK) | |
159 | - { | |
160 | - ArchiveRead_SetError((ArchiveReaderStruct*)reader, | |
161 | - "7zlib failed to unpack entry '%s'", | |
162 | - READER7Z(reader)->db.Database.Files[READER7Z(reader)->entry].Name); | |
163 | - return 0; | |
164 | - } | |
170 | + char tmppath[PATH_MAX + 1]; | |
171 | + snprintf(tmppath, PATH_MAX + 1, "%s.tmp", fullpath); | |
165 | 172 | |
166 | - char tmppath[PATH_MAX + 1]; | |
167 | - snprintf(tmppath, PATH_MAX + 1, "%s.tmp", fullpath); | |
173 | + FILE* outfile = fopen(tmppath, "wb"); | |
174 | + if (!outfile) | |
175 | + { | |
176 | + ArchiveRead_SetError((ArchiveReaderStruct*)reader, | |
177 | + "Failed to open output file '%s'", tmppath); | |
178 | + return 0; | |
179 | + } | |
180 | + fwrite(READER7Z(reader)->outBuffer + offset, 1, outSizeProcessed, | |
181 | + outfile); | |
182 | + fclose(outfile); | |
168 | 183 | |
169 | - FILE* outfile = fopen(tmppath, "wb"); | |
170 | - if (!outfile) | |
171 | - { | |
172 | - ArchiveRead_SetError((ArchiveReaderStruct*)reader, | |
173 | - "Failed to open output file '%s'", tmppath); | |
174 | - return 0; | |
184 | + remove(fullpath); | |
185 | + rename(tmppath, fullpath); | |
175 | 186 | } |
176 | - fwrite(READER7Z(reader)->outBuffer + offset, 1, outSizeProcessed, | |
177 | - outfile); | |
178 | - fclose(outfile); | |
179 | - | |
180 | - remove(fullpath); | |
181 | - rename(tmppath, fullpath); | |
182 | 187 | |
183 | 188 | if (READER7Z(reader)->db.Database.Files[READER7Z(reader)->entry].AreAttributesDefined) |
184 | 189 | SetFileAttributes(fullpath, READER7Z(reader)->db.Database.Files[READER7Z(reader)->entry].Attributes); |
@@ -222,6 +227,7 @@ void* ArchiveRead7z_OpenFile(char const* file) | ||
222 | 227 | SZ_RESULT ret = SzArchiveOpen(&instream.sz_stream, &reader->db, &g_allocImp, |
223 | 228 | &g_allocTempImp); |
224 | 229 | fclose(instream.filep); |
230 | + instream.filep = 0; | |
225 | 231 | if (ret != SZ_OK) |
226 | 232 | { |
227 | 233 | ArchiveRead_SetError(&reader->base, |
@@ -385,65 +385,71 @@ int ArchiveReadTar_ExtractEntryToBase | ||
385 | 385 | READERTAR(reader)->entry_path); |
386 | 386 | |
387 | 387 | if (ArchiveReadTar_EntryIsDirectory(reader)) |
388 | - return ArchiveRead_EnsureDirectory(fullpath, strlen(base_path)); | |
389 | - | |
390 | - int rmostsep = strlen(fullpath) - 1; | |
391 | - while (rmostsep > 0 | |
392 | - && fullpath[rmostsep] != '/' && fullpath[rmostsep] != '\\') | |
393 | - --rmostsep; | |
394 | - if (rmostsep > 0) | |
395 | 388 | { |
396 | - char save = fullpath[rmostsep]; | |
397 | - fullpath[rmostsep] = 0; | |
398 | 389 | if (!ArchiveRead_EnsureDirectory(fullpath, strlen(base_path))) |
399 | - { | |
400 | - ArchiveRead_SetError((ArchiveReaderStruct*)reader, | |
401 | - "Failed to create directory '%s' for extraction", fullpath); | |
402 | 390 | return 0; |
403 | - } | |
404 | - fullpath[rmostsep] = save; | |
405 | 391 | } |
406 | - | |
407 | - char tmppath[PATH_MAX + 1]; | |
408 | - snprintf(tmppath, PATH_MAX + 1, "%s.tmp", fullpath); | |
409 | - | |
410 | - FILE* outfile = fopen(tmppath, "wb"); | |
411 | - if (!outfile) | |
392 | + else | |
412 | 393 | { |
413 | - ArchiveRead_SetError((ArchiveReaderStruct*)reader, | |
414 | - "Failed to open file '%s' for output", tmppath); | |
415 | - return 0; | |
416 | - } | |
394 | + int rmostsep = strlen(fullpath) - 1; | |
395 | + while (rmostsep > 0 | |
396 | + && fullpath[rmostsep] != '/' && fullpath[rmostsep] != '\\') | |
397 | + --rmostsep; | |
398 | + if (rmostsep > 0) | |
399 | + { | |
400 | + char save = fullpath[rmostsep]; | |
401 | + fullpath[rmostsep] = 0; | |
402 | + if (!ArchiveRead_EnsureDirectory(fullpath, strlen(base_path))) | |
403 | + { | |
404 | + ArchiveRead_SetError((ArchiveReaderStruct*)reader, | |
405 | + "Failed to create directory '%s' for extraction", fullpath); | |
406 | + return 0; | |
407 | + } | |
408 | + fullpath[rmostsep] = save; | |
409 | + } | |
417 | 410 | |
418 | - char buf[BLOCKSIZE]; | |
419 | - while (READERTAR(reader)->entry_data > 0) | |
420 | - { | |
421 | - if (DecompressRead(READERTAR(reader), buf, BLOCKSIZE) != BLOCKSIZE) | |
411 | + char tmppath[PATH_MAX + 1]; | |
412 | + snprintf(tmppath, PATH_MAX + 1, "%s.tmp", fullpath); | |
413 | + | |
414 | + FILE* outfile = fopen(tmppath, "wb"); | |
415 | + if (!outfile) | |
422 | 416 | { |
423 | 417 | ArchiveRead_SetError((ArchiveReaderStruct*)reader, |
424 | - "Failed to read %d bytes from decompression stream", BLOCKSIZE); | |
425 | - fclose(outfile); | |
426 | - remove(tmppath); | |
418 | + "Failed to open file '%s' for output", tmppath); | |
427 | 419 | return 0; |
428 | 420 | } |
429 | - int write = (READERTAR(reader)->entry_data < BLOCKSIZE) ? | |
430 | - READERTAR(reader)->entry_data : BLOCKSIZE; | |
431 | - if (fwrite(buf, 1, write, outfile) != write) | |
421 | + | |
422 | + char buf[BLOCKSIZE]; | |
423 | + while (READERTAR(reader)->entry_data > 0) | |
432 | 424 | { |
433 | - ArchiveRead_SetError((ArchiveReaderStruct*)reader, | |
434 | - "Failed to write %d bytes to '%s'", write, tmppath); | |
435 | - fclose(outfile); | |
436 | - remove(tmppath); | |
437 | - return 0; | |
425 | + if (DecompressRead(READERTAR(reader), buf, BLOCKSIZE) != BLOCKSIZE) | |
426 | + { | |
427 | + ArchiveRead_SetError((ArchiveReaderStruct*)reader, | |
428 | + "Failed to read %d bytes from decompression stream", BLOCKSIZE); | |
429 | + fclose(outfile); | |
430 | + remove(tmppath); | |
431 | + return 0; | |
432 | + } | |
433 | + int write = (READERTAR(reader)->entry_data < BLOCKSIZE) ? | |
434 | + READERTAR(reader)->entry_data : BLOCKSIZE; | |
435 | + if (fwrite(buf, 1, write, outfile) != write) | |
436 | + { | |
437 | + ArchiveRead_SetError((ArchiveReaderStruct*)reader, | |
438 | + "Failed to write %d bytes to '%s'", write, tmppath); | |
439 | + fclose(outfile); | |
440 | + remove(tmppath); | |
441 | + return 0; | |
442 | + } | |
443 | + READERTAR(reader)->entry_data -= write; | |
438 | 444 | } |
439 | - READERTAR(reader)->entry_data -= write; | |
440 | - } | |
441 | - fclose(outfile); | |
445 | + fclose(outfile); | |
446 | + | |
447 | + remove(fullpath); | |
448 | + rename(tmppath, fullpath); | |
442 | 449 | |
443 | - remove(fullpath); | |
444 | - rename(tmppath, fullpath); | |
450 | + setfiletime(fullpath, READERTAR(reader)->entry_time); | |
451 | + } | |
445 | 452 | |
446 | - setfiletime(fullpath, READERTAR(reader)->entry_time); | |
447 | 453 | chmod(fullpath, READERTAR(reader)->entry_mode); |
448 | 454 | |
449 | 455 | return 1; |
@@ -117,84 +117,90 @@ int ArchiveReadZip_ExtractEntryToBase | ||
117 | 117 | READERZIP(reader)->entry_path); |
118 | 118 | |
119 | 119 | if (ArchiveReadZip_EntryIsDirectory(reader)) |
120 | - return ArchiveRead_EnsureDirectory(fullpath, strlen(base_path)); | |
121 | - | |
122 | - int rmostsep = strlen(fullpath) - 1; | |
123 | - while (rmostsep > 0 | |
124 | - && fullpath[rmostsep] != '/' && fullpath[rmostsep] != '\\') | |
125 | - --rmostsep; | |
126 | - if (rmostsep > 0) | |
127 | 120 | { |
128 | - char save = fullpath[rmostsep]; | |
129 | - fullpath[rmostsep] = 0; | |
130 | 121 | if (!ArchiveRead_EnsureDirectory(fullpath, strlen(base_path))) |
122 | + return 0; | |
123 | + } | |
124 | + else | |
125 | + { | |
126 | + int rmostsep = strlen(fullpath) - 1; | |
127 | + while (rmostsep > 0 | |
128 | + && fullpath[rmostsep] != '/' && fullpath[rmostsep] != '\\') | |
129 | + --rmostsep; | |
130 | + if (rmostsep > 0) | |
131 | + { | |
132 | + char save = fullpath[rmostsep]; | |
133 | + fullpath[rmostsep] = 0; | |
134 | + if (!ArchiveRead_EnsureDirectory(fullpath, strlen(base_path))) | |
135 | + { | |
136 | + ArchiveRead_SetError((ArchiveReaderStruct*)reader, | |
137 | + "Failed to create directory '%s' for extraction", fullpath); | |
138 | + return 0; | |
139 | + } | |
140 | + fullpath[rmostsep] = save; | |
141 | + } | |
142 | + | |
143 | + if (unzOpenCurrentFile(READERZIP(reader)->zf) != UNZ_OK) | |
131 | 144 | { |
132 | 145 | ArchiveRead_SetError((ArchiveReaderStruct*)reader, |
133 | - "Failed to create directory '%s' for extraction", fullpath); | |
146 | + "minizip couldn't open entry '%s' for extraction", | |
147 | + READERZIP(reader)->entry_path); | |
134 | 148 | return 0; |
135 | 149 | } |
136 | - fullpath[rmostsep] = save; | |
137 | - } | |
138 | 150 | |
139 | - if (unzOpenCurrentFile(READERZIP(reader)->zf) != UNZ_OK) | |
140 | - { | |
141 | - ArchiveRead_SetError((ArchiveReaderStruct*)reader, | |
142 | - "minizip couldn't open entry '%s' for extraction", | |
143 | - READERZIP(reader)->entry_path); | |
144 | - return 0; | |
145 | - } | |
151 | + char tmppath[PATH_MAX + 1]; | |
152 | + snprintf(tmppath, PATH_MAX + 1, "%s.tmp", fullpath); | |
146 | 153 | |
147 | - char tmppath[PATH_MAX + 1]; | |
148 | - snprintf(tmppath, PATH_MAX + 1, "%s.tmp", fullpath); | |
154 | + FILE* outfile = fopen(tmppath, "wb"); | |
155 | + if (!outfile) | |
156 | + { | |
157 | + ArchiveRead_SetError((ArchiveReaderStruct*)reader, | |
158 | + "Failed to open file '%s' for output", tmppath); | |
159 | + unzCloseCurrentFile(READERZIP(reader)->zf); | |
160 | + return 0; | |
161 | + } | |
149 | 162 | |
150 | - FILE* outfile = fopen(tmppath, "wb"); | |
151 | - if (!outfile) | |
152 | - { | |
153 | - ArchiveRead_SetError((ArchiveReaderStruct*)reader, | |
154 | - "Failed to open file '%s' for output", tmppath); | |
155 | - unzCloseCurrentFile(READERZIP(reader)->zf); | |
156 | - return 0; | |
157 | - } | |
163 | + int const buf_size = 1024 * 1024; | |
164 | + char* buf = malloc(buf_size); | |
165 | + int read; | |
166 | + while ((read = unzReadCurrentFile(READERZIP(reader)->zf, buf, buf_size)) > 0) | |
167 | + { | |
168 | + if (fwrite(buf, 1, read, outfile) != read) | |
169 | + { | |
170 | + ArchiveRead_SetError((ArchiveReaderStruct*)reader, | |
171 | + "Failed to write %d bytes to '%s'", read, tmppath); | |
172 | + free(buf); | |
173 | + fclose(outfile); | |
174 | + remove(tmppath); | |
175 | + unzCloseCurrentFile(READERZIP(reader)->zf); | |
176 | + return 0; | |
177 | + } | |
178 | + } | |
179 | + free(buf); | |
180 | + fclose(outfile); | |
158 | 181 | |
159 | - int const buf_size = 1024 * 1024; | |
160 | - char* buf = malloc(buf_size); | |
161 | - int read; | |
162 | - while ((read = unzReadCurrentFile(READERZIP(reader)->zf, buf, buf_size)) > 0) | |
163 | - { | |
164 | - if (fwrite(buf, 1, read, outfile) != read) | |
182 | + int close_result = unzCloseCurrentFile(READERZIP(reader)->zf); | |
183 | + if (read < 0) | |
165 | 184 | { |
166 | 185 | ArchiveRead_SetError((ArchiveReaderStruct*)reader, |
167 | - "Failed to write %d bytes to '%s'", read, tmppath); | |
168 | - free(buf); | |
169 | - fclose(outfile); | |
186 | + "minizip error extracting entry '%s'", READERZIP(reader)->entry_path); | |
187 | + remove(tmppath); | |
188 | + return 0; | |
189 | + } | |
190 | + if (close_result == UNZ_CRCERROR) | |
191 | + { | |
192 | + ArchiveRead_SetError((ArchiveReaderStruct*)reader, | |
193 | + "Bad CRC extracting entry '%s'", READERZIP(reader)->entry_path); | |
170 | 194 | remove(tmppath); |
171 | - unzCloseCurrentFile(READERZIP(reader)->zf); | |
172 | 195 | return 0; |
173 | 196 | } |
174 | - } | |
175 | - free(buf); | |
176 | - fclose(outfile); | |
177 | 197 | |
178 | - int close_result = unzCloseCurrentFile(READERZIP(reader)->zf); | |
179 | - if (read < 0) | |
180 | - { | |
181 | - ArchiveRead_SetError((ArchiveReaderStruct*)reader, | |
182 | - "minizip error extracting entry '%s'", READERZIP(reader)->entry_path); | |
183 | - remove(tmppath); | |
184 | - return 0; | |
185 | - } | |
186 | - if (close_result == UNZ_CRCERROR) | |
187 | - { | |
188 | - ArchiveRead_SetError((ArchiveReaderStruct*)reader, | |
189 | - "Bad CRC extracting entry '%s'", READERZIP(reader)->entry_path); | |
190 | - remove(tmppath); | |
191 | - return 0; | |
192 | - } | |
198 | + remove(fullpath); | |
199 | + rename(tmppath, fullpath); | |
193 | 200 | |
194 | - remove(fullpath); | |
195 | - rename(tmppath, fullpath); | |
201 | + setfiletime(fullpath, READERZIP(reader)->entry_info.dosDate); | |
202 | + } | |
196 | 203 | |
197 | - setfiletime(fullpath, READERZIP(reader)->entry_info.dosDate); | |
198 | 204 | SetFileAttributes(fullpath, READERZIP(reader)->entry_info.external_fa); |
199 | 205 | |
200 | 206 | return 1; |
@@ -9,6 +9,7 @@ | ||
9 | 9 | #define WIN32_LEAN_AND_MEAN |
10 | 10 | #include <windows.h> |
11 | 11 | #include <commctrl.h> |
12 | +#include <stdio.h> | |
12 | 13 | #include "mainwnd.hh" |
13 | 14 | #include "packagelist.hh" |
14 | 15 | #include "pkgindex.hh" |
@@ -57,6 +58,57 @@ void CategoryTree_Reload() | ||
57 | 58 | 0, (LPARAM)(LPTVINSERTSTRUCT)&tvins); |
58 | 59 | } |
59 | 60 | } |
60 | - int cats[] = {0, -1}; | |
61 | - PackageList_SetCategories(cats); | |
61 | + int cats = -1; | |
62 | + PackageList_SetCategories(&cats); | |
63 | +} | |
64 | + | |
65 | + | |
66 | +int CategoryTree_WM_NOTIFY | |
67 | + (HWND hwndDlg, | |
68 | + WPARAM wParam, | |
69 | + LPARAM lParam, | |
70 | + int* return_value_out __attribute__((unused))) | |
71 | +{ | |
72 | + switch (((LPNMHDR)lParam)->code) | |
73 | + { | |
74 | + case TVN_SELCHANGED: | |
75 | + if (((LPNMTREEVIEW)lParam)->itemNew.lParam < 0) | |
76 | + { | |
77 | + HWND htv = GetDlgItem(hwndDlg, IDC_CATLIST); | |
78 | + int childct = 0; | |
79 | + HTREEITEM child = TreeView_GetChild(htv, | |
80 | + ((LPNMTREEVIEW)lParam)->itemNew.hItem); | |
81 | + for (; child; child = TreeView_GetNextSibling(htv, child)) | |
82 | + ++childct; | |
83 | + int cats[childct + 1]; | |
84 | + cats[childct] = -1; | |
85 | + for (child = TreeView_GetChild(htv, | |
86 | + ((LPNMTREEVIEW)lParam)->itemNew.hItem); | |
87 | + child; | |
88 | + child = TreeView_GetNextSibling(htv, child)) | |
89 | + { | |
90 | + TVITEM tvitem; | |
91 | + tvitem.hItem = child; | |
92 | + tvitem.mask = TVIF_PARAM; | |
93 | + if (TreeView_GetItem(htv, &tvitem)) | |
94 | + cats[childct - 1] = tvitem.lParam - 1; | |
95 | + else | |
96 | + cats[childct - 1] = -1; | |
97 | + --childct; | |
98 | + } | |
99 | + PackageList_SetCategories(cats); | |
100 | + } | |
101 | + else if (((LPNMTREEVIEW)lParam)->itemNew.lParam == 0) | |
102 | + { | |
103 | + int cats = -1; | |
104 | + PackageList_SetCategories(&cats); | |
105 | + } | |
106 | + else | |
107 | + { | |
108 | + int cats[] = {((LPNMTREEVIEW)lParam)->itemNew.lParam - 1, -1}; | |
109 | + PackageList_SetCategories(cats); | |
110 | + } | |
111 | + break; | |
112 | + } | |
113 | + return 0; | |
62 | 114 | } |
@@ -6,12 +6,21 @@ | ||
6 | 6 | #define CATEGORYTREE_HH_INC |
7 | 7 | |
8 | 8 | |
9 | +#define WIN32_LEAN_AND_MEAN | |
10 | +#include <windows.h> | |
11 | + | |
12 | + | |
9 | 13 | #ifdef __cplusplus |
10 | 14 | extern "C" { |
11 | 15 | #endif |
12 | 16 | |
13 | 17 | |
14 | 18 | void CategoryTree_Reload(); |
19 | +int CategoryTree_WM_NOTIFY | |
20 | + (HWND hwndDlg, | |
21 | + WPARAM wParam, | |
22 | + LPARAM lParam, | |
23 | + int* return_value_out); | |
15 | 24 | |
16 | 25 | |
17 | 26 | #ifdef __cplusplus |
@@ -7,7 +7,8 @@ | ||
7 | 7 | |
8 | 8 | typedef struct CallbackInfo |
9 | 9 | { |
10 | - int (*next_callback)(size_t, size_t); | |
10 | + int (*next_callback)(size_t, size_t, void*); | |
11 | + void* callback_param; | |
11 | 12 | } CallbackInfo; |
12 | 13 | |
13 | 14 | int DLCallback |
@@ -18,14 +19,15 @@ int DLCallback | ||
18 | 19 | double ulnow) |
19 | 20 | { |
20 | 21 | return ((CallbackInfo*)clientp)->next_callback((size_t)dltotal, |
21 | - (size_t)dlnow); | |
22 | + (size_t)dlnow, ((CallbackInfo*)clientp)->callback_param); | |
22 | 23 | } |
23 | 24 | |
24 | 25 | |
25 | 26 | int DownloadFile |
26 | 27 | (const char* url, |
27 | 28 | const char* local, |
28 | - int (*prog_callback)(size_t, size_t)) | |
29 | + int (*prog_callback)(size_t, size_t, void*), | |
30 | + void* callback_param) | |
29 | 31 | { |
30 | 32 | int ret = 1; |
31 | 33 |
@@ -51,6 +53,7 @@ int DownloadFile | ||
51 | 53 | curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, DLCallback); |
52 | 54 | CallbackInfo info; |
53 | 55 | info.next_callback = prog_callback; |
56 | + info.callback_param = callback_param; | |
54 | 57 | curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &info); |
55 | 58 | } |
56 | 59 | else |
@@ -17,7 +17,8 @@ extern "C" { | ||
17 | 17 | int DownloadFile |
18 | 18 | (const char* url, |
19 | 19 | const char* local, |
20 | - int (*prog_callback)(size_t, size_t)); | |
20 | + int (*prog_callback)(size_t, size_t, void*), | |
21 | + void* callback_param); | |
21 | 22 | |
22 | 23 | |
23 | 24 | #ifdef __cplusplus |
@@ -16,6 +16,7 @@ | ||
16 | 16 | #include "ui_general.hh" |
17 | 17 | #include "pkgindex.hh" |
18 | 18 | #include "packagelist.hh" |
19 | +#include "categorytree.hh" | |
19 | 20 | |
20 | 21 | |
21 | 22 | HWND g_hmainwnd = 0; |
@@ -100,7 +101,7 @@ BOOL CALLBACK MainWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) | ||
100 | 101 | |
101 | 102 | HWND hcb = GetDlgItem(hwndDlg, IDC_CATTYPE); |
102 | 103 | SendMessage(hcb, CB_ADDSTRING, 0, (LPARAM)"Category"); |
103 | - SendMessage(hcb, CB_ADDSTRING, 0, (LPARAM)"State"); | |
104 | + SendMessage(hcb, CB_ADDSTRING, 0, (LPARAM)"Installed"); | |
104 | 105 | SendMessage(hcb, CB_ADDSTRING, 0, (LPARAM)"Release Status"); |
105 | 106 | SendMessage(hcb, CB_SETCURSEL, 0, 0); |
106 | 107 |
@@ -153,19 +154,22 @@ BOOL CALLBACK MainWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) | ||
153 | 154 | case IDM_SOURCES_REPOSITORIES: |
154 | 155 | EditReposDlg(); |
155 | 156 | return TRUE; |
156 | - case IDC_CATLIST: | |
157 | - if (HIWORD(wParam) == LBN_SELCHANGE) | |
158 | - { | |
159 | - //UI_OnCategoryChange(ListBox_GetCurSel((HWND)lParam)); | |
160 | - return TRUE; | |
161 | - } | |
162 | - break; | |
163 | 157 | } |
164 | 158 | break; |
165 | 159 | |
166 | 160 | case WM_NOTIFY: |
167 | 161 | switch (((LPNMHDR)lParam)->idFrom) |
168 | 162 | { |
163 | + case IDC_CATLIST: | |
164 | + { | |
165 | + int retval; | |
166 | + if (CategoryTree_WM_NOTIFY(hwndDlg, wParam, lParam, &retval)) | |
167 | + { | |
168 | + SetWindowLong(hwndDlg, DWL_MSGRESULT, retval); | |
169 | + return TRUE; | |
170 | + } | |
171 | + } | |
172 | + break; | |
169 | 173 | case IDC_COMPLIST: |
170 | 174 | switch (((LPNMHDR)lParam)->code) |
171 | 175 | { |
@@ -33,6 +33,7 @@ | ||
33 | 33 | <Add option="-Wall" /> |
34 | 34 | <Add option="-pipe" /> |
35 | 35 | <Add option="-mthreads" /> |
36 | + <Add option="-fno-exceptions" /> | |
36 | 37 | <Add option="-D_WIN32_IE=0x0400" /> |
37 | 38 | <Add option="-DCURL_STATICLIB" /> |
38 | 39 | <Add directory="$(#curl.include)" /> |
@@ -41,7 +42,6 @@ | ||
41 | 42 | </Compiler> |
42 | 43 | <Linker> |
43 | 44 | <Add library="curl" /> |
44 | - <Add library="z" /> | |
45 | 45 | <Add library="shfolder" /> |
46 | 46 | <Add library="shell32" /> |
47 | 47 | <Add library="gdi32" /> |
@@ -52,7 +52,6 @@ | ||
52 | 52 | <Add library="wsock32" /> |
53 | 53 | <Add library="wldap32" /> |
54 | 54 | <Add directory="$(#curl.lib)" /> |
55 | - <Add directory="$(#zlib)" /> | |
56 | 55 | </Linker> |
57 | 56 | <Unit filename="7z\7zCrc.c"> |
58 | 57 | <Option compilerVar="CC" /> |
@@ -186,14 +186,8 @@ void PackageList_SetCategories(const int* categories) | ||
186 | 186 | { |
187 | 187 | ListView_DeleteAllItems(g_hpackagelist); |
188 | 188 | |
189 | - if (*categories == -1) | |
190 | - { | |
191 | - PackageView_SetPackage(-1); | |
192 | - return; | |
193 | - } | |
194 | - | |
195 | 189 | int have_item = 0; |
196 | - if (*categories == 0) | |
190 | + if (*categories == -1) | |
197 | 191 | { |
198 | 192 | int i = 0; |
199 | 193 | for (; i < PkgIndex_NumPackages(); ++i) |
@@ -163,12 +163,19 @@ extern "C" int PkgIndex_Load() | ||
163 | 163 | const char* name = NonEmptyAttribute(cat_el, "name"); |
164 | 164 | if (!name) |
165 | 165 | continue; |
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))); | |
166 | + StringIntMap::const_iterator found = | |
167 | + g_pkgindex.category_ids.find(id); | |
168 | + if (found != g_pkgindex.category_ids.end()) | |
169 | + g_pkgindex.headings.back().second.push_back(found->second); | |
170 | + else | |
171 | + { | |
172 | + g_pkgindex.headings.back().second.push_back( | |
173 | + g_pkgindex.categories.size() | |
174 | + ); | |
175 | + g_pkgindex.category_ids[id] = g_pkgindex.categories.size(); | |
176 | + g_pkgindex.categories.push_back(std::make_pair(std::string(id), | |
177 | + std::string(name))); | |
178 | + } | |
172 | 179 | } |
173 | 180 | g_pkgindex.headings.back().second.push_back(-1); |
174 | 181 | } |
@@ -19,9 +19,6 @@ | ||
19 | 19 | #include "categorytree.hh" |
20 | 20 | |
21 | 21 | |
22 | -ProgressThreadInfo* g_dlthreadinfo = 0; | |
23 | - | |
24 | - | |
25 | 22 | void LastError_MsgBox(const char* title) |
26 | 23 | { |
27 | 24 | MessageBox(g_hmainwnd, MGGetErrors()[0], title, MB_OK | MB_ICONERROR); |
@@ -29,26 +26,22 @@ void LastError_MsgBox(const char* title) | ||
29 | 26 | } |
30 | 27 | |
31 | 28 | |
32 | -int ListDownloadCallback(size_t total, size_t current) | |
29 | +int ListDownloadCallback(size_t total, size_t current, void* param) | |
33 | 30 | { |
34 | - return ProgressThread_IsCancelled(g_dlthreadinfo) ? 1 : 0; | |
31 | + return ProgressThread_IsCancelled((ProgressThreadInfo*)param) ? 1 : 0; | |
35 | 32 | } |
36 | 33 | |
37 | 34 | int UpdateListThread(ProgressThreadInfo* info, void* param) |
38 | 35 | { |
39 | - g_dlthreadinfo = info; | |
40 | - | |
41 | 36 | ProgressThread_NewStatus(info, "Downloading updated manifest..."); |
42 | 37 | |
43 | 38 | char localpath[PATH_MAX + 1]; |
44 | 39 | snprintf(localpath, PATH_MAX + 1, "%s\\mingw_avail.mft", GetBinDir()); |
45 | 40 | int dlresult = DownloadFile( |
46 | 41 | "http://localhost:1330/mingwinst/mingw_avail.mft", localpath, |
47 | - ListDownloadCallback | |
42 | + ListDownloadCallback, info | |
48 | 43 | ); |
49 | 44 | |
50 | - g_dlthreadinfo = 0; | |
51 | - | |
52 | 45 | if (dlresult > 0 && dlresult != 2) |
53 | 46 | dlresult = -dlresult; |
54 | 47 | return dlresult; |
@@ -63,3 +56,8 @@ void UI_UpdateLists() | ||
63 | 56 | CategoryTree_Reload(); |
64 | 57 | return; |
65 | 58 | } |
59 | + | |
60 | + | |
61 | +void UI_ApplyChanges() | |
62 | +{ | |
63 | +} |
@@ -12,6 +12,7 @@ extern "C" { | ||
12 | 12 | |
13 | 13 | |
14 | 14 | void UI_UpdateLists(); |
15 | +void UI_ApplyChanges(); | |
15 | 16 | |
16 | 17 | void LastError_MsgBox(const char* title); |
17 | 18 |