]>
cygwin.com Git - cygwin-apps/setup.git/blob - install.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 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. */
22 static char *cvsid
= "\n%%% $Id$\n";
29 #include <sys/types.h>
32 #include "zlib/zlib.h"
46 static HWND ins_dialog
= 0;
47 static HWND ins_pkgname
= 0;
48 static HWND ins_filename
= 0;
49 static HWND ins_pprogress
= 0;
50 static HWND ins_iprogress
= 0;
51 static HWND ins_diskfull
= 0;
52 static HANDLE init_event
;
54 static int total_bytes
= 0;
55 static int total_bytes_sofar
= 0;
56 static int package_bytes
= 0;
59 dialog_cmd (HWND h
, int id
, HWND hwndctl
, UINT code
)
69 dialog_proc (HWND h
, UINT message
, WPARAM wParam
, LPARAM lParam
)
77 ins_pkgname
= GetDlgItem (h
, IDC_INS_PKG
);
78 ins_filename
= GetDlgItem (h
, IDC_INS_FILE
);
79 ins_pprogress
= GetDlgItem (h
, IDC_INS_PPROGRESS
);
80 ins_iprogress
= GetDlgItem (h
, IDC_INS_IPROGRESS
);
81 ins_diskfull
= GetDlgItem (h
, IDC_INS_DISKFULL
);
82 SetEvent (init_event
);
85 return HANDLE_WM_COMMAND (h
, wParam
, lParam
, dialog_cmd
);
95 HANDLE ins_dialog
= CreateDialog (hinstance
, MAKEINTRESOURCE (IDD_INSTATUS
),
98 fatal ("create dialog");
99 ShowWindow (ins_dialog
, SW_SHOWNORMAL
);
100 UpdateWindow (ins_dialog
);
101 while (GetMessage (&m
, 0, 0, 0) > 0) {
102 TranslateMessage (&m
);
103 DispatchMessage (&m
);
107 static DWORD start_tics
;
116 init_event
= CreateEvent (0, 0, 0, 0);
117 thread
= CreateThread (0, 0, dialog
, 0, 0, &tid
);
118 WaitForSingleObject (init_event
, 10000);
119 CloseHandle (init_event
);
120 SendMessage (ins_pprogress
, PBM_SETRANGE
, 0, MAKELPARAM (0, 100));
121 SendMessage (ins_iprogress
, PBM_SETRANGE
, 0, MAKELPARAM (0, 100));
122 SendMessage (ins_diskfull
, PBM_SETRANGE
, 0, MAKELPARAM (0, 100));
125 SetWindowText (ins_pkgname
, "");
126 SetWindowText (ins_filename
, "");
127 SendMessage (ins_pprogress
, PBM_SETPOS
, (WPARAM
) 0, 0);
128 SendMessage (ins_iprogress
, PBM_SETPOS
, (WPARAM
) 0, 0);
129 SendMessage (ins_diskfull
, PBM_SETPOS
, (WPARAM
) 0, 0);
130 ShowWindow (ins_dialog
, SW_SHOWNORMAL
);
131 SetForegroundWindow (ins_dialog
);
139 if (package_bytes
> 100)
141 perc
= bytes
/ (package_bytes
/ 100);
142 SendMessage (ins_pprogress
, PBM_SETPOS
, (WPARAM
) perc
, 0);
145 if (total_bytes
> 100)
147 perc
= (total_bytes_sofar
+ bytes
) / (total_bytes
/ 100);
148 SendMessage (ins_iprogress
, PBM_SETPOS
, (WPARAM
) perc
, 0);
151 int df
= diskfull (root_dir
);
152 SendMessage (ins_diskfull
, PBM_SETPOS
, (WPARAM
) df
, 0);
156 badrename (char *o
, char *n
)
159 char *err
= strerror (errno
);
161 err
= "(unknown error)";
162 note (IDS_ERR_RENAME
, o
, n
, err
);
165 static char *standard_dirs
[] = {
181 #define pi (package[i].info[package[i].trust])
183 #define LOOP_PACKAGES \
184 for (i=0; i<npackages; i++) \
185 if ((package[i].action == ACTION_NEW \
186 || package[i].action == ACTION_UPGRADE) \
190 do_install (HINSTANCE h
)
192 int i
, num_installs
= 0;
193 next_dialog
= IDD_S_DESKTOP
;
195 mkdir_p (1, root_dir
);
197 for (i
=0; standard_dirs
[i
]; i
++)
199 char *p
= concat (root_dir
, standard_dirs
[i
], 0);
204 /* Create /var/run/utmp */
205 char *utmp
= concat (root_dir
, "/var/run/utmp", 0);
206 FILE *ufp
= fopen (utmp
, "wb");
211 dismiss_url_status_dialog ();
216 total_bytes_sofar
= 0;
220 total_bytes
+= pi
.install_size
;
225 char *local
= pi
.install
, *cp
, *fn
, *base
;
228 for (cp
=pi
.install
; *cp
; cp
++)
229 if (*cp
== '/' || *cp
== '\\' || *cp
== ':')
231 SetWindowText (ins_pkgname
, base
);
233 gzFile lst
= gzopen (concat (root_dir
, "/etc/setup/",
234 package
[i
].name
, ".lst.gz", 0),
237 package_bytes
= pi
.install_size
;
240 while (fn
= tar_next_file ())
244 while (*fn
== '/' || *fn
== '\\')
248 gzprintf (lst
, "%s\n", fn
);
250 if (strncmp (fn
, "usr/bin/", 8) == 0)
251 dest_file
= concat (root_dir
, "/bin/", fn
+8, 0);
252 else if (strncmp (fn
, "usr/lib/", 8) == 0)
253 dest_file
= concat (root_dir
, "/lib/", fn
+8, 0);
255 dest_file
= concat (root_dir
, "/", fn
, 0);
257 SetWindowText (ins_filename
, dest_file
);
258 tar_read_file (dest_file
);
260 progress (tar_ftell ());
265 total_bytes_sofar
+= pi
.install_size
;
272 ShowWindow (ins_dialog
, SW_HIDE
);
274 if (num_installs
== 0)
276 exit_msg
= IDS_NOTHING_INSTALLED
;
280 char *odbn
= concat (root_dir
, "/etc/setup/installed.db", 0);
281 char *ndbn
= concat (root_dir
, "/etc/setup/installed.db.new", 0);
282 char *sdbn
= concat (root_dir
, "/etc/setup/installed.db.old", 0);
286 FILE *odb
= fopen (odbn
, "rt");
287 FILE *ndb
= fopen (ndbn
, "wb");
291 char *err
= strerror (errno
);
293 err
= "(unknown error)";
294 fatal (IDS_ERR_OPEN_WRITE
, ndb
, err
);
299 char line
[1000], pkg
[1000];
301 while (fgets (line
, 1000, odb
))
304 sscanf (line
, "%s", pkg
);
307 if (strcmp (pkg
, package
[i
].name
) == 0)
320 fprintf (ndb
, "%s %s %d\n", package
[i
].name
,
321 pi
.install
, pi
.install_size
);
329 if (odb
&& rename (odbn
, sdbn
))
330 badrename (odbn
, sdbn
);
333 if (rename (ndbn
, odbn
))
334 badrename (ndbn
, odbn
);
337 remove_mount ("/usr");
338 remove_mount ("/usr/bin");
339 remove_mount ("/usr/lib");
340 remove_mount ("/var");
341 remove_mount ("/lib");
342 remove_mount ("/bin");
343 remove_mount ("/etc");
345 int istext
= (root_text
== IDC_ROOT_TEXT
) ? 1 : 0;
346 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
348 create_mount ("/", root_dir
, istext
, issystem
);
349 create_mount ("/usr/bin", concat (root_dir
, "/bin", 0), istext
, issystem
);
350 create_mount ("/usr/lib", concat (root_dir
, "/lib", 0), istext
, issystem
);
352 exit_msg
= IDS_INSTALL_COMPLETE
;
This page took 0.054018 seconds and 6 git commands to generate.