]>
cygwin.com Git - cygwin-apps/setup.git/blob - install.cc
2a5852f2f07ca46e78a6b4f2543a1e33f99acbe9
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 intall all the packages selected in
17 the install list (in ini.h). Note that we use a separate thread to
18 maintain the progress dialog, so we avoid the complexity of
19 handling two tasks in one thread. We also create or update all the
20 files in /etc/setup/* and create the mount points. */
27 #include <sys/types.h>
30 #include "zlib/zlib.h"
44 static HWND ins_dialog
= 0;
45 static HWND ins_pkgname
= 0;
46 static HWND ins_filename
= 0;
47 static HWND ins_pprogress
= 0;
48 static HWND ins_iprogress
= 0;
49 static HWND ins_diskfull
= 0;
50 static HANDLE init_event
;
52 static int total_bytes
= 0;
53 static int total_bytes_sofar
= 0;
54 static int package_bytes
= 0;
57 dialog_cmd (HWND h
, int id
, HWND hwndctl
, UINT code
)
67 dialog_proc (HWND h
, UINT message
, WPARAM wParam
, LPARAM lParam
)
75 ins_pkgname
= GetDlgItem (h
, IDC_INS_PKG
);
76 ins_filename
= GetDlgItem (h
, IDC_INS_FILE
);
77 ins_pprogress
= GetDlgItem (h
, IDC_INS_PPROGRESS
);
78 ins_iprogress
= GetDlgItem (h
, IDC_INS_IPROGRESS
);
79 ins_diskfull
= GetDlgItem (h
, IDC_INS_DISKFULL
);
80 SetEvent (init_event
);
83 return HANDLE_WM_COMMAND(h
, wParam
, lParam
, dialog_cmd
);
93 HANDLE ins_dialog
= CreateDialog (hinstance
, MAKEINTRESOURCE (IDD_INSTATUS
),
96 fatal ("create dialog");
97 ShowWindow (ins_dialog
, SW_SHOWNORMAL
);
98 UpdateWindow (ins_dialog
);
99 while (GetMessage (&m
, 0, 0, 0) > 0) {
100 TranslateMessage (&m
);
101 DispatchMessage (&m
);
105 static DWORD start_tics
;
114 init_event
= CreateEvent (0, 0, 0, 0);
115 thread
= CreateThread (0, 0, dialog
, 0, 0, &tid
);
116 WaitForSingleObject (init_event
, 10000);
117 CloseHandle (init_event
);
118 SendMessage (ins_pprogress
, PBM_SETRANGE
, 0, MAKELPARAM (0, 100));
119 SendMessage (ins_iprogress
, PBM_SETRANGE
, 0, MAKELPARAM (0, 100));
120 SendMessage (ins_diskfull
, PBM_SETRANGE
, 0, MAKELPARAM (0, 100));
123 SetWindowText (ins_pkgname
, "");
124 SetWindowText (ins_filename
, "");
125 SendMessage (ins_pprogress
, PBM_SETPOS
, (WPARAM
) 0, 0);
126 SendMessage (ins_iprogress
, PBM_SETPOS
, (WPARAM
) 0, 0);
127 SendMessage (ins_diskfull
, PBM_SETPOS
, (WPARAM
) 0, 0);
128 ShowWindow (ins_dialog
, SW_SHOWNORMAL
);
129 SetForegroundWindow (ins_dialog
);
137 if (package_bytes
> 100)
139 perc
= bytes
/ (package_bytes
/ 100);
140 SendMessage (ins_pprogress
, PBM_SETPOS
, (WPARAM
) perc
, 0);
143 if (total_bytes
> 100)
145 perc
= (total_bytes_sofar
+ bytes
) / (total_bytes
/ 100);
146 SendMessage (ins_iprogress
, PBM_SETPOS
, (WPARAM
) perc
, 0);
149 int df
= diskfull (root_dir
);
150 SendMessage (ins_diskfull
, PBM_SETPOS
, (WPARAM
) df
, 0);
154 badrename (char *o
, char *n
)
157 char *err
= strerror (errno
);
159 err
= "(unknown error)";
160 note (IDS_ERR_RENAME
, o
, n
, err
);
163 static char *standard_dirs
[] = {
179 #define pi (package[i].info[package[i].trust])
181 #define LOOP_PACKAGES \
182 for (i=0; i<npackages; i++) \
183 if (package[i].action == ACTION_NEW \
184 || package[i].action == ACTION_UPGRADE)
187 do_install (HINSTANCE h
)
189 int i
, num_installs
= 0;
192 mkdir_p (1, root_dir
);
194 for (i
=0; standard_dirs
[i
]; i
++)
196 char *p
= concat (root_dir
, standard_dirs
[i
], 0);
201 /* Create /var/run/utmp */
202 char *utmp
= concat (root_dir
, "/var/run/utmp", 0);
203 FILE *ufp
= fopen (utmp
, "wb");
208 dismiss_url_status_dialog ();
213 total_bytes_sofar
= 0;
217 total_bytes
+= pi
.install_size
;
222 char *local
= pi
.install
, *cp
, *fn
, *base
;
225 for (cp
=pi
.install
; *cp
; cp
++)
226 if (*cp
== '/' || *cp
== '\\' || *cp
== ':')
228 SetWindowText (ins_pkgname
, base
);
230 gzFile lst
= gzopen (concat (root_dir
, "/etc/setup/",
231 package
[i
].name
, ".lst.gz", 0),
234 package_bytes
= pi
.install_size
;
237 while (fn
= tar_next_file ())
241 while (*fn
== '/' || *fn
== '\\')
245 gzprintf(lst
, "%s\n", fn
);
247 if (strncmp (fn
, "usr/bin/", 8) == 0)
248 dest_file
= concat(root_dir
, "/bin/", fn
+8, 0);
249 else if (strncmp (fn
, "usr/lib/", 8) == 0)
250 dest_file
= concat(root_dir
, "/lib/", fn
+8, 0);
252 dest_file
= concat(root_dir
, "/", fn
, 0);
254 SetWindowText (ins_filename
, dest_file
);
255 tar_read_file (dest_file
);
257 progress (tar_ftell ());
262 total_bytes_sofar
+= pi
.install_size
;
269 ShowWindow (ins_dialog
, SW_HIDE
);
271 if (num_installs
== 0)
273 note (IDS_NOTHING_INSTALLED
);
277 char *odbn
= concat (root_dir
, "/etc/setup/installed.db", 0);
278 char *ndbn
= concat (root_dir
, "/etc/setup/installed.db.new", 0);
279 char *sdbn
= concat (root_dir
, "/etc/setup/installed.db.old", 0);
283 FILE *odb
= fopen (odbn
, "rt");
284 FILE *ndb
= fopen (ndbn
, "wb");
288 char *err
= strerror (errno
);
290 err
= "(unknown error)";
291 fatal (IDS_ERR_OPEN_WRITE
, ndb
, err
);
296 char line
[1000], pkg
[1000];
298 while (fgets (line
, 1000, odb
))
301 sscanf(line
, "%s", pkg
);
304 if (strcmp (pkg
, package
[i
].name
) == 0)
317 fprintf (ndb
, "%s %s %d\n", package
[i
].name
,
318 pi
.install
, pi
.install_size
);
326 if (odb
&& rename (odbn
, sdbn
))
327 badrename (odbn
, sdbn
);
330 if (rename (ndbn
, odbn
))
331 badrename (ndbn
, odbn
);
334 remove_mount ("/usr");
335 remove_mount ("/usr/bin");
336 remove_mount ("/usr/lib");
337 remove_mount ("/var");
338 remove_mount ("/lib");
339 remove_mount ("/bin");
340 remove_mount ("/etc");
342 int istext
= (root_text
== IDC_ROOT_TEXT
) ? 1 : 0;
343 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
345 create_mount ("/", root_dir
, istext
, issystem
);
346 create_mount ("/usr/bin", concat (root_dir
, "/bin", 0), istext
, issystem
);
347 create_mount ("/usr/lib", concat (root_dir
, "/lib", 0), istext
, issystem
);
351 note (IDS_INSTALL_COMPLETE
);
This page took 0.050727 seconds and 5 git commands to generate.