1 /* Add entries to the GNU Emacs Program Manager folder.
2 Copyright (C) 1995, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 /****************************************************************************
22 * Program: addpm (adds emacs to the Windows program manager)
25 * argv[1] = install path for emacs
26 * argv[2] = full path to icon for emacs (optional)
36 DdeCallback (UINT uType
, UINT uFmt
, HCONV hconv
,
37 HSZ hsz1
, HSZ hsz2
, HDDEDATA hdata
,
38 DWORD dwData1
, DWORD dwData2
)
40 return ((HDDEDATA
) NULL
);
43 #define DdeCommand(str) \
44 DdeClientTransaction (str, strlen (str)+1, HConversation, (HSZ)NULL, \
45 CF_TEXT, XTYP_EXECUTE, 30000, NULL)
47 #define REG_ROOT "SOFTWARE\\GNU\\Emacs"
48 #define REG_GTK "SOFTWARE\\GTK\\2.0"
49 #define REG_APP_PATH \
50 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\emacs.exe"
60 {"EMACSLOADPATH", "%emacs_dir%/site-lisp;%emacs_dir%/../site-lisp;%emacs_dir%/lisp;%emacs_dir%/leim"},
61 {"SHELL", "%emacs_dir%/bin/cmdproxy.exe"},
62 {"EMACSDATA", "%emacs_dir%/etc"},
63 {"EMACSPATH", "%emacs_dir%/bin"},
64 /* We no longer set INFOPATH because Info-default-directory-list
66 /* {"INFOPATH", "%emacs_dir%/info"}, */
67 {"EMACSDOC", "%emacs_dir%/etc"},
80 /* Record the location of Emacs to the App Paths key if we have
81 sufficient permissions to do so. This helps Windows find emacs quickly
82 if the user types emacs.exe in the "Run Program" dialog without having
83 emacs on their path. Some applications also use the same registry key
84 to discover the installation directory for programs they are looking for.
85 Multiple installations cannot be handled by this method, but it does not
86 affect the general operation of other installations of Emacs, and we
87 are blindly overwriting the Start Menu entries already.
89 if (RegCreateKeyEx (HKEY_LOCAL_MACHINE
, REG_APP_PATH
, 0, "",
90 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
,
91 &hrootkey
, NULL
) == ERROR_SUCCESS
)
97 len
= strlen (path
) + 15; /* \bin\emacs.exe + terminator. */
98 emacs_path
= (char *) alloca (len
);
99 sprintf (emacs_path
, "%s\\bin\\emacs.exe", path
);
101 RegSetValueEx (hrootkey
, NULL
, 0, REG_SZ
, emacs_path
, len
);
103 /* Look for a GTK installation. If found, add it to the library search
104 path for Emacs so that the image libraries it provides are available
105 to Emacs regardless of whether it is in the path or not. */
106 if (RegOpenKeyEx (HKEY_LOCAL_MACHINE
, REG_GTK
, REG_OPTION_NON_VOLATILE
,
107 KEY_READ
, >k_key
) == ERROR_SUCCESS
)
109 if (RegQueryValueEx (gtk_key
, "DllPath", NULL
, NULL
,
110 NULL
, &size
) == ERROR_SUCCESS
)
112 char *gtk_path
= (char *) alloca (size
);
113 if (RegQueryValueEx (gtk_key
, "DllPath", NULL
, NULL
,
114 gtk_path
, &size
) == ERROR_SUCCESS
)
116 /* Make sure the emacs bin directory continues to be searched
117 first by including it as well. */
119 len
= strlen (path
) + 5 + size
;
120 dll_paths
= (char *) alloca (size
+ strlen (path
) + 1);
121 sprintf (dll_paths
, "%s\\bin;%s", path
, gtk_path
);
122 RegSetValueEx (hrootkey
, "Path", 0, REG_SZ
, dll_paths
, len
);
125 RegCloseKey (gtk_key
);
127 RegCloseKey (hrootkey
);
130 /* Previous versions relied on registry settings, but we do not need
131 them any more. If registry settings are installed from a previous
132 version, replace them to ensure they are the current settings.
133 Otherwise, do nothing. */
135 /* Check both the current user and the local machine to see if we
136 have any resources. */
138 if (RegOpenKeyEx (HKEY_LOCAL_MACHINE
, REG_ROOT
,
139 REG_OPTION_NON_VOLATILE
,
140 KEY_WRITE
, &hrootkey
) != ERROR_SUCCESS
141 && RegOpenKeyEx (HKEY_CURRENT_USER
, REG_ROOT
,
142 REG_OPTION_NON_VOLATILE
,
143 KEY_WRITE
, &hrootkey
) != ERROR_SUCCESS
)
148 for (i
= 0; i
< (sizeof (env_vars
) / sizeof (env_vars
[0])); i
++)
150 char * value
= env_vars
[i
].value
? env_vars
[i
].value
: path
;
152 if (RegSetValueEx (hrootkey
, env_vars
[i
].name
,
154 value
, lstrlen (value
) + 1) != ERROR_SUCCESS
)
158 RegCloseKey (hrootkey
);
171 char modname
[MAX_PATH
];
172 char additem
[MAX_PATH
*2 + 100];
178 /* If no args specified, use our location to set emacs_path. */
180 if (argc
< 2 || argc
> 3)
182 fprintf (stderr
, "usage: addpm [-q] [emacs_path [icon_path]]\n");
188 && (argv
[1][0] == '/' || argv
[1][0] == '-')
189 && argv
[1][1] == 'q')
197 emacs_path
= argv
[1];
200 if (!GetModuleFileName (NULL
, modname
, MAX_PATH
) ||
201 (p
= strrchr (modname
, '\\')) == NULL
)
203 fprintf (stderr
, "fatal error");
208 /* Set emacs_path to emacs_dir if we are in "%emacs_dir%\bin". */
209 if ((p
= strrchr (modname
, '\\')) && stricmp (p
, "\\bin") == 0)
212 emacs_path
= modname
;
216 fprintf (stderr
, "usage: addpm emacs_path [icon_path]\n");
220 /* Tell user what we are going to do. */
225 char msg
[ MAX_PATH
];
226 sprintf (msg
, "Install Emacs at %s?\n", emacs_path
);
227 result
= MessageBox (NULL
, msg
, "Install Emacs",
228 MB_OKCANCEL
| MB_ICONQUESTION
);
231 fprintf (stderr
, "Install cancelled\n");
237 add_registry (emacs_path
);
238 prog_name
= "runemacs.exe";
240 DdeInitialize (&idDde
, (PFNCALLBACK
)DdeCallback
, APPCMD_CLIENTONLY
, 0);
242 ProgMan
= DdeCreateStringHandle (idDde
, "PROGMAN", CP_WINANSI
);
244 HConversation
= DdeConnect (idDde
, ProgMan
, ProgMan
, NULL
);
245 if (HConversation
!= 0)
247 DdeCommand ("[CreateGroup (\"Gnu Emacs\")]");
248 DdeCommand ("[ReplaceItem (Emacs)]");
250 sprintf (additem
, "[AddItem (\"%s\\bin\\%s\", Emacs, \"%s\")]",
251 emacs_path
, prog_name
, argv
[2]);
253 sprintf (additem
, "[AddItem (\"%s\\bin\\%s\", Emacs)]",
254 emacs_path
, prog_name
);
255 DdeCommand (additem
);
257 DdeDisconnect (HConversation
);
260 DdeFreeStringHandle (idDde
, ProgMan
);
262 DdeUninitialize (idDde
);
267 /* arch-tag: f923609d-b781-4ef4-abce-ca0da29cbbf0
268 (do not change this comment) */