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 BoolOption
NoShortcutsOption (false, 'n', "no-shortcuts", IDS_HELPTEXT_NO_SHORTCUTS
);
44 BoolOption
NoStartMenuOption (false, 'N', "no-startmenu", IDS_HELPTEXT_NO_STARTMENU
);
45 static BoolOption
NoDesktopOption (false, 'd', "no-desktop", IDS_HELPTEXT_NO_DESKTOP
);
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());
98 const char *startmenusuffix()
100 if (!is_64bit
&& (WowNativeMachine() != IMAGE_FILE_MACHINE_I386
))
103 if (WowNativeMachine() != IMAGE_FILE_MACHINE_AMD64
)
110 static const char *startmenudir()
116 start_menu (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_PROGRAMS
:
125 CSIDL_PROGRAMS
, &id
);
126 SHGetPathFromIDList (id
, path
);
127 strncat (path
, startmenudir(), MAX_PATH
- strlen(path
) - 1);
128 strncat (path
, startmenusuffix(), MAX_PATH
- strlen(path
) - 1);
129 LogBabblePrintf ("Program directory for program link: %s", path
);
130 make_link (path
, title
, target
, arg
, iconpath
);
134 desktop_icon (const std::string
& title
, const std::string
& target
,
135 const std::string
& arg
, const std::string
& iconpath
)
137 /* Special folders always < MAX_PATH. */
140 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
141 SHGetSpecialFolderLocation (NULL
,
142 issystem
? CSIDL_COMMON_DESKTOPDIRECTORY
:
143 CSIDL_DESKTOPDIRECTORY
, &id
);
144 SHGetPathFromIDList (id
, path
);
145 LogBabblePrintf ("Desktop directory for desktop link: %s", path
);
146 make_link (path
, title
, target
, arg
, iconpath
);
152 batname
= backslash (cygpath ("/Cygwin.bat"));
155 size_t len
= batname
.size () + 7;
157 mklongpath (wname
, batname
.c_str (), len
);
159 /* if the batch file exists, don't overwrite it */
160 if (GetFileAttributesW (wname
) != INVALID_FILE_ATTRIBUTES
)
163 bat
= nt_wfopen (wname
, "wt", 0755);
168 fprintf (bat
, "@echo off\n\n");
170 fprintf (bat
, "%.2s\n", get_root_dir ().c_str());
171 fprintf (bat
, "chdir %s\n\n",
172 replace(backslash(get_root_dir() + "/bin"), "%", "%%").c_str());
174 fprintf (bat
, "bash --login -i\n");
180 save_icon (std::string
&iconpath
, const char *resource_name
)
182 HRSRC rsrc
= FindResource (NULL
, resource_name
, "FILE");
185 Log (LOG_PLAIN
) << "FindResource failed" << GetLastError() << endLog
;
189 HGLOBAL res
= LoadResource (NULL
, rsrc
);
190 char *data
= (char *) LockResource (res
);
191 int len
= SizeofResource (NULL
, rsrc
);
194 WIN32_FILE_ATTRIBUTE_DATA attr
;
196 size_t ilen
= iconpath
.size () + 7;
198 mklongpath (wname
, iconpath
.c_str (), ilen
);
199 if (GetFileAttributesExW (wname
, GetFileExInfoStandard
, &attr
)
200 && attr
.dwFileAttributes
!= INVALID_FILE_ATTRIBUTES
201 && attr
.nFileSizeLow
> 7022) /* Size of old icon */
204 f
= nt_wfopen (wname
, "wb", 0644);
207 fwrite (data
, 1, len
, f
);
212 #define TARGET "/bin/mintty"
213 #define DEFAULTICON "/Cygwin.ico"
214 #define TERMINALICON "/Cygwin-Terminal.ico"
215 #define TERMINALTITLE (is_64bit ? "Cygwin64 Terminal" \
221 std::string target
= backslash (cygpath (TARGET
));
222 std::string defaulticon
= backslash (cygpath (DEFAULTICON
));
223 std::string terminalicon
= backslash (cygpath (TERMINALICON
));
225 save_icon (defaulticon
, "CYGWIN.ICON");
226 save_icon (terminalicon
, "CYGWIN-TERMINAL.ICON");
231 start_menu (TERMINALTITLE
, target
, "-i " TERMINALICON
" -", terminalicon
);
234 desktop_icon (TERMINALTITLE
, target
, "-i " TERMINALICON
" -", terminalicon
);
237 static int da
[] = { IDC_ROOT_DESKTOP
, 0 };
238 static int ma
[] = { IDC_ROOT_MENU
, 0 };
241 check_if_enable_next (HWND h
)
243 EnableWindow (GetDlgItem (h
, IDOK
), 1);
249 std::wstring fmt
= LoadStringW(Logger ().getExitMsg ());
250 std::wstring buf
= format(fmt
, backslash (Logger ().getFileName (LOG_BABBLE
)).c_str ());
251 eset (h
, IDC_STATUS
, buf
);
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 ShowWindow (GetDlgItem(h
, IDC_DESKTOP_HEADER_DOWNLOAD
), SW_SHOW
);
263 ShowWindow (GetDlgItem(h
, IDC_DESKTOP_HEADER_TITLE_DOWNLOAD
), SW_SHOW
);
264 ShowWindow (GetDlgItem(h
, IDC_DESKTOP_HEADER_INSTALL
), SW_HIDE
);
265 ShowWindow (GetDlgItem(h
, IDC_DESKTOP_HEADER_TITLE_INSTALL
), SW_HIDE
);
269 EnableWindow (GetDlgItem (h
, IDC_ROOT_DESKTOP
), TRUE
);
270 EnableWindow (GetDlgItem (h
, IDC_ROOT_MENU
), TRUE
);
271 ShowWindow (GetDlgItem(h
, IDC_DESKTOP_HEADER_DOWNLOAD
), SW_HIDE
);
272 ShowWindow (GetDlgItem(h
, IDC_DESKTOP_HEADER_TITLE_DOWNLOAD
), SW_HIDE
);
273 ShowWindow (GetDlgItem(h
, IDC_DESKTOP_HEADER_INSTALL
), SW_SHOW
);
274 ShowWindow (GetDlgItem(h
, IDC_DESKTOP_HEADER_TITLE_INSTALL
), SW_SHOW
);
275 rbset (h
, da
, root_desktop
);
276 rbset (h
, ma
, root_menu
);
278 check_if_enable_next (h
);
283 check_desktop (const std::string title
, const std::string target
)
285 /* Special folders always < MAX_PATH. */
288 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
289 SHGetSpecialFolderLocation (NULL
,
290 issystem
? CSIDL_COMMON_DESKTOPDIRECTORY
:
291 CSIDL_DESKTOPDIRECTORY
, &id
);
292 SHGetPathFromIDList (id
, path
);
293 LogBabblePrintf ("Desktop directory for desktop link: %s", path
);
294 std::string fname
= std::string(path
) + "/" + title
+ ".lnk";
296 if (_access (fname
.c_str(), 0) == 0)
297 return 0; /* already exists */
299 return IDC_ROOT_DESKTOP
;
303 check_startmenu (const std::string title
, const std::string target
)
305 /* Special folders always < MAX_PATH. */
308 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
309 SHGetSpecialFolderLocation (NULL
,
310 issystem
? CSIDL_COMMON_PROGRAMS
:
311 CSIDL_PROGRAMS
, &id
);
312 SHGetPathFromIDList (id
, path
);
313 LogBabblePrintf ("Program directory for program link: %s", path
);
314 strcat (path
, startmenudir());
315 strcat (path
, startmenusuffix());
316 std::string fname
= std::string(path
) + "/" + title
+ ".lnk";
318 if (_access (fname
.c_str(), 0) == 0)
319 return 0; /* already exists */
321 return IDC_ROOT_MENU
;
327 root_desktop
= rbget (h
, da
);
328 root_menu
= rbget (h
, ma
);
332 dialog_cmd (HWND h
, int id
, HWND hwndctl
, UINT code
)
337 case IDC_ROOT_DESKTOP
:
340 check_if_enable_next (h
);
347 DesktopSetupPage::Create ()
349 return PropertyPage::Create (NULL
, dialog_cmd
, IDD_DESKTOP
);
353 DesktopSetupPage::OnInit ()
355 SetDlgItemFont(IDC_STATUS_HEADER
, "MS Shell Dlg", 8, FW_BOLD
);
359 DesktopSetupPage::OnActivate ()
361 if (NoShortcutsOption
|| source
== IDC_SOURCE_DOWNLOAD
)
363 root_desktop
= root_menu
= 0;
367 std::string target
= backslash (cygpath (TARGET
));
369 if (NoStartMenuOption
)
375 root_menu
= check_startmenu (TERMINALTITLE
, target
);
384 root_desktop
= check_desktop (TERMINALTITLE
, target
);
388 load_dialog (GetHWND ());
392 DesktopSetupPage::OnBack ()
400 DesktopSetupPage::OnFinish ()
404 if (source
!= IDC_SOURCE_DOWNLOAD
)
411 DesktopSetupPage::OnUnattended ()
413 Window::PostMessageNow (WM_APP_UNATTENDED_FINISH
);
414 // GetOwner ()->PressButton(PSBTN_FINISH);
419 DesktopSetupPage::OnMessageApp (UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
423 case WM_APP_UNATTENDED_FINISH
:
425 GetOwner ()->PressButton(PSBTN_FINISH
);