2 * Copyright (c) 2000, 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
38 void make_link_2 (char *exepath
, char *args
, char *icon
, char *lname
);
41 char *etc_profile
[] = {
42 "PATH=/bin:/usr/bin:/usr/local/bin:$PATH",
48 "if [ ! -f /etc/group ]; then",
49 " echo Creating /etc/group",
50 " mkgroup -l >/etc/group",
55 "# Set up USER's home directory",
56 "if [ -z \"$HOME\" ]; then",
60 "if [ ! -d $HOME ]; then",
66 "for i in /etc/profile.d/*.sh ; do",
67 " if [ -f $i ]; then",
72 "export PS1='\033]0;\\w\a",
73 "\033[32m\\u@\\h \033[33m\\w\033[0m",
80 #define COMMAND9XARGS "/E:4096 /c"
81 #define COMMAND9XEXE "\\command.com"
84 static char *iconname
;
89 for (char *t
= s
; *t
; t
++)
96 make_link (char *linkpath
, char *title
, char *target
)
98 char argbuf
[_MAX_PATH
];
99 char *fname
= concat (linkpath
, "/", title
, ".lnk", 0);
101 if (_access (fname
, 0) == 0)
102 return; /* already exists */
104 msg ("make_link %s, %s, %s\n", fname
, title
, target
);
108 char *exepath
, *args
;
109 OSVERSIONINFO verinfo
;
110 verinfo
.dwOSVersionInfoSize
= sizeof (verinfo
);
112 /* If we are running Win9x, build a command line. */
113 GetVersionEx (&verinfo
);
114 if (verinfo
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
122 char windir
[MAX_PATH
];
124 GetWindowsDirectory (windir
, sizeof (windir
));
125 exepath
= concat (windir
, COMMAND9XEXE
, 0);
126 sprintf (argbuf
, "%s %s", COMMAND9XARGS
, target
);
130 msg ("make_link_2 (%s, %s, %s, %s)", exepath
, args
, iconname
, fname
);
131 make_link_2 (exepath
, args
, iconname
, fname
);
135 start_menu (char *title
, char *target
)
137 char path
[_MAX_PATH
];
139 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
140 SHGetSpecialFolderLocation (NULL
, issystem
? CSIDL_COMMON_PROGRAMS
: CSIDL_PROGRAMS
, &id
);
141 SHGetPathFromIDList (id
, path
);
142 strcat (path
, "/Cygnus Solutions");
143 make_link (path
, title
, target
);
147 desktop_icon (char *title
, char *target
)
149 char path
[_MAX_PATH
];
151 int issystem
= (root_scope
== IDC_ROOT_SYSTEM
) ? 1 : 0;
152 SHGetSpecialFolderLocation (NULL
, issystem
? CSIDL_DESKTOP
: CSIDL_COMMON_DESKTOPDIRECTORY
, &id
);
153 SHGetPathFromIDList (id
, path
);
154 make_link (path
, title
, target
);
160 batname
= backslash (concat (root_dir
, "/cygwin.bat", 0));
162 /* if the batch file exists, don't overwrite it */
163 if (_access (batname
, 0) == 0)
166 FILE *bat
= fopen (batname
, "wt");
170 fprintf (bat
, "@echo off\n\n");
172 fprintf (bat
, "SET MAKE_MODE=unix\n");
174 char *bin
= backslash (concat (root_dir
, "/bin", 0));
175 char *usrbin
= backslash (concat (root_dir
, "/usr/bin", 0));
176 char *usrlocalbin
= backslash (concat (root_dir
, "/usr/local/bin", 0));
178 fprintf (bat
, "SET PATH=%s;%s;%s;\"%%PATH%%\"\n", usrlocalbin
, usrbin
, bin
);
180 fprintf (bat
, "%.2s\n", root_dir
);
181 fprintf (bat
, "chdir %s\n\n", backslash (_strdup (root_dir
+2)));
183 fprintf (bat
, "bash --login -i\n");
195 char *fname
= concat (root_dir
, "/etc/profile", 0);
197 /* if the file exists, don't overwrite it */
198 if (_access (fname
, 0) == 0)
201 FILE *p
= fopen (fname
, "wb");
206 for (i
=0; etc_profile
[i
]; i
++)
207 fprintf (p
, "%s\n", etc_profile
[i
]);
215 iconname
= backslash (concat (root_dir
, "/cygwin.ico", 0));
217 HRSRC rsrc
= FindResource (NULL
, "CYGWIN.ICON", "FILE");
220 fatal ("FindResource failed");
222 HGLOBAL res
= LoadResource (NULL
, rsrc
);
223 char *data
= (char *) LockResource (res
);
224 int len
= SizeofResource (NULL
, rsrc
);
226 FILE *f
= fopen (iconname
, "wb");
229 fwrite (data
, 1, len
, f
);
235 do_desktop (HINSTANCE h
)
244 start_menu ("Cygwin 1.1 Bash Shell", batname
);
246 desktop_icon ("Cygwin", batname
);