[PATCH] make setup mirror list more like web page not just urls

Brian Inglis Brian.Inglis@SystematicSw.ab.ca
Wed Nov 15 21:35:00 GMT 2017


Hi folks,

[reposted without text attachment to see if patch gets thru]

Working on a FAST_CWD FAQ, looking at the Setup mirror site page and the web
page, I wondered if we could usefully add the mirrors.lst region and territory
(called area and location in the code) to the Setup display, to avoid users
having to refer to the web page to find out where mirrors are based geographically.

The first change was to prefix the displayed_url member in site.cc
site_list_type::init "constructor" with "area - location - ".

The sort key was the mirror url host name with the domain components in reverse
order to sort non-country TLDs together before CC TLDs.
The code tested for TLD length == 3 to distinguish between CC and non-CC TLDs,
as this code is over 10 years old and there were only the original com, edu,
gov, mil, net, org non-CC domains, before other gTLDs were added.
That test was changed to handle all gTLDs with length >= 3, to prefix area and
location to the sort key member, reverse the domain components in the servername
field instead of the url host, and suffix the url protocol prefix to keep the
key unique where sites offer both ftp and http mirrors, rather than the whole
url in the original.

For checking, a short script used awk to do the same when fed with mirrors.lst,
produce lines with the displayed url and sort key separated by a tab, and sort
by the key to produce the displayed urls in the same order as the code should.
The output of the script [was] in the first text attachment to show the
displayed urls in the sorted order.

When this was displayed in setup, some of the urls were cut off by the list box
border, estimated about 3 ems too narrow.
The width of the list box and related controls in res.rc was increased by about
30 pixels, and the position of the Add button moved over the same amount, to
give an acceptable display.

The required patch is attached for discussion: some may not like the display of
the default mirror from /etc/setup/setup.rc last_mirror, which appears in the
list as " - - url", as the other mirrors.lst fields are not currently saved
under last_mirror, and more work may be needed to improve this.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

-------------- next part --------------
diff --git a/res.rc b/res.rc
index 80d1bf1..fa90a65 100644
--- a/res.rc
+++ b/res.rc
@@ -135,10 +135,10 @@ CAPTION "Cygwin Setup - Choose Download Site(s)"
 FONT 8, "MS Shell Dlg"
 BEGIN
     ICON            IDI_CYGWIN,IDC_HEADICON,SETUP_HEADICON_X,0,21,20
-    LISTBOX         IDC_URL_LIST,66,45,185,110,LBS_NOINTEGRALHEIGHT | 
+    LISTBOX         IDC_URL_LIST,66,45,216,110,LBS_NOINTEGRALHEIGHT | 
                     LBS_EXTENDEDSEL | WS_VSCROLL | WS_HSCROLL | WS_GROUP | 
                     WS_TABSTOP
-    LTEXT           "Available Download Sites:",IDC_STATIC,66,34,183,8,NOT 
+    LTEXT           "Available Download Sites:",IDC_STATIC,66,34,216,8,NOT 
                     WS_GROUP
     CONTROL         "",IDC_HEADSEPARATOR,"Static",SS_BLACKFRAME | SS_SUNKEN,0,28,
                     SETUP_STANDARD_DIALOG_W,1
@@ -146,10 +146,10 @@ BEGIN
                     IDC_STATIC,21,9,239,16,NOT WS_GROUP
     LTEXT           "Choose A Download Site",IDC_STATIC_HEADER_TITLE,7,0,258,
                     8,NOT WS_GROUP
-    EDITTEXT        IDC_EDIT_USER_URL,65,160,185,14,ES_AUTOHSCROLL | 
+    EDITTEXT        IDC_EDIT_USER_URL,65,160,216,14,ES_AUTOHSCROLL | 
                     WS_GROUP
     LTEXT           "User URL:",IDC_SITE_USERURL,15,162,45,8,NOT WS_GROUP
-    PUSHBUTTON      "Add",IDC_BUTTON_ADD_URL,255,160,50,14
+    PUSHBUTTON      "Add",IDC_BUTTON_ADD_URL,288,160,50,14
 END
 
 IDD_NET DIALOG DISCARDABLE  0, 0, SETUP_STANDARD_DIALOG_DIMS
diff --git a/setup.exe.manifest b/setup.exe.manifest
old mode 100755
new mode 100644
diff --git a/setup64.exe.manifest b/setup64.exe.manifest
old mode 100755
new mode 100644
diff --git a/site.cc b/site.cc
index c33da36..b8b988e 100644
--- a/site.cc
+++ b/site.cc
@@ -154,30 +154,30 @@ site_list_type::init (const string &_url, const string &_servername,
   if (url.at(url.length()-1) != '/')
     url.append("/");
 
-  /* displayed_url is protocol and site name part of url */
+  /* displayed_url is area, location, protocol part of url, and servername */
   string::size_type path_offset = url.find ("/", url.find ("//") + 2);
-  displayed_url = url.substr(0, path_offset);
-
-  /* the sorting key is hostname components in reverse order (to sort by country code)
-     plus the url (to ensure uniqueness) */
-  key = string();
-  string::size_type last_idx = displayed_url.length () - 1;
-  string::size_type idx = url.find_last_of("./", last_idx);
-  if (last_idx - idx == 3)
+  displayed_url = area + " - " + location + " - " + url.substr (0, path_offset);
+
+  /* the sorting key is area, location, servername components in reverse order
+   * (to sort by country code) plus the protocol (to ensure uniqueness) */
+  key = area + " " + location + " ";
+  string::size_type last_idx = servername.length ();
+  string::size_type idx = servername.find_last_of (".", last_idx);
+
+  if (last_idx - idx >= 3)
   {
-    /* Sort non-country TLDs (.com, .net, ...) together. */
+    /* Sort gTLDs (.com, .net, .info, ...) together. */
     key += " ";
   }
+
   do
   {
-    key += url.substr(idx + 1, last_idx - idx);
-    key += " ";
+    key += servername.substr (idx + 1, last_idx - idx) + " ";
     last_idx = idx - 1;
-    idx = url.find_last_of("./", last_idx);
-    if (idx == string::npos)
-      idx = 0;
-  } while (idx > 0);
-  key += url;
+    idx = servername.find_last_of (".", last_idx);
+  } while (idx != string::npos && idx > 0);
+
+  key += url.substr (0, url.find (':'));
 }
 
 site_list_type::site_list_type (const string &_url,



More information about the Cygwin-apps mailing list