JAL-1460 tidied up the use of windows link file parser
authorJim Procter <jprocter@jalview.org>
Thu, 24 May 2018 13:38:59 +0000 (14:38 +0100)
committerJim Procter <jprocter@jalview.org>
Thu, 24 May 2018 13:38:59 +0000 (14:38 +0100)
src/jalview/gui/Desktop.java

index e592abf..04487e0 100644 (file)
@@ -3413,32 +3413,8 @@ public class Desktop extends jalview.jbgui.GDesktop
             files.add(file.toString());
           }
         }
-        if (Platform.isWindows())
-        {
-          Cache.log
-                  .debug("Scanning dropped content for Windows Link Files");
-
-          // resolve any .lnk files in the file drop
-          for (int f = 0; f < files.size(); f++)
-          {
-            if (protocols.get(f).equals(DataSourceType.FILE))
-            {
-              File lf = new File(files.get(f));
-              if (WindowsShortcut.isPotentialValidLink(lf))
-              {
-                // process link file to get a URL
-                Cache.log.debug("Found potential link file: " + lf);
-                WindowsShortcut wscfile = new WindowsShortcut(lf);
-                String fullname = wscfile.getRealFilename();
-                protocols.set(f, FormatAdapter.checkProtocol(fullname));
-                files.set(f, fullname);
-                Cache.log.debug("Parsed real filename " + fullname
-                        + " to extract protocol: " + protocols.get(f));
-              }
-            }
-          }
-        }
       }
+
       if (Cache.log.isDebugEnabled())
       {
         if (data == null || !added)
@@ -3472,6 +3448,34 @@ public class Desktop extends jalview.jbgui.GDesktop
         }
       }
     }
+    if (Platform.isWindows())
+
+    {
+      Cache.log.debug("Scanning dropped content for Windows Link Files");
+
+      // resolve any .lnk files in the file drop
+      for (int f = 0; f < files.size(); f++)
+      {
+        if (protocols.get(f).equals(DataSourceType.FILE) && files.get(f).toLowerCase().endsWith(".lnk") || files.get(f).toLowerCase().endsWith(".url")|| files.get(f).toLowerCase().endsWith(".site"))
+        {
+          try {
+            File lf = new File(files.get(f));
+            // process link file to get a URL
+            Cache.log.debug("Found potential link file: " + lf);
+            WindowsShortcut wscfile = new WindowsShortcut(lf);
+            String fullname = wscfile.getRealFilename();
+            protocols.set(f, FormatAdapter.checkProtocol(fullname));
+            files.set(f, fullname);
+            Cache.log.debug("Parsed real filename " + fullname
+                    + " to extract protocol: " + protocols.get(f));
+          }
+          catch (Exception ex)
+          {
+            Cache.log.error("Couldn't parse "+files.get(f)+" as a link file.",ex);
+          }
+        }
+      }
+    }
   }
 
   /**