Rewrite LocationPathString match

This commit is contained in:
弘韬 张 2021-01-22 16:19:03 +08:00
parent 79962fb03e
commit b426dd10d1

View file

@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows;
namespace Flow.Launcher.Plugin.SharedCommands
@ -142,35 +143,28 @@ namespace Flow.Launcher.Plugin.SharedCommands
Process.Start(FileExplorerProgramEXE, $" /select,\"{path}\"");
}
///<summary>
/// This checks whether a given string is a directory path or network location string.
/// It does not check if location actually exists.
///</summary>
public static bool IsLocationPathString(string querySearchString)
{
if (string.IsNullOrEmpty(querySearchString))
if (string.IsNullOrEmpty(querySearchString) || querySearchString.Length < 3)
return false;
// // shared folder location, and not \\\location\
if (querySearchString.Length >= 3
&& querySearchString.StartsWith(@"\\")
&& char.IsLetter(querySearchString[2]))
if (querySearchString.StartsWith(@"\\")
&& querySearchString[2] != '\\')
return true;
// c:\
if (querySearchString.Length == 3
&& char.IsLetter(querySearchString[0])
if (char.IsLetter(querySearchString[0])
&& querySearchString[1] == ':'
&& querySearchString[2] == '\\')
return true;
// c:\\
if (querySearchString.Length >= 4
&& char.IsLetter(querySearchString[0])
&& querySearchString[1] == ':'
&& querySearchString[2] == '\\'
&& char.IsLetter(querySearchString[3]))
return true;
{
return querySearchString.Length == 3 || querySearchString[3] != '\\';
}
return false;
}