]>
Commit | Line | Data |
---|---|---|
23c9e63c | 1 | /* |
9fe1181b | 2 | * Copyright (c) 2000, 2001, Red Hat, Inc. |
23c9e63c DD |
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 | ||
8507f105 DD |
19 | static char *cvsid = "\n%%% $Id$\n"; |
20 | ||
23c9e63c DD |
21 | #include "win32.h" |
22 | ||
23 | #include <stdio.h> | |
42bf5b92 | 24 | #include <unistd.h> |
23c9e63c DD |
25 | |
26 | #include "resource.h" | |
27 | #include "msg.h" | |
28 | #include "ini.h" | |
29 | #include "dialog.h" | |
30 | #include "concat.h" | |
31 | #include "geturl.h" | |
32 | #include "state.h" | |
33 | #include "mkdir.h" | |
89b1a15b | 34 | #include "log.h" |
42bf5b92 | 35 | #include "port.h" |
23c9e63c | 36 | |
9fe1181b | 37 | DWORD |
c46a33a9 | 38 | get_file_size (const char *name) |
88a77116 CV |
39 | { |
40 | HANDLE h; | |
41 | WIN32_FIND_DATA buf; | |
42 | DWORD ret = 0; | |
43 | ||
44 | h = FindFirstFileA (name, &buf); | |
b41962a3 | 45 | if (h != INVALID_HANDLE_VALUE) |
88a77116 CV |
46 | { |
47 | if (buf.nFileSizeHigh == 0) | |
48 | ret = buf.nFileSizeLow; | |
49 | FindClose (h); | |
50 | } | |
51 | return ret; | |
52 | } | |
53 | ||
3b9077d4 | 54 | static int |
42bf5b92 | 55 | download_one (char *name, int expected_size, int action) |
3b9077d4 DD |
56 | { |
57 | char *local = name; | |
58 | int errors = 0; | |
59 | ||
88a77116 | 60 | DWORD size; |
01954c34 | 61 | if ((size = get_file_size (local)) > 0) |
42bf5b92 CF |
62 | if (size == expected_size && action != ACTION_SRC_ONLY |
63 | && action != ACTION_REDO ) | |
3b9077d4 DD |
64 | return 0; |
65 | ||
66 | mkdir_p (0, local); | |
67 | ||
68 | if (get_url_to_file (concat (MIRROR_SITE, "/", name, 0), | |
69 | concat (local, ".tmp", 0), | |
70 | expected_size)) | |
71 | { | |
72 | note (IDS_DOWNLOAD_FAILED, name); | |
73 | return 1; | |
74 | } | |
75 | else | |
76 | { | |
88a77116 CV |
77 | size = get_file_size (concat (local, ".tmp", 0)); |
78 | if (size == expected_size) | |
3b9077d4 DD |
79 | { |
80 | log (0, "Downloaded %s", local); | |
42bf5b92 CF |
81 | if ( _access (local , 0) == 0) |
82 | remove ( local ); | |
3b9077d4 DD |
83 | rename (concat (local, ".tmp", 0), local); |
84 | } | |
85 | else | |
86 | { | |
87 | log (0, "Download %s wrong size (%d actual vs %d expected)", | |
88a77116 CV |
88 | local, size, expected_size); |
89 | note (IDS_DOWNLOAD_SHORT, local, size, expected_size); | |
3b9077d4 DD |
90 | return 1; |
91 | } | |
92 | } | |
93 | ||
94 | return 0; | |
95 | } | |
96 | ||
23c9e63c DD |
97 | void |
98 | do_download (HINSTANCE h) | |
99 | { | |
100 | int i; | |
2a1a01e0 | 101 | int errors = 0; |
2f9645a1 CV |
102 | total_download_bytes = 0; |
103 | total_download_bytes_sofar = 0; | |
104 | ||
c46a33a9 CF |
105 | for (Package *pkg = package; pkg->name; pkg++) |
106 | if (is_download_action (pkg)) | |
2f9645a1 | 107 | { |
c46a33a9 CF |
108 | Info *pi = pkg->info + pkg->trust; |
109 | DWORD size = get_file_size (pi->install); | |
110 | char *local = pi->install; | |
111 | if (pkg->action != ACTION_SRC_ONLY && | |
112 | (pkg->action == ACTION_REDO || | |
113 | size != pi->install_size)) | |
114 | total_download_bytes += pi->install_size; | |
115 | local = pi->source; | |
116 | size = get_file_size (pi->source); | |
117 | if (pkg->srcpicked && | |
118 | (pkg->action == ACTION_SRC_ONLY || | |
119 | size != pi->source_size)) | |
120 | total_download_bytes += pi->source_size; | |
2f9645a1 | 121 | } |
23c9e63c | 122 | |
c46a33a9 CF |
123 | for (Package *pkg = package; pkg->name; pkg++) |
124 | if (is_download_action (pkg)) | |
23c9e63c | 125 | { |
c46a33a9 CF |
126 | int e = 0; |
127 | Info *pi = pkg->info + pkg->trust; | |
128 | if (pkg->action != ACTION_SRC_ONLY) | |
129 | e += download_one (pi->install, pi->install_size, pkg->action); | |
130 | if (pkg->srcpicked && pi->source) | |
131 | e += download_one (pi->source, pi->source_size, pkg->action); | |
3b9077d4 DD |
132 | errors += e; |
133 | if (e) | |
c46a33a9 | 134 | pkg->action = ACTION_ERROR; |
23c9e63c DD |
135 | } |
136 | ||
137 | dismiss_url_status_dialog (); | |
bf1d5889 | 138 | |
2a1a01e0 DD |
139 | if (errors) |
140 | { | |
141 | if (yesno (IDS_DOWNLOAD_INCOMPLETE) == IDYES) | |
142 | { | |
143 | next_dialog = IDD_SITE; | |
144 | return; | |
145 | } | |
146 | } | |
147 | ||
bf1d5889 DD |
148 | if (source == IDC_SOURCE_DOWNLOAD) |
149 | { | |
2a1a01e0 DD |
150 | if (errors) |
151 | exit_msg = IDS_DOWNLOAD_INCOMPLETE; | |
152 | else | |
153 | exit_msg = IDS_DOWNLOAD_COMPLETE; | |
bf1d5889 DD |
154 | next_dialog = 0; |
155 | } | |
156 | else | |
157 | next_dialog = IDD_S_INSTALL; | |
23c9e63c | 158 | } |