2 * Copyright (c) 2000, 2001, 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 download all the files we need to
17 do the installation. */
20 static const char *cvsid
=
39 #include "filemanip.h"
42 #include "io_stream.h"
44 #include "package_db.h"
45 #include "package_meta.h"
46 #include "package_version.h"
47 #include "package_source.h"
52 extern ThreeBarProgressPage Progress
;
57 check_for_cached (packagesource
& pkgsource
)
60 1) is there a legacy version in the cache dir available.
61 (Note that the cache dir is represented by a mirror site of
67 get_file_size (local_dir
+ "/" + pkgsource
.Canonical ())) >
69 if (size
== pkgsource
.size
)
72 set_cached (String ("file://") + local_dir
+ "/" + pkgsource
.Canonical ());
77 2) is there a version from one of the selected mirror sites available ?
79 for (size_t n
= 1; n
<= pkgsource
.sites
.number (); n
++)
81 get_file_size (local_dir
+ "/" +
82 rfc1738_escape_part (pkgsource
.sites
[n
]->key
) + "/" +
83 pkgsource
.Canonical ())) > 0)
84 if (size
== pkgsource
.size
)
87 set_cached (String ("file://") + local_dir
+ "/" +
88 rfc1738_escape_part (pkgsource
.sites
[n
]->
90 pkgsource
.Canonical ());
97 /* download a file from a mirror site to the local cache. */
99 download_one (packagesource
& pkgsource
, HWND owner
)
101 if (check_for_cached (pkgsource
) && source
!= IDC_SOURCE_DOWNLOAD
)
104 /* try the download sites one after another */
107 for (size_t n
= 1; n
<= pkgsource
.sites
.number () && !success
; n
++)
109 String
const local
= local_dir
+ "/" +
110 rfc1738_escape_part (pkgsource
.sites
[n
]->
112 pkgsource
.Canonical ();
113 io_stream::mkpath_p (PATH_TO_FILE
, String ("file://") + local
);
115 if (get_url_to_file(pkgsource
.sites
[n
]->key
+ "/" +
116 pkgsource
.Canonical (),
117 local
+ ".tmp", pkgsource
.size
, owner
))
119 /* FIXME: note new source ? */
124 size_t size
= get_file_size (local
+ ".tmp");
125 if (size
== pkgsource
.size
)
127 log (LOG_PLAIN
, String ("Downloaded ") + local
);
128 if (_access (local
.cstr_oneuse(), 0) == 0)
129 remove (local
.cstr_oneuse());
130 rename ((local
+ ".tmp").cstr_oneuse(), local
.cstr_oneuse());
132 pkgsource
.set_cached (String ("file://") + local
);
133 // FIXME: move the downloaded file to the
134 // original locations - without the mirror site dir in the way
140 "Download %s wrong size (%u actual vs %d expected)",
141 local
.cstr_oneuse(), size
, pkgsource
.size
);
142 remove ((local
+ ".tmp").cstr_oneuse());
149 /* FIXME: Do we want to note this? if so how? */
154 do_download_thread (HINSTANCE h
, HWND owner
)
157 total_download_bytes
= 0;
158 total_download_bytes_sofar
= 0;
161 /* calculate the amount needed */
162 for (size_t n
= 1; n
< db
.packages
.number (); n
++)
164 packagemeta
& pkg
= *db
.packages
[n
];
165 if (pkg
.desired
&& (pkg
.desired
->srcpicked
|| pkg
.desired
->binpicked
))
167 packageversion
*version
= pkg
.desired
;
169 (check_for_cached (version
->bin
)
170 && source
!= IDC_SOURCE_DOWNLOAD
) && pkg
.desired
->binpicked
)
171 total_download_bytes
+= version
->bin
.size
;
173 (check_for_cached (version
->src
)
174 && source
!= IDC_SOURCE_DOWNLOAD
) && pkg
.desired
->srcpicked
)
175 total_download_bytes
+= version
->src
.size
;
179 /* and do the download. FIXME: This here we assign a new name for the cached version
180 * and check that above.
182 for (size_t n
= 1; n
< db
.packages
.number (); n
++)
184 packagemeta
& pkg
= *db
.packages
[n
];
185 if (pkg
.desired
&& (pkg
.desired
->srcpicked
|| pkg
.desired
->binpicked
))
188 packageversion
*version
= pkg
.desired
;
189 if (version
->binpicked
)
190 e
+= download_one (version
->bin
, owner
);
191 if (version
->srcpicked
)
192 e
+= download_one (version
->src
, owner
);
196 pkg
->action
= ACTION_ERROR
;
203 if (yesno (owner
, IDS_DOWNLOAD_INCOMPLETE
) == IDYES
)
205 next_dialog
= IDD_SITE
;
210 if (source
== IDC_SOURCE_DOWNLOAD
)
213 exit_msg
= IDS_DOWNLOAD_INCOMPLETE
;
215 exit_msg
= IDS_DOWNLOAD_COMPLETE
;
219 next_dialog
= IDD_S_INSTALL
;
223 do_download_reflector (void *p
)
226 context
= (HANDLE
*) p
;
228 do_download_thread ((HINSTANCE
) context
[0], (HWND
) context
[1]);
230 // Tell the progress page that we're done downloading
231 Progress
.PostMessage (WM_APP_DOWNLOAD_THREAD_COMPLETE
, 0, next_dialog
);
236 static HANDLE context
[2];
239 do_download (HINSTANCE h
, HWND owner
)
244 _beginthread (do_download_reflector
, 0, context
);