123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- 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;
- 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 };
- 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;
- 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(() =>
- {
- OpenFileDialog dialog = new OpenFileDialog();
- var initPath = String.Empty;
- if (Settings.javaPath is not null)
- if (Settings.javaPath != String.Empty)
- initPath = Path.GetFullPath(Settings.javaPath);
- dialog.AllowMultiple = false;
- dialog.Directory = initPath;
- var result = dialog.ShowAsync(window).Result;
- if (result is null)
- return;
- if (result[0] == String.Empty)
- return;
- JavaPath = result[0];
- });
- }
- }
|