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
=
29 #include "propsheet.h"
46 #include "package_db.h"
47 #include "package_meta.h"
48 #include "package_version.h"
50 #include "filemanip.h"
52 #include "io_stream.h"
54 #include "getopt++/BoolOption.h"
56 #include "PackageSpecification.h"
58 static BoolOption
NoShortcutsOption (false, 'n', "no-shortcuts", "Disable creation of desktop and start menu shortcuts");
59 static BoolOption
NoStartMenuOption (false, 'N', "no-startmenu", "Disable creation of start menu shortcut");
60 static BoolOption
NoDesktopOption (false, 'd', "no-desktop", "Disable creation of desktop shortcut");
62 static OSVERSIONINFO verinfo
;
64 /* Lines starting with '@' are conditionals - include 'N' for NT,
65 '5' for Win95, '8' for Win98, '*' for all, like this:
72 static const char *etc_profile
[] = {
73 "PATH=\"/usr/local/bin:/usr/bin:/bin:$PATH\"",
77 "# Set up USER's home directory",
78 "if [ -z \"$HOME\" ]; then",
79 " HOME=\"/home/$USER\"",
82 "if [ ! -d \"$HOME\" ]; then",
83 " mkdir -p \"$HOME\"",
88 "for i in /etc/profile.d/*.sh ; do",
89 " if [ -f $i ]; then",
94 "export MAKE_MODE=unix",
95 "export PS1='\\[\\033]0;\\w\\007",
96 "\\033[32m\\]\\u@\\h \\[\\033[33m\\w\\033[0m\\]",
103 #define COMMAND9XARGS String("/E:4096 /c")
104 #define COMMAND9XEXE String("\\command.com")
106 static String batname
;
107 static String iconname
;
110 make_link (String
const &linkpath
, String
const &title
, String
const &target
)
112 String fname
= linkpath
+ "/" + title
+ ".lnk";
114 if (_access (fname
.cstr_oneuse(), 0) == 0)
115 return; /* already exists */
117 msg ("make_link %s, %s, %s\n",
118 fname
.cstr_oneuse(), title
.cstr_oneuse(), target
.cstr_oneuse());
120 io_stream::mkpath_p (PATH_TO_FILE
, String ("file://") + fname
);
125 /* If we are running Win9x, build a command line. */
126 if (verinfo
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
130 // sprintf (argbuf, " ");
134 char windir
[MAX_PATH
];
136 GetWindowsDirectory (windir
, sizeof (windir
));
137 exepath
= String(windir
) + COMMAND9XEXE
;
138 argbuf
= COMMAND9XARGS
+ " " + target
;
139 // sprintf (argbuf, "%s %s", COMMAND9XARGS, target.cstr_oneuse());
142 msg ("make_link_2 (%s, %s, %s, %s)",
143 exepath
.cstr_oneuse(), argbuf
.cstr_oneuse(),
144 iconname
.cstr_oneuse(), fname
.cstr_oneuse());
145 make_link_2 (exepath
.cstr_oneuse(), argbuf
.cstr_oneuse(),
146 iconname
.cstr_oneuse(), fname
.cstr_oneuse());
150 start_menu (String
const &title
, String
const &target
)
153 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
154 SHGetSpecialFolderLocation (NULL
,
155 issystem
? CSIDL_COMMON_PROGRAMS
:
156 CSIDL_PROGRAMS
, &id
);
157 char _path
[_MAX_PATH
];
158 SHGetPathFromIDList (id
, _path
);
160 // Win95 does not use common programs unless multiple users for Win95 is enabled
161 msg ("Program directory for program link: %s", path
.cstr_oneuse());
162 if (path
.size() == 0)
164 SHGetSpecialFolderLocation (NULL
, CSIDL_PROGRAMS
, &id
);
165 SHGetPathFromIDList (id
, _path
);
166 path
= String(_path
);
167 msg ("Program directory for program link changed to: %s",
170 // end of Win95 addition
172 make_link (path
, title
, target
);
176 desktop_icon (String
const &title
, String
const &target
)
178 char path
[_MAX_PATH
];
180 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
181 //SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_DESKTOP : CSIDL_COMMON_DESKTOPDIRECTORY, &id);
182 SHGetSpecialFolderLocation (NULL
,
183 issystem
? CSIDL_COMMON_DESKTOPDIRECTORY
:
184 CSIDL_DESKTOPDIRECTORY
, &id
);
185 SHGetPathFromIDList (id
, path
);
186 // following lines added because it appears Win95 does not use common programs
187 // unless it comes into play when multiple users for Win95 is enabled
188 msg ("Desktop directory for desktop link: %s", path
);
189 if (strlen (path
) == 0)
191 SHGetSpecialFolderLocation (NULL
, CSIDL_DESKTOPDIRECTORY
, &id
);
192 SHGetPathFromIDList (id
, path
);
193 msg ("Desktop directory for deskop link changed to: %s", path
);
195 // end of Win95 addition
196 make_link (path
, title
, target
);
202 batname
= backslash (cygpath ("/cygwin.bat"));
204 /* if the batch file exists, don't overwrite it */
205 if (_access (batname
.cstr_oneuse(), 0) == 0)
208 FILE *bat
= fopen (batname
.cstr_oneuse(), "wt");
212 fprintf (bat
, "@echo off\n\n");
214 fprintf (bat
, "%.2s\n", get_root_dir ().cstr_oneuse());
215 fprintf (bat
, "chdir %s\n\n",
216 backslash (get_root_dir () + "/bin").cstr_oneuse());
218 fprintf (bat
, "bash --login -i\n");
226 String fname
= cygpath ("/etc/profile");
228 /* if the file exists, don't overwrite it */
229 if (_access (fname
.cstr_oneuse(), 0) == 0)
233 switch (verinfo
.dwPlatformId
)
235 case VER_PLATFORM_WIN32_NT
:
238 case VER_PLATFORM_WIN32_WINDOWS
:
239 if (verinfo
.dwMinorVersion
== 0)
248 msg ("os is %c", os
);
250 FILE *p
= fopen (fname
.cstr_oneuse(), "wb");
255 for (i
= 0; etc_profile
[i
]; i
++)
257 if (etc_profile
[i
][0] == '@')
260 msg ("profile: %s", etc_profile
[i
]);
261 for (const char *cp
= etc_profile
[i
] + 1; *cp
; cp
++)
262 if (*cp
== os
|| *cp
== '*')
264 msg ("allow is %d\n", allow
);
267 fprintf (p
, "%s\n", etc_profile
[i
]);
274 uexists (const char *path
)
276 String f
= cygpath (path
);
277 int a
= _access (f
.cstr_oneuse(), 0);
286 String fname
= cygpath ("/etc/postinstall/passwd-grp.bat");
287 io_stream::mkpath_p (PATH_TO_FILE
, String("file://") + fname
);
289 if ((uexists ("/etc/passwd") || uexists ("/etc/passwd.lnk"))
290 && (uexists ("/etc/group") || uexists ("/etc/group.lnk")))
293 if (verinfo
.dwPlatformId
!= VER_PLATFORM_WIN32_NT
)
296 packagemeta
*pkg
= db
.findBinary (PackageSpecification("cygwin"));
297 if (pkg
&& pkg
->installed
)
299 /* mkpasswd and mkgroup are not working on 9x/ME up to 1.1.5-4 */
300 String border_version
= canonicalize_version ("1.1.5-4");
301 String inst_version
=
302 canonicalize_version (pkg
->installed
.Canonical_version ());
303 if (inst_version
.compare(border_version
) <= 0)
308 FILE *p
= fopen (fname
.cstr_oneuse(), "wt");
311 if (!(uexists ("/etc/passwd") || uexists ("/etc/passwd.lnk")))
312 fprintf (p
, "bin\\mkpasswd -l > etc\\passwd\n");
313 if (!(uexists ("/etc/group") || uexists ("/etc/group.lnk")))
314 fprintf (p
, "bin\\mkgroup -l > etc\\group\n");
321 iconname
= backslash (cygpath ("/cygwin.ico"));
323 HRSRC rsrc
= FindResource (NULL
, "CYGWIN.ICON", "FILE");
326 fatal ("FindResource failed");
328 HGLOBAL res
= LoadResource (NULL
, rsrc
);
329 char *data
= (char *) LockResource (res
);
330 int len
= SizeofResource (NULL
, rsrc
);
332 FILE *f
= fopen (iconname
.cstr_oneuse(), "wb");
335 fwrite (data
, 1, len
, f
);
347 make_passwd_group ();
351 start_menu ("Cygwin Bash Shell", batname
);
356 desktop_icon ("Cygwin", batname
);
360 static int da
[] = { IDC_ROOT_DESKTOP
, 0 };
361 static int ma
[] = { IDC_ROOT_MENU
, 0 };
364 check_if_enable_next (HWND h
)
366 EnableWindow (GetDlgItem (h
, IDOK
), 1);
372 rbset (h
, da
, root_desktop
);
373 rbset (h
, ma
, root_menu
);
374 check_if_enable_next (h
);
378 check_desktop (String
const title
, String
const target
)
380 char path
[_MAX_PATH
];
382 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
383 SHGetSpecialFolderLocation (NULL
,
384 issystem
? CSIDL_COMMON_DESKTOPDIRECTORY
:
385 CSIDL_DESKTOPDIRECTORY
, &id
);
386 SHGetPathFromIDList (id
, path
);
387 // following lines added because it appears Win95 does not use common programs
388 // unless it comes into play when multiple users for Win95 is enabled
389 msg ("Desktop directory for desktop link: %s", path
);
390 if (strlen (path
) == 0)
392 SHGetSpecialFolderLocation (NULL
, CSIDL_DESKTOPDIRECTORY
, &id
);
393 SHGetPathFromIDList (id
, path
);
394 msg ("Desktop directory for deskop link changed to: %s", path
);
396 // end of Win95 addition
397 String fname
= String (path
) + "/" + title
+ ".lnk";
399 if (_access (fname
.cstr_oneuse(), 0) == 0)
400 return 0; /* already exists */
402 fname
= String (path
) + "/" + title
+ ".pif"; /* check for a pif as well */
404 if (_access (fname
.cstr_oneuse(), 0) == 0)
405 return 0; /* already exists */
407 return IDC_ROOT_DESKTOP
;
411 check_startmenu (String
const title
, String
const target
)
413 char path
[_MAX_PATH
];
415 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
416 SHGetSpecialFolderLocation (NULL
,
417 issystem
? CSIDL_COMMON_PROGRAMS
:
418 CSIDL_PROGRAMS
, &id
);
419 SHGetPathFromIDList (id
, path
);
420 // following lines added because it appears Win95 does not use common programs
421 // unless it comes into play when multiple users for Win95 is enabled
422 msg ("Program directory for program link: %s", path
);
423 if (strlen (path
) == 0)
425 SHGetSpecialFolderLocation (NULL
, CSIDL_PROGRAMS
, &id
);
426 SHGetPathFromIDList (id
, path
);
427 msg ("Program directory for program link changed to: %s", path
);
429 // end of Win95 addition
430 strcat (path
, "/Cygwin");
431 String fname
= String (path
) + "/" + title
+ ".lnk";
433 if (_access (fname
.cstr_oneuse(), 0) == 0)
434 return 0; /* already exists */
436 fname
= String (path
) + "/" + title
+ ".pif"; /* check for a pif as well */
438 if (_access (fname
.cstr_oneuse(), 0) == 0)
439 return 0; /* already exists */
441 return IDC_ROOT_MENU
;
447 root_desktop
= rbget (h
, da
);
448 root_menu
= rbget (h
, ma
);
452 dialog_cmd (HWND h
, int id
, HWND hwndctl
, UINT code
)
457 case IDC_ROOT_DESKTOP
:
460 check_if_enable_next (h
);
467 DesktopSetupPage::Create ()
469 return PropertyPage::Create (NULL
, dialog_cmd
, IDD_DESKTOP
);
473 DesktopSetupPage::OnInit ()
475 // FIXME: This CoInitialize() feels like it could be moved to startup in main.cc.
477 verinfo
.dwOSVersionInfoSize
= sizeof (verinfo
);
478 GetVersionEx (&verinfo
);
480 if (NoShortcutsOption
)
482 root_desktop
= root_menu
= 0;
486 if (NoStartMenuOption
)
489 MessageBox(NULL
, "NoStartMenuOption", "NoStartMenuOption", MB_OK
);
494 check_startmenu ("Cygwin Bash Shell",
495 backslash (cygpath ("/cygwin.bat")));
505 check_desktop ("Cygwin", backslash (cygpath ("/cygwin.bat")));
509 load_dialog (GetHWND ());
514 DesktopSetupPage::OnBack ()
523 DesktopSetupPage::OnFinish ()
528 NEXT (IDD_S_POSTINSTALL
);
529 do_postinstall (GetInstance (), h
);
535 DesktopSetupPage::OnUnattended ()
537 Window::PostMessage (WM_APP_UNATTENDED_FINISH
);
538 // GetOwner ()->PressButton(PSBTN_FINISH);
543 DesktopSetupPage::OnMessageApp (UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
547 case WM_APP_UNATTENDED_FINISH
:
549 GetOwner ()->PressButton(PSBTN_FINISH
);