|
@@ -25,119 +25,161 @@ using Serilog.Events;
|
|
|
using Serilog.Formatting;
|
|
|
using Avalonia.Controls;
|
|
|
using Avalonia.Threading;
|
|
|
+using System.Net;
|
|
|
+using System.IO.Compression;
|
|
|
|
|
|
namespace VeloeMinecraftLauncher.ViewModels
|
|
|
{
|
|
|
public class MainWindowViewModel : ViewModelBase
|
|
|
{
|
|
|
public MainWindowViewModel()
|
|
|
- {
|
|
|
- //creating logger
|
|
|
- EventSink eventSink = new(null);
|
|
|
- eventSink.DataReceived += LogHandler;
|
|
|
-
|
|
|
- logger = new LoggerConfiguration()
|
|
|
- .MinimumLevel.Debug()
|
|
|
- .WriteTo.Sink(eventSink)
|
|
|
- .WriteTo.File("launcher.log", LogEventLevel.Debug, fileSizeLimitBytes: 100000000)// restricted... is Optional
|
|
|
- .CreateLogger();
|
|
|
- Settings.logger = logger;
|
|
|
-
|
|
|
- //loading settings
|
|
|
- logger.Debug("Loading settings.");
|
|
|
- Settings.LoadSettings();
|
|
|
- username = Settings.Username;
|
|
|
-
|
|
|
- //loading local verions
|
|
|
- logger.Debug("Loading local versions.");
|
|
|
- updateAvailable();
|
|
|
-
|
|
|
- //check launcher update
|
|
|
- logger.Debug("Checking launcher versions updates.");
|
|
|
- latestLauncherInfo = Downloader.DownloadAndDeserializeJsonData<LatestLauncherVersion>("https://files.veloe.link/launcher/update/versions.json");
|
|
|
- if (latestLauncherInfo is not null)
|
|
|
- {
|
|
|
- logger.Debug("Launcher version on server: {0}", latestLauncherInfo.latest);
|
|
|
- logger.Debug("Launcher version: {0}", Assembly.GetExecutingAssembly().GetName().Version);
|
|
|
- string[] version = latestLauncherInfo.latest.Split('.');
|
|
|
-
|
|
|
- var vat = Assembly.GetExecutingAssembly().GetName().Version;
|
|
|
-
|
|
|
- if (Int16.Parse(version[0]) > Assembly.GetExecutingAssembly().GetName().Version.Major ||
|
|
|
- Int16.Parse(version[1]) > Assembly.GetExecutingAssembly().GetName().Version.Minor ||
|
|
|
- Int16.Parse(version[2]) > Assembly.GetExecutingAssembly().GetName().Version.Build ||
|
|
|
- Int16.Parse(version[3]) > Assembly.GetExecutingAssembly().GetName().Version.Revision)
|
|
|
+ {
|
|
|
+ Task.Run(() =>
|
|
|
{
|
|
|
- logger.Debug("Update available!");
|
|
|
- IsUpdateAvailable = true;
|
|
|
- }
|
|
|
- }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ //creating logger
|
|
|
+ EventSink eventSink = new(null);
|
|
|
+ eventSink.DataReceived += LogHandler;
|
|
|
+
|
|
|
+ logger = new LoggerConfiguration()
|
|
|
+ .MinimumLevel.Debug()
|
|
|
+ .WriteTo.Sink(eventSink)
|
|
|
+ .WriteTo.File("launcher.log", LogEventLevel.Debug, fileSizeLimitBytes: 100000000)// restricted... is Optional
|
|
|
+ .CreateLogger();
|
|
|
+ Settings.logger = logger;
|
|
|
+
|
|
|
+ //loading settings
|
|
|
+ logger.Debug("Loading settings.");
|
|
|
+ Settings.LoadSettings();
|
|
|
+ username = Settings.Username;
|
|
|
+
|
|
|
+ //loading local verions
|
|
|
+ logger.Debug("Loading local versions.");
|
|
|
+ updateAvailable();
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ OpenErrorWindow(ex);
|
|
|
+ }
|
|
|
|
|
|
- logger.Debug("Connecting to WebSoket");
|
|
|
- //conection to my servers
|
|
|
- connection = new HubConnectionBuilder()
|
|
|
- .WithUrl("https://monitor.veloe.link/hubs/data")
|
|
|
- .WithAutomaticReconnect()
|
|
|
- .Build();
|
|
|
+ UpdateUpdater();
|
|
|
|
|
|
- Func<Exception, Task> reconnecting = ex => Task.Run(() => {
|
|
|
- logger.Warning("Reconnecting to WebCoket...");
|
|
|
- });
|
|
|
- Func<string, Task> reconnected = str => Task.Run(() => {
|
|
|
- logger.Warning("Reconnected to WebCoket.");
|
|
|
- connection.InvokeAsync("ConnectToGroup", "McTFC");
|
|
|
- connection.InvokeAsync("ConnectToGroup", "McVanilla");
|
|
|
- connection.InvokeAsync("ConnectToGroup", "McTech");
|
|
|
- });
|
|
|
+ try
|
|
|
+ {
|
|
|
+ //check launcher update
|
|
|
+ logger.Information("Checking launcher versions updates.");
|
|
|
+ latestLauncherInfo = Downloader.DownloadAndDeserializeJsonData<LatestLauncherVersion>("https://files.veloe.link/launcher/update/versions.json");
|
|
|
+ if (latestLauncherInfo is not null)
|
|
|
+ {
|
|
|
+ logger.Information("Launcher version on server: {0}", latestLauncherInfo.latest);
|
|
|
+ logger.Information("Launcher version: {0}", Assembly.GetExecutingAssembly().GetName().Version);
|
|
|
+ string[] version = latestLauncherInfo.latest.Split('.');
|
|
|
|
|
|
- connection.Reconnecting += reconnecting;
|
|
|
- connection.Reconnected += reconnected;
|
|
|
+ var vat = Assembly.GetExecutingAssembly().GetName().Version;
|
|
|
|
|
|
- connection.On<string>("UpdateMcTFC", (message) =>
|
|
|
- {
|
|
|
- McStatus status = JsonSerializer.Deserialize<McStatus>(message);
|
|
|
- McTfcBlock = $"McTFC: Online {status.NumPlayers}/{status.MaxPlayers}";
|
|
|
- mcTfcTimer.Stop();
|
|
|
- mcTfcTimer.Start();
|
|
|
- //ConsoleText += message;
|
|
|
- });
|
|
|
+ if (Int16.Parse(version[0]) > Assembly.GetExecutingAssembly().GetName().Version.Major ||
|
|
|
+ Int16.Parse(version[1]) > Assembly.GetExecutingAssembly().GetName().Version.Minor ||
|
|
|
+ Int16.Parse(version[2]) > Assembly.GetExecutingAssembly().GetName().Version.Build ||
|
|
|
+ Int16.Parse(version[3]) > Assembly.GetExecutingAssembly().GetName().Version.Revision)
|
|
|
+ {
|
|
|
+ logger.Debug("Update available!");
|
|
|
+ IsUpdateAvailable = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ OpenErrorWindow(ex);
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ logger.Debug("Connecting to WebSoket");
|
|
|
+ //conection to my servers
|
|
|
+ connection = new HubConnectionBuilder()
|
|
|
+ .WithUrl("https://monitor.veloe.link/hubs/data")
|
|
|
+ .WithAutomaticReconnect()
|
|
|
+ .Build();
|
|
|
+
|
|
|
+ Func<Exception, Task> reconnecting = ex => Task.Run(() =>
|
|
|
+ {
|
|
|
+ logger.Warning("Reconnecting to WebCoket...");
|
|
|
+ });
|
|
|
+ Func<string, Task> reconnected = str => Task.Run(() =>
|
|
|
+ {
|
|
|
+ logger.Warning("Reconnected to WebCoket.");
|
|
|
+ connection.InvokeAsync("ConnectToGroup", "McTFC");
|
|
|
+ connection.InvokeAsync("ConnectToGroup", "McVanilla");
|
|
|
+ connection.InvokeAsync("ConnectToGroup", "McTech");
|
|
|
+ });
|
|
|
|
|
|
- connection.On<string>("UpdateMcVanilla", (message) =>
|
|
|
- {
|
|
|
- McStatus status = JsonSerializer.Deserialize<McStatus>(message);
|
|
|
- McTfcBlock = $"McVanilla: Online {status.NumPlayers}/{status.MaxPlayers}";
|
|
|
- mcTechTimer.Stop();
|
|
|
- mcTechTimer.Start();
|
|
|
- //ConsoleText += message;
|
|
|
- });
|
|
|
+ connection.Reconnecting += reconnecting;
|
|
|
+ connection.Reconnected += reconnected;
|
|
|
|
|
|
- connection.On<string>("UpdateMcTech", (message) =>
|
|
|
- {
|
|
|
- McStatus status = JsonSerializer.Deserialize<McStatus>(message);
|
|
|
- McTfcBlock = $"McTech: Online {status.NumPlayers}/{status.MaxPlayers}";
|
|
|
- mcVanillaTimer.Stop();
|
|
|
- mcVanillaTimer.Start();
|
|
|
- //ConsoleText += message;
|
|
|
- });
|
|
|
+ connection.On<string>("UpdateMcTFC", (message) =>
|
|
|
+ {
|
|
|
+ McStatus status = JsonSerializer.Deserialize<McStatus>(message);
|
|
|
+ McTfcBlock = $"McTFC: Online";
|
|
|
+ McTfcPlayersBlock = $"{status.NumPlayers}/{status.MaxPlayers}";
|
|
|
+ McTfcTip = String.Empty;
|
|
|
+ if (UInt16.Parse(status.NumPlayers) > 0)
|
|
|
+ foreach (var player in status.Players)
|
|
|
+ {
|
|
|
+ McTfcTip += player;
|
|
|
+ McTfcTip += "\n";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ McTfcTip = "No players.";
|
|
|
+ mcTfcTimer.Stop();
|
|
|
+ mcTfcTimer.Start();
|
|
|
|
|
|
- mcTfcTimer.Elapsed += OnTimedEventMcTfc;
|
|
|
- mcTfcTimer.Start();
|
|
|
- mcTechTimer.Elapsed += OnTimedEventMcTech;
|
|
|
- mcTechTimer.Start();
|
|
|
- mcVanillaTimer.Elapsed += OnTimedEventMcVanilla;
|
|
|
- mcVanillaTimer.Start();
|
|
|
+ //ConsoleText += message;
|
|
|
+ });
|
|
|
|
|
|
- connection.StartAsync();
|
|
|
+ connection.On<string>("UpdateMcVanilla", (message) =>
|
|
|
+ {
|
|
|
+ McStatus status = JsonSerializer.Deserialize<McStatus>(message);
|
|
|
+ McVanillaBlock = $"McVanilla: Online";
|
|
|
+ McVanillaPlayersBlock = $"{status.NumPlayers}/{status.MaxPlayers}";
|
|
|
+ mcTechTimer.Stop();
|
|
|
+ mcTechTimer.Start();
|
|
|
+ //ConsoleText += message;
|
|
|
+ });
|
|
|
|
|
|
- connection.InvokeAsync("ConnectToGroup", "McTFC");
|
|
|
- connection.InvokeAsync("ConnectToGroup", "McVanilla");
|
|
|
- connection.InvokeAsync("ConnectToGroup", "McTech");
|
|
|
+ connection.On<string>("UpdateMcTech", (message) =>
|
|
|
+ {
|
|
|
+ McStatus status = JsonSerializer.Deserialize<McStatus>(message);
|
|
|
+ McTechBlock = $"McTech: Online {status.NumPlayers}/{status.MaxPlayers}";
|
|
|
+ McTechPlayersBlock = $"{status.NumPlayers}/{status.MaxPlayers}";
|
|
|
+ mcVanillaTimer.Stop();
|
|
|
+ mcVanillaTimer.Start();
|
|
|
+ //ConsoleText += message;
|
|
|
+ });
|
|
|
|
|
|
- consoleOutputTimer.Elapsed += UpdateConsoleOutput;
|
|
|
- consoleOutputTimer.AutoReset = false;
|
|
|
- }
|
|
|
+ mcTfcTimer.Elapsed += OnTimedEventMcTfc;
|
|
|
+ mcTfcTimer.Start();
|
|
|
+ mcTechTimer.Elapsed += OnTimedEventMcTech;
|
|
|
+ mcTechTimer.Start();
|
|
|
+ mcVanillaTimer.Elapsed += OnTimedEventMcVanilla;
|
|
|
+ mcVanillaTimer.Start();
|
|
|
+
|
|
|
+ connection.StartAsync();
|
|
|
|
|
|
- int i = 0;
|
|
|
+ connection.InvokeAsync("ConnectToGroup", "McTFC");
|
|
|
+ connection.InvokeAsync("ConnectToGroup", "McVanilla");
|
|
|
+ connection.InvokeAsync("ConnectToGroup", "McTech");
|
|
|
+
|
|
|
+ consoleOutputTimer.Elapsed += UpdateConsoleOutput;
|
|
|
+ consoleOutputTimer.AutoReset = false;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ OpenErrorWindow(ex);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
System.Timers.Timer mcTfcTimer = new System.Timers.Timer(30000);
|
|
|
System.Timers.Timer mcTechTimer = new System.Timers.Timer(30000);
|
|
@@ -157,6 +199,12 @@ namespace VeloeMinecraftLauncher.ViewModels
|
|
|
private string mcTfcBlock = "Wait for update...";
|
|
|
private string mcTechBlock = "Wait for update...";
|
|
|
private string mcVanillaBlock = "Wait for update...";
|
|
|
+ private string mcTfcPlayersBlock = String.Empty;
|
|
|
+ private string mcTechPlayersBlock = String.Empty;
|
|
|
+ private string mcVanillaPlayersBlock = String.Empty;
|
|
|
+ private string mcTfcTip = "No players.";
|
|
|
+ private string mcTechTip = "No players.";
|
|
|
+ private string mcVanillaTip = "No players.";
|
|
|
|
|
|
ILogger logger;
|
|
|
|
|
@@ -300,6 +348,60 @@ namespace VeloeMinecraftLauncher.ViewModels
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public string McTfcPlayersBlock
|
|
|
+ {
|
|
|
+ get => mcTfcPlayersBlock;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ this.RaiseAndSetIfChanged(ref mcTfcPlayersBlock, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public string McTechPlayersBlock
|
|
|
+ {
|
|
|
+ get => mcTechPlayersBlock;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ this.RaiseAndSetIfChanged(ref mcTechPlayersBlock, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public string McVanillaPlayersBlock
|
|
|
+ {
|
|
|
+ get => mcVanillaPlayersBlock;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ this.RaiseAndSetIfChanged(ref mcVanillaPlayersBlock, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public string McTfcTip
|
|
|
+ {
|
|
|
+ get => mcTfcTip;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ this.RaiseAndSetIfChanged(ref mcTfcTip, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public string McTechTip
|
|
|
+ {
|
|
|
+ get => mcTechTip;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ this.RaiseAndSetIfChanged(ref mcTechTip, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public string McVanillaTip
|
|
|
+ {
|
|
|
+ get => mcVanillaTip;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ this.RaiseAndSetIfChanged(ref mcVanillaTip, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public int ConsoleTextCaretIndex
|
|
|
{
|
|
|
get { return int.MaxValue; }
|
|
@@ -313,123 +415,144 @@ namespace VeloeMinecraftLauncher.ViewModels
|
|
|
|
|
|
public void OnClickCommand()
|
|
|
{
|
|
|
- var versionsDownloader = new VersionsDownloader { DataContext = new VersionsDownloaderViewModel() };
|
|
|
+ var versionsDownloader = new VersionsDownloader
|
|
|
+ {
|
|
|
+ DataContext = new VersionsDownloaderViewModel()
|
|
|
+ };
|
|
|
|
|
|
if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
|
|
{
|
|
|
//var versionsDownloaderTask =
|
|
|
versionsDownloader.Closed += updateAvailable;
|
|
|
versionsDownloader.ShowDialog(desktop.MainWindow);
|
|
|
- //versionsDownloaderTask.Wait();
|
|
|
-
|
|
|
+ //versionsDownloaderTask.Wait();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public void StartMinecraft()
|
|
|
{
|
|
|
- logger.Debug("Starting minecraft.");
|
|
|
- if (DownloadedVerion is null)
|
|
|
- return;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ logger.Debug("Starting minecraft.");
|
|
|
+ if (DownloadedVerion is null)
|
|
|
+ return;
|
|
|
|
|
|
- int version = 0;
|
|
|
+ int version = 0;
|
|
|
|
|
|
- //var verionJsonFileStream = File.OpenRead(DownloadedVerion.path);
|
|
|
- using (StreamReader reader = new StreamReader(DownloadedVerion.path))
|
|
|
- {
|
|
|
- string json = reader.ReadToEnd();
|
|
|
+ //var verionJsonFileStream = File.OpenRead(DownloadedVerion.path);
|
|
|
+ using (StreamReader reader = new StreamReader(DownloadedVerion.path))
|
|
|
+ {
|
|
|
+ string json = reader.ReadToEnd();
|
|
|
|
|
|
- var versionJson = JsonSerializer.Deserialize<Entity.Version.Version>(json);
|
|
|
+ var versionJson = JsonSerializer.Deserialize<Entity.Version.Version>(json);
|
|
|
|
|
|
- string arguments = StartCommandBuilder.Build(versionJson, Username);
|
|
|
+ string arguments = StartCommandBuilder.Build(versionJson, Username);
|
|
|
|
|
|
- if (!Settings.useCustomJava)
|
|
|
- {
|
|
|
- if (versionJson.javaVersion != null)
|
|
|
+ if (!Settings.useCustomJava)
|
|
|
{
|
|
|
- logger.Debug("Java version required: {0}", versionJson.javaVersion.majorVersion);
|
|
|
- version = versionJson.javaVersion.majorVersion;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (versionJson.inheritsFrom != null)
|
|
|
+ if (versionJson.javaVersion != null)
|
|
|
{
|
|
|
- using (StreamReader inheritsFromReader = new StreamReader(Settings.MinecraftForlderPath + "versions/" + versionJson.inheritsFrom + "/" + versionJson.inheritsFrom + ".json"))
|
|
|
+ logger.Debug("Java version required: {0}", versionJson.javaVersion.majorVersion);
|
|
|
+ version = versionJson.javaVersion.majorVersion;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (versionJson.inheritsFrom != null)
|
|
|
{
|
|
|
- string jsonInheritsFrom = inheritsFromReader.ReadToEnd();
|
|
|
- var inheritsFromJson = JsonSerializer.Deserialize<Entity.Version.Version>(jsonInheritsFrom);
|
|
|
- if (inheritsFromJson.javaVersion != null)
|
|
|
+ using (StreamReader inheritsFromReader = new StreamReader(Settings.MinecraftForlderPath + "versions/" + versionJson.inheritsFrom + "/" + versionJson.inheritsFrom + ".json"))
|
|
|
{
|
|
|
- logger.Debug("Java version required: {0}", inheritsFromJson.javaVersion.majorVersion);
|
|
|
- version = inheritsFromJson.javaVersion.majorVersion;
|
|
|
+ string jsonInheritsFrom = inheritsFromReader.ReadToEnd();
|
|
|
+ var inheritsFromJson = JsonSerializer.Deserialize<Entity.Version.Version>(jsonInheritsFrom);
|
|
|
+ if (inheritsFromJson.javaVersion != null)
|
|
|
+ {
|
|
|
+ logger.Debug("Java version required: {0}", inheritsFromJson.javaVersion.majorVersion);
|
|
|
+ version = inheritsFromJson.javaVersion.majorVersion;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ ConsoleText += arguments;
|
|
|
+ ArgumentsBox = arguments;
|
|
|
}
|
|
|
-
|
|
|
- ConsoleText += arguments;
|
|
|
- ArgumentsBox = arguments;
|
|
|
- }
|
|
|
|
|
|
- if (DownloadedVerion is null)
|
|
|
- return;
|
|
|
+ if (DownloadedVerion is null)
|
|
|
+ return;
|
|
|
|
|
|
- string javaPath = Settings.JavaPath;
|
|
|
+ string javaPath = Settings.JavaPath;
|
|
|
|
|
|
- if (!Settings.useCustomJava)
|
|
|
- javaPath = Settings.MinecraftForlderPath + "javaruntime/" + version + "/bin/java.exe";
|
|
|
+ if (!Settings.useCustomJava)
|
|
|
+ {
|
|
|
+ javaPath = Settings.MinecraftForlderPath + "javaruntime/" + version + "/bin/java";
|
|
|
+ if (OperatingSystem.IsWindows())
|
|
|
+ javaPath += ".exe";
|
|
|
+ }
|
|
|
|
|
|
- logger.Debug("Java version path: {0}", javaPath);
|
|
|
- logger.Debug("Minecraft arguments: {0}", ArgumentsBox);
|
|
|
+ logger.Debug("Java version path: {0}", javaPath);
|
|
|
+ logger.Debug("Minecraft arguments: {0}", ArgumentsBox);
|
|
|
|
|
|
- ProcessStartInfo proc;
|
|
|
- proc = new ProcessStartInfo
|
|
|
- {
|
|
|
- UseShellExecute = false,
|
|
|
- RedirectStandardOutput = true,
|
|
|
- RedirectStandardError = true,
|
|
|
- WindowStyle = ProcessWindowStyle.Hidden,
|
|
|
- CreateNoWindow = true,
|
|
|
- FileName = System.IO.Path.Combine(Settings.MinecraftForlderPath, javaPath),
|
|
|
- StandardErrorEncoding = Encoding.UTF8,
|
|
|
- WorkingDirectory = Settings.MinecraftForlderPath,
|
|
|
- Arguments = ArgumentsBox
|
|
|
- };
|
|
|
+ ProcessStartInfo proc;
|
|
|
+ proc = new ProcessStartInfo
|
|
|
+ {
|
|
|
+ UseShellExecute = false,
|
|
|
+ RedirectStandardOutput = true,
|
|
|
+ RedirectStandardError = true,
|
|
|
+ WindowStyle = ProcessWindowStyle.Hidden,
|
|
|
+ CreateNoWindow = true,
|
|
|
+ FileName = System.IO.Path.Combine(Settings.MinecraftForlderPath, javaPath),
|
|
|
+ StandardErrorEncoding = Encoding.UTF8,
|
|
|
+ WorkingDirectory = Settings.MinecraftForlderPath,
|
|
|
+ Arguments = ArgumentsBox
|
|
|
+ };
|
|
|
|
|
|
|
|
|
- Process minecraft = new Process();
|
|
|
+ Process minecraft = new Process();
|
|
|
|
|
|
- minecraft.StartInfo = proc;
|
|
|
+ minecraft.StartInfo = proc;
|
|
|
|
|
|
- Task.Run(() =>
|
|
|
- {
|
|
|
- logger.Debug("Starting java process.");
|
|
|
-
|
|
|
- minecraft.OutputDataReceived += OutputHandler;
|
|
|
- minecraft.ErrorDataReceived += OutputHandler;
|
|
|
+ Task.Run(() =>
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ logger.Debug("Starting java process.");
|
|
|
|
|
|
- //minecraft.Exited += ProcessExited; //dont work properly
|
|
|
- //* Start process and handlers
|
|
|
- //minecraft.WaitForExit();
|
|
|
- minecraft.Start();
|
|
|
+ minecraft.OutputDataReceived += OutputHandler;
|
|
|
+ minecraft.ErrorDataReceived += OutputHandler;
|
|
|
|
|
|
- minecraft.BeginOutputReadLine();
|
|
|
- minecraft.BeginErrorReadLine();
|
|
|
+ //minecraft.Exited += ProcessExited; //dont work properly
|
|
|
+ //* Start process and handlers
|
|
|
+ //minecraft.WaitForExit();
|
|
|
+ minecraft.Start();
|
|
|
|
|
|
- if (!Settings.gameLogToLauncher)
|
|
|
- {
|
|
|
- minecraft.OutputDataReceived -= OutputHandler;
|
|
|
- minecraft.CancelOutputRead();
|
|
|
- }
|
|
|
+ minecraft.BeginOutputReadLine();
|
|
|
+ minecraft.BeginErrorReadLine();
|
|
|
|
|
|
- return Task.CompletedTask;
|
|
|
- });
|
|
|
- logger.Debug("Updating Username in Settings");
|
|
|
- Settings.Username = username;
|
|
|
- Settings.lastChosenVersion = DownloadedVerion.version;
|
|
|
- Settings.SaveSettings();
|
|
|
+ if (!Settings.gameLogToLauncher)
|
|
|
+ {
|
|
|
+ minecraft.OutputDataReceived -= OutputHandler;
|
|
|
+ minecraft.CancelOutputRead();
|
|
|
+ }
|
|
|
|
|
|
+ return Task.CompletedTask;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ OpenErrorWindow(ex);
|
|
|
+ return Task.CompletedTask;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ logger.Debug("Updating Settings");
|
|
|
+ Settings.Username = username;
|
|
|
+ Settings.lastChosenVersion = DownloadedVerion.version;
|
|
|
+ Settings.SaveSettings();
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ OpenErrorWindow(ex);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
|
|
@@ -497,9 +620,11 @@ namespace VeloeMinecraftLauncher.ViewModels
|
|
|
|
|
|
foreach (var dir in dirs)
|
|
|
{
|
|
|
+ logger.Debug("Checking folder {0}", dir.Name);
|
|
|
string checkedPath;
|
|
|
- if (File.Exists(checkedPath = dir.FullName + "\\" + dir.Name + ".json"))
|
|
|
+ if (File.Exists(checkedPath = dir.FullName + "/" + dir.Name + ".json"))
|
|
|
{
|
|
|
+ logger.Debug("Found version {0}",dir.Name);
|
|
|
DownloadedVersions.Add(new DownloadedVerion() { path = checkedPath, version = dir.Name });
|
|
|
profiles.profiles.Add($"Version {dir.Name}", new Profile() { name = dir.Name, lastVersionId = dir.Name, launcherVisibilityOnGameClose = "keep the launcher open" });
|
|
|
}
|
|
@@ -538,7 +663,14 @@ namespace VeloeMinecraftLauncher.ViewModels
|
|
|
|
|
|
public void updateAvailable(object sendingObject, EventArgs e)
|
|
|
{
|
|
|
- updateAvailable();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ updateAvailable();
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ OpenErrorWindow(ex);
|
|
|
+ }
|
|
|
|
|
|
switch (sendingObject)
|
|
|
{
|
|
@@ -559,11 +691,8 @@ namespace VeloeMinecraftLauncher.ViewModels
|
|
|
|
|
|
if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
|
|
{
|
|
|
- //var versionsDownloaderTask =
|
|
|
settingsWindow.Closed += updateAvailable;
|
|
|
settingsWindow.ShowDialog(desktop.MainWindow);
|
|
|
- //versionsDownloaderTask.Wait();
|
|
|
- //updateAvailable();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -571,19 +700,127 @@ namespace VeloeMinecraftLauncher.ViewModels
|
|
|
{
|
|
|
logger.Debug("Started updater.exe");
|
|
|
Process updater = new Process();
|
|
|
- updater.StartInfo.FileName = "updater.exe";
|
|
|
+ updater.StartInfo.FileName = "Updater";
|
|
|
+ if (OperatingSystem.IsWindows())
|
|
|
+ updater.StartInfo.FileName += ".exe";
|
|
|
|
|
|
- updater.Start();
|
|
|
+ if (!File.Exists(updater.StartInfo.FileName))
|
|
|
+ UpdateUpdater();
|
|
|
|
|
|
- if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
|
|
+ if (!File.Exists(updater.StartInfo.FileName))
|
|
|
{
|
|
|
- //var versionsDownloaderTask =
|
|
|
- desktop.MainWindow.Close();
|
|
|
- //versionsDownloaderTask.Wait();
|
|
|
- //updateAvailable();
|
|
|
+ updater.Start();
|
|
|
+
|
|
|
+ if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
|
|
+ {
|
|
|
+ desktop.MainWindow.Close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ OpenErrorWindow(new FileNotFoundException($"File {updater.StartInfo.FileName} not found!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void UpdateUpdater()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string fileName = "Updater";
|
|
|
+ if (OperatingSystem.IsWindows())
|
|
|
+ fileName += ".exe";
|
|
|
+ if (File.Exists(fileName))
|
|
|
+ {
|
|
|
+ FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(fileName);
|
|
|
+ LatestLauncherVersion latestLauncherVersion = Downloader.DownloadAndDeserializeJsonData<LatestLauncherVersion>("https://files.veloe.link/launcher/update/versions.json");
|
|
|
+
|
|
|
+ if (OperatingSystem.IsLinux())
|
|
|
+ {
|
|
|
+ logger.Information("Manual updates only.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (latestLauncherVersion != null)
|
|
|
+ {
|
|
|
+ string[] version = latestLauncherVersion.updater.Split('.');
|
|
|
+ logger.Information("Latest updater version on server: {0}", latestLauncherVersion.updater);
|
|
|
+ string[] versionOnServer = fileVersionInfo.FileVersion.Split('.');
|
|
|
+ logger.Information("Updater version: {0}", fileVersionInfo.FileVersion);
|
|
|
+
|
|
|
+ if (!(Int16.Parse(version[0]) > Int16.Parse(versionOnServer[0]) ||
|
|
|
+ Int16.Parse(version[1]) > Int16.Parse(versionOnServer[1]) ||
|
|
|
+ Int16.Parse(version[2]) > Int16.Parse(versionOnServer[2]) ||
|
|
|
+ Int16.Parse(version[3]) > Int16.Parse(versionOnServer[3])))
|
|
|
+ {
|
|
|
+ logger.Information("No update required.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ WebClient webClient = new WebClient();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ logger.Information("Downloading updater.zip");
|
|
|
+ string url = String.Empty;
|
|
|
+
|
|
|
+ if (OperatingSystem.IsWindows())
|
|
|
+ url = "https://files.veloe.link/launcher/update/updater.zip";
|
|
|
+
|
|
|
+ if (OperatingSystem.IsLinux())
|
|
|
+ url = "https://files.veloe.link/launcher/update/updater_linux-x64.zip";
|
|
|
+
|
|
|
+ if (url == String.Empty)
|
|
|
+ return;
|
|
|
+
|
|
|
+ webClient.DownloadFile(new System.Uri(url), "updater.zip"); ;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ logger.Error("Error occured on getting updater.zip from the server.");
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+
|
|
|
+ logger.Information("Unpacking updater.zip");
|
|
|
+ ZipFile.ExtractToDirectory($"updater.zip", Directory.GetCurrentDirectory(), true);
|
|
|
+
|
|
|
+ logger.Information("Deleting updater.zip");
|
|
|
+ File.Delete($"updater.zip");
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ OpenErrorWindow(ex);
|
|
|
}
|
|
|
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OpenErrorWindow(Exception ex)
|
|
|
+ {
|
|
|
+ var message = ex.Message;
|
|
|
+ var stackTrace = ex.StackTrace;
|
|
|
+ Settings.logger.Error(ex.Message);
|
|
|
+ Settings.logger.Error(ex.StackTrace);
|
|
|
+ Exception innerException = ex.InnerException;
|
|
|
+ while (innerException is not null)
|
|
|
+ {
|
|
|
+ message += "\n" + innerException.Message;
|
|
|
+ stackTrace += "\n" + innerException.StackTrace;
|
|
|
+ Settings.logger.Error(innerException.Message);
|
|
|
+ Settings.logger.Error(innerException.StackTrace);
|
|
|
+ innerException = innerException.InnerException;
|
|
|
+ }
|
|
|
|
|
|
+ Dispatcher.UIThread.InvokeAsync(() =>
|
|
|
+ {
|
|
|
+ if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
|
|
+ {
|
|
|
+ var ErrorMessageViewModel = new ErrorWindowViewModel(message, stackTrace);
|
|
|
+ var ErrorMessage = new ErrorWindow()
|
|
|
+ {
|
|
|
+ DataContext = ErrorMessageViewModel
|
|
|
+ };
|
|
|
+ ErrorMessage.ShowDialog(desktop.MainWindow);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
private void OnTimedEventMcTfc(Object source, ElapsedEventArgs e)
|
|
@@ -605,6 +842,7 @@ namespace VeloeMinecraftLauncher.ViewModels
|
|
|
public class LatestLauncherVersion
|
|
|
{
|
|
|
public string latest { get; set; }
|
|
|
+ public string updater { get; set; }
|
|
|
public string url { get; set; }
|
|
|
}
|
|
|
|