Update Test 1

This commit is contained in:
BubbaGumpShrump 2024-12-08 11:39:28 -05:00
parent abd10c1092
commit 097e72e3a3
3 changed files with 181 additions and 3 deletions

View file

@ -290,7 +290,11 @@ function Read-LogEntry {
}
# Get PFP
$victimPFP = "https://robertsspaceindustries.com$($page1.images[0].src)"
if ($page1.images[0].src -like "/media/*") {
$victimPFP = "https://robertsspaceindustries.com$($page1.images[0].src)"
} Else {
$victimPFP = $page1.images[0].src
}
Write-Output "NewKill=throwaway,$enemyPilot,$enemyShip,$enemyOrgs,$joinDate2,$citizenRecord,$killTime,$victimPFP"

View file

@ -3,6 +3,33 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="396" Width="626">
<Grid Background="{DynamicResource BackgroundLightBrush}">
<TextBlock Text="Download and update features coming soon!" FontSize="24" Foreground="{DynamicResource TextBrush}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Grid Margin="0,0,5,7">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!-- Current Version Display -->
<StackPanel Orientation="Horizontal" Margin="10" Grid.Row="0">
<TextBlock Text="Current Version: " FontSize="16" FontWeight="Bold" VerticalAlignment="Center" Foreground="{DynamicResource AltTextBrush}" />
<TextBlock x:Name="CurrentVersionText" Text="2.0-beta.0" FontSize="16" VerticalAlignment="Center" Foreground="{DynamicResource TextBrush}"/>
</StackPanel>
<!-- Available Version Display -->
<StackPanel Orientation="Horizontal" Margin="10" Grid.Row="1">
<TextBlock Text="Available Version: " FontSize="16" FontWeight="Bold" VerticalAlignment="Center" Foreground="{DynamicResource AltTextBrush}"/>
<TextBlock x:Name="AvailableVersionText" Text="Checking..." FontSize="16" VerticalAlignment="Center" Foreground="{DynamicResource TextBrush}"/>
</StackPanel>
<!-- Install Button -->
<StackPanel HorizontalAlignment="Right" VerticalAlignment="Bottom" Grid.Row="2" Grid.Column="2">
<Button x:Name="InstallButton" Content="Install Update" Width="150" Height="40" IsEnabled="False"
Click="InstallButton_Click" Style="{StaticResource ButtonStyle}" FontFamily="{StaticResource Orbitron}"/>
</StackPanel>
</Grid>
</Grid>
</UserControl>

View file

@ -1,12 +1,159 @@
using System.Windows.Controls;
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace AutoTrackR2
{
public partial class UpdatePage : UserControl
{
private string currentVersion = "v2.0-beta.0";
private string latestVersion;
public UpdatePage()
{
InitializeComponent();
CurrentVersionText.Text = currentVersion;
CheckForUpdates();
}
private async void CheckForUpdates()
{
try
{
// Fetch the latest release info from GitHub
latestVersion = await GetLatestVersionFromGitHub();
// Update the Available Version field
AvailableVersionText.Text = latestVersion;
// Enable the Install button if a new version is available
if (IsNewVersionAvailable(currentVersion, latestVersion))
{
InstallButton.IsEnabled = true;
}
}
catch (Exception ex)
{
AvailableVersionText.Text = "Error checking updates.";
MessageBox.Show($"Failed to check for updates: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private async Task<string> GetLatestVersionFromGitHub()
{
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("User-Agent", "AutoTrackR2");
string repoOwner = "BubbaGumpShrump";
string repoName = "AutoTrackR2";
try
{
// Attempt to fetch the latest release
var url = $"https://api.github.com/repos/{repoOwner}/{repoName}/releases/latest";
var response = await client.GetStringAsync(url);
// Parse the JSON using System.Text.Json
using var document = System.Text.Json.JsonDocument.Parse(response);
var root = document.RootElement;
var tagName = root.GetProperty("tag_name").GetString();
return tagName;
}
catch (HttpRequestException ex) when (ex.StatusCode == System.Net.HttpStatusCode.NotFound)
{
// Fallback to releases list if 'latest' not found
var url = $"https://api.github.com/repos/{repoOwner}/{repoName}/releases";
var response = await client.GetStringAsync(url);
using var document = System.Text.Json.JsonDocument.Parse(response);
var root = document.RootElement;
// Get the tag name of the first release
if (root.GetArrayLength() > 0)
{
var firstRelease = root[0];
return firstRelease.GetProperty("tag_name").GetString();
}
throw new Exception("No releases found.");
}
}
private bool IsNewVersionAvailable(string currentVersion, string latestVersion)
{
// Compare version strings (you can implement more complex version parsing logic if needed)
return string.Compare(currentVersion, latestVersion, StringComparison.Ordinal) < 0;
}
private async void InstallButton_Click(object sender, RoutedEventArgs e)
{
try
{
InstallButton.IsEnabled = false;
InstallButton.Content = "Installing...";
// Download and install the latest version
string downloadUrl = await GetDownloadUrlFromGitHub();
await DownloadAndInstallUpdate(downloadUrl);
MessageBox.Show("Update installed successfully. Please restart the application.", "Update Installed", MessageBoxButton.OK, MessageBoxImage.Information);
}
catch (Exception ex)
{
MessageBox.Show($"Failed to install update: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
finally
{
InstallButton.IsEnabled = true;
InstallButton.Content = "Install Update";
}
}
private async Task<string> GetDownloadUrlFromGitHub()
{
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("User-Agent", "AutoTrackR2");
// GitHub repo details
string repoOwner = "BubbaGumpShrump";
string repoName = "AutoTrackR2";
var url = $"https://api.github.com/repos/{repoOwner}/{repoName}/releases/latest";
var response = await client.GetStringAsync(url);
// Parse the JSON using System.Text.Json
using var document = System.Text.Json.JsonDocument.Parse(response);
var root = document.RootElement;
// Extract the browser download URL for the first asset
var assets = root.GetProperty("assets");
if (assets.GetArrayLength() > 0)
{
var downloadUrl = assets[0].GetProperty("browser_download_url").GetString();
return downloadUrl;
}
else
{
throw new Exception("No assets found in the latest release.");
}
}
private async Task DownloadAndInstallUpdate(string url)
{
string tempFilePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "update.exe");
using var client = new HttpClient();
var response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
using var fs = new System.IO.FileStream(tempFilePath, System.IO.FileMode.Create);
await response.Content.CopyToAsync(fs);
// Launch the installer
System.Diagnostics.Process.Start(tempFilePath);
}
}
}