浏览代码

Bug 1901: Allow using Windows Store apps aliases as terminals (particularly Windows Terminal)

https://winscp.net/tracker/1901
(cherry picked from commit 00a37137381ac63422f6f0be20f0b6ed3e0988ff)

Source commit: f63e60c7f66eabbec10280269b585a5fc9eb2d7f
Martin Prikryl 5 年之前
父节点
当前提交
16155c20b2
共有 1 个文件被更改,包括 29 次插入3 次删除
  1. 29 3
      source/windows/GUITools.cpp

+ 29 - 3
source/windows/GUITools.cpp

@@ -28,6 +28,7 @@
 #include <HistoryComboBox.hpp>
 #include <HistoryComboBox.hpp>
 #include <vssym32.h>
 #include <vssym32.h>
 #include <DateUtils.hpp>
 #include <DateUtils.hpp>
+#include <IOUtils.hpp>
 
 
 #include "Animations96.h"
 #include "Animations96.h"
 #include "Animations120.h"
 #include "Animations120.h"
@@ -39,9 +40,19 @@
 extern const UnicodeString PageantTool = L"pageant.exe";
 extern const UnicodeString PageantTool = L"pageant.exe";
 extern const UnicodeString PuttygenTool = L"puttygen.exe";
 extern const UnicodeString PuttygenTool = L"puttygen.exe";
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
+static bool __fastcall FileExistsFix(const UnicodeString & Path)
+{
+  // WORKAROUND
+  ::SetLastError(ERROR_SUCCESS);
+  return
+    FileExists(ApiPath(Path)) ||
+    // returned when resolving symlinks in %LOCALAPPDATA%\Microsoft\WindowsApps
+    (GetLastError() == ERROR_CANT_ACCESS_FILE);
+}
+//---------------------------------------------------------------------------
 bool __fastcall FindFile(UnicodeString & Path)
 bool __fastcall FindFile(UnicodeString & Path)
 {
 {
-  bool Result = FileExists(ApiPath(Path));
+  bool Result = FileExistsFix(Path);
 
 
   if (!Result)
   if (!Result)
   {
   {
@@ -61,17 +72,32 @@ bool __fastcall FindFile(UnicodeString & Path)
     }
     }
   }
   }
 
 
-  if (!Result)
+  if (!Result && SameText(ExtractFileName(Path), Path))
   {
   {
     UnicodeString Paths = GetEnvironmentVariable(L"PATH");
     UnicodeString Paths = GetEnvironmentVariable(L"PATH");
     if (!Paths.IsEmpty())
     if (!Paths.IsEmpty())
     {
     {
-      UnicodeString NewPath = FileSearch(ExtractFileName(Path), Paths);
+      UnicodeString NewPath = FileSearch(Path, Paths);
       Result = !NewPath.IsEmpty();
       Result = !NewPath.IsEmpty();
       if (Result)
       if (Result)
       {
       {
         Path = NewPath;
         Path = NewPath;
       }
       }
+      else
+      {
+        // Basically the same what FileSearch does, except for FileExistsFix.
+        // Once this proves working, we can ged rid of the FileSearch call.
+        while (!Result && !Paths.IsEmpty())
+        {
+          UnicodeString P = CutToChar(Paths, L';', false);
+          NewPath = TPath::Combine(P, Path);
+          Result = FileExistsFix(NewPath);
+          if (Result)
+          {
+            Path = NewPath;
+          }
+        }
+      }
     }
     }
   }
   }
   return Result;
   return Result;