]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0617: GvimExt: does not support different runtime dirs v9.2.0617
authorK.Takata <kentkt@csc.jp>
Wed, 10 Jun 2026 20:46:21 +0000 (20:46 +0000)
committerChristian Brabandt <cb@256bit.org>
Wed, 10 Jun 2026 20:50:42 +0000 (20:50 +0000)
Problem:  GvimExt: does not support different runtime dir types
Solution: Add support for all Vim supported runtime directories
          (Ken Takata)

Vim itself supports certain runtime directory structures.
However, GvimExt supports only one type of them.

Check three types of runtime directory structures.

1. gvim.exe is in runtimedir.
2. gvim.exe is in the parent of runtimedir.
   runtimedir is "vimXX".
3. gvim.exe is in the parent of runtimedir.
   runtimedir is "runtime".

related: vim/vim-win32-installer#356
closes:  #20465

Signed-off-by: K.Takata <kentkt@csc.jp>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/GvimExt/Make_ming.mak
src/GvimExt/Make_mvc.mak
src/GvimExt/gvimext.cpp
src/version.c

index b73e6fd92a697e731aba9917d7396bd262ff879f..341f4add527e6895b983b9b284854aec1fd9ba20 100644 (file)
@@ -86,8 +86,8 @@ $(DLL): $(OBJ) $(RES) $(DEFFILE)
                        $(LIBS) \
                -Wl,-Bstatic $(STATIC_LIBS) -Wl,-Bdynamic
 
-gvimext.o: gvimext.cpp
-       $(CXX) $(CXXFLAGS) -DFEAT_GETTEXT -DWINVER=$(WINVER) -D_WIN32_WINNT=$(WINVER) -c $? -o $@
+gvimext.o: gvimext.cpp gvimext.h ../version.h
+       $(CXX) $(CXXFLAGS) -DFEAT_GETTEXT -DWINVER=$(WINVER) -D_WIN32_WINNT=$(WINVER) -c $< -o $@
 
 $(RES): gvimext_ming.rc
        $(WINDRES) $(WINDRES_FLAGS) --input-format=rc --output-format=coff -DMING $? -o $@
index 874b34c74eb6c930be5a1d04bf198eb6f75332b1..b05a4314729c938881f103c78ad58da188b08b81 100644 (file)
@@ -50,7 +50,7 @@ CPU = ARM64
 cc = cl
 link = link
 rc = rc
-cflags = -nologo -c
+cflags = -nologo -c -GF
 lflags = -incremental:no -nologo
 rcflags = /r
 olelibsdll = ole32.lib uuid.lib oleaut32.lib user32.lib gdi32.lib advapi32.lib
@@ -84,7 +84,7 @@ gvimext.dll: gvimext.obj gvimext.res
                -out:$*.dll $** $(olelibsdll) shell32.lib comctl32.lib \
                -subsystem:$(SUBSYSTEM)
 
-gvimext.obj: gvimext.h
+gvimext.obj: gvimext.h ../version.h
 
 .cpp.obj:
        $(cc) $(cflags) -DFEAT_GETTEXT $(cvarsmt) $*.cpp
index 6d07b8b3c459be923249739f04f73131c8dabae7..40b84777f67f0d25f19f265afefb001c142b0943 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include "gvimext.h"
+#include "../version.h"
 
 #define ARRAY_LENGTH(a) (sizeof(a) / sizeof((a)[0]))
 
@@ -52,7 +53,7 @@ UINT cbFiles = 0;
 // Returns the path in name[BUFSIZE].  It's empty when it fails.
 //
     static void
-getGvimName(char *name, int runtime)
+getGvimName(char *name, BOOL runtime)
 {
     HKEY       keyhandle;
     DWORD      hlen;
@@ -102,9 +103,9 @@ getGvimName(char *name, int runtime)
 }
 
     static void
-getGvimInvocation(char *name, int runtime)
+getGvimInvocation(char *name)
 {
-    getGvimName(name, runtime);
+    getGvimName(name, FALSE);
     // avoid that Vim tries to expand wildcards in the file names
     strcat(name, " --literal");
 }
@@ -115,11 +116,20 @@ getGvimInvocationW(wchar_t *nameW)
     char *name;
 
     name = (char *)malloc(BUFSIZE);
-    getGvimInvocation(name, 0);
+    getGvimInvocation(name);
     mbstowcs(nameW, name, BUFSIZE);
     free(name);
 }
 
