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