Browse Source

code cleaning, fix old versions start

Veloe 2 years ago
parent
commit
31edfbdac9

+ 137 - 125
VeloeMinecraftLauncher/MinecraftLauncher/Downloader.cs

@@ -42,9 +42,9 @@ internal static class Downloader
             if (DownloadJava)
             {
                 Settings.logger.Debug("Getting required Java version.");
-                if (versionJson.JavaVersion.MajorVersion != null)
+                string javaUrl = "";
+                if (versionJson.JavaVersion is not null && versionJson.JavaVersion.MajorVersion != null)
                 {
-                    string javaUrl = "";
                     switch (versionJson.JavaVersion.MajorVersion)
                     {
                         case 8:
@@ -78,26 +78,40 @@ internal static class Downloader
                                 javaUrl = "https://files.veloe.link/launcher/java/18/linux64/java.zip";
 
                             break;
-                    }
-                    if (javaUrl != "")
-                    {
-                        Settings.logger.Debug("Downloading Java");
-                        DownloadingFileName("java.zip");
-                        webClient.DownloadFileAsync(new System.Uri(javaUrl), Settings.MinecraftForlderPath + "java.zip");
-                        waitWhileBisy(ref webClient);
+                    }                   
+                }
 
-                        Settings.logger.Debug("Unpacking Java");
-                        DownloadingFileName("Unpacking java.zip");
-                        ZipFile.ExtractToDirectory($"{Settings.MinecraftForlderPath}java.zip", Settings.MinecraftForlderPath, true);
-                        File.Delete($"{Settings.MinecraftForlderPath}java.zip");
-                    }
-                    else
-                        Settings.logger.Debug("Required Java version don't found in json file."); //log that java was not downloaded;
+                if (versionJson.Assets == "legacy")
+                {
+                    if (Environment.Is64BitOperatingSystem && OperatingSystem.IsWindows())
+                        javaUrl = "https://files.veloe.link/launcher/java/8/windows64/java.zip";
+                    if (!Environment.Is64BitOperatingSystem && OperatingSystem.IsWindows())
+                        javaUrl = "https://files.veloe.link/launcher/java/8/windows32/java.zip";
+
+                    if (Environment.Is64BitOperatingSystem && OperatingSystem.IsLinux())
+                        javaUrl = "https://files.veloe.link/launcher/java/8/linux64/java.zip";
+                    if (!Environment.Is64BitOperatingSystem && OperatingSystem.IsLinux())
+                        javaUrl = "https://files.veloe.link/launcher/java/8/linux32/java.zip";
+                }
+
+                if (javaUrl != "")
+                {
+                    Settings.logger.Debug("Downloading Java");
+                    DownloadingFileName("java.zip");
+                    webClient.DownloadFileAsync(new System.Uri(javaUrl), Settings.minecraftForlderPath + "java.zip");
+                    waitWhileBisy(ref webClient);
+
+                    Settings.logger.Debug("Unpacking Java");
+                    DownloadingFileName("Unpacking java.zip");
+                    ZipFile.ExtractToDirectory($"{Settings.minecraftForlderPath}java.zip", Settings.minecraftForlderPath, true);
+                    File.Delete($"{Settings.minecraftForlderPath}java.zip");
                 }
+                else
+                    Settings.logger.Debug("Required Java version don't found in json file."); //log that java was not downloaded;
             }
 
             //download json
