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"
41 #include "package_db.h"
42 #include "package_meta.h"
43 #include "package_version.h"
44 #include "filemanip.h"
45 #include "io_stream.h"
46 #include "getopt++/BoolOption.h"
47 #include "PackageSpecification.h"
50 static BoolOption
NoShortcutsOption (false, 'n', "no-shortcuts", "Disable creation of desktop and start menu shortcuts");
51 static BoolOption
NoStartMenuOption (false, 'N', "no-startmenu", "Disable creation of start menu shortcut");
52 static BoolOption
NoDesktopOption (false, 'd', "no-desktop", "Disable creation of desktop shortcut");
54 /* Lines starting with '@' are conditionals - include 'N' for NT,
55 '5' for Win95, '8' for Win98, '*' for all, like this:
62 static std::string batname
;
63 static std::string iconname
;
65 static ControlAdjuster::ControlInfo DesktopControlsInfo
[] = {
66 {IDC_DESKTOP_SEPARATOR
, CP_STRETCH
, CP_BOTTOM
},
67 {IDC_STATUS
, CP_LEFT
, CP_BOTTOM
},
68 {IDC_STATUS_HEADER
, CP_LEFT
, CP_BOTTOM
},
72 DesktopSetupPage::DesktopSetupPage ()
74 sizeProcessor
.AddControlInfo (DesktopControlsInfo
);
78 make_link (const std::string
& linkpath
,
79 const std::string
& title
,
80 const std::string
& target
)
82 std::string fname
= linkpath
+ "/" + title
+ ".lnk";
84 if (_access (fname
.c_str(), 0) == 0)
85 return; /* already exists */
87 msg ("make_link %s, %s, %s\n",
88 fname
.c_str(), title
.c_str(), target
.c_str());
90 io_stream::mkpath_p (PATH_TO_FILE
, std::string ("file://") + fname
);
102 char windir
[MAX_PATH
];
104 GetWindowsDirectory (windir
, sizeof (windir
));
105 exepath
= std::string(windir
) + "\\command.com";
106 argbuf
= "/E:4096 /c " + target
;
109 msg ("make_link_2 (%s, %s, %s, %s)",
110 exepath
.c_str(), argbuf
.c_str(),
111 iconname
.c_str(), fname
.c_str());
112 make_link_2 (exepath
.c_str(), argbuf
.c_str(),
113 iconname
.c_str(), fname
.c_str());
117 start_menu (const std::string
& title
, const std::string
& target
)
120 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
121 SHGetSpecialFolderLocation (NULL
,
122 issystem
? CSIDL_COMMON_PROGRAMS
:
123 CSIDL_PROGRAMS
, &id
);
124 char _path
[MAX_PATH
];
125 SHGetPathFromIDList (id
, _path
);
126 std::string
path(_path
);
127 // Win95 does not use common programs unless multiple users for Win95 is enabled
128 msg ("Program directory for program link: %s", path
.c_str());
131 SHGetSpecialFolderLocation (NULL
, CSIDL_PROGRAMS
, &id
);
132 SHGetPathFromIDList (id
, _path
);
134 msg ("Program directory for program link changed to: %s",
137 // end of Win95 addition
139 make_link (path
, title
, target
);
143 desktop_icon (const std::string
& title
, const std::string
& target
)
147 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
148 //SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_DESKTOP : CSIDL_COMMON_DESKTOPDIRECTORY, &id);
149 SHGetSpecialFolderLocation (NULL
,
150 issystem
? CSIDL_COMMON_DESKTOPDIRECTORY
:
151 CSIDL_DESKTOPDIRECTORY
, &id
);
152 SHGetPathFromIDList (id
, path
);
153 // following lines added because it appears Win95 does not use common programs
154 // unless it comes into play when multiple users for Win95 is enabled
155 msg ("Desktop directory for desktop link: %s", path
);
156 if (strlen (path
) == 0)
158 SHGetSpecialFolderLocation (NULL
, CSIDL_DESKTOPDIRECTORY
, &id
);
159 SHGetPathFromIDList (id
, path
);
160 msg ("Desktop directory for deskop link changed to: %s", path
);
162 // end of Win95 addition
163 make_link (path
, title
, target
);
169 batname
= backslash (cygpath ("/Cygwin.bat"));
171 /* if the batch file exists, don't overwrite it */
172 if (_access (batname
.c_str(), 0) == 0)
175 FILE *bat
= fopen (batname
.c_str(), "wt");
179 fprintf (bat
, "@echo off\n\n");
181 fprintf (bat
, "%.2s\n", get_root_dir ().c_str());
182 fprintf (bat
, "chdir %s\n\n",
183 replace(backslash(get_root_dir() + "/bin"), "%", "%%").c_str());
185 fprintf (bat
, "bash --login -i\n");
193 iconname
= backslash (cygpath ("/Cygwin.ico"));
195 HRSRC rsrc
= FindResource (NULL
, "CYGWIN.ICON", "FILE");
198 fatal ("FindResource failed");
200 HGLOBAL res
= LoadResource (NULL
, rsrc
);
201 char *data
= (char *) LockResource (res
);
202 int len
= SizeofResource (NULL
, rsrc
);
204 FILE *f
= fopen (iconname
.c_str(), "wb");
207 fwrite (data
, 1, len
, f
);
221 start_menu ("Cygwin Bash Shell", batname
);
226 desktop_icon ("Cygwin", batname
);
230 static int da
[] = { IDC_ROOT_DESKTOP
, 0 };
231 static int ma
[] = { IDC_ROOT_MENU
, 0 };
234 check_if_enable_next (HWND h
)
236 EnableWindow (GetDlgItem (h
, IDOK
), 1);
239 extern LogFile
* theLog
;
244 char buf
[1000], fmt
[1000];
245 if (LoadString (hinstance
, exit_msg
, fmt
, sizeof (fmt
)) > 0)
247 snprintf (buf
, 1000, fmt
, backslash(theLog
->getFileName(LOG_BABBLE
)).c_str());
248 eset(h
, IDC_STATUS
, buf
);
252 static char *header_string
= NULL
;
253 static char *message_string
= NULL
;
257 if (source
== IDC_SOURCE_DOWNLOAD
)
259 // Don't need the checkboxes
260 EnableWindow (GetDlgItem (h
, IDC_ROOT_DESKTOP
), FALSE
);
261 EnableWindow (GetDlgItem (h
, IDC_ROOT_MENU
), FALSE
);
262 if (header_string
== NULL
)
263 header_string
= eget (h
, IDC_STATIC_HEADER_TITLE
, header_string
);
264 if (message_string
== NULL
)
265 message_string
= eget (h
, IDC_STATIC_HEADER
, message_string
);
266 eset (h
, IDC_STATIC_HEADER_TITLE
, "Installation complete");
267 eset (h
, IDC_STATIC_HEADER
, "Shows installation status in download-only mode.");
271 EnableWindow (GetDlgItem (h
, IDC_ROOT_DESKTOP
), TRUE
);
272 EnableWindow (GetDlgItem (h
, IDC_ROOT_MENU
), TRUE
);
273 if (header_string
!= NULL
)
274 eset (h
, IDC_STATIC_HEADER_TITLE
, header_string
);
275 if (message_string
!= NULL
)
276 eset (h
, IDC_STATIC_HEADER
, message_string
);
277 rbset (h
, da
, root_desktop
);
278 rbset (h
, ma
, root_menu
);
280 check_if_enable_next (h
);
285 check_desktop (const std::string title
, const std::string target
)
289 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
290 SHGetSpecialFolderLocation (NULL
,
291 issystem
? CSIDL_COMMON_DESKTOPDIRECTORY
:
292 CSIDL_DESKTOPDIRECTORY
, &id
);
293 SHGetPathFromIDList (id
, path
);
294 // following lines added because it appears Win95 does not use common programs
295 // unless it comes into play when multiple users for Win95 is enabled
296 msg ("Desktop directory for desktop link: %s", path
);
297 if (strlen (path
) == 0)
299 SHGetSpecialFolderLocation (NULL
, CSIDL_DESKTOPDIRECTORY
, &id
);
300 SHGetPathFromIDList (id
, path
);
301 msg ("Desktop directory for deskop link changed to: %s", path
);
303 // end of Win95 addition
304 std::string fname
= std::string(path
) + "/" + title
+ ".lnk";
306 if (_access (fname
.c_str(), 0) == 0)
307 return 0; /* already exists */
309 fname
= std::string(path
) + "/" + title
+ ".pif"; /* check for a pif as well */
311 if (_access (fname
.c_str(), 0) == 0)
312 return 0; /* already exists */
314 return IDC_ROOT_DESKTOP
;
318 check_startmenu (const std::string title
, const std::string target
)
322 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
323 SHGetSpecialFolderLocation (NULL
,
324 issystem
? CSIDL_COMMON_PROGRAMS
:
325 CSIDL_PROGRAMS
, &id
);
326 SHGetPathFromIDList (id
, path
);
327 // following lines added because it appears Win95 does not use common programs
328 // unless it comes into play when multiple users for Win95 is enabled
329 msg ("Program directory for program link: %s", path
);
330 if (strlen (path
) == 0)
332 SHGetSpecialFolderLocation (NULL
, CSIDL_PROGRAMS
, &id
);
333 SHGetPathFromIDList (id
, path
);
334 msg ("Program directory for program link changed to: %s", path
);
336 // end of Win95 addition
337 strcat (path
, "/Cygwin");
338 std::string fname
= std::string(path
) + "/" + title
+ ".lnk";
340 if (_access (fname
.c_str(), 0) == 0)
341 return 0; /* already exists */
343 fname
= std::string(path
) + "/" + title
+ ".pif"; /* check for a pif as well */
345 if (_access (fname
.c_str(), 0) == 0)
346 return 0; /* already exists */
348 return IDC_ROOT_MENU
;
354 root_desktop
= rbget (h
, da
);
355 root_menu
= rbget (h
, ma
);
359 dialog_cmd (HWND h
, int id
, HWND hwndctl
, UINT code
)
364 case IDC_ROOT_DESKTOP
:
367 check_if_enable_next (h
);
374 DesktopSetupPage::Create ()
376 return PropertyPage::Create (NULL
, dialog_cmd
, IDD_DESKTOP
);
380 DesktopSetupPage::OnInit ()
382 // FIXME: This CoInitialize() feels like it could be moved to startup in main.cc.
385 SetDlgItemFont(IDC_STATUS_HEADER
, "MS Shell Dlg", 8, FW_BOLD
);
389 DesktopSetupPage::OnActivate ()
391 if (NoShortcutsOption
|| source
== IDC_SOURCE_DOWNLOAD
)
393 root_desktop
= root_menu
= 0;
397 if (NoStartMenuOption
)
404 check_startmenu ("Cygwin Bash Shell",
405 backslash (cygpath ("/cygwin.bat")));
415 check_desktop ("Cygwin", backslash (cygpath ("/cygwin.bat")));
419 load_dialog (GetHWND ());
423 DesktopSetupPage::OnBack ()
431 DesktopSetupPage::OnFinish ()
435 if (source
!= IDC_SOURCE_DOWNLOAD
)
442 DesktopSetupPage::OnUnattended ()
444 Window::PostMessage (WM_APP_UNATTENDED_FINISH
);
445 // GetOwner ()->PressButton(PSBTN_FINISH);
450 DesktopSetupPage::OnMessageApp (UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
454 case WM_APP_UNATTENDED_FINISH
:
456 GetOwner ()->PressButton(PSBTN_FINISH
);