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"
56 static OSVERSIONINFO verinfo
;
58 /* Lines starting with '@' are conditionals - include 'N' for NT,
59 '5' for Win95, '8' for Win98, '*' for all, like this:
66 static const char *etc_profile
[] = {
67 "PATH=\"/usr/local/bin:/usr/bin:/bin:$PATH\"",
71 "# Set up USER's home directory",
72 "if [ -z \"$HOME\" ]; then",
73 " HOME=\"/home/$USER\"",
76 "if [ ! -d \"$HOME\" ]; then",
77 " mkdir -p \"$HOME\"",
82 "for i in /etc/profile.d/*.sh ; do",
83 " if [ -f $i ]; then",
88 "export MAKE_MODE=unix",
89 "export PS1='\\[\\033]0;\\w\\007",
90 "\\033[32m\\]\\u@\\h \\[\\033[33m\\w\\033[0m\\]",
97 #define COMMAND9XARGS String("/E:4096 /c")
98 #define COMMAND9XEXE String("\\command.com")
100 static String batname
;
101 static String iconname
;
104 make_link (String
const &linkpath
, String
const &title
, String
const &target
)
106 String fname
= linkpath
+ "/" + title
+ ".lnk";
108 if (_access (fname
.cstr_oneuse(), 0) == 0)
109 return; /* already exists */
111 msg ("make_link %s, %s, %s\n",
112 fname
.cstr_oneuse(), title
.cstr_oneuse(), target
.cstr_oneuse());
114 io_stream::mkpath_p (PATH_TO_FILE
, fname
);
119 /* If we are running Win9x, build a command line. */
120 if (verinfo
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
124 // sprintf (argbuf, " ");
128 char windir
[MAX_PATH
];
130 GetWindowsDirectory (windir
, sizeof (windir
));
131 exepath
= String(windir
) + COMMAND9XEXE
;
132 argbuf
= COMMAND9XARGS
+ " " + target
;
133 // sprintf (argbuf, "%s %s", COMMAND9XARGS, target.cstr_oneuse());
136 msg ("make_link_2 (%s, %s, %s, %s)",
137 exepath
.cstr_oneuse(), argbuf
.cstr_oneuse(),
138 iconname
.cstr_oneuse(), fname
.cstr_oneuse());
139 make_link_2 (exepath
.cstr_oneuse(), argbuf
.cstr_oneuse(),
140 iconname
.cstr_oneuse(), fname
.cstr_oneuse());
144 start_menu (String
const &title
, String
const &target
)
147 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
148 SHGetSpecialFolderLocation (NULL
,
149 issystem
? CSIDL_COMMON_PROGRAMS
:
150 CSIDL_PROGRAMS
, &id
);
151 char _path
[_MAX_PATH
];
152 SHGetPathFromIDList (id
, _path
);
154 // Win95 does not use common programs unless multiple users for Win95 is enabled
155 msg ("Program directory for program link: %s", path
.cstr_oneuse());
156 if (path
.size() == 0)
158 SHGetSpecialFolderLocation (NULL
, CSIDL_PROGRAMS
, &id
);
159 SHGetPathFromIDList (id
, _path
);
160 path
= String(_path
);
161 msg ("Program directory for program link changed to: %s",
164 // end of Win95 addition
166 make_link (path
, title
, target
);
170 desktop_icon (String
const &title
, String
const &target
)
172 char path
[_MAX_PATH
];
174 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
175 //SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_DESKTOP : CSIDL_COMMON_DESKTOPDIRECTORY, &id);
176 SHGetSpecialFolderLocation (NULL
,
177 issystem
? CSIDL_COMMON_DESKTOPDIRECTORY
:
178 CSIDL_DESKTOPDIRECTORY
, &id
);
179 SHGetPathFromIDList (id
, path
);
180 // following lines added because it appears Win95 does not use common programs
181 // unless it comes into play when multiple users for Win95 is enabled
182 msg ("Desktop directory for desktop link: %s", path
);
183 if (strlen (path
) == 0)
185 SHGetSpecialFolderLocation (NULL
, CSIDL_DESKTOPDIRECTORY
, &id
);
186 SHGetPathFromIDList (id
, path
);
187 msg ("Desktop directory for deskop link changed to: %s", path
);
189 // end of Win95 addition
190 make_link (path
, title
, target
);
196 batname
= backslash (cygpath ("/cygwin.bat"));
198 /* if the batch file exists, don't overwrite it */
199 if (_access (batname
.cstr_oneuse(), 0) == 0)
202 FILE *bat
= fopen (batname
.cstr_oneuse(), "wt");
206 fprintf (bat
, "@echo off\n\n");
208 fprintf (bat
, "%.2s\n", get_root_dir ().cstr_oneuse());
209 fprintf (bat
, "chdir %s\n\n",
210 backslash (get_root_dir () + "/bin").cstr_oneuse());
212 fprintf (bat
, "bash --login -i\n");
220 String fname
= cygpath ("/etc/profile");
222 /* if the file exists, don't overwrite it */
223 if (_access (fname
.cstr_oneuse(), 0) == 0)
227 switch (verinfo
.dwPlatformId
)
229 case VER_PLATFORM_WIN32_NT
:
232 case VER_PLATFORM_WIN32_WINDOWS
:
233 if (verinfo
.dwMinorVersion
== 0)
242 msg ("os is %c", os
);
244 FILE *p
= fopen (fname
.cstr_oneuse(), "wb");
249 for (i
= 0; etc_profile
[i
]; i
++)
251 if (etc_profile
[i
][0] == '@')
254 msg ("profile: %s", etc_profile
[i
]);
255 for (const char *cp
= etc_profile
[i
] + 1; *cp
; cp
++)
256 if (*cp
== os
|| *cp
== '*')
258 msg ("allow is %d\n", allow
);
261 fprintf (p
, "%s\n", etc_profile
[i
]);
268 uexists (const char *path
)
270 String f
= cygpath (path
);
271 int a
= _access (f
.cstr_oneuse(), 0);
280 String fname
= cygpath ("/etc/postinstall/passwd-grp.bat");
281 io_stream::mkpath_p (PATH_TO_FILE
, fname
);
283 if (uexists ("/etc/passwd") && uexists ("/etc/group"))
286 if (verinfo
.dwPlatformId
!= VER_PLATFORM_WIN32_NT
)
289 packagemeta
*pkg
= db
.packages
.getbykey ("cygwin");
290 if (pkg
&& pkg
->installed
)
292 /* mkpasswd and mkgroup are not working on 9x/ME up to 1.1.5-4 */
293 String border_version
= canonicalize_version ("1.1.5-4");
294 String inst_version
=
295 canonicalize_version (pkg
->installed
->Canonical_version ());
296 if (inst_version
.compare(border_version
) <= 0)
301 FILE *p
= fopen (fname
.cstr_oneuse(), "wt");
304 if (!uexists ("/etc/passwd"))
305 fprintf (p
, "bin\\mkpasswd -l > etc\\passwd\n");
306 if (!uexists ("/etc/group"))
307 fprintf (p
, "bin\\mkgroup -l > etc\\group\n");
314 iconname
= backslash (cygpath ("/cygwin.ico"));
316 HRSRC rsrc
= FindResource (NULL
, "CYGWIN.ICON", "FILE");
319 fatal ("FindResource failed");
321 HGLOBAL res
= LoadResource (NULL
, rsrc
);
322 char *data
= (char *) LockResource (res
);
323 int len
= SizeofResource (NULL
, rsrc
);
325 FILE *f
= fopen (iconname
.cstr_oneuse(), "wb");
328 fwrite (data
, 1, len
, f
);
340 make_passwd_group ();
344 start_menu ("Cygwin Bash Shell", batname
);
349 desktop_icon ("Cygwin", batname
);
353 static int da
[] = { IDC_ROOT_DESKTOP
, 0 };
354 static int ma
[] = { IDC_ROOT_MENU
, 0 };
357 check_if_enable_next (HWND h
)
359 EnableWindow (GetDlgItem (h
, IDOK
), 1);
365 rbset (h
, da
, root_desktop
);
366 rbset (h
, ma
, root_menu
);
367 check_if_enable_next (h
);
371 check_desktop (String
const title
, String
const target
)
373 char path
[_MAX_PATH
];
375 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
376 SHGetSpecialFolderLocation (NULL
,
377 issystem
? CSIDL_COMMON_DESKTOPDIRECTORY
:
378 CSIDL_DESKTOPDIRECTORY
, &id
);
379 SHGetPathFromIDList (id
, path
);
380 // following lines added because it appears Win95 does not use common programs
381 // unless it comes into play when multiple users for Win95 is enabled
382 msg ("Desktop directory for desktop link: %s", path
);
383 if (strlen (path
) == 0)
385 SHGetSpecialFolderLocation (NULL
, CSIDL_DESKTOPDIRECTORY
, &id
);
386 SHGetPathFromIDList (id
, path
);
387 msg ("Desktop directory for deskop link changed to: %s", path
);
389 // end of Win95 addition
390 String fname
= String (path
) + "/" + title
+ ".lnk";
392 if (_access (fname
.cstr_oneuse(), 0) == 0)
393 return 0; /* already exists */
395 fname
= String (path
) + "/" + title
+ ".pif"; /* check for a pif as well */
397 if (_access (fname
.cstr_oneuse(), 0) == 0)
398 return 0; /* already exists */
400 return IDC_ROOT_DESKTOP
;
404 check_startmenu (String
const title
, String
const target
)
406 char path
[_MAX_PATH
];
408 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
409 SHGetSpecialFolderLocation (NULL
,
410 issystem
? CSIDL_COMMON_PROGRAMS
:
411 CSIDL_PROGRAMS
, &id
);
412 SHGetPathFromIDList (id
, path
);
413 // following lines added because it appears Win95 does not use common programs
414 // unless it comes into play when multiple users for Win95 is enabled
415 msg ("Program directory for program link: %s", path
);
416 if (strlen (path
) == 0)
418 SHGetSpecialFolderLocation (NULL
, CSIDL_PROGRAMS
, &id
);
419 SHGetPathFromIDList (id
, path
);
420 msg ("Program directory for program link changed to: %s", path
);
422 // end of Win95 addition
423 strcat (path
, "/Cygwin");
424 String fname
= String (path
) + "/" + title
+ ".lnk";
426 if (_access (fname
.cstr_oneuse(), 0) == 0)
427 return 0; /* already exists */
429 fname
= String (path
) + "/" + title
+ ".pif"; /* check for a pif as well */
431 if (_access (fname
.cstr_oneuse(), 0) == 0)
432 return 0; /* already exists */
434 return IDC_ROOT_MENU
;
440 root_desktop
= rbget (h
, da
);
441 root_menu
= rbget (h
, ma
);
445 dialog_cmd (HWND h
, int id
, HWND hwndctl
, UINT code
)
450 case IDC_ROOT_DESKTOP
:
453 check_if_enable_next (h
);
460 DesktopSetupPage::Create ()
462 return PropertyPage::Create (NULL
, dialog_cmd
, IDD_DESKTOP
);
466 DesktopSetupPage::OnInit ()
468 // FIXME: This CoInitialize() feels like it could be moved to startup in main.cc.
470 verinfo
.dwOSVersionInfoSize
= sizeof (verinfo
);
471 GetVersionEx (&verinfo
);
473 check_desktop ("Cygwin", backslash (cygpath ("/cygwin.bat")));
475 check_startmenu ("Cygwin Bash Shell",
476 backslash (cygpath ("/cygwin.bat")));
477 load_dialog (GetHWND ());
481 DesktopSetupPage::OnBack ()
490 DesktopSetupPage::OnFinish ()
495 NEXT (IDD_S_POSTINSTALL
);
496 do_postinstall (GetInstance (), h
);