Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

[Environments] Extension Refresh & other fixes #3532

Merged
merged 5 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private void AddUserToHyperVAdminGroupAndEnableHyperV(Notification notification)

// Add the user to the Hyper-V Administrators group and enable the Hyper-V feature if it is not already enabled.
// Using a string instead of a file for the script so it can't be manipulated via the file system.
startInfo.Arguments = $"-ExecutionPolicy Bypass -Command \"{HyperVSetupScript.SetupFunction}\"";
startInfo.Arguments = $"-ExecutionPolicy Bypass -Command \"{HyperVSetupScript.SetupFunction} {user}\"";
startInfo.UseShellExecute = true;
startInfo.Verb = "runas";

Expand Down
27 changes: 13 additions & 14 deletions common/Environments/Scripts/HyperVSetupScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace DevHome.Common.Environments.Scripts;
public static class HyperVSetupScript
{
public const string SetupFunction = @"

# For cmdlet operation results so we can compare results and choose the right exit code
enum OperationStatus
{
Expand All @@ -32,7 +31,8 @@ 5. The user is in the Hyper-V Admin group and the Hyper-V Feature is not already
6. The user is already in the Hyper-V Admin group and the Hyper-V Feature is already enabled.
#>
function Initialize-HyperVForDevHome()
{
{
param ([Parameter(Mandatory=$true)][string]$user)
$featureEnablementResult = [OperationStatus]::OperationNotRun
$adminGroupResult = [OperationStatus]::OperationNotRun
$hyperVGroupSid = 'S-1-5-32-578'
Expand All @@ -56,39 +56,39 @@ exit 6
if (-not $featureEnabled)
{
$dsimHyperVFeature = Enable-WindowsOptionalFeature -Online -FeatureName 'Microsoft-Hyper-V' -All -NoRestart

# when $dsimHyperVFeature is not null we've enabled the feature successfully
if ($null -ne $dsimHyperVFeature)
{
# Hyper-V feature enabled successfully.
$featureEnablementResult = [OperationStatus]::OperationSucceeded
$featureEnablementResult = [OperationStatus]::OperationSucceeded
}
else
{
{
# Failed to enable the Hyper-V feature.
$featureEnablementResult = [OperationStatus]::OperationFailed
$featureEnablementResult = [OperationStatus]::OperationFailed
}
}

# Check the Hyper-V Administrators group to see if the user is inside the group
$userGroupObject = Get-LocalGroupMember -Sid $hyperVGroupSid | Where-Object { $_.Name -eq ([System.Security.Principal.WindowsIdentity]::GetCurrent().Name) }
$userGroupObject = Get-LocalGroupMember -Sid $hyperVGroupSid | Where-Object { $_.Name -eq $user }
$isUserInGroup = $null -ne $userGroupObject

# Add user to Hyper-v Administrators group if they aren't already in the group
if (-not $isUserInGroup)
if (-not $isUserInGroup)
{
Add-LocalGroupMember -Sid $hyperVGroupSid -Member ([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)
Add-LocalGroupMember -Sid $hyperVGroupSid -Member $user

# Check if the last command succeeded
if ($?)
{
# User added to the Hyper-V Administrators group.
$adminGroupResult = [OperationStatus]::OperationSucceeded
$adminGroupResult = [OperationStatus]::OperationSucceeded
}
else
{
# Failed to add user to the Hyper-V Administrators group.
$adminGroupResult = [OperationStatus]::OperationFailed
$adminGroupResult = [OperationStatus]::OperationFailed
}
}

Expand Down Expand Up @@ -132,6 +132,5 @@ exit 99
}

# Run script
Initialize-HyperVForDevHome
";
Initialize-HyperVForDevHome";
}
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,13 @@ public AddRepoViewModel(

ChangeToUrlPage();

// If the user isn't setting up a local machine, hide the browse button.
// Since we can't browse for a folder on a remote machine.
if (!_setupFlowOrchestrator.IsSettingUpLocalMachine)
{
FolderPickerViewModel.HideBrowseButton();
}

// override changes ChangeToUrlPage to correctly set the state.
UrlParsingError = string.Empty;
ShouldShowUrlError = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public partial class FolderPickerViewModel : ObservableObject
[ObservableProperty]
private bool _isBrowseButtonEnabled;

/// <summary>
/// Visually hides the browse button.
/// </summary>
[ObservableProperty]
private bool _showBrowseButton = true;

/// <summary>
/// Used to show different content in the textbox based on whether the checkbox is checked or unchecked.
/// </summary>
Expand Down Expand Up @@ -98,6 +104,11 @@ public void DisableBrowseButton()
IsBrowseButtonEnabled = false;
}

public void HideBrowseButton()
{
ShowBrowseButton = false;
}

public void SetCloneLocation(string cloneLocation)
{
CloneLocation = cloneLocation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ public void OnNavigatedTo(NavigationEventArgs args)
var parameter = args.Parameter?.ToString();

if ((!string.IsNullOrEmpty(parameter)) &&
parameter.Contains(_creationFlowNavigationParameter, StringComparison.OrdinalIgnoreCase) &&
Orchestrator.CurrentSetupFlowKind != SetupFlowKind.CreateEnvironment)
parameter.Contains(_creationFlowNavigationParameter, StringComparison.OrdinalIgnoreCase))
{
// We expect that when navigating from anywhere in Dev Home to the create environment page
// that the arg.Parameter variable be semicolon delimited string with the first value being 'StartCreationFlow'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
Expand Down Expand Up @@ -394,6 +395,14 @@ public async Task UpdateListViewModelList(ComputeSystemsLoadedData data)
{
_notificationsHelper?.DisplayComputeSystemEnumerationErrors(data);

// Remove the mappings that failed to load.
// The errors are already handled by the notification helper.
foreach (var mapping in data.DevIdToComputeSystemMap.Where(map =>
map.Value.Result.Status == ProviderOperationStatus.Failure))
{
data.DevIdToComputeSystemMap.Remove(mapping.Key);
}

var curListViewModel = new ComputeSystemsListViewModel(data);

// Fetch data for all compute systems that support the ApplyConfiguration flag in parallel
Expand Down
3 changes: 2 additions & 1 deletion tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,8 @@
<Button
x:Uid="ClonePath_Button"
Margin="5,27,0,0"
IsEnabled="{x:Bind AddRepoViewModel.FolderPickerViewModel.IsBrowseButtonEnabled, Mode=OneWay}">
IsEnabled="{x:Bind AddRepoViewModel.FolderPickerViewModel.IsBrowseButtonEnabled, Mode=OneWay}"
Visibility="{x:Bind AddRepoViewModel.FolderPickerViewModel.ShowBrowseButton, Mode=OneWay}">
<i:Interaction.Behaviors>
<ic:EventTriggerBehavior EventName="Click">
<ic:InvokeCommandAction Command="{x:Bind AddRepoViewModel.OpenFolderPickerCommand}" />
Expand Down
Loading