Skip to content

Commit

Permalink
Merge pull request #1
Browse files Browse the repository at this point in the history
fetch version list from online
  • Loading branch information
Plextora authored Feb 10, 2023
2 parents 6971432 + a82de9c commit 31d9f0c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
4 changes: 4 additions & 0 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Forms;
Expand All @@ -27,6 +29,7 @@ public partial class MainWindow
public static bool IsMinecraftRunning;
public static bool IsCustomDll;
public static string? CustomDllName;
public static List<string> VersionList = new();

private NotifyIcon? _notifyIcon;
private readonly ContextMenu _contextMenu = new();
Expand Down Expand Up @@ -57,6 +60,7 @@ public MainWindow()
CreditWindow.Closing += OnClosing;
Updater.GetInjectorChangelog();
Updater.GetClientChangelog();
Updater.FetchVersionList();

_notifyIcon = new NotifyIcon();
if (!File.Exists("first_run"))
Expand Down
37 changes: 29 additions & 8 deletions Utils/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public static class Updater
"https://raw.githubusercontent.com/Imrglop/Latite-Releases/main/injector_changelog";
private const string CLIENT_CHANGELOG_URL =
"https://raw.githubusercontent.com/Imrglop/Latite-Releases/main/client_changelog";
private const string GAME_VERSIONS_URL =
"https://raw.githubusercontent.com/Imrglop/Latite-Releases/main/game_versions";
private static string? _selectedVersion;

private static readonly WebClient? Client = new WebClient();
Expand Down Expand Up @@ -79,16 +81,35 @@ public static void UpdateInjector()
Application.Current.Shutdown();
}

public static void FetchVersionList()
{
if (Form != null) {
Form.VersionSelectionComboBox.Items.Clear();
MainWindow.VersionList.Clear();
if (Client != null)
{
string str = Client.DownloadString(
GAME_VERSIONS_URL);
if (str != null)
{
str.Replace("\r", ""); // Remove RETURN so the string is clean.
string[] lines = str.Split('\n');

foreach (string line in lines)
{
MainWindow.VersionList.Add(line);
string displayStr = "Version " + line;
Form.VersionSelectionComboBox.Items.Add(displayStr);
}
}
}
Form.VersionSelectionComboBox.SelectedIndex = 0;
}
}

public static string GetSelectedVersion()
{
return Form?.VersionSelectionComboBox.SelectedIndex switch
{
0 => "1.19.51",
1 => "1.18.12",
2 => "1.18",
3 => "1.17.41",
_ => "Could not get version"
};
return VersionList[Form.VersionSelectionComboBox.SelectedIndex];
}

private static string? GetChangelogLine(string? changelog, int line, string changelogNum)
Expand Down

0 comments on commit 31d9f0c

Please sign in to comment.