]>
cygwin.com Git - cygwin-apps/setup.git/blob - choose.cc
2 * Copyright (c) 2000, Red Hat, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * A copy of the GNU General Public License can be found at
12 * Written by DJ Delorie <dj@cygnus.com>
16 /* The purpose of this file is to let the user choose which packages
17 to install, and which versions of the package when more than one
18 version is provided. The "trust" level serves as an indication as
19 to which version should be the default choice. At the moment, all
20 we do is compare with previously installed packages to skip any
21 that are already installed (by setting the action to ACTION_SAME).
22 While the "trust" stuff is supported, it's not really implemented
23 yet. We always prefer the "current" option. In the future, this
24 file might have a user dialog added to let the user choose to not
25 install packages, or to install packages that aren't installed by
28 static char *cvsid
= "\n%%% $Id$\n";
44 #include "filemanip.h"
55 #define TRUST_KEEP 101
56 #define TRUST_UNINSTALL 102
57 #define TRUST_NONE 103
58 #define TRUST_REDO 104
59 #define TRUST_SRC_ONLY 105
61 static int initialized
= 0;
63 static int full_list
= 0;
65 static int scroll_ulc_x
, scroll_ulc_y
;
67 static HWND lv
, nextbutton
, choose_inst_text
;
69 static int header_height
;
70 static HANDLE sysfont
;
71 static int row_height
;
72 static HANDLE bm_spin
, bm_rtarrow
, bm_checkyes
, bm_checkno
, bm_checkna
;
83 { "Current", 7, 0, 0 },
89 { "Package", 7, 0, 0 },
93 #define NUM_COLUMNS (sizeof (headers) / (sizeof (headers[0])) - 1)
95 int *package_indexes
, nindexes
;
97 struct ExtraPackageInfo
99 char *installed_file
; /* filename of previous "install" file */
100 char *installed_ver
; /* version part */
101 int installed_size
; /* ditto, size. */
106 int which_is_installed
; /* == TRUST* or -1 */
111 int trust
; /* may be keep or uninstall */
112 char *caption
; /* ==0 at EOL */
114 chooser
[NTRUST
+ 3]; /* one extra for NULL above */
117 static ExtraPackageInfo
*extra
;
126 hdc
= BeginPaint (hwnd
, &ps
);
128 SelectObject (hdc
, sysfont
);
129 SetBkColor (hdc
, GetSysColor (COLOR_WINDOW
));
132 GetClientRect (hwnd
, &cr
);
136 x
= cr
.left
- scroll_ulc_x
;
137 y
= cr
.top
- scroll_ulc_y
+ header_height
;
140 for (i
= 0; headers
[i
].text
; i
++)
142 TextOut (hdc
, x
+ headers
[i
].x
, 3, headers
[i
].text
, headers
[i
].slen
);
143 MoveToEx (hdc
, x
+ headers
[i
].x
, header_height
-3, &p
);
144 LineTo (hdc
, x
+ headers
[i
].x
+ headers
[i
].width
, header_height
-3);
147 IntersectClipRect (hdc
, cr
.left
, cr
.top
+ header_height
, cr
.right
, cr
.bottom
);
149 for (ii
= 0; ii
< nindexes
; ii
++)
151 i
= package_indexes
[ii
];
152 int r
= y
+ ii
* row_height
;
153 int by
= r
+ tm
.tmHeight
- 11;
154 if (extra
[i
].installed_ver
&& extra
[i
].installed_ver
[0])
156 TextOut (hdc
, x
+ headers
[CURRENT_COL
].x
, r
,
157 extra
[i
].installed_ver
, strlen (extra
[i
].installed_ver
));
158 SelectObject (bitmap_dc
, bm_rtarrow
);
159 BitBlt (hdc
, x
+ headers
[CURRENT_COL
].x
+ headers
[0].width
+ ICON_MARGIN
/2 + HMARGIN
/2, by
,
160 11, 11, bitmap_dc
, 0, 0, SRCCOPY
);
163 char *s
= extra
[i
].chooser
[extra
[i
].pick
].caption
;
166 TextOut (hdc
, x
+ headers
[NEW_COL
].x
+ 11 + ICON_MARGIN
, r
,
168 if (extra
[i
].npick
> 1)
170 SelectObject (bitmap_dc
, bm_spin
);
171 BitBlt (hdc
, x
+ headers
[NEW_COL
].x
, by
, 11, 11,
172 bitmap_dc
, 0, 0, SRCCOPY
);
176 HANDLE check_bm
= bm_checkna
;
177 if (extra
[i
].chooser
[extra
[i
].pick
].src_avail
)
179 if (package
[i
].srcaction
== SRCACTION_NO
&&
180 extra
[i
].chooser
[extra
[i
].pick
].trust
!= TRUST_SRC_ONLY
)
181 check_bm
= bm_checkno
;
182 else if (package
[i
].srcaction
== SRCACTION_YES
||
183 extra
[i
].chooser
[extra
[i
].pick
].trust
== TRUST_SRC_ONLY
)
184 check_bm
= bm_checkyes
;
186 SelectObject (bitmap_dc
, check_bm
);
187 BitBlt (hdc
, x
+ headers
[SRC_COL
].x
, by
, 11, 11,
188 bitmap_dc
, 0, 0, SRCCOPY
);
191 TextOut (hdc
, x
+ headers
[PACKAGE_COL
].x
, r
, package
[i
].name
, strlen (package
[i
].name
));
196 static char *msg
= "Nothing to Install/Update";
197 if (source
== IDC_SOURCE_DOWNLOAD
)
198 msg
= "Nothing to Download";
199 TextOut (hdc
, HMARGIN
, header_height
, msg
, strlen (msg
));
202 EndPaint (hwnd
, &ps
);
206 scroll_common (HWND hwnd
, int which
, int *var
, int code
)
211 si
.cbSize
= sizeof (si
);
213 GetScrollInfo (hwnd
, which
, &si
);
218 si
.nPos
= si
.nTrackPos
;
220 case SB_THUMBPOSITION
:
229 si
.nPos
+= row_height
;
232 si
.nPos
-= row_height
;
235 si
.nPos
+= si
.nPage
* 9/10;
238 si
.nPos
-= si
.nPage
* 9/10;
242 if ((int)si
.nPos
< 0)
244 if (si
.nPos
+ si
.nPage
> si
.nMax
)
245 si
.nPos
= si
.nMax
- si
.nPage
;
248 SetScrollInfo (hwnd
, which
, &si
, TRUE
);
250 int ox
= scroll_ulc_x
;
251 int oy
= scroll_ulc_y
;
255 GetClientRect (hwnd
, &cr
);
257 sr
.top
+= header_height
;
258 ScrollWindow (hwnd
, ox
- scroll_ulc_x
, oy
- scroll_ulc_y
, &sr
, &sr
);
261 ScrollWindow (hwnd
, ox
- scroll_ulc_x
, 0, &sr
, &sr
);
264 static LRESULT CALLBACK
265 list_vscroll (HWND hwnd
, HWND hctl
, UINT code
, int pos
)
267 scroll_common (hwnd
, SB_VERT
, &scroll_ulc_y
, code
);
270 static LRESULT CALLBACK
271 list_hscroll (HWND hwnd
, HWND hctl
, UINT code
, int pos
)
273 scroll_common (hwnd
, SB_HORZ
, &scroll_ulc_x
, code
);
276 static LRESULT CALLBACK
277 list_click (HWND hwnd
, BOOL dblclk
, int x
, int y
, UINT hitCode
)
284 if (y
< header_height
)
287 y
+= scroll_ulc_y
- header_height
;
289 r
= (y
+ ROW_MARGIN
/2) / row_height
;
291 if (r
< 0 || r
>= npackages
)
294 int p
= package_indexes
[r
];
296 if (x
>= headers
[NEW_COL
].x
- HMARGIN
/2 && x
<= headers
[NEW_COL
+ 1].x
- HMARGIN
/2)
299 while (extra
[p
].chooser
[extra
[p
].pick
].trust
< NTRUST
&&
300 (package
[p
].info
[extra
[p
].chooser
[extra
[p
].pick
].trust
].install_exists
301 ==0 && source
== IDC_SOURCE_CWD
) &&
302 package
[p
].info
[extra
[p
].chooser
[extra
[p
].pick
].trust
].install
&&
303 extra
[p
].chooser
[extra
[p
].pick
].caption
!= 0)
305 if (extra
[p
].chooser
[extra
[p
].pick
].caption
== 0)
309 if (x
>= headers
[SRC_COL
].x
- HMARGIN
/2 && x
<= headers
[SRC_COL
+ 1].x
- HMARGIN
/2)
311 if (extra
[p
].chooser
[extra
[p
].pick
].src_avail
)
312 package
[p
].srcaction
^= (SRCACTION_NO
^SRCACTION_YES
);
316 rect
.left
= headers
[NEW_COL
].x
- scroll_ulc_x
;
317 rect
.right
= headers
[SRC_COL
+ 1].x
- scroll_ulc_x
;
318 rect
.top
= header_height
+ r
* row_height
- scroll_ulc_y
;
319 rect
.bottom
= rect
.top
+ row_height
;
320 InvalidateRect (hwnd
, &rect
, TRUE
);
323 static LRESULT CALLBACK
324 listview_proc (HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
329 return HANDLE_WM_HSCROLL (hwnd
, wParam
, lParam
, list_hscroll
);
331 return HANDLE_WM_VSCROLL (hwnd
, wParam
, lParam
, list_vscroll
);
333 return HANDLE_WM_LBUTTONDOWN (hwnd
, wParam
, lParam
, list_click
);
338 return DefWindowProc (hwnd
, message
, wParam
, lParam
);
343 register_windows (HINSTANCE hinst
)
352 memset (&wcex
, 0, sizeof (wcex
));
353 wcex
.cbSize
= sizeof (WNDCLASSEX
);
354 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
355 wcex
.lpfnWndProc
= listview_proc
;
356 wcex
.hInstance
= hinst
;
357 wcex
.hIcon
= LoadIcon (0, IDI_APPLICATION
);
358 wcex
.hCursor
= LoadCursor (0, IDC_ARROW
);
359 wcex
.hbrBackground
= (HBRUSH
) (COLOR_WINDOW
+ 1);
360 wcex
.lpszClassName
= "listview";
362 RegisterClassEx (&wcex
);
366 note_width (HDC dc
, char *string
, int addend
, int column
)
371 GetTextExtentPoint32 (dc
, string
, strlen (string
), &s
);
372 if (headers
[column
].width
< s
.cx
+ addend
)
373 headers
[column
].width
= s
.cx
+ addend
;
377 check_existence (int p
, int trust
, int check_src
)
379 if (source
== IDC_SOURCE_NETINST
)
381 if (source
== IDC_SOURCE_DOWNLOAD
)
383 if (check_src
== 0 && _access (package
[p
].info
[trust
].install
, 0) == 0)
385 else if (check_src
== 1 && _access (package
[p
].info
[trust
].source
, 0) == 0)
390 if (source
== IDC_SOURCE_CWD
)
392 if (check_src
== 0 && package
[p
].info
[trust
].install
&&
393 _access (package
[p
].info
[trust
].install
, 0) == 0)
395 else if (check_src
== 1 && package
[p
].info
[trust
].source
&&
396 _access (package
[p
].info
[trust
].source
, 0) == 0)
405 for (int i
= 0; i
< npackages
; i
++)
407 for (int t
= 0; t
< NTRUST
; t
++)
409 /* 0 = check install file */
410 package
[i
].info
[t
].install_exists
= check_existence (i
, t
, 0);
411 /* 1 = check source file */
412 package
[i
].info
[t
].source_exists
= check_existence (i
, t
, 1);
414 for (int t
= 0; t
< NTRUST
; t
++)
416 if (package
[i
].info
[t
].install
&&
417 extra
[i
].installed_ver
!= package
[i
].info
[t
].version
)
419 if (source
== IDC_SOURCE_NETINST
)
420 package
[i
].info
[t
].partial_list_display
= 1;
421 else if (source
== IDC_SOURCE_DOWNLOAD
)
422 package
[i
].info
[t
].partial_list_display
= 1-package
[i
].info
[t
].install_exists
;
423 else if (source
== IDC_SOURCE_CWD
)
424 if (package
[i
].info
[t
].install_exists
)
425 package
[i
].info
[t
].partial_list_display
= 1;
427 package
[i
].info
[t
].partial_list_display
= 0;
429 if (package
[i
].info
[t
].partial_list_display
)
430 extra
[i
].in_partial_list
= 1;
437 best_trust (int p
, int trust
)
441 if (package
[p
].info
[t
].install
&&
442 ((package
[p
].info
[t
].install_exists
&& source
== IDC_SOURCE_CWD
) ||
443 (package
[p
].info
[t
].install_exists
== 0 &&
444 source
== IDC_SOURCE_DOWNLOAD
) || source
== IDC_SOURCE_NETINST
))
446 if (extra
[p
].installed_file
&& extra
[p
].installed_ver
== package
[p
].info
[t
].version
)
452 default_trust (HWND h
, int trust
)
456 for (i
= 0; i
< npackages
; i
++)
458 t
= best_trust (i
, trust
);
460 package
[i
].trust
= t
;
461 for (c
= 0; c
< extra
[i
].npick
; c
++)
462 if (t
== extra
[i
].chooser
[c
].trust
)
466 GetClientRect (h
, &r
);
467 InvalidateRect (h
, &r
, TRUE
);
469 SetFocus (nextbutton
);
473 set_full_list (HWND h
, int isfull
)
477 if (package_indexes
== 0)
478 package_indexes
= (int *) malloc (npackages
* sizeof (int));
479 for (i
= j
= 0; i
< npackages
; i
++)
481 if ((isfull
|| (extra
[i
].in_partial_list
&&
482 extra
[i
].chooser
[extra
[i
].pick
].trust
!= TRUST_KEEP
&&
483 extra
[i
].chooser
[extra
[i
].pick
].trust
!= TRUST_NONE
)) &&
484 (source
== IDC_SOURCE_DOWNLOAD
|| source
== IDC_SOURCE_NETINST
||
485 package
[i
].info
[TRUST_PREV
].install_exists
||
486 package
[i
].info
[TRUST_CURR
].install_exists
||
487 package
[i
].info
[TRUST_TEST
].install_exists
))
488 package_indexes
[j
++] = i
;
493 GetClientRect (h
, &r
);
495 memset (&si
, 0, sizeof (si
));
496 si
.cbSize
= sizeof (si
);
499 si
.nMax
= headers
[2].x
+ headers
[2].width
+ HMARGIN
;
501 SetScrollInfo (h
, SB_HORZ
, &si
, TRUE
);
503 si
.nMax
= nindexes
* row_height
;
504 si
.nPage
= r
.bottom
- header_height
;
505 SetScrollInfo (h
, SB_VERT
, &si
, TRUE
);
507 scroll_ulc_x
= scroll_ulc_y
= 0;
509 InvalidateRect (h
, &r
, TRUE
);
512 SetFocus (nextbutton
);
519 for (i
= 0; i
< npackages
; i
++)
523 #define C extra[i].chooser[c]
524 if (extra
[i
].installed_ver
)
526 C
.caption
= "Uninstall";
527 C
.trust
= TRUST_UNINSTALL
;
530 C
.trust
= TRUST_KEEP
;
534 if (extra
[i
].installed_ver
&&
535 package
[i
].info
[extra
[i
].which_is_installed
].source
&&
536 ((package
[i
].info
[extra
[i
].which_is_installed
].source_exists
&&
537 source
==IDC_SOURCE_CWD
) ||
538 source
==IDC_SOURCE_DOWNLOAD
|| source
==IDC_SOURCE_NETINST
))
540 C
.caption
= "Sources";
541 if (package
[i
].info
[extra
[i
].which_is_installed
].source_exists
== 1 &&
542 source
== IDC_SOURCE_DOWNLOAD
)
543 C
.caption
= "Redo Sources";
544 C
.trust
= TRUST_SRC_ONLY
;
549 for (t
= TRUST_PREV
; t
< NTRUST
; t
++)
550 if (package
[i
].info
[t
].install
)
551 if (t
!= extra
[i
].which_is_installed
)
553 C
.caption
= package
[i
].info
[t
].version
;
554 if (C
.caption
== 0 || C
.caption
[0] == 0)
557 if (package
[i
].info
[t
].source
&&
558 ((package
[i
].info
[t
].source_exists
&&
559 source
==IDC_SOURCE_CWD
) ||
560 (package
[i
].info
[t
].source_exists
==0 &&
561 source
==IDC_SOURCE_DOWNLOAD
) || source
==IDC_SOURCE_NETINST
))
567 if (source
== IDC_SOURCE_DOWNLOAD
)
569 C
.caption
= "ReDownload";
573 C
.caption
= "ReInstall";
575 if (package
[i
].info
[t
].source
&&
576 ((package
[i
].info
[t
].source_exists
&&
577 source
==IDC_SOURCE_CWD
) ||
578 source
== IDC_SOURCE_DOWNLOAD
|| source
==IDC_SOURCE_NETINST
))
580 C
.trust
= TRUST_REDO
;
587 C
.trust
= TRUST_NONE
;
591 if (! extra
[i
].installed_file
)
594 C
.trust
= TRUST_NONE
;
605 create_listview (HWND dlg
, RECT
*r
)
608 lv
= CreateWindowEx (WS_EX_CLIENTEDGE
,
611 WS_CHILD
| WS_HSCROLL
| WS_VSCROLL
| WS_VISIBLE
,
613 r
->right
-r
->left
+ 1, r
->bottom
-r
->top
+ 1,
615 (HMENU
) MAKEINTRESOURCE(IDC_CHOOSE_LIST
),
618 ShowWindow (lv
, SW_SHOW
);
620 for (i
= 0; headers
[i
].text
; i
++)
621 headers
[i
].width
= 0;
624 sysfont
= GetStockObject (DEFAULT_GUI_FONT
);
625 SelectObject (dc
, sysfont
);
626 GetTextMetrics (dc
, &tm
);
627 header_height
= tm
.tmHeight
+ 5 + 3;
629 bitmap_dc
= CreateCompatibleDC (dc
);
631 row_height
= (tm
.tmHeight
+ tm
.tmExternalLeading
+ ROW_MARGIN
);
632 int irh
= tm
.tmExternalLeading
+ tm
.tmDescent
+ 11 + ROW_MARGIN
;
633 if (row_height
< irh
)
636 for (i
= 0; headers
[i
].text
; i
++)
637 note_width (dc
, headers
[i
].text
, 0, i
);
638 for (i
= 0; i
< npackages
; i
++)
640 note_width (dc
, extra
[i
].installed_ver
, 0, CURRENT_COL
);
641 note_width (dc
, extra
[i
].installed_ver
, 11 + ICON_MARGIN
, NEW_COL
);
642 for (t
= 0; t
< NTRUST
; t
++)
643 note_width (dc
, package
[i
].info
[t
].version
, 11 + ICON_MARGIN
, NEW_COL
);
644 note_width (dc
, package
[i
].name
, 0, PACKAGE_COL
);
645 note_width (dc
, package
[i
].sdesc
, 0, PACKAGE_COL
);
647 note_width (dc
, "keep", 11 + ICON_MARGIN
, NEW_COL
);
648 note_width (dc
, "uninstall", 11 + ICON_MARGIN
, NEW_COL
);
650 headers
[CURRENT_COL
].x
= HMARGIN
/2;
651 headers
[NEW_COL
].x
= (headers
[CURRENT_COL
].x
+ headers
[CURRENT_COL
].width
652 + HMARGIN
+ 11 + ICON_MARGIN
);
653 headers
[SRC_COL
].x
= headers
[NEW_COL
].x
+ headers
[NEW_COL
].width
+ HMARGIN
;
654 headers
[PACKAGE_COL
].x
= headers
[SRC_COL
].x
+ headers
[SRC_COL
].width
+ HMARGIN
;
656 default_trust (lv
, TRUST_CURR
);
657 set_full_list (lv
, full_list
);
658 static int ta
[] = { IDC_CHOOSE_CURR
, 0 };
659 rbset (dlg
, ta
, IDC_CHOOSE_CURR
);
665 dialog_cmd (HWND h
, int id
, HWND hwndctl
, UINT code
)
669 case IDC_CHOOSE_PREV
:
670 default_trust (lv
, TRUST_PREV
);
671 set_full_list (lv
, full_list
);
673 case IDC_CHOOSE_CURR
:
674 default_trust (lv
, TRUST_CURR
);
675 set_full_list (lv
, full_list
);
678 default_trust (lv
, TRUST_TEST
);
679 set_full_list (lv
, full_list
);
681 case IDC_CHOOSE_FULLPART
:
682 set_full_list (lv
, !full_list
);
686 if (source
== IDC_SOURCE_CWD
)
687 NEXT (IDD_S_INSTALL
);
689 NEXT (IDD_S_DOWNLOAD
);
694 if (source
== IDC_SOURCE_CWD
)
707 GetParentRect (HWND parent
, HWND child
, RECT
*r
)
710 GetWindowRect (child
, r
);
713 ScreenToClient (parent
, &p
);
718 ScreenToClient (parent
, &p
);
724 dialog_proc (HWND h
, UINT message
, WPARAM wParam
, LPARAM lParam
)
732 nextbutton
= GetDlgItem (h
, IDOK
);
733 frame
= GetDlgItem (h
, IDC_LISTVIEW_POS
);
734 choose_inst_text
= GetDlgItem(h
,IDC_CHOOSE_INST_TEXT
);
735 if (source
== IDC_SOURCE_DOWNLOAD
)
736 SetWindowText (choose_inst_text
, "Select packages to download ");
738 SetWindowText (choose_inst_text
, "Select packages to install ");
739 GetParentRect (h
, frame
, &r
);
742 create_listview (h
, &r
);
748 return HANDLE_WM_COMMAND (h
, wParam
, lParam
, dialog_cmd
);
761 if ((*s
== '/' || *s
== ':' || *s
== '\\') && s
[1])
769 get_package_version (int p
, int trust
)
772 char instpkg
[_MAX_PATH
];
773 instpkg
[0]=0; /* make sure empty to start with */
775 strcpy (instpkg
, extra
[p
].installed_file
);
777 strcpy (instpkg
, package
[p
].info
[trust
].install
);
778 for (v
= base (instpkg
); *v
; v
++)
779 if (*v
== '-' && isdigit (v
[1]))
787 if (strncmp (d
, ".tar", 4) == 0)
795 package
[p
].info
[trust
].version
= strdup (v
);
796 extra
[p
].installed_ver
= strdup (v
);
801 package
[p
].info
[trust
].version
= "0";
802 extra
[p
].installed_ver
= "0";
807 find_tar_ext (const char *path
)
809 char *p
= strchr (path
, '\0') - 7;
814 if (strcmp (p
, ".tar.gz") != 0)
817 else if (--p
<= path
|| strcmp (p
, ".tar.bz2") != 0)
824 scan2 (char *path
, unsigned int size
)
829 tarext
= find_tar_ext (path
);
833 char mainpkg
[_MAX_PATH
], pkginfo
[_MAX_PATH
], tarpkg
[_MAX_PATH
],
836 strcpy (mainpkg
, path
);
837 strcpy (tarpkg
, path
);
838 mainpkg
[tarext
] = 0; /* strip off the tar.[bg]z2? */
840 for (ver
= mainpkg
; *ver
; ver
++)
841 if ((*ver
== '-' || *ver
== '_') && isdigit (ver
[1]))
847 for (i
= 0; i
< npackages
; i
++)
850 for (t
= 0; t
< NTRUST
; t
++)
852 if (package
[i
].info
[t
].install
)
854 strcpy (pkginfo
, package
[i
].info
[t
].install
);
855 pkginfo
[find_tar_ext (pkginfo
)] = '\0'; /* strip off the tar.gz */
856 for (verinfo
= pkginfo
; *verinfo
; verinfo
++)
858 if ((*verinfo
== '-' || *verinfo
== '_') && isdigit (verinfo
[1]))
867 if (strcmp (pkginfo
, mainpkg
) == 0)
869 for (t
= 0; t
< NTRUST
; t
++)
870 if ((package
[i
].info
[t
].install
&&
871 strcmp (base (package
[i
].info
[t
].install
), base (path
)) == 0) ||
872 (package
[i
].info
[t
].source
&&
873 strcmp (base (package
[i
].info
[t
].source
), base (path
)) == 0))
875 if (strcmp (base (package
[i
].info
[t
].install
), base (path
)) == 0)
876 package
[i
].info
[t
].install_exists
= 1;
878 package
[i
].info
[t
].source_exists
= 1;
881 else if (t
>= NTRUST
- 1)
882 if (!package
[i
].info
[TRUST_CURR
].install
)
884 package
[i
].info
[TRUST_CURR
].version
= 0;
885 int tarsrcext
= tarext
- 4;
886 if (tarsrcext
> 0 && strncmp (path
+ tarsrcext
, "-src", 4) == 0)
888 int n
= find_tar_ext (tarpkg
);
889 memmove (tarpkg
+ n
- 4, tarpkg
+ n
, strlen (tarpkg
+ n
) + 1);
890 package
[i
].info
[TRUST_CURR
].install
= strdup (tarpkg
);
891 if (!package
[i
].info
[TRUST_CURR
].source
)
892 package
[i
].info
[TRUST_CURR
].source
= strdup (path
);
893 package
[i
].info
[TRUST_CURR
].source_size
= size
;
894 package
[i
].info
[TRUST_CURR
].source_exists
= 1;
895 if (package
[i
].info
[TRUST_CURR
].version
== 0)
896 get_package_version (i
, TRUST_CURR
);
900 package
[i
].info
[TRUST_CURR
].install
= strdup (path
);
901 package
[i
].info
[TRUST_CURR
].install_size
= size
;
902 package
[i
].info
[TRUST_CURR
].install_exists
= 1;
903 if (package
[i
].info
[TRUST_CURR
].version
== 0)
904 get_package_version (i
, TRUST_CURR
);
908 else if (!package
[i
].info
[TRUST_PREV
].install
)
910 package
[i
].info
[TRUST_PREV
].version
= 0;
911 int tarsrcext
= tarext
- 4;
912 if (tarsrcext
> 0 && strncmp (path
+ tarsrcext
, "-src", 4) == 0)
914 int n
= find_tar_ext (tarpkg
);
915 memmove (tarpkg
+ n
- 4, tarpkg
+ n
, strlen (tarpkg
+ n
) + 1);
916 package
[i
].info
[TRUST_PREV
].install
= strdup (tarpkg
);
917 if (!package
[i
].info
[TRUST_PREV
].source
)
918 package
[i
].info
[TRUST_PREV
].source
= strdup (path
);
919 package
[i
].info
[TRUST_PREV
].source_size
= size
;
920 package
[i
].info
[TRUST_PREV
].source_exists
= 1;
921 if (package
[i
].info
[TRUST_PREV
].version
== 0)
922 get_package_version (i
, TRUST_PREV
);
926 package
[i
].info
[TRUST_PREV
].install
= strdup (path
);
927 package
[i
].info
[TRUST_PREV
].install_size
= size
;
928 package
[i
].info
[TRUST_PREV
].install_exists
= 1;
929 if (package
[i
].info
[TRUST_PREV
].version
== 0)
930 get_package_version (i
, TRUST_PREV
);
940 scan_downloaded_files ()
952 char line
[1000], pkg
[1000], inst
[1000], src
[1000];
955 FILE *db
= fopen (cygpath ("/etc/setup/installed.db", 0), "rt");
959 while (fgets (line
, 1000, db
))
963 sscanf (line
, "%s %s %d %s %d", pkg
, inst
, &instsz
, src
, &srcsz
);
965 for (i
= 0; i
< npackages
; i
++)
966 if (strcmp (package
[i
].name
, pkg
) == 0)
969 extra
[i
].installed_file
= inst
;
970 extra
[i
].installed_size
= instsz
;
971 get_package_version (i
, -1);
973 char *binst
= base (inst
);
974 int n
= find_tar_ext (binst
) + 4;
975 for (t
= 0; t
< NTRUST
; t
++)
976 if (package
[i
].info
[t
].install
977 && strncmp (base (package
[i
].info
[t
].install
), binst
, n
) == 0)
979 extra
[i
].which_is_installed
= t
;
980 extra
[i
].installed_ver
= package
[i
].info
[t
].version
;
981 if (extra
[i
].installed_ver
== 0) /* still */
982 get_package_version (i
, t
);
986 if (extra
[i
].installed_ver
== 0) /* still */
987 get_package_version (i
, -1);
995 package_sort (const void *va
, const void *vb
)
997 Package
*a
= (Package
*)va
;
998 Package
*b
= (Package
*)vb
;
999 return strcmp (a
->name
, b
->name
);
1003 do_choose (HINSTANCE h
)
1007 qsort (package
, npackages
, sizeof (package
[0]), package_sort
);
1010 bm_spin
= LoadImage (h
, MAKEINTRESOURCE (IDB_SPIN
), IMAGE_BITMAP
, 0, 0, 0);
1011 bm_rtarrow
= LoadImage (h
, MAKEINTRESOURCE (IDB_RTARROW
), IMAGE_BITMAP
, 0, 0, 0);
1013 bm_checkyes
= LoadImage (h
, MAKEINTRESOURCE (IDB_CHECK_YES
), IMAGE_BITMAP
, 0, 0, 0);
1014 bm_checkno
= LoadImage (h
, MAKEINTRESOURCE (IDB_CHECK_NO
), IMAGE_BITMAP
, 0, 0, 0);
1015 bm_checkna
= LoadImage (h
, MAKEINTRESOURCE (IDB_CHECK_NA
), IMAGE_BITMAP
, 0, 0, 0);
1017 extra
= (ExtraPackageInfo
*) malloc (npackages
* sizeof (ExtraPackageInfo
));
1018 memset (extra
, 0, npackages
* sizeof (ExtraPackageInfo
));
1019 for (i
= 0; i
< npackages
; i
++)
1021 extra
[i
].which_is_installed
= -1;
1022 extra
[i
].in_partial_list
= 0;
1024 extra
[i
].chooser
[extra
[i
].pick
].trust
= TRUST_NONE
;
1025 for (int t
= 0; t
< NTRUST
; t
++)
1027 package
[i
].info
[t
].partial_list_display
= 0;
1028 package
[i
].info
[t
].install_exists
= 0;
1029 package
[i
].info
[t
].source_exists
= 0;
1033 register_windows (h
);
1035 if (source
== IDC_SOURCE_DOWNLOAD
|| source
== IDC_SOURCE_CWD
)
1036 scan_downloaded_files ();
1038 read_installed_db ();
1042 rv
= DialogBox (h
, MAKEINTRESOURCE (IDD_CHOOSE
), 0, dialog_proc
);
1044 fatal (IDS_DIALOG_FAILED
);
1046 for (i
= 0; i
< npackages
; i
++)
1048 switch (extra
[i
].chooser
[extra
[i
].pick
].trust
)
1053 if (extra
[i
].installed_file
)
1054 package
[i
].action
= ACTION_UPGRADE
;
1056 package
[i
].action
= ACTION_NEW
;
1057 package
[i
].trust
= extra
[i
].chooser
[extra
[i
].pick
].trust
;
1061 package
[i
].action
= ACTION_REDO
;
1062 if ( extra
[i
].which_is_installed
>= 0
1063 && extra
[i
].which_is_installed
<= TRUST_TEST
)
1064 package
[i
].trust
= extra
[i
].which_is_installed
;
1066 package
[i
].trust
= TRUST_CURR
;
1069 case TRUST_UNINSTALL
:
1070 package
[i
].action
= ACTION_UNINSTALL
;
1071 if (package
[i
].srcaction
== SRCACTION_YES
)
1072 package
[i
].action
= ACTION_SRC_ONLY
;
1075 case TRUST_SRC_ONLY
:
1076 package
[i
].action
= ACTION_SRC_ONLY
;
1077 if ( extra
[i
].which_is_installed
>= 0
1078 && extra
[i
].which_is_installed
<= TRUST_TEST
)
1079 package
[i
].trust
= extra
[i
].which_is_installed
;
1081 package
[i
].trust
= TRUST_CURR
;
1082 package
[i
].srcaction
= SRCACTION_YES
;
1088 package
[i
].action
= ACTION_SAME
;
1089 if (package
[i
].srcaction
== SRCACTION_YES
)
1090 package
[i
].action
= ACTION_SRC_ONLY
;
1095 log (LOG_BABBLE
, "Chooser results...");
1096 for (i
= 0; i
< npackages
; i
++)
1098 static char *infos
[] = {"prev", "curr", "test"};
1099 const char *trust
= ((package
[i
].trust
== TRUST_PREV
) ? "prev"
1100 : (package
[i
].trust
== TRUST_CURR
) ? "curr"
1101 : (package
[i
].trust
== TRUST_TEST
) ? "test"
1103 const char *action
= ((package
[i
].action
== ACTION_UNKNOWN
) ? "unknown"
1104 : (package
[i
].action
== ACTION_SAME
) ? "same"
1105 : (package
[i
].action
== ACTION_NEW
) ? "new"
1106 : (package
[i
].action
== ACTION_UPGRADE
) ? "upgrade"
1107 : (package
[i
].action
== ACTION_UNINSTALL
) ? "uninstall"
1108 : (package
[i
].action
== ACTION_REDO
&&
1109 source
== IDC_SOURCE_DOWNLOAD
) ? "redownload"
1110 : (package
[i
].action
== ACTION_REDO
&&
1111 source
!= IDC_SOURCE_DOWNLOAD
) ? "reinstall"
1112 : (package
[i
].action
== ACTION_SRC_ONLY
) ? "sources"
1113 : (package
[i
].action
== ACTION_ERROR
) ? "error"
1115 const char *installed
= ((extra
[i
].which_is_installed
== -1) ? "none"
1116 : (extra
[i
].which_is_installed
== TRUST_PREV
) ? "prev"
1117 : (extra
[i
].which_is_installed
== TRUST_CURR
) ? "curr"
1118 : (extra
[i
].which_is_installed
== TRUST_TEST
) ? "test"
1120 const char *partial_list
= ((extra
[i
].in_partial_list
== 1) ? "yes" : "no");
1122 log (LOG_BABBLE
, "[%s] action=%s trust=%s installed=%s partial_list=%s src?=%s",
1123 package
[i
].name
, action
, trust
, installed
,
1124 partial_list
, package
[i
].srcaction
== SRCACTION_NO
? "no" : "yes");
1125 for (int t
= 0; t
< NTRUST
; t
++)
1127 if (package
[i
].info
[t
].install
)
1128 log (LOG_BABBLE
, " [%s] ver=%s partial_list=%s \r\n inst=%s %d exists=%s \r\n src=%s %d exists=%s",
1130 package
[i
].info
[t
].version
?: "(none)",
1131 (package
[i
].info
[t
].partial_list_display
== 1) ? "yes":"no",
1132 package
[i
].info
[t
].install
?: "(none)",
1133 package
[i
].info
[t
].install_size
,
1134 (package
[i
].info
[t
].install_exists
== 1) ? "yes":"no",
1135 package
[i
].info
[t
].source
?: "(none)",
1136 package
[i
].info
[t
].source_size
,
1137 (package
[i
].info
[t
].source_exists
== 1) ? "yes":"no");
This page took 0.08164 seconds and 5 git commands to generate.