Bläddra i källkod

small viewmodels code cleaning

Veloe 2 år sedan
förälder
incheckning
e5d43ec41e

+ 4 - 9
VeloeMinecraftLauncher/ViewModels/ErrorWindowViewModel.cs

@@ -1,9 +1,4 @@
 using ReactiveUI;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace VeloeMinecraftLauncher.ViewModels
 {
@@ -20,14 +15,14 @@ namespace VeloeMinecraftLauncher.ViewModels
 
         public string ErrorTrace
         {
-            get { return errorTrace; }
-            set { this.RaiseAndSetIfChanged(ref errorTrace, value); }
+            get => errorTrace;
+            set => this.RaiseAndSetIfChanged(ref errorTrace, value);
         }
 
         public string ErrorMessage
         {
-            get { return errorMessage; }
-            set { this.RaiseAndSetIfChanged(ref errorMessage, value); }
+            get => errorMessage;
+            set => this.RaiseAndSetIfChanged(ref errorMessage, value);
         }
     }
 }

+ 32 - 87
VeloeMinecraftLauncher/ViewModels/MainWindowViewModel.cs

@@ -1,7 +1,6 @@
 using Avalonia.Controls.ApplicationLifetimes;
 using ReactiveUI;
 using System;
-using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Diagnostics;
 using System.IO;
@@ -9,20 +8,13 @@ using System.Text;
 using System.Text.Json;
 using System.Threading.Tasks;
 using VeloeMinecraftLauncher.Entity.LauncherProfiles;
-using VeloeMinecraftLauncher.Entity.VersionManifest;
 using VeloeMinecraftLauncher.MinecraftLauncher;
 using VeloeMinecraftLauncher.Views;
-using System;
-using System.Threading.Tasks;
-using System.Windows;
 using Microsoft.AspNetCore.SignalR.Client;
 using VeloeMinecraftLauncher.Entity.McStatus;
 using System.Timers;
-using System.ComponentModel;
 using System.Reflection;
 using Serilog;
-using Serilog.Events;
-using Serilog.Formatting;
 using Avalonia.Controls;
 using Avalonia.Threading;
 using System.Net;
@@ -96,8 +88,8 @@ namespace VeloeMinecraftLauncher.ViewModels
                 {
                   
                 logger.Debug("Connecting to WebSoket");
-            //conection to my servers 
-            connection = new HubConnectionBuilder()
+                //conection to my servers 
+                connection = new HubConnectionBuilder()
                     .WithUrl("https://monitor.veloe.link/hubs/data")
                     .WithAutomaticReconnect()
                     .Build();
@@ -134,8 +126,8 @@ namespace VeloeMinecraftLauncher.ViewModels
                     mcTfcTimer.Stop();
                     mcTfcTimer.Start();
 
-                //ConsoleText += message;
-            });
+                    //ConsoleText += message;
+                });
 
                 connection.On<string>("UpdateMcVanilla", (message) =>
                 {
@@ -144,8 +136,8 @@ namespace VeloeMinecraftLauncher.ViewModels
                     McVanillaPlayersBlock = $"{status.NumPlayers}/{status.MaxPlayers}";
                     mcTechTimer.Stop();
                     mcTechTimer.Start();
-                //ConsoleText += message;
-            });
+                    //ConsoleText += message;
+                });
 
                 connection.On<string>("UpdateMcTech", (message) =>
                 {
@@ -154,8 +146,8 @@ namespace VeloeMinecraftLauncher.ViewModels
                     McTechPlayersBlock = $"{status.NumPlayers}/{status.MaxPlayers}";
                     mcVanillaTimer.Stop();
                     mcVanillaTimer.Start();
-                //ConsoleText += message;
-            });
+                    //ConsoleText += message;
+                });
 
                 mcTfcTimer.Elapsed += OnTimedEventMcTfc;
                 mcTfcTimer.Start();
@@ -178,7 +170,7 @@ namespace VeloeMinecraftLauncher.ViewModels
                     OpenErrorWindow(ex);
                 }
             });
-            
+
         }
 
         System.Timers.Timer mcTfcTimer = new System.Timers.Timer(30000);
@@ -189,7 +181,7 @@ namespace VeloeMinecraftLauncher.ViewModels
         private HubConnection connection;
         private string downloadButton = "Download versions";
         private string startButton = "Start Minecraft";
-        private string username;
+        private string username = "";
         private StringBuilder consoleText = new StringBuilder();
         private int downloadedIndex;
         private string argumentsBox;
@@ -245,21 +237,15 @@ namespace VeloeMinecraftLauncher.ViewModels
             }
         }
         public string Greeting => "Welcome to Cringe Launcher!";
