]> cygwin.com Git - cygwin-apps/setup.git/blob - download.cc
* download.cc (download_one): Add missing parenthesis.
[cygwin-apps/setup.git] / download.cc
1 /*
2 * Copyright (c) 2000, Red Hat, Inc.
3 *
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.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by DJ Delorie <dj@cygnus.com>
13 *
14 */
15
16 /* The purpose of this file is to download all the files we need to
17 do the installation. */
18
19 static char *cvsid = "\n%%% $Id$\n";
20
21 #include "win32.h"
22
23 #include <stdio.h>
24 #include <sys/types.h>
25 #include <sys/stat.h>
26
27 #include "resource.h"
28 #include "msg.h"
29 #include "ini.h"
30 #include "dialog.h"
31 #include "concat.h"
32 #include "geturl.h"
33 #include "state.h"
34 #include "mkdir.h"
35 #include "log.h"
36
37 #define pi (package[i].info[package[i].trust])
38
39 static DWORD
40 get_file_size (char *name)
41 {
42 HANDLE h;
43 WIN32_FIND_DATA buf;
44 DWORD ret = 0;
45
46 h = FindFirstFileA (name, &buf);
47 if (h)
48 {
49 if (buf.nFileSizeHigh == 0)
50 ret = buf.nFileSizeLow;
51 FindClose (h);
52 }
53 return ret;
54 }
55
56 static int
57 download_one (char *name, int expected_size)
58 {
59 char *local = name;
60 int errors = 0;
61
62 DWORD size;
63 if ((size = get_file_size (local)) > 0)
64 if (size == expected_size)
65 return 0;
66
67 mkdir_p (0, local);
68
69 if (get_url_to_file (concat (MIRROR_SITE, "/", name, 0),
70 concat (local, ".tmp", 0),
71 expected_size))
72 {
73 note (IDS_DOWNLOAD_FAILED, name);
74 return 1;
75 }
76 else
77 {
78 size = get_file_size (concat (local, ".tmp", 0));
79 if (size == expected_size)
80 {
81 log (0, "Downloaded %s", local);
82 rename (concat (local, ".tmp", 0), local);
83 }
84 else
85 {
86 log (0, "Download %s wrong size (%d actual vs %d expected)",
87 local, size, expected_size);
88 note (IDS_DOWNLOAD_SHORT, local, size, expected_size);
89 return 1;
90 }
91 }
92
93 return 0;
94 }
95
96 void
97 do_download (HINSTANCE h)
98 {
99 int i;
100 int errors = 0;
101
102 for (i=0; i<npackages; i++)
103 if (package[i].action == ACTION_NEW || package[i].action == ACTION_UPGRADE)
104 {
105 int e = download_one (pi.install, pi.install_size);
106 if (package[i].srcaction == SRCACTION_YES && pi.source)
107 e += download_one (pi.source, pi.source_size);
108 errors += e;
109 if (e)
110 package[i].action = ACTION_ERROR;
111 }
112
113 dismiss_url_status_dialog ();
114
115 if (errors)
116 {
117 if (yesno (IDS_DOWNLOAD_INCOMPLETE) == IDYES)
118 {
119 next_dialog = IDD_SITE;
120 return;
121 }
122 }
123
124 if (source == IDC_SOURCE_DOWNLOAD)
125 {
126 if (errors)
127 exit_msg = IDS_DOWNLOAD_INCOMPLETE;
128 else
129 exit_msg = IDS_DOWNLOAD_COMPLETE;
130 next_dialog = 0;
131 }
132 else
133 next_dialog = IDD_S_INSTALL;
134 }
This page took 0.397986 seconds and 5 git commands to generate.