Fixed Latest version played not getting saved. Also added online Launcher updater. Launcher now also says what version it is in the bottom left.

This commit is contained in:
IveBeenAlone
2026-01-19 11:27:00 -05:00
parent 25fbe2f22b
commit 636ad3d6ae
3 changed files with 163 additions and 5 deletions

131
Form1.cs
View File

@@ -22,9 +22,13 @@ namespace HelloWorld
{
public partial class Form1 : Form
{
private const string UpdateURL = "https://ibatv.xyz/data/lnch/hy.txt";
public Form1()
{
InitializeComponent();
btnLauncherUpdate.Visible = false;
LoadComboBoxItems();
LoadDownloadedFiles();
@@ -32,8 +36,19 @@ namespace HelloWorld
string path = ".ibalaunch";
string uuidsave = ".ibalaunch\\uuid";
string usersave = ".ibalaunch\\username";
string verssave = ".ibalaunch\\lastplayedversion";
string HytaleUserData = "UserData";
Version localVersion = GetLocalVersion();
string localversionstring = localVersion.ToString();
//Console.WriteLine("Version" + localversionstring);
labelLauncherVersion.Text = localversionstring;
try
{
DirectoryInfo di = Directory.CreateDirectory(path);
@@ -94,8 +109,62 @@ namespace HelloWorld
else
{
}
// UUID File Checking
if (File.Exists(verssave))
{
FileInfo fileInfo = new FileInfo(verssave);
if (fileInfo.Length == 0)
{
Console.WriteLine("Last Played file is empty. Not setting anything.");
}
else
{
Console.WriteLine("Last Played file is not empty. Size: " + fileInfo.Length + " bytes.");
comboBox2Play.Text = File.ReadAllText(verssave);
}
}
else
{
}
}
private async Task CheckForUpdateAsync()
{
try
{
Version localVersion = GetLocalVersion();
Version onlineVersion = await GetOnlineVersionAsync();
if (onlineVersion > localVersion)
{
btnLauncherUpdate.Visible = true;
}
}
catch (Exception ex)
{
// Optional: log or ignore
Debug.WriteLine(ex.Message);
}
}
private Version GetLocalVersion()
{
return Assembly.GetExecutingAssembly().GetName().Version;
}
private async Task<Version> GetOnlineVersionAsync()
{
using (HttpClient client = new HttpClient())
{
string versionText = await client.GetStringAsync(UpdateURL);
return new Version(versionText.Trim());
}
}
private void button1_Click(object sender, EventArgs e){}
private void lblHelloWorld_Click(object sender, EventArgs e){}
private void label2_Click(object sender, EventArgs e){}
@@ -455,5 +524,67 @@ namespace HelloWorld
}
}
private async void btnLauncherUpdate_Click(object sender, EventArgs e)
{
string tempExe = Path.Combine(Path.GetTempPath(), "latest.exe");
await DownloadUpdateAsync(tempExe);
StartUpdaterAndExit(tempExe);
}
private async Task DownloadUpdateAsync(string destinationPath)
{
using (HttpClient client = new HttpClient())
using (var response = await client.GetAsync("https://ibatv.xyz/data/lnch/hy/latest.exe", HttpCompletionOption.ResponseHeadersRead))
{
response.EnsureSuccessStatusCode();
using (var fs = new FileStream(
destinationPath,
FileMode.Create,
FileAccess.Write,
FileShare.None))
{
await response.Content.CopyToAsync(fs);
}
}
}
private void StartUpdaterAndExit(string newExePath)
{
string currentExe = Application.ExecutablePath;
string cmd =
$"/C timeout 2 >nul && " +
$"copy /Y \"{newExePath}\" \"{currentExe}\" && " +
$"start \"\" \"{currentExe}\"";
Process.Start(new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = cmd,
WindowStyle = ProcessWindowStyle.Normal,
CreateNoWindow = true
});
Application.Exit();
}
private async void Form1_Load(object sender, EventArgs e)
{
await CheckForUpdateAsync();
}
private void labelLauncherVersion_Click(object sender, EventArgs e)
{
}
}
}