66dea58
To: vim_dev@googlegroups.com
66dea58
Subject: Patch 7.4.012
66dea58
Fcc: outbox
66dea58
From: Bram Moolenaar <Bram@moolenaar.net>
66dea58
Mime-Version: 1.0
66dea58
Content-Type: text/plain; charset=UTF-8
66dea58
Content-Transfer-Encoding: 8bit
66dea58
------------
66dea58
66dea58
Patch 7.4.012
66dea58
Problem:    MS-Windows: resolving shortcut does not work properly with
66dea58
	    multi-byte characters.
66dea58
Solution:   Use wide system functions. (Ken Takata)
66dea58
Files:	    src/os_mswin.c
66dea58
66dea58
66dea58
*** ../vim-7.4.011/src/os_mswin.c	2013-06-16 16:41:11.000000000 +0200
66dea58
--- src/os_mswin.c	2013-08-30 16:43:23.000000000 +0200
66dea58
***************
66dea58
*** 1761,1769 ****
66dea58
      IPersistFile	*ppf = NULL;
66dea58
      OLECHAR		wsz[MAX_PATH];
66dea58
      WIN32_FIND_DATA	ffd; // we get those free of charge
66dea58
!     TCHAR		buf[MAX_PATH]; // could have simply reused 'wsz'...
66dea58
      char_u		*rfname = NULL;
66dea58
      int			len;
66dea58
  
66dea58
      /* Check if the file name ends in ".lnk". Avoid calling
66dea58
       * CoCreateInstance(), it's quite slow. */
66dea58
--- 1761,1773 ----
66dea58
      IPersistFile	*ppf = NULL;
66dea58
      OLECHAR		wsz[MAX_PATH];
66dea58
      WIN32_FIND_DATA	ffd; // we get those free of charge
66dea58
!     CHAR		buf[MAX_PATH]; // could have simply reused 'wsz'...
66dea58
      char_u		*rfname = NULL;
66dea58
      int			len;
66dea58
+ # ifdef FEAT_MBYTE
66dea58
+     IShellLinkW		*pslw = NULL;
66dea58
+     WIN32_FIND_DATAW	ffdw; // we get those free of charge
66dea58
+ # endif
66dea58
  
66dea58
      /* Check if the file name ends in ".lnk". Avoid calling
66dea58
       * CoCreateInstance(), it's quite slow. */
66dea58
***************
66dea58
*** 1775,1792 ****
66dea58
  
66dea58
      CoInitialize(NULL);
66dea58
  
66dea58
      // create a link manager object and request its interface
66dea58
      hr = CoCreateInstance(
66dea58
  	    &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
66dea58
  	    &IID_IShellLink, (void**)&psl;;
66dea58
      if (hr != S_OK)
66dea58
! 	goto shortcut_error;
66dea58
  
66dea58
      // Get a pointer to the IPersistFile interface.
66dea58
      hr = psl->lpVtbl->QueryInterface(
66dea58
  	    psl, &IID_IPersistFile, (void**)&ppf);
66dea58
      if (hr != S_OK)
66dea58
! 	goto shortcut_error;
66dea58
  
66dea58
      // full path string must be in Unicode.
66dea58
      MultiByteToWideChar(CP_ACP, 0, fname, -1, wsz, MAX_PATH);
66dea58
--- 1779,1840 ----
66dea58
  
66dea58
      CoInitialize(NULL);
66dea58
  
66dea58
+ # ifdef FEAT_MBYTE
66dea58
+     if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
66dea58
+     {
66dea58
+ 	// create a link manager object and request its interface
66dea58
+ 	hr = CoCreateInstance(
66dea58
+ 		&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
66dea58
+ 		&IID_IShellLinkW, (void**)&pslw);
66dea58
+ 	if (hr == S_OK)
66dea58
+ 	{
66dea58
+ 	    WCHAR	*p = enc_to_utf16(fname, NULL);
66dea58
+ 
66dea58
+ 	    if (p != NULL)
66dea58
+ 	    {
66dea58
+ 		// Get a pointer to the IPersistFile interface.
66dea58
+ 		hr = pslw->lpVtbl->QueryInterface(
66dea58
+ 			pslw, &IID_IPersistFile, (void**)&ppf);
66dea58
+ 		if (hr != S_OK)
66dea58
+ 		    goto shortcut_errorw;
66dea58
+ 
66dea58
+ 		// "load" the name and resolve the link
66dea58
+ 		hr = ppf->lpVtbl->Load(ppf, p, STGM_READ);
66dea58
+ 		if (hr != S_OK)
66dea58
+ 		    goto shortcut_errorw;
66dea58
+ #  if 0  // This makes Vim wait a long time if the target does not exist.
66dea58
+ 		hr = pslw->lpVtbl->Resolve(pslw, NULL, SLR_NO_UI);
66dea58
+ 		if (hr != S_OK)
66dea58
+ 		    goto shortcut_errorw;
66dea58
+ #  endif
66dea58
+ 
66dea58
+ 		// Get the path to the link target.
66dea58
+ 		ZeroMemory(wsz, MAX_PATH * sizeof(WCHAR));
66dea58
+ 		hr = pslw->lpVtbl->GetPath(pslw, wsz, MAX_PATH, &ffdw, 0);
66dea58
+ 		if (hr == S_OK && wsz[0] != NUL)
66dea58
+ 		    rfname = utf16_to_enc(wsz, NULL);
66dea58
+ 
66dea58
+ shortcut_errorw:
66dea58
+ 		vim_free(p);
66dea58
+ 		if (hr == S_OK)
66dea58
+ 		    goto shortcut_end;
66dea58
+ 	    }
66dea58
+ 	}
66dea58
+ 	/* Retry with non-wide function (for Windows 98). */
66dea58
+     }
66dea58
+ # endif
66dea58
      // create a link manager object and request its interface
66dea58
      hr = CoCreateInstance(
66dea58
  	    &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
66dea58
  	    &IID_IShellLink, (void**)&psl;;
66dea58
      if (hr != S_OK)
66dea58
! 	goto shortcut_end;
66dea58
  
66dea58
      // Get a pointer to the IPersistFile interface.
66dea58
      hr = psl->lpVtbl->QueryInterface(
66dea58
  	    psl, &IID_IPersistFile, (void**)&ppf);
66dea58
      if (hr != S_OK)
66dea58
! 	goto shortcut_end;
66dea58
  
66dea58
      // full path string must be in Unicode.
66dea58
      MultiByteToWideChar(CP_ACP, 0, fname, -1, wsz, MAX_PATH);
66dea58
***************
66dea58
*** 1794,1805 ****
66dea58
      // "load" the name and resolve the link
66dea58
      hr = ppf->lpVtbl->Load(ppf, wsz, STGM_READ);
66dea58
      if (hr != S_OK)
66dea58
! 	goto shortcut_error;
66dea58
! #if 0  // This makes Vim wait a long time if the target doesn't exist.
66dea58
      hr = psl->lpVtbl->Resolve(psl, NULL, SLR_NO_UI);
66dea58
      if (hr != S_OK)
66dea58
! 	goto shortcut_error;
66dea58
! #endif
66dea58
  
66dea58
      // Get the path to the link target.
66dea58
      ZeroMemory(buf, MAX_PATH);
66dea58
--- 1842,1853 ----
66dea58
      // "load" the name and resolve the link
66dea58
      hr = ppf->lpVtbl->Load(ppf, wsz, STGM_READ);
66dea58
      if (hr != S_OK)
66dea58
! 	goto shortcut_end;
66dea58
! # if 0  // This makes Vim wait a long time if the target doesn't exist.
66dea58
      hr = psl->lpVtbl->Resolve(psl, NULL, SLR_NO_UI);
66dea58
      if (hr != S_OK)
66dea58
! 	goto shortcut_end;
66dea58
! # endif
66dea58
  
66dea58
      // Get the path to the link target.
66dea58
      ZeroMemory(buf, MAX_PATH);
66dea58
***************
66dea58
*** 1807,1818 ****
66dea58
      if (hr == S_OK && buf[0] != NUL)
66dea58
  	rfname = vim_strsave(buf);
66dea58
  
66dea58
! shortcut_error:
66dea58
      // Release all interface pointers (both belong to the same object)
66dea58
      if (ppf != NULL)
66dea58
  	ppf->lpVtbl->Release(ppf);
66dea58
      if (psl != NULL)
66dea58
  	psl->lpVtbl->Release(psl);
66dea58
  
66dea58
      CoUninitialize();
66dea58
      return rfname;
66dea58
--- 1855,1870 ----
66dea58
      if (hr == S_OK && buf[0] != NUL)
66dea58
  	rfname = vim_strsave(buf);
66dea58
  
66dea58
! shortcut_end:
66dea58
      // Release all interface pointers (both belong to the same object)
66dea58
      if (ppf != NULL)
66dea58
  	ppf->lpVtbl->Release(ppf);
66dea58
      if (psl != NULL)
66dea58
  	psl->lpVtbl->Release(psl);
66dea58
+ # ifdef FEAT_MBYTE
66dea58
+     if (pslw != NULL)
66dea58
+ 	pslw->lpVtbl->Release(pslw);
66dea58
+ # endif
66dea58
  
66dea58
      CoUninitialize();
66dea58
      return rfname;
66dea58
*** ../vim-7.4.011/src/version.c	2013-08-30 16:35:41.000000000 +0200
66dea58
--- src/version.c	2013-08-30 16:39:40.000000000 +0200
66dea58
***************
66dea58
*** 740,741 ****
66dea58
--- 740,743 ----
66dea58
  {   /* Add new patch number below this line */
66dea58
+ /**/
66dea58
+     12,
66dea58
  /**/
66dea58
66dea58
-- 
66dea58
hundred-and-one symptoms of being an internet addict:
66dea58
142. You dream about creating the world's greatest web site.
66dea58
66dea58
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
66dea58
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
66dea58
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
66dea58
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///