-            var path = Settings.MinecraftForlderPath + "/versions/" + versionJson.Id;
+            var path = Settings.minecraftForlderPath + "/versions/" + versionJson.Id;
             if (!Directory.Exists(path))
             {
                 Settings.logger.Debug("Creating path: {0}", path);
@@ -141,64 +155,52 @@ internal static class Downloader
             Settings.logger.Debug("Downloading libraries.");
             foreach (var library in versionJson.Libraries)
             {
-                var libPath = Settings.MinecraftForlderPath + "libraries/";
-                string[] libPathSplit = new[] { "" };
+                var libPath = Settings.minecraftForlderPath + "libraries/";
                 string libUrl = "";
                 string sha1 = String.Empty;
                 // getting path and url if universal lib
                 if (library.Natives is null)
                 {
-                    libPath = Settings.MinecraftForlderPath + "libraries/";
-                    libPathSplit = library.Downloads.Artifact.Path.Split('/');
+                    libPath = Settings.minecraftForlderPath + "libraries/" + library.Downloads.Artifact.Path;
                     libUrl = library.Downloads.Artifact.Url;
                     sha1 = library.Downloads.Artifact.Sha1;
-                    for (int i = 0; i < libPathSplit.Length - 1; i++)
-                    {
-                        libPath += libPathSplit[i] + "/";
-                    }
-
                 }
                 else
                 {   // getting path if native
-                    libPath = Settings.MinecraftForlderPath + "libraries/";
-                    libPathSplit = new[] { "" };
+                    libPath = Settings.minecraftForlderPath + "libraries/";
                     libUrl = "";
-
-                    if (OperatingSystem.IsWindows() && library.Natives.Windows is not null)
+                    if (library.Downloads.Classifiers is not null)
                     {
-                        if (library.Downloads.Classifiers.NativesWindows is not null)
-                        {
-                            libPathSplit = library.Downloads.Classifiers.NativesWindows.Path.Split('/');
-                            libUrl = library.Downloads.Classifiers.NativesWindows.Url;
-                            sha1 = library.Downloads.Classifiers.NativesWindows.Sha1;
-                        }
-                        else
+                        if (OperatingSystem.IsWindows() && library.Natives.Windows is not null)
                         {
-                            if (Environment.Is64BitOperatingSystem)
+                            if (library.Downloads.Classifiers.NativesWindows is not null)
                             {
-                                libPathSplit = library.Downloads.Classifiers.NativesWindows64.Path.Split('/');
-                                libUrl = library.Downloads.Classifiers.NativesWindows64.Url;
-                                sha1 = library.Downloads.Classifiers.NativesWindows64.Sha1;
+                                libPath += library.Downloads.Classifiers.NativesWindows.Path;
+                                libUrl = library.Downloads.Classifiers.NativesWindows.Url;
+                                sha1 = library.Downloads.Classifiers.NativesWindows.Sha1;
                             }
                             else
                             {
-                                libPathSplit = library.Downloads.Classifiers.NativesWindows32.Path.Split('/');
-                                libUrl = library.Downloads.Classifiers.NativesWindows32.Url;
-                                sha1 = library.Downloads.Classifiers.NativesWindows32.Sha1;
+                                if (Environment.Is64BitOperatingSystem && library.Downloads.Classifiers.NativesWindows64 is not null)
+                                {
+                                    libPath += library.Downloads.Classifiers.NativesWindows64.Path;
+                                    libUrl = library.Downloads.Classifiers.NativesWindows64.Url;
+                                    sha1 = library.Downloads.Classifiers.NativesWindows64.Sha1;
+                                }
+                                else if (library.Downloads.Classifiers.NativesWindows32 is not null)
+                                {
+                                    libPath += library.Downloads.Classifiers.NativesWindows32.Path;
+                                    libUrl = library.Downloads.Classifiers.NativesWindows32.Url;
+                                    sha1 = library.Downloads.Classifiers.NativesWindows32.Sha1;
+                                }
                             }
                         }
-                    }
-                    if (OperatingSystem.IsLinux() && library.Natives.Linux is not null)
-                    {
-                        libPathSplit = library.Downloads.Classifiers.NativesLinux.Path.Split('/');
-                        libUrl = library.Downloads.Classifiers.NativesLinux.Url;
-                        sha1 = library.Downloads.Classifiers.NativesLinux.Url;
-                    }
-
-
-                    for (int i = 0; i < libPathSplit.Length - 1; i++)
-                    {
-                        libPath += libPathSplit[i] + "/";
+                        if (OperatingSystem.IsLinux() && library.Natives.Linux is not null && library.Downloads.Classifiers.NativesLinux is not null)
+                        {
+                            libPath += library.Downloads.Classifiers.NativesLinux.Path;
+                            libUrl = library.Downloads.Classifiers.NativesLinux.Url;
+                            sha1 = library.Downloads.Classifiers.NativesLinux.Url;
+                        }
                     }
                 }
 
@@ -206,21 +208,24 @@ internal static class Downloader
                 if (libUrl == String.Empty)
                     continue;
 
+                var libName = Path.GetFileName(libPath);
+                var libDir = Path.GetDirectoryName(libPath);
+
                 //checking rules
                 if (library.Rules == null)
-                {
-                    if (!Directory.Exists(libPath))
+                {                 
+                    if (!Directory.Exists(libDir))
                     {
                         Settings.logger.Debug("Creating path: {0}", path);
-                        Directory.CreateDirectory(libPath);
+                        Directory.CreateDirectory(libDir);
                     }
 
                     chksum = String.Empty;
 
-                    if (File.Exists(libPath + "/" + libPathSplit.Last()))
+                    if (File.Exists(libPath))
                     {
-                        DownloadingFileName($"Checking hash: {libPathSplit.Last()}");
-                        FileStream fop = File.OpenRead(libPath + "/" + libPathSplit.Last());
+                        DownloadingFileName($"Checking hash: {libName}");
+                        FileStream fop = File.OpenRead(libPath);
                         byte[] hash = System.Security.Cryptography.SHA1.Create().ComputeHash(fop);
                         chksum = BitConverter.ToString(hash).Replace("-", String.Empty).ToLower();
 
@@ -230,9 +235,9 @@ internal static class Downloader
 
                     if (chksum != sha1)
                     {
-                        Settings.logger.Debug("Downloading: {0}", libPathSplit.Last());
-                        DownloadingFileName(libPathSplit.Last());
-                        webClient.DownloadFileAsync(new System.Uri(libUrl), libPath + "/" + libPathSplit.Last());
+                        Settings.logger.Debug("Downloading: {0}", libName);
+                        DownloadingFileName(libName);
+                        webClient.DownloadFileAsync(new System.Uri(libUrl), libDir + "/" + libName);
                         waitWhileBisy(ref webClient);
                     }
                 }
@@ -242,18 +247,18 @@ internal static class Downloader
                     {
                         if (rule.Action == "allow") // && rule.os is null
                         {
-                            if (!Directory.Exists(libPath))
+                            if (!Directory.Exists(libDir))
                             {
                                 Settings.logger.Debug("Creating path: {0}", path);
-                                Directory.CreateDirectory(libPath);
+                                Directory.CreateDirectory(libDir);
                             }
 
                             chksum = String.Empty;
 
-                            if (File.Exists(libPath + "/" + libPathSplit.Last()) && sha1 != String.Empty)
+                            if (File.Exists(libDir + "/" + libName) && sha1 != String.Empty)
                             {
-                                DownloadingFileName($"Checking hash: {libPathSplit.Last()}");
-                                FileStream fop = File.OpenRead(libPath + "/" + libPathSplit.Last());
+                                DownloadingFileName($"Checking hash: {libName}");
+                                FileStream fop = File.OpenRead(libDir + "/" + libName);
                                 byte[] hash = System.Security.Cryptography.SHA1.Create().ComputeHash(fop);
                                 chksum = BitConverter.ToString(hash).Replace("-", String.Empty).ToLower();
 
@@ -263,9 +268,9 @@ internal static class Downloader
 
                             if (chksum != sha1)
                             {
-                                Settings.logger.Debug("Downloading: {0}", libPathSplit.Last());
-                                DownloadingFileName(libPathSplit.Last());
-                                webClient.DownloadFileAsync(new System.Uri(libUrl), libPath + "/" + libPathSplit.Last());
+                                Settings.logger.Debug("Downloading: {0}", libName);
+                                DownloadingFileName(libName);
+                                webClient.DownloadFileAsync(new System.Uri(libUrl), libDir + "/" + libName);
                                 waitWhileBisy(ref webClient);
                             }
                             continue;
@@ -279,33 +284,33 @@ internal static class Downloader
                                 Settings.logger.Debug("Creating path: {0}", path);
                                 Directory.CreateDirectory(libPath);
                             }
-                            Settings.logger.Debug("Downloading: {0}", libPathSplit.Last());
-                            DownloadingFileName = libPathSplit.Last();
-                            webClient.DownloadFileAsync(new System.Uri(libUrl), libPath + "/" + libPathSplit.Last());
+                            Settings.logger.Debug("Downloading: {0}", libName);
+                            DownloadingFileName = libName;
+                            webClient.DownloadFileAsync(new System.Uri(libUrl), libPath + "/" + libName);
                             waitWhileBisy(ref webClient);
                         }
                         */
                     }
                 }
                 //unpacking native libs
-                if (((library.Natives is not null || library.Downloads.Classifiers is not null) && File.Exists(libPath + "/" + libPathSplit.Last())) /*&& chksum != sha1*/)
+                if ((library.Natives is not null || library.Downloads.Classifiers is not null) && File.Exists(libPath)/*&& chksum != sha1*/)
                 {
                     try
                     {
-                        if (!((
+                        if (!(library.Downloads.Classifiers is not null && (
                             library.Downloads.Classifiers.NativesWindows is not null ||
                             library.Downloads.Classifiers.NativesWindows64 is not null ||
-                            library.Downloads.Classifiers.NativesWindows32 is not null) && OperatingSystem.IsWindows() ||
-                            library.Downloads.Classifiers.NativesLinux is not null && OperatingSystem.IsLinux()))
+                            (library.Downloads.Classifiers.NativesWindows32 is not null && OperatingSystem.IsWindows()) ||
+                            (library.Downloads.Classifiers.NativesLinux is not null && OperatingSystem.IsLinux()))))
                             continue;
 
-                        if (!Directory.Exists(Settings.MinecraftForlderPath + "versions/" + versionJson.Id + "/natives/"))
+                        if (!Directory.Exists(Settings.minecraftForlderPath + "versions/" + versionJson.Id + "/natives/"))
                         {
-                            Settings.logger.Debug("Creating path: {0}", Settings.MinecraftForlderPath + "versions/" + versionJson.Id + "/natives/");
-                            Directory.CreateDirectory(Settings.MinecraftForlderPath + "versions/" + versionJson.Id + "/natives/");
+                            Settings.logger.Debug("Creating path: {0}", Settings.minecraftForlderPath + "versions/" + versionJson.Id + "/natives/");
+                            Directory.CreateDirectory(Settings.minecraftForlderPath + "versions/" + versionJson.Id + "/natives/");
                         }
-                        Settings.logger.Debug("Extracting {0} to {1}", libPathSplit.Last(), Settings.MinecraftForlderPath + "versions/" + versionJson.Id + "/natives/");
-                        ZipFile.ExtractToDirectory(libPath + "/" + libPathSplit.Last(), Settings.MinecraftForlderPath + "versions/" + versionJson.Id + "/natives/", true);
+                        Settings.logger.Debug("Extracting {0} to {1}", libName, Settings.minecraftForlderPath + "versions/" + versionJson.Id + "/natives/");
+                        ZipFile.ExtractToDirectory(libDir + "/" + libName, Settings.minecraftForlderPath + "versions/" + versionJson.Id + "/natives/", true);
                     }
                     catch (IOException ex)
                     {
@@ -316,15 +321,15 @@ internal static class Downloader
             }
 
             var assetsJson = Downloader.DownloadAndDeserializeJsonData<AssetsManifest>(versionJson.AssetIndex.Url);
-            var assetsPath = Settings.MinecraftForlderPath + "assets/" + versionJson.Assets + "/objects";
+            var assetsPath = Settings.minecraftForlderPath + "assets/" + versionJson.Assets + "/objects";
             var assetsUrl = "https://resources.download.minecraft.net/";
 
             //download assets json
             Settings.logger.Debug("Downloading: {0}", versionJson.Assets + ".json");
 
-            if (!Directory.Exists(Settings.MinecraftForlderPath + "/assets/" + versionJson.Assets + "/indexes/"))
-                Directory.CreateDirectory(Settings.MinecraftForlderPath + "/assets/" + versionJson.Assets + "/indexes/");
-            webClient.DownloadFileAsync(new System.Uri(versionJson.AssetIndex.Url), Settings.MinecraftForlderPath + "/assets/" + versionJson.Assets + "/indexes/" + versionJson.Assets + ".json");
+            if (!Directory.Exists(Settings.minecraftForlderPath + "/assets/" + versionJson.Assets + "/indexes/"))
+                Directory.CreateDirectory(Settings.minecraftForlderPath + "/assets/" + versionJson.Assets + "/indexes/");
+            webClient.DownloadFileAsync(new System.Uri(versionJson.AssetIndex.Url), Settings.minecraftForlderPath + "/assets/" + versionJson.Assets + "/indexes/" + versionJson.Assets + ".json");
             waitWhileBisy(ref webClient);
 
             //download assets
@@ -361,27 +366,27 @@ internal static class Downloader
                 var forgePath = $"Forge{versionJson.Id}";
                 var forgeUrl = $"https://files.veloe.link/launcher/forge/Forge{versionJson.Id}/";
 
-                if (!Directory.Exists($"{Settings.MinecraftForlderPath}versions/Forge{versionJson.Id}"))
+                if (!Directory.Exists($"{Settings.minecraftForlderPath}versions/Forge{versionJson.Id}"))
                 {
-                    Settings.logger.Debug("Creating path: {0}", $"{Settings.MinecraftForlderPath}versions/" + forgePath);
-                    Directory.CreateDirectory($"{Settings.MinecraftForlderPath}versions/" + forgePath);
+                    Settings.logger.Debug("Creating path: {0}", $"{Settings.minecraftForlderPath}versions/" + forgePath);
+                    Directory.CreateDirectory($"{Settings.minecraftForlderPath}versions/" + forgePath);
                 }
                 waitWhileBisy(ref webClient);
 
                 Settings.logger.Debug("Downloading: {0}", $"Forge{versionJson.Id}.json");
                 DownloadingFileName($"Forge{versionJson.Id}.json");
-                webClient.DownloadFileAsync(new System.Uri($"{forgeUrl}Forge{versionJson.Id}.json"), Settings.MinecraftForlderPath + "versions/" + forgePath + "/" + forgePath + ".json");
+                webClient.DownloadFileAsync(new System.Uri($"{forgeUrl}Forge{versionJson.Id}.json"), Settings.minecraftForlderPath + "versions/" + forgePath + "/" + forgePath + ".json");
                 waitWhileBisy(ref webClient);
 
                 Settings.logger.Debug("Downloading: {0}", "libraries.zip");
                 DownloadingFileName("libraries.zip");
-                webClient.DownloadFileAsync(new System.Uri(forgeUrl + "libraries.zip"), Settings.MinecraftForlderPath + "versions/" + forgePath + "/libraries.zip");
+                webClient.DownloadFileAsync(new System.Uri(forgeUrl + "libraries.zip"), Settings.minecraftForlderPath + "versions/" + forgePath + "/libraries.zip");
                 waitWhileBisy(ref webClient);
 
                 Settings.logger.Debug("Extracting: {0}", "libraries.zip");
                 DownloadingFileName("Unpacking libraries.zip");
-                ZipFile.ExtractToDirectory($"{Settings.MinecraftForlderPath}versions/Forge{versionJson.Id}/libraries.zip", Settings.MinecraftForlderPath, true);
-                File.Delete($"{Settings.MinecraftForlderPath}versions/Forge{versionJson.Id}/libraries.zip");
+                ZipFile.ExtractToDirectory($"{Settings.minecraftForlderPath}versions/Forge{versionJson.Id}/libraries.zip", Settings.minecraftForlderPath, true);
+                File.Delete($"{Settings.minecraftForlderPath}versions/Forge{versionJson.Id}/libraries.zip");
             }
 
             if (InstallOptifine)
@@ -389,45 +394,45 @@ internal static class Downloader
                 var optifinePath = $"Optifine{versionJson.Id}";
                 var optifineUrl = $"https://files.veloe.link/launcher/optifine/Optifine{versionJson.Id}/";
 
-                if (!Directory.Exists($"{Settings.MinecraftForlderPath}versions/Optifine{versionJson.Id}"))
+                if (!Directory.Exists($"{Settings.minecraftForlderPath}versions/Optifine{versionJson.Id}"))
                 {
-                    Settings.logger.Debug("Creating path: {0}", $"{Settings.MinecraftForlderPath}Optifine/" + optifinePath);
-                    Directory.CreateDirectory($"{Settings.MinecraftForlderPath}Optifine/" + optifinePath);
+                    Settings.logger.Debug("Creating path: {0}", $"{Settings.minecraftForlderPath}Optifine/" + optifinePath);
+                    Directory.CreateDirectory($"{Settings.minecraftForlderPath}Optifine/" + optifinePath);
                 }
 
                 Settings.logger.Debug("Downloading: {0}", $"Optifine{versionJson.Id}.json");
                 DownloadingFileName($"Optifine{versionJson.Id}.json");
-                webClient.DownloadFileAsync(new System.Uri($"{optifineUrl}Optifine{versionJson.Id}.json"), Settings.MinecraftForlderPath + "versions/" + optifinePath + "/" + optifinePath + ".json");
+                webClient.DownloadFileAsync(new System.Uri($"{optifineUrl}Optifine{versionJson.Id}.json"), Settings.minecraftForlderPath + "versions/" + optifinePath + "/" + optifinePath + ".json");
                 waitWhileBisy(ref webClient);
 
                 Settings.logger.Debug("Downloading: {0}", $"Optifine{versionJson.Id}.jar");
                 DownloadingFileName($"Optifine{versionJson.Id}.json");
-                webClient.DownloadFileAsync(new System.Uri($"{optifineUrl}Optifine{versionJson.Id}.jar"), Settings.MinecraftForlderPath + "versions/" + optifinePath + "/" + optifinePath + ".jar");
+                webClient.DownloadFileAsync(new System.Uri($"{optifineUrl}Optifine{versionJson.Id}.jar"), Settings.minecraftForlderPath + "versions/" + optifinePath + "/" + optifinePath + ".jar");
                 waitWhileBisy(ref webClient);
 
                 Settings.logger.Debug("Downloading: {0}", "libraries.zip");
                 DownloadingFileName("libraries.zip");
-                webClient.DownloadFileAsync(new System.Uri(optifineUrl + "libraries.zip"), Settings.MinecraftForlderPath + "versions/" + optifinePath + "/libraries.zip");
+                webClient.DownloadFileAsync(new System.Uri(optifineUrl + "libraries.zip"), Settings.minecraftForlderPath + "versions/" + optifinePath + "/libraries.zip");
                 waitWhileBisy(ref webClient);
 
                 Settings.logger.Debug("Extracting: {0}", "libraries.zip");
                 DownloadingFileName("Unpacking libraries.zip");
-                ZipFile.ExtractToDirectory($"{Settings.MinecraftForlderPath}versions/Optifine{versionJson.Id}/libraries.zip", Settings.MinecraftForlderPath, true);
-                File.Delete($"{Settings.MinecraftForlderPath}versions/Optifine{versionJson.Id}/libraries.zip");
+                ZipFile.ExtractToDirectory($"{Settings.minecraftForlderPath}versions/Optifine{versionJson.Id}/libraries.zip", Settings.minecraftForlderPath, true);
+                File.Delete($"{Settings.minecraftForlderPath}versions/Optifine{versionJson.Id}/libraries.zip");
             }
 
             if (InstallForgeOptifine)
             {
-                if (!Directory.Exists($"{Settings.MinecraftForlderPath}versions/Forge{versionJson.Id}/mods"))
+                if (!Directory.Exists($"{Settings.minecraftForlderPath}versions/Forge{versionJson.Id}/mods"))
                 {
-                    Settings.logger.Debug("Creating path: {0}", $"{Settings.MinecraftForlderPath}versions/Forge" + versionJson.Id + "/mods");
-                    Directory.CreateDirectory($"{Settings.MinecraftForlderPath}versions/Forge" + versionJson.Id + "/mods");
+                    Settings.logger.Debug("Creating path: {0}", $"{Settings.minecraftForlderPath}versions/Forge" + versionJson.Id + "/mods");
+                    Directory.CreateDirectory($"{Settings.minecraftForlderPath}versions/Forge" + versionJson.Id + "/mods");
                 }
 
                 Settings.logger.Debug("Downloading: {0}", $"Optifine{versionJson.Id}.jar");
                 DownloadingFileName($"Optifine{versionJson.Id}.jar");
                 webClient.DownloadFileAsync(new System.Uri(@$"https://files.veloe.link/launcher/forge/Forge{versionJson.Id}/Optifine{versionJson.Id}.jar"),
-                Settings.MinecraftForlderPath + "versions/Forge" + versionJson.Id + "/mods/" + "Optifine" + versionJson.Id + ".jar");
+                Settings.minecraftForlderPath + "versions/Forge" + versionJson.Id + "/mods/" + "Optifine" + versionJson.Id + ".jar");
                 waitWhileBisy(ref webClient);
             }
 
@@ -444,7 +449,8 @@ internal static class Downloader
             IsControlsEnabled(true);
             DownloadingFileName($"Error occured while downloading {versionJson.Id}.");
             Settings.logger.Error(ex.Message);
-            Settings.logger.Error(ex.StackTrace);
+            if (ex.StackTrace is not null)
+                Settings.logger.Error(ex.StackTrace);
             return TaskStatus.Faulted;
         }
         return TaskStatus.RanToCompletion;
