ChangeLog fixes
[bpt/emacs.git] / nt / runemacs.c
index 07e24f7..20b6f0c 100644 (file)
@@ -1,6 +1,6 @@
 /* runemacs --- Simple program to start Emacs with its console window hidden.
 
-Copyright (C) 2001-201 Free Software Foundation, Inc.
+Copyright (C) 2001-2014 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -45,6 +45,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <malloc.h>
 
 static void set_user_model_id (void);
+static int ensure_unicows_dll (void);
 
 int WINAPI
 WinMain (HINSTANCE hSelf, HINSTANCE hPrev, LPSTR cmdline, int nShow)
@@ -59,6 +60,9 @@ WinMain (HINSTANCE hSelf, HINSTANCE hPrev, LPSTR cmdline, int nShow)
   char *p;
   char modname[MAX_PATH];
 
+  if (!ensure_unicows_dll ())
+    goto error;
+
   set_user_model_id ();
 
   if (!GetModuleFileName (NULL, modname, MAX_PATH))
@@ -71,6 +75,11 @@ WinMain (HINSTANCE hSelf, HINSTANCE hPrev, LPSTR cmdline, int nShow)
   /* Quote executable name in case of spaces in the path. */
   *new_cmdline = '"';
   strcpy (new_cmdline + 1, modname);
+  /* Detect and handle un-installed runemacs.exe in nt/ subdirectory,
+     while emacs.exe is in src/.  */
+  if ((p = strrchr (new_cmdline, '\\')) != NULL
+      && stricmp (p, "\\nt") == 0)
+    strcpy (p, "\\src");
 
 #ifdef CHOOSE_NEWEST_EXE
   {
@@ -107,7 +116,7 @@ WinMain (HINSTANCE hSelf, HINSTANCE hPrev, LPSTR cmdline, int nShow)
 #endif
 
   /* Append original arguments if any; first look for arguments we
-     recognise (-wait, -high, and -low), and apply them ourselves.  */
+     recognize (-wait, -high, and -low), and apply them ourselves.  */
   while (cmdline[0] == '-' || cmdline[0] == '/')
     {
       if (strncmp (cmdline+1, "wait", 4) == 0)
@@ -203,3 +212,43 @@ set_user_model_id (void)
     }
 }
 
+static int
+ensure_unicows_dll (void)
+{
+  OSVERSIONINFO os_ver;
+  HMODULE h;
+
+  ZeroMemory (&os_ver, sizeof (OSVERSIONINFO));
+  os_ver.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
+  if (!GetVersionEx (&os_ver))
+    return 0;
+
+  if (os_ver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
+    {
+      h = LoadLibrary ("Unicows.dll");
+      if (!h)
+       {
+         int button;
+
+         button = MessageBox (NULL,
+                              "Emacs cannot load the UNICOWS.DLL library.\n"
+                              "This library is essential for using Emacs\n"
+                              "on this system.  You need to install it.\n\n"
+                              "However, you can still use Emacs by invoking\n"
+                              "it with the '-nw' command-line option.\n\n"
+                              "Emacs will exit when you click OK.",
+                              "Emacs cannot load UNICOWS.DLL",
+                              MB_ICONERROR | MB_TASKMODAL
+                              | MB_SETFOREGROUND | MB_OK);
+         switch (button)
+           {
+             case IDOK:
+             default:
+               return 0;
+           }
+       }
+      FreeLibrary (h);
+      return 1;
+    }
+  return 1;
+}