Rebased the entire system to have a built-in downloader. Also probably fixed some bugs?

This commit is contained in:
IveBeenAlone
2026-01-18 20:03:35 -05:00
parent 80c2985921
commit 25fbe2f22b
4 changed files with 354 additions and 13 deletions

269
Form1.cs
View File

@@ -5,12 +5,18 @@ using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace HelloWorld
{
@@ -19,6 +25,10 @@ namespace HelloWorld
public Form1()
{
InitializeComponent();
LoadComboBoxItems();
LoadDownloadedFiles();
string path = ".ibalaunch";
string uuidsave = ".ibalaunch\\uuid";
string usersave = ".ibalaunch\\username";
@@ -159,22 +169,57 @@ namespace HelloWorld
Console.WriteLine("UUID Shit done.");
// All of this shit is Last Played version data.
string DropDownGameVers = comboBox2Play.Text;
string verssave = ".ibalaunch\\lastplayedversion";
File.Create(verssave).Dispose();
Console.WriteLine("LastPlayedVersion File exists, comparing textbox");
string VersFileText = File.ReadAllText(verssave);
if (VersFileText != DropDownGameVers)
{
Console.WriteLine("LastPlayedVersion mismatch, writing!");
try
{
File.WriteAllText(verssave, DropDownGameVers);
Console.WriteLine("LastPlayedVersion file saved.");
}
catch (Exception)
{
Console.WriteLine("An error occurred: idfk probably rw permission error?");
}
}
else
{
Console.WriteLine("LastPlayedVersion already saved.");
}
Console.WriteLine("LastPlayedVersion Shit done.");
// Genuinely FUCK windows and C# and fucking whatever else to make this shit work
// I swear to fucking god I spent a solid 3 hours trying to make this thing
// OPEN A FUCKING EXE AND PASS ARGS CORRECTLY
string relativeExePath = Path.Combine("release\\package\\game\\latest\\Client\\", "HytaleClient.exe");
string relativeExePath = Path.Combine("install\\release\\package\\game\\latest\\Client\\", "HytaleClient.exe");
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string workingDirectory = Path.Combine(baseDirectory, "install");
string Hytaleappdir = "\\release\\package\\game\\latest";
string HytaleJava = "\\release\\package\\jre\\latest\\bin\\java.exe";
string workingDirectory = Path.Combine(baseDirectory, "Versions");
string Hytaleappdir = "\\install\\release\\package\\game\\latest";
string HytaleJava = "\\install\\release\\package\\jre\\latest\\bin\\java.exe";
string GamePath = "\"" + workingDirectory + "\\" + relativeExePath + "\""; //hytale.exe
string AppPath = "\"" + workingDirectory + Hytaleappdir + "\""; // game\latest
string UserdataPath = "\"" + baseDirectory + "UserData"+"\""; // game\latest
string JavaPath = "\"" + workingDirectory + HytaleJava + "\""; // java
string LaunchVersion = comboBox2Play.Text;
string GamePath = "\"" + workingDirectory + "\\" + LaunchVersion + "\\" + relativeExePath + "\""; //hytale.exe
string AppPath = "\"" + workingDirectory + "\\" + LaunchVersion + Hytaleappdir + "\""; // game\latest
string UserdataPath = "\"" + baseDirectory + "UserData"+"\"";
string JavaPath = "\"" + workingDirectory + "\\" + LaunchVersion + HytaleJava + "\""; // java
string arguments = " --app-dir " +AppPath+ " --user-dir " + UserdataPath + " --java-exec " + JavaPath + " --auth-mode offline --uuid 13371337-1337-1337-1337-1337" + textBoxUUID.Text + " --name \"" + textBoxUsername.Text + "\""; // Command-line arguments for the VB app
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = GamePath,
@@ -191,7 +236,7 @@ namespace HelloWorld
}
catch (Exception ex)
{
MessageBox.Show($"Error starting the VB.NET application: {ex.Message}");
MessageBox.Show($"Error starting the application: {ex.Message}\n" + GamePath + arguments);
}
}
@@ -204,5 +249,211 @@ namespace HelloWorld
textBoxUUID.Text = GeneratedUUIDVal.ToString();
}
private void checkUUID_CheckedChanged(object sender, EventArgs e){}
private async void LoadComboBoxItems()
{
string url = "https://ibatv.xyz/data/list.txt";
try
{
using (HttpClient client = new HttpClient())
{
string fileContents = await client.GetStringAsync(url);
string[] lines = fileContents
.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
comboBox1.Items.Clear();
comboBox1.Items.AddRange(lines);
}
}
catch (Exception ex)
{
MessageBox.Show("Failed to load items: " + ex.Message);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e){}
private async void btnInstallVersion_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedItem == null)
{
MessageBox.Show("Please select a version first.");
return;
}
string baseUrl = "https://ibatv.xyz/data/files/";
string rawName = comboBox1.SelectedItem.ToString();
string fileName = rawName.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)
? rawName
: rawName + ".zip";
string fileUrl = baseUrl + fileName;
string InstallBaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string savePath = Path.Combine(InstallBaseDirectory, fileName);
string installDir = Path.Combine(InstallBaseDirectory, "Versions");
string localListPath = Path.Combine(installDir,"versions.txt");
try
{
using (HttpClient client = new HttpClient())
using (HttpResponseMessage response = await client.GetAsync(fileUrl, HttpCompletionOption.ResponseHeadersRead))
{
response.EnsureSuccessStatusCode();
long? totalBytes = response.Content.Headers.ContentLength;
using (var contentStream = await response.Content.ReadAsStreamAsync())
using (var fileStream = new FileStream(savePath, FileMode.Create, FileAccess.Write, FileShare.None, 41943040, true))
{
var buffer = new byte[41943040]; //40MiB apparently. :shrug:
long totalRead = 0;
int bytesRead;
installProgressBar1.Value = 0;
while ((bytesRead = await contentStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
await fileStream.WriteAsync(buffer, 0, bytesRead);
totalRead += bytesRead;
if (totalBytes.HasValue)
{
int progress = (int)((totalRead * 100L) / totalBytes.Value);
installProgressBar1.Value = Math.Min(progress, 100);
}
}
}
}
string folderName = Path.GetFileNameWithoutExtension(fileName);
string extractPath = Path.Combine(installDir, folderName);
Directory.CreateDirectory(extractPath);
ZipFile.ExtractToDirectory(savePath, extractPath);
File.Delete(savePath);
string baseName = Path.GetFileNameWithoutExtension(fileName);
List<string> downloadedFiles = new List<string>();
if (File.Exists(localListPath))
downloadedFiles = File.ReadAllLines(localListPath).ToList();
// Append only if not already in the list
if (!downloadedFiles.Contains(baseName, StringComparer.OrdinalIgnoreCase))
{
File.AppendAllText(localListPath, baseName + Environment.NewLine);
LoadDownloadedFiles();
}
MessageBox.Show("Download complete:\n" + savePath + "\n" + "Extracted to:\n" + installDir);
}
catch (Exception ex)
{
MessageBox.Show("Download failed:\n" + ex.Message);
}
}
private void comboBox2Play_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void LoadDownloadedFiles()
{
string InstallBaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string installDir = Path.Combine(InstallBaseDirectory, "Versions");
string localListPath = Path.Combine(installDir, "versions.txt");
comboBox2Play.Items.Clear(); // Clear old items
if (File.Exists(localListPath))
{
var downloadedFiles = File.ReadAllLines(localListPath);
foreach (var file in downloadedFiles)
{
if (!string.IsNullOrWhiteSpace(file))
comboBox2Play.Items.Add(file);
}
}
}
private void btnUninstallVersion_Click(object sender, EventArgs e)
{
//string baseUrl = "https://ibatv.xyz/data/files/";
string rawName = comboBox1.SelectedItem.ToString();
string fileName = rawName.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)
? rawName
: rawName + ".zip";
//string fileUrl = baseUrl + fileName;
string InstallBaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string savePath = Path.Combine(InstallBaseDirectory, fileName);
string installDir = Path.Combine(InstallBaseDirectory, "Versions");
string localListPath = Path.Combine(installDir, "versions.txt");
if (comboBox2Play.SelectedItem == null)
{
MessageBox.Show("Please select a version to delete.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
string selectedVersion = comboBox2Play.SelectedItem.ToString();
// Confirm deletion
var result = MessageBox.Show(
$"Are you sure you want to delete the version '{selectedVersion}'?",
"Confirm Deletion",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question
);
if (result != DialogResult.Yes)
return;
try
{
// Delete installed folder
//string installDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string versionPath = Path.Combine(installDir, selectedVersion);
if (Directory.Exists(versionPath))
Directory.Delete(versionPath, true); // true = recursive delete
// Update local list
// string localListPath = Path.Combine(installDir, "downloaded_files.txt");
if (File.Exists(localListPath))
{
var downloadedFiles = File.ReadAllLines(localListPath).ToList();
downloadedFiles.RemoveAll(f => string.Equals(f, selectedVersion, StringComparison.OrdinalIgnoreCase));
File.WriteAllLines(localListPath, downloadedFiles);
}
// Remove from ComboBox
comboBox2Play.Items.Remove(selectedVersion);
LoadDownloadedFiles();
MessageBox.Show($"Version '{selectedVersion}' has been deleted.", "Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show("Error deleting version:\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}