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 /* Hack to support older versions. */
114 if (strncmp (xemacs_package->info[xemacs_package->trust].version,
116 return strdup ("runemacs.exe");
117 else if (xemacs_package->type == TY_CYGWIN)
118 return backslash (concat ("xemacs-",
119 xemacs_package->info[xemacs_package->trust].version,
122 return strdup ("xemacs.exe");
126 start_menu (char *title, char *target)
128 char path[_MAX_PATH];
130 int issystem = (root_scope == IDC_ROOT_SYSTEM) ? 1 : 0;
131 SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_COMMON_PROGRAMS : CSIDL_PROGRAMS, &id);
132 SHGetPathFromIDList (id, path);
133 // following lines added because it appears Win95 does not use common programs
134 // unless it comes into play when multiple users for Win95 is enabled
135 msg("Program directory for program link: %s",path);
136 if ( strlen(path) == 0) {
137 SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id);
138 SHGetPathFromIDList (id, path);
139 msg("Program directory for program link changed to: %s",path);
141 // end of Win95 addition
143 strcat (path, XEMACS_INFO_XEMACS_ORG_REGISTRY_NAME);
144 make_link (path, title, target);
148 desktop_icon (char *title, char *target)
150 char path[_MAX_PATH];
152 int issystem = (root_scope == IDC_ROOT_SYSTEM) ? 1 : 0;
153 //SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_DESKTOP : CSIDL_COMMON_DESKTOPDIRECTORY, &id);
154 SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_COMMON_DESKTOPDIRECTORY : CSIDL_DESKTOPDIRECTORY, &id);
155 SHGetPathFromIDList (id, path);
156 // following lines added because it appears Win95 does not use common programs
157 // unless it comes into play when multiple users for Win95 is enabled
158 msg("Desktop directory for desktop link: %s",path);
159 if ( strlen(path) == 0) {
160 SHGetSpecialFolderLocation (NULL, CSIDL_DESKTOPDIRECTORY, &id);
161 SHGetPathFromIDList (id, path);
162 msg("Desktop directory for deskop link changed to: %s",path);
164 // end of Win95 addition
165 make_link (path, title, target);
171 char *f = concat (root_dir, path, 0);
172 int a = _access (f, 0);
182 if (verinfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
188 if (!strcmp (package[i].name, "cygwin"))
190 /* mkpasswd and mkgroup are not working on 9x/ME up to 1.1.5-4 */
191 char *border_version = canonicalize_version ("1.1.5-4");
192 char *inst_version = canonicalize_version (pi.version);
194 if (strcmp (inst_version, border_version) <= 0)
202 if (uexists ("/etc/passwd") && uexists ("/etc/group"))
205 char *fname = concat (root_dir, "/etc/postinstall/passwd-grp.bat", 0);
208 FILE *p = fopen (fname, "wb");
212 if (!uexists ("/etc/passwd"))
213 fprintf (p, "bin\\mkpasswd -l > etc\\passwd\n");
214 if (!uexists ("/etc/group"))
215 fprintf (p, "bin\\mkgroup -l > etc\\group\n");
223 iconname = backslash (concat (root_dir, XEMACS_RESOURCE_DIR,
226 HRSRC rsrc = FindResource (NULL, "XEMACS.ICON", "FILE");
229 fatal ("FindResource failed");
231 HGLOBAL res = LoadResource (NULL, rsrc);
232 char *data = (char *) LockResource (res);
233 int len = SizeofResource (NULL, rsrc);
235 FILE *f = fopen (iconname, "wb");
238 fwrite (data, 1, len, f);
248 if (root_menu && batname) {
249 start_menu ("XEmacs", batname);
252 if (root_desktop && batname) {
253 desktop_icon ("XEmacs", batname);
256 // set regkeys for the application
257 if (xemacs_package != 0)
259 int issystem = (root_scope == IDC_ROOT_SYSTEM ? 1 : 0);
260 if (xemacs_package->type == TY_NATIVE)
262 #define FROB(exe) set_app_path ((exe), \
263 find_xemacs_exe_path (), \
265 FROB (find_xemacs_exe_name ());
266 FROB ("runemacs.exe");
270 else if (xemacs_package->type == TY_CYGWIN)
273 char* root = find_cygwin_root (&junk);
274 #define FROB(exe) set_app_path ((exe), \
275 concat (find_xemacs_exe_path (), ";", \
277 root, "\\usr\\bin", 0), \
279 FROB (find_xemacs_exe_name ());
280 FROB ("runemacs.exe");
287 static int da[] = { IDC_ROOT_DESKTOP, 0 };
288 static int ma[] = { IDC_ROOT_MENU, 0 };
291 check_if_enable_next (HWND h)
293 EnableWindow (GetDlgItem (h, IDOK), 1);
299 rbset (h, da, root_desktop);
300 rbset (h, ma, root_menu);
301 check_if_enable_next (h);
304 static int check_desktop (char *title, char *target)
306 char path[_MAX_PATH];
308 int issystem = (root_scope == IDC_ROOT_SYSTEM) ? 1 : 0;
309 SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_COMMON_DESKTOPDIRECTORY : CSIDL_DESKTOPDIRECTORY, &id);
310 SHGetPathFromIDList (id, path);
311 // following lines added because it appears Win95 does not use common programs
312 // unless it comes into play when multiple users for Win95 is enabled
313 msg ("Desktop directory for desktop link: %s",path);
314 if (strlen (path) == 0) {
315 SHGetSpecialFolderLocation (NULL, CSIDL_DESKTOPDIRECTORY, &id);
316 SHGetPathFromIDList (id, path);
317 msg ("Desktop directory for deskop link changed to: %s",path);
319 // end of Win95 addition
320 char *fname = concat (path, "/", title, ".lnk", 0);
322 if (_access (fname, 0) == 0)
323 return 0; /* already exists */
325 fname = concat (path, "/", title, ".pif", 0); /* check for a pif as well */
327 if (_access (fname, 0) == 0)
328 return 0; /* already exists */
330 return IDC_ROOT_DESKTOP;
333 static int check_startmenu (char *title, char *target)
335 char path[_MAX_PATH];
337 int issystem = (root_scope == IDC_ROOT_SYSTEM) ? 1 : 0;
338 SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_COMMON_PROGRAMS : CSIDL_PROGRAMS, &id);
339 SHGetPathFromIDList (id, path);
340 // following lines added because it appears Win95 does not use common programs
341 // unless it comes into play when multiple users for Win95 is enabled
342 msg ("Program directory for program link: %s",path);
343 if (strlen (path) == 0) {
344 SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id);
345 SHGetPathFromIDList (id, path);
346 msg ("Program directory for program link changed to: %s",path);
348 // end of Win95 addition
350 strcat (path, XEMACS_INFO_XEMACS_ORG_REGISTRY_NAME);
351 char *fname = concat (path, "/", title, ".lnk", 0);
353 if (_access (fname, 0) == 0)
354 return 0; /* already exists */
356 fname = concat (path, "/", title, ".pif", 0); /* check for a pif as well */
358 if (_access (fname, 0) == 0)
359 return 0; /* already exists */
361 return IDC_ROOT_MENU;
367 root_desktop= rbget (h, da);
368 root_menu = rbget (h, ma);
372 dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
377 case IDC_ROOT_DESKTOP:
380 check_if_enable_next (h);
386 NEXT (IDD_S_POSTINSTALL);
402 dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
410 return HANDLE_WM_COMMAND (h, wParam, lParam, dialog_cmd);
416 do_desktop (HINSTANCE h)
420 verinfo.dwOSVersionInfoSize = sizeof (verinfo);
421 GetVersionEx (&verinfo);
424 if (xemacs_package != 0 && xemacs_package->type != TY_GENERIC)
426 batname = concat (find_xemacs_exe_path (), "\\",
427 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);