123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- using ReactiveUI;
- using ReactiveUI.Validation.Extensions;
- using System;
- using System.IO;
- using System.Reflection;
- using VeloeMinecraftLauncher.MinecraftLauncher;
- using Avalonia.Controls;
- using System.Threading.Tasks;
- using System.Collections.ObjectModel;
- using Serilog.Events;
- using Avalonia.Media;
- using Avalonia;
- using Egorozh.ColorPicker;
- using VeloeMinecraftLauncher.Views;
- namespace VeloeMinecraftLauncher.ViewModels
- {
- public class SettingsWindowViewModel : ViewModelBase
- {
- public SettingsWindowViewModel()
- {
- LauncherVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
- var logger = Settings.logger;
- this.ValidationRule(
- viewModel => viewModel.MaxRam,
- value => { UInt32 result; bool resultb = UInt32.TryParse(value, out result); /*logger.Debug("Validator result: {0} {1}", value, resultb);*/ IsValid = resultb; return resultb; },
- "Not a number.");
- this.ValidationRule(
- viewModel => viewModel.MaxLog,
- value => { UInt32 result; bool resultb = UInt32.TryParse(value, out result); /*logger.Debug("Validator result: {0} {1}", value, resultb);*/ IsValid = resultb; return resultb; },
- "Not a number.");
-
- }
- private string launcherVersion;
- private string minecraftFolderPath = Settings.MinecraftForlderPath;
- private string javaPath = Settings.JavaPath;
- private string maxRam = Settings.MaxRam.ToString();
- private bool isValid;
- private LogEventLevel fileLogEventLevel = Settings.fileLogEventLevel;
- private LogEventLevel consoleLogEventLevel = Settings.consoleLogEventLevel;
- private string maxLog = Settings.MaxLog.ToString();
-
- private ObservableCollection<LogEventLevel> logEventLevels = new() {LogEventLevel.Debug, LogEventLevel.Information, LogEventLevel.Warning, LogEventLevel.Error };
- private ColorPickerControl ColorPicker = null;
- public bool UseCustomJava
- {
- get => Settings.useCustomJava;
- set
- {
- this.RaiseAndSetIfChanged(ref Settings.useCustomJava, value);
- }
- }
- public bool SetMaxRam
- {
- get => Settings.setMaxRam;
- set
- {
- this.RaiseAndSetIfChanged(ref Settings.setMaxRam, value);
- }
- }
- public bool SetMinecraftFolder
- {
- get => Settings.setPath;
- set
- {
- this.RaiseAndSetIfChanged(ref Settings.setPath, value);
- }
- }
- public bool CheckAssets
- {
- get => Settings.checkGameAssets;
- set
- {
- this.RaiseAndSetIfChanged(ref Settings.checkGameAssets, value);
- }
- }
- public string JavaPath
- {
- get => javaPath;
- set
- {
- this.RaiseAndSetIfChanged(ref javaPath, value);
- }
- }
- public string MaxRam
- {
- get => maxRam.ToString();
- set
- {
- this.RaiseAndSetIfChanged(ref maxRam, value);
- }
- }
- public bool IsValid
- {
- get => isValid;
- set => this.RaiseAndSetIfChanged(ref isValid, value);
- }
- public string MinecraftFolderPath
- {
- get => minecraftFolderPath;
- set
- {
- this.RaiseAndSetIfChanged(ref minecraftFolderPath, value);
- }
- }
- public string LauncherVersion
- {
- get => launcherVersion;
- set
- {
- this.RaiseAndSetIfChanged(ref launcherVersion, value);
- }
- }
- public bool GameLogToLauncher
- {
- get => Settings.gameLogToLauncher;
- set
- {
- this.RaiseAndSetIfChanged(ref Settings.gameLogToLauncher, value);
- }
- }
- public ObservableCollection<LogEventLevel> LogEventLevels
- {
- get => logEventLevels;
- set => this.RaiseAndSetIfChanged(ref logEventLevels, value);
- }
- public LogEventLevel FileLogEventLevel
- {
- get =>fileLogEventLevel;
- set => this.RaiseAndSetIfChanged(ref fileLogEventLevel, value);
- }
- public LogEventLevel ConsoleLogEventLevel
- {
- get => consoleLogEventLevel;
- set => this.RaiseAndSetIfChanged(ref consoleLogEventLevel, value);
- }
- public bool SetMaxLog
- {
- get => Settings.setMaxLog;
- set => this.RaiseAndSetIfChanged(ref Settings.setMaxLog, value);
- }
- public string MaxLog
- {
- get => maxLog;
- set => this.RaiseAndSetIfChanged(ref maxLog, value);
- }
- public void SaveSettings()
- {
- Settings.JavaPath = javaPath;
- Settings.MinecraftForlderPath = minecraftFolderPath;
- Settings.MaxRam = UInt32.Parse(maxRam);
- Settings.MaxLog = UInt32.Parse(maxLog);
- Settings.consoleLogEventLevel = consoleLogEventLevel;
- Settings.fileLogEventLevel = fileLogEventLevel;
- Settings.SaveSettings();
- }
- public void OpenMinecraftPathDialog(Window window)
- {
- Task.Run(() =>
- {
- OpenFolderDialog dialog = new OpenFolderDialog();
- var initPath = String.Empty;
- if (Settings.MinecraftForlderPath is not null)
- if (Settings.MinecraftForlderPath != String.Empty)
- initPath = Path.GetFullPath(Settings.MinecraftForlderPath);
- dialog.Directory = initPath;
- var result = dialog.ShowAsync(window).Result;
- if (result is null)
- return;
- if (result == String.Empty)
- return;
- MinecraftFolderPath = result;
- });
- }
- public void OpenJavaPathDialog(Window window)
- {
- Task.Run(() =>
- {
- OpenFolderDialog dialog = new OpenFolderDialog();
- var initPath = String.Empty;
- if (Settings.JavaPath is not null)
- if (Settings.JavaPath != String.Empty)
- initPath = Path.GetFullPath(Settings.JavaPath);
- dialog.Directory = initPath;
- var result = dialog.ShowAsync(window).Result;
- if (result is null)
- return;
- if (result == String.Empty)
- return;
- JavaPath = result;
- });
- }
- public void SetColor(Window window)
- {
- if (ColorPicker == null)
- ColorPicker = window.FindControl<ColorPickerControl>("ColorPicker");
- InterfaceColor = Color.FromRgb(ColorPicker.Color.R, ColorPicker.Color.G, ColorPicker.Color.B);
- MaterialOpacity = float.Parse(ColorPicker.Color.A.ToString())/byte.MaxValue;
- if (ColorPicker.Color.R >= 200 && ColorPicker.Color.G >= 200 && ColorPicker.Color.B >= 200 || MaterialOpacity <= 0.1)
- {
- Application.Current.Styles[0] = App.FluentLight;
- Application.Current.Styles[2] = App.FluentColorPickerThemeLight;
- Application.Current.Styles[1] = App.DataGridFluent;
- }
- else
- {
- Application.Current.Styles[0] = App.FluentDark;
- Application.Current.Styles[2] = App.FluentColorPickerThemeDark;
- Application.Current.Styles[1] = App.DataGridFluent;
- }
- ((ViewModelBase)((MainWindow) window.Owner).DataContext).RaisePropertyChanged(nameof(InterfaceColor));
- ((ViewModelBase)((MainWindow) window.Owner).DataContext).RaisePropertyChanged(nameof(MaterialOpacity));
- }
- }
- }
|