@@ -478,7 +484,7 @@ internal static class Downloader
 
             Settings.logger.Debug("Downloading {0}.json", FilteredVersion.Id);
             DownloadingFileName($"{FilteredVersion.Id}.json");
-            var versionJson = Downloader.DownloadAndDeserializeJsonData<Entity.Version.Version>(FilteredVersion.Url, Settings.MinecraftForlderPath + "versions/" + FilteredVersion.Id + "/", FilteredVersion.Id + ".json");
+            var versionJson = Downloader.DownloadAndDeserializeJsonData<Entity.Version.Version>(FilteredVersion.Url, Settings.minecraftForlderPath + "versions/" + FilteredVersion.Id + "/", FilteredVersion.Id + ".json");
 
             await Downloader.StartDownload(
                 DownloadingFileName,
@@ -494,17 +500,17 @@ internal static class Downloader
 
             IsControlsEnabled(false);
 
-            string modpackUrl = null;
+            string modpackUrl = string.Empty;
 
             if (SelectedModpack.Url is not null)
                 modpackUrl = SelectedModpack.Url;
             else
                 modpackUrl = $"https://files.veloe.link/launcher/modpacks/{SelectedModpack.Name}.zip";
 
-            if (!Directory.Exists($"{Settings.MinecraftForlderPath}versions/{SelectedModpack.Name}"))
+            if (!Directory.Exists($"{Settings.minecraftForlderPath}versions/{SelectedModpack.Name}"))
             {
-                Settings.logger.Debug("Creating path: {0}", $"{Settings.MinecraftForlderPath}versions/{SelectedModpack.Name}");
-                Directory.CreateDirectory($"{Settings.MinecraftForlderPath}versions/{SelectedModpack.Name}");
+                Settings.logger.Debug("Creating path: {0}", $"{Settings.minecraftForlderPath}versions/{SelectedModpack.Name}");
+                Directory.CreateDirectory($"{Settings.minecraftForlderPath}versions/{SelectedModpack.Name}");
             }
 
             WebClient webClient = new WebClient();
@@ -513,13 +519,13 @@ internal static class Downloader
 
             Settings.logger.Debug("Downloading: {0}", $"{SelectedModpack.Name}.zip");
             DownloadingFileName($"{SelectedModpack.Name}.zip");
-            webClient.DownloadFileAsync(new System.Uri(modpackUrl), Settings.MinecraftForlderPath + $"versions/{SelectedModpack.Name}.zip");
+            webClient.DownloadFileAsync(new System.Uri(modpackUrl), Settings.minecraftForlderPath + $"versions/{SelectedModpack.Name}.zip");
             waitWhileBisy(ref webClient);
 
             Settings.logger.Debug("Extracting: {0}", $"{SelectedModpack.Name}.zip");
             DownloadingFileName($"Unpacking {SelectedModpack.Name}.zip");
-            ZipFile.ExtractToDirectory($"{Settings.MinecraftForlderPath}versions/{SelectedModpack.Name}.zip", Settings.MinecraftForlderPath + $"versions/{SelectedModpack.Name}", true);
-            File.Delete($"{Settings.MinecraftForlderPath}versions/{SelectedModpack.Name}.zip");
+            ZipFile.ExtractToDirectory($"{Settings.minecraftForlderPath}versions/{SelectedModpack.Name}.zip", Settings.minecraftForlderPath + $"versions/{SelectedModpack.Name}", true);
+            File.Delete($"{Settings.minecraftForlderPath}versions/{SelectedModpack.Name}.zip");
 
             RemoveProgressBar(webClient);
 
@@ -537,20 +543,23 @@ internal static class Downloader
             var message = ex.Message;
             var stackTrace = ex.StackTrace;
             Settings.logger.Error(ex.Message);
-            Settings.logger.Error(ex.StackTrace);
-            Exception innerException = ex.InnerException;
+            if (ex.StackTrace is not null)
+                Settings.logger.Error(ex.StackTrace);
+            Exception? innerException = ex.InnerException;
             while (innerException is not null)
             {
                 message += "\n" + innerException.Message;
                 stackTrace += "\n" + innerException.StackTrace;
                 Settings.logger.Error(innerException.Message);
-                Settings.logger.Error(innerException.StackTrace);
+                if (innerException.StackTrace is not null)
+                    Settings.logger.Error(innerException.StackTrace);
                 innerException = innerException.InnerException;
             }
 
+#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
             Dispatcher.UIThread.InvokeAsync(() =>
             {
-                if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
+            if (Avalonia.Application.Current is not null && Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
                 {
                     Dispatcher.UIThread.InvokeAsync(() =>
                     {
@@ -563,6 +572,7 @@ internal static class Downloader
                     });
                 }
             });
+#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
             return TaskStatus.Faulted;
         }
         return TaskStatus.RanToCompletion;
@@ -608,20 +618,22 @@ internal static class Downloader
                 var message = ex.Message;
                 var stackTrace = ex.StackTrace;
                 Settings.logger.Error(ex.Message);
-                Settings.logger.Error(ex.StackTrace);
-                Exception innerException = ex.InnerException;
+                if (ex.StackTrace is not null)
+                    Settings.logger.Error(ex.StackTrace);
+                Exception? innerException = ex.InnerException;
                 while (innerException is not null)
                 {
                     message += "\n" + innerException.Message;
                     stackTrace += "\n" + innerException.StackTrace;
                     Settings.logger.Error(innerException.Message);
-                    Settings.logger.Error(innerException.StackTrace);
+                    if (innerException.StackTrace is not null)
+                        Settings.logger.Error(innerException.StackTrace);
                     innerException = innerException.InnerException;
                 }
 
                 Dispatcher.UIThread.InvokeAsync(() =>
                 {
-                    if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
+                    if (Avalonia.Application.Current is not null && Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
                     {
                         Dispatcher.UIThread.InvokeAsync(() =>
                         {

+ 3 - 3
VeloeMinecraftLauncher/MinecraftLauncher/EventSink.cs

@@ -5,10 +5,10 @@ namespace VeloeMinecraftLauncher.MinecraftLauncher;
 
 public class EventSink : Serilog.Core.ILogEventSink
 {
-    private readonly IFormatProvider _formatProvider = null;
-    public event EventHandler DataReceived;
+    private readonly IFormatProvider? _formatProvider = null;
+    public event EventHandler? DataReceived;
 
-    public EventSink(IFormatProvider formatProvider)
+    public EventSink(IFormatProvider? formatProvider)
     {
         _formatProvider = formatProvider;
     }

+ 48 - 48
VeloeMinecraftLauncher/MinecraftLauncher/Settings.cs

@@ -9,20 +9,20 @@ namespace VeloeMinecraftLauncher.MinecraftLauncher;
 internal static class Settings
 {
     //public static readonly string JavaPath = "C:\\Program Files\\Microsoft\\jdk-11.0.12.7-hotspot\\bin\\java.exe";
-    public static string JavaPath = "";
-    public static string MinecraftForlderPath = Directory.GetCurrentDirectory() + '/';
-    public static UInt32 MaxRam = 2048;
+    public static string javaPath = "";
+    public static string minecraftForlderPath = Directory.GetCurrentDirectory() + '/';
+    public static UInt32 maxRam = 2048;
     public static bool useCustomJava = false;
     public static bool setMaxRam = false;
     public static bool setPath = true;
     public static bool checkGameAssets = false;
     public static bool gameLogToLauncher = false;
-    public static string Username;
+    public static string username;
     public static string lastChosenVersion;
     public static Serilog.ILogger logger;
     public static Serilog.ILogger avaloniaLogger;
     public static bool setMaxLog = false;
-    public static UInt32 MaxLog = 1024;
+    public static UInt32 maxLog = 1024;
     public static LogEventLevel consoleLogEventLevel = LogEventLevel.Debug;
     public static LogEventLevel fileLogEventLevel = LogEventLevel.Debug;
 
@@ -30,20 +30,20 @@ internal static class Settings
     {
         if (settings is null)
             return;
-        JavaPath = settings.JavaPath;
-        MinecraftForlderPath = settings.MinecraftForlderPath;
-        MaxRam = settings.MaxRam;
-        useCustomJava = settings.useCustomJava;
-        setMaxRam = settings.setMaxRam;
-        setPath = settings.setPath;
-        checkGameAssets = settings.checkGameAssets;
-        gameLogToLauncher = settings.gameLogToLauncher;
-        lastChosenVersion = settings.lastChosenVersion;
-        Username = settings.Username;
-        setMaxLog = settings.setMaxLog;
-        MaxLog = settings.MaxLog;
-        consoleLogEventLevel = settings.consoleLogEventLevel;
-        fileLogEventLevel = settings.fileLogEventLevel;
+        javaPath = settings.JavaPath;
+        minecraftForlderPath = settings.MinecraftForlderPath;
+        maxRam = settings.MaxRam;
+        useCustomJava = settings.UseCustomJava;
+        setMaxRam = settings.SetMaxRam;
+        setPath = settings.SetPath;
+        checkGameAssets = settings.CheckGameAssets;
+        gameLogToLauncher = settings.GameLogToLauncher;
+        lastChosenVersion = settings.LastChosenVersion;
+        username = settings.Username;
+        setMaxLog = settings.SetMaxLog;
+        maxLog = settings.MaxLog;
+        consoleLogEventLevel = settings.ConsoleLogEventLevel;
+        fileLogEventLevel = settings.FileLogEventLevel;
 
     }
 
@@ -75,14 +75,14 @@ internal static class Settings
 
     public static void SaveSettings()
     {
-        if(MinecraftForlderPath == string.Empty)
-            MinecraftForlderPath = Directory.GetCurrentDirectory();
+        if(minecraftForlderPath == string.Empty)
+            minecraftForlderPath = Directory.GetCurrentDirectory();
 
-        if(MinecraftForlderPath.Last() is not ('/' or '\\'))
-            MinecraftForlderPath = MinecraftForlderPath + "/";
+        if(minecraftForlderPath.Last() is not ('/' or '\\'))
+            minecraftForlderPath = minecraftForlderPath + "/";
 
-        if (!Directory.Exists(MinecraftForlderPath))
-            Directory.CreateDirectory(MinecraftForlderPath);
+        if (!Directory.Exists(minecraftForlderPath))
+            Directory.CreateDirectory(minecraftForlderPath);
 
         var settings = JsonSerializer.Serialize(new SettingsSerializable());
 
@@ -95,37 +95,37 @@ public class SettingsSerializable
     public string JavaPath {get; set;}
     public string MinecraftForlderPath { get; set;}
     public UInt32 MaxRam { get; set; }
-    public bool useCustomJava { get; set; }
-    public bool setMaxRam { get; set; }
-    public bool setPath { get; set; }
-    public bool checkGameAssets { get; set; }
+    public bool UseCustomJava { get; set; }
+    public bool SetMaxRam { get; set; }
+    public bool SetPath { get; set; }
+    public bool CheckGameAssets { get; set; }
 
-    public bool gameLogToLauncher { get; set; }
+    public bool GameLogToLauncher { get; set; }
 
     public string Username { get; set; }
 
-    public string lastChosenVersion { get; set; }
+    public string LastChosenVersion { get; set; }
 
-    public bool setMaxLog { get; set; }
+    public bool SetMaxLog { get; set; }
     public UInt32 MaxLog { get; set; }
-    public LogEventLevel consoleLogEventLevel { get; set; }
-    public LogEventLevel fileLogEventLevel { get; set; }
+    public LogEventLevel ConsoleLogEventLevel { get; set; }
+    public LogEventLevel FileLogEventLevel { get; set; }
 
     public SettingsSerializable()
     {
-        JavaPath = Settings.JavaPath;
-        MinecraftForlderPath= Settings.MinecraftForlderPath;
-        MaxRam= Settings.MaxRam;
-        useCustomJava= Settings.useCustomJava;
-        setMaxRam= Settings.setMaxRam;
-        setPath = Settings.setPath;
-        checkGameAssets= Settings.checkGameAssets;
-        gameLogToLauncher= Settings.gameLogToLauncher;
-        Username = Settings.Username;
-        lastChosenVersion= Settings.lastChosenVersion;
-        setMaxLog= Settings.setMaxLog;
-        MaxLog = Settings.MaxLog;
-        consoleLogEventLevel= Settings.consoleLogEventLevel;
-        fileLogEventLevel= Settings.fileLogEventLevel;
+        JavaPath = Settings.javaPath;
+        MinecraftForlderPath= Settings.minecraftForlderPath;
+        MaxRam= Settings.maxRam;
+        UseCustomJava= Settings.useCustomJava;
+        SetMaxRam= Settings.setMaxRam;
+        SetPath = Settings.setPath;
+        CheckGameAssets= Settings.checkGameAssets;
+        GameLogToLauncher= Settings.gameLogToLauncher;
+        Username = Settings.username;
+        LastChosenVersion= Settings.lastChosenVersion;
+        SetMaxLog= Settings.setMaxLog;
+        MaxLog = Settings.maxLog;
+        ConsoleLogEventLevel= Settings.consoleLogEventLevel;
+        FileLogEventLevel= Settings.fileLogEventLevel;
     }
 }

+ 22 - 18
VeloeMinecraftLauncher/MinecraftLauncher/StartCommandBuilder.cs

@@ -24,9 +24,9 @@ internal static class StartCommandBuilder
 
         // setting natives folder
         if (version.InheritsFrom is null)
-            returnString.Append($"-Djava.library.path={Settings.MinecraftForlderPath + "versions/" + version.Id + "/natives/"}");
+            returnString.Append($"-Djava.library.path={Settings.minecraftForlderPath + "versions/" + version.Id + "/natives/"}");
         else
-            returnString.Append($"-Djava.library.path={Settings.MinecraftForlderPath + "versions/" + version.InheritsFrom + "/natives/"}"); //for forge, vanilla optifine, fabric
+            returnString.Append($"-Djava.library.path={Settings.minecraftForlderPath + "versions/" + version.InheritsFrom + "/natives/"}"); //for forge, vanilla optifine, fabric
 
         returnString.Append(" -cp ");
 
@@ -78,24 +78,24 @@ internal static class StartCommandBuilder
                     libPath += dir+"/";
                 }
                 if (rulesVaild)
-                    returnString.Append(Settings.MinecraftForlderPath + "libraries/" + libPath + dirs[dirs.Length-2]+"-"+dirs[dirs.Length-1]+".jar;");
+                    returnString.Append(Settings.minecraftForlderPath + "libraries/" + libPath + dirs[dirs.Length-2]+"-"+dirs[dirs.Length-1]+".jar;");
 
                 continue;
             }
 
             if (rulesVaild)
-                returnString.Append(Settings.MinecraftForlderPath + "libraries/" + library.Downloads.Artifact.Path + separator);
+                returnString.Append(Settings.minecraftForlderPath + "libraries/" + library.Downloads.Artifact.Path + separator);
 
         }
         
         Entity.Version.Version inheritsFrom = new();
         if (version.InheritsFrom is null)
-            returnString.Append(Settings.MinecraftForlderPath + "versions/" + version.Id + "/" + version.Id + ".jar"); //main jar file
+            returnString.Append(Settings.minecraftForlderPath + "versions/" + version.Id + "/" + version.Id + ".jar"); //main jar file
         else
         {
             //for forge, vanilla optifine, fabric
             //add libraries from inherited version
-            var inheritsJsonString = File.ReadAllText(Settings.MinecraftForlderPath + "versions/" + version.InheritsFrom + "/" + version.InheritsFrom + ".json");
+            var inheritsJsonString = File.ReadAllText(Settings.minecraftForlderPath + "versions/" + version.InheritsFrom + "/" + version.InheritsFrom + ".json");
             
             inheritsFrom = JsonSerializer.Deserialize<Entity.Version.Version>(inheritsJsonString, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
 
@@ -132,18 +132,18 @@ internal static class StartCommandBuilder
                 }
 
                 if(rulesVaild)
-                    returnString.Append(Settings.MinecraftForlderPath + "libraries/" + library.Downloads.Artifact.Path + separator);
+                    returnString.Append(Settings.minecraftForlderPath + "libraries/" + library.Downloads.Artifact.Path + separator);
 
             }
             //main jar file
             //check here if there is jar file not inherited
             //check if it is not 0kb size (fabric)
-            var fileInfo = new FileInfo($"{Settings.MinecraftForlderPath}versions/{version.Id}/{version.Id}.jar");
+            var fileInfo = new FileInfo($"{Settings.minecraftForlderPath}versions/{version.Id}/{version.Id}.jar");
 
             if (fileInfo.Exists && fileInfo.Length > 0)
-                returnString.Append(Settings.MinecraftForlderPath + "versions/" + version.Id + "/" + version.Id + ".jar");//for optifine
+                returnString.Append(Settings.minecraftForlderPath + "versions/" + version.Id + "/" + version.Id + ".jar");//for optifine
             else
-                returnString.Append(Settings.MinecraftForlderPath + "versions/" + version.InheritsFrom + "/" + version.InheritsFrom + ".jar");//for forge
+                returnString.Append(Settings.minecraftForlderPath + "versions/" + version.InheritsFrom + "/" + version.InheritsFrom + ".jar");//for forge
         }
 
        //check for jvm fabric options
@@ -173,7 +173,7 @@ internal static class StartCommandBuilder
                     }
                     if (value.Contains("${library_directory}"))
                     {
-                        value = value.Replace("${library_directory}", Settings.MinecraftForlderPath + "libraries/");
+                        value = value.Replace("${library_directory}", Settings.minecraftForlderPath + "libraries/");
                     }
                     if (value.Contains("${classpath_separator}"))
                     {
@@ -187,7 +187,7 @@ internal static class StartCommandBuilder
 
         //max ram
         if (Settings.setMaxRam)
-            returnString.Append($" -Xmx{Settings.MaxRam}M ");
+            returnString.Append($" -Xmx{Settings.maxRam}M ");
 
 
         returnString.Append(" " + version.MainClass);
@@ -230,9 +230,13 @@ internal static class StartCommandBuilder
             for (int i = 0; i < minecraftArguments.Count(); i++)
             {
                 if (minecraftArguments[i].Contains("--"))
+                {
                     args.Add(minecraftArguments[i]);
-                else
-                    argsValues.Add(minecraftArguments[i]);
+                    if (minecraftArguments[i+1] is not null)
+                        argsValues.Add(minecraftArguments[i+1]);
+                }
+                //else
+                //    argsValues.Add(minecraftArguments[i]);
             }
         }
 
@@ -319,16 +323,16 @@ internal static class StartCommandBuilder
                 case "--gameDir":
                     //for forge
                     if (!(argsValues.Where(x => x.Contains("forge")).Count() > 0 || version.Id.ToLower().Contains("fabric")))
-                        returnString.Append(" --gameDir " + Settings.MinecraftForlderPath);
+                        returnString.Append(" --gameDir " + Settings.minecraftForlderPath);
                     else
-                        returnString.Append(" --gameDir " + Settings.MinecraftForlderPath + "versions/" + version.Id);
+                        returnString.Append(" --gameDir " + Settings.minecraftForlderPath + "versions/" + version.Id);
                     break;
                 case "--assetsDir":
                     //for forge
                     if (version.InheritsFrom is null)
-                        returnString.Append(" --assetsDir " + Settings.MinecraftForlderPath + "assets/" + version.Assets + "/");
+                        returnString.Append(" --assetsDir " + Settings.minecraftForlderPath + "assets/" + version.Assets + "/");
                     else
-                        returnString.Append(" --assetsDir " + Settings.MinecraftForlderPath + "assets/" + inheritsFrom.Assets + "/");
+                        returnString.Append(" --assetsDir " + Settings.minecraftForlderPath + "assets/" + inheritsFrom.Assets + "/");
                     break;
                 case "--assetIndex":
                     //for forge

+ 1 - 1
VeloeMinecraftLauncher/Program.cs

@@ -23,7 +23,7 @@ namespace VeloeMinecraftLauncher
             Settings.LoadSettings();
             var logger = new Serilog.LoggerConfiguration()
                .MinimumLevel.Debug()
-               .WriteTo.File("avalonia.log", Settings.fileLogEventLevel, fileSizeLimitBytes: Settings.MaxLog * 1024, rollOnFileSizeLimit: true)// restricted... is Optional
+               .WriteTo.File("avalonia.log", Settings.fileLogEventLevel, fileSizeLimitBytes: Settings.maxLog * 1024, rollOnFileSizeLimit: true)// restricted... is Optional
                .CreateLogger();
             
             Settings.avaloniaLogger = logger;

+ 32 - 27
VeloeMinecraftLauncher/ViewModels/MainWindowViewModel.cs

@@ -43,14 +43,14 @@ public class MainWindowViewModel : ViewModelBase
                 _logger = new LoggerConfiguration()
                     .MinimumLevel.Debug()
                     .WriteTo.Sink(eventSink , Settings.consoleLogEventLevel)
-                    .WriteTo.File("launcher.log", Settings.fileLogEventLevel, fileSizeLimitBytes: Settings.MaxLog * 1024, rollOnFileSizeLimit: true)// restricted... is Optional
+                    .WriteTo.File("launcher.log", Settings.fileLogEventLevel, fileSizeLimitBytes: Settings.maxLog * 1024, rollOnFileSizeLimit: true)// restricted... is Optional
                     .CreateLogger();
                 Settings.logger = _logger;
 
                 //loading settings
                 _logger.Debug("Loading settings.");
                 Settings.LoadSettings();
-                _username = Settings.Username;
+                _username = Settings.username;
 
                 //loading local verions
                 _logger.Debug("Loading local versions.");
@@ -214,7 +214,7 @@ public class MainWindowViewModel : ViewModelBase
         }
     }
 
-    public DownloadedVersion DownloadedVerion
+    public DownloadedVersion DownloadedVersion
     {
         get => _downloadedVersion;
         set
@@ -233,7 +233,7 @@ public class MainWindowViewModel : ViewModelBase
         {
             this.RaiseAndSetIfChanged(ref _downloadedIndex, value);
             if (value >= 0 && value < DownloadedVersions.Count)
-                DownloadedVerion = DownloadedVersions[value];
+                DownloadedVersion = DownloadedVersions[value];
         }
     }
     public string Greeting => "Welcome to Cringe Launcher!";
@@ -337,12 +337,13 @@ public class MainWindowViewModel : ViewModelBase
 
     public async void StartMinecraft()
     {
+#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
         Task.Run(async() =>
         {
             try
             {
                 _logger.Debug("Starting minecraft.");
-                if (DownloadedVerion is null)
+                if (DownloadedVersion is null)
                 {
                     IsNoGameRunning = true;
                     return;
@@ -351,7 +352,7 @@ public class MainWindowViewModel : ViewModelBase
 
                 int version = 0;
 
-                using (StreamReader reader = new StreamReader(DownloadedVerion.path))
+                using (StreamReader reader = new StreamReader(DownloadedVersion.path))
                 {
                     string json = reader.ReadToEnd();
 
@@ -365,7 +366,7 @@ public class MainWindowViewModel : ViewModelBase
                             result = Downloader.StartDownload(value => StartButtonOutput = value, value => IsNoGameRunning = value, value => { }, value => { }, versionJson).Result;
                         else
                         {
-                            using (StreamReader inheritsFromReader = new StreamReader(Settings.MinecraftForlderPath + "versions/" + versionJson.InheritsFrom + "/" + versionJson.InheritsFrom + ".json"))
+                            using (StreamReader inheritsFromReader = new StreamReader(Settings.minecraftForlderPath + "versions/" + versionJson.InheritsFrom + "/" + versionJson.InheritsFrom + ".json"))
                             {
                                 string jsonInheritsFrom = inheritsFromReader.ReadToEnd();
                                 var inheritsFromJson = JsonSerializer.Deserialize<Entity.Version.Version>(jsonInheritsFrom, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
@@ -385,16 +386,16 @@ public class MainWindowViewModel : ViewModelBase
 
                     if (!Settings.useCustomJava)
                     {
-                        if (versionJson.JavaVersion != null)
+                        if (versionJson.JavaVersion is not null)
                         {
                             _logger.Debug("Java version required: {0}", versionJson.JavaVersion.MajorVersion);
                             version = versionJson.JavaVersion.MajorVersion;
                         }
                         else
                         {
-                            if (versionJson.InheritsFrom != null)
+                            if (versionJson.InheritsFrom is not null)
                             {
-                                using (StreamReader inheritsFromReader = new StreamReader(Settings.MinecraftForlderPath + "versions/" + versionJson.InheritsFrom + "/" + versionJson.InheritsFrom + ".json"))
+                                using (StreamReader inheritsFromReader = new StreamReader(Settings.minecraftForlderPath + "versions/" + versionJson.InheritsFrom + "/" + versionJson.InheritsFrom + ".json"))
                                 {
                                     string jsonInheritsFrom = inheritsFromReader.ReadToEnd();
                                     var inheritsFromJson = JsonSerializer.Deserialize<Entity.Version.Version>(jsonInheritsFrom, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
@@ -405,6 +406,10 @@ public class MainWindowViewModel : ViewModelBase
                                     }
                                 }
                             }
+                            else
+                            {
+                                version = 7;
+                            }
                         }
                     }
 
@@ -412,14 +417,14 @@ public class MainWindowViewModel : ViewModelBase
                     ArgumentsBox = arguments;
                 }
 
-                if (DownloadedVerion is null)
+                if (DownloadedVersion is null)
                     return;
 
-                string javaPath = Settings.JavaPath;
+                string javaPath = Settings.javaPath;
 
                 if (!Settings.useCustomJava)
                 {
-                    javaPath = Settings.MinecraftForlderPath + "javaruntime/" + version + "/bin/java";
+                    javaPath = Settings.minecraftForlderPath + "javaruntime/" + version + "/bin/java";
                     if (OperatingSystem.IsWindows())
                         javaPath += ".exe";
                 }
@@ -435,9 +440,9 @@ public class MainWindowViewModel : ViewModelBase
                     RedirectStandardError = true,
                     WindowStyle = ProcessWindowStyle.Hidden,
                     CreateNoWindow = true,
-                    FileName = System.IO.Path.Combine(Settings.MinecraftForlderPath, javaPath),
+                    FileName = System.IO.Path.Combine(Settings.minecraftForlderPath, javaPath),
                     StandardErrorEncoding = Encoding.UTF8,
-                    WorkingDirectory = Settings.MinecraftForlderPath,
+                    WorkingDirectory = Settings.minecraftForlderPath,
                     Arguments = ArgumentsBox
                 };
 
@@ -483,8 +488,8 @@ public class MainWindowViewModel : ViewModelBase
                     }
                 });
                 _logger.Debug("Updating Settings");
-                Settings.Username = _username;
-                Settings.lastChosenVersion = DownloadedVerion.version;
+                Settings.username = _username;
+                Settings.lastChosenVersion = DownloadedVersion.version;
                 Settings.SaveSettings();
 
             }
@@ -493,7 +498,7 @@ public class MainWindowViewModel : ViewModelBase
                 OpenErrorWindow(ex);
             }
         });
-        
+#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
     }
 
     void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
@@ -507,7 +512,7 @@ public class MainWindowViewModel : ViewModelBase
         _consoleText.Append(outLine.Data + "\n");          
     }
 
-    void LogHandler(object sendingProcess, EventArgs args)
+    void LogHandler(object? sendingProcess, EventArgs args)
     {
         if (!_consoleOutputTimer.Enabled)
         {
@@ -526,7 +531,7 @@ public class MainWindowViewModel : ViewModelBase
 
     void ScrollToEnd(string ScrollName)
     {
-        if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
+        if (Avalonia.Application.Current is not null && Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
         {
             Dispatcher.UIThread.InvokeAsync(() =>
             {
@@ -537,7 +542,7 @@ public class MainWindowViewModel : ViewModelBase
         }
     }
 
-    void ProcessExited(object sendingProcess, EventArgs e)
+    void ProcessExited(object? sendingProcess, EventArgs e)
     {
         ((Process)sendingProcess).Exited -= ProcessExited;
 
@@ -559,7 +564,7 @@ public class MainWindowViewModel : ViewModelBase
             DownloadedVersions = new();
 
         DownloadedVersions.Clear();
-        DirectoryInfo versions = new( Settings.MinecraftForlderPath + "versions");
+        DirectoryInfo versions = new( Settings.minecraftForlderPath + "versions");
         try
         {
             var dirs = versions.GetDirectories("*", SearchOption.TopDirectoryOnly);
@@ -592,18 +597,18 @@ public class MainWindowViewModel : ViewModelBase
                 }
                 
             }
-            if (!File.Exists(Settings.MinecraftForlderPath + "launcher_profiles.json"))
+            if (!File.Exists(Settings.minecraftForlderPath + "launcher_profiles.json"))
             {
-                var file = File.Create(Settings.MinecraftForlderPath + "launcher_profiles.json");
+                var file = File.Create(Settings.minecraftForlderPath + "launcher_profiles.json");
                 file.Close();
                 file.Dispose();
             }
             var lpString = JsonSerializer.Serialize(profiles, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
-            File.WriteAllText(Settings.MinecraftForlderPath + "launcher_profiles.json", lpString);
+            File.WriteAllText(Settings.minecraftForlderPath + "launcher_profiles.json", lpString);
         }
         catch (DirectoryNotFoundException ex)
         {
-            Directory.CreateDirectory(Settings.MinecraftForlderPath + "versions");
+            Directory.CreateDirectory(Settings.minecraftForlderPath + "versions");
             return;
         }
         
@@ -686,7 +691,7 @@ public class MainWindowViewModel : ViewModelBase
                     return;
                 }
 
-                if (latestLauncherVersion != null)
+                if (latestLauncherVersion is not null)
                 {
                     _logger.Information("Latest updater version on server: {0}", latestLauncherVersion.Updater);
                     _logger.Information("Updater version: {0}", fileVersionInfo.FileVersion);

+ 14 - 14
VeloeMinecraftLauncher/ViewModels/SettingsWindowViewModel.cs

@@ -32,13 +32,13 @@ public class SettingsWindowViewModel : ViewModelBase
 }
 
     private string _launcherVersion;
-    private string _minecraftFolderPath = Settings.MinecraftForlderPath;
-    private string _javaPath = Settings.JavaPath;
-    private string _maxRam = Settings.MaxRam.ToString();
+    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 string _maxLog = Settings.maxLog.ToString();
     
     private ObservableCollection<LogEventLevel> _logEventLevels = new() {LogEventLevel.Debug, LogEventLevel.Information, LogEventLevel.Warning, LogEventLevel.Error };
 
@@ -134,10 +134,10 @@ public class SettingsWindowViewModel : ViewModelBase
 
     public void SaveSettings()
     {
-        Settings.JavaPath = _javaPath;
-        Settings.MinecraftForlderPath = _minecraftFolderPath;
-        Settings.MaxRam = UInt32.Parse(_maxRam);
-        Settings.MaxLog = UInt32.Parse(_maxLog);
+        Settings.javaPath = _javaPath;
+        Settings.minecraftForlderPath = _minecraftFolderPath;
+        Settings.maxRam = UInt32.Parse(_maxRam);
+        Settings.maxLog = UInt32.Parse(_maxLog);
         Settings.consoleLogEventLevel = _consoleLogEventLevel;
         Settings.fileLogEventLevel = _fileLogEventLevel;
         Settings.SaveSettings();
@@ -151,9 +151,9 @@ public class SettingsWindowViewModel : ViewModelBase
 
             var initPath = String.Empty;
 
-            if (Settings.MinecraftForlderPath is not null)
-                if (Settings.MinecraftForlderPath != String.Empty)
-                    initPath = Path.GetFullPath(Settings.MinecraftForlderPath);
+            if (Settings.minecraftForlderPath is not null)
+                if (Settings.minecraftForlderPath != String.Empty)
+                    initPath = Path.GetFullPath(Settings.minecraftForlderPath);
 
             dialog.Directory = initPath;
 
@@ -176,9 +176,9 @@ public class SettingsWindowViewModel : ViewModelBase
 
             var initPath = String.Empty;
 
-            if (Settings.JavaPath is not null)
-                if (Settings.JavaPath != String.Empty)
-                    initPath = Path.GetFullPath(Settings.JavaPath);
+            if (Settings.javaPath is not null)
+                if (Settings.javaPath != String.Empty)
+                    initPath = Path.GetFullPath(Settings.javaPath);
 
             dialog.AllowMultiple = false;
             dialog.Directory = initPath;

+ 2 - 2
VeloeMinecraftLauncher/ViewModels/VersionsDownloaderViewModel.cs

@@ -159,7 +159,7 @@ public class VersionsDownloaderViewModel : ViewModelBase
                 }
 
                 Dispatcher.UIThread.InvokeAsync(async () => { 
-                if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
+                if (Avalonia.Application.Current is not null && Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
                 {
                     var ErrorMessageViewModel = new ErrorWindowViewModel(message, stackTrace);
                     var ErrorMessage = new ErrorWindow()
@@ -312,7 +312,7 @@ public class VersionsDownloaderViewModel : ViewModelBase
 
             _logger.Debug("Downloading {0}.json", FilteredVersion.Id);
             DownloadingFileName = $"{FilteredVersion.Id}.json";
-            var versionJson = Downloader.DownloadAndDeserializeJsonData<Entity.Version.Version>(FilteredVersion.Url, Settings.MinecraftForlderPath + "versions/" + FilteredVersion.Id + "/", FilteredVersion.Id + ".json");
+            var versionJson = Downloader.DownloadAndDeserializeJsonData<Entity.Version.Version>(FilteredVersion.Url, Settings.minecraftForlderPath + "versions/" + FilteredVersion.Id + "/", FilteredVersion.Id + ".json");
 
             if (versionJson is not null)
                 Downloader.StartDownload(