KillTally

This commit is contained in:
BubbaGumpShrump 2024-12-08 15:15:56 -05:00
parent 2b003ef7f8
commit af8d0a756b
6 changed files with 83 additions and 68 deletions

View file

@ -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"/>

View file

@ -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

View file

@ -97,45 +97,18 @@ $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
# Get Enlisted Date
if ($($page1.content) -match $joinDatePattern) {
$joinDate = $matches[1]
$joinDate = $joinDate -replace ',', ''
} else {
$joinDate = "-"
}
# 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"
#>
# Load historic kills from csv
$historicKills = Import-CSV "$scriptFolder\Kill-log.csv" | Sort-Object Descending
Try{
foreach ($kill in $historicKills) {
Write-Output "NewKill=throwaway,$($kill.EnemyPilot),$($kill.EnemyShip),$($kill.OrgAffiliation),$($kill.Enlisted),$($kill.RecordNumber),$($kill.KillTime),$($kill.PFP)"
$global:killTally++
}
} Catch {}
Write-Output "KillTally=$global:killTally"
# Match and extract username from gamelog
Do {
@ -296,6 +269,8 @@ function Read-LogEntry {
$victimPFP = $page1.images[0].src
}
$global:killTally++
Write-Output "KillTally=$global:killTally"
Write-Output "NewKill=throwaway,$enemyPilot,$enemyShip,$enemyOrgs,$joinDate2,$citizenRecord,$killTime,$victimPFP"
$GameMode = $GameMode.ToLower()
@ -355,6 +330,7 @@ function Read-LogEntry {
GameVersion = $GameVersion
TrackRver = $TrackRver
Logged = $logMode
PFP = $victimPFP
}
# Export to CSV

View file

@ -28,7 +28,7 @@
<!-- 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}"/>
Click="InstallButton_Click" Style="{StaticResource DisabledButtonStyle}" FontFamily="{StaticResource Orbitron}"/>
</StackPanel>
</Grid>
</Grid>

View file

@ -9,7 +9,7 @@ namespace AutoTrackR2
{
public partial class UpdatePage : UserControl
{
private string currentVersion = "v2.0-beta.1";
private string currentVersion = "v2.0-beta.01";
private string latestVersion;
public UpdatePage()
@ -33,6 +33,7 @@ namespace AutoTrackR2
if (IsNewVersionAvailable(currentVersion, latestVersion))
{
InstallButton.IsEnabled = true;
InstallButton.Style = (Style)FindResource("ButtonStyle");
}
}
catch (Exception ex)
@ -94,25 +95,25 @@ namespace AutoTrackR2
try
{
InstallButton.IsEnabled = false;
InstallButton.Content = "Installing...";
InstallButton.Content = "Preparing to Install...";
// Define the download URL
string downloadUrl = "https://github.com/BubbaGumpShrump/AutoTrackR2/releases/download/v2.0-beta.1/AutoTrackR2_Setup.msi";
// Get the download URL for the latest release
string downloadUrl = await GetLatestMsiDownloadUrlFromGitHub();
// Download the installer before closing the app
string installerPath = await DownloadInstaller(downloadUrl);
// Download the installer to the user's Downloads folder
string installerPath = await DownloadInstallerToDownloads(downloadUrl);
// Launch the installer after the download completes
// Launch the installer for manual installation
RunInstaller(installerPath);
// Gracefully close the app after starting the installer
// Gracefully close the app after launching the installer
Application.Current.Shutdown();
MessageBox.Show("Update installed successfully. Please restart the application.", "Update Installed", MessageBoxButton.OK, MessageBoxImage.Information);
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 install update: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show($"Failed to download and launch the installer: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
finally
{
@ -121,39 +122,69 @@ namespace AutoTrackR2
}
}
private async Task<string> DownloadInstaller(string url)
private async Task<string> GetLatestMsiDownloadUrlFromGitHub()
{
string tempFilePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "AutoTrackR2_Setup.msi");
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
string downloadsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Downloads";
string installerPath = Path.Combine(downloadsFolder, "AutoTrackR2_Setup.msi");
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);
// Write the downloaded content to the Downloads folder
using var fs = new FileStream(installerPath, FileMode.Create);
await response.Content.CopyToAsync(fs);
return tempFilePath;
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}\" /quiet /norestart",
UseShellExecute = false, // 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);
// Start the installer manually (this will let the user run it)
System.Diagnostics.Process.Start(installerPath);
}
catch (Exception ex)
{
MessageBox.Show($"Failed to start the installer: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show($"Failed to open the installer: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}

View file

@ -198,8 +198,8 @@
{
"Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:AutoTrackR2_Setup"
"ProductCode" = "8:{108D4428-AB25-444D-90C2-E507EA3020D8}"
"PackageCode" = "8:{0EBFA2DB-5EEC-48A0-9212-E8C33A05CE53}"
"ProductCode" = "8:{F79114DA-3386-4C48-8836-A39014EFC706}"
"PackageCode" = "8:{AE03249A-7FA7-432F-A8D6-D6B34490F51F}"
"UpgradeCode" = "8:{0B78A147-D0DE-4F72-8906-A62611787CA7}"
"AspNetVersion" = "8:"
"RestartWWWService" = "11:FALSE"