This is the mail archive of the cygwin-apps mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH setup 4/5] Query user after download error in interactive mode


Instead of just giving the user a "Try again?" Yes/No choice that goes
to IDD_SITE on Yes, create a dialog IDD_DOWNLOAD_ERROR with the
following choices: 'Retry' (retry the download), 'Back' (return to
IDD_CHOOSE), 'Continue' (ignore the errors), or 'Cancel' (exit).

The dialog lists the packages that had download errors so that the
user can make an informed choice.

Users who liked the old behavior (IDD_SITE) can select Back twice.
---
 download.cc | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 res.rc      | 22 ++++++++++++++++++
 resource.h  |  2 ++
 3 files changed, 95 insertions(+), 5 deletions(-)

diff --git a/download.cc b/download.cc
index 841f680..b059bf5 100644
--- a/download.cc
+++ b/download.cc
@@ -25,6 +25,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <process.h>
+#include <vector>
 
 #include "resource.h"
 #include "msg.h"
@@ -182,16 +183,65 @@ download_one (packagesource & pkgsource, HWND owner)
     }
   if (success)
     return 0;
-  /* FIXME: Do we want to note this? if so how? */
   return 1;
 }
 
+static std::vector <packageversion> download_failures;
+static std::string download_warn_pkgs;
+
+static INT_PTR CALLBACK
+download_error_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
+{
+  switch (message)
+    {
+    case WM_INITDIALOG:
+      eset (h, IDC_DOWNLOAD_EDIT, download_warn_pkgs);
+      SetFocus (GetDlgItem(h, IDRETRY));
+      return FALSE;
+
+    case WM_COMMAND:
+      switch (LOWORD (wParam))
+	{
+	case IDRETRY:
+	case IDC_BACK:
+	case IDIGNORE:
+	case IDABORT:
+	  EndDialog (h, LOWORD (wParam));
+	default:
+	  // Not reached.
+	  return 0;
+	}
+
+    default:
+      // Not handled.
+      return FALSE;
+    }
+  return TRUE;
+}
+
+static int
+query_download_errors (HINSTANCE h, HWND owner)
+{
+  download_warn_pkgs = "";
+  Log (LOG_PLAIN) << "The following package(s) had download errors:" << endLog;
+  for (std::vector <packageversion>::const_iterator i = download_failures.begin (); i != download_failures.end (); i++)
+    {
+      packageversion pv = *i;
+      std::string pvs = pv.Name () + "-" + pv.Canonical_version ();
+      Log (LOG_PLAIN) << "  " << pvs << endLog;
+      download_warn_pkgs += pvs + "\r\n";
+    }
+  return DialogBox (h, MAKEINTRESOURCE (IDD_DOWNLOAD_ERROR), owner,
+		    download_error_proc);
+}
+
 static int
 do_download_thread (HINSTANCE h, HWND owner)
 {
   int errors = 0;
   total_download_bytes = 0;
   total_download_bytes_sofar = 0;
+  download_failures.clear ();
 
   Progress.SetText1 ("Checking for packages to download...");
   Progress.SetText2 ("");
@@ -235,6 +285,8 @@ do_download_thread (HINSTANCE h, HWND owner)
 	  int e = 0;
 	  e += download_one (*version.source(), owner);
 	  errors += e;
+	  if (e)
+	    download_failures.push_back (version);
 #if 0
 	  if (e)
 	    pkg->action = ACTION_ERROR;
@@ -246,21 +298,35 @@ do_download_thread (HINSTANCE h, HWND owner)
     {
       // In unattended mode we retry the download, but not forever.
       static int retries = 5;
+      int rc;
       if (unattended_mode && --retries <= 0)
         {
 	  Log (LOG_PLAIN) << "download error in unattended_mode: out of retries" << endLog;
-	  Logger ().setExitMsg (IDS_INSTALL_INCOMPLETE);
-	  Logger ().exit (1);
+	  rc = IDABORT;
 	}
       else if (unattended_mode)
         {
 	  Log (LOG_PLAIN) << "download error in unattended_mode: " << retries
 	    << (retries > 1 ? " retries" : " retry") << " remaining." << endLog;
+	  rc = IDRETRY;
+	}
+      else
+	rc = query_download_errors (h, owner);
+      switch (rc)
+	{
+	case IDRETRY:
 	  Progress.SetActivateTask (WM_APP_START_DOWNLOAD);
 	  return IDD_INSTATUS;
+	case IDC_BACK:
+	  return IDD_CHOOSE;
+	case IDABORT:
+	  Logger ().setExitMsg (IDS_DOWNLOAD_INCOMPLETE_EXIT);
+	  Logger ().exit (1);
+	case IDIGNORE:
+	  break;
+	default:
+	  break;
 	}
-      else if (yesno (owner, IDS_DOWNLOAD_INCOMPLETE) == IDYES)
-	return IDD_SITE;
     }
 
   if (source == IDC_SOURCE_DOWNLOAD)
diff --git a/res.rc b/res.rc
index d1f0871..62fbe40 100644
--- a/res.rc
+++ b/res.rc
@@ -416,6 +416,28 @@ BEGIN
 
 END
 
+IDD_DOWNLOAD_ERROR DIALOG DISCARDABLE  0, 0, SETUP_STANDARD_DIALOG_DIMS
+STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION
+CAPTION "Download Incomplete"
+FONT 8, "MS Shell Dlg"
+BEGIN
+    ICON            IDI_WARNING,IDC_HEADICON,10,10
+    LTEXT           "The following package(s) had download errors:",
+                    IDC_STATIC,7,8,320,16
+    EDITTEXT        IDC_DOWNLOAD_EDIT,7,24,320,88,WS_VSCROLL |
+                    ES_LEFT | ES_MULTILINE | ES_READONLY |
+                    ES_AUTOVSCROLL
+    LTEXT           "Select 'Retry' to retry the download, "
+                    "'Back' to return to the package selection page, "
+                    "'Continue' to go on anyway (NOT RECOMMENDED), or "
+                    "'Cancel' to exit.",
+                    IDC_STATIC,7,120,320,24
+    DEFPUSHBUTTON   "&Retry",IDRETRY,45,150,50,15
+    PUSHBUTTON      "&Back",IDC_BACK,110,150,50,15
+    PUSHBUTTON      "&Continue",IDIGNORE,175,150,50,15
+    PUSHBUTTON      "Cancel",IDABORT,240,150,50,15
+END
+
 IDD_POSTINSTALL DIALOG DISCARDABLE  0, 0, SETUP_STANDARD_DIALOG_W, 142
 STYLE DS_MODALFRAME | DS_3DLOOK | DS_CENTER | WS_CHILD | WS_VISIBLE |
     WS_CAPTION | WS_SYSMENU
diff --git a/resource.h b/resource.h
index 98a4a0f..c04c13d 100644
--- a/resource.h
+++ b/resource.h
@@ -68,6 +68,7 @@
 #define IDD_DROPPED                       221
 #define IDD_POSTINSTALL                   222
 #define IDD_FILE_INUSE                    223
+#define IDD_DOWNLOAD_ERROR                224
 
 // Bitmaps
 
@@ -178,3 +179,4 @@
 #define IDC_FILE_INUSE_HELP               592
 #define IDC_NET_DIRECT_LEGACY             593
 #define IDC_CHOOSE_SYNC                   594
+#define IDC_DOWNLOAD_EDIT                 595
-- 
2.15.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]