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"
43 #include "package_db.h"
44 #include "package_meta.h"
45 #include "package_version.h"
47 #include "filemanip.h"
49 #include "io_stream.h"
51 #include "getopt++/BoolOption.h"
53 #include "PackageSpecification.h"
55 static BoolOption
NoShortcutsOption (false, 'n', "no-shortcuts", "Disable creation of desktop and start menu shortcuts");
56 static BoolOption
NoStartMenuOption (false, 'N', "no-startmenu", "Disable creation of start menu shortcut");
57 static BoolOption
NoDesktopOption (false, 'd', "no-desktop", "Disable creation of desktop shortcut");
59 static OSVERSIONINFO verinfo
;
61 /* Lines starting with '@' are conditionals - include 'N' for NT,
62 '5' for Win95, '8' for Win98, '*' for all, like this:
69 #define COMMAND9XARGS String("/E:4096 /c")
70 #define COMMAND9XEXE String("\\command.com")
72 static String batname
;
73 static String iconname
;
76 make_link (String
const &linkpath
, String
const &title
, String
const &target
)
78 String fname
= linkpath
+ "/" + title
+ ".lnk";
80 if (_access (fname
.cstr_oneuse(), 0) == 0)
81 return; /* already exists */
83 msg ("make_link %s, %s, %s\n",
84 fname
.cstr_oneuse(), title
.cstr_oneuse(), target
.cstr_oneuse());
86 io_stream::mkpath_p (PATH_TO_FILE
, String ("file://") + fname
);
91 /* If we are running Win9x, build a command line. */
92 if (verinfo
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
96 // sprintf (argbuf, " ");
100 char windir
[MAX_PATH
];
102 GetWindowsDirectory (windir
, sizeof (windir
));
103 exepath
= String(windir
) + COMMAND9XEXE
;
104 argbuf
= COMMAND9XARGS
+ " " + target
;
105 // sprintf (argbuf, "%s %s", COMMAND9XARGS, target.cstr_oneuse());
108 msg ("make_link_2 (%s, %s, %s, %s)",
109 exepath
.cstr_oneuse(), argbuf
.cstr_oneuse(),
110 iconname
.cstr_oneuse(), fname
.cstr_oneuse());
111 make_link_2 (exepath
.cstr_oneuse(), argbuf
.cstr_oneuse(),
112 iconname
.cstr_oneuse(), fname
.cstr_oneuse());
116 start_menu (String
const &title
, String
const &target
)
119 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
120 SHGetSpecialFolderLocation (NULL
,
121 issystem
? CSIDL_COMMON_PROGRAMS
:
122 CSIDL_PROGRAMS
, &id
);
123 char _path
[MAX_PATH
];
124 SHGetPathFromIDList (id
, _path
);
126 // Win95 does not use common programs unless multiple users for Win95 is enabled
127 msg ("Program directory for program link: %s", path
.cstr_oneuse());
128 if (path
.size() == 0)
130 SHGetSpecialFolderLocation (NULL
, CSIDL_PROGRAMS
, &id
);
131 SHGetPathFromIDList (id
, _path
);
132 path
= String(_path
);
133 msg ("Program directory for program link changed to: %s",
136 // end of Win95 addition
138 make_link (path
, title
, target
);
142 desktop_icon (String
const &title
, String
const &target
)
146 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
147 //SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_DESKTOP : CSIDL_COMMON_DESKTOPDIRECTORY, &id);
148 SHGetSpecialFolderLocation (NULL
,
149 issystem
? CSIDL_COMMON_DESKTOPDIRECTORY
:
150 CSIDL_DESKTOPDIRECTORY
, &id
);
151 SHGetPathFromIDList (id
, path
);
152 // following lines added because it appears Win95 does not use common programs
153 // unless it comes into play when multiple users for Win95 is enabled
154 msg ("Desktop directory for desktop link: %s", path
);
155 if (strlen (path
) == 0)
157 SHGetSpecialFolderLocation (NULL
, CSIDL_DESKTOPDIRECTORY
, &id
);
158 SHGetPathFromIDList (id
, path
);
159 msg ("Desktop directory for deskop link changed to: %s", path
);
161 // end of Win95 addition
162 make_link (path
, title
, target
);
168 batname
= backslash (cygpath ("/cygwin.bat"));
170 /* if the batch file exists, don't overwrite it */
171 if (_access (batname
.cstr_oneuse(), 0) == 0)
174 FILE *bat
= fopen (batname
.cstr_oneuse(), "wt");
178 fprintf (bat
, "@echo off\n\n");
180 fprintf (bat
, "%.2s\n", get_root_dir ().cstr_oneuse());
181 fprintf (bat
, "chdir %s\n\n",
182 backslash (get_root_dir () + "/bin").replace ("%", "%%").cstr_oneuse());
184 fprintf (bat
, "bash --login -i\n");
192 iconname
= backslash (cygpath ("/cygwin.ico"));
194 HRSRC rsrc
= FindResource (NULL
, "CYGWIN.ICON", "FILE");
197 fatal ("FindResource failed");
199 HGLOBAL res
= LoadResource (NULL
, rsrc
);
200 char *data
= (char *) LockResource (res
);
201 int len
= SizeofResource (NULL
, rsrc
);
203 FILE *f
= fopen (iconname
.cstr_oneuse(), "wb");
206 fwrite (data
, 1, len
, f
);
220 start_menu ("Cygwin Bash Shell", batname
);
225 desktop_icon ("Cygwin", batname
);
229 static int da
[] = { IDC_ROOT_DESKTOP
, 0 };
230 static int ma
[] = { IDC_ROOT_MENU
, 0 };
233 check_if_enable_next (HWND h
)
235 EnableWindow (GetDlgItem (h
, IDOK
), 1);
241 rbset (h
, da
, root_desktop
);
242 rbset (h
, ma
, root_menu
);
243 check_if_enable_next (h
);
247 check_desktop (String
const title
, String
const target
)
251 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
252 SHGetSpecialFolderLocation (NULL
,
253 issystem
? CSIDL_COMMON_DESKTOPDIRECTORY
:
254 CSIDL_DESKTOPDIRECTORY
, &id
);
255 SHGetPathFromIDList (id
, path
);
256 // following lines added because it appears Win95 does not use common programs
257 // unless it comes into play when multiple users for Win95 is enabled
258 msg ("Desktop directory for desktop link: %s", path
);
259 if (strlen (path
) == 0)
261 SHGetSpecialFolderLocation (NULL
, CSIDL_DESKTOPDIRECTORY
, &id
);
262 SHGetPathFromIDList (id
, path
);
263 msg ("Desktop directory for deskop link changed to: %s", path
);
265 // end of Win95 addition
266 String fname
= String (path
) + "/" + title
+ ".lnk";
268 if (_access (fname
.cstr_oneuse(), 0) == 0)
269 return 0; /* already exists */
271 fname
= String (path
) + "/" + title
+ ".pif"; /* check for a pif as well */
273 if (_access (fname
.cstr_oneuse(), 0) == 0)
274 return 0; /* already exists */
276 return IDC_ROOT_DESKTOP
;
280 check_startmenu (String
const title
, String
const target
)
284 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
285 SHGetSpecialFolderLocation (NULL
,
286 issystem
? CSIDL_COMMON_PROGRAMS
:
287 CSIDL_PROGRAMS
, &id
);
288 SHGetPathFromIDList (id
, path
);
289 // following lines added because it appears Win95 does not use common programs
290 // unless it comes into play when multiple users for Win95 is enabled
291 msg ("Program directory for program link: %s", path
);
292 if (strlen (path
) == 0)
294 SHGetSpecialFolderLocation (NULL
, CSIDL_PROGRAMS
, &id
);
295 SHGetPathFromIDList (id
, path
);
296 msg ("Program directory for program link changed to: %s", path
);
298 // end of Win95 addition
299 strcat (path
, "/Cygwin");
300 String fname
= String (path
) + "/" + title
+ ".lnk";
302 if (_access (fname
.cstr_oneuse(), 0) == 0)
303 return 0; /* already exists */
305 fname
= String (path
) + "/" + title
+ ".pif"; /* check for a pif as well */
307 if (_access (fname
.cstr_oneuse(), 0) == 0)
308 return 0; /* already exists */
310 return IDC_ROOT_MENU
;
316 root_desktop
= rbget (h
, da
);
317 root_menu
= rbget (h
, ma
);
321 dialog_cmd (HWND h
, int id
, HWND hwndctl
, UINT code
)
326 case IDC_ROOT_DESKTOP
:
329 check_if_enable_next (h
);
336 DesktopSetupPage::Create ()
338 return PropertyPage::Create (NULL
, dialog_cmd
, IDD_DESKTOP
);
342 DesktopSetupPage::OnInit ()
344 // FIXME: This CoInitialize() feels like it could be moved to startup in main.cc.
346 verinfo
.dwOSVersionInfoSize
= sizeof (verinfo
);
347 GetVersionEx (&verinfo
);
349 if (NoShortcutsOption
)
351 root_desktop
= root_menu
= 0;
355 if (NoStartMenuOption
)
358 MessageBox(NULL
, "NoStartMenuOption", "NoStartMenuOption", MB_OK
);
363 check_startmenu ("Cygwin Bash Shell",
364 backslash (cygpath ("/cygwin.bat")));
374 check_desktop ("Cygwin", backslash (cygpath ("/cygwin.bat")));
378 load_dialog (GetHWND ());
383 DesktopSetupPage::OnBack ()
391 DesktopSetupPage::OnFinish ()
401 DesktopSetupPage::OnUnattended ()
403 Window::PostMessage (WM_APP_UNATTENDED_FINISH
);
404 // GetOwner ()->PressButton(PSBTN_FINISH);
409 DesktopSetupPage::OnMessageApp (UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
413 case WM_APP_UNATTENDED_FINISH
:
415 GetOwner ()->PressButton(PSBTN_FINISH
);