mirror of
https://github.com/BubbaGumpShrump/AutoTrackR2.git
synced 2025-05-22 00:35:30 +00:00
commit
bb517b99e6
11 changed files with 308 additions and 80 deletions
Binary file not shown.
Before ![]() (image error) Size: 42 KiB |
BIN
AutoTrackR2/Assets/WRITH.png
Normal file
BIN
AutoTrackR2/Assets/WRITH.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 66 KiB |
|
@ -19,11 +19,10 @@
|
|||
<None Remove="Assets\HIT.png" />
|
||||
<None Remove="Assets\NW.png" />
|
||||
<None Remove="Assets\VOX.png" />
|
||||
<None Remove="Assets\WRITH.jpg" />
|
||||
<None Remove="Assets\WRITH.png" />
|
||||
<None Remove="config.ini" />
|
||||
<None Remove="Fonts\Orbitron-Bold.ttf" />
|
||||
<None Remove="Fonts\Roboto-Regular.ttf" />
|
||||
<None Remove="kill-log.csv" />
|
||||
<None Remove="KillTrackR_MainScript.ps1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -59,7 +58,7 @@
|
|||
<Resource Include="Assets\VOX.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Resource>
|
||||
<Resource Include="Assets\WRITH.jpg">
|
||||
<Resource Include="Assets\WRITH.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Resource>
|
||||
<Resource Include="config.ini" />
|
||||
|
@ -69,7 +68,6 @@
|
|||
<Resource Include="Fonts\Roboto-Regular.ttf">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Resource>
|
||||
<Resource Include="kill-log.csv" />
|
||||
<EmbeddedResource Include="KillTrackR_MainScript.ps1">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
|
|
|
@ -259,7 +259,7 @@ namespace AutoTrackR2
|
|||
(Color)ColorConverter.ConvertFromString("#FFFFFF"), // Text
|
||||
(Color)ColorConverter.ConvertFromString("#CFFF04") // AltText
|
||||
);
|
||||
ChangeLogo("/Assets/AVSQN.png", (Color)ColorConverter.ConvertFromString("#3fbcff"));
|
||||
ChangeLogo("/Assets/HEX.png", (Color)ColorConverter.ConvertFromString("#39FF14"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
</Border>
|
||||
|
||||
<!-- StackPanel for Start and Stop buttons -->
|
||||
<Border Background="{DynamicResource BackgroundDarkBrush}" BorderBrush="{DynamicResource AccentBrush}" Grid.Row="0" Grid.Column="1" BorderThickness="2" CornerRadius="5" Margin="0,0,0,134"/>
|
||||
<Border Background="{DynamicResource BackgroundDarkBrush}" BorderBrush="{DynamicResource AccentBrush}" Grid.Row="0" Grid.Column="1" BorderThickness="2" CornerRadius="5" Margin="0,0,0,82"/>
|
||||
<StackPanel Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center" Height="269" Width="152">
|
||||
<TextBlock Name="PilotNameTitle" Text="Pilot" Width="152" Height="20" Background="Transparent" FontFamily="{StaticResource Orbitron}" Margin="0,5,0,0" Foreground="{DynamicResource AltTextBrush}" FontSize="14"/>
|
||||
<TextBlock Name="PilotNameTextBox" Text="" Width="152" Height="20" Background="Transparent" FontFamily="{StaticResource Orbitron}" Margin="0,0,0,0" Foreground="{DynamicResource TextBrush}" FontSize="10" TextAlignment="Center"/>
|
||||
|
@ -35,7 +35,9 @@
|
|||
<TextBlock Name="PlayerShipTextBox" Text="" Width="152" Height="20" Background="Transparent" FontFamily="{StaticResource Orbitron}" Margin="0,0,0,0" Foreground="{DynamicResource TextBrush}" FontSize="10" TextAlignment="Center"/>
|
||||
<TextBlock Name="GameModeTitle" Text="Game Mode" Width="152" Height="20" Background="Transparent" FontFamily="{StaticResource Orbitron}" Margin="0,5,0,0" Foreground="{DynamicResource AltTextBrush}" FontSize="14"/>
|
||||
<TextBlock Name="GameModeTextBox" Text="" Width="152" Height="20" Background="Transparent" FontFamily="{StaticResource Orbitron}" Margin="0,0,0,0" Foreground="{DynamicResource TextBrush}" FontSize="10" TextAlignment="Center"/>
|
||||
<TextBox Name="DebugPanel" Text="" Width="152" Height="136" Background="Transparent" FontFamily="{StaticResource Orbitron}" Margin="0,0,0,0" Foreground="{DynamicResource TextBrush}" FontSize="8" BorderThickness="0"/>
|
||||
<TextBlock Name="KillTallyTitle" Text="Kill Tally" Width="152" Height="20" Background="Transparent" FontFamily="{StaticResource Orbitron}" Margin="0,5,0,0" Foreground="{DynamicResource AltTextBrush}" FontSize="14"/>
|
||||
<TextBlock Name="KillTallyTextBox" Text="" Width="152" Height="20" Background="Transparent" FontFamily="{StaticResource Orbitron}" Margin="0,0,0,0" Foreground="{DynamicResource TextBrush}" FontSize="10" TextAlignment="Center"/>
|
||||
<TextBox x:Name="DebugPanel" Text="" Width="152" Height="98" Background="Transparent" FontFamily="{StaticResource Orbitron}" Foreground="{DynamicResource TextBrush}" FontSize="8" BorderThickness="0" Margin="0,9,0,0"/>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center" Height="120" Width="172" >
|
||||
<Button Name="StartButton" Content="Start" Width="100" Height="40" Style="{StaticResource ButtonStyle}" FontFamily="{StaticResource Orbitron}" Margin="0,20" Click="StartButton_Click"/>
|
||||
|
|
|
@ -109,6 +109,12 @@ namespace AutoTrackR2
|
|||
GameModeTextBox.Text = gameMode;
|
||||
AdjustFontSize(GameModeTextBox);
|
||||
}
|
||||
else if (e.Data.Contains("KillTally="))
|
||||
{
|
||||
string killTally = e.Data.Split('=')[1].Trim();
|
||||
KillTallyTextBox.Text = killTally;
|
||||
AdjustFontSize(KillTallyTextBox);
|
||||
}
|
||||
else if (e.Data.Contains("NewKill="))
|
||||
{
|
||||
// Parse the kill data
|
||||
|
@ -278,6 +284,8 @@ namespace AutoTrackR2
|
|||
PilotNameTextBox.Text = string.Empty;
|
||||
PlayerShipTextBox.Text = string.Empty;
|
||||
GameModeTextBox.Text = string.Empty;
|
||||
KillTallyTextBox.Text = string.Empty;
|
||||
KillFeedStackPanel.Children.Clear();
|
||||
}
|
||||
|
||||
private void AdjustFontSize(TextBlock textBlock)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
$TrackRver = "2.0"
|
||||
$TrackRver = "2.0r"
|
||||
|
||||
# Path to the config file
|
||||
$appName = "AutoTrackR2"
|
||||
|
@ -20,6 +20,8 @@ if (Test-Path $configFile) {
|
|||
exit
|
||||
}
|
||||
|
||||
$parentApp = (Get-Process -Name AutoTrackR2).ID
|
||||
|
||||
# Access config values
|
||||
$logFilePath = $config.Logfile
|
||||
$apiUrl = $config.ApiUrl
|
||||
|
@ -97,45 +99,19 @@ $ueePattern = '<p class="entry citizen-record">\s*<span class="label">UEE Citize
|
|||
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
$process = Get-Process | Where-Object {$_.Name -like "AutoTrackR2"}
|
||||
<#
|
||||
$enemyPilot = "feezydafox"
|
||||
$enemyShip = "AEGS_Gladius"
|
||||
$KillTime = (Get-Date).ToUniversalTime().ToString("d MMM yyyy H:mm 'UTC'")
|
||||
$page1 = Invoke-WebRequest -uri "https://robertsspaceindustries.com/citizens/$enemyPilot"
|
||||
$global:killTally = 0
|
||||
$global:GameMode = ""
|
||||
$global:GameVersion = ""
|
||||
|
||||
# Get Enlisted Date
|
||||
if ($($page1.content) -match $joinDatePattern) {
|
||||
$joinDate = $matches[1]
|
||||
$joinDate = $joinDate -replace ',', ''
|
||||
} else {
|
||||
$joinDate = "-"
|
||||
# Load historic kills from csv
|
||||
if (Test-Path "$scriptFolder\Kill-Log.csv") {
|
||||
$historicKills = Import-CSV "$scriptFolder\Kill-log.csv"
|
||||
foreach ($kill in $historicKills) {
|
||||
Write-Output "NewKill=throwaway,$($kill.EnemyPilot),$($kill.EnemyShip),$($kill.OrgAffiliation),$($kill.Enlisted),$($kill.RecordNumber),$($kill.KillTime),$($kill.PFP)"
|
||||
$global:killTally++
|
||||
}
|
||||
}
|
||||
|
||||
# Check if there are any matches
|
||||
$enemyOrgs = $page1.links[4].innerHTML
|
||||
|
||||
if ($null -eq $enemyOrgs) {
|
||||
$enemyOrgs = "-"
|
||||
}
|
||||
|
||||
# Get UEE Number
|
||||
if ($($page1.content) -match $ueePattern) {
|
||||
# The matched UEE Citizen Record number is in $matches[1]
|
||||
$citizenRecord = $matches[1]
|
||||
} else {
|
||||
$citizenRecord = "-"
|
||||
}
|
||||
If ($citizenRecord -eq "n/a") {
|
||||
$citizenRecordAPI = "-1"
|
||||
$citizenRecord = "-"
|
||||
} Else {
|
||||
$citizenRecordAPI = $citizenRecord
|
||||
}
|
||||
# Get PFP
|
||||
$victimPFP = "https://robertsspaceindustries.com$($page1.images[0].src)"
|
||||
|
||||
Write-Output "NewKill=break,$enemyPilot,$enemyShip,$enemyOrgs,$joinDate,$citizenRecord,$killTime,$victimPFP"
|
||||
#>
|
||||
Write-Output "KillTally=$global:killTally"
|
||||
|
||||
# Match and extract username from gamelog
|
||||
Do {
|
||||
|
@ -169,15 +145,15 @@ Do {
|
|||
Write-Output "PlayerShip=$global:loadOut"
|
||||
|
||||
If ($line -match $versionPattern){
|
||||
$GameVersion = $matches['gameversion']
|
||||
$global:GameVersion = $matches['gameversion']
|
||||
}
|
||||
if ($line -match $acPattern){
|
||||
$GameMode = "AC"
|
||||
$global:GameMode = "AC"
|
||||
}
|
||||
if ($line -match $puPattern){
|
||||
$GameMode = "PU"
|
||||
$global:GameMode = "PU"
|
||||
}
|
||||
Write-Output "GameMode=$GameMode"
|
||||
Write-Output "GameMode=$global:GameMode"
|
||||
|
||||
}
|
||||
# If no match found, print "Logged In: False"
|
||||
|
@ -213,7 +189,11 @@ function Read-LogEntry {
|
|||
}
|
||||
|
||||
If ($null -ne $page1){
|
||||
|
||||
# Check if the Autotrackr2 process is running
|
||||
if ($null -eq (Get-Process -ID $parentApp -ErrorAction SilentlyContinue)) {
|
||||
Stop-Process -Id $PID -Force
|
||||
}
|
||||
|
||||
If ($enemyShip -eq $global:lastKill){
|
||||
$enemyShip = "Passenger"
|
||||
} Else {
|
||||
|
@ -240,7 +220,7 @@ function Read-LogEntry {
|
|||
if ($ship -notmatch $shipManPattern){
|
||||
$ship = "Player"
|
||||
}
|
||||
If ($enemyShip -notmatch $shipManPattern) {
|
||||
If ($enemyShip -notmatch $shipManPattern -and $enemyShip -notlike "Passenger" ) {
|
||||
$enemyShip = "Player"
|
||||
}
|
||||
|
||||
|
@ -258,7 +238,7 @@ function Read-LogEntry {
|
|||
$ship = $ship -replace '-00(1|2|3|4|5|6|7|8|9|0)$', ''
|
||||
}
|
||||
|
||||
$KillTime = (Get-Date).ToUniversalTime().ToString("d MMM yyyy H:mm 'UTC'")
|
||||
$KillTime = (Get-Date).ToUniversalTime().ToString("dd MMM yyyy HH:mm 'UTC'")
|
||||
|
||||
# Get Enlisted Date
|
||||
if ($($page1.content) -match $joinDatePattern) {
|
||||
|
@ -290,11 +270,17 @@ 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 = "https://cdn.robertsspaceindustries.com/static/images/account/avatar_default_big.jpg"
|
||||
}
|
||||
|
||||
$global:killTally++
|
||||
Write-Output "KillTally=$global:killTally"
|
||||
Write-Output "NewKill=throwaway,$enemyPilot,$enemyShip,$enemyOrgs,$joinDate2,$citizenRecord,$killTime,$victimPFP"
|
||||
|
||||
$GameMode = $GameMode.ToLower()
|
||||
$global:GameMode = $global:GameMode.ToLower()
|
||||
# Send to API
|
||||
# Define the data to send
|
||||
If ($null -ne $apiUrl -and $offlineMode -eq $false){
|
||||
|
@ -306,8 +292,8 @@ function Read-LogEntry {
|
|||
weapon = $weapon
|
||||
method = $damageType
|
||||
loadout_ship = $ship
|
||||
game_version = $GameVersion
|
||||
gamemode = $GameMode
|
||||
game_version = $global:GameVersion
|
||||
gamemode = $global:GameMode
|
||||
trackr_version = $TrackRver
|
||||
}
|
||||
|
||||
|
@ -320,7 +306,7 @@ function Read-LogEntry {
|
|||
|
||||
try {
|
||||
# Send the POST request with JSON data
|
||||
Invoke-RestMethod -Uri $apiURL -Method Post -Body ($data | ConvertTo-Json -Depth 5) -Headers $headers
|
||||
$null = Invoke-RestMethod -Uri $apiURL -Method Post -Body ($data | ConvertTo-Json -Depth 5) -Headers $headers
|
||||
$logMode = "API"
|
||||
} catch {
|
||||
# Catch and display errors
|
||||
|
@ -347,10 +333,11 @@ function Read-LogEntry {
|
|||
Weapon = $weapon
|
||||
Ship = $ship
|
||||
Method = $damageType
|
||||
Mode = $GameMode
|
||||
GameVersion = $GameVersion
|
||||
Mode = $global:GameMode
|
||||
GameVersion = $global:GameVersion
|
||||
TrackRver = $TrackRver
|
||||
Logged = $logMode
|
||||
PFP = $victimPFP
|
||||
}
|
||||
|
||||
# Export to CSV
|
||||
|
@ -358,8 +345,8 @@ function Read-LogEntry {
|
|||
# If file doesn't exist, create it with headers
|
||||
$killData | Export-Csv -Path $csvPath -NoTypeInformation
|
||||
} else {
|
||||
# Append data to the existing file
|
||||
$killData | Export-Csv -Path $csvPath -Append -NoTypeInformation
|
||||
# Append data to the existing file without adding headers
|
||||
$killData | ConvertTo-Csv -NoTypeInformation | Select-Object -Skip 1 | Out-File -Append -Encoding utf8 -FilePath $csvPath
|
||||
}
|
||||
|
||||
$sleeptimer = 10
|
||||
|
@ -373,7 +360,7 @@ function Read-LogEntry {
|
|||
}
|
||||
|
||||
# Record video
|
||||
if ($recording -eq $true -and $enemyShip -ne "Passenger"){
|
||||
if ($videoRecord -eq $true -and $enemyShip -ne "Passenger"){
|
||||
# send keybind for windows game bar recording
|
||||
Start-Sleep 2
|
||||
$sleeptimer = $sleeptimer -9
|
||||
|
@ -381,10 +368,10 @@ function Read-LogEntry {
|
|||
Start-Sleep 7
|
||||
|
||||
$latestFile = Get-ChildItem -Path $videoPath | Where-Object { -not $_.PSIsContainer } | Sort-Object CreationTime -Descending | Select-Object -First 1
|
||||
# Check if the latest file is no more than 10 seconds old
|
||||
# Check if the latest file is no more than 30 seconds old
|
||||
if ($latestFile) {
|
||||
$fileAgeInSeconds = (New-TimeSpan -Start $latestFile.CreationTime -End (Get-Date)).TotalSeconds
|
||||
if ($fileAgeInSeconds -le 10) {
|
||||
if ($fileAgeInSeconds -le 30) {
|
||||
# Generate a timestamp in ddMMMyyyy-HH:mm format
|
||||
$timestamp = (Get-Date).ToString("ddMMMyyyy-HHmm")
|
||||
|
||||
|
@ -419,12 +406,12 @@ function Read-LogEntry {
|
|||
|
||||
# Detect PU or AC
|
||||
if ($line -match $puPattern) {
|
||||
$GameMode = "PU"
|
||||
Write-Output "GameMode=$GameMode"
|
||||
$global:GameMode = "PU"
|
||||
Write-Output "GameMode=$global:GameMode"
|
||||
}
|
||||
if ($line -match $acPattern) {
|
||||
$GameMode = "AC"
|
||||
Write-Output "GameMode=$GameMode"
|
||||
$global:GameMode = "AC"
|
||||
Write-Output "GameMode=$global:GameMode"
|
||||
}
|
||||
|
||||
#Set loadout
|
||||
|
|
|
@ -3,6 +3,37 @@
|
|||
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>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="20" Grid.Row="2">
|
||||
<TextBlock Text="Still a work in progress. Please uninstall current version before installing update." FontSize="16" Foreground="{DynamicResource TextBrush}" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- Install Button -->
|
||||
<StackPanel HorizontalAlignment="Right" VerticalAlignment="Bottom" Grid.Row="2" Grid.Column="2">
|
||||
<Button x:Name="InstallButton" Content="Download Update" Width="150" Height="40" IsEnabled="False"
|
||||
Click="InstallButton_Click" Style="{StaticResource DisabledButtonStyle}" FontFamily="{StaticResource Orbitron}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
|
|
@ -1,12 +1,206 @@
|
|||
using System.Windows.Controls;
|
||||
using System;
|
||||
using System.IO;
|
||||
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-release";
|
||||
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;
|
||||
InstallButton.Style = (Style)FindResource("ButtonStyle");
|
||||
}
|
||||
}
|
||||
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 = "Preparing to Install...";
|
||||
|
||||
// Get the download URL for the latest release
|
||||
string downloadUrl = await GetLatestMsiDownloadUrlFromGitHub();
|
||||
|
||||
// Download the installer to the user's Downloads folder
|
||||
string installerPath = await DownloadInstallerToDownloads(downloadUrl);
|
||||
|
||||
// Launch the installer for manual installation
|
||||
RunInstaller(installerPath);
|
||||
|
||||
// Gracefully close the app after launching the installer
|
||||
Application.Current.Shutdown();
|
||||
|
||||
MessageBox.Show("Update installer has been downloaded. Please finish the installation manually.", "Update Ready", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Failed to download and launch the installer: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
InstallButton.IsEnabled = true;
|
||||
InstallButton.Content = "Install Update";
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<string> GetLatestMsiDownloadUrlFromGitHub()
|
||||
{
|
||||
using var client = new HttpClient();
|
||||
client.DefaultRequestHeaders.Add("User-Agent", "AutoTrackR2");
|
||||
|
||||
string repoOwner = "BubbaGumpShrump";
|
||||
string repoName = "AutoTrackR2";
|
||||
|
||||
try
|
||||
{
|
||||
// Fetch the latest release info from GitHub
|
||||
var url = $"https://api.github.com/repos/{repoOwner}/{repoName}/releases/latest";
|
||||
var response = await client.GetStringAsync(url);
|
||||
|
||||
// Parse the JSON response
|
||||
using var document = System.Text.Json.JsonDocument.Parse(response);
|
||||
var root = document.RootElement;
|
||||
|
||||
// Find the .msi asset in the release
|
||||
foreach (var asset in root.GetProperty("assets").EnumerateArray())
|
||||
{
|
||||
string assetName = asset.GetProperty("name").GetString();
|
||||
if (assetName.EndsWith(".msi"))
|
||||
{
|
||||
return asset.GetProperty("browser_download_url").GetString();
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception("No .msi file found in the latest release.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"Error fetching the release data: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<string> DownloadInstallerToDownloads(string url)
|
||||
{
|
||||
// Get the path to the user's Downloads folder (this works for OneDrive and other cloud storage setups)
|
||||
string downloadsFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads");
|
||||
string installerPath = Path.Combine(downloadsFolder, "AutoTrackR2_Setup.msi");
|
||||
|
||||
// Ensure the downloads folder exists
|
||||
if (!Directory.Exists(downloadsFolder))
|
||||
{
|
||||
throw new Exception($"Downloads folder not found at: {downloadsFolder}");
|
||||
}
|
||||
|
||||
using var client = new HttpClient();
|
||||
var response = await client.GetAsync(url);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
// Write the downloaded content to the Downloads folder
|
||||
using var fs = new FileStream(installerPath, FileMode.Create);
|
||||
await response.Content.CopyToAsync(fs);
|
||||
|
||||
return installerPath;
|
||||
}
|
||||
|
||||
private void RunInstaller(string installerPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Prepare the command to run the .msi installer using msiexec
|
||||
var processStartInfo = new System.Diagnostics.ProcessStartInfo
|
||||
{
|
||||
FileName = "msiexec",
|
||||
Arguments = $"/i \"{installerPath}\" /norestart REINSTALLMODE=amus", // Silent install with no restart
|
||||
UseShellExecute = true, // Ensures that the process runs in the background
|
||||
CreateNoWindow = true // Hides the command prompt window
|
||||
};
|
||||
|
||||
// Start the process (this will run the installer)
|
||||
System.Diagnostics.Process.Start(processStartInfo);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Failed to open the installer: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,6 +50,14 @@
|
|||
"PrerequisitesLocation" = "2:1"
|
||||
"Url" = "8:"
|
||||
"ComponentsUrl" = "8:"
|
||||
"Items"
|
||||
{
|
||||
"{EDC2488A-8267-493A-A98E-7D9C3B36CDF3}:.NETFramework,Version=v4.7.2"
|
||||
{
|
||||
"Name" = "8:Microsoft .NET Framework 4.7.2 (x86 and x64)"
|
||||
"ProductCode" = "8:.NETFramework,Version=v4.7.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"Release"
|
||||
|
@ -190,24 +198,24 @@
|
|||
{
|
||||
"Name" = "8:Microsoft Visual Studio"
|
||||
"ProductName" = "8:AutoTrackR2_Setup"
|
||||
"ProductCode" = "8:{01D113D7-62EA-41EE-A06E-55A8D5DD1883}"
|
||||
"PackageCode" = "8:{E1AF24CD-7A12-42A7-ABC0-6D3EDCDA6FF2}"
|
||||
"ProductCode" = "8:{288819A9-947F-47BE-900E-205C7D7EAAF7}"
|
||||
"PackageCode" = "8:{94C078B7-DD3E-4091-9F5E-780DE3481E1C}"
|
||||
"UpgradeCode" = "8:{0B78A147-D0DE-4F72-8906-A62611787CA7}"
|
||||
"AspNetVersion" = "8:"
|
||||
"RestartWWWService" = "11:FALSE"
|
||||
"RemovePreviousVersions" = "11:TRUE"
|
||||
"DetectNewerInstalledVersion" = "11:TRUE"
|
||||
"DetectNewerInstalledVersion" = "11:FALSE"
|
||||
"InstallAllUsers" = "11:FALSE"
|
||||
"ProductVersion" = "8:2.0"
|
||||
"ProductVersion" = "8:2.0.2"
|
||||
"Manufacturer" = "8:GrieferNET"
|
||||
"ARPHELPTELEPHONE" = "8:"
|
||||
"ARPHELPLINK" = "8:"
|
||||
"ARPHELPLINK" = "8:discord.gg/griefernet"
|
||||
"Title" = "8:AutoTrackR2_Setup"
|
||||
"Subject" = "8:"
|
||||
"ARPCONTACT" = "8:Fisk"
|
||||
"Keywords" = "8:"
|
||||
"ARPCOMMENTS" = "8:"
|
||||
"ARPURLINFOABOUT" = "8:"
|
||||
"ARPCOMMENTS" = "8:Star Citizen Kill Tracking App"
|
||||
"ARPURLINFOABOUT" = "8:https://GrieferNET.org"
|
||||
"ARPPRODUCTICON" = "8:"
|
||||
"ARPIconIndex" = "3:0"
|
||||
"SearchPath" = "8:"
|
||||
|
@ -554,7 +562,7 @@
|
|||
"Type" = "3:8"
|
||||
"ContextData" = "8:Bitmap"
|
||||
"Attributes" = "3:4"
|
||||
"Setting" = "3:1"
|
||||
"Setting" = "3:0"
|
||||
"UsePlugInResources" = "11:TRUE"
|
||||
}
|
||||
"CopyrightWarning"
|
||||
|
@ -565,8 +573,8 @@
|
|||
"Type" = "3:3"
|
||||
"ContextData" = "8:"
|
||||
"Attributes" = "3:0"
|
||||
"Setting" = "3:1"
|
||||
"Value" = "8:#1202"
|
||||
"Setting" = "3:2"
|
||||
"Value" = "8:GNU GENERAL PUBLIC LICENSE v3"
|
||||
"DefaultValue" = "8:#1202"
|
||||
"UsePlugInResources" = "11:TRUE"
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue