示例#1
0
        /// <summary>Creates all the NullSafe Values for Settings.ini</summary>
        public static void NullSafeSettings()
        {
            /* Pervent Removal of Login Info Before Main Screen (Temporary Boolean) */
            FileAccountSave.SaveLoginInformation = true;

            /* Migrate old Key Entries */
            if (settingFile.KeyExists("Server"))
            {
                FileAccountSave.ChoosenGameServer = settingFile.Read("Server");
                settingFile.DeleteKey("Server");
                FileAccountSave.SaveAccount();
            }

            if (settingFile.KeyExists("AccountEmail"))
            {
                FileAccountSave.UserRawEmail = settingFile.Read("AccountEmail");
                settingFile.DeleteKey("AccountEmail");
                FileAccountSave.SaveAccount();
            }

            if (settingFile.KeyExists("Password"))
            {
                FileAccountSave.UserHashedPassword = settingFile.Read("Password");
                settingFile.DeleteKey("Password");
                FileAccountSave.SaveAccount();
            }

            /* Reset This Value as its now Safe to Do So */
            FileAccountSave.SaveLoginInformation = false;

            if (settingFile.KeyExists("Firewall"))
            {
                FirewallLauncherStatus = settingFile.Read("Firewall");
                FirewallGameStatus     = FirewallLauncherStatus;
                settingFile.DeleteKey("Firewall");
            }

            if (settingFile.KeyExists("WindowsDefender"))
            {
                DefenderLauncherStatus = settingFile.Read("WindowsDefender");
                DefenderGameStatus     = DefenderLauncherStatus;
                settingFile.DeleteKey("WindowsDefender");
            }

            /* Check if any Entries are missing */

            if (UnixOS.Detected() && !settingFile.KeyExists("InstallationDirectory"))
            {
                settingFile.Write("InstallationDirectory", "GameFiles");
            }
            else if (!settingFile.KeyExists("InstallationDirectory"))
            {
                settingFile.Write("InstallationDirectory", GameInstallation);
            }

            if (UnixOS.Detected() && settingFile.KeyExists("OldInstallationDirectory"))
            {
                settingFile.DeleteKey("OldInstallationDirectory");
            }
            else if (!UnixOS.Detected() && !settingFile.KeyExists("OldInstallationDirectory"))
            {
                settingFile.Write("OldInstallationDirectory", GameInstallationOld);
            }

            if (!settingFile.KeyExists("CDN"))
            {
                settingFile.Write("CDN", CDN);
            }
            else if (settingFile.KeyExists("CDN"))
            {
                if (CDN.EndsWith("/"))
                {
                    char[] charsToTrim = { '/' };
                    string FinalCDNURL = CDN.TrimEnd(charsToTrim);

                    settingFile.Write("CDN", FinalCDNURL);
                }
            }

            if (!settingFile.KeyExists("Language"))
            {
                settingFile.Write("Language", Lang);
            }

            if (!settingFile.KeyExists("DisableProxy"))
            {
                settingFile.Write("DisableProxy", Proxy);
            }

            if (!settingFile.KeyExists("DisableRPC"))
            {
                settingFile.Write("DisableRPC", RPC);
            }

            if (!settingFile.KeyExists("IgnoreUpdateVersion"))
            {
                settingFile.Write("IgnoreUpdateVersion", IgnoreVersion);
            }

            if (!settingFile.KeyExists("FilePermission") && !UnixOS.Detected())
            {
                settingFile.Write("FilePermission", FilePermissionStatus);
            }
            else if (settingFile.KeyExists("FilePermission") && UnixOS.Detected())
            {
                settingFile.DeleteKey("FilePermission");
            }

            if (!settingFile.KeyExists("GameIntegrity"))
            {
                settingFile.Write("GameIntegrity", GameIntegrity);
            }

            if (!settingFile.KeyExists("ProxyPort"))
            {
                settingFile.Write("ProxyPort", string.Empty);
            }

            if (!settingFile.KeyExists("WebCallMethod"))
            {
                settingFile.Write("WebCallMethod", WebCallMethod);
            }

            if (!settingFile.KeyExists("ThemeSupport"))
            {
                settingFile.Write("ThemeSupport", ThemeSupport);
            }
            if (!settingFile.KeyExists("StreamingSupport"))
            {
                settingFile.Write("StreamingSupport", StreamingSupport);
            }

            if (!settingFile.KeyExists("Insider"))
            {
                settingFile.Write("Insider", Insider);
            }
            else if (settingFile.KeyExists("Insider") && !EnableInsiderBetaTester.Allowed())
            {
                Log.Core("Insider Status: ".ToUpper() + "Opted Into the Beta Preview -> " + EnableInsiderBetaTester.Allowed(Insider == "1"));
            }

            if (!UnixOS.Detected())
            {
                if (!settingFile.KeyExists("FirewallLauncher"))
                {
                    settingFile.Write("FirewallLauncher", FirewallLauncherStatus);
                }

                if (!settingFile.KeyExists("FirewallGame"))
                {
                    settingFile.Write("FirewallGame", FirewallGameStatus);
                }

                if (WindowsProductVersion.GetWindowsNumber() >= 10.0)
                {
                    if (!settingFile.KeyExists("DefenderLauncher"))
                    {
                        settingFile.Write("DefenderLauncher", DefenderLauncherStatus);
                    }

                    if (!settingFile.KeyExists("DefenderGame"))
                    {
                        settingFile.Write("DefenderGame", DefenderGameStatus);
                    }
                }
                else if (WindowsProductVersion.GetWindowsNumber() < 10.0)
                {
                    if (settingFile.KeyExists("DefenderLauncher") || !string.IsNullOrWhiteSpace(settingFile.Read("DefenderLauncher")))
                    {
                        settingFile.DeleteKey("DefenderLauncher");
                    }

                    if (settingFile.KeyExists("DefenderGame") || !string.IsNullOrWhiteSpace(settingFile.Read("DefenderGame")))
                    {
                        settingFile.DeleteKey("DefenderGame");
                    }
                }

                if (WindowsProductVersion.GetWindowsNumber() == 6.1 && !settingFile.KeyExists("PatchesApplied"))
                {
                    settingFile.Write("PatchesApplied", Win7UpdatePatches);
                }
                else if ((UnixOS.Detected() || WindowsProductVersion.GetWindowsNumber() != 6.1) && settingFile.KeyExists("PatchesApplied"))
                {
                    settingFile.DeleteKey("PatchesApplied");
                }
            }

            /* Key Entries to Convert into Boolens */

            /** Proxy Port Number **/
            bool UsingCustomProxyPort = false;

            if (!string.IsNullOrWhiteSpace(settingFile.Read("ProxyPort")))
            {
                bool isNumeric = int.TryParse(settingFile.Read("ProxyPort"), out int Port);

                if (isNumeric)
                {
                    if (Port > 0)
                    {
                        ServerProxy.ProxyPort = Port;
                        UsingCustomProxyPort  = true;
                        Log.Info("SETTINGS FILE: Custom Proxy Port -> " + Port);
                    }
                }
            }

            if (!UsingCustomProxyPort)
            {
                bool isNumeric = int.TryParse(DateTime.Now.Year.ToString(), out int Port);

                if (isNumeric)
                {
                    ServerProxy.ProxyPort = new Random().Next(2017, Port);
                }
                else
                {
                    ServerProxy.ProxyPort = new Random().Next(2017, 2021);
                }

                Log.Info("SETTINGS FILE: Random Generated Default Port -> " + ServerProxy.ProxyPort);
            }

            if (!string.IsNullOrWhiteSpace(WebCallMethod))
            {
                Log.Info("SETTINGS FILE: Choosen WebCall Method -> " + WebCallMethod);
            }

            /* Key Entries to Remove (No Longer Needed) */

            if (settingFile.KeyExists("LauncherPosX"))
            {
                settingFile.DeleteKey("LauncherPosX");
            }

            if (settingFile.KeyExists("LauncherPosY"))
            {
                settingFile.DeleteKey("LauncherPosY");
            }

            if (settingFile.KeyExists("DisableVerifyHash"))
            {
                settingFile.DeleteKey("DisableVerifyHash");
            }

            if (settingFile.KeyExists("TracksHigh"))
            {
                settingFile.DeleteKey("TracksHigh");
            }

            if (settingFile.KeyExists("ModNetDisabled"))
            {
                settingFile.DeleteKey("ModNetDisabled");
            }

            if (settingFile.KeyExists("ModNetZip"))
            {
                settingFile.DeleteKey("ModNetZip");
            }

            settingFile = new IniFile("Settings.ini");
        }
        public static void NullSafeSettings()
        {
            if (settingFile.KeyExists("Server"))
            {
                FileAccountSave.ChoosenGameServer = settingFile.Read("Server");
                settingFile.DeleteKey("Server");
                FileAccountSave.SaveAccount();
            }

            if (settingFile.KeyExists("AccountEmail"))
            {
                FileAccountSave.UserRawEmail = settingFile.Read("AccountEmail");
                settingFile.DeleteKey("AccountEmail");
                FileAccountSave.SaveAccount();
            }

            if (settingFile.KeyExists("Password"))
            {
                FileAccountSave.UserHashedPassword = settingFile.Read("Password");
                settingFile.DeleteKey("Password");
                FileAccountSave.SaveAccount();
            }

            if (DetectLinux.LinuxDetected() && !settingFile.KeyExists("InstallationDirectory"))
            {
                settingFile.Write("InstallationDirectory", "GameFiles");
            }
            else if (!settingFile.KeyExists("InstallationDirectory"))
            {
                settingFile.Write("InstallationDirectory", GameInstallation);
            }
            else if (!File.Exists(GameInstallation) && !string.IsNullOrEmpty(GameInstallation))
            {
                Directory.CreateDirectory(GameInstallation);
            }

            if (!settingFile.KeyExists("CDN"))
            {
                settingFile.Write("CDN", CDN);
            }
            else if (settingFile.KeyExists("CDN"))
            {
                if (CDN.EndsWith("/"))
                {
                    char[] charsToTrim = { '/' };
                    string FinalCDNURL = CDN.TrimEnd(charsToTrim);

                    settingFile.Write("CDN", FinalCDNURL);
                }
            }

            if (!settingFile.KeyExists("Language"))
            {
                settingFile.Write("Language", Lang);
            }

            if (!settingFile.KeyExists("DisableProxy"))
            {
                settingFile.Write("DisableProxy", Proxy);
            }

            if (!settingFile.KeyExists("DisableRPC"))
            {
                settingFile.Write("DisableRPC", RPC);
            }

            if (!settingFile.KeyExists("IgnoreUpdateVersion"))
            {
                settingFile.Write("IgnoreUpdateVersion", IgnoreVersion);
            }

            if (!DetectLinux.LinuxDetected())
            {
                if (!settingFile.KeyExists("Firewall"))
                {
                    settingFile.Write("Firewall", FirewallStatus);
                }

                if (WindowsProductVersion.GetWindowsNumber() >= 10.0)
                {
                    if (!settingFile.KeyExists("WindowsDefender"))
                    {
                        settingFile.Write("WindowsDefender", WindowsDefenderStatus);
                    }
                }
                else if (WindowsProductVersion.GetWindowsNumber() < 10.0)
                {
                    if (settingFile.KeyExists("WindowsDefender") || !string.IsNullOrEmpty(settingFile.Read("WindowsDefender")))
                    {
                        settingFile.DeleteKey("WindowsDefender");
                    }
                }

                if (WindowsProductVersion.GetWindowsNumber() == 6.1 && !settingFile.KeyExists("PatchesApplied"))
                {
                    settingFile.Write("PatchesApplied", Win7UpdatePatches);
                }
                else if (WindowsProductVersion.GetWindowsNumber() != 6.1 && settingFile.KeyExists("PatchesApplied"))
                {
                    settingFile.DeleteKey("PatchesApplied");
                }
            }

            /* Key Entries to Remove (No Longer Needed) */

            if (settingFile.KeyExists("LauncherPosX"))
            {
                settingFile.DeleteKey("LauncherPosX");
            }

            if (settingFile.KeyExists("LauncherPosY"))
            {
                settingFile.DeleteKey("LauncherPosY");
            }

            if (settingFile.KeyExists("DisableVerifyHash"))
            {
                settingFile.DeleteKey("DisableVerifyHash");
            }

            if (settingFile.KeyExists("TracksHigh"))
            {
                settingFile.DeleteKey("TracksHigh");
            }

            if (settingFile.KeyExists("ModNetDisabled"))
            {
                settingFile.DeleteKey("ModNetDisabled");
            }

            settingFile = new IniFile("Settings.ini");
        }
        public static void NullSafeSettings()
        {
            if (settingFile.KeyExists("Server"))
            {
                FileAccountSave.ChoosenGameServer = settingFile.Read("Server");
                settingFile.DeleteKey("Server");
                FileAccountSave.SaveAccount();
            }

            if (settingFile.KeyExists("AccountEmail"))
            {
                FileAccountSave.UserRawEmail = settingFile.Read("AccountEmail");
                settingFile.DeleteKey("AccountEmail");
                FileAccountSave.SaveAccount();
            }

            if (settingFile.KeyExists("Password"))
            {
                FileAccountSave.UserHashedPassword = settingFile.Read("Password");
                settingFile.DeleteKey("Password");
                FileAccountSave.SaveAccount();
            }

            if (DetectLinux.LinuxDetected() && !settingFile.KeyExists("InstallationDirectory"))
            {
                settingFile.Write("InstallationDirectory", "GameFiles");
            }
            else if (!settingFile.KeyExists("InstallationDirectory"))
            {
                settingFile.Write("InstallationDirectory", "");
            }
            else if (!File.Exists(settingFile.Read("InstallationDirectory")) && !string.IsNullOrEmpty(settingFile.Read("InstallationDirectory")))
            {
                Directory.CreateDirectory(settingFile.Read("InstallationDirectory"));
            }

            if (!settingFile.KeyExists("CDN") || string.IsNullOrEmpty(settingFile.Read("CDN")))
            {
                settingFile.Write("CDN", "http://localhost");
            }
            else if (settingFile.KeyExists("CDN"))
            {
                string SavedCDN = settingFile.Read("CDN");

                if (SavedCDN.EndsWith("/"))
                {
                    char[] charsToTrim = { '/' };
                    string FinalCDNURL = SavedCDN.TrimEnd(charsToTrim);

                    settingFile.Write("CDN", FinalCDNURL);
                }
            }

            if (!settingFile.KeyExists("Language") || string.IsNullOrEmpty(settingFile.Read("Language")))
            {
                settingFile.Write("Language", "en");
            }

            if (!settingFile.KeyExists("DisableProxy") || string.IsNullOrEmpty(settingFile.Read("DisableProxy")))
            {
                settingFile.Write("DisableProxy", "0");
            }

            if (!settingFile.KeyExists("DisableRPC") || string.IsNullOrEmpty(settingFile.Read("DisableRPC")))
            {
                settingFile.Write("DisableRPC", "0");
            }

            if (!settingFile.KeyExists("IgnoreUpdateVersion"))
            {
                settingFile.Write("IgnoreUpdateVersion", string.Empty);
            }

            if (!DetectLinux.LinuxDetected())
            {
                if (!settingFile.KeyExists("PatchesApplied") && WindowsProductVersion.GetWindowsNumber() == 6.1)
                {
                    settingFile.Write("PatchesApplied", "0");
                }
                else if (settingFile.KeyExists("PatchesApplied") && WindowsProductVersion.GetWindowsNumber() != 6.1)
                {
                    settingFile.DeleteKey("PatchesApplied");
                }

                if (!settingFile.KeyExists("Firewall") || string.IsNullOrEmpty(settingFile.Read("Firewall")))
                {
                    settingFile.Write("Firewall", "Not Excluded");
                }

                if (WindowsProductVersion.GetWindowsNumber() >= 10.0)
                {
                    if (!settingFile.KeyExists("WindowsDefender") || string.IsNullOrEmpty(settingFile.Read("WindowsDefender")))
                    {
                        settingFile.Write("WindowsDefender", "Not Excluded");
                    }
                }
                else if (WindowsProductVersion.GetWindowsNumber() < 10.0)
                {
                    if (settingFile.KeyExists("WindowsDefender") || !string.IsNullOrEmpty(settingFile.Read("WindowsDefender")))
                    {
                        settingFile.DeleteKey("WindowsDefender");
                    }
                }
            }

            settingFile = new IniFile("Settings.ini");
        }