Fixes maybe

This commit is contained in:
BubbaGumpShrump 2024-12-08 12:26:10 -05:00
parent 7b95c7ae54
commit 5474348087
2 changed files with 37 additions and 30 deletions
AutoTrackR2
AutoTrackR2_Setup

View file

@ -1,4 +1,5 @@
using System; using System;
using System.IO;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
@ -8,7 +9,7 @@ namespace AutoTrackR2
{ {
public partial class UpdatePage : UserControl public partial class UpdatePage : UserControl
{ {
private string currentVersion = "v2.0-beta.0"; private string currentVersion = "v2.0-beta.1";
private string latestVersion; private string latestVersion;
public UpdatePage() public UpdatePage()
@ -114,38 +115,27 @@ namespace AutoTrackR2
private async Task<string> GetDownloadUrlFromGitHub() private async Task<string> GetDownloadUrlFromGitHub()
{ {
using var client = new HttpClient(); // Use the exact URL since we know it
client.DefaultRequestHeaders.Add("User-Agent", "AutoTrackR2"); return "https://github.com/BubbaGumpShrump/AutoTrackR2/releases/download/v2.0-beta.1/AutoTrackR2_Setup.msi";
}
// GitHub repo details private bool IsFileLocked(string filePath)
string repoOwner = "BubbaGumpShrump"; {
string repoName = "AutoTrackR2"; try
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 assets array
var assets = root.GetProperty("assets");
foreach (var asset in assets.EnumerateArray())
{ {
// Look for a `.msi` asset using (var fileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None))
var name = asset.GetProperty("name").GetString();
if (name != null && name.EndsWith(".msi", StringComparison.OrdinalIgnoreCase))
{ {
return asset.GetProperty("browser_download_url").GetString(); return false; // File is not locked
} }
} }
catch (IOException)
throw new Exception("No .msi installer found in the latest release assets."); {
return true; // File is locked
}
} }
private async Task DownloadAndInstallUpdate(string url) private async Task DownloadAndInstallUpdate(string url)
{ {
string tempFilePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "update.exe"); string tempFilePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "AutoTrackR2_Setup.msi");
using var client = new HttpClient(); using var client = new HttpClient();
var response = await client.GetAsync(url); var response = await client.GetAsync(url);
@ -154,8 +144,25 @@ namespace AutoTrackR2
using var fs = new System.IO.FileStream(tempFilePath, System.IO.FileMode.Create); using var fs = new System.IO.FileStream(tempFilePath, System.IO.FileMode.Create);
await response.Content.CopyToAsync(fs); await response.Content.CopyToAsync(fs);
// Launch the installer // Wait for the system to release the file
System.Diagnostics.Process.Start(tempFilePath); await Task.Delay(2000); // Wait for 2 seconds
// Check if the file is locked
if (IsFileLocked(tempFilePath))
{
MessageBox.Show("The installer file is locked by another process.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
try
{
// Launch the installer
System.Diagnostics.Process.Start(tempFilePath);
}
catch (Exception ex)
{
MessageBox.Show($"Failed to start the installer: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
} }
} }
} }

View file

@ -198,15 +198,15 @@
{ {
"Name" = "8:Microsoft Visual Studio" "Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:AutoTrackR2_Setup" "ProductName" = "8:AutoTrackR2_Setup"
"ProductCode" = "8:{EFAF7F55-60EF-4945-8F33-90A4F528AD59}" "ProductCode" = "8:{772D186F-E30D-4D2B-99F2-F246555558FA}"
"PackageCode" = "8:{C60FD0A3-3782-47B2-A89B-EBAD286F0786}" "PackageCode" = "8:{5A6337B9-AA07-4C66-8796-160B93276023}"
"UpgradeCode" = "8:{0B78A147-D0DE-4F72-8906-A62611787CA7}" "UpgradeCode" = "8:{0B78A147-D0DE-4F72-8906-A62611787CA7}"
"AspNetVersion" = "8:" "AspNetVersion" = "8:"
"RestartWWWService" = "11:FALSE" "RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE" "RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:TRUE" "DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:FALSE" "InstallAllUsers" = "11:FALSE"
"ProductVersion" = "8:2.0" "ProductVersion" = "8:1.9"
"Manufacturer" = "8:GrieferNET" "Manufacturer" = "8:GrieferNET"
"ARPHELPTELEPHONE" = "8:" "ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:" "ARPHELPLINK" = "8:"