]>
cygwin.com Git - cygwin-apps/setup.git/blob - site.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 get the list of mirror sites and ask
17 the user which mirror site they want to download from. */
19 static char *cvsid
= "\n%%% $Id$\n";
38 #define OTHER_IDX (-2)
46 static site_list_type
*site_list
= 0;
47 static int list_idx
= NO_IDX
;
48 static int mirror_idx
= NO_IDX
;
51 check_if_enable_next (HWND h
)
53 EnableWindow (GetDlgItem (h
, IDOK
), (mirror_idx
!= NO_IDX
) ? 1 : 0);
59 HWND listbox
= GetDlgItem (h
, IDC_URL_LIST
);
60 SendMessage (listbox
, LB_SETCURSEL
, list_idx
, 0);
61 check_if_enable_next (h
);
67 HWND listbox
= GetDlgItem (h
, IDC_URL_LIST
);
68 list_idx
= SendMessage (listbox
, LB_GETCURSEL
, 0, 0);
69 if (list_idx
== LB_ERR
)
77 mirror_idx
= SendMessage (listbox
, LB_GETITEMDATA
, list_idx
, 0);
78 if (mirror_idx
== OTHER_IDX
)
81 mirror_site
= site_list
[mirror_idx
].url
;
92 root_dir
= find_root_mount (&istext
, &issystem
);
105 FILE *f
= fopen (concat (root_dir
, "/etc/setup/last-mirror", 0), "wb");
108 fprintf (f
, "%s\n", MIRROR_SITE
);
113 dialog_cmd (HWND h
, int id
, HWND hwndctl
, UINT code
)
120 check_if_enable_next (h
);
125 if (mirror_idx
== OTHER_IDX
)
126 NEXT (IDD_OTHER_URL
);
131 NEXT (IDD_S_LOAD_INI
);
147 dialog_proc (HWND h
, UINT message
, WPARAM wParam
, LPARAM lParam
)
154 listbox
= GetDlgItem (h
, IDC_URL_LIST
);
155 for (i
=0; site_list
[i
].url
; i
++)
157 j
= SendMessage (listbox
, LB_ADDSTRING
, 0, (LPARAM
)site_list
[i
].displayed_url
);
158 SendMessage (listbox
, LB_SETITEMDATA
, j
, i
);
160 j
= SendMessage (listbox
, LB_ADDSTRING
, 0, (LPARAM
)"Other URL");
161 SendMessage (listbox
, LB_SETITEMDATA
, j
, OTHER_IDX
);
165 return HANDLE_WM_COMMAND (h
, wParam
, lParam
, dialog_cmd
);
171 site_sort (const void *va
, const void *vb
)
173 site_list_type
*a
= (site_list_type
*)va
;
174 site_list_type
*b
= (site_list_type
*)vb
;
175 return strcmp (a
->sort_key
, b
->sort_key
);
179 get_site_list (HINSTANCE h
)
181 char mirror_url
[1000];
182 if (LoadString (h
, IDS_MIRROR_LST
, mirror_url
, sizeof (mirror_url
)) <= 0)
184 char *mirrors
= get_url_to_string (mirror_url
);
185 dismiss_url_status_dialog ();
189 char *bol
, *eol
, *nl
;
192 /* null plus account for possibly missing NL plus account for "Other
193 URL" from previous run. */
196 for (bol
=mirrors
; *bol
; bol
++)
200 site_list
= (site_list_type
*) malloc (nmirrors
* sizeof (site_list_type
));
207 for (eol
= bol
; *eol
&& *eol
!= '\n'; eol
++) ;
212 while (eol
> bol
&& eol
[-1] == '\r')
215 if (bol
[0] != '#' && bol
[0] > ' ')
217 char *semi
= strchr (bol
, ';');
220 site_list
[nmirrors
].url
= _strdup (bol
);
221 site_list
[nmirrors
].displayed_url
= _strdup (bol
);
222 char *dot
= strchr (site_list
[nmirrors
].displayed_url
, '.');
225 dot
= strchr (dot
, '/');
229 site_list
[nmirrors
].sort_key
= (char *) malloc (2*strlen (bol
) + 3);
231 dot
= site_list
[nmirrors
].displayed_url
;
233 char *dp
= site_list
[nmirrors
].sort_key
;
234 while (dot
!= site_list
[nmirrors
].displayed_url
)
236 if (*dot
== '.' || *dot
== '/')
240 *dp
++ = '~'; /* sort .com/.edu/.org together */
241 for (sp
=dot
+1; *sp
&& *sp
!= '.' && *sp
!= '/';)
248 strcpy (dp
, site_list
[nmirrors
].displayed_url
);
253 site_list
[nmirrors
].url
= 0;
255 qsort (site_list
, nmirrors
, sizeof (site_list_type
), site_sort
);
260 /* List of machines that should not be used by default when saved
262 #define NOSAVE1 "ftp://sources.redhat.com/"
263 #define NOSAVE1_LEN (sizeof ("ftp://sources.redhat.com/") - 1)
264 #define NOSAVE2 "ftp://sourceware.cygnus.com/"
265 #define NOSAVE2_LEN (sizeof ("ftp://sourceware.cygnus.com/") - 1)
266 #define NOSAVE3 "ftp://gcc.gnu.org/"
267 #define NOSAVE3_LEN (sizeof ("ftp://gcc.gnu.org/") - 1)
270 get_initial_list_idx ()
276 FILE *f
= fopen (concat (root_dir
, "/etc/setup/last-mirror", 0), "rt");
282 char * fg_ret
= fgets (site
, 1000, f
);
287 char *eos
= site
+ strlen (site
) - 1;
288 while (eos
>= site
&& (*eos
== '\n' || *eos
== '\r'))
295 for (i
= 0; site_list
[i
].url
; i
++)
296 if (strcmp (site_list
[i
].url
, site
) == 0)
299 if (! site_list
[i
].url
)
301 /* Don't default to certain machines ever since they suffer
302 from bandwidth limitations. */
303 if (strnicmp (site
, NOSAVE1
, NOSAVE1_LEN
) == 0
304 || strnicmp (site
, NOSAVE2
, NOSAVE2_LEN
) == 0
305 || strnicmp (site
, NOSAVE3
, NOSAVE3_LEN
) == 0)
307 site_list
[i
].displayed_url
=
308 site_list
[i
].url
= _strdup (site
);
309 site_list
[i
+1].url
= 0;
312 mirror_idx
= list_idx
= i
;
316 do_site (HINSTANCE h
)
321 if (get_site_list (h
))
327 get_initial_list_idx ();
329 rv
= DialogBox (h
, MAKEINTRESOURCE (IDD_SITE
), 0, dialog_proc
);
331 fatal (IDS_DIALOG_FAILED
);
333 if (mirror_idx
!= OTHER_IDX
)
334 log (0, "site: %s", mirror_site
);
This page took 0.047936 seconds and 5 git commands to generate.