Skip to content

Commit

Permalink
fix: device install in 2 phases: binaries et. alia then enroll, then …
Browse files Browse the repository at this point in the history
…install service
  • Loading branch information
XavierChanth committed Oct 4, 2024
1 parent 8b269dc commit 6e044b0
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ public static AtsignStatus Status(string atsign)
_controller.LoadError(ex);
}
var returnString = response.Split(":").ToList();
if(returnString.Count < 1)
{
// Most likely at_activate binary is missing if the output was empty
_controller.LoadError(new Exception("No output from at_activate status"));
}
var exitCode = returnString[0].Split(" ")[1];

if (exitCode == "0")
Expand Down
89 changes: 49 additions & 40 deletions tools/windows-installer/NoPortsInstaller/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,33 +86,48 @@ public async Task Install(ProgressBar progress, Label status)
await UpdateProgressBar(progress, 75);
status.Content = "Creating Registries NoPorts...";
CreateRegistryKeys();
await UpdateProgressBar(progress, 90);
if (InstallType.Equals(InstallType.Device))
{
status.Content = "Setting up NoPorts Service...";
CopyIntoServiceAccount();
await SetupService(status);
}
await UpdateProgressBar(progress, 100);
InstallLogger.Log($"Installation Complete");
if (InstallType.Equals(InstallType.Client) || InstallType.Equals(InstallType.Device))
if (InstallType.Equals(InstallType.Client))
{
Pages.Add(new FinishInstall());
}
if (InstallType.Equals(InstallType.Device))
{
EnrollDevice();
}
NextPage();
}
catch (Exception ex)
}
catch (Exception ex)
{
await Cleanup();
LoadError(ex);
}
}

/// <summary>
/// Uninstalls NoPorts, including the service.
/// </summary>
/// <param name="progress"></param>
public async Task Uninstall(ProgressBar progress)
public async Task InstallService(ProgressBar progress, Label status)
{
try
{
await UpdateProgressBar(progress, 25);
status.Content = "Setting up NoPorts Service...";
CopyIntoServiceAccount();
await SetupService(status);
await UpdateProgressBar(progress, 100);
NextPage();
}
catch (Exception ex)
{
await Cleanup();
LoadError(ex);
}
}

