fixed some bugs, added ability to work without internet

This commit is contained in:
2025-05-21 13:50:10 +05:00
parent ab1aefd619
commit e915892fa2
7 changed files with 79 additions and 46 deletions

View File

@@ -2,7 +2,6 @@ using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Mlaumcherb.Client.Avalonia.классы;
using Mlaumcherb.Client.Avalonia.сеть;
using Mlaumcherb.Client.Avalonia.сеть.Update;
using Mlaumcherb.Client.Avalonia.холопы;
@@ -20,19 +19,26 @@ public class LauncherApp : Application
Config = Config.LoadFromFile();
Logger.DebugLogEnabled = Config.debug;
AvaloniaXamlLoader.Load(this);
Update();
// some file required by forge installer
if (!File.Exists("launcher_profiles.json"))
try
{
File.WriteAllText("launcher_profiles.json", "{}");
}
SelfUpdateAsync();
// some file required by forge installer
if (!File.Exists("launcher_profiles.json"))
{
File.WriteAllText("launcher_profiles.json", "{}");
}
InstalledVersionCatalog = InstalledVersionCatalog.Load();
InstalledVersionCatalog = InstalledVersionCatalog.Load();
}
catch (Exception e)
{
ErrorHelper.ShowMessageBox(nameof(LauncherApp), e);
}
}
private async void Update()
private async void SelfUpdateAsync()
{
try
{
@@ -46,6 +52,10 @@ public class LauncherApp : Application
Logger.LogInfo(nameof(LauncherApp), "restarting...");
upd.RestartSelf();
}
else
{
Logger.LogInfo(nameof(LauncherApp), "no updates found");
}
}
catch (Exception e)
{

View File

@@ -71,7 +71,7 @@ public partial class MainWindow : Window
try
{
LauncherApp.Logger.OnLogMessage += GuiLogMessage;
LauncherVersionTextBox.Text = $"v {Assembly.GetExecutingAssembly().GetName().Version}";
LauncherVersionTextBox.Text = $"v{Assembly.GetExecutingAssembly().GetName().Version}";
PlayerName = LauncherApp.Config.player_name;
MemoryLimit = LauncherApp.Config.max_memory;
@@ -92,6 +92,20 @@ public partial class MainWindow : Window
}
}
protected override void OnUnloaded(RoutedEventArgs e)
{
SaveGuiPropertiesToConfig();
}
private void SaveGuiPropertiesToConfig()
{
LauncherApp.Config.player_name = PlayerName;
LauncherApp.Config.max_memory = MemoryLimit;
LauncherApp.Config.download_java = EnableJavaDownload;
LauncherApp.Config.redirect_game_output = RedirectGameOutput;
LauncherApp.Config.SaveToFile();
}
private void UpdateInstalledVersionsCatalogView(string? selectVersion)
{
LauncherApp.InstalledVersionCatalog.CheckInstalledVersions();
@@ -121,8 +135,15 @@ public partial class MainWindow : Window
private void RescanInstalledVersionsButton_OnClick(object? sender, RoutedEventArgs e)
{
var selectedVersionView = InstalledVersionCatalogComboBox.SelectedItem as InstalledGameVersionItemView;
UpdateInstalledVersionsCatalogView(selectedVersionView?.Props.Id);
try
{
var selectedVersionView = InstalledVersionCatalogComboBox.SelectedItem as InstalledGameVersionItemView;
UpdateInstalledVersionsCatalogView(selectedVersionView?.Props.Id);
}
catch (Exception ex)
{
ErrorHelper.ShowMessageBox(nameof(MainWindow), ex);
}
}
private void GuiLogMessage(LauncherLogger.LogMessage msg)
@@ -147,22 +168,27 @@ public partial class MainWindow : Window
Dispatcher.UIThread.Invoke(() => LaunchButton.IsEnabled = false);
LauncherApp.Config.last_launched_version = selectedVersionView.Props.Id;
LauncherApp.Config.player_name = PlayerName;
LauncherApp.Config.max_memory = MemoryLimit;
LauncherApp.Config.download_java = EnableJavaDownload;
LauncherApp.Config.redirect_game_output = RedirectGameOutput;
LauncherApp.Config.SaveToFile();
SaveGuiPropertiesToConfig();
var v = await selectedVersionView.Props.LoadDescriptor(UpdateGameFiles);
await v.Download(UpdateGameFiles, nt =>
{
Dispatcher.UIThread.Invoke(() =>
try
{
await v.Download(UpdateGameFiles, nt =>
{
DownloadsPanel.Children.Add(new NetworkTaskView(nt,
ntv => DownloadsPanel.Children.Remove(ntv)));
});
}
);
Dispatcher.UIThread.Invoke(() =>
{
DownloadsPanel.Children.Add(new NetworkTaskView(nt,
ntv => DownloadsPanel.Children.Remove(ntv)));
});
}
);
}
catch (Exception ex)
{
ErrorHelper.ShowMessageBox(nameof(MainWindow), ex);
}
Dispatcher.UIThread.Invoke(() =>
{
UpdateGameFiles = false;
@@ -183,7 +209,6 @@ public partial class MainWindow : Window
{
try
{
string workingDir = Directory.GetCurrent().ToString();
LauncherApp.Logger.LogDebug(nameof(MainWindow),
$"opening working directory: {workingDir}");