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