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
=
44 #include "package_db.h"
45 #include "package_meta.h"
46 #include "package_version.h"
48 #include "filemanip.h"
50 #include "io_stream.h"
53 #include "getopt++/BoolOption.h"
55 static BoolOption
NoShortcutsOption (false, 'n', "no-shortcuts", "Disable creation of desktop and start menu shortcuts");
57 static OSVERSIONINFO verinfo
;
59 /* Lines starting with '@' are conditionals - include 'N' for NT,
60 '5' for Win95, '8' for Win98, '*' for all, like this:
67 static const char *etc_profile
[] = {
68 "PATH=\"/usr/local/bin:/usr/bin:/bin:$PATH\"",
72 "# Set up USER's home directory",
73 "if [ -z \"$HOME\" ]; then",
74 " HOME=\"/home/$USER\"",
77 "if [ ! -d \"$HOME\" ]; then",
78 " mkdir -p \"$HOME\"",
83 "for i in /etc/profile.d/*.sh ; do",
84 " if [ -f $i ]; then",
89 "export MAKE_MODE=unix",
90 "export PS1='\\[\\033]0;\\w\\007",
91 "\\033[32m\\]\\u@\\h \\[\\033[33m\\w\\033[0m\\]",
98 #define COMMAND9XARGS String("/E:4096 /c")
99 #define COMMAND9XEXE String("\\command.com")
101 static String batname
;
102 static String iconname
;
105 make_link (String
const &linkpath
, String
const &title
, String
const &target
)
107 String fname
= linkpath
+ "/" + title
+ ".lnk";
109 if (_access (fname
.cstr_oneuse(), 0) == 0)
110 return; /* already exists */
112 msg ("make_link %s, %s, %s\n",
113 fname
.cstr_oneuse(), title
.cstr_oneuse(), target
.cstr_oneuse());
115 io_stream::mkpath_p (PATH_TO_FILE
, String ("file://") + fname
);
120 /* If we are running Win9x, build a command line. */
121 if (verinfo
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
125 // sprintf (argbuf, " ");
129 char windir
[MAX_PATH
];
131 GetWindowsDirectory (windir
, sizeof (windir
));
132 exepath
= String(windir
) + COMMAND9XEXE
;
133 argbuf
= COMMAND9XARGS
+ " " + target
;
134 // sprintf (argbuf, "%s %s", COMMAND9XARGS, target.cstr_oneuse());
137 msg ("make_link_2 (%s, %s, %s, %s)",
138 exepath
.cstr_oneuse(), argbuf
.cstr_oneuse(),
139 iconname
.cstr_oneuse(), fname
.cstr_oneuse());
140 make_link_2 (exepath
.cstr_oneuse(), argbuf
.cstr_oneuse(),
141 iconname
.cstr_oneuse(), fname
.cstr_oneuse());
145 start_menu (String
const &title
, String
const &target
)
148 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
149 SHGetSpecialFolderLocation (NULL
,
150 issystem
? CSIDL_COMMON_PROGRAMS
:
151 CSIDL_PROGRAMS
, &id
);
152 char _path
[_MAX_PATH
];
153 SHGetPathFromIDList (id
, _path
);
155 // Win95 does not use common programs unless multiple users for Win95 is enabled
156 msg ("Program directory for program link: %s", path
.cstr_oneuse());
157 if (path
.size() == 0)
159 SHGetSpecialFolderLocation (NULL
, CSIDL_PROGRAMS
, &id
);
160 SHGetPathFromIDList (id
, _path
);
161 path
= String(_path
);
162 msg ("Program directory for program link changed to: %s",
165 // end of Win95 addition
167 make_link (path
, title
, target
);
171 desktop_icon (String
const &title
, String
const &target
)
173 char path
[_MAX_PATH
];
175 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
176 //SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_DESKTOP : CSIDL_COMMON_DESKTOPDIRECTORY, &id);
177 SHGetSpecialFolderLocation (NULL
,
178 issystem
? CSIDL_COMMON_DESKTOPDIRECTORY
:
179 CSIDL_DESKTOPDIRECTORY
, &id
);
180 SHGetPathFromIDList (id
, path
);
181 // following lines added because it appears Win95 does not use common programs
182 // unless it comes into play when multiple users for Win95 is enabled
183 msg ("Desktop directory for desktop link: %s", path
);
184 if (strlen (path
) == 0)
186 SHGetSpecialFolderLocation (NULL
, CSIDL_DESKTOPDIRECTORY
, &id
);
187 SHGetPathFromIDList (id
, path
);
188 msg ("Desktop directory for deskop link changed to: %s", path
);
190 // end of Win95 addition
191 make_link (path
, title
, target
);
197 batname
= backslash (cygpath ("/cygwin.bat"));
199 /* if the batch file exists, don't overwrite it */
200 if (_access (batname
.cstr_oneuse(), 0) == 0)
203 FILE *bat
= fopen (batname
.cstr_oneuse(), "wt");
207 fprintf (bat
, "@echo off\n\n");
209 fprintf (bat
, "%.2s\n", get_root_dir ().cstr_oneuse());
210 fprintf (bat
, "chdir %s\n\n",
211 backslash (get_root_dir () + "/bin").cstr_oneuse());
213 fprintf (bat
, "bash --login -i\n");
221 String fname
= cygpath ("/etc/profile");
223 /* if the file exists, don't overwrite it */
224 if (_access (fname
.cstr_oneuse(), 0) == 0)
228 switch (verinfo
.dwPlatformId
)
230 case VER_PLATFORM_WIN32_NT
:
233 case VER_PLATFORM_WIN32_WINDOWS
:
234 if (verinfo
.dwMinorVersion
== 0)
243 msg ("os is %c", os
);
245 FILE *p
= fopen (fname
.cstr_oneuse(), "wb");
250 for (i
= 0; etc_profile
[i
]; i
++)
252 if (etc_profile
[i
][0] == '@')
255 msg ("profile: %s", etc_profile
[i
]);
256 for (const char *cp
= etc_profile
[i
] + 1; *cp
; cp
++)
257 if (*cp
== os
|| *cp
== '*')
259 msg ("allow is %d\n", allow
);
262 fprintf (p
, "%s\n", etc_profile
[i
]);
269 uexists (const char *path
)
271 String f
= cygpath (path
);
272 int a
= _access (f
.cstr_oneuse(), 0);
281 String fname
= cygpath ("/etc/postinstall/passwd-grp.bat");
282 io_stream::mkpath_p (PATH_TO_FILE
, String("file://") + fname
);
284 if ((uexists ("/etc/passwd") || uexists ("/etc/passwd.lnk"))
285 && (uexists ("/etc/group") || uexists ("/etc/group.lnk")))
288 if (verinfo
.dwPlatformId
!= VER_PLATFORM_WIN32_NT
)
291 packagemeta
*pkg
= db
.packages
.getbykey ("cygwin");
292 if (pkg
&& pkg
->installed
)
294 /* mkpasswd and mkgroup are not working on 9x/ME up to 1.1.5-4 */
295 String border_version
= canonicalize_version ("1.1.5-4");
296 String inst_version
=
297 canonicalize_version (pkg
->installed
.Canonical_version ());
298 if (inst_version
.compare(border_version
) <= 0)
303 FILE *p
= fopen (fname
.cstr_oneuse(), "wt");
306 if (!(uexists ("/etc/passwd") || uexists ("/etc/passwd.lnk")))
307 fprintf (p
, "bin\\mkpasswd -l > etc\\passwd\n");
308 if (!(uexists ("/etc/group") || uexists ("/etc/group.lnk")))
309 fprintf (p
, "bin\\mkgroup -l > etc\\group\n");
316 iconname
= backslash (cygpath ("/cygwin.ico"));
318 HRSRC rsrc
= FindResource (NULL
, "CYGWIN.ICON", "FILE");
321 fatal ("FindResource failed");
323 HGLOBAL res
= LoadResource (NULL
, rsrc
);
324 char *data
= (char *) LockResource (res
);
325 int len
= SizeofResource (NULL
, rsrc
);
327 FILE *f
= fopen (iconname
.cstr_oneuse(), "wb");
330 fwrite (data
, 1, len
, f
);
342 make_passwd_group ();
346 start_menu ("Cygwin Bash Shell", batname
);
351 desktop_icon ("Cygwin", batname
);
355 static int da
[] = { IDC_ROOT_DESKTOP
, 0 };
356 static int ma
[] = { IDC_ROOT_MENU
, 0 };
359 check_if_enable_next (HWND h
)
361 EnableWindow (GetDlgItem (h
, IDOK
), 1);
367 rbset (h
, da
, root_desktop
);
368 rbset (h
, ma
, root_menu
);
369 check_if_enable_next (h
);
373 check_desktop (String
const title
, String
const target
)
375 char path
[_MAX_PATH
];
377 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
378 SHGetSpecialFolderLocation (NULL
,
379 issystem
? CSIDL_COMMON_DESKTOPDIRECTORY
:
380 CSIDL_DESKTOPDIRECTORY
, &id
);
381 SHGetPathFromIDList (id
, path
);
382 // following lines added because it appears Win95 does not use common programs
383 // unless it comes into play when multiple users for Win95 is enabled
384 msg ("Desktop directory for desktop link: %s", path
);
385 if (strlen (path
) == 0)
387 SHGetSpecialFolderLocation (NULL
, CSIDL_DESKTOPDIRECTORY
, &id
);
388 SHGetPathFromIDList (id
, path
);
389 msg ("Desktop directory for deskop link changed to: %s", path
);
391 // end of Win95 addition
392 String fname
= String (path
) + "/" + title
+ ".lnk";
394 if (_access (fname
.cstr_oneuse(), 0) == 0)
395 return 0; /* already exists */
397 fname
= String (path
) + "/" + title
+ ".pif"; /* check for a pif as well */
399 if (_access (fname
.cstr_oneuse(), 0) == 0)
400 return 0; /* already exists */
402 return IDC_ROOT_DESKTOP
;
406 check_startmenu (String
const title
, String
const target
)
408 char path
[_MAX_PATH
];
410 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
411 SHGetSpecialFolderLocation (NULL
,
412 issystem
? CSIDL_COMMON_PROGRAMS
:
413 CSIDL_PROGRAMS
, &id
);
414 SHGetPathFromIDList (id
, path
);
415 // following lines added because it appears Win95 does not use common programs
416 // unless it comes into play when multiple users for Win95 is enabled
417 msg ("Program directory for program link: %s", path
);
418 if (strlen (path
) == 0)
420 SHGetSpecialFolderLocation (NULL
, CSIDL_PROGRAMS
, &id
);
421 SHGetPathFromIDList (id
, path
);
422 msg ("Program directory for program link changed to: %s", path
);
424 // end of Win95 addition
425 strcat (path
, "/Cygwin");
426 String fname
= String (path
) + "/" + title
+ ".lnk";
428 if (_access (fname
.cstr_oneuse(), 0) == 0)
429 return 0; /* already exists */
431 fname
= String (path
) + "/" + title
+ ".pif"; /* check for a pif as well */
433 if (_access (fname
.cstr_oneuse(), 0) == 0)
434 return 0; /* already exists */
436 return IDC_ROOT_MENU
;
442 root_desktop
= rbget (h
, da
);
443 root_menu
= rbget (h
, ma
);
447 dialog_cmd (HWND h
, int id
, HWND hwndctl
, UINT code
)
452 case IDC_ROOT_DESKTOP
:
455 check_if_enable_next (h
);
462 DesktopSetupPage::Create ()
464 return PropertyPage::Create (NULL
, dialog_cmd
, IDD_DESKTOP
);
468 DesktopSetupPage::OnInit ()
470 // FIXME: This CoInitialize() feels like it could be moved to startup in main.cc.
472 verinfo
.dwOSVersionInfoSize
= sizeof (verinfo
);
473 GetVersionEx (&verinfo
);
475 check_desktop ("Cygwin", backslash (cygpath ("/cygwin.bat")));
477 check_startmenu ("Cygwin Bash Shell",
478 backslash (cygpath ("/cygwin.bat")));
479 if (NoShortcutsOption
)
486 load_dialog (GetHWND ());
490 DesktopSetupPage::OnBack ()
499 DesktopSetupPage::OnFinish ()
504 NEXT (IDD_S_POSTINSTALL
);
505 do_postinstall (GetInstance (), h
);