+    static BOOL
+FileExists(LPCTSTR szPath)
+{
+    DWORD dwAttrib = GetFileAttributes(szPath);
+
+    return (dwAttrib != INVALID_FILE_ATTRIBUTES
+           && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
+}
+
 //
 // Get the Vim runtime directory into buf[BUFSIZE].
 // The result is empty when it failed.
@@ -130,21 +140,47 @@ getRuntimeDir(char *buf)
 {
     int                idx;
 
-    getGvimName(buf, 1);
-    if (buf[0] != 0)
-    {
-       // When no path found, use the search path to expand it.
-       if (strchr(buf, '/') == NULL && strchr(buf, '\\') == NULL)
-           strcpy(buf, searchpath(buf));
+    getGvimName(buf, TRUE);
+    if (buf[0] == 0)
+       return;
 
-       // remove "gvim.exe" from the end
-       for (idx = (int)strlen(buf) - 1; idx >= 0; idx--)
-           if (buf[idx] == '\\' || buf[idx] == '/')
-           {
-               buf[idx + 1] = 0;
-               break;
-           }
+    // When no path found, use the search path to expand it.
+    if (strchr(buf, '/') == NULL && strchr(buf, '\\') == NULL)
+       strcpy(buf, searchpath(buf));
+
+    // remove "gvim.exe" from the end
+    for (idx = (int)strlen(buf) - 1; idx >= 0; idx--)
+       if (buf[idx] == '\\' || buf[idx] == '/')
+       {
+           buf[++idx] = 0;
+           break;
+       }
+
+    // Check the existence of defaults.vim
+    char *p = buf + idx;
+    strcpy(p, "defaults.vim");
+    if (FileExists(buf))
+    {
+       *p = 0;         // Cut "defaults.vim"
+       return;
+    }
+    // Check the existence of vimXX\defaults.vim
+    strcpy(p, VIM_VERSION_NODOT "\\" "defaults.vim");
+    if (FileExists(buf))
+    {
+       p[ARRAY_LENGTH(VIM_VERSION_NODOT)] = 0; // Cut "defaults.vim"
+       return;
+    }
+    // Check the existence of runtime\defaults.vim
+    strcpy(p, "runtime" "\\" "defaults.vim");
+    if (FileExists(buf))
+    {
+       p[ARRAY_LENGTH("runtime")] = 0;         // Cut "defaults.vim"
+       return;
     }
+    // Not found
+    buf[0] = 0;
+    return;
 }
 
     WCHAR *
@@ -923,10 +959,10 @@ BOOL CALLBACK CShellExt::EnumWindowsProc(HWND hWnd, LPARAM lParam)
     // No child window ???
     // if (GetParent(hWnd)) return TRUE;
     // Class name should be Vim, if failed to get class name, return
-    if (GetClassName(hWnd, temp, sizeof(temp)) == 0)
+    if (GetClassName(hWnd, temp, ARRAY_LENGTH(temp)) == 0)
        return TRUE;
     // Compare class name to that of vim, if not, return
-    if (_strnicmp(temp, "vim", sizeof("vim")) != 0)
+    if (_strnicmp(temp, "vim", ARRAY_LENGTH("vim")) != 0)
        return TRUE;
     // First check if the number of vim instance exceeds MAX_HWND
     CShellExt *cs = (CShellExt*) lParam;
@@ -942,7 +978,7 @@ BOOL CALLBACK CShellExt::EnumWindowsProc(HWND hWnd, LPARAM lParam)
 BOOL CShellExt::LoadMenuIcon()
 {
     char vimExeFile[BUFSIZE];
-    getGvimName(vimExeFile, 1);
+    getGvimName(vimExeFile, TRUE);
     if (vimExeFile[0] == '\0')
        return FALSE;
     HICON hVimIcon;
@@ -958,17 +994,20 @@ BOOL CShellExt::LoadMenuIcon()
     static char *
 searchpath(char *name)
 {
-    static char widename[2 * BUFSIZE];
-    WCHAR location[BUFSIZE + 1];
+    static union {
+       char    location[2 * BUFSIZE];
+       WCHAR   wname[BUFSIZE];
+    };
+    WCHAR wlocation[BUFSIZE + 1];
 
     // There appears to be a bug in FindExecutableA() on Windows NT.
     // Use FindExecutableW() instead...
-    MultiByteToWideChar(CP_ACP, 0, name, -1, (LPWSTR)widename, BUFSIZE);
-    if (FindExecutableW((LPCWSTR)widename, L"", location) > (HINSTANCE)32)
+    MultiByteToWideChar(CP_ACP, 0, name, -1, wname, BUFSIZE);
+    if (FindExecutableW(wname, L"", wlocation) > (HINSTANCE)32)
     {
-       WideCharToMultiByte(CP_ACP, 0, location, -1,
-               (LPSTR)widename, 2 * BUFSIZE, NULL, NULL);
-       return widename;
+       WideCharToMultiByte(CP_ACP, 0, wlocation, -1,
+               location, sizeof(location), NULL, NULL);
+       return location;
     }
     return (char *)"";
 }
index 7790231b81873a5edee7563f41af8ca565e26fd2..e100c8a4b1e35a4d00e30f9d8ac9a348d64ab583 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    617,
 /**/
     616,
 /**/