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
24 #include "propsheet.h"
36 #include "package_db.h"
37 #include "package_meta.h"
38 #include "filemanip.h"
39 #include "io_stream.h"
40 #include "getopt++/BoolOption.h"
43 static BoolOption
NoShortcutsOption (false, 'n', "no-shortcuts", "Disable creation of desktop and start menu shortcuts");
44 static BoolOption
NoStartMenuOption (false, 'N', "no-startmenu", "Disable creation of start menu shortcut");
45 static BoolOption
NoDesktopOption (false, 'd', "no-desktop", "Disable creation of desktop shortcut");
47 /* Lines starting with '@' are conditionals - include 'N' for NT,
48 '5' for Win95, '8' for Win98, '*' for all, like this:
55 static std::string batname
;
56 static ControlAdjuster::ControlInfo DesktopControlsInfo
[] = {
57 {IDC_DESKTOP_SEPARATOR
, CP_STRETCH
, CP_BOTTOM
},
58 {IDC_STATUS
, CP_LEFT
, CP_BOTTOM
},
59 {IDC_STATUS_HEADER
, CP_LEFT
, CP_BOTTOM
},
63 DesktopSetupPage::DesktopSetupPage ()
65 sizeProcessor
.AddControlInfo (DesktopControlsInfo
);
69 make_link (const std::string
& linkpath
,
70 const std::string
& title
,
71 const std::string
& target
,
72 const std::string
& arg
,
73 const std::string
& icon
)
75 std::string fname
= linkpath
+ "/" + title
+ ".lnk";
77 if (_access (fname
.c_str(), 0) == 0)
78 return; /* already exists */
80 LogBabblePrintf ("make_link %s, %s, %s\n",
81 fname
.c_str(), title
.c_str(), target
.c_str());
83 io_stream::mkpath_p (PATH_TO_FILE
, std::string ("file://") + fname
, 0);
91 LogBabblePrintf ("make_link_2 (%s, %s, %s, %s)",
92 exepath
.c_str(), argbuf
.c_str(),
93 icon
.c_str(), fname
.c_str());
94 make_link_2 (exepath
.c_str(), argbuf
.c_str(),
95 icon
.c_str(), fname
.c_str());
99 start_menu (const std::string
& title
, const std::string
& target
,
100 const std::string
& arg
, const std::string
& iconpath
)
102 /* Special folders always < MAX_PATH. */
105 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
106 SHGetSpecialFolderLocation (NULL
,
107 issystem
? CSIDL_COMMON_PROGRAMS
:
108 CSIDL_PROGRAMS
, &id
);
109 SHGetPathFromIDList (id
, path
);
110 strncat (path
, "/Cygwin", MAX_PATH
);
111 LogBabblePrintf ("Program directory for program link: %s", path
);
112 make_link (path
, title
, target
, arg
, iconpath
);
116 desktop_icon (const std::string
& title
, const std::string
& target
,
117 const std::string
& arg
, const std::string
& iconpath
)
119 /* Special folders always < MAX_PATH. */
122 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
123 SHGetSpecialFolderLocation (NULL
,
124 issystem
? CSIDL_COMMON_DESKTOPDIRECTORY
:
125 CSIDL_DESKTOPDIRECTORY
, &id
);
126 SHGetPathFromIDList (id
, path
);
127 LogBabblePrintf ("Desktop directory for desktop link: %s", path
);
128 make_link (path
, title
, target
, arg
, iconpath
);
134 batname
= backslash (cygpath ("/Cygwin.bat"));
137 size_t len
= batname
.size () + 7;
139 mklongpath (wname
, batname
.c_str (), len
);
141 /* if the batch file exists, don't overwrite it */
142 if (GetFileAttributesW (wname
) != INVALID_FILE_ATTRIBUTES
)
145 bat
= nt_wfopen (wname
, "wt", 0755);
150 fprintf (bat
, "@echo off\n\n");
152 fprintf (bat
, "%.2s\n", get_root_dir ().c_str());
153 fprintf (bat
, "chdir %s\n\n",
154 replace(backslash(get_root_dir() + "/bin"), "%", "%%").c_str());
156 fprintf (bat
, "bash --login -i\n");
162 save_icon (std::string
&iconpath
, const char *resource_name
)
164 HRSRC rsrc
= FindResource (NULL
, resource_name
, "FILE");
167 fatal ("FindResource failed");
169 HGLOBAL res
= LoadResource (NULL
, rsrc
);
170 char *data
= (char *) LockResource (res
);
171 int len
= SizeofResource (NULL
, rsrc
);
174 WIN32_FILE_ATTRIBUTE_DATA attr
;
176 size_t ilen
= iconpath
.size () + 7;
178 mklongpath (wname
, iconpath
.c_str (), ilen
);
179 if (GetFileAttributesExW (wname
, GetFileExInfoStandard
, &attr
)
180 && attr
.dwFileAttributes
!= INVALID_FILE_ATTRIBUTES
181 && attr
.nFileSizeLow
> 7022) /* Size of old icon */
184 f
= nt_wfopen (wname
, "wb", 0644);
187 fwrite (data
, 1, len
, f
);
192 #define TARGET "/bin/mintty"
193 #define DEFAULTICON "/Cygwin.ico"
194 #define TERMINALICON "/Cygwin-Terminal.ico"
195 #define TERMINALTITLE (is_64bit ? "Cygwin64 Terminal" \
197 #define STARTMENUDIR "/Cygwin"
202 std::string target
= backslash (cygpath (TARGET
));
203 std::string defaulticon
= backslash (cygpath (DEFAULTICON
));
204 std::string terminalicon
= backslash (cygpath (TERMINALICON
));
206 save_icon (defaulticon
, "CYGWIN.ICON");
207 save_icon (terminalicon
, "CYGWIN-TERMINAL.ICON");
212 start_menu (TERMINALTITLE
, target
, "-i " TERMINALICON
" -", terminalicon
);
215 desktop_icon (TERMINALTITLE
, target
, "-i " TERMINALICON
" -", terminalicon
);
218 static int da
[] = { IDC_ROOT_DESKTOP
, 0 };
219 static int ma
[] = { IDC_ROOT_MENU
, 0 };
222 check_if_enable_next (HWND h
)
224 EnableWindow (GetDlgItem (h
, IDOK
), 1);
230 char buf
[1000], fmt
[1000];
231 if (LoadString (hinstance
, Logger ().getExitMsg (), fmt
, sizeof (fmt
)) > 0)
233 snprintf (buf
, 1000, fmt
,
234 backslash (Logger ().getFileName (LOG_BABBLE
)).c_str ());
235 eset (h
, IDC_STATUS
, buf
);
239 static char *header_string
= NULL
;
240 static char *message_string
= NULL
;
244 if (source
== IDC_SOURCE_DOWNLOAD
)
246 // Don't need the checkboxes
247 EnableWindow (GetDlgItem (h
, IDC_ROOT_DESKTOP
), FALSE
);
248 EnableWindow (GetDlgItem (h
, IDC_ROOT_MENU
), FALSE
);
249 if (header_string
== NULL
)
250 header_string
= eget (h
, IDC_STATIC_HEADER_TITLE
, header_string
);
251 if (message_string
== NULL
)
252 message_string
= eget (h
, IDC_STATIC_HEADER
, message_string
);
253 eset (h
, IDC_STATIC_HEADER_TITLE
, "Installation complete");
254 eset (h
, IDC_STATIC_HEADER
, "Shows installation status in download-only mode.");
258 EnableWindow (GetDlgItem (h
, IDC_ROOT_DESKTOP
), TRUE
);
259 EnableWindow (GetDlgItem (h
, IDC_ROOT_MENU
), TRUE
);
260 if (header_string
!= NULL
)
261 eset (h
, IDC_STATIC_HEADER_TITLE
, header_string
);
262 if (message_string
!= NULL
)
263 eset (h
, IDC_STATIC_HEADER
, message_string
);
264 rbset (h
, da
, root_desktop
);
265 rbset (h
, ma
, root_menu
);
267 check_if_enable_next (h
);
272 check_desktop (const std::string title
, const std::string target
)
274 /* Special folders always < MAX_PATH. */
277 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
278 SHGetSpecialFolderLocation (NULL
,
279 issystem
? CSIDL_COMMON_DESKTOPDIRECTORY
:
280 CSIDL_DESKTOPDIRECTORY
, &id
);
281 SHGetPathFromIDList (id
, path
);
282 LogBabblePrintf ("Desktop directory for desktop link: %s", path
);
283 std::string fname
= std::string(path
) + "/" + title
+ ".lnk";
285 if (_access (fname
.c_str(), 0) == 0)
286 return 0; /* already exists */
288 return IDC_ROOT_DESKTOP
;
292 check_startmenu (const std::string title
, const std::string target
)
294 /* Special folders always < MAX_PATH. */
297 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
298 SHGetSpecialFolderLocation (NULL
,
299 issystem
? CSIDL_COMMON_PROGRAMS
:
300 CSIDL_PROGRAMS
, &id
);
301 SHGetPathFromIDList (id
, path
);
302 LogBabblePrintf ("Program directory for program link: %s", path
);
303 strcat (path
, STARTMENUDIR
);
304 std::string fname
= std::string(path
) + "/" + title
+ ".lnk";
306 if (_access (fname
.c_str(), 0) == 0)
307 return 0; /* already exists */
309 return IDC_ROOT_MENU
;
315 root_desktop
= rbget (h
, da
);
316 root_menu
= rbget (h
, ma
);
320 dialog_cmd (HWND h
, int id
, HWND hwndctl
, UINT code
)
325 case IDC_ROOT_DESKTOP
:
328 check_if_enable_next (h
);
335 DesktopSetupPage::Create ()
337 return PropertyPage::Create (NULL
, dialog_cmd
, IDD_DESKTOP
);
341 DesktopSetupPage::OnInit ()
343 SetDlgItemFont(IDC_STATUS_HEADER
, "MS Shell Dlg", 8, FW_BOLD
);
347 DesktopSetupPage::OnActivate ()
349 if (NoShortcutsOption
|| source
== IDC_SOURCE_DOWNLOAD
)
351 root_desktop
= root_menu
= 0;
355 std::string target
= backslash (cygpath (TARGET
));
357 if (NoStartMenuOption
)
363 root_menu
= check_startmenu (TERMINALTITLE
, target
);
372 root_desktop
= check_desktop (TERMINALTITLE
, target
);
376 load_dialog (GetHWND ());
380 DesktopSetupPage::OnBack ()
388 DesktopSetupPage::OnFinish ()
392 if (source
!= IDC_SOURCE_DOWNLOAD
)
399 DesktopSetupPage::OnUnattended ()
401 Window::PostMessageNow (WM_APP_UNATTENDED_FINISH
);
402 // GetOwner ()->PressButton(PSBTN_FINISH);
407 DesktopSetupPage::OnMessageApp (UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
411 case WM_APP_UNATTENDED_FINISH
:
413 GetOwner ()->PressButton(PSBTN_FINISH
);