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