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
46 void make_link_2 (char *exepath, char *args, char *icon, char *lname);
49 static OSVERSIONINFO verinfo;
51 /* Lines starting with '@' are conditionals - include 'N' for NT,
52 '5' for Win95, '8' for Win98, '*' for all, like this:
59 #define COMMAND9XARGS "/E:4096 /c"
60 #define COMMAND9XEXE "\\command.com"
62 static char *iconname;
64 static char *uninstname;
67 make_link (char *linkpath, char *title, char *target, char* args)
70 char argbuf[_MAX_PATH];
72 char *fname = concat (linkpath, "/", title, ".lnk", 0);
74 if (_access (fname, 0) == 0)
75 return; /* already exists */
77 msg ("make_link %s, %s, %s, %s\n", fname, title, target, args);
83 /* If we are running Win9x, build a command line. */
84 if (verinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
92 char windir[MAX_PATH];
94 GetWindowsDirectory (windir, sizeof (windir));
95 exepath = concat (windir, COMMAND9XEXE, 0);
96 sprintf (argbuf, "%s %s", COMMAND9XARGS, target);
100 msg ("make_link_2 (%s, %s, %s, %s)", exepath, args, iconname, fname);
101 make_link_2 (backslash (exepath), args, iconname, fname);
105 find_xemacs_exe_path ()
107 if (xemacs_package->type == TY_CYGWIN)
108 return backslash (concat (root_dir, "/bin/", XEMACS_CYGWIN_ARCH_NAME, 0));
110 return backslash (concat (root_dir, "\\XEmacs-",
111 xemacs_package->info[xemacs_package->trust].version,
112 "\\", XEMACS_NATIVE_ARCH_NAME, 0));
116 find_xemacs_exe_name ()
118 /* Hack to support older versions. */
119 if (strncmp (xemacs_package->info[xemacs_package->trust].version,
121 return strdup ("runemacs.exe");
122 else if (xemacs_package->type == TY_CYGWIN)
123 return backslash (concat ("xemacs-",
124 xemacs_package->info[xemacs_package->trust].version,
127 return strdup ("xemacs.exe");
131 remove_link (char *linkpath, char* title)
135 char *fname = backslash (concat (linkpath, "/", title, ".lnk", 0));
136 msg ("remove_link %s, %s\n", fname, title);
137 if (_access (fname, 0) != 0)
138 return; /* doesn't exist */
143 msg ("remove_link %s\n", linkpath);
144 if (_access (linkpath, 0) != 0)
145 return; /* doesn't exist */
151 start_menu (char *title, char *target, int rem, char* args)
153 char path[_MAX_PATH];
155 int issystem = (root_scope == IDC_ROOT_SYSTEM) ? 1 : 0;
156 SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_COMMON_PROGRAMS : CSIDL_PROGRAMS, &id);
157 SHGetPathFromIDList (id, path);
158 // following lines added because it appears Win95 does not use common programs
159 // unless it comes into play when multiple users for Win95 is enabled
160 msg("Program directory for program link: %s",path);
161 if ( strlen(path) == 0) {
162 SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id);
163 SHGetPathFromIDList (id, path);
164 msg("Program directory for program link changed to: %s",path);
166 // end of Win95 addition
168 strcat (path, XEMACS_INFO_XEMACS_ORG_REGISTRY_NAME);
170 make_link (path, title, target, args);
172 remove_link (path, title);
176 desktop_icon (char *title, char *target, int rem)
178 char path[_MAX_PATH];
180 int issystem = (root_scope == IDC_ROOT_SYSTEM) ? 1 : 0;
181 //SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_DESKTOP : CSIDL_COMMON_DESKTOPDIRECTORY, &id);
182 SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_COMMON_DESKTOPDIRECTORY : CSIDL_DESKTOPDIRECTORY, &id);
183 SHGetPathFromIDList (id, path);
184 // following lines added because it appears Win95 does not use common programs
185 // unless it comes into play when multiple users for Win95 is enabled
186 msg("Desktop directory for desktop link: %s",path);
187 if ( strlen(path) == 0) {
188 SHGetSpecialFolderLocation (NULL, CSIDL_DESKTOPDIRECTORY, &id);
189 SHGetPathFromIDList (id, path);
190 msg("Desktop directory for deskop link changed to: %s",path);
192 // end of Win95 addition
194 make_link (path, title, target, "");
196 remove_link (path, title);
202 iconname = backslash (concat (root_dir, XEMACS_RESOURCE_DIR,
205 HRSRC rsrc = FindResource (NULL, "XEMACS.ICON", "FILE");
208 fatal ("FindResource failed");
210 HGLOBAL res = LoadResource (NULL, rsrc);
211 char *data = (char *) LockResource (res);
212 int len = SizeofResource (NULL, rsrc);
214 FILE *f = fopen (iconname, "wb");
217 fwrite (data, 1, len, f);
223 remove_desktop_setup()
225 start_menu ("XEmacs", 0, 1, 0);
226 start_menu ("Uninstall XEmacs", 0, 1, 0);
227 start_menu (0, 0, 1, 0);
228 desktop_icon ("XEmacs", 0, 1);
230 if (xemacs_package != 0)
232 #define FROB(exe) remove_app_path (exe)
233 FROB (find_xemacs_exe_name ());
234 FROB ("runemacs.exe");
245 if (root_menu && batname) {
246 start_menu ("XEmacs", batname, 0, "");
247 start_menu ("Uninstall XEmacs", uninstname, 0, "-u");
250 if (root_desktop && batname) {
251 desktop_icon ("XEmacs", batname, 0);
254 // set regkeys for the application
255 if (xemacs_package != 0)
257 int issystem = (root_scope == IDC_ROOT_SYSTEM ? 1 : 0);
258 if (xemacs_package->type == TY_NATIVE
259 || xemacs_package->type == TY_CYGWIN)
261 if (xemacs_package->type == TY_NATIVE)
263 #define FROB(exe) set_app_path ((exe), \
264 find_xemacs_exe_path (), \
266 FROB (find_xemacs_exe_name ());
267 FROB ("runemacs.exe");
271 else if (xemacs_package->type == TY_CYGWIN)
274 char* root = find_cygwin_root (&junk);
275 #define FROB(exe) set_app_path ((exe), \
276 concat (find_xemacs_exe_path (), ";", \
278 root, "\\usr\\bin", 0), \
280 FROB (find_xemacs_exe_name ());
281 FROB ("runemacs.exe");
285 set_install_path (find_xemacs_exe_path(), issystem);
287 // Register file types
292 log (0, "Registering .java files");
293 setup_explorer ("java", "Java Source file", batname);
294 setup_explorer ("jav", "Java Source file", batname);
298 log (0, "Registering .cpp files");
299 setup_explorer ("cpp", "C++ Source file", batname);
300 setup_explorer ("cc", "C++ Source file", batname);
301 setup_explorer ("hh", "C++ Header file", batname);
305 log (0, "Registering .c files");
306 setup_explorer ("c", "C Source file", batname);
307 setup_explorer ("h", "C Header file", batname);
311 log (0, "Registering .el files");
312 setup_explorer ("el", "E-Lisp Source file", batname);
316 log (0, "Registering .txt files");
317 setup_explorer ("txt", "Text file", batname);
321 log (0, "Registering .idl files");
322 setup_explorer ("idl", "OMG IDL file", batname);
328 static int da[] = { IDC_ROOT_DESKTOP, 0 };
329 static int ma[] = { IDC_ROOT_MENU, 0 };
331 static int ct[] = { IDC_C_TYPE, 0 };
332 static int javat[] = { IDC_JAVA_TYPE, 0 };
333 static int cppt[] = { IDC_CPP_TYPE, 0 };
334 static int elispt[] = { IDC_ELISP_TYPE, 0 };
335 static int txtt[] = { IDC_TXT_TYPE, 0 };
336 static int idlt[] = { IDC_IDL_TYPE, 0 };
339 check_if_enable_next (HWND h)
341 EnableWindow (GetDlgItem (h, IDOK), 1);
347 rbset (h, da, root_desktop);
348 rbset (h, ma, root_menu);
349 rbset (h, ct, reg_c);
350 rbset (h, javat, reg_java);
351 rbset (h, cppt, reg_cpp);
352 rbset (h, elispt, reg_elisp);
353 rbset (h, txtt, reg_txt);
354 rbset (h, idlt, reg_idl);
355 check_if_enable_next (h);
358 static int check_desktop (char *title, char *target)
360 char path[_MAX_PATH];
362 int issystem = (root_scope == IDC_ROOT_SYSTEM) ? 1 : 0;
363 SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_COMMON_DESKTOPDIRECTORY : CSIDL_DESKTOPDIRECTORY, &id);
364 SHGetPathFromIDList (id, path);
365 // following lines added because it appears Win95 does not use common programs
366 // unless it comes into play when multiple users for Win95 is enabled
367 msg ("Desktop directory for desktop link: %s",path);
368 if (strlen (path) == 0) {
369 SHGetSpecialFolderLocation (NULL, CSIDL_DESKTOPDIRECTORY, &id);
370 SHGetPathFromIDList (id, path);
371 msg ("Desktop directory for deskop link changed to: %s",path);
373 // end of Win95 addition
374 char *fname = concat (path, "/", title, ".lnk", 0);
376 if (_access (fname, 0) == 0)
377 return 0; /* already exists */
379 fname = concat (path, "/", title, ".pif", 0); /* check for a pif as well */
381 if (_access (fname, 0) == 0)
382 return 0; /* already exists */
384 return IDC_ROOT_DESKTOP;
387 static int check_startmenu (char *title, char *target)
389 char path[_MAX_PATH];
391 int issystem = (root_scope == IDC_ROOT_SYSTEM) ? 1 : 0;
392 SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_COMMON_PROGRAMS : CSIDL_PROGRAMS, &id);
393 SHGetPathFromIDList (id, path);
394 // following lines added because it appears Win95 does not use common programs
395 // unless it comes into play when multiple users for Win95 is enabled
396 msg ("Program directory for program link: %s",path);
397 if (strlen (path) == 0) {
398 SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id);
399 SHGetPathFromIDList (id, path);
400 msg ("Program directory for program link changed to: %s",path);
402 // end of Win95 addition
404 strcat (path, XEMACS_INFO_XEMACS_ORG_REGISTRY_NAME);
405 char *fname = concat (path, "\\", title, ".lnk", 0);
407 if (_access (fname, 0) == 0)
408 return 0; /* already exists */
410 fname = concat (path, "\\", title, ".pif", 0); /* check for a pif as well */
412 if (_access (fname, 0) == 0)
413 return 0; /* already exists */
415 return IDC_ROOT_MENU;
421 root_desktop= rbget (h, da);
422 root_menu = rbget (h, ma);
423 reg_c = rbget (h, ct);
424 reg_java = rbget (h, javat);
425 reg_cpp = rbget (h, cppt);
426 reg_elisp = rbget (h, elispt);
427 reg_txt = rbget (h, txtt);
428 reg_idl = rbget (h, idlt);
432 dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
437 case IDC_ROOT_DESKTOP:
440 check_if_enable_next (h);
446 NEXT (IDD_S_POSTINSTALL);
462 dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
470 return HANDLE_WM_COMMAND (h, wParam, lParam, dialog_cmd);
476 do_desktop (HINSTANCE h)
480 verinfo.dwOSVersionInfoSize = sizeof (verinfo);
481 GetVersionEx (&verinfo);
485 if (xemacs_package != 0 && xemacs_package->type != TY_GENERIC)
487 batname = concat (find_xemacs_exe_path (), "\\",
488 find_xemacs_exe_name (),
490 uninstname = concat (find_xemacs_exe_path (), "\\", "setup.exe", 0);
491 root_desktop = check_desktop ("XEmacs", batname);
492 root_menu = check_startmenu ("XEmacs", batname);
494 reg_cpp = IDC_CPP_TYPE;
495 reg_java = IDC_JAVA_TYPE;
496 reg_elisp = IDC_ELISP_TYPE;
497 reg_txt = IDC_TXT_TYPE;
498 reg_idl = IDC_IDL_TYPE;
514 rv = DialogBox (h, MAKEINTRESOURCE (IDD_DESKTOP), 0, dialog_proc);
516 fatal (IDS_DIALOG_FAILED);