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
=
45 #include "package_db.h"
46 #include "package_meta.h"
47 #include "package_version.h"
49 #include "filemanip.h"
51 #include "io_stream.h"
54 #include "getopt++/BoolOption.h"
56 static BoolOption
NoShortcutsOption (false, 'n', "no-shortcuts", "Disable creation of desktop and start menu shortcuts");
58 static OSVERSIONINFO verinfo
;
60 /* Lines starting with '@' are conditionals - include 'N' for NT,
61 '5' for Win95, '8' for Win98, '*' for all, like this:
68 static const char *etc_profile
[] = {
69 "PATH=\"/usr/local/bin:/usr/bin:/bin:$PATH\"",
73 "# Set up USER's home directory",
74 "if [ -z \"$HOME\" ]; then",
75 " HOME=\"/home/$USER\"",
78 "if [ ! -d \"$HOME\" ]; then",
79 " mkdir -p \"$HOME\"",
84 "for i in /etc/profile.d/*.sh ; do",
85 " if [ -f $i ]; then",
90 "export MAKE_MODE=unix",
91 "export PS1='\\[\\033]0;\\w\\007",
92 "\\033[32m\\]\\u@\\h \\[\\033[33m\\w\\033[0m\\]",
99 #define COMMAND9XARGS String("/E:4096 /c")
100 #define COMMAND9XEXE String("\\command.com")
102 static String batname
;
103 static String iconname
;
106 make_link (String
const &linkpath
, String
const &title
, String
const &target
)
108 String fname
= linkpath
+ "/" + title
+ ".lnk";
110 if (_access (fname
.cstr_oneuse(), 0) == 0)
111 return; /* already exists */
113 msg ("make_link %s, %s, %s\n",
114 fname
.cstr_oneuse(), title
.cstr_oneuse(), target
.cstr_oneuse());
116 io_stream::mkpath_p (PATH_TO_FILE
, String ("file://") + fname
);
121 /* If we are running Win9x, build a command line. */
122 if (verinfo
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
126 // sprintf (argbuf, " ");
130 char windir
[MAX_PATH
];
132 GetWindowsDirectory (windir
, sizeof (windir
));
133 exepath
= String(windir
) + COMMAND9XEXE
;
134 argbuf
= COMMAND9XARGS
+ " " + target
;
135 // sprintf (argbuf, "%s %s", COMMAND9XARGS, target.cstr_oneuse());
138 msg ("make_link_2 (%s, %s, %s, %s)",
139 exepath
.cstr_oneuse(), argbuf
.cstr_oneuse(),
140 iconname
.cstr_oneuse(), fname
.cstr_oneuse());
141 make_link_2 (exepath
.cstr_oneuse(), argbuf
.cstr_oneuse(),
142 iconname
.cstr_oneuse(), fname
.cstr_oneuse());
146 start_menu (String
const &title
, String
const &target
)
149 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
150 SHGetSpecialFolderLocation (NULL
,
151 issystem
? CSIDL_COMMON_PROGRAMS
:
152 CSIDL_PROGRAMS
, &id
);
153 char _path
[_MAX_PATH
];
154 SHGetPathFromIDList (id
, _path
);
156 // Win95 does not use common programs unless multiple users for Win95 is enabled
157 msg ("Program directory for program link: %s", path
.cstr_oneuse());
158 if (path
.size() == 0)
160 SHGetSpecialFolderLocation (NULL
, CSIDL_PROGRAMS
, &id
);
161 SHGetPathFromIDList (id
, _path
);
162 path
= String(_path
);
163 msg ("Program directory for program link changed to: %s",
166 // end of Win95 addition
168 make_link (path
, title
, target
);
172 desktop_icon (String
const &title
, String
const &target
)
174 char path
[_MAX_PATH
];
176 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
177 //SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_DESKTOP : CSIDL_COMMON_DESKTOPDIRECTORY, &id);
178 SHGetSpecialFolderLocation (NULL
,
179 issystem
? CSIDL_COMMON_DESKTOPDIRECTORY
:
180 CSIDL_DESKTOPDIRECTORY
, &id
);
181 SHGetPathFromIDList (id
, path
);
182 // following lines added because it appears Win95 does not use common programs
183 // unless it comes into play when multiple users for Win95 is enabled
184 msg ("Desktop directory for desktop link: %s", path
);
185 if (strlen (path
) == 0)
187 SHGetSpecialFolderLocation (NULL
, CSIDL_DESKTOPDIRECTORY
, &id
);
188 SHGetPathFromIDList (id
, path
);
189 msg ("Desktop directory for deskop link changed to: %s", path
);
191 // end of Win95 addition
192 make_link (path
, title
, target
);
198 batname
= backslash (cygpath ("/cygwin.bat"));
200 /* if the batch file exists, don't overwrite it */
201 if (_access (batname
.cstr_oneuse(), 0) == 0)
204 FILE *bat
= fopen (batname
.cstr_oneuse(), "wt");
208 fprintf (bat
, "@echo off\n\n");
210 fprintf (bat
, "%.2s\n", get_root_dir ().cstr_oneuse());
211 fprintf (bat
, "chdir %s\n\n",
212 backslash (get_root_dir () + "/bin").cstr_oneuse());
214 fprintf (bat
, "bash --login -i\n");
222 String fname
= cygpath ("/etc/profile");
224 /* if the file exists, don't overwrite it */
225 if (_access (fname
.cstr_oneuse(), 0) == 0)
229 switch (verinfo
.dwPlatformId
)
231 case VER_PLATFORM_WIN32_NT
:
234 case VER_PLATFORM_WIN32_WINDOWS
:
235 if (verinfo
.dwMinorVersion
== 0)
244 msg ("os is %c", os
);
246 FILE *p
= fopen (fname
.cstr_oneuse(), "wb");
251 for (i
= 0; etc_profile
[i
]; i
++)
253 if (etc_profile
[i
][0] == '@')
256 msg ("profile: %s", etc_profile
[i
]);
257 for (const char *cp
= etc_profile
[i
] + 1; *cp
; cp
++)
258 if (*cp
== os
|| *cp
== '*')
260 msg ("allow is %d\n", allow
);
263 fprintf (p
, "%s\n", etc_profile
[i
]);
270 uexists (const char *path
)
272 String f
= cygpath (path
);
273 int a
= _access (f
.cstr_oneuse(), 0);
282 String fname
= cygpath ("/etc/postinstall/passwd-grp.bat");
283 io_stream::mkpath_p (PATH_TO_FILE
, String("file://") + fname
);
285 if ((uexists ("/etc/passwd") || uexists ("/etc/passwd.lnk"))
286 && (uexists ("/etc/group") || uexists ("/etc/group.lnk")))
289 if (verinfo
.dwPlatformId
!= VER_PLATFORM_WIN32_NT
)
292 packagemeta
*pkg
= db
.packages
.getbykey ("cygwin");
293 if (pkg
&& pkg
->installed
)
295 /* mkpasswd and mkgroup are not working on 9x/ME up to 1.1.5-4 */
296 String border_version
= canonicalize_version ("1.1.5-4");
297 String inst_version
=
298 canonicalize_version (pkg
->installed
->Canonical_version ());
299 if (inst_version
.compare(border_version
) <= 0)
304 FILE *p
= fopen (fname
.cstr_oneuse(), "wt");
307 if (!(uexists ("/etc/passwd") || uexists ("/etc/passwd.lnk")))
308 fprintf (p
, "bin\\mkpasswd -l > etc\\passwd\n");
309 if (!(uexists ("/etc/group") || uexists ("/etc/group.lnk")))
310 fprintf (p
, "bin\\mkgroup -l > etc\\group\n");
317 iconname
= backslash (cygpath ("/cygwin.ico"));
319 HRSRC rsrc
= FindResource (NULL
, "CYGWIN.ICON", "FILE");
322 fatal ("FindResource failed");
324 HGLOBAL res
= LoadResource (NULL
, rsrc
);
325 char *data
= (char *) LockResource (res
);
326 int len
= SizeofResource (NULL
, rsrc
);
328 FILE *f
= fopen (iconname
.cstr_oneuse(), "wb");
331 fwrite (data
, 1, len
, f
);
343 make_passwd_group ();
347 start_menu ("Cygwin Bash Shell", batname
);
352 desktop_icon ("Cygwin", batname
);
356 static int da
[] = { IDC_ROOT_DESKTOP
, 0 };
357 static int ma
[] = { IDC_ROOT_MENU
, 0 };
360 check_if_enable_next (HWND h
)
362 EnableWindow (GetDlgItem (h
, IDOK
), 1);
368 rbset (h
, da
, root_desktop
);
369 rbset (h
, ma
, root_menu
);
370 check_if_enable_next (h
);
374 check_desktop (String
const title
, String
const target
)
376 char path
[_MAX_PATH
];
378 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
379 SHGetSpecialFolderLocation (NULL
,
380 issystem
? CSIDL_COMMON_DESKTOPDIRECTORY
:
381 CSIDL_DESKTOPDIRECTORY
, &id
);
382 SHGetPathFromIDList (id
, path
);
383 // following lines added because it appears Win95 does not use common programs
384 // unless it comes into play when multiple users for Win95 is enabled
385 msg ("Desktop directory for desktop link: %s", path
);
386 if (strlen (path
) == 0)
388 SHGetSpecialFolderLocation (NULL
, CSIDL_DESKTOPDIRECTORY
, &id
);
389 SHGetPathFromIDList (id
, path
);
390 msg ("Desktop directory for deskop link changed to: %s", path
);
392 // end of Win95 addition
393 String fname
= String (path
) + "/" + title
+ ".lnk";
395 if (_access (fname
.cstr_oneuse(), 0) == 0)
396 return 0; /* already exists */
398 fname
= String (path
) + "/" + title
+ ".pif"; /* check for a pif as well */
400 if (_access (fname
.cstr_oneuse(), 0) == 0)
401 return 0; /* already exists */
403 return IDC_ROOT_DESKTOP
;
407 check_startmenu (String
const title
, String
const target
)
409 char path
[_MAX_PATH
];
411 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
412 SHGetSpecialFolderLocation (NULL
,
413 issystem
? CSIDL_COMMON_PROGRAMS
:
414 CSIDL_PROGRAMS
, &id
);
415 SHGetPathFromIDList (id
, path
);
416 // following lines added because it appears Win95 does not use common programs
417 // unless it comes into play when multiple users for Win95 is enabled
418 msg ("Program directory for program link: %s", path
);
419 if (strlen (path
) == 0)
421 SHGetSpecialFolderLocation (NULL
, CSIDL_PROGRAMS
, &id
);
422 SHGetPathFromIDList (id
, path
);
423 msg ("Program directory for program link changed to: %s", path
);
425 // end of Win95 addition
426 strcat (path
, "/Cygwin");
427 String fname
= String (path
) + "/" + title
+ ".lnk";
429 if (_access (fname
.cstr_oneuse(), 0) == 0)
430 return 0; /* already exists */
432 fname
= String (path
) + "/" + title
+ ".pif"; /* check for a pif as well */
434 if (_access (fname
.cstr_oneuse(), 0) == 0)
435 return 0; /* already exists */
437 return IDC_ROOT_MENU
;
443 root_desktop
= rbget (h
, da
);
444 root_menu
= rbget (h
, ma
);
448 dialog_cmd (HWND h
, int id
, HWND hwndctl
, UINT code
)
453 case IDC_ROOT_DESKTOP
:
456 check_if_enable_next (h
);
463 DesktopSetupPage::Create ()
465 return PropertyPage::Create (NULL
, dialog_cmd
, IDD_DESKTOP
);
469 DesktopSetupPage::OnInit ()
471 // FIXME: This CoInitialize() feels like it could be moved to startup in main.cc.
473 verinfo
.dwOSVersionInfoSize
= sizeof (verinfo
);
474 GetVersionEx (&verinfo
);
476 check_desktop ("Cygwin", backslash (cygpath ("/cygwin.bat")));
478 check_startmenu ("Cygwin Bash Shell",
479 backslash (cygpath ("/cygwin.bat")));
480 if (NoShortcutsOption
)
487 load_dialog (GetHWND ());
491 DesktopSetupPage::OnBack ()
500 DesktopSetupPage::OnFinish ()
505 NEXT (IDD_S_POSTINSTALL
);
506 do_postinstall (GetInstance (), h
);