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