/// <summary>
/// Uninstalls NoPorts, including the service.
/// </summary>
/// <param name="progress"></param>
public async Task Uninstall(ProgressBar progress)
{
try
{
Expand Down Expand Up @@ -153,33 +168,27 @@ public async Task Uninstall(ProgressBar progress)
/// <summary>
/// will change
/// </summary>
public void Enroll()
public void EnrollDevice()
{
try
{
if (!KeysInstalled())
{
InstallLogger.Log("Keys not found, starting enrollment process...");
if (ActivateController.Status(DeviceAtsign) != AtsignStatus.Activated)
{
throw new Exception("Keys not found locally and on registrar. Please onboard first.");
}
Pages.Add(new Enroll());
Pages.Add(new Install("APKAM Keys cut, continue to installation."));
}
else
{
InstallLogger.Log("Keys found. Continuing to install...");
Pages.Add(new Install("Keys found on device, continue to installation."));
}
}
catch (Exception ex)
{
LoadError(ex);
}
}
if (!KeysInstalled())
{
if (ActivateController.Status(DeviceAtsign) != AtsignStatus.Activated)
{
throw new Exception("Keys not found locally and on registrar. Please onboard first.");
}

InstallLogger.Log("Starting enrollment process before continuing to install...");
Pages.Add(new Enroll());
}
else
{
InstallLogger.Log("Keys found. Continuing to service install...");
Pages.Add(new InstallService());
Pages.Add(new FinishInstall());
}
}

public void UpdateConfigRegistry()
public void UpdateConfigRegistry()
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace NoPortsInstaller.Pages.Activate
{
/// <summary>
/// Interaction logic for Enroll.xaml
/// Interaction logic for EnrollDevice.xaml
/// </summary>
public partial class AtsignApprove : Page
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Windows;
using NoPortsInstaller.Pages.Install;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;

namespace NoPortsInstaller.Pages.Activate
{
/// <summary>
/// Interaction logic for Enroll.xaml
/// Interaction logic for EnrollDevice.xaml
/// </summary>
public partial class Enroll : Page
{
Expand Down Expand Up @@ -100,14 +101,21 @@ private async void Generate_Click(object sender, RoutedEventArgs e)
{
EnrollResponse.Content = "";
string otp = $"{OtpBox1.Text}{OtpBox2.Text}{OtpBox3.Text}{OtpBox4.Text}{OtpBox5.Text}{OtpBox6.Text}".ToUpper();

_controller.DeviceName = _controller.NormalizeDeviceName($"client_{otp}");
if (!_controller.InstallType.Equals(InstallType.Device))
{
_controller.DeviceName = _controller.NormalizeDeviceName($"client_{otp}");
}
Loading.Visibility = Visibility.Visible;
bool value = await Task.Run(() => ActivateController.Enroll(otp));
Loading.Visibility = Visibility.Hidden;
if (value)
{
_controller.NextPage();
if (_controller.InstallType.Equals(InstallType.Device))
{
_controller.Pages.Add(new InstallService());
_controller.Pages.Add(new FinishInstall());
}
_controller.NextPage();
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private void BackPageButton_Click(object sender, System.Windows.RoutedEventArgs
private void NextPageButton_Click(object sender, System.Windows.RoutedEventArgs e)
{
_controller.AdditionalArgs = _controller.NormalizeArgs(AdditionalArgs.Text);
_controller.Enroll();
_controller.Pages.Add(new Download());
_controller.NextPage();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<Page x:Class="NoPortsInstaller.Pages.Install.InstallService"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:NoPortsInstaller"
mc:Ignorable="d"
d:DesignHeight="350" d:DesignWidth="500"
Title="Download">

<Grid Width="500">
<Rectangle HorizontalAlignment="Left" Height="350" VerticalAlignment="Center" Width="162" Fill="#FF252526" Margin="-8,0,0,0">
<Rectangle.Stroke>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Stroke>
</Rectangle>
<Rectangle HorizontalAlignment="Left" Stroke="Black" VerticalAlignment="Center" Height="1" Width="1">
<Rectangle.Fill>
<ImageBrush ImageSource="/Assets/NoPortsDark.png"/>
</Rectangle.Fill>
</Rectangle>
<Image HorizontalAlignment="Left" Height="177" Margin="20,0,0,0" VerticalAlignment="Center" Width="122" Source="/Assets/NoPortsDark.png" Stretch="Fill">
<Image.OpacityMask>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Image.OpacityMask>
</Image>
<Label Content="NoPorts Installation" HorizontalAlignment="Left" Height="28" VerticalAlignment="Top" Width="194" Margin="168,10,0,0" FontSize="16" FontWeight="Bold"/>
<Label Content="Installation In Progress" HorizontalAlignment="Left" Height="27" VerticalAlignment="Top" Width="199" Margin="168,45,0,0"/>
<Rectangle HorizontalAlignment="Left" Height="2" Margin="168,71,0,0" Stroke="Black" VerticalAlignment="Top" Width="220" Fill="Black" RenderTransformOrigin="0.5,0.5">
<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleY="-1"/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Rectangle.RenderTransform>
</Rectangle>
<Label Content="" HorizontalAlignment="Left" Height="28" VerticalAlignment="Top" Width="199" Margin="168,86,0,0" FontSize="11"/>
<ProgressBar x:Name="InstallProgress" HorizontalAlignment="Left" Height="22" Margin="173,114,0,0" VerticalAlignment="Top" Width="228"/>
<Label x:Name="Status" Content="Starting Service Installation..." HorizontalAlignment="Left" Margin="175,136,0,0" VerticalAlignment="Top" Width="226"/>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Windows.Controls;

namespace NoPortsInstaller.Pages.Install
{
/// <summary>
/// Interaction logic for Page1.xaml
/// </summary>
public partial class InstallService : Page
{
private readonly Controller _controller;
public InstallService()
{
InitializeComponent();
_controller = App.ControllerInstance;
_ = _controller.InstallService(InstallProgress, Status);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public Download()
{
InitializeComponent();
_controller = App.ControllerInstance;
_controller.Install(InstallProgress, Status);
_ = _controller.Install(InstallProgress, Status);
}
}
}

0 comments on commit 6e044b0

Please sign in to comment.