Skip to content

Commit

Permalink
Rewrite release manager to handle unique release instances for each R…
Browse files Browse the repository at this point in the history
…ID/type/version combo
  • Loading branch information
rettoph committed May 3, 2021
1 parent f1161c1 commit d81c510
Show file tree
Hide file tree
Showing 26 changed files with 586 additions and 681 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using System.Windows;
Expand All @@ -11,6 +12,7 @@
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VoidHuntersRevived.Client.Launcher.Models;
using VoidHuntersRevived.Client.Launcher.Services;

namespace VoidHuntersRevived.Client.Launcher.Controls
Expand Down Expand Up @@ -42,11 +44,50 @@ public LaunchType(String handle, String name, String description)
this.Name = name;
this.Description = description;

if (LauncherService.CheckUpdate(this.Handle))
this.LaunchButton.IsEnabled = false;

(new Thread(new ThreadStart(() =>
{
_shouldUpdate = true;
this.LaunchButton.Content = "Update & Launch";
}
var attempt = 0;
Release latest = default;

while(latest == default && attempt < 5)
{
attempt++;

this.Dispatcher.Invoke(() =>
{
this.LaunchButton.Content = $"({attempt}) Checking for Updates...";
});

latest = LauncherService.Info(this.Handle);
}

if(latest == default)
{
this.Dispatcher.Invoke(() =>
{
this.LaunchButton.Content = $"Update Server Unavailable";
});
}
else if (!Directory.Exists(latest?.DownloadPath))
{
this.Dispatcher.Invoke(() =>
{
_shouldUpdate = true;
this.LaunchButton.Content = "Update & Launch";
this.LaunchButton.IsEnabled = true;
});
}
else
{
this.Dispatcher.Invoke(() =>
{
this.LaunchButton.Content = "Launch";
this.LaunchButton.IsEnabled = true;
});
}
}))).Start();

this.LaunchButton.Click += this.HandleLaunchClicked;
}
Expand All @@ -58,7 +99,10 @@ private void HandleLaunchClicked(object sender, RoutedEventArgs e)
{
if (_shouldUpdate)
{
this.LaunchButton.Content = "Updating...";
this.Dispatcher.Invoke(() =>
{
this.LaunchButton.Content = "Updating...";
});

var proc = LauncherService.Update(this.Handle);

Expand All @@ -79,9 +123,12 @@ private void HandleLaunchClicked(object sender, RoutedEventArgs e)
}
}

this.LaunchButton.Content = "Launching...";
LauncherService.Launch(this.Handle);
this.Dispatcher.Invoke(() =>
{
this.LaunchButton.Content = "Launching...";
});

LauncherService.Launch(this.Handle);
Thread.Sleep(2000);

this.Dispatcher.Invoke(() =>
Expand Down
18 changes: 18 additions & 0 deletions src/clients/VoidHuntersRevived.Client.Launcher/Models/Release.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace VoidHuntersRevived.Client.Launcher.Models
{
public class Release
{
public Int32 Id { get; set; }
public String Version { get; set; }
public String RID { get; set; }
public String Type { get; set; }
public String DownloadUrl { get; set; }
public DateTime CreatedAt { get; set; }
public String DownloadPath { get; set; }
public String Executable { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Microsoft.Win32;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using VoidHuntersRevived.Client.Launcher.Models;

namespace VoidHuntersRevived.Client.Launcher.Services
{
Expand All @@ -17,34 +19,38 @@ static LauncherService()
_path = Registry.GetValue("HKEY_CURRENT_USER\\Software\\rettoph\\VoidHuntersRevived", "InstallDir", "undefined").ToString();
}

public static Process Run(String args, Boolean useShellExecute = false, Boolean redirectStandardOutput = true, Boolean createNoWindow = true)
public static Process Run(String args, Boolean redirect = true)
{
return Process.Start(new ProcessStartInfo()
{
FileName = System.IO.Path.Combine(_path, _excecutable),
WorkingDirectory = _path,
Arguments = args,
UseShellExecute = useShellExecute,
RedirectStandardOutput = redirectStandardOutput,
CreateNoWindow = createNoWindow
UseShellExecute = false,
RedirectStandardOutput = redirect,
RedirectStandardError = redirect
});
}

public static Boolean CheckUpdate(String type)
public static Release Info(String type)
{
var proc = LauncherService.Run($"{type} --check");
var proc = LauncherService.Run($"{type} --action info");

return Boolean.Parse(proc.StandardOutput.ReadLine());
proc.WaitForExit();

var output = proc.StandardOutput.ReadToEnd();

return JsonConvert.DeserializeObject<Release>(output);
}

public static Process Update(String type)
{
return LauncherService.Run($"{type} --update");
return LauncherService.Run($"{type} --action update");
}

public static Process Launch(String type)
{
return LauncherService.Run($"{type} --launch", false, false, false);
return LauncherService.Run($"{type} --action launch", false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
<UseWPF>true</UseWPF>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
Target="[INSTALLFOLDER]\VoidHuntersRevived.Utilities.Launcher.exe"
Directory="ProgramMenuSubfolder"
WorkingDirectory="INSTALLFOLDER"
Arguments="client-launcher --launch"
Arguments="client-launcher --action launch"
Icon="icon.ico"
/>

Expand Down
Loading

0 comments on commit d81c510

Please sign in to comment.