From f670149cc259ae8aa57849252ba1632c13885cb8 Mon Sep 17 00:00:00 2001 From: Huzaifa Danish Date: Thu, 1 Aug 2024 15:48:22 -0700 Subject: [PATCH 1/5] Added create env page refresh --- .../DevHome.SetupFlow/ViewModels/SetupFlowViewModel.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/SetupFlowViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/SetupFlowViewModel.cs index 57c548d2d..8d7e720b4 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/SetupFlowViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/SetupFlowViewModel.cs @@ -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' From fe96db6690b96423e1df79ff12caaf62682655ea Mon Sep 17 00:00:00 2001 From: Huzaifa Danish Date: Mon, 5 Aug 2024 14:51:06 -0700 Subject: [PATCH 2/5] Fixed adding Hyper-V adming user --- .../Helpers/EnvironmentsNotificationHelper.cs | 2 +- .../Environments/Scripts/HyperVSetupScript.cs | 27 +++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/common/Environments/Helpers/EnvironmentsNotificationHelper.cs b/common/Environments/Helpers/EnvironmentsNotificationHelper.cs index 552b9efb8..53ad7a207 100644 --- a/common/Environments/Helpers/EnvironmentsNotificationHelper.cs +++ b/common/Environments/Helpers/EnvironmentsNotificationHelper.cs @@ -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"; diff --git a/common/Environments/Scripts/HyperVSetupScript.cs b/common/Environments/Scripts/HyperVSetupScript.cs index 01348c790..e0fb5529d 100644 --- a/common/Environments/Scripts/HyperVSetupScript.cs +++ b/common/Environments/Scripts/HyperVSetupScript.cs @@ -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 { @@ -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' @@ -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 } } @@ -132,6 +132,5 @@ exit 99 } # Run script - Initialize-HyperVForDevHome - "; + Initialize-HyperVForDevHome"; } From 750ea71c0edee3f298f6074e09a50cf8e91762a2 Mon Sep 17 00:00:00 2001 From: Huzaifa Danish Date: Tue, 6 Aug 2024 14:41:47 -0700 Subject: [PATCH 3/5] Disable browse button --- .../DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs | 7 +++++++ .../ViewModels/FolderPickerViewModel.cs | 11 +++++++++++ .../DevHome.SetupFlow/Views/AddRepoDialog.xaml | 3 ++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs index a4529374a..9aa3966de 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs @@ -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; diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/FolderPickerViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/FolderPickerViewModel.cs index b51582298..9c1a5dee7 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/FolderPickerViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/FolderPickerViewModel.cs @@ -49,6 +49,12 @@ public partial class FolderPickerViewModel : ObservableObject [ObservableProperty] private bool _isBrowseButtonEnabled; + /// + /// Visually hides the browse button. + /// + [ObservableProperty] + private bool _showBrowseButton = true; + /// /// Used to show different content in the textbox based on whether the checkbox is checked or unchecked. /// @@ -98,6 +104,11 @@ public void DisableBrowseButton() IsBrowseButtonEnabled = false; } + public void HideBrowseButton() + { + ShowBrowseButton = false; + } + public void SetCloneLocation(string cloneLocation) { CloneLocation = cloneLocation; diff --git a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml index 62743f400..6f4eb3463 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml +++ b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml @@ -398,7 +398,8 @@