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 manage all the desktop setup, such
17 as start menu, batch files, desktop icons, and shortcuts. Note
18 that unlike other do_* functions, this one is called directly from
22 static const char *cvsid
=
47 #include "package_db.h"
48 #include "package_meta.h"
49 #include "package_version.h"
53 static OSVERSIONINFO verinfo
;
55 /* Lines starting with '@' are conditionals - include 'N' for NT,
56 '5' for Win95, '8' for Win98, '*' for all, like this:
63 static const char *etc_profile
[] = {
64 "PATH=\"/usr/local/bin:/usr/bin:/bin:$PATH\"",
68 "# Set up USER's home directory",
69 "if [ -z \"$HOME\" ]; then",
70 " HOME=\"/home/$USER\"",
73 "if [ ! -d \"$HOME\" ]; then",
74 " mkdir -p \"$HOME\"",
79 "for i in /etc/profile.d/*.sh ; do",
80 " if [ -f $i ]; then",
85 "export MAKE_MODE=unix",
86 "export PS1='\\[\\033]0;\\w\\007",
87 "\\033[32m\\]\\u@\\h \\[\\033[33m\\w\\033[0m\\]",
94 #define COMMAND9XARGS "/E:4096 /c"
95 #define COMMAND9XEXE "\\command.com"
98 static char *iconname
;
101 make_link (const char *linkpath
, const char *title
, const char *target
)
103 char argbuf
[_MAX_PATH
];
104 char *fname
= concat (linkpath
, "/", title
, ".lnk", 0);
106 if (_access (fname
, 0) == 0)
107 return; /* already exists */
109 msg ("make_link %s, %s, %s\n", fname
, title
, target
);
115 /* If we are running Win9x, build a command line. */
116 if (verinfo
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
118 exepath
= concat (target
, 0);
119 sprintf (argbuf
, " ");
123 char windir
[MAX_PATH
];
125 GetWindowsDirectory (windir
, sizeof (windir
));
126 exepath
= concat (windir
, COMMAND9XEXE
, 0);
127 sprintf (argbuf
, "%s %s", COMMAND9XARGS
, target
);
130 msg ("make_link_2 (%s, %s, %s, %s)", exepath
, argbuf
, iconname
, fname
);
131 make_link_2 (exepath
, argbuf
, iconname
, fname
);
135 start_menu (const char *title
, const char *target
)
137 char path
[_MAX_PATH
];
139 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
140 SHGetSpecialFolderLocation (NULL
,
141 issystem
? CSIDL_COMMON_PROGRAMS
:
142 CSIDL_PROGRAMS
, &id
);
143 SHGetPathFromIDList (id
, path
);
144 // following lines added because it appears Win95 does not use common programs
145 // unless it comes into play when multiple users for Win95 is enabled
146 msg ("Program directory for program link: %s", path
);
147 if (strlen (path
) == 0)
149 SHGetSpecialFolderLocation (NULL
, CSIDL_PROGRAMS
, &id
);
150 SHGetPathFromIDList (id
, path
);
151 msg ("Program directory for program link changed to: %s", path
);
153 // end of Win95 addition
154 strcat (path
, "/Cygwin");
155 make_link (path
, title
, target
);
159 desktop_icon (const char *title
, const char *target
)
161 char path
[_MAX_PATH
];
163 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
164 //SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_DESKTOP : CSIDL_COMMON_DESKTOPDIRECTORY, &id);
165 SHGetSpecialFolderLocation (NULL
,
166 issystem
? CSIDL_COMMON_DESKTOPDIRECTORY
:
167 CSIDL_DESKTOPDIRECTORY
, &id
);
168 SHGetPathFromIDList (id
, path
);
169 // following lines added because it appears Win95 does not use common programs
170 // unless it comes into play when multiple users for Win95 is enabled
171 msg ("Desktop directory for desktop link: %s", path
);
172 if (strlen (path
) == 0)
174 SHGetSpecialFolderLocation (NULL
, CSIDL_DESKTOPDIRECTORY
, &id
);
175 SHGetPathFromIDList (id
, path
);
176 msg ("Desktop directory for deskop link changed to: %s", path
);
178 // end of Win95 addition
179 make_link (path
, title
, target
);
185 batname
= backslash (cygpath ("/cygwin.bat", 0));
187 /* if the batch file exists, don't overwrite it */
188 if (_access (batname
, 0) == 0)
191 FILE *bat
= fopen (batname
, "wt");
195 fprintf (bat
, "@echo off\n\n");
197 fprintf (bat
, "%.2s\n", get_root_dir ());
198 fprintf (bat
, "chdir %s\n\n",
199 backslash (concat (get_root_dir () + 2, "/bin", 0)));
201 fprintf (bat
, "bash --login -i\n");
209 char *fname
= cygpath ("/etc/profile", 0);
211 /* if the file exists, don't overwrite it */
212 if (_access (fname
, 0) == 0)
216 switch (verinfo
.dwPlatformId
)
218 case VER_PLATFORM_WIN32_NT
:
221 case VER_PLATFORM_WIN32_WINDOWS
:
222 if (verinfo
.dwMinorVersion
== 0)
231 msg ("os is %c", os
);
233 FILE *p
= fopen (fname
, "wb");
238 for (i
= 0; etc_profile
[i
]; i
++)
240 if (etc_profile
[i
][0] == '@')
243 msg ("profile: %s", etc_profile
[i
]);
244 for (const char *cp
= etc_profile
[i
] + 1; *cp
; cp
++)
245 if (*cp
== os
|| *cp
== '*')
247 msg ("allow is %d\n", allow
);
250 fprintf (p
, "%s\n", etc_profile
[i
]);
257 uexists (const char *path
)
259 char *f
= cygpath (path
, 0);
260 int a
= _access (f
, 0);
270 char *fname
= cygpath ("/etc/postinstall/passwd-grp.bat", 0);
273 FILE *p
= fopen (fname
, "wt");
276 if (verinfo
.dwPlatformId
!= VER_PLATFORM_WIN32_NT
)
279 packagemeta
*pkg
= db
.packages
.getbykey ("cygwin");
280 if (pkg
&& pkg
->installed
)
282 /* mkpasswd and mkgroup are not working on 9x/ME up to 1.1.5-4 */
283 char *border_version
= canonicalize_version ("1.1.5-4");
285 canonicalize_version (pkg
->installed
->Canonical_version ());
286 if (strcmp (inst_version
, border_version
) <= 0)
291 if (uexists ("/etc/passwd") && uexists ("/etc/group"))
294 if (!uexists ("/etc/passwd"))
295 fprintf (p
, "bin\\mkpasswd -l > etc\\passwd\n");
296 if (!uexists ("/etc/group"))
297 fprintf (p
, "bin\\mkgroup -l > etc\\group\n");
306 iconname
= backslash (cygpath ("/cygwin.ico", 0));
308 HRSRC rsrc
= FindResource (NULL
, "CYGWIN.ICON", "FILE");
311 fatal ("FindResource failed");
313 HGLOBAL res
= LoadResource (NULL
, rsrc
);
314 char *data
= (char *) LockResource (res
);
315 int len
= SizeofResource (NULL
, rsrc
);
317 FILE *f
= fopen (iconname
, "wb");
320 fwrite (data
, 1, len
, f
);
332 make_passwd_group ();
336 start_menu ("Cygwin Bash Shell", batname
);
341 desktop_icon ("Cygwin", batname
);
345 static int da
[] = { IDC_ROOT_DESKTOP
, 0 };
346 static int ma
[] = { IDC_ROOT_MENU
, 0 };
349 check_if_enable_next (HWND h
)
351 EnableWindow (GetDlgItem (h
, IDOK
), 1);
357 rbset (h
, da
, root_desktop
);
358 rbset (h
, ma
, root_menu
);
359 check_if_enable_next (h
);
363 check_desktop (const char *title
, const char *target
)
365 char path
[_MAX_PATH
];
367 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
368 SHGetSpecialFolderLocation (NULL
,
369 issystem
? CSIDL_COMMON_DESKTOPDIRECTORY
:
370 CSIDL_DESKTOPDIRECTORY
, &id
);
371 SHGetPathFromIDList (id
, path
);
372 // following lines added because it appears Win95 does not use common programs
373 // unless it comes into play when multiple users for Win95 is enabled
374 msg ("Desktop directory for desktop link: %s", path
);
375 if (strlen (path
) == 0)
377 SHGetSpecialFolderLocation (NULL
, CSIDL_DESKTOPDIRECTORY
, &id
);
378 SHGetPathFromIDList (id
, path
);
379 msg ("Desktop directory for deskop link changed to: %s", path
);
381 // end of Win95 addition
382 char *fname
= concat (path
, "/", title
, ".lnk", 0);
384 if (_access (fname
, 0) == 0)
385 return 0; /* already exists */
387 fname
= concat (path
, "/", title
, ".pif", 0); /* check for a pif as well */
389 if (_access (fname
, 0) == 0)
390 return 0; /* already exists */
392 return IDC_ROOT_DESKTOP
;
396 check_startmenu (const char *title
, const char *target
)
398 char path
[_MAX_PATH
];
400 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
401 SHGetSpecialFolderLocation (NULL
,
402 issystem
? CSIDL_COMMON_PROGRAMS
:
403 CSIDL_PROGRAMS
, &id
);
404 SHGetPathFromIDList (id
, path
);
405 // following lines added because it appears Win95 does not use common programs
406 // unless it comes into play when multiple users for Win95 is enabled
407 msg ("Program directory for program link: %s", path
);
408 if (strlen (path
) == 0)
410 SHGetSpecialFolderLocation (NULL
, CSIDL_PROGRAMS
, &id
);
411 SHGetPathFromIDList (id
, path
);
412 msg ("Program directory for program link changed to: %s", path
);
414 // end of Win95 addition
415 strcat (path
, "/Cygwin");
416 char *fname
= concat (path
, "/", title
, ".lnk", 0);
418 if (_access (fname
, 0) == 0)
419 return 0; /* already exists */
421 fname
= concat (path
, "/", title
, ".pif", 0); /* check for a pif as well */
423 if (_access (fname
, 0) == 0)
424 return 0; /* already exists */
426 return IDC_ROOT_MENU
;
432 root_desktop
= rbget (h
, da
);
433 root_menu
= rbget (h
, ma
);
437 dialog_cmd (HWND h
, int id
, HWND hwndctl
, UINT code
)
442 case IDC_ROOT_DESKTOP
:
445 check_if_enable_next (h
);
452 DesktopSetupPage::Create ()
454 return PropertyPage::Create (NULL
, dialog_cmd
, IDD_DESKTOP
);
458 DesktopSetupPage::OnInit ()
460 // FIXME: This CoInitialize() feels like it could be moved to startup in main.cc.
462 verinfo
.dwOSVersionInfoSize
= sizeof (verinfo
);
463 GetVersionEx (&verinfo
);
465 check_desktop ("Cygwin", backslash (cygpath ("/cygwin.bat", 0)));
467 check_startmenu ("Cygwin Bash Shell",
468 backslash (cygpath ("/cygwin.bat", 0)));
469 load_dialog (GetHWND ());
473 DesktopSetupPage::OnBack ()
482 DesktopSetupPage::OnFinish ()
487 NEXT (IDD_S_POSTINSTALL
);
488 do_postinstall (GetInstance (), h
);