-        public string DownloadButton { 
-            get => downloadButton; 
-            set 
-            {
-               this.RaiseAndSetIfChanged(ref downloadButton, value);
-            } 
+        public string DownloadButton {
+            get => downloadButton;
+            set => this.RaiseAndSetIfChanged(ref downloadButton, value);
         }
 
         public string StartButton
         {
             get => startButton;
-            set
-            {
-                this.RaiseAndSetIfChanged(ref startButton, value);
-            }
+            set => this.RaiseAndSetIfChanged(ref startButton, value);
         }
 
         public string Username 
@@ -295,131 +281,87 @@ namespace VeloeMinecraftLauncher.ViewModels
         public string ArgumentsBox
         {
             get => argumentsBox;
-            set
-            {
-                this.RaiseAndSetIfChanged(ref argumentsBox, value);
-            }
+            set => this.RaiseAndSetIfChanged(ref argumentsBox, value);
         }
 
         public string SettingsButton
         {
             get => settingsButton;
-            set
-            {
-                this.RaiseAndSetIfChanged(ref settingsButton, value);
-            }
+            set => this.RaiseAndSetIfChanged(ref settingsButton, value);
         }
 
         public bool IsNoGameRunning
         {
             get => isNoGameRunning;
-            set
-            {
-                this.RaiseAndSetIfChanged(ref isNoGameRunning, value);
-            }
+            set => this.RaiseAndSetIfChanged(ref isNoGameRunning, value);
         }
 
         public bool IsUpdateAvailable
         {
             get => isUpdateAvailable;
-            set
-            {
-                this.RaiseAndSetIfChanged(ref isUpdateAvailable, value);
-            }
+            set => this.RaiseAndSetIfChanged(ref isUpdateAvailable, value);
         }
 
         public string McTfcBlock
         {
             get => mcTfcBlock;
-            set
-            {
-                this.RaiseAndSetIfChanged(ref mcTfcBlock, value);
-            }
+            set => this.RaiseAndSetIfChanged(ref mcTfcBlock, value);
         }
 
         public string McTechBlock
         {
             get => mcTechBlock;
-            set
-            {
-                this.RaiseAndSetIfChanged(ref mcTechBlock, value);
-            }
+            set => this.RaiseAndSetIfChanged(ref mcTechBlock, value);
         }
 
         public string McVanillaBlock
         {
             get => mcVanillaBlock;
-            set
-            {
-                this.RaiseAndSetIfChanged(ref mcVanillaBlock, value);
-            }
+            set => this.RaiseAndSetIfChanged(ref mcVanillaBlock, value);
         }
 
         public string McTfcPlayersBlock
         {
             get => mcTfcPlayersBlock;
-            set
-            {
-                this.RaiseAndSetIfChanged(ref mcTfcPlayersBlock, value);
-            }
+            set => this.RaiseAndSetIfChanged(ref mcTfcPlayersBlock, value);
         }
 
         public string McTechPlayersBlock
         {
             get => mcTechPlayersBlock;
-            set
-            {
-                this.RaiseAndSetIfChanged(ref mcTechPlayersBlock, value);
-            }
+            set => this.RaiseAndSetIfChanged(ref mcTechPlayersBlock, value);
         }
 
         public string McVanillaPlayersBlock
         {
             get => mcVanillaPlayersBlock;
-            set
-            {
-                this.RaiseAndSetIfChanged(ref mcVanillaPlayersBlock, value);
-            }
+            set => this.RaiseAndSetIfChanged(ref mcVanillaPlayersBlock, value);
         }
 
         public string McTfcTip
         {
             get => mcTfcTip;
-            set
-            {
-                this.RaiseAndSetIfChanged(ref mcTfcTip, value);
-            }
+            set => this.RaiseAndSetIfChanged(ref mcTfcTip, value);
         }
 
         public string McTechTip
         {
             get => mcTechTip;
-            set
-            {
-                this.RaiseAndSetIfChanged(ref mcTechTip, value);
-            }
+            set => this.RaiseAndSetIfChanged(ref mcTechTip, value);
         }
 
         public string McVanillaTip
         {
             get => mcVanillaTip;
-            set
-            {
-                this.RaiseAndSetIfChanged(ref mcVanillaTip, value);
-            }
+            set => this.RaiseAndSetIfChanged(ref mcVanillaTip, value);
         }
 
         public int ConsoleTextCaretIndex
         {
             get { return int.MaxValue; }
-            set
-            {
-                this.RaisePropertyChanged(nameof(ConsoleTextCaretIndex));
-            }
+            set => this.RaisePropertyChanged(nameof(ConsoleTextCaretIndex));
         }
 
-
-
         public void OnClickCommand()
         {
             var versionsDownloader = new VersionsDownloader 
@@ -444,7 +386,10 @@ namespace VeloeMinecraftLauncher.ViewModels
                 {
                     logger.Debug("Starting minecraft.");
                     if (DownloadedVerion is null)
+                    {
+                        IsNoGameRunning = true;
                         return;
+                    }
 
 
                     int version = 0;
@@ -764,7 +709,7 @@ namespace VeloeMinecraftLauncher.ViewModels
                 OpenErrorWindow(new FileNotFoundException($"File {updater.StartInfo.FileName} not found!"));
         }
 
-            private void UpdateUpdater()
+        private void UpdateUpdater()
         {
             try
             {

+ 12 - 42
VeloeMinecraftLauncher/ViewModels/SettingsWindowViewModel.cs

@@ -8,9 +8,6 @@ using Avalonia.Controls;
 using System.Threading.Tasks;
 using System.Collections.ObjectModel;
 using Serilog.Events;
-using Avalonia.Media;
-using Avalonia;
-using VeloeMinecraftLauncher.Views;
 
 namespace VeloeMinecraftLauncher.ViewModels
 {
@@ -45,58 +42,40 @@ namespace VeloeMinecraftLauncher.ViewModels
         
         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 UseCustomJava
+        {
+            get => Settings.useCustomJava;
+            set => this.RaiseAndSetIfChanged(ref Settings.useCustomJava, value);
         }
 
         public bool SetMaxRam
         {
             get => Settings.setMaxRam;
-            set
-            {
-                this.RaiseAndSetIfChanged(ref Settings.setMaxRam, value);
-            }
+            set => this.RaiseAndSetIfChanged(ref Settings.setMaxRam, value);
         }
 
         public bool SetMinecraftFolder
         {
             get => Settings.setPath;
-            set
-            {
-                this.RaiseAndSetIfChanged(ref Settings.setPath, value);
-            }
+            set => this.RaiseAndSetIfChanged(ref Settings.setPath, value);
         }
 
         public bool CheckAssets
         {
             get => Settings.checkGameAssets;
-            set
-            {
-                this.RaiseAndSetIfChanged(ref Settings.checkGameAssets, value);
-            }
+            set => this.RaiseAndSetIfChanged(ref Settings.checkGameAssets, value);
         }
 
         public string JavaPath
         {
             get => javaPath;
-            set
-            {
-                this.RaiseAndSetIfChanged(ref javaPath, value);
-            }
+            set => this.RaiseAndSetIfChanged(ref javaPath, value);
         }
 
         public string MaxRam
         {
             get => maxRam.ToString();
-            set
-            {
-                this.RaiseAndSetIfChanged(ref maxRam, value);              
-            }
+            set => this.RaiseAndSetIfChanged(ref maxRam, value);
         }
 
         public bool IsValid
@@ -108,28 +87,19 @@ namespace VeloeMinecraftLauncher.ViewModels
         public string MinecraftFolderPath
         {
             get => minecraftFolderPath;
-            set
-            {
-                this.RaiseAndSetIfChanged(ref minecraftFolderPath, value);
-            }
+            set => this.RaiseAndSetIfChanged(ref minecraftFolderPath, value);
         }
 
         public string LauncherVersion
         {
             get => launcherVersion;
-            set
-            {
-                this.RaiseAndSetIfChanged(ref launcherVersion, value);
-            }
+            set => this.RaiseAndSetIfChanged(ref launcherVersion, value);
         }
 
         public bool GameLogToLauncher
         {
             get => Settings.gameLogToLauncher;
-            set
-            {
-                this.RaiseAndSetIfChanged(ref Settings.gameLogToLauncher, value);
-            }
+            set => this.RaiseAndSetIfChanged(ref Settings.gameLogToLauncher, value);
         }
 
         public ObservableCollection<LogEventLevel> LogEventLevels

+ 29 - 48
VeloeMinecraftLauncher/ViewModels/VersionsDownloaderViewModel.cs

@@ -2,16 +2,10 @@
 using Avalonia.Threading;
 using ReactiveUI;
 using System;
-using System.Collections.Generic;
 using System.Collections.ObjectModel;
-using System.IO;
-using System.IO.Compression;
-using System.Linq;
 using System.Net;
 using System.Net.Http;
-using System.Text;
 using System.Threading.Tasks;
-using VeloeMinecraftLauncher.Entity.Assets;
 using VeloeMinecraftLauncher.Entity.VersionManifest;
 using VeloeMinecraftLauncher.MinecraftLauncher;
 using VeloeMinecraftLauncher.Views;
@@ -170,23 +164,19 @@ namespace VeloeMinecraftLauncher.ViewModels
 
         public ObservableCollection<Entity.VersionManifest.Version>FilteredVersions
         {
-            get => filteredVersions; set
-            {
-                this.RaiseAndSetIfChanged(ref filteredVersions, value);
-            }
+            get => filteredVersions; 
+            set => this.RaiseAndSetIfChanged(ref filteredVersions, value);
         }
 
         public string StartButton
         {
-            get => startButton; set
-            {
-                this.RaiseAndSetIfChanged(ref startButton, value);
-            }
+            get => startButton; 
+            set => this.RaiseAndSetIfChanged(ref startButton, value);
         }
 
         public bool ShowOld
         {
-            get { return showOld; }
+            get => showOld;
             set { 
                 this.RaiseAndSetIfChanged(ref showOld, value);
                 updateList();
@@ -195,7 +185,7 @@ namespace VeloeMinecraftLauncher.ViewModels
 
         public bool ShowSnaps
         {
-            get { return showSnaps; }
+            get => showSnaps;
             set { 
                 this.RaiseAndSetIfChanged(ref showSnaps, value);
                 updateList();
@@ -204,37 +194,33 @@ namespace VeloeMinecraftLauncher.ViewModels
 
         public int Progress
         {
-            get { return progress; }
-            set
-            {
-                this.RaiseAndSetIfChanged(ref progress, value);
-            }
+            get => progress;
+            set => this.RaiseAndSetIfChanged(ref progress, value);
         }
 
         public string DownloadingFileName
         {
-            get { return downloadingFileName; }
-            set
-            {
-                this.RaiseAndSetIfChanged(ref downloadingFileName, value);
-            }
+            get => downloadingFileName;
+            set => this.RaiseAndSetIfChanged(ref downloadingFileName, value);
         }
 
         public bool InstallForge
         {
-            get { return installForge; }
-            set {
+            get => installForge;
+            set
+            {
                 this.RaiseAndSetIfChanged(ref installForge, value);
-                
+
                 if (InstallFabric)
                     InstallFabric = false;
-                }
+            }
         }
 
         public bool InstallFabric
         {
-            get { return installFabric; }
-            set { 
+            get => installFabric;
+            set
+            {
                 this.RaiseAndSetIfChanged(ref installFabric, value);
                 if (InstallForge)
                     InstallForge = false;
@@ -243,10 +229,8 @@ namespace VeloeMinecraftLauncher.ViewModels
 
         public bool InstallOptifine
         {
-            get { return installOptifine; }
-            set { 
-                this.RaiseAndSetIfChanged(ref installOptifine, value);
-            }
+            get => installOptifine;
+            set => this.RaiseAndSetIfChanged(ref installOptifine, value);
         }
 
         public bool InstallForgeOptifine
@@ -262,38 +246,38 @@ namespace VeloeMinecraftLauncher.ViewModels
 
         public bool InstallForgeVisible
         {
-            get { return installForgeVisible; }
+            get => installForgeVisible;
             set => this.RaiseAndSetIfChanged(ref installForgeVisible, value);
         }
 
         public bool InstallFabricVisible
         {
-            get { return installFabricVisible; }
+            get => installFabricVisible;
             set => this.RaiseAndSetIfChanged(ref installFabricVisible, value);
         }
 
         public bool InstallOptifineVisible
         {
-            get { return installOptifineVisible; }
+            get => installOptifineVisible;
             set => this.RaiseAndSetIfChanged(ref installOptifineVisible, value);
         }
 
         public bool InstallForgeOptifineVisible
         {
-            get { return installForgeOptifineVisible; }
+            get => installForgeOptifineVisible;
             set => this.RaiseAndSetIfChanged(ref installForgeOptifineVisible, value);
         }
 
         public bool DownloadJava
         {
-            get { return downloadJava;  }
-            set { this.RaiseAndSetIfChanged(ref downloadJava, value); }
+            get => downloadJava;
+            set => this.RaiseAndSetIfChanged(ref downloadJava, value);
         }
 
         public bool IsControlsEnabled
         {
-            get { return isControlsEnabled; }
-            set { this.RaiseAndSetIfChanged(ref isControlsEnabled, value); }
+            get => isControlsEnabled;
+            set => this.RaiseAndSetIfChanged(ref isControlsEnabled, value);
         }
 
         public async Task OnStartBunttonClick()
@@ -381,12 +365,9 @@ namespace VeloeMinecraftLauncher.ViewModels
                     {
                         DataContext = ErrorMessageViewModel
                     };
-                    //var versionsDownloaderTask =
-                    ErrorMessage.ShowDialog(desktop.MainWindow);
-                    //versionsDownloaderTask.Wait();              
+                    ErrorMessage.ShowDialog(desktop.MainWindow);            
                 }
             }
         }
-
     }
 }