123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using Avalonia;
- using Avalonia.Controls;
- using Avalonia.Controls.ApplicationLifetimes;
- using Avalonia.Media;
- using Avalonia.Threading;
- using ReactiveUI;
- using ReactiveUI.Validation.Helpers;
- using System;
- using System.ComponentModel;
- using System.IO;
- using System.Net;
- using VeloeMinecraftLauncher.Utils;
- using VeloeMinecraftLauncher.Views;
- using VeloeMinecraftLauncher.Views.TitleBar;
- namespace VeloeMinecraftLauncher.ViewModels;
- public class ViewModelBase : ReactiveValidationObject
- {
- public ViewModelBase()
- {
- this.RaisePropertyChanged(nameof(InterfaceColor));
- this.RaisePropertyChanged(nameof(MaterialOpacity));
- }
- public Color InterfaceColor
- {
- get => Color.Parse("Black");
- set => this.RaisePropertyChanged(nameof(InterfaceColor));
- }
- public float MaterialOpacity
- {
- get => 0.5F;
- set => this.RaisePropertyChanged(nameof(MaterialOpacity));
- }
- public static void OpenErrorWindow(Exception ex)
- {
- string message = string.Empty;
- string stackTrace = string.Empty;
- string logfile = string.Empty;
- Exception? innerException;
- switch (ex)
- {
- case WebException or Win32Exception or JavaProcessException or IOException:
- message = ex.Message;
- Settings.logger.Error(ex.Message);
- if (ex is JavaProcessException javaEx && Path.Exists(javaEx.LogPath))
- logfile = ((JavaProcessException)ex).LogPath;
- if (ex.StackTrace is not null)
- Settings.logger.Error(ex.StackTrace);
- innerException = ex.InnerException;
- while (innerException is not null)
- {
- Settings.logger.Error(innerException.Message);
- if (innerException.StackTrace is not null)
- Settings.logger.Error(innerException.StackTrace);
- innerException = innerException.InnerException;
- }
- break;
- default:
- message = ex.Message;
- stackTrace = ex.StackTrace ?? string.Empty;
- Settings.logger.Error(ex.Message);
- if (ex.StackTrace is not null)
- Settings.logger.Error(ex.StackTrace);
- innerException = ex.InnerException;
- while (innerException is not null)
- {
- message += "\n" + innerException.Message;
- stackTrace += "\n" + innerException.StackTrace;
- Settings.logger.Error(innerException.Message);
- if (innerException.StackTrace is not null)
- Settings.logger.Error(innerException.StackTrace);
- innerException = innerException.InnerException;
- }
- break;
- }
- OpenErrorWindow(message, logfile, stackTrace);
- }
- public static void OpenErrorWindow(string message, string logfile = "", string stackTrace = "")
- {
- #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
- if (Application.Current is not null && Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
- {
- Dispatcher.UIThread.InvokeAsync(() =>
- {
- var ErrorMessageViewModel = new MessageWindowViewModel(message, "Error message", logfile: logfile);
- var ErrorMessage = new MessageWindow()
- {
- DataContext = ErrorMessageViewModel
- };
- //TODO change it to binding
- ErrorMessage.GetControl<TitleBarWindow>("titleBar").TitleText = "Error Message";
-
- ErrorMessage.ShowDialog(desktop.MainWindow);
- });
- }
- #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
- }
- }
|