Skip to content

Commit 8d1ac74

Browse files
committed
added action open_any
1 parent d3a5cb9 commit 8d1ac74

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

AssistantComputerControl/Actions.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,49 @@ public void Open(string parameter) {
445445
}
446446
}
447447
}
448+
public void OpenAny(string parameter)
449+
{
450+
string fileLocation = MainProgram.shortcutLocation;
451+
Regex rx = new Regex("^" + parameter + Regex.Escape(".") + ".*", RegexOptions.IgnoreCase);
452+
if (Directory.Exists(fileLocation) || Uri.IsWellFormedUriString(fileLocation, UriKind.Absolute))
453+
{
454+
DirectoryInfo d = new DirectoryInfo(fileLocation);
455+
bool opened = false;
456+
foreach (var dirFile in d.GetFiles())
457+
{
458+
if (!MainProgram.testingAction)
459+
{
460+
bool result = rx.IsMatch(dirFile.Name);
461+
if (result)
462+
{
463+
Process.Start(dirFile.FullName);
464+
opened = true;
465+
break;
466+
}
467+
}
468+
}
469+
if (!opened)
470+
{
471+
Error("File(" + parameter + ") doesn't exist at" + " (" + fileLocation + ")");
472+
}
473+
else
474+
{
475+
if (!MainProgram.testingAction)
476+
{
477+
successMessage = "OPEN: opened " + parameter;
478+
}
479+
else
480+
{
481+
successMessage = "OPEN: simulated opening " + parameter;
482+
}
483+
}
484+
485+
}
486+
else
487+
{
488+
Error("Directory doesn't exist (" + fileLocation + ")");
489+
}
490+
}
448491
public void OpenAll(string parameter) {
449492
string fileLocation = (!parameter.Contains(@":\") || !parameter.Contains(@":/")) ? Path.Combine(MainProgram.shortcutLocation, parameter) : parameter;
450493

0 commit comments

Comments
 (0)