448
|
1 /*
|
|
2 * Copyright (c) 2000, Red Hat, Inc.
|
|
3 *
|
|
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.
|
|
8 *
|
|
9 * A copy of the GNU General Public License can be found at
|
|
10 * http://www.gnu.org/
|
|
11 *
|
|
12 * Written by DJ Delorie <dj@cygnus.com>
|
|
13 *
|
|
14 */
|
|
15
|
|
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
|
|
19 install.cc */
|
|
20
|
|
21
|
|
22 #include "win32.h"
|
|
23 #include <shlobj.h>
|
|
24
|
|
25 #include <io.h>
|
|
26 #include <stdio.h>
|
|
27 #include <stdlib.h>
|
|
28 #ifndef WIN32_NATIVE
|
|
29 #include <unistd.h>
|
|
30 #endif
|
|
31
|
|
32 #include "resource.h"
|
|
33 #include "ini.h"
|
|
34 #include "msg.h"
|
|
35 #include "state.h"
|
|
36 #include "concat.h"
|
|
37 #include "mkdir.h"
|
|
38 #include "dialog.h"
|
|
39 #include "version.h"
|
|
40 #include "reginfo.h"
|
|
41 #include "regedit.h"
|
|
42 #include "port.h"
|
657
|
43 #include "log.h"
|
448
|
44
|
|
45 extern "C" {
|
|
46 void make_link_2 (char *exepath, char *args, char *icon, char *lname);
|
|
47 };
|
|
48
|
|
49 static OSVERSIONINFO verinfo;
|
|
50
|
|
51 /* Lines starting with '@' are conditionals - include 'N' for NT,
|
|
52 '5' for Win95, '8' for Win98, '*' for all, like this:
|
|
53 echo foo
|
|
54 @N8
|
|
55 echo NT or 98
|
|
56 @*
|
|
57 */
|
|
58
|
|
59 #define COMMAND9XARGS "/E:4096 /c"
|
|
60 #define COMMAND9XEXE "\\command.com"
|
|
61
|
|
62 static char *iconname;
|
|
63 static char *batname;
|
|
64
|
|
65 static void
|
|
66 make_link (char *linkpath, char *title, char *target)
|
|
67 {
|
|
68 char argbuf[_MAX_PATH];
|
|
69 char *fname = concat (linkpath, "/", title, ".lnk", 0);
|
|
70
|
|
71 if (_access (fname, 0) == 0)
|
|
72 return; /* already exists */
|
|
73
|
|
74 msg ("make_link %s, %s, %s\n", fname, title, target);
|
|
75
|
|
76 mkdir_p (0, fname);
|
|
77
|
|
78 char *exepath, *args;
|
|
79
|
|
80 /* If we are running Win9x, build a command line. */
|
|
81 if (verinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
|
|
82 {
|
|
83 exepath = target;
|
|
84 args = "";
|
|
85 }
|
|
86 else
|
|
87 {
|
|
88 char windir[MAX_PATH];
|
|
89
|
|
90 GetWindowsDirectory (windir, sizeof (windir));
|
|
91 exepath = concat (windir, COMMAND9XEXE, 0);
|
|
92 sprintf (argbuf, "%s %s", COMMAND9XARGS, target);
|
|
93 args = argbuf;
|
|
94 }
|
|
95
|
|
96 msg ("make_link_2 (%s, %s, %s, %s)", exepath, args, iconname, fname);
|
|
97 make_link_2 (exepath, args, iconname, fname);
|
|
98 }
|
|
99
|
|
100 static char*
|
|
101 find_xemacs_exe_path ()
|
|
102 {
|
|
103 if (xemacs_package->type == TY_CYGWIN)
|
|
104 return backslash (concat (root_dir, "/bin/", XEMACS_CYGWIN_ARCH_NAME, 0));
|
|
105 else
|
|
106 return backslash (concat (root_dir, "\\XEmacs-",
|
|
107 xemacs_package->info[xemacs_package->trust].version,
|
|
108 "\\", XEMACS_NATIVE_ARCH_NAME, 0));
|
|
109 }
|
|
110
|
|
111 static char*
|
|
112 find_xemacs_exe_name ()
|
|
113 {
|
462
|
114 /* Hack to support older versions. */
|
|
115 if (strncmp (xemacs_package->info[xemacs_package->trust].version,
|
|
116 "21.1", 4) == 0)
|
|
117 return strdup ("runemacs.exe");
|
|
118 else if (xemacs_package->type == TY_CYGWIN)
|
448
|
119 return backslash (concat ("xemacs-",
|
|
120 xemacs_package->info[xemacs_package->trust].version,
|
|
121 ".exe", 0));
|
|
122 else
|
|
123 return strdup ("xemacs.exe");
|
|
124 }
|
|
125
|
|
126 static void
|
657
|
127 remove_link (char *linkpath, char* title)
|
|
128 {
|
|
129 char *fname = concat (linkpath, "/", title, ".lnk", 0);
|
|
130
|
|
131 if (_access (fname, 0) != 0)
|
|
132 return; /* doesn't exist */
|
|
133
|
|
134 msg ("remove_link %s, %s, %s\n", fname, title);
|
|
135 _unlink (fname);
|
|
136 }
|
|
137
|
|
138 static void
|
|
139 start_menu (char *title, char *target, int remove)
|
448
|
140 {
|
|
141 char path[_MAX_PATH];
|
|
142 LPITEMIDLIST id;
|
|
143 int issystem = (root_scope == IDC_ROOT_SYSTEM) ? 1 : 0;
|
|
144 SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_COMMON_PROGRAMS : CSIDL_PROGRAMS, &id);
|
|
145 SHGetPathFromIDList (id, path);
|
|
146 // following lines added because it appears Win95 does not use common programs
|
|
147 // unless it comes into play when multiple users for Win95 is enabled
|
|
148 msg("Program directory for program link: %s",path);
|
|
149 if ( strlen(path) == 0) {
|
|
150 SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id);
|
|
151 SHGetPathFromIDList (id, path);
|
|
152 msg("Program directory for program link changed to: %s",path);
|
|
153 }
|
|
154 // end of Win95 addition
|
|
155 strcat (path, "/");
|
|
156 strcat (path, XEMACS_INFO_XEMACS_ORG_REGISTRY_NAME);
|
657
|
157 if (remove == 0)
|
|
158 make_link (path, title, target);
|
|
159 else
|
|
160 remove_link (path, title);
|
448
|
161 }
|
|
162
|
|
163 static void
|
657
|
164 desktop_icon (char *title, char *target, int remove)
|
448
|
165 {
|
|
166 char path[_MAX_PATH];
|
|
167 LPITEMIDLIST id;
|
|
168 int issystem = (root_scope == IDC_ROOT_SYSTEM) ? 1 : 0;
|
|
169 //SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_DESKTOP : CSIDL_COMMON_DESKTOPDIRECTORY, &id);
|
|
170 SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_COMMON_DESKTOPDIRECTORY : CSIDL_DESKTOPDIRECTORY, &id);
|
|
171 SHGetPathFromIDList (id, path);
|
|
172 // following lines added because it appears Win95 does not use common programs
|
|
173 // unless it comes into play when multiple users for Win95 is enabled
|
|
174 msg("Desktop directory for desktop link: %s",path);
|
|
175 if ( strlen(path) == 0) {
|
|
176 SHGetSpecialFolderLocation (NULL, CSIDL_DESKTOPDIRECTORY, &id);
|
|
177 SHGetPathFromIDList (id, path);
|
|
178 msg("Desktop directory for deskop link changed to: %s",path);
|
|
179 }
|
|
180 // end of Win95 addition
|
657
|
181 if (remove == 0)
|
|
182 make_link (path, title, target);
|
|
183 else
|
|
184 remove_link (path, title);
|
448
|
185 }
|
|
186
|
|
187 static void
|
|
188 save_icon ()
|
|
189 {
|
|
190 iconname = backslash (concat (root_dir, XEMACS_RESOURCE_DIR,
|
|
191 "xemacs.ico", 0));
|
|
192
|
|
193 HRSRC rsrc = FindResource (NULL, "XEMACS.ICON", "FILE");
|
|
194 if (rsrc == NULL)
|
|
195 {
|
|
196 fatal ("FindResource failed");
|
|
197 }
|
|
198 HGLOBAL res = LoadResource (NULL, rsrc);
|
|
199 char *data = (char *) LockResource (res);
|
|
200 int len = SizeofResource (NULL, rsrc);
|
|
201
|
|
202 FILE *f = fopen (iconname, "wb");
|
|
203 if (f)
|
|
204 {
|
|
205 fwrite (data, 1, len, f);
|
|
206 fclose (f);
|
|
207 }
|
|
208 }
|
|
209
|
657
|
210 void
|
|
211 remove_desktop_setup()
|
|
212 {
|
|
213 start_menu ("XEmacs", 0, 1);
|
|
214 desktop_icon ("XEmacs", 0, 1);
|
|
215
|
|
216 if (xemacs_package != 0)
|
|
217 {
|
|
218 int issystem = (root_scope == IDC_ROOT_SYSTEM ? 1 : 0);
|
|
219 #define FROB(exe) remove_app_path ((exe), \
|
|
220 issystem)
|
|
221 /* FROB (find_xemacs_exe_name ()); */
|
|
222 FROB ("runemacs.exe");
|
|
223 FROB ("xemacs.exe");
|
|
224 #undef FROB
|
|
225 }
|
|
226 }
|
|
227
|
448
|
228 static void
|
|
229 do_desktop_setup()
|
|
230 {
|
|
231 save_icon ();
|
|
232
|
|
233 if (root_menu && batname) {
|
657
|
234 start_menu ("XEmacs", batname, 0);
|
448
|
235 }
|
|
236
|
|
237 if (root_desktop && batname) {
|
657
|
238 desktop_icon ("XEmacs", batname, 0);
|
448
|
239 }
|
|
240
|
|
241 // set regkeys for the application
|
|
242 if (xemacs_package != 0)
|
|
243 {
|
|
244 int issystem = (root_scope == IDC_ROOT_SYSTEM ? 1 : 0);
|
657
|
245 if (xemacs_package->type == TY_NATIVE
|
|
246 || xemacs_package->type == TY_CYGWIN)
|
448
|
247 {
|
657
|
248 if (xemacs_package->type == TY_NATIVE)
|
|
249 {
|
448
|
250 #define FROB(exe) set_app_path ((exe), \
|
|
251 find_xemacs_exe_path (), \
|
|
252 issystem)
|
657
|
253 FROB (find_xemacs_exe_name ());
|
|
254 FROB ("runemacs.exe");
|
|
255 FROB ("xemacs.exe");
|
448
|
256 #undef FROB
|
657
|
257 }
|
|
258 else if (xemacs_package->type == TY_CYGWIN)
|
|
259 {
|
|
260 int junk;
|
|
261 char* root = find_cygwin_root (&junk);
|
448
|
262 #define FROB(exe) set_app_path ((exe), \
|
|
263 concat (find_xemacs_exe_path (), ";", \
|
|
264 root, "\\bin;", \
|
|
265 root, "\\usr\\bin", 0), \
|
|
266 issystem)
|
657
|
267 FROB (find_xemacs_exe_name ());
|
|
268 FROB ("runemacs.exe");
|
|
269 FROB ("xemacs.exe");
|
448
|
270 #undef FROB
|
657
|
271 }
|
|
272 set_install_path (find_xemacs_exe_path(), issystem);
|
|
273 }
|
|
274 // Register file types
|
|
275 if (batname)
|
|
276 {
|
|
277 if (reg_java)
|
|
278 {
|
|
279 log (0, "Registering .java files");
|
|
280 setup_explorer ("java", "Java Source file", batname);
|
|
281 setup_explorer ("jav", "Java Source file", batname);
|
|
282 }
|
|
283 if (reg_cpp)
|
|
284 {
|
|
285 log (0, "Registering .cpp files");
|
|
286 setup_explorer ("cpp", "C++ Source file", batname);
|
|
287 setup_explorer ("cc", "C++ Source file", batname);
|
|
288 setup_explorer ("hh", "C++ Header file", batname);
|
|
289 }
|
|
290 if (reg_c)
|
|
291 {
|
|
292 log (0, "Registering .c files");
|
|
293 setup_explorer ("c", "C Source file", batname);
|
|
294 setup_explorer ("h", "C Header file", batname);
|
|
295 }
|
|
296 if (reg_elisp)
|
|
297 {
|
|
298 log (0, "Registering .el files");
|
|
299 setup_explorer ("el", "E-Lisp Source file", batname);
|
|
300 }
|
|
301 if (reg_txt)
|
|
302 {
|
|
303 log (0, "Registering .txt files");
|
|
304 setup_explorer ("txt", "Text file", batname);
|
|
305 }
|
448
|
306 }
|
|
307 }
|
|
308 }
|
|
309
|
|
310 static int da[] = { IDC_ROOT_DESKTOP, 0 };
|
|
311 static int ma[] = { IDC_ROOT_MENU, 0 };
|
|
312
|
657
|
313 static int ct[] = { IDC_C_TYPE, 0 };
|
|
314 static int javat[] = { IDC_JAVA_TYPE, 0 };
|
|
315 static int cppt[] = { IDC_CPP_TYPE, 0 };
|
|
316 static int elispt[] = { IDC_ELISP_TYPE, 0 };
|
|
317 static int txtt[] = { IDC_TXT_TYPE, 0 };
|
|
318
|
448
|
319 static void
|
|
320 check_if_enable_next (HWND h)
|
|
321 {
|
|
322 EnableWindow (GetDlgItem (h, IDOK), 1);
|
|
323 }
|
|
324
|
|
325 static void
|
|
326 load_dialog (HWND h)
|
|
327 {
|
|
328 rbset (h, da, root_desktop);
|
|
329 rbset (h, ma, root_menu);
|
657
|
330 rbset (h, ct, reg_c);
|
|
331 rbset (h, javat, reg_java);
|
|
332 rbset (h, cppt, reg_cpp);
|
|
333 rbset (h, elispt, reg_elisp);
|
|
334 rbset (h, txtt, reg_txt);
|
448
|
335 check_if_enable_next (h);
|
|
336 }
|
|
337
|
|
338 static int check_desktop (char *title, char *target)
|
|
339 {
|
|
340 char path[_MAX_PATH];
|
|
341 LPITEMIDLIST id;
|
|
342 int issystem = (root_scope == IDC_ROOT_SYSTEM) ? 1 : 0;
|
|
343 SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_COMMON_DESKTOPDIRECTORY : CSIDL_DESKTOPDIRECTORY, &id);
|
|
344 SHGetPathFromIDList (id, path);
|
|
345 // following lines added because it appears Win95 does not use common programs
|
|
346 // unless it comes into play when multiple users for Win95 is enabled
|
|
347 msg ("Desktop directory for desktop link: %s",path);
|
|
348 if (strlen (path) == 0) {
|
|
349 SHGetSpecialFolderLocation (NULL, CSIDL_DESKTOPDIRECTORY, &id);
|
|
350 SHGetPathFromIDList (id, path);
|
|
351 msg ("Desktop directory for deskop link changed to: %s",path);
|
|
352 }
|
|
353 // end of Win95 addition
|
|
354 char *fname = concat (path, "/", title, ".lnk", 0);
|
|
355
|
|
356 if (_access (fname, 0) == 0)
|
|
357 return 0; /* already exists */
|
|
358
|
|
359 fname = concat (path, "/", title, ".pif", 0); /* check for a pif as well */
|
|
360
|
|
361 if (_access (fname, 0) == 0)
|
|
362 return 0; /* already exists */
|
|
363
|
|
364 return IDC_ROOT_DESKTOP;
|
|
365 }
|
|
366
|
|
367 static int check_startmenu (char *title, char *target)
|
|
368 {
|
|
369 char path[_MAX_PATH];
|
|
370 LPITEMIDLIST id;
|
|
371 int issystem = (root_scope == IDC_ROOT_SYSTEM) ? 1 : 0;
|
|
372 SHGetSpecialFolderLocation (NULL, issystem ? CSIDL_COMMON_PROGRAMS : CSIDL_PROGRAMS, &id);
|
|
373 SHGetPathFromIDList (id, path);
|
|
374 // following lines added because it appears Win95 does not use common programs
|
|
375 // unless it comes into play when multiple users for Win95 is enabled
|
|
376 msg ("Program directory for program link: %s",path);
|
|
377 if (strlen (path) == 0) {
|
|
378 SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id);
|
|
379 SHGetPathFromIDList (id, path);
|
|
380 msg ("Program directory for program link changed to: %s",path);
|
|
381 }
|
|
382 // end of Win95 addition
|
|
383 strcat (path, "/");
|
|
384 strcat (path, XEMACS_INFO_XEMACS_ORG_REGISTRY_NAME);
|
|
385 char *fname = concat (path, "/", title, ".lnk", 0);
|
|
386
|
|
387 if (_access (fname, 0) == 0)
|
|
388 return 0; /* already exists */
|
|
389
|
|
390 fname = concat (path, "/", title, ".pif", 0); /* check for a pif as well */
|
|
391
|
|
392 if (_access (fname, 0) == 0)
|
|
393 return 0; /* already exists */
|
|
394
|
|
395 return IDC_ROOT_MENU;
|
|
396 }
|
|
397
|
|
398 static void
|
|
399 save_dialog (HWND h)
|
|
400 {
|
|
401 root_desktop= rbget (h, da);
|
|
402 root_menu = rbget (h, ma);
|
657
|
403 reg_c = rbget (h, ct);
|
|
404 reg_java = rbget (h, javat);
|
|
405 reg_cpp = rbget (h, cppt);
|
|
406 reg_elisp = rbget (h, elispt);
|
|
407 reg_txt = rbget (h, txtt);
|
448
|
408 }
|
|
409
|
|
410 static BOOL
|
|
411 dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
|
|
412 {
|
|
413 switch (id)
|
|
414 {
|
|
415
|
|
416 case IDC_ROOT_DESKTOP:
|
|
417 case IDC_ROOT_MENU:
|
|
418 save_dialog (h);
|
|
419 check_if_enable_next (h);
|
|
420 break;
|
|
421
|
|
422 case IDOK:
|
|
423 save_dialog (h);
|
|
424 do_desktop_setup();
|
|
425 NEXT (IDD_S_POSTINSTALL);
|
|
426 break;
|
|
427
|
|
428 case IDC_BACK:
|
|
429 save_dialog (h);
|
|
430 NEXT (IDD_CHOOSE);
|
|
431 break;
|
|
432
|
|
433 case IDCANCEL:
|
|
434 NEXT (0);
|
|
435 break;
|
|
436 }
|
|
437 return FALSE;
|
|
438 }
|
|
439
|
|
440 static BOOL CALLBACK
|
|
441 dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
|
|
442 {
|
|
443 switch (message)
|
|
444 {
|
|
445 case WM_INITDIALOG:
|
|
446 load_dialog (h);
|
|
447 return FALSE;
|
|
448 case WM_COMMAND:
|
|
449 return HANDLE_WM_COMMAND (h, wParam, lParam, dialog_cmd);
|
|
450 }
|
|
451 return FALSE;
|
|
452 }
|
|
453
|
|
454 void
|
|
455 do_desktop (HINSTANCE h)
|
|
456 {
|
|
457 CoInitialize (NULL);
|
|
458
|
|
459 verinfo.dwOSVersionInfoSize = sizeof (verinfo);
|
|
460 GetVersionEx (&verinfo);
|
|
461 batname = 0;
|
|
462
|
|
463 if (xemacs_package != 0 && xemacs_package->type != TY_GENERIC)
|
|
464 {
|
|
465 batname = concat (find_xemacs_exe_path (), "\\",
|
452
|
466 find_xemacs_exe_name (),
|
|
467 0);
|
448
|
468 root_desktop = check_desktop ("XEmacs", batname);
|
|
469 root_menu = check_startmenu ("XEmacs", batname);
|
657
|
470 reg_c = IDC_C_TYPE;
|
|
471 reg_cpp = IDC_CPP_TYPE;
|
|
472 reg_java = IDC_JAVA_TYPE;
|
|
473 reg_elisp = IDC_ELISP_TYPE;
|
|
474 reg_txt = IDC_TXT_TYPE;
|
448
|
475 }
|
|
476 else
|
|
477 {
|
|
478 root_desktop = 0;
|
|
479 root_menu = 0;
|
657
|
480 reg_c = 0;
|
|
481 reg_cpp = 0;
|
|
482 reg_java = 0;
|
|
483 reg_elisp = 0;
|
|
484 reg_txt = 0;
|
448
|
485 }
|
|
486
|
|
487 int rv = 0;
|
|
488
|
|
489 rv = DialogBox (h, MAKEINTRESOURCE (IDD_DESKTOP), 0, dialog_proc);
|
|
490 if (rv == -1)
|
|
491 fatal (IDS_DIALOG_FAILED);
|
|
492 }
|