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
45 void make_link_2 (char *exepath, char *args, char *icon, char *lname);
48 static OSVERSIONINFO verinfo;
50 /* Lines starting with '@' are conditionals - include 'N' for NT,
51 '5' for Win95, '8' for Win98, '*' for all, like this:
58 #define COMMAND9XARGS "/E:4096 /c"
59 #define COMMAND9XEXE "\\command.com"
61 static char *iconname;
65 make_link (char *linkpath, char *title, char *target)
67 char argbuf[_MAX_PATH];
68 char *fname = concat (linkpath, "/", title, ".lnk", 0);
70 if (_access (fname, 0) == 0)
71 return; /* already exists */
73 msg ("make_link %s, %s, %s\n", fname, title, target);
79 /* If we are running Win9x, build a command line. */
80 if (verinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
87 char windir[MAX_PATH];
89 GetWindowsDirectory (windir, sizeof (windir));
90 exepath = concat (windir, COMMAND9XEXE, 0);
91 sprintf (argbuf, "%s %s", COMMAND9XARGS, target);
95 msg ("make_link_2 (%s, %s, %s, %s)", exepath, args, iconname, fname);
96 make_link_2 (exepath, args, iconname, fname);
100 find_xemacs_exe_path ()
102 if (xemacs_package->type == TY_CYGWIN)
103 return backslash (concat (root_dir, "/bin/", XEMACS_CYGWIN_ARCH_NAME, 0));
105 return backslash (concat (root_dir, "\\XEmacs-",
106 xemacs_package->info[xemacs_package->trust].version,
107 "\\", XEMACS_NATIVE_ARCH_NAME, 0));
111 find_xemacs_exe_name ()
113 if (xemacs_package->type == TY_CYGWIN)
114 return backslash (concat ("xemacs-",
115 xemacs_package->info[xemacs_package->trust].version,
118 return strdup ("xemacs.exe");
122 start_menu (char *title, char *target)
124 char path[_MAX_PATH];
126 int issystem = (root_scope == IDC_ROOT_SYSTEM) ? 1 : 0;
127 SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_COMMON_PROGRAMS : CSIDL_PROGRAMS, &id);
128 SHGetPathFromIDList (id, path);
129 // following lines added because it appears Win95 does not use common programs
130 // unless it comes into play when multiple users for Win95 is enabled
131 msg("Program directory for program link: %s",path);
132 if ( strlen(path) == 0) {
133 SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id);
134 SHGetPathFromIDList (id, path);
135 msg("Program directory for program link changed to: %s",path);
137 // end of Win95 addition
139 strcat (path, XEMACS_INFO_XEMACS_ORG_REGISTRY_NAME);
140 make_link (path, title, target);
144 desktop_icon (char *title, char *target)
146 char path[_MAX_PATH];
148 int issystem = (root_scope == IDC_ROOT_SYSTEM) ? 1 : 0;
149 //SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_DESKTOP : CSIDL_COMMON_DESKTOPDIRECTORY, &id);
150 SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_COMMON_DESKTOPDIRECTORY : 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) {
156 SHGetSpecialFolderLocation (NULL, CSIDL_DESKTOPDIRECTORY, &id);
157 SHGetPathFromIDList (id, path);
158 msg("Desktop directory for deskop link changed to: %s",path);
160 // end of Win95 addition
161 make_link (path, title, target);
167 char *f = concat (root_dir, path, 0);
168 int a = _access (f, 0);
178 if (verinfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
184 if (!strcmp (package[i].name, "cygwin"))
186 /* mkpasswd and mkgroup are not working on 9x/ME up to 1.1.5-4 */
187 char *border_version = canonicalize_version ("1.1.5-4");
188 char *inst_version = canonicalize_version (pi.version);
190 if (strcmp (inst_version, border_version) <= 0)
198 if (uexists ("/etc/passwd") && uexists ("/etc/group"))
201 char *fname = concat (root_dir, "/etc/postinstall/passwd-grp.bat", 0);
204 FILE *p = fopen (fname, "wb");
208 if (!uexists ("/etc/passwd"))
209 fprintf (p, "bin\\mkpasswd -l > etc\\passwd\n");
210 if (!uexists ("/etc/group"))
211 fprintf (p, "bin\\mkgroup -l > etc\\group\n");
219 iconname = backslash (concat (root_dir, XEMACS_RESOURCE_DIR,
222 HRSRC rsrc = FindResource (NULL, "XEMACS.ICON", "FILE");
225 fatal ("FindResource failed");
227 HGLOBAL res = LoadResource (NULL, rsrc);
228 char *data = (char *) LockResource (res);
229 int len = SizeofResource (NULL, rsrc);
231 FILE *f = fopen (iconname, "wb");
234 fwrite (data, 1, len, f);
244 if (root_menu && batname) {
245 start_menu ("XEmacs", batname);
248 if (root_desktop && batname) {
249 desktop_icon ("XEmacs", batname);
252 // set regkeys for the application
253 if (xemacs_package != 0)
255 int issystem = (root_scope == IDC_ROOT_SYSTEM ? 1 : 0);
256 if (xemacs_package->type == TY_NATIVE)
258 #define FROB(exe) set_app_path ((exe), \
259 find_xemacs_exe_path (), \
261 FROB (find_xemacs_exe_name ());
262 FROB ("runemacs.exe");
266 else if (xemacs_package->type == TY_CYGWIN)
269 char* root = find_cygwin_root (&junk);
270 #define FROB(exe) set_app_path ((exe), \
271 concat (find_xemacs_exe_path (), ";", \
273 root, "\\usr\\bin", 0), \
275 FROB (find_xemacs_exe_name ());
276 FROB ("runemacs.exe");
283 static int da[] = { IDC_ROOT_DESKTOP, 0 };
284 static int ma[] = { IDC_ROOT_MENU, 0 };
287 check_if_enable_next (HWND h)
289 EnableWindow (GetDlgItem (h, IDOK), 1);
295 rbset (h, da, root_desktop);
296 rbset (h, ma, root_menu);
297 check_if_enable_next (h);
300 static int check_desktop (char *title, char *target)
302 char path[_MAX_PATH];
304 int issystem = (root_scope == IDC_ROOT_SYSTEM) ? 1 : 0;
305 SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_COMMON_DESKTOPDIRECTORY : CSIDL_DESKTOPDIRECTORY, &id);
306 SHGetPathFromIDList (id, path);
307 // following lines added because it appears Win95 does not use common programs
308 // unless it comes into play when multiple users for Win95 is enabled
309 msg ("Desktop directory for desktop link: %s",path);
310 if (strlen (path) == 0) {
311 SHGetSpecialFolderLocation (NULL, CSIDL_DESKTOPDIRECTORY, &id);
312 SHGetPathFromIDList (id, path);
313 msg ("Desktop directory for deskop link changed to: %s",path);
315 // end of Win95 addition
316 char *fname = concat (path, "/", title, ".lnk", 0);
318 if (_access (fname, 0) == 0)
319 return 0; /* already exists */
321 fname = concat (path, "/", title, ".pif", 0); /* check for a pif as well */
323 if (_access (fname, 0) == 0)
324 return 0; /* already exists */
326 return IDC_ROOT_DESKTOP;
329 static int check_startmenu (char *title, char *target)
331 char path[_MAX_PATH];
333 int issystem = (root_scope == IDC_ROOT_SYSTEM) ? 1 : 0;
334 SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_COMMON_PROGRAMS : CSIDL_PROGRAMS, &id);
335 SHGetPathFromIDList (id, path);
336 // following lines added because it appears Win95 does not use common programs
337 // unless it comes into play when multiple users for Win95 is enabled
338 msg ("Program directory for program link: %s",path);
339 if (strlen (path) == 0) {
340 SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id);
341 SHGetPathFromIDList (id, path);
342 msg ("Program directory for program link changed to: %s",path);
344 // end of Win95 addition
346 strcat (path, XEMACS_INFO_XEMACS_ORG_REGISTRY_NAME);
347 char *fname = concat (path, "/", title, ".lnk", 0);
349 if (_access (fname, 0) == 0)
350 return 0; /* already exists */
352 fname = concat (path, "/", title, ".pif", 0); /* check for a pif as well */
354 if (_access (fname, 0) == 0)
355 return 0; /* already exists */
357 return IDC_ROOT_MENU;
363 root_desktop= rbget (h, da);
364 root_menu = rbget (h, ma);
368 dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
373 case IDC_ROOT_DESKTOP:
376 check_if_enable_next (h);
382 NEXT (IDD_S_POSTINSTALL);
398 dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
406 return HANDLE_WM_COMMAND (h, wParam, lParam, dialog_cmd);
412 do_desktop (HINSTANCE h)
416 verinfo.dwOSVersionInfoSize = sizeof (verinfo);
417 GetVersionEx (&verinfo);
420 if (xemacs_package != 0 && xemacs_package->type != TY_GENERIC)
422 batname = concat (find_xemacs_exe_path (), "\\",
424 find_xemacs_exe_name (),
429 root_desktop = check_desktop ("XEmacs", batname);
430 root_menu = check_startmenu ("XEmacs", batname);
440 rv = DialogBox (h, MAKEINTRESOURCE (IDD_DESKTOP), 0, dialog_proc);
442 fatal (IDS_DIALOG_FAILED);