Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions GVFS/GVFS.Platform.Windows/ProjFSFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -679,9 +679,16 @@ private static bool TryEnableProjFSOptionalFeature(ITracer tracer, PhysicalFileS

private static ProcessResult GetProjFSOptionalFeatureStatus()
{
return CallPowershellCommand(
"$var=(Get-WindowsOptionalFeature -Online -FeatureName " + OptionalFeatureName + "); if($var -eq $null){exit " +
(int)ProjFSInboxStatus.NotInbox + "}else{if($var.State -eq 'Enabled'){exit " + (int)ProjFSInboxStatus.Enabled + "}else{exit " + (int)ProjFSInboxStatus.Disabled + "}}");
try
{
return CallPowershellCommand(
"$var=(Get-WindowsOptionalFeature -Online -FeatureName " + OptionalFeatureName + "); if($var -eq $null){exit " +
(int)ProjFSInboxStatus.NotInbox + "}else{if($var.State -eq 'Enabled'){exit " + (int)ProjFSInboxStatus.Enabled + "}else{exit " + (int)ProjFSInboxStatus.Disabled + "}}");
}
catch (PowershellNotFoundException e)
{
return new ProcessResult(string.Empty, e.Message, (int)ProjFSInboxStatus.Invalid);
}
Comment thread
derrickstolee marked this conversation as resolved.
}

private static EventMetadata CreateEventMetadata(Exception e = null)
Expand All @@ -698,7 +705,14 @@ private static EventMetadata CreateEventMetadata(Exception e = null)

private static ProcessResult CallPowershellCommand(string command)
{
return ProcessHelper.Run("powershell.exe", "-NonInteractive -NoProfile -Command \"& { " + command + " }\"");
ProcessResult whereResult = ProcessHelper.Run("where.exe", "powershell.exe");

if (whereResult.ExitCode != 0)
{
throw new PowershellNotFoundException();
}

return ProcessHelper.Run(whereResult.Output.Trim(), "-NonInteractive -NoProfile -Command \"& { " + command + " }\"");
}

// Using an Impl method allows TryPrepareFolderForCallbacks to catch any ProjFS dependency related exceptions
Expand Down Expand Up @@ -734,5 +748,13 @@ public static extern bool GetVolumePathName(
StringBuilder volumePathName,
uint bufferLength);
}

private class PowershellNotFoundException : Exception
{
public PowershellNotFoundException()
: base("powershell.exe was not found")
{
}
}
}
}