Blame SOURCES/7.4.012

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