151 lines
5.0 KiB
C#
151 lines
5.0 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.IO.Compression;
|
|
using System.Net;
|
|
using System.Windows;
|
|
using System.Windows.Forms;
|
|
|
|
namespace HighGroundRoyaleLauncher
|
|
{
|
|
public partial class MainWindow : Window
|
|
{
|
|
private string remoteVersionURL = "http://147.93.30.25/HGR/HGRVersion.txt";
|
|
private string remoteZipURL = "http://147.93.30.25/HGR/HGRBuild.zip";
|
|
|
|
private string installPath = "";
|
|
private string zipPath => Path.Combine(installPath, "game.zip");
|
|
private string versionPath => Path.Combine(installPath, "version.txt");
|
|
private string gameFolder => Path.Combine(installPath, "Game");
|
|
private string exePath => Path.Combine(gameFolder, "HighGroundRoyaleNetcode.exe");
|
|
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
installPathBox.Text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "HighGroundRoyale");
|
|
}
|
|
|
|
private void Browse_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
using (var dialog = new FolderBrowserDialog())
|
|
{
|
|
dialog.Description = "Select Installation Folder";
|
|
dialog.SelectedPath = installPathBox.Text;
|
|
|
|
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
{
|
|
installPathBox.Text = dialog.SelectedPath;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void InstallButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
installPath = installPathBox.Text.Trim();
|
|
|
|
if (string.IsNullOrEmpty(installPath))
|
|
{
|
|
System.Windows.MessageBox.Show("Please select a valid installation path.");
|
|
return;
|
|
}
|
|
|
|
Directory.CreateDirectory(installPath);
|
|
CheckForUpdates();
|
|
}
|
|
|
|
private void CheckForUpdates()
|
|
{
|
|
statusText.Text = "Checking for updates...";
|
|
using (WebClient client = new WebClient())
|
|
{
|
|
client.DownloadStringCompleted += (s, e) =>
|
|
{
|
|
if (e.Error == null)
|
|
{
|
|
string remoteVersion = e.Result.Trim();
|
|
string localVersion = File.Exists(versionPath) ? File.ReadAllText(versionPath).Trim() : "";
|
|
|
|
if (remoteVersion != localVersion)
|
|
{
|
|
statusText.Text = "Update available. Downloading...";
|
|
DownloadGame(remoteVersion);
|
|
}
|
|
else
|
|
{
|
|
statusText.Text = "Up to date.";
|
|
LaunchGame();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
statusText.Text = "Failed to check version.";
|
|
System.Windows.MessageBox.Show(e.Error.Message);
|
|
}
|
|
};
|
|
client.DownloadStringAsync(new Uri(remoteVersionURL));
|
|
}
|
|
}
|
|
|
|
private void DownloadGame(string newVersion)
|
|
{
|
|
using (WebClient client = new WebClient())
|
|
{
|
|
client.DownloadProgressChanged += (s, e) =>
|
|
{
|
|
progressBar.Value = e.ProgressPercentage;
|
|
};
|
|
|
|
client.DownloadFileCompleted += (s, e) =>
|
|
{
|
|
if (e.Error == null)
|
|
{
|
|
statusText.Text = "Download complete. Extracting...";
|
|
ExtractGame(newVersion);
|
|
}
|
|
else
|
|
{
|
|
statusText.Text = "Download failed.";
|
|
System.Windows.MessageBox.Show(e.Error.Message);
|
|
}
|
|
};
|
|
|
|
client.DownloadFileAsync(new Uri(remoteZipURL), zipPath);
|
|
}
|
|
}
|
|
|
|
private void ExtractGame(string newVersion)
|
|
{
|
|
try
|
|
{
|
|
if (Directory.Exists(gameFolder))
|
|
Directory.Delete(gameFolder, true);
|
|
|
|
ZipFile.ExtractToDirectory(zipPath, gameFolder);
|
|
File.WriteAllText(versionPath, newVersion);
|
|
File.Delete(zipPath);
|
|
|
|
statusText.Text = "Installation complete!";
|
|
LaunchGame();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
statusText.Text = "Extraction failed.";
|
|
System.Windows.MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void LaunchGame()
|
|
{
|
|
if (File.Exists(exePath))
|
|
{
|
|
Process.Start(exePath);
|
|
System.Windows.Application.Current.Shutdown();
|
|
}
|
|
else
|
|
{
|
|
System.Windows.MessageBox.Show("Game executable not found after install.");
|
|
}
|
|
}
|
|
}
|
|
}
|