+2000-10-23 DJ Delorie <dj@redhat.com>
+
+ * ini.h: add source actions
+ * fromcwd.cc: check for available sources
+ * res.rc: add checkbox bitmaps
+ * resource.h: ditto
+ * check-*.bmp: new
+ * choose.cc: add source column
+ * download.cc: download sources if called for
+ * install.cc: [un]install sources too
+
2000-10-22 DJ Delorie <dj@redhat.com>
* choose.cc (build_labels): Don't skip TRUST_PREV completely; only
#include "log.h"
#include "find.h"
-#define HMARGIN 10
-#define ROW_MARGIN 5
-#define ICON_MARGIN 4
+#define HMARGIN 10
+#define ROW_MARGIN 5
+#define ICON_MARGIN 4
+
+#define CHECK_SIZE 11
#define TRUST_KEEP 101
#define TRUST_UNINSTALL 102
static int header_height;
static HANDLE sysfont;
static int row_height;
-static HANDLE bm_spin, bm_rtarrow;
+static HANDLE bm_spin, bm_rtarrow, bm_checkyes, bm_checkno, bm_checkna;
static HDC bitmap_dc;
static struct {
int x;
} headers[] = {
{ "Current", 7, 0, 0 },
+#define CURRENT_COL 0
{ "New", 3, 0, 0 },
+#define NEW_COL 1
+ { "Src?", 4, 0, 0 },
+#define SRC_COL 2
{ "Package", 7, 0, 0 },
+#define PACKAGE_COL 3
{ 0, 0, 0, 0 }
};
+#define NUM_COLUMNS (sizeof(headers)/(sizeof(headers[0]))-1)
int *package_indexes, nindexes;
int which_is_installed; /* == TRUST* or -1 */
struct {
+ int src_avail;
int trust; /* may be keep or uninstall */
char *caption; /* ==0 at EOL */
} chooser[NTRUST+3]; /* one extra for NULL above */
int by = r + tm.tmHeight - 11;
if (extra[i].installed_ver && extra[i].installed_ver[0])
{
- TextOut (hdc, x+headers[0].x, r, extra[i].installed_ver, strlen (extra[i].installed_ver));
+ TextOut (hdc, x+headers[CURRENT_COL].x, r,
+ extra[i].installed_ver, strlen (extra[i].installed_ver));
SelectObject (bitmap_dc, bm_rtarrow);
- BitBlt (hdc, x+headers[0].x+headers[0].width+ICON_MARGIN/2+HMARGIN/2, by,
+ BitBlt (hdc, x+headers[CURRENT_COL].x+headers[0].width+ICON_MARGIN/2+HMARGIN/2, by,
11, 11, bitmap_dc, 0, 0, SRCCOPY);
}
char *s = extra[i].chooser[extra[i].pick].caption;
if (s)
{
- TextOut (hdc, x+headers[1].x + 11 + ICON_MARGIN, r,
+ TextOut (hdc, x+headers[NEW_COL].x + 11 + ICON_MARGIN, r,
s, strlen (s));
if (extra[i].npick > 1)
{
SelectObject (bitmap_dc, bm_spin);
- BitBlt (hdc, x+headers[1].x, by, 11, 11,
+ BitBlt (hdc, x+headers[NEW_COL].x, by, 11, 11,
bitmap_dc, 0, 0, SRCCOPY);
}
}
+ HANDLE check_bm = bm_checkna;
+ if (extra[i].chooser[extra[i].pick].src_avail)
+ {
+ if (package[i].srcaction == SRCACTION_NO)
+ check_bm = bm_checkno;
+ else if (package[i].srcaction == SRCACTION_YES)
+ check_bm = bm_checkyes;
+ }
+ SelectObject (bitmap_dc, check_bm);
+ BitBlt (hdc, x+headers[SRC_COL].x, by, 11, 11,
+ bitmap_dc, 0, 0, SRCCOPY);
+
if (package[i].name)
- TextOut (hdc, x+headers[2].x, r, package[i].name, strlen(package[i].name));
+ TextOut (hdc, x+headers[PACKAGE_COL].x, r, package[i].name, strlen(package[i].name));
}
if (nindexes == 0)
x += scroll_ulc_x;
y += scroll_ulc_y - header_height;
- if (x < headers[1].x - HMARGIN/2 || x > headers[2].x - HMARGIN/2)
- return 0;
-
r = (y + ROW_MARGIN/2) / row_height;
if (r < 0 || r >= npackages)
int p = package_indexes[r];
- extra[p].pick ++;
- if (extra[p].chooser[extra[p].pick].caption == 0)
- extra[p].pick = 0;
+ if (x >= headers[NEW_COL].x - HMARGIN/2 && x <= headers[NEW_COL+1].x - HMARGIN/2)
+ {
+ extra[p].pick ++;
+ if (extra[p].chooser[extra[p].pick].caption == 0)
+ extra[p].pick = 0;
+ }
+
+ if (x >= headers[SRC_COL].x - HMARGIN/2 && x <= headers[SRC_COL+1].x - HMARGIN/2)
+ {
+ if (extra[p].chooser[extra[p].pick].src_avail)
+ package[p].srcaction ^= (SRCACTION_NO^SRCACTION_YES);
+ }
RECT rect;
- rect.left = headers[1].x - scroll_ulc_x;
- rect.right = headers[2].x - scroll_ulc_x;
+ rect.left = headers[NEW_COL].x - scroll_ulc_x;
+ rect.right = headers[SRC_COL+1].x - scroll_ulc_x;
rect.top = header_height + r * row_height - scroll_ulc_y;
rect.bottom = rect.top + row_height;
InvalidateRect (hwnd, &rect, TRUE);
if (C.caption == 0 || C.caption[0] == 0)
C.caption = "0.0";
C.trust = t;
+ if (package[i].info[t].source)
+ C.src_avail = 1;
c++;
/* we intentionally skip TRUST_PREV */
if (t != TRUST_PREV || !extra[i].installed_ver)
extra[i].in_partial_list = 1;
+
}
if (c == 0)
note_width (dc, headers[i].text, 0, i);
for (i=0; i<npackages; i++)
{
- note_width (dc, extra[i].installed_ver, 0, 0);
- note_width (dc, extra[i].installed_ver, 11+ICON_MARGIN, 1);
+ note_width (dc, extra[i].installed_ver, 0, CURRENT_COL);
+ note_width (dc, extra[i].installed_ver, 11+ICON_MARGIN, NEW_COL);
for (t=0; t<NTRUST; t++)
- note_width (dc, package[i].info[t].version, 11+ICON_MARGIN, 1);
- note_width (dc, package[i].name, 0, 2);
- note_width (dc, package[i].sdesc, 0, 2);
+ note_width (dc, package[i].info[t].version, 11+ICON_MARGIN, NEW_COL);
+ note_width (dc, package[i].name, 0, PACKAGE_COL);
+ note_width (dc, package[i].sdesc, 0, PACKAGE_COL);
}
- note_width (dc, "keep", 11+ICON_MARGIN, 1);
- note_width (dc, "uninstall", 11+ICON_MARGIN, 1);
+ note_width (dc, "keep", 11+ICON_MARGIN, NEW_COL);
+ note_width (dc, "uninstall", 11+ICON_MARGIN, NEW_COL);
- headers[0].x = HMARGIN/2;
- headers[1].x = headers[0].x + headers[0].width + HMARGIN + 11 + ICON_MARGIN;
- headers[2].x = headers[1].x + headers[1].width + HMARGIN;
+ headers[CURRENT_COL].x = HMARGIN/2;
+ headers[NEW_COL].x = (headers[CURRENT_COL].x + headers[CURRENT_COL].width
+ + HMARGIN + 11 + ICON_MARGIN);
+ headers[SRC_COL].x = headers[NEW_COL].x + headers[NEW_COL].width + HMARGIN;
+ headers[PACKAGE_COL].x = headers[SRC_COL].x + headers[SRC_COL].width + HMARGIN;
set_full_list (lv, full_list);
default_trust (lv, TRUST_CURR);
fclose (db);
}
-static void
-foo1() {
- int i;
-
- for (i=0; i<npackages; i++)
- if (package[i].action == ACTION_UNKNOWN)
- package[i].action = ACTION_NEW;
-
- if (source == IDC_SOURCE_CWD)
- next_dialog = IDD_S_INSTALL;
- else
- next_dialog = IDD_S_DOWNLOAD;
-}
-
int
package_sort (const void *va, const void *vb)
{
bm_spin = LoadImage (h, MAKEINTRESOURCE (IDB_SPIN), IMAGE_BITMAP, 0, 0, 0);
bm_rtarrow = LoadImage (h, MAKEINTRESOURCE (IDB_RTARROW), IMAGE_BITMAP, 0, 0, 0);
+ bm_checkyes = LoadImage (h, MAKEINTRESOURCE (IDB_CHECK_YES), IMAGE_BITMAP, 0, 0, 0);
+ bm_checkno = LoadImage (h, MAKEINTRESOURCE (IDB_CHECK_NO), IMAGE_BITMAP, 0, 0, 0);
+ bm_checkna = LoadImage (h, MAKEINTRESOURCE (IDB_CHECK_NA), IMAGE_BITMAP, 0, 0, 0);
+
extra = (ExtraPackageInfo *) malloc (npackages * sizeof (ExtraPackageInfo));
memset (extra, 0, npackages * sizeof (ExtraPackageInfo));
for (i=0; i<npackages; i++)
- {
- extra[i].which_is_installed = -1;
- }
+ extra[i].which_is_installed = -1;
register_windows (h);
: (package[i].action == ACTION_ERROR) ? "error"
: "unknown");
- log (LOG_BABBLE, "[%s] action=%s trust=%s", package[i].name, action, trust);
+ log (LOG_BABBLE, "[%s] action=%s trust=%s src? %s", package[i].name, action, trust,
+ package[i].srcaction == SRCACTION_NO ? "no" : "yes");
for (int t=0; t<NTRUST; t++)
{
if (package[i].info[t].install)
#define pi (package[i].info[package[i].trust])
+static int
+download_one (char *name, int expected_size)
+{
+ char *local = name;
+ int errors = 0;
+
+ struct stat s;
+ if (stat (local, &s) >= 0)
+ if (s.st_size == expected_size)
+ return 0;
+
+ mkdir_p (0, local);
+
+ if (get_url_to_file (concat (MIRROR_SITE, "/", name, 0),
+ concat (local, ".tmp", 0),
+ expected_size))
+ {
+ note (IDS_DOWNLOAD_FAILED, name);
+ return 1;
+ }
+ else
+ {
+ stat (concat (local, ".tmp", 0), &s);
+ if (s.st_size == expected_size)
+ {
+ log (0, "Downloaded %s", local);
+ rename (concat (local, ".tmp", 0), local);
+ }
+ else
+ {
+ log (0, "Download %s wrong size (%d actual vs %d expected)",
+ local, s.st_size, expected_size);
+ note (IDS_DOWNLOAD_SHORT, local, s.st_size, expected_size);
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
void
do_download (HINSTANCE h)
{
for (i=0; i<npackages; i++)
if (package[i].action == ACTION_NEW || package[i].action == ACTION_UPGRADE)
{
- char *local = pi.install;
-
- struct stat s;
- if (stat (local, &s) >= 0)
- if (s.st_size == pi.install_size)
- continue;
-
- mkdir_p (0, local);
-
- if (get_url_to_file (concat (MIRROR_SITE, "/", pi.install, 0),
- concat (local, ".tmp", 0),
- pi.install_size))
- {
- note (IDS_DOWNLOAD_FAILED, pi.install);
- package[i].action = ACTION_ERROR;
- errors ++;
- continue;
- }
- else
- {
- stat (concat (local, ".tmp", 0), &s);
- if (s.st_size == pi.install_size)
- {
- log (0, "Downloaded %s", local);
- rename (concat (local, ".tmp", 0), local);
- }
- else
- {
- log (0, "Download %s wrong size (%d actual vs %d expected)", local, s.st_size, pi.install_size);
- note (IDS_DOWNLOAD_SHORT, local, s.st_size, pi.install_size);
- package[i].action = ACTION_ERROR;
- errors ++;
- }
- }
+ int e = download_one (pi.install, pi.install_size);
+ if (package[i].srcaction == SRCACTION_YES && pi.source)
+ e += download_one (pi.source, pi.source_size);
+ errors += e;
+ if (e)
+ package[i].action = ACTION_ERROR;
}
dismiss_url_status_dialog ();
find (".", found_file);
+ // Now see about source tarballs
+ int i, t;
+ Package *p;
+ char srcpath[_MAX_PATH];
+ for (i=0; i<npackages; i++)
+ {
+ p = package+i;
+ for (t=TRUST_PREV; t<=TRUST_TEST; t++)
+ if (p->info[t].install)
+ {
+ strcpy (srcpath, p->info[t].install);
+ strcpy (srcpath + strlen (srcpath) - 7, "-src.tar.gz");
+ msg ("looking for %s", srcpath);
+
+ WIN32_FIND_DATA wfd;
+ HANDLE h = FindFirstFile (srcpath, &wfd);
+ if (h != INVALID_HANDLE_VALUE)
+ {
+ msg("-- got it");
+ FindClose (h);
+ p->info[t].source = _strdup (srcpath);
+ p->info[t].source_size = wfd.nFileSizeLow;
+ }
+ }
+ }
+
return;
}
#define ACTION_UNINSTALL 4
#define ACTION_ERROR 5
+#define SRCACTION_NO 0
+#define SRCACTION_YES 1
+
typedef struct {
char *name; /* package name, like "cygwin" */
char *sdesc; /* short description (replaces "name" if provided) */
char *ldesc; /* long description (multi-line) */
int action; /* ACTION_* - only NEW and UPGRADE get installed */
+ int srcaction;/* SRCACTION_ */
int trust; /* TRUST_* (selects among info[] below) */
struct {
return 0;
}
+
+static int num_installs, num_uninstalls;
+
+static void
+uninstall_one (char *name, int action)
+{
+ hash dirs;
+ char line[_MAX_PATH];
+
+ gzFile lst = gzopen (concat (root_dir, "/etc/setup/",
+ name, ".lst.gz", 0),
+ "rb");
+ if (lst)
+ {
+ SetWindowText (ins_pkgname, name);
+ SetWindowText (ins_action, "Uninstalling...");
+ if (action == ACTION_UPGRADE)
+ log (0, "Uninstalling old %s", name);
+ else
+ log (0, "Uninstalling %s", name);
+
+ while (gzgets (lst, line, sizeof (line)))
+ {
+ if (line[strlen(line)-1] == '\n')
+ line[strlen(line)-1] = 0;
+
+ dirs.add_subdirs (line);
+
+ char *d = map_filename (line);
+ DWORD dw = GetFileAttributes (d);
+ if (dw != 0xffffffff && !(dw & FILE_ATTRIBUTE_DIRECTORY))
+ {
+ log (LOG_BABBLE, "unlink %s", d);
+ DeleteFile (d);
+ }
+ }
+ gzclose (lst);
+
+ remove (concat (root_dir, "/etc/setup/", name, ".lst.gz", 0));
+
+ dirs.reverse_sort ();
+ char *subdir = 0;
+ while ((subdir = dirs.enumerate (subdir)) != 0)
+ {
+ char *d = map_filename (subdir);
+ if (RemoveDirectory (d))
+ log (LOG_BABBLE, "rmdir %s", d);
+ }
+ num_uninstalls ++;
+ }
+}
+
+
+static int
+install_one (char *name, char *file, int file_size, int action)
+{
+ int errors = 0;
+ char *local = file, *cp, *fn, *base;
+
+ base = local;
+ for (cp=local; *cp; cp++)
+ if (*cp == '/' || *cp == '\\' || *cp == ':')
+ base = cp+1;
+ SetWindowText (ins_pkgname, base);
+
+ if (!exists (local) && exists (base))
+ local = base;
+ if (!exists (local))
+ {
+ note (IDS_ERR_OPEN_READ, local, "No such file");
+ return 1;
+ }
+
+ gzFile lst = gzopen (concat (root_dir, "/etc/setup/",
+ name, ".lst.gz", 0),
+ "wb9");
+
+ package_bytes = file_size;
+
+ switch (action)
+ {
+ case ACTION_NEW:
+ SetWindowText (ins_action, "Installing...");
+ break;
+ case ACTION_UPGRADE:
+ SetWindowText (ins_action, "Upgrading...");
+ break;
+ }
+
+ log (0, "Installing %s", local);
+ tar_open (local);
+ while (fn = tar_next_file ())
+ {
+ char *dest_file;
+
+ if (lst)
+ gzprintf (lst, "%s\n", fn);
+
+ dest_file = map_filename (fn);
+
+ SetWindowText (ins_filename, dest_file);
+ log (LOG_BABBLE, "Installing file %s", dest_file);
+ if (tar_read_file (dest_file) != 0)
+ {
+ log (0, "Unable to install file %s", dest_file);
+ errors ++;
+ }
+
+ progress (tar_ftell ());
+ num_installs ++;
+ }
+ tar_close ();
+
+ total_bytes_sofar += file_size;
+ progress (0);
+
+ int df = diskfull (root_dir);
+ SendMessage (ins_diskfull, PBM_SETPOS, (WPARAM) df, 0);
+
+ if (lst)
+ gzclose (lst);
+
+ return errors;
+}
+
void
do_install (HINSTANCE h)
{
- int i, num_installs = 0, num_uninstalls = 0;
+ int i;
int errors = 0;
+ num_installs = 0, num_uninstalls = 0;
+
next_dialog = IDD_DESKTOP;
mkdir_p (1, root_dir);
if (package[i].action == ACTION_UNINSTALL
|| (package[i].action == ACTION_UPGRADE && pi.install))
{
- hash dirs;
- char line[_MAX_PATH];
-
- gzFile lst = gzopen (concat (root_dir, "/etc/setup/",
- package[i].name, ".lst.gz", 0),
- "rb");
- if (lst)
- {
- SetWindowText (ins_pkgname, package[i].name);
- SetWindowText (ins_action, "Uninstalling...");
- if (package[i].action == ACTION_UPGRADE)
- log (0, "Uninstalling old %s", package[i].name);
- else
- log (0, "Uninstalling %s", package[i].name);
-
- while (gzgets (lst, line, sizeof (line)))
- {
- if (line[strlen(line)-1] == '\n')
- line[strlen(line)-1] = 0;
-
- dirs.add_subdirs (line);
-
- char *d = map_filename (line);
- DWORD dw = GetFileAttributes (d);
- if (dw != 0xffffffff && !(dw & FILE_ATTRIBUTE_DIRECTORY))
- {
- log (LOG_BABBLE, "unlink %s", d);
- DeleteFile (d);
- }
- }
- gzclose (lst);
-
- dirs.reverse_sort ();
- char *subdir = 0;
- while ((subdir = dirs.enumerate (subdir)) != 0)
- {
- char *d = map_filename (subdir);
- if (RemoveDirectory (d))
- log (LOG_BABBLE, "rmdir %s", d);
- }
- num_uninstalls ++;
- }
+ uninstall_one (package[i].name, package[i].action);
+ uninstall_one (concat (package[i].name, "-src", 0), package[i].action);
}
if ((package[i].action == ACTION_NEW
|| package[i].action == ACTION_UPGRADE)
&& pi.install)
{
- char *local = pi.install, *cp, *fn, *base;
-
- base = local;
- for (cp=pi.install; *cp; cp++)
- if (*cp == '/' || *cp == '\\' || *cp == ':')
- base = cp+1;
- SetWindowText (ins_pkgname, base);
-
- if (!exists (local) && exists (base))
- local = base;
- if (!exists (local))
+ int e = install_one (package[i].name, pi.install, pi.install_size, package[i].action);
+ if (package[i].srcaction == SRCACTION_YES && pi.source)
+ e += install_one (concat (package[i].name, "-src", 0), pi.source, pi.source_size,
+ package[i].action);
+ if (e)
{
package[i].action = ACTION_ERROR;
- note (IDS_ERR_OPEN_READ, local, "No such file");
- errors ++;
- continue;
+ errors++;
}
-
- gzFile lst = gzopen (concat (root_dir, "/etc/setup/",
- package[i].name, ".lst.gz", 0),
- "wb9");
-
- package_bytes = pi.install_size;
-
- switch (package[i].action)
- {
- case ACTION_NEW:
- SetWindowText (ins_action, "Installing...");
- break;
- case ACTION_UPGRADE:
- SetWindowText (ins_action, "Upgrading...");
- break;
- }
-
- log (0, "Installing %s", local);
- tar_open (local);
- while (fn = tar_next_file ())
- {
- char *dest_file;
-
- if (lst)
- gzprintf (lst, "%s\n", fn);
-
- dest_file = map_filename (fn);
-
- SetWindowText (ins_filename, dest_file);
- log (LOG_BABBLE, "Installing file %s", dest_file);
- if (tar_read_file (dest_file) != 0)
- {
- package[i].action = ACTION_ERROR;
- log (0, "Unable to install file %s", dest_file);
- errors ++;
- }
-
- progress (tar_ftell ());
- num_installs ++;
- }
- tar_close ();
-
- total_bytes_sofar += pi.install_size;
- progress (0);
-
- df = diskfull (root_dir);
- SendMessage (ins_diskfull, PBM_SETPOS, (WPARAM) df, 0);
-
- if (lst)
- gzclose (lst);
}
} // end of big package loop
LOOP_PACKAGES
{
- fprintf (ndb, "%s %s %d\n", package[i].name,
- pi.install, pi.install_size);
+ if (package[i].srcaction == SRCACTION_YES)
+ fprintf (ndb, "%s %s %d %s %d\n", package[i].name,
+ pi.install, pi.install_size,
+ pi.source, pi.source_size);
+ else
+ fprintf (ndb, "%s %s %d\n", package[i].name,
+ pi.install, pi.install_size);
}
if (odb)
SPIN BITMAP DISCARDABLE "choose-spin.bmp"
IDB_SPIN BITMAP DISCARDABLE "choose-spin.bmp"
IDB_RTARROW BITMAP DISCARDABLE "choose-rtarrow.bmp"
+IDB_CHECK_YES BITMAP DISCARDABLE "check-yes.bmp"
+IDB_CHECK_NO BITMAP DISCARDABLE "check-no.bmp"
+IDB_CHECK_NA BITMAP DISCARDABLE "check-na.bmp"
/////////////////////////////////////////////////////////////////////////////
//
#define IDS_WININET 22
#define IDS_ERR_CHDIR 23
#define IDS_OLD_SETUP_VERSION 24
-#define IDS_DOWNLOAD_FAILED 25
-#define IDS_DOWNLOAD_INCOMPLETE 26
-#define IDS_INSTALL_INCOMPLETE 27
+#define IDS_DOWNLOAD_FAILED 25
+#define IDS_DOWNLOAD_INCOMPLETE 26
+#define IDS_INSTALL_INCOMPLETE 27
#define IDD_ROOT 101
#define IDD_SOURCE 102
#define IDD_OTHER_URL 103
#define IDI_SPIN 120
#define IDI_CYGWIN 121
#define IDD_LOCAL_DIR 122
+#define IDB_CHECK_YES 123
+#define IDB_CHECK_NO 124
+#define IDB_CHECK_NA 125
#define IDC_SOURCE_DOWNLOAD 1000
#define IDC_SOURCE_NETINST 1001
#define IDC_SOURCE_CWD 1002
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_3D_CONTROLS 1
-#define _APS_NEXT_RESOURCE_VALUE 123
+#define _APS_NEXT_RESOURCE_VALUE 126
#define _APS_NEXT_COMMAND_VALUE 40003
#define _APS_NEXT_CONTROL_VALUE 1045
#define _APS_NEXT_SYMED_VALUE 101