Hello noel,

This is just .lnk following. Supplying context.files information in
dragenter and dragover events (as opposed to the current situation,
where context.files is only supplied during drop) will be a future CL.


I'd like you to do a code review.  Please execute
        g4 diff -c 8981284

or point your web browser to
        http://mondrian/8981284

to review the following code:

Change 8981284 by [EMAIL PROTECTED] on 2008/11/13 12:01:54 *pending*

        Drag and Drop (on IE) now follows shortcuts (.lnk files), just like
        Firefox/Windows.
        
        R=noel
        [EMAIL PROTECTED]
        DELTA=40  (38 added, 0 deleted, 2 changed)
        OCL=8981284

Affected files ...

... //depot/googleclient/gears/opensource/gears/desktop/drop_target_ie.cc#12 
edit

40 delta lines: 38 added, 0 deleted, 2 changed

Also consider running:
        g4 lint -c 8981284

which verifies that the changelist doesn't introduce new style violations.

If you can't do the review, please let me know as soon as possible.  During
your review, please ensure that all new code has corresponding unit tests and
that existing unit tests are updated appropriately.  Visit
http://www/eng/code_review.html for more information.

This is a semiautomated message from "g4 mail".  Complaints or suggestions?
Mail [EMAIL PROTECTED]
Change 8981284 by [EMAIL PROTECTED] on 2008/11/13 12:01:54 *pending*

        Drag and Drop (on IE) now follows shortcuts (.lnk files), just like
        Firefox/Windows.

Affected files ...

... //depot/googleclient/gears/opensource/gears/desktop/drop_target_ie.cc#12 
edit

==== //depot/googleclient/gears/opensource/gears/desktop/drop_target_ie.cc#12 - 
c:\devel\srcwingears2/googleclient/gears/opensource/gears/desktop/drop_target_ie.cc
 ====
# action=edit type=text
--- googleclient/gears/opensource/gears/desktop/drop_target_ie.cc       
2008-11-13 12:01:20.000000000 +1100
+++ googleclient/gears/opensource/gears/desktop/drop_target_ie.cc       
2008-11-13 11:58:03.000000000 +1100
@@ -30,6 +30,8 @@
 #ifdef OS_WINCE
 // The Drag-and-Drop API is not implemented on Windows CE.
 #else
+#include <shlobj.h>
+
 #include "gears/desktop/drop_target_ie.h"
 
 #include "gears/base/common/leak_counter.h"
@@ -256,6 +258,32 @@
 }
 
 
+// This function overwrites buffer in-place.
+static HRESULT ResolveShortcut(TCHAR *buffer) {
+  static CComPtr<IShellLink> link;
+  if (!link && FAILED(link.CoCreateInstance(CLSID_ShellLink))) {
+    return E_FAIL;
+  }
+
+  CComQIPtr<IPersistFile> file(link);
+  if (!file) return E_FAIL;
+
+  // Open the shortcut file, load its content.
+  HRESULT hr = file->Load(buffer, STGM_READ);
+  if (FAILED(hr)) return hr;
+
+  // Resolve the target of the shortcut.
+  hr = link->Resolve(NULL, SLR_UPDATE);
+  if (FAILED(hr)) return hr;
+
+  // Read the target path.
+  hr = link->GetPath(buffer, MAX_PATH, 0, SLGP_UNCPRIORITY);
+  if (FAILED(hr)) return hr;
+
+  return S_OK;
+}
+
+
 HRESULT DropTarget::HandleOnDragDrop()
 {
   ProvideDebugVisualFeedback(false);
@@ -285,8 +313,18 @@
     UINT num_files = DragQueryFile((HDROP)stg_medium.hGlobal, -1, 0, 0);
     TCHAR buffer[MAX_PATH + 1];
     for (UINT i = 0; i < num_files; i++) {
-      int filename_length =
-          DragQueryFile((HDROP)stg_medium.hGlobal, i, buffer, sizeof(buffer));
+      DragQueryFile((HDROP)stg_medium.hGlobal, i, buffer, sizeof(buffer));
+      SHFILEINFO sh_file_info;
+      if (!SHGetFileInfo(buffer, 0, &sh_file_info, sizeof(sh_file_info),
+                         SHGFI_ATTRIBUTES) ||
+          !(sh_file_info.dwAttributes & SFGAO_FILESYSTEM) ||
+          (sh_file_info.dwAttributes & SFGAO_FOLDER)) {
+        continue;
+      }
+      if ((sh_file_info.dwAttributes & SFGAO_LINK) &&
+          FAILED(ResolveShortcut(buffer))) {
+        continue;
+      }
       filenames.push_back(std::string16(buffer));
     }
     ::ReleaseStgMedium(&stg_medium);

Reply via email to