コード例 #1
0
        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");
        }
コード例 #2
0
        private static void Start()
        {
            DiscordLauncherPresence.Start("Start Up", null);

            if (!UnixOS.Detected())
            {
                DiscordLauncherPresence.Status("Start Up", "Checking .NET Framework");
                try
                {
                    /* Check if User has a compatible .NET Framework Installed */
                    if (int.TryParse(RegistryCore.Read("Release", @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\"), out int NetFrame_Version))
                    {
                        /* For now, allow edge case of Windows 8.0 to run .NET 4.6.1 where upgrading to 8.1 is not possible */
                        if (WindowsProductVersion.GetWindowsNumber() == 6.2 && NetFrame_Version <= 394254)
                        {
                            if (MessageBox.Show(null, Translations.Database("Program_TextBox_NetFrame_P1") +
                                                " .NETFramework, Version=v4.6.1 \n\n" + Translations.Database("Program_TextBox_NetFrame_P2"),
                                                "GameLauncher.exe - " + Translations.Database("Program_TextBox_NetFrame_P3"),
                                                MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                            {
                                Process.Start("https://dotnet.microsoft.com/download/dotnet-framework/net461");
                            }

                            FunctionStatus.LauncherForceClose = true;
                        }
                        /* Otherwise, all other OS Versions should have 4.6.2 as a Minimum Version */
                        else if (NetFrame_Version <= 394802)
                        {
                            if (MessageBox.Show(null, Translations.Database("Program_TextBox_NetFrame_P1") +
                                                " .NETFramework, Version=v4.6.2 \n\n" + Translations.Database("Program_TextBox_NetFrame_P2"),
                                                "GameLauncher.exe - " + Translations.Database("Program_TextBox_NetFrame_P3"),
                                                MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                            {
                                Process.Start("https://dotnet.microsoft.com/download/dotnet-framework");
                            }

                            FunctionStatus.LauncherForceClose = true;
                        }
                        else
                        {
                            Log.System("NET-FRAMEWORK: Supported Installed Version");
                        }
                    }
                    else
                    {
                        Log.Warning("NET-FRAMEWORK: Failed to Parse Version");
                    }
                }
                catch
                {
                    FunctionStatus.LauncherForceClose = true;
                }
            }

            if (FunctionStatus.LauncherForceClose)
            {
                FunctionStatus.ErrorCloseLauncher("Closing From .NET Framework Check", false);
            }
            else
            {
                /* Splash Screen */
                if (!Debugger.IsAttached)
                {
                    /* Starts Splash Screen */
                    SplashScreen.ThreadStatus("Start");
                }

                LogToFileAddons.RemoveLogs();
                Log.StartLogging();

                Log.Info("CURRENT DATE: " + Time.GetTime("Date"));
                Log.Checking("LAUNCHER MIGRATION: Appdata and/or Roaming Folders");
                /* Deletes Folders that will Crash the Launcher (Cleanup Migration) */
                try
                {
                    if (Directory.Exists(Strings.Encode(Path.Combine(Locations.LocalAppDataFolder, "Soapbox_Race_World"))))
                    {
                        Directory.Delete(Strings.Encode(Path.Combine(Locations.LocalAppDataFolder, "Soapbox_Race_World")), true);
                    }
                    if (Directory.Exists(Strings.Encode(Path.Combine(Locations.RoamingAppDataFolder, "Soapbox_Race_World"))))
                    {
                        Directory.Delete(Strings.Encode(Path.Combine(Locations.RoamingAppDataFolder, "Soapbox_Race_World")), true);
                    }
                    if (Directory.Exists(Strings.Encode(Path.Combine(Locations.LocalAppDataFolder, "SoapBoxRaceWorld"))))
                    {
                        Directory.Delete(Strings.Encode(Path.Combine(Locations.LocalAppDataFolder, "SoapBoxRaceWorld")), true);
                    }
                    if (Directory.Exists(Strings.Encode(Path.Combine(Locations.RoamingAppDataFolder, "SoapBoxRaceWorld"))))
                    {
                        Directory.Delete(Strings.Encode(Path.Combine(Locations.RoamingAppDataFolder, "SoapBoxRaceWorld")), true);
                    }
                    if (Directory.Exists(Strings.Encode(Path.Combine(Locations.LocalAppDataFolder, "WorldUnited.gg"))))
                    {
                        Directory.Delete(Strings.Encode(Path.Combine(Locations.LocalAppDataFolder, "WorldUnited.gg")), true);
                    }
                    if (Directory.Exists(Strings.Encode(Path.Combine(Locations.RoamingAppDataFolder, "WorldUnited.gg"))))
                    {
                        Directory.Delete(Strings.Encode(Path.Combine(Locations.RoamingAppDataFolder, "WorldUnited.gg")), true);
                    }
                }
                catch (Exception Error)
                {
                    LogToFileAddons.OpenLog("LAUNCHER MIGRATION", null, Error, null, true);
                }
                Log.Completed("LAUNCHER MIGRATION");

                Log.Checking("LAUNCHER XML: If File Exists or Not");
                DiscordLauncherPresence.Status("Start Up", "Checking if UserSettings XML Exists");
                /* Create Default Configuration Files (if they don't already exist) */
                if (!File.Exists(Locations.UserSettingsXML))
                {
                    try
                    {
                        if (!Directory.Exists(Locations.UserSettingsFolder))
                        {
                            Directory.CreateDirectory(Locations.UserSettingsFolder);
                        }

                        File.WriteAllBytes(Locations.UserSettingsXML, ExtractResource.AsByte("GameLauncher.Resources.UserSettings.UserSettings.xml"));
                    }
                    catch (Exception Error)
                    {
                        LogToFileAddons.OpenLog("LAUNCHER XML", null, Error, null, true);
                    }
                }
                Log.Completed("LAUNCHER XML");

                string Insider = string.Empty;
                if (EnableInsiderDeveloper.Allowed())
                {
                    Insider = "DEV TEST ";
                }
                else if (EnableInsiderBetaTester.Allowed())
                {
                    Insider = "BETA TEST ";
                }

                Log.Build(Insider + "BUILD: GameLauncher " + Application.ProductVersion + "_" + InsiderInfo.BuildNumberOnly());

                Log.Checking("OS: Detecting");
                DiscordLauncherPresence.Status("Start Up", "Checking Operating System");
                try
                {
                    if (UnixOS.Detected())
                    {
                        InformationCache.OSName = UnixOS.FullName();
                        Log.System("SYSTEM: Detected OS: " + InformationCache.OSName);
                    }
                    else
                    {
                        InformationCache.OSName = WindowsProductVersion.ConvertWindowsNumberToName();
                        Log.System("SYSTEM: Detected OS: " + InformationCache.OSName);
                        Log.System("SYSTEM: Windows Build: " + WindowsProductVersion.GetWindowsBuildNumber());
                        Log.System("SYSTEM: NT Version: " + Environment.OSVersion.VersionString);
                        Log.System("SYSTEM: Video Card: " + HardwareInfo.GPU.CardName());
                        Log.System("SYSTEM: Driver Version: " + HardwareInfo.GPU.DriverVersion());
                    }
                    Log.Completed("OS: Detected");
                }
                catch (Exception Error)
                {
                    LogToFileAddons.OpenLog("SYSTEM", null, Error, null, true);
                    FunctionStatus.LauncherForceCloseReason = "Code: 0\n" + Translations.Database("Program_TextBox_System_Detection") + "\n" + Error.Message;
                    FunctionStatus.LauncherForceClose       = true;
                }

                if (FunctionStatus.LauncherForceClose)
                {
                    FunctionStatus.ErrorCloseLauncher("Closing From Operating System Check", false);
                }
                else
                {
                    /* Set Launcher Directory */
                    Log.Checking("SETUP: Setting Launcher Folder Directory");
                    Directory.SetCurrentDirectory(Locations.LauncherFolder);
                    Log.Completed("SETUP: Current Directory now Set at -> " + Locations.LauncherFolder);

                    if (!UnixOS.Detected())
                    {
                        Log.Checking("FOLDER LOCATION: Checking Launcher Folder Directory");
                        DiscordLauncherPresence.Status("Start Up", "Checking Launcher Folder Locations");

                        switch (FunctionStatus.CheckFolder(Locations.LauncherFolder))
                        {
                        case FolderType.IsTempFolder:
                        case FolderType.IsUsersFolders:
                        case FolderType.IsProgramFilesFolder:
                        case FolderType.IsWindowsFolder:
                        case FolderType.IsRootFolder:
                            String Constructed_Msg = String.Empty;

                            Constructed_Msg += Translations.Database("Program_TextBox_Folder_Check_Launcher") + "\n\n";
                            Constructed_Msg += Translations.Database("Program_TextBox_Folder_Check_Launcher_P2") + "\n";
                            Constructed_Msg += "• X:\\GameLauncher.exe " + Translations.Database("Program_TextBox_Folder_Check_Launcher_P3") + "\n";
                            Constructed_Msg += "• C:\\Program Files\n";
                            Constructed_Msg += "• C:\\Program Files (x86)\n";
                            Constructed_Msg += "• C:\\Users " + Translations.Database("Program_TextBox_Folder_Check_Launcher_P4") + "\n";
                            Constructed_Msg += "• C:\\Windows\n\n";
                            Constructed_Msg += Translations.Database("Program_TextBox_Folder_Check_Launcher_P5") + "\n";
                            Constructed_Msg += "• 'C:\\Soapbox Race World' " + Translations.Database("Program_TextBox_Folder_Check_Launcher_P6") + " 'C:\\SBRW'\n";
                            Constructed_Msg += Translations.Database("Program_TextBox_Folder_Check_Launcher_P7") + "\n\n";

                            MessageBox.Show(null, Constructed_Msg, "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            FunctionStatus.LauncherForceClose = true;
                            break;
                        }

                        Log.Completed("FOLDER LOCATION: Done");
                    }

                    if (FunctionStatus.LauncherForceClose)
                    {
                        FunctionStatus.ErrorCloseLauncher("Closing From Invalid Launcher Location", false);
                    }
                    else
                    {
                        Log.Checking("WRITE TEST: Launcher Folder Test");
                        if (!FunctionStatus.HasWriteAccessToFolder(Locations.LauncherFolder))
                        {
                            MessageBox.Show(Translations.Database("Program_TextBox_Folder_Write_Test"));
                        }
                        Log.Completed("WRITE TEST: Passed");

                        Log.Checking("INI FILES: Doing Nullsafe");
                        DiscordLauncherPresence.Status("Start Up", "Doing NullSafe ini Files");
                        FileSettingsSave.NullSafeSettings();
                        FileAccountSave.NullSafeAccount();
                        Log.Completed("INI FILES: Done");
                        /* Sets up Theming */
                        Theming.CheckIfThemeExists();

                        Log.Function("APPLICATION: Setting Language");
                        CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo(Translations.UI(Translations.Application_Language = FileSettingsSave.Lang.ToLower(), true));
                        Log.Completed("APPLICATION: Done Setting Language '" + Translations.UI(Translations.Application_Language) + "'");

                        /* Windows 7 TLS Check */
                        if (WindowsProductVersion.GetWindowsNumber() == 6.1)
                        {
                            Log.Checking("SSL/TLS: Windows 7 Detected");
                            DiscordLauncherPresence.Status("Start Up", "Checking Windows 7 SSL/TLS");

                            try
                            {
                                String MessageBoxPopupTLS = String.Empty;
                                string keyName            = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client";
                                string subKey             = "DisabledByDefault";

                                if (Registry.GetValue(keyName, subKey, null) == null)
                                {
                                    MessageBoxPopupTLS = Translations.Database("Program_TextBox_W7_TLS_P1") + "\n\n";

                                    MessageBoxPopupTLS += "- HKLM/SYSTEM/CurrentControlSet/Control/SecurityProviders\n  /SCHANNEL/Protocols/TLS 1.2/Client\n";
                                    MessageBoxPopupTLS += "- Value: DisabledByDefault -> 0\n\n";

                                    MessageBoxPopupTLS += Translations.Database("Program_TextBox_W7_TLS_P2") + "\n\n";
                                    MessageBoxPopupTLS += Translations.Database("Program_TextBox_W7_TLS_P3");

                                    /* There is only 'OK' Available because this IS Required */
                                    if (MessageBox.Show(null, MessageBoxPopupTLS, "SBRW Launcher",
                                                        MessageBoxButtons.OK, MessageBoxIcon.Warning) == DialogResult.OK)
                                    {
                                        RegistryCore.Write("DisabledByDefault", 0x0,
                                                           @"SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client");
                                        MessageBox.Show(null, Translations.Database("Program_TextBox_W7_TLS_P4"),
                                                        "SBRW Launcher", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    }
                                    Log.Completed("SSL/TLS: Added Registry Key");
                                }
                                else
                                {
                                    Log.Completed("SSL/TLS: Done");
                                }
                            }
                            catch (Exception Error)
                            {
                                LogToFileAddons.OpenLog("SSL/TLS", null, Error, null, true);
                            }
                        }

                        /* Windows 7 HotFix Check */
                        if (WindowsProductVersion.GetWindowsNumber() == 6.1 && string.IsNullOrWhiteSpace(FileSettingsSave.Win7UpdatePatches))
                        {
                            Log.Checking("HotFixes: Windows 7 Detected");
                            DiscordLauncherPresence.Status("Start Up", "Checking Windows 7 HotFixes");

                            try
                            {
                                if (!ManagementSearcher.GetInstalledHotFix("KB3020369") || !ManagementSearcher.GetInstalledHotFix("KB3125574"))
                                {
                                    String MessageBoxPopupKB = String.Empty;
                                    MessageBoxPopupKB  = Translations.Database("Program_TextBox_W7_KB_P1") + "\n";
                                    MessageBoxPopupKB += Translations.Database("Program_TextBox_W7_KB_P2") + "\n\n";

                                    if (!ManagementSearcher.GetInstalledHotFix("KB3020369"))
                                    {
                                        MessageBoxPopupKB += "- " + Translations.Database("Program_TextBox_W7_KB_P3") + " KB3020369\n";
                                    }

                                    if (!ManagementSearcher.GetInstalledHotFix("KB3125574"))
                                    {
                                        MessageBoxPopupKB += "- " + Translations.Database("Program_TextBox_W7_KB_P3") + " KB3125574\n";
                                    }
                                    MessageBoxPopupKB += "\n" + Translations.Database("Program_TextBox_W7_KB_P4") + "\n";

                                    if (MessageBox.Show(null, MessageBoxPopupKB, "SBRW Launcher",
                                                        MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                                    {
                                        /* Since it's Informational we just need to know if they clicked 'OK' */
                                        FileSettingsSave.Win7UpdatePatches = "1";
                                    }
                                    else
                                    {
                                        /* or if they clicked 'Cancel' */
                                        FileSettingsSave.Win7UpdatePatches = "0";
                                    }

                                    FileSettingsSave.SaveSettings();
                                }

                                Log.Completed("HotFixes: Done");
                            }
                            catch (Exception Error)
                            {
                                LogToFileAddons.OpenLog("HotFixes", null, Error, null, true);
                            }
                        }
                    }

                    Log.Checking("JSON: Servers File");
                    try
                    {
                        if (File.Exists(Strings.Encode(Path.Combine(Locations.LauncherFolder, Locations.NameOldServersJSON))))
                        {
                            if (File.Exists(Strings.Encode(Path.Combine(Locations.LauncherFolder, Locations.NameNewServersJSON))))
                            {
                                File.Delete(Strings.Encode(Path.Combine(Locations.LauncherFolder, Locations.NameNewServersJSON)));
                            }

                            File.Move(
                                Strings.Encode(Path.Combine(Locations.LauncherFolder, Locations.NameOldServersJSON)),
                                Strings.Encode(Path.Combine(Locations.LauncherFolder, Locations.NameNewServersJSON)));
                            Log.Completed("JSON: Renaming Servers File");
                        }
                        else if (!File.Exists(Strings.Encode(Path.Combine(Locations.LauncherFolder, Locations.NameNewServersJSON))))
                        {
                            try
                            {
                                File.WriteAllText(
                                    Strings.Encode(Path.Combine(Locations.LauncherFolder, Locations.NameNewServersJSON)), "[]");
                                Log.Completed("JSON: Created Servers File");
                            }
                            catch (Exception Error)
                            {
                                LogToFileAddons.OpenLog("JSON SERVER FILE", null, Error, null, true);
                            }
                        }
                    }
                    catch (Exception Error)
                    {
                        LogToFileAddons.OpenLog("JSON SERVER FILE", null, Error, null, true);
                    }
                    Log.Checking("JSON: Done");

                    if (!string.IsNullOrWhiteSpace(FileSettingsSave.GameInstallation))
                    {
                        Log.Checking("CLEANLINKS: Game Path");
                        if (File.Exists(Locations.GameLinksFile))
                        {
                            ModNetHandler.CleanLinks(Locations.GameLinksFile, FileSettingsSave.GameInstallation);
                            Log.Completed("CLEANLINKS: Done");
                        }
                        else
                        {
                            Log.Completed("CLEANLINKS: Not Present");
                        }
                    }

                    Log.Checking("PROXY: Checking if Proxy Is Disabled from User Settings! It's value is " + FileSettingsSave.Proxy);
                    if (FileSettingsSave.Proxy == "0")
                    {
                        Log.Core("PROXY: Starting Proxy (From Startup)");
                        ServerProxy.Instance.Start("Splash Screen [Program.cs]");
                        Log.Completed("PROXY: Started");
                    }
                    else
                    {
                        Log.Completed("PROXY: Disabled");
                    }

                    Log.Info("REDISTRIBUTABLE: Moved to Function");
                    /* (Starts Function Chain) Check if Redistributable Packages are Installed */
                    Redistributable.Check();
                }
            }
        }
コード例 #3
0
        /*******************************/

        /* On Button/Dropdown Functions /
        *  /*******************************/

        /* Settings Save */
        private void SettingsSave_Click(object sender, EventArgs e)
        {
            //TODO null check
            FileSettingsSave.Lang = SettingsLanguage.SelectedValue.ToString();

            if (WindowsProductVersion.GetWindowsNumber() >= 10.0 && (FileSettingsSave.GameInstallation != _newGameFilesPath) && !DetectLinux.LinuxDetected())
            {
                WindowsDefenderGameFilesDirctoryChange();
            }
            else if (FileSettingsSave.GameInstallation != _newGameFilesPath)
            {
                CheckGameFilesDirectoryPrevention();

                if (!DetectLinux.LinuxDetected())
                {
                    //Remove current Firewall for the Game Files
                    string CurrentGameFilesExePath = Path.Combine(FileSettingsSave.GameInstallation + "\\nfsw.exe");

                    if (File.Exists(CurrentGameFilesExePath) && FirewallHelper.RuleExist("SBRW - Game") == true)
                    {
                        bool removeFirewallRule = true;
                        bool firstTimeRun       = true;

                        string nameOfGame  = "SBRW - Game";
                        string localOfGame = CurrentGameFilesExePath;

                        string groupKeyGame    = "Need for Speed: World";
                        string descriptionGame = groupKeyGame;

                        //Inbound & Outbound
                        FirewallHelper.DoesRulesExist(removeFirewallRule, firstTimeRun, nameOfGame, localOfGame, groupKeyGame, descriptionGame, FirewallProtocol.Any);
                    }
                }

                FileSettingsSave.GameInstallation = _newGameFilesPath;

                //Clean Mods Files from New Dirctory (If it has .links in directory)
                var linksPath = Path.Combine(_newGameFilesPath, "\\.links");
                ModNetLinksCleanup.CleanLinks(linksPath);

                _restartRequired = true;
            }

            if (FileSettingsSave.CDN != ((CDNObject)SettingsCDNPick.SelectedItem).Url)
            {
                SettingsCDNCurrentText.Text = "CHANGED CDN";
                SettingsCDNCurrent.Text     = ((CDNObject)SettingsCDNPick.SelectedItem).Url;
                FileSettingsSave.CDN        = ((CDNObject)SettingsCDNPick.SelectedItem).Url;
                _restartRequired            = true;
            }

            String disableProxy = (SettingsProxyCheckbox.Checked == true) ? "1" : "0";

            if (FileSettingsSave.Proxy != disableProxy)
            {
                FileSettingsSave.Proxy = (SettingsProxyCheckbox.Checked == true) ? "1" : "0";
                _restartRequired       = true;
            }

            String disableRPC = (SettingsDiscordRPCCheckbox.Checked == true) ? "1" : "0";

            if (FileSettingsSave.RPC != disableRPC)
            {
                FileSettingsSave.RPC = (SettingsDiscordRPCCheckbox.Checked == true) ? "1" : "0";
                _restartRequired     = true;
            }

            if (_restartRequired)
            {
                MessageBox.Show(null, "In order to see settings changes, you need to restart launcher manually.", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            //Actually lets check those 2 files
            if (File.Exists(FileSettingsSave.GameInstallation + "/profwords") && File.Exists(FileSettingsSave.GameInstallation + "/profwords_dis"))
            {
                File.Delete(FileSettingsSave.GameInstallation + "/profwords_dis");
            }

            //Delete/Enable profwords filter here
            if (SettingsWordFilterCheck.Checked)
            {
                if (File.Exists(FileSettingsSave.GameInstallation + "/profwords"))
                {
                    File.Move(FileSettingsSave.GameInstallation + "/profwords", FileSettingsSave.GameInstallation + "/profwords_dis");
                }
            }
            else
            {
                if (File.Exists(FileSettingsSave.GameInstallation + "/profwords_dis"))
                {
                    File.Move(FileSettingsSave.GameInstallation + "/profwords_dis", FileSettingsSave.GameInstallation + "/profwords");
                }
            }

            /* Save Settings */
            FileSettingsSave.SaveSettings();

            var userSettingsXml = new XmlDocument();

            try
            {
                if (File.Exists(_userSettings))
                {
                    try
                    {
                        userSettingsXml.Load(_userSettings);
                        var language = userSettingsXml.SelectSingleNode("Settings/UI/Language");
                        language.InnerText = SettingsLanguage.SelectedValue.ToString();
                    }
                    catch
                    {
                        File.Delete(_userSettings);

                        var setting = userSettingsXml.AppendChild(userSettingsXml.CreateElement("Settings"));
                        var ui      = setting.AppendChild(userSettingsXml.CreateElement("UI"));

                        var persistentValue = setting.AppendChild(userSettingsXml.CreateElement("PersistentValue"));
                        var chat            = persistentValue.AppendChild(userSettingsXml.CreateElement("Chat"));
                        chat.InnerXml = "<DefaultChatGroup Type=\"string\">" + Self.currentLanguage + "</DefaultChatGroup>";
                        ui.InnerXml   = "<Language Type=\"string\">" + SettingsLanguage.SelectedValue + "</Language>";

                        var directoryInfo = Directory.CreateDirectory(Path.GetDirectoryName(_userSettings));
                    }
                }
                else
                {
                    try
                    {
                        var setting = userSettingsXml.AppendChild(userSettingsXml.CreateElement("Settings"));
                        var ui      = setting.AppendChild(userSettingsXml.CreateElement("UI"));

                        var persistentValue = setting.AppendChild(userSettingsXml.CreateElement("PersistentValue"));
                        var chat            = persistentValue.AppendChild(userSettingsXml.CreateElement("Chat"));
                        chat.InnerXml = "<DefaultChatGroup Type=\"string\">" + Self.currentLanguage + "</DefaultChatGroup>";
                        ui.InnerXml   = "<Language Type=\"string\">" + SettingsLanguage.SelectedValue + "</Language>";

                        var directoryInfo = Directory.CreateDirectory(Path.GetDirectoryName(_userSettings));
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(null, "There was an error saving your settings to actual file. Restoring default.\n" + ex.Message, "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        File.Delete(_userSettings);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(null, "There was an error saving your settings to actual file. Restoring default.\n" + ex.Message, "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error);
                File.Delete(_userSettings);
            }

            /* Save XML Settings */
            userSettingsXml.Save(_userSettings);

            //DialogResult = DialogResult.OK;
            Close();
        }
コード例 #4
0
        public static void SaveSettings()
        {
            if (settingFile.Read("CDN") != CDN)
            {
                if (CDN.EndsWith("/"))
                {
                    char[] charsToTrim = { '/' };
                    string FinalCDNURL = CDN.TrimEnd(charsToTrim);

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

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

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

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

            if (settingFile.Read("InstallationDirectory") != GameInstallation)
            {
                settingFile.Write("InstallationDirectory", GameInstallation);
            }

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

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

                if (WindowsProductVersion.GetWindowsNumber() >= 10.0)
                {
                    if (settingFile.Read("WindowsDefender") != WindowsDefenderStatus)
                    {
                        settingFile.Write("WindowsDefender", WindowsDefenderStatus);
                    }
                }

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

            settingFile = new IniFile("Settings.ini");
        }
コード例 #5
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");
        }
コード例 #6
0
        public static void DisableChecks(bool CompletedEvent)
        {
            cheats_detected = Get_Cheat_Status();

            if (cheats_detected != 0)
            {
                if (cheats_detected == 64 && !CompletedEvent)
                {
                    /* You Know the Rules and So Do I */
                }
                else
                {
                    if (ServerProxy.Running())
                    {
                        foreach (string report_url in URLs.AntiCheatFD)
                        {
                            if (Completed == 0)
                            {
                                Completed++;
                                FunctionStatus.ExternalToolsWasUsed = true;
                            }

                            if (report_url.EndsWith("?"))
                            {
                                try
                                {
                                    Uri sendReport = new Uri(report_url + "serverip=" + serverip + "&user_id=" + user_id + "&persona_name=" + persona_name + "&event_session=" + event_id + "&cheat_type=" + cheats_detected + "&hwid=" + HardwareID.FingerPrint.Value() + "&persona_id=" + persona_id + "&launcher_hash=" + WebHelpers.Value() + "&launcher_certificate=" + CertificateStore.LauncherSerial + "&hwid_fallback=" + HardwareID.FingerPrint.ValueAlt() + "&car_used=" + DiscordGamePresence.PersonaCarName + "&os_platform=" + InformationCache.OSName + "&event_status=" + CompletedEvent);
                                    ServicePointManager.FindServicePoint(sendReport).ConnectionLeaseTimeout = (int)TimeSpan.FromSeconds(30).TotalMilliseconds;

                                    var Client = new WebClient
                                    {
                                        Encoding = Encoding.UTF8
                                    };

                                    if (!WebCalls.Alternative())
                                    {
                                        Client = new WebClientWithTimeout {
                                            Encoding = Encoding.UTF8
                                        };
                                    }
                                    else
                                    {
                                        Client.Headers.Add("user-agent", "SBRW Launcher " + Application.ProductVersion + " - (" + InsiderInfo.BuildNumberOnly() + ")");
                                    }
                                    Client.DownloadStringCompleted += (Nice, Brock) => { Client.Dispose(); };

                                    try
                                    {
                                        string NTVersion = WindowsProductVersion.GetWindowsBuildNumber() != 0 ? WindowsProductVersion.GetWindowsBuildNumber().ToString() : "Wine";
                                        Client.Headers.Add("os-version", NTVersion);
                                        Client.DownloadStringAsync(sendReport);
                                    }
                                    catch { }
                                }
                                catch { }
                            }
                            else
                            {
                                try
                                {
                                    Uri sendReport = new Uri(report_url);
                                    ServicePointManager.FindServicePoint(sendReport).ConnectionLeaseTimeout = (int)TimeSpan.FromSeconds(30).TotalMilliseconds;

                                    var request  = (HttpWebRequest)WebRequest.Create(sendReport);
                                    var postData = "serverip=" + serverip + "&user_id=" + user_id + "&persona_name=" + persona_name + "&event_session=" + event_id + "&cheat_type=" + cheats_detected + "&hwid=" + HardwareID.FingerPrint.Value() + "&persona_id=" + persona_id + "&launcher_hash=" + WebHelpers.Value() + "&launcher_certificate=" + CertificateStore.LauncherSerial + "&hwid_fallback=" + HardwareID.FingerPrint.ValueAlt() + "&car_used=" + DiscordGamePresence.PersonaCarName + "&os_platform=" + InformationCache.OSName + "&event_status=" + CompletedEvent;

                                    var data = Encoding.ASCII.GetBytes(postData);
                                    request.Method        = "POST";
                                    request.ContentType   = "application/x-www-form-urlencoded";
                                    request.ContentLength = data.Length;
                                    request.Timeout       = (int)TimeSpan.FromSeconds(30).TotalMilliseconds;

                                    using (var stream = request.GetRequestStream())
                                    {
                                        stream.Write(data, 0, data.Length);
                                    }

                                    var    response       = (HttpWebResponse)request.GetResponse();
                                    String responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
                                }
                                catch { }
                            }
                        }
                    }
                    else
                    {
                        if (Completed != URLs.AntiCheatSD.Length)
                        {
                            foreach (string report_url in URLs.AntiCheatSD)
                            {
                                Completed++;
                                if (report_url.EndsWith("?"))
                                {
                                    try
                                    {
                                        Uri sendReport = new Uri(report_url + "serverip=" + serverip + "&user_id=" + user_id + "&cheat_type=" + cheats_detected + "&hwid=" + HardwareID.FingerPrint.Value() + "&launcher_hash=" + WebHelpers.Value() + "&launcher_certificate=" + CertificateStore.LauncherSerial + "&hwid_fallback=" + HardwareID.FingerPrint.ValueAlt() + "&os_platform=" + InformationCache.OSName);
                                        ServicePointManager.FindServicePoint(sendReport).ConnectionLeaseTimeout = (int)TimeSpan.FromSeconds(30).TotalMilliseconds;

                                        var Client = new WebClient
                                        {
                                            Encoding = Encoding.UTF8
                                        };

                                        if (!WebCalls.Alternative())
                                        {
                                            Client = new WebClientWithTimeout {
                                                Encoding = Encoding.UTF8
                                            };
                                        }
                                        else
                                        {
                                            Client.Headers.Add("user-agent", "SBRW Launcher " + Application.ProductVersion + " - (" + InsiderInfo.BuildNumberOnly() + ")");
                                        }
                                        Client.DownloadStringCompleted += (Nice, Brock) => { Client.Dispose(); };

                                        try
                                        {
                                            string NTVersion = WindowsProductVersion.GetWindowsBuildNumber() != 0 ? WindowsProductVersion.GetWindowsBuildNumber().ToString() : "Wine";
                                            Client.Headers.Add("os-version", NTVersion);
                                            Client.DownloadStringAsync(sendReport);
                                        }
                                        catch { }
                                    }
                                    catch { }
                                }
                            }
                        }
                    }

                    TimeConversions.MUFRTime();
                }
            }

            detect_MULTIHACK = detect_FAST_POWERUPS = detect_SPEEDHACK = detect_SMOOTH_WALLS = detect_TANK_MODE = detect_WALLHACK = detect_DRIFTMOD = detect_PURSUITBOT = false;
            cheats_detected  = 0;
            Secret.Abort();
        }
コード例 #7
0
        /// <summary>Saves all Current Values</summary>
        public static void SaveSettings()
        {
            if (settingFile.Read("CDN") != CDN)
            {
                if (CDN.EndsWith("/"))
                {
                    char[] charsToTrim = { '/' };
                    string FinalCDNURL = CDN.TrimEnd(charsToTrim);

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

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

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

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

            if (settingFile.Read("InstallationDirectory") != GameInstallation)
            {
                settingFile.Write("InstallationDirectory", GameInstallation);
            }

            if (!UnixOS.Detected() && settingFile.Read("OldInstallationDirectory") != GameInstallationOld)
            {
                settingFile.Write("OldInstallationDirectory", GameInstallationOld);
            }

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

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

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

            if (settingFile.Read("ThemeSupport") != ThemeSupport)
            {
                settingFile.Write("ThemeSupport", ThemeSupport);
            }

            if (settingFile.Read("StreamingSupport") != StreamingSupport)
            {
                settingFile.Write("StreamingSupport", StreamingSupport);
            }

            if (settingFile.Read("Insider") != Insider)
            {
                settingFile.Write("Insider", Insider);
            }

            if (!UnixOS.Detected())
            {
                if (settingFile.Read("FilePermission") != FilePermissionStatus)
                {
                    settingFile.Write("FilePermission", FilePermissionStatus);
                }

                if (settingFile.Read("FirewallLauncher") != FirewallLauncherStatus)
                {
                    settingFile.Write("FirewallLauncher", FirewallLauncherStatus);
                }

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

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

                    if (settingFile.Read("DefenderGame") != DefenderGameStatus)
                    {
                        settingFile.Write("DefenderGame", DefenderGameStatus);
                    }
                }

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

            settingFile = new IniFile("Settings.ini");
        }
コード例 #8
0
        private static void Main2(Arguments args)
        {
            if (!DetectLinux.LinuxDetected())
            {
                //Check if User has .NETFramework 4.6.2 or later Installed
                const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";

                using (var ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey))
                {
                    if (ndpKey != null && ndpKey.GetValue("Release") != null && (int)ndpKey.GetValue("Release") >= 394802)
                    {
                        /* Check Up to Date Certificate Status */
                        try
                        {
                            WebClient update_data = new WebClient();
                            update_data.CancelAsync();
                            update_data.Headers.Add("user-agent", "GameLauncher " + Application.ProductVersion + " (+https://github.com/SoapBoxRaceWorld/GameLauncher_NFSW)");
                            update_data.DownloadStringAsync(new Uri("http://crl.carboncrew.org/RCA-Info.json"));
                            update_data.DownloadStringCompleted += (sender, e) => {
                                JSONRootCA API = JsonConvert.DeserializeObject <JSONRootCA>(e.Result);

                                if (API.CN != null)
                                {
                                    Log.Info("CERTIFICATE STORE: Setting Common Name -> " + API.CN);
                                    CertificateStore.RootCACommonName = API.CN;
                                }

                                if (API.Subject != null)
                                {
                                    Log.Info("CERTIFICATE STORE: Setting Subject Name -> " + API.Subject);
                                    CertificateStore.RootCASubjectName = API.Subject;
                                }

                                if (API.Ids != null)
                                {
                                    foreach (IdsModel entries in API.Ids)
                                    {
                                        if (entries.Serial != null)
                                        {
                                            Log.Info("CERTIFICATE STORE: Setting Serial Number -> " + entries.Serial);
                                            CertificateStore.RootCASerial = entries.Serial;
                                        }
                                    }
                                }

                                if (API.File != null)
                                {
                                    foreach (FileModel entries in API.File)
                                    {
                                        if (entries.Name != null)
                                        {
                                            Log.Info("CERTIFICATE STORE: Setting Root CA File Name -> " + entries.Name);
                                            CertificateStore.RootCAFileName = entries.Name;
                                        }

                                        if (entries.Cer != null)
                                        {
                                            Log.Info("CERTIFICATE STORE: Setting Root CA File URL -> " + entries.Cer);
                                            CertificateStore.RootCAFileURL = entries.Cer;
                                        }
                                    }
                                }
                            };
                        }
                        catch
                        {
                            Log.Error("CERTIFICATE STORE: Unable to Retrive Latest Certificate Information");
                        }
                    }
                    else
                    {
                        DialogResult frameworkError = MessageBox.Show(null, "This application requires one of the following versions of the .NET Framework:\n" +
                                                                      " .NETFramework, Version=v4.6.2 \n\nDo you want to install this .NET Framework version now?", "GameLauncher.exe - This application could not be started.", MessageBoxButtons.YesNo, MessageBoxIcon.Error);

                        if (frameworkError == DialogResult.Yes)
                        {
                            Process.Start("https://dotnet.microsoft.com/download/dotnet-framework");
                        }
                        Process.GetProcessById(Process.GetCurrentProcess().Id).Kill();
                    }
                }
            }

            File.Delete("communication.log");
            File.Delete("launcher.log");

            Log.StartLogging();

            FileSettingsSave.NullSafeSettings();
            FileAccountSave.NullSafeAccount();

            Self.currentLanguage = CultureInfo.CurrentCulture.Name.Split('-')[0].ToUpper();
            Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture("en-US");
            Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("en-US");

            if (UriScheme.IsCommandLineArgumentsInstalled())
            {
                UriScheme.InstallCommandLineArguments(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), AppDomain.CurrentDomain.FriendlyName));
                if (args.Parse != null)
                {
                    new UriScheme(args.Parse);
                }
            }

            if (EnableInsider.ShouldIBeAnInsider() == true)
            {
                Log.Build("INSIDER: GameLauncher " + Application.ProductVersion + "_" + EnableInsider.BuildNumber());
            }
            else
            {
                Log.Build("BUILD: GameLauncher " + Application.ProductVersion);
            }

            if (Properties.Settings.Default.IsRestarting)
            {
                Properties.Settings.Default.IsRestarting = false;
                Properties.Settings.Default.Save();
                Thread.Sleep(3000);
            }

            if (!DetectLinux.LinuxDetected())
            {
                //Windows Firewall Runner
                if (!string.IsNullOrEmpty(FileSettingsSave.FirewallStatus))
                {
                    string nameOfLauncher  = "SBRW - Game Launcher";
                    string localOfLauncher = Assembly.GetEntryAssembly().Location;

                    string nameOfUpdater  = "SBRW - Game Launcher Updater";
                    string localOfUpdater = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "GameLauncherUpdater.exe");

                    string groupKeyLauncher    = "Game Launcher for Windows";
                    string descriptionLauncher = "Soapbox Race World";

                    bool removeFirewallRule = false;
                    bool firstTimeRun       = false;

                    if (FileSettingsSave.FirewallStatus == "Not Excluded")
                    {
                        firstTimeRun = true;
                        FileSettingsSave.FirewallStatus = "Excluded";
                    }
                    else if (FileSettingsSave.FirewallStatus == "Reset")
                    {
                        removeFirewallRule = true;
                        FileSettingsSave.FirewallStatus = "Not Excluded";
                    }

                    FileSettingsSave.SaveSettings();

                    //Inbound & Outbound
                    FirewallHelper.DoesRulesExist(removeFirewallRule, firstTimeRun, nameOfLauncher, localOfLauncher, groupKeyLauncher, descriptionLauncher, FirewallProtocol.Any);
                    FirewallHelper.DoesRulesExist(removeFirewallRule, firstTimeRun, nameOfUpdater, localOfUpdater, groupKeyLauncher, descriptionLauncher, FirewallProtocol.Any);

                    //This Removes the Game File Exe From Firewall
                    //To Find the one that Adds the Exe To Firewall -> Search for `OnDownloadFinished()`
                    string CurrentGameFilesExePath = Path.Combine(FileSettingsSave.GameInstallation + "\\nfsw.exe");

                    if (File.Exists(CurrentGameFilesExePath) && removeFirewallRule == true)
                    {
                        string nameOfGame  = "SBRW - Game";
                        string localOfGame = CurrentGameFilesExePath;

                        string groupKeyGame    = "Need for Speed: World";
                        string descriptionGame = groupKeyGame;

                        //Inbound & Outbound
                        FirewallHelper.DoesRulesExist(removeFirewallRule, firstTimeRun, nameOfGame, localOfGame, groupKeyGame, descriptionGame, FirewallProtocol.Any);
                    }
                }
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(true);

            VisualsAPIChecker.PingAPIStatus();

            /* Set Launcher Directory */
            Log.Info("CORE: Setting up current directory: " + Path.GetDirectoryName(Application.ExecutablePath));
            Directory.SetCurrentDirectory(Path.GetDirectoryName(Application.ExecutablePath));

            if (!DetectLinux.LinuxDetected())
            {
                Log.Info("CORE: Checking current directory");

                switch (Self.CheckFolder(Directory.GetCurrentDirectory()))
                {
                case FolderType.IsTempFolder:
                    MessageBox.Show(null, "Please, extract me and my DLL files before executing...", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    Environment.Exit(0);
                    break;

                case FolderType.IsUsersFolders:
                    MessageBox.Show(null, "Please, choose a different directory for the game launcher.\n\nSpecial Folders such as:" +
                                    "\n\nDownloads, Documents, Desktop, Videos, Music, OneDrive, or Any Type of User Folders" +
                                    "\n\nAre Disadvised", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    Environment.Exit(0);
                    break;

                case FolderType.IsProgramFilesFolder:
                    MessageBox.Show(null, "Please, choose a different directory for the game launcher." +
                                    "\n\nSpecial Folders such as:\n\nProgram Files or Program Files (x86)\n\nAre Disadvised", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    Environment.Exit(0);
                    break;

                case FolderType.IsWindowsFolder:
                    MessageBox.Show(null, "Please, choose a different directory for the game launcher." +
                                    "\n\nSpecial Folder such as:\n\nWindows\n\nAre Disadvised", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    Environment.Exit(0);
                    break;
                }

                if (!Self.HasWriteAccessToFolder(Path.GetDirectoryName(Application.ExecutablePath)))
                {
                    MessageBox.Show("This application requires admin priviledge");
                }

                //Update this text file if a new GameLauncherUpdater.exe has been delployed - DavidCarbon
                try
                {
                    try
                    {
                        switch (APIStatusChecker.CheckStatus("http://api.github.com/repos/SoapboxRaceWorld/GameLauncherUpdater/releases/latest"))
                        {
                        case API.Online:
                            WebClient update_data = new WebClient();
                            update_data.CancelAsync();
                            update_data.Headers.Add("user-agent", "GameLauncher " + Application.ProductVersion + " (+https://github.com/SoapBoxRaceWorld/GameLauncher_NFSW)");
                            update_data.DownloadStringAsync(new Uri("http://api.github.com/repos/SoapboxRaceWorld/GameLauncherUpdater/releases/latest"));
                            update_data.DownloadStringCompleted += (sender, e) => {
                                GitHubRelease GHAPI = JsonConvert.DeserializeObject <GitHubRelease>(e.Result);

                                if (GHAPI.TagName != null)
                                {
                                    Log.Info("LAUNCHER UPDATER: Setting Latest Version -> " + GHAPI.TagName);
                                    LatestUpdaterBuildVersion = GHAPI.TagName;
                                }
                                Log.Info("LAUNCHER UPDATER: Latest Version -> " + LatestUpdaterBuildVersion);
                            };
                            break;

                        default:
                            Log.Error("LAUNCHER UPDATER: Failed to Retrive Latest Updater Information from GitHub");
                            break;
                        }
                    }
                    catch
                    {
                        var GetLatestUpdaterBuildVersion = new WebClient().DownloadString(Self.secondstaticapiserver + "/Version.txt");
                        if (!string.IsNullOrEmpty(GetLatestUpdaterBuildVersion))
                        {
                            Log.Info("LAUNCHER UPDATER: Setting Latest Version -> " + GetLatestUpdaterBuildVersion);
                            LatestUpdaterBuildVersion = GetLatestUpdaterBuildVersion;
                        }
                    }
                    Log.Info("LAUNCHER UPDATER: Fail Safe Latest Version -> " + LatestUpdaterBuildVersion);
                }
                catch (Exception ex)
                {
                    Log.Error("LAUNCHER UPDATER: Failed to get new version file: " + ex.Message);
                }
            }

            if (!DetectLinux.LinuxDetected())
            {
                //Windows 7 Fix
                if ((string.IsNullOrEmpty(FileSettingsSave.Win7UpdatePatches) && WindowsProductVersion.GetWindowsNumber() == 6.1) || FileSettingsSave.Win7UpdatePatches == "0")
                {
                    if (Self.GetInstalledHotFix("KB3020369") == false || Self.GetInstalledHotFix("KB3125574") == false)
                    {
                        String messageBoxPopupKB = String.Empty;
                        messageBoxPopupKB  = "Hey Windows 7 User, we've detected a potential issue of some missing Updates that are required.\n";
                        messageBoxPopupKB += "We found that these Windows Update packages are showing as not installed:\n\n";

                        if (Self.GetInstalledHotFix("KB3020369") == false)
                        {
                            messageBoxPopupKB += "- Update KB3020369\n";
                        }
                        if (Self.GetInstalledHotFix("KB3125574") == false)
                        {
                            messageBoxPopupKB += "- Update KB3125574\n";
                        }

                        messageBoxPopupKB += "\nAditionally, we must add a value to the registry:\n";

                        messageBoxPopupKB += "- HKLM/SYSTEM/CurrentControlSet/Control/SecurityProviders\n/SCHANNEL/Protocols/TLS 1.2/Client\n";
                        messageBoxPopupKB += "- Value: DisabledByDefault -> 0\n\n";

                        messageBoxPopupKB += "Would you like to add those values?";
                        DialogResult replyPatchWin7 = MessageBox.Show(null, messageBoxPopupKB, "SBRW Launcher", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                        if (replyPatchWin7 == DialogResult.Yes)
                        {
                            RegistryKey key = Registry.LocalMachine.CreateSubKey(@"SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client");
                            key.SetValue("DisabledByDefault", 0x0);

                            MessageBox.Show(null, "Registry option set, Remember that the changes may require a system reboot to take effect", "SBRW Launcher", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else
                        {
                            MessageBox.Show(null, "Roger that, There may be some issues connecting to the servers.", "SBRW Launcher", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }

                        FileSettingsSave.Win7UpdatePatches = "1";
                        FileSettingsSave.SaveSettings();
                    }
                }

                if (!RedistributablePackage.IsInstalled(RedistributablePackageVersion.VC2015to2019x86))
                {
                    var result = MessageBox.Show(
                        "You do not have the 32-bit 2015-2019 VC++ Redistributable Package installed.\n \nThis will install in the Background\n \nThis may restart your computer. \n \nClick OK to install it.",
                        "Compatibility",
                        MessageBoxButtons.OKCancel,
                        MessageBoxIcon.Warning);

                    if (result != DialogResult.OK)
                    {
                        MessageBox.Show("The game will not be started.", "Compatibility", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        return;
                    }

                    var wc = new WebClient();
                    wc.DownloadFile("https://aka.ms/vs/16/release/VC_redist.x86.exe", "VC_redist.x86.exe");
                    var proc = Process.Start(new ProcessStartInfo
                    {
                        Verb      = "runas",
                        Arguments = "/quiet",
                        FileName  = "VC_redist.x86.exe"
                    });

                    if (proc == null)
                    {
                        MessageBox.Show("Failed to run package installer. The game will not be started.", "Compatibility", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        return;
                    }
                }

                if (Environment.Is64BitOperatingSystem == true)
                {
                    if (!RedistributablePackage.IsInstalled(RedistributablePackageVersion.VC2015to2019x64))
                    {
                        var result = MessageBox.Show(
                            "You do not have the 64-bit 2015-2019 VC++ Redistributable Package installed.\n \nThis will install in the Background\n \nThis may restart your computer. \n \nClick OK to install it.",
                            "Compatibility",
                            MessageBoxButtons.OKCancel,
                            MessageBoxIcon.Warning);

                        if (result != DialogResult.OK)
                        {
                            MessageBox.Show("The game will not be started.", "Compatibility", MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                            return;
                        }

                        var wc = new WebClient();
                        wc.DownloadFile("https://aka.ms/vs/16/release/VC_redist.x64.exe", "VC_redist.x64.exe");
                        var proc = Process.Start(new ProcessStartInfo
                        {
                            Verb      = "runas",
                            Arguments = "/quiet",
                            FileName  = "VC_redist.x64.exe"
                        });

                        if (proc == null)
                        {
                            MessageBox.Show("Failed to run package installer. The game will not be started.", "Compatibility", MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                            return;
                        }
                    }
                }
            }

            Console.WriteLine("Application path: " + Path.GetDirectoryName(Application.ExecutablePath));

            if (!string.IsNullOrEmpty(FileSettingsSave.GameInstallation))
            {
                if (!Self.HasWriteAccessToFolder(FileSettingsSave.GameInstallation))
                {
                    MessageBox.Show("This application requires admin priviledge. Restarting...");
                }
            }

            //INFO: this is here because this dll is necessary for downloading game files and I want to make it async.
            //Updated RedTheKitsune Code so it downloads the file if its missing. It also restarts the launcher if the user click on yes on Prompt. - DavidCarbon
            if (!File.Exists("LZMA.dll"))
            {
                try
                {
                    Log.Warning("CORE: Starting LZMA downloader");
                    using (WebClient wc = new WebClient())
                    {
                        wc.DownloadFileAsync(new Uri(Self.fileserver + "/LZMA.dll"), "LZMA.dll");
                    }

                    DialogResult restartApp = MessageBox.Show(null, "Downloaded Missing LZMA.dll File. \nPlease Restart Launcher, Thanks!", "GameLauncher Restart Required", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                    if (restartApp == DialogResult.Yes)
                    {
                        Properties.Settings.Default.IsRestarting = true;
                        Properties.Settings.Default.Save();
                        Application.Restart();
                    }

                    Process.GetProcessById(Process.GetCurrentProcess().Id).Kill();
                }
                catch (Exception ex)
                {
                    Log.Error("CORE: Failed to download LZMA. " + ex.Message);
                }
            }

            //StaticConfiguration.DisableErrorTraces = false;

            if (!File.Exists("servers.json"))
            {
                try
                {
                    File.WriteAllText("servers.json", "[]");
                } catch { /* ignored */ }
            }

            if (Properties.Settings.Default.IsRestarting)
            {
                Properties.Settings.Default.IsRestarting = false;
                Properties.Settings.Default.Save();
                Thread.Sleep(3000);
            }

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            if (Debugger.IsAttached)
            {
                ShowMainScreen();
            }
            else
            {
                if (NFSW.IsNFSWRunning())
                {
                    MessageBox.Show(null, "An instance of Need for Speed: World is already running", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    Process.GetProcessById(Process.GetCurrentProcess().Id).Kill();
                }

                var mutex = new Mutex(false, "GameLauncherNFSW-MeTonaTOR");
                try
                {
                    if (mutex.WaitOne(0, false))
                    {
                        string[] files =
                        {
                            "CommandLine.dll - 2.8.0",
                            "DiscordRPC.dll - 1.0.169.0",
                            "Flurl.dll - 3.0.1",
                            "Flurl.Http.dll - 3.0.1",
                            "INIFileParser.dll - 2.5.2",
                            "LZMA.dll - 9.10 beta",
                            "Microsoft.WindowsAPICodePack.dll - 1.1.0.0",
                            "Microsoft.WindowsAPICodePack.Shell.dll - 1.1.0.0",
                            "Microsoft.WindowsAPICodePack.ShellExtensions.dll - 1.1.0.0",
                            "Nancy.dll - 2.0.0",
                            "Nancy.Hosting.Self.dll - 2.0.0",
                            "Newtonsoft.Json.dll - 12.0.3",
                            "System.Runtime.InteropServices.RuntimeInformation.dll - 4.6.24705.01. Commit Hash: 4d1af962ca0fede10beb01d197367c2f90e92c97",
                            "System.ValueTuple.dll - 4.6.26515.06 @BuiltBy: dlab-DDVSOWINAGE059 @Branch: release/2.1 @SrcCode: https://github.com/dotnet/corefx/tree/30ab651fcb4354552bd4891619a0bdd81e0ebdbf",
                            "WindowsFirewallHelper.dll - 1.6.3.40"
                        };

                        var missingfiles = new List <string>();

                        if (!DetectLinux.LinuxDetected())
                        { //MONO Hates that...
                            foreach (var file in files)
                            {
                                var splitFileVersion = file.Split(new string[] { " - " }, StringSplitOptions.None);

                                if (!File.Exists(Directory.GetCurrentDirectory() + "\\" + splitFileVersion[0]))
                                {
                                    missingfiles.Add(splitFileVersion[0] + " - Not Found");
                                }
                                else
                                {
                                    try
                                    {
                                        var      versionInfo  = FileVersionInfo.GetVersionInfo(splitFileVersion[0]);
                                        string[] versionsplit = versionInfo.ProductVersion.Split('+');
                                        string   version      = versionsplit[0];

                                        if (version == "")
                                        {
                                            missingfiles.Add(splitFileVersion[0] + " - Invalid File");
                                        }
                                        else
                                        {
                                            if (Self.CheckArchitectureFile(splitFileVersion[0]) == false)
                                            {
                                                missingfiles.Add(splitFileVersion[0] + " - Wrong Architecture");
                                            }
                                            else
                                            {
                                                if (version != splitFileVersion[1])
                                                {
                                                    missingfiles.Add(splitFileVersion[0] + " - Invalid Version (" + splitFileVersion[1] + " != " + version + ")");
                                                }
                                            }
                                        }
                                    }
                                    catch
                                    {
                                        missingfiles.Add(splitFileVersion[0] + " - Invalid File");
                                    }
                                }
                            }
                        }
                        if (missingfiles.Count != 0)
                        {
                            ShowSplashScreen(false);

                            var message = "Cannot launch GameLauncher. The following files are invalid:\n\n";

                            foreach (var file in missingfiles)
                            {
                                message += "• " + file + "\n";
                            }

                            MessageBox.Show(null, message, "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else
                        {
                            Theming.CheckIfThemeExists();
                            ShowSplashScreen(true);
                        }
                    }
                    else
                    {
                        ShowSplashScreen(false);
                        MessageBox.Show(null, "An instance of Launcher is already running.", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                finally
                {
                    mutex.Close();
                    mutex = null;
                }
            }
        }
コード例 #9
0
 public static SecurityCenterCodes SecurityCenterSavedCodes()
 {
     if (UnixOS.Detected())
     {
         return(SecurityCenterCodes.Unix);
     }
     else if (FileSettingsSave.FirewallLauncherStatus == "Excluded" && FileSettingsSave.FirewallGameStatus == "Excluded")
     {
         return(SecurityCenterCodes.Firewall_Updated);
     }
     else if ((FileSettingsSave.FirewallLauncherStatus == "Excluded" && FileSettingsSave.FirewallGameStatus == "Not Excluded") ||
              (FileSettingsSave.FirewallLauncherStatus == "Unknown" && FileSettingsSave.FirewallGameStatus == "Unknown") ||
              (FileSettingsSave.FirewallLauncherStatus == "Removed" && FileSettingsSave.FirewallGameStatus == "Removed"))
     {
         return(SecurityCenterCodes.Firewall_Outdated);
     }
     else if ((FileSettingsSave.FirewallLauncherStatus == "Error" && FileSettingsSave.FirewallGameStatus == "Error") ||
              (FileSettingsSave.FirewallLauncherStatus == "Not Supported" && FileSettingsSave.FirewallGameStatus == "Not Supported"))
     {
         return(SecurityCenterCodes.Firewall_Error);
     }
     else if ((WindowsProductVersion.GetWindowsNumber() >= 10) &&
              FileSettingsSave.DefenderLauncherStatus == "Excluded" && FileSettingsSave.DefenderGameStatus == "Excluded")
     {
         return(SecurityCenterCodes.Defender_Updated);
     }
     else if ((WindowsProductVersion.GetWindowsNumber() >= 10) &&
              ((FileSettingsSave.DefenderLauncherStatus == "Excluded" && FileSettingsSave.DefenderGameStatus == "Not Excluded") ||
               (FileSettingsSave.DefenderLauncherStatus == "Unknown" && FileSettingsSave.DefenderGameStatus == "Unknown") ||
               (FileSettingsSave.DefenderLauncherStatus == "Removed" && FileSettingsSave.DefenderGameStatus == "Removed")))
     {
         return(SecurityCenterCodes.Defender_Outdated);
     }
     else if ((WindowsProductVersion.GetWindowsNumber() >= 10) &&
              ((FileSettingsSave.DefenderLauncherStatus == "Error" && FileSettingsSave.DefenderGameStatus == "Error") ||
               (FileSettingsSave.DefenderLauncherStatus == "Not Supported" && FileSettingsSave.DefenderGameStatus == "Not Supported")))
     {
         return(SecurityCenterCodes.Defender_Error);
     }
     else if (FileSettingsSave.FilePermissionStatus == "Set")
     {
         return(SecurityCenterCodes.Permissions_Updated);
     }
     else if (FileSettingsSave.FilePermissionStatus == "Error")
     {
         return(SecurityCenterCodes.Permissions_Error);
     }
     else if (FileSettingsSave.FilePermissionStatus == "Not Set")
     {
         return(SecurityCenterCodes.Permissions_Outdated);
     }
     else if ((FileSettingsSave.FirewallLauncherStatus == "Not Excluded" && FileSettingsSave.FirewallGameStatus == "Not Excluded") ||
              ((WindowsProductVersion.GetWindowsNumber() >= 10) &&
               FileSettingsSave.DefenderLauncherStatus == "Not Excluded" && FileSettingsSave.DefenderGameStatus == "Not Excluded"))
     {
         return(SecurityCenterCodes.Unknown);
     }
     else
     {
         return(SecurityCenterCodes.Unknown);
     }
 }
コード例 #10
0
ファイル: Program.cs プロジェクト: lazenes/NFSTR-Launcher
        private static void DoRunChecks(Arguments args)
        {
            /* Splash Screen */
            if (!Debugger.IsAttached && !DetectLinux.LinuxDetected())
            {
                _SplashScreen = new Thread(new ThreadStart(SplashScreen));
                _SplashScreen.Start();
            }

            File.Delete("communication.log");
            File.Delete("launcher.log");
            Log.StartLogging();

            if (!DetectLinux.LinuxDetected())
            {
                //Check if User has .NETFramework 4.6.2 or later Installed
                const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";

                using (var ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey))
                {
                    if (ndpKey != null && ndpKey.GetValue("Release") != null && (int)ndpKey.GetValue("Release") >= 394802)
                    {
                        /* Check Up to Date Certificate Status */
                        try
                        {
                            WebClient update_data = new WebClient();
                            update_data.CancelAsync();
                            update_data.Headers.Add("user-agent", "GameLauncher " + Application.ProductVersion + " (+https://github.com/SoapBoxRaceWorld/GameLauncher_NFSW)");
                            update_data.DownloadStringAsync(new Uri("http://crl.carboncrew.org/RCA-Info.json"));
                            update_data.DownloadStringCompleted += (sender, e) => {
                                JsonRootCA API = JsonConvert.DeserializeObject <JsonRootCA>(e.Result);

                                if (API.CN != null)
                                {
                                    Log.Info("CERTIFICATE STORE: Setting Common Name -> " + API.CN);
                                    CertificateStore.RootCACommonName = API.CN;
                                }

                                if (API.Subject != null)
                                {
                                    Log.Info("CERTIFICATE STORE: Setting Subject Name -> " + API.Subject);
                                    CertificateStore.RootCASubjectName = API.Subject;
                                }

                                if (API.Ids != null)
                                {
                                    foreach (IdsModel entries in API.Ids)
                                    {
                                        if (entries.Serial != null)
                                        {
                                            Log.Info("CERTIFICATE STORE: Setting Serial Number -> " + entries.Serial);
                                            CertificateStore.RootCASerial = entries.Serial;
                                        }
                                    }
                                }

                                if (API.File != null)
                                {
                                    foreach (FileModel entries in API.File)
                                    {
                                        if (entries.Name != null)
                                        {
                                            Log.Info("CERTIFICATE STORE: Setting Root CA File Name -> " + entries.Name);
                                            CertificateStore.RootCAFileName = entries.Name;
                                        }

                                        if (entries.Cer != null)
                                        {
                                            Log.Info("CERTIFICATE STORE: Setting Root CA File URL -> " + entries.Cer);
                                            CertificateStore.RootCAFileURL = entries.Cer;
                                        }
                                    }
                                }
                            };
                        }
                        catch
                        {
                            Log.Error("CERTIFICATE STORE: Unable to Retrive Latest Certificate Information");
                        }
                    }
                    else
                    {
                        DialogResult frameworkError = MessageBox.Show(null, "This application requires one of the following versions of the .NET Framework:\n" +
                                                                      " .NETFramework, Version=v4.6.2 \n\nDo you want to install this .NET Framework version now?", "GameLauncher.exe - This application could not be started.", MessageBoxButtons.YesNo, MessageBoxIcon.Error);

                        if (frameworkError == DialogResult.Yes)
                        {
                            Process.Start("https://dotnet.microsoft.com/download/dotnet-framework");
                        }

                        /* Close Splash Screen (Just in Case) */
                        if (IsSplashScreenLive == true)
                        {
                            _SplashScreen.Abort();
                        }

                        Process.GetProcessById(Process.GetCurrentProcess().Id).Kill();
                    }
                }
            }

            FileSettingsSave.NullSafeSettings();
            FileAccountSave.NullSafeAccount();

            FunctionStatus.CurrentLanguage        = CultureInfo.CurrentCulture.Name.Split('-')[0].ToUpper();
            Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture("en-US");
            Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("en-US");

            if (UriScheme.IsCommandLineArgumentsInstalled())
            {
                UriScheme.InstallCommandLineArguments(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), AppDomain.CurrentDomain.FriendlyName));
                if (args.Parse != null)
                {
                    new UriScheme(args.Parse);
                }
            }

            if (EnableInsider.ShouldIBeAnInsider() == true)
            {
                Log.Build("INSIDER: GameLauncher " + Application.ProductVersion + "_" + EnableInsider.BuildNumber());
            }
            else
            {
                Log.Build("BUILD: GameLauncher " + Application.ProductVersion);
            }

            if (Properties.Settings.Default.IsRestarting)
            {
                Properties.Settings.Default.IsRestarting = false;
                Properties.Settings.Default.Save();
                Thread.Sleep(3000);
            }

            if (!DetectLinux.LinuxDetected())
            {
                //Windows Firewall Runner
                if (!string.IsNullOrEmpty(FileSettingsSave.FirewallStatus))
                {
                    if (FirewallManager.IsServiceRunning == true && FirewallHelper.FirewallStatus() == true)
                    {
                        string nameOfLauncher  = "SBRW - Game Launcher";
                        string localOfLauncher = Assembly.GetEntryAssembly().Location;

                        string nameOfUpdater  = "SBRW - Game Launcher Updater";
                        string localOfUpdater = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "GameLauncherUpdater.exe");

                        string groupKeyLauncher    = "Game Launcher for Windows";
                        string descriptionLauncher = "Soapbox Race World";

                        bool removeFirewallRule = false;
                        bool firstTimeRun       = false;

                        if (FileSettingsSave.FirewallStatus == "Not Excluded" || FileSettingsSave.FirewallStatus == "Turned Off" || FileSettingsSave.FirewallStatus == "Service Stopped" || FileSettingsSave.FirewallStatus == "Unknown")
                        {
                            firstTimeRun = true;
                            FileSettingsSave.FirewallStatus = "Excluded";
                        }
                        else if (FileSettingsSave.FirewallStatus == "Reset")
                        {
                            removeFirewallRule = true;
                            FileSettingsSave.FirewallStatus = "Not Excluded";
                        }

                        //Inbound & Outbound
                        FirewallHelper.DoesRulesExist(removeFirewallRule, firstTimeRun, nameOfLauncher, localOfLauncher, groupKeyLauncher, descriptionLauncher, FirewallProtocol.Any);
                        FirewallHelper.DoesRulesExist(removeFirewallRule, firstTimeRun, nameOfUpdater, localOfUpdater, groupKeyLauncher, descriptionLauncher, FirewallProtocol.Any);

                        //This Removes the Game File Exe From Firewall
                        //To Find the one that Adds the Exe To Firewall -> Search for `OnDownloadFinished()`
                        string CurrentGameFilesExePath = Path.Combine(FileSettingsSave.GameInstallation + "\\nfsw.exe");

                        if (File.Exists(CurrentGameFilesExePath) && removeFirewallRule == true)
                        {
                            string nameOfGame  = "SBRW - Game";
                            string localOfGame = CurrentGameFilesExePath;

                            string groupKeyGame    = "Need for Speed: World";
                            string descriptionGame = groupKeyGame;

                            //Inbound & Outbound
                            FirewallHelper.DoesRulesExist(removeFirewallRule, firstTimeRun, nameOfGame, localOfGame, groupKeyGame, descriptionGame, FirewallProtocol.Any);
                        }
                    }
                    else if (FirewallManager.IsServiceRunning == true && FirewallHelper.FirewallStatus() == false)
                    {
                        FileSettingsSave.FirewallStatus = "Turned Off";
                    }
                    else
                    {
                        FileSettingsSave.FirewallStatus = "Service Stopped";
                    }

                    FileSettingsSave.SaveSettings();
                }
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(true);

            /* Set Launcher Directory */
            Log.Info("CORE: Setting up current directory: " + Path.GetDirectoryName(Application.ExecutablePath));
            Directory.SetCurrentDirectory(Path.GetDirectoryName(Application.ExecutablePath));

            if (!DetectLinux.LinuxDetected())
            {
                Log.Info("CORE: Checking current directory");

                switch (FunctionStatus.CheckFolder(Directory.GetCurrentDirectory()))
                {
                case FolderType.IsTempFolder:
                case FolderType.IsUsersFolders:
                case FolderType.IsProgramFilesFolder:
                case FolderType.IsWindowsFolder:
                case FolderType.IsRootFolder:
                    String constructMsg = String.Empty;

                    constructMsg += "Bu Dizinde NFS World Dosyaları Yok.\nLütfen Bu Başlatıcı Dosyalarını oyunun Dosyalarının Olduğu dizine atın NOT:\n\n";
                    constructMsg += "• X:\\ (Anadizin, veya C:\\ ve D:\\)\n";
                    constructMsg += "• C:\\Program Files\n";
                    constructMsg += "• C:\\Program Files (x86)\n";
                    constructMsg += "• C:\\Kullanıcı ('Masaüstü' veya 'Belgeler')\n";
                    constructMsg += "• C:\\Windows\n\n";
                    constructMsg += "Dizinlerine Kurmayınız!";
                    MessageBox.Show(null, constructMsg, "NFSTR.Com Başlatıcı", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    Environment.Exit(0);
                    break;
                }

                if (!FunctionStatus.HasWriteAccessToFolder(Path.GetDirectoryName(Application.ExecutablePath)))
                {
                    MessageBox.Show("Bu Uygulama Admin Yetkileri Gerektirir");
                }

                //Update this text file if a new GameLauncherUpdater.exe has been delployed - DavidCarbon
                try
                {
                    try
                    {
                        switch (APIStatusChecker.CheckStatus("http://api.github.com/repos/SoapboxRaceWorld/GameLauncherUpdater/releases/latest"))
                        {
                        case APIStatus.Online:
                            WebClient update_data = new WebClient();
                            update_data.CancelAsync();
                            update_data.Headers.Add("user-agent", "GameLauncher " + Application.ProductVersion + " (+https://github.com/SoapBoxRaceWorld/GameLauncher_NFSW)");
                            update_data.DownloadStringAsync(new Uri("http://api.github.com/repos/SoapboxRaceWorld/GameLauncherUpdater/releases/latest"));
                            update_data.DownloadStringCompleted += (sender, e) => {
                                GitHubRelease GHAPI = JsonConvert.DeserializeObject <GitHubRelease>(e.Result);

                                if (GHAPI.TagName != null)
                                {
                                    Log.Info("LAUNCHER UPDATER: Setting Latest Version -> " + GHAPI.TagName);
                                    LatestUpdaterBuildVersion = GHAPI.TagName;
                                }
                                Log.Info("LAUNCHER UPDATER: Latest Version -> " + LatestUpdaterBuildVersion);
                            };
                            break;

                        default:
                            Log.Error("LAUNCHER UPDATER: Failed to Retrive Latest Updater Information from GitHub");
                            break;
                        }
                    }
                    catch
                    {
                        var GetLatestUpdaterBuildVersion = new WebClient().DownloadString(URLs.secondstaticapiserver + "/Version.txt");
                        if (!string.IsNullOrEmpty(GetLatestUpdaterBuildVersion))
                        {
                            Log.Info("LAUNCHER UPDATER: Setting Latest Version -> " + GetLatestUpdaterBuildVersion);
                            LatestUpdaterBuildVersion = GetLatestUpdaterBuildVersion;
                        }
                    }
                    Log.Info("LAUNCHER UPDATER: Fail Safe Latest Version -> " + LatestUpdaterBuildVersion);
                }
                catch (Exception ex)
                {
                    Log.Error("LAUNCHER UPDATER: Failed to get new version file: " + ex.Message);
                }
            }

            if (!DetectLinux.LinuxDetected())
            {
                //Windows 7 Fix
                if (WindowsProductVersion.GetWindowsNumber() == 6.1 && (string.IsNullOrEmpty(FileSettingsSave.Win7UpdatePatches)))
                {
                    if (ManagementSearcher.GetInstalledHotFix("KB3020369") == false || ManagementSearcher.GetInstalledHotFix("KB3125574") == false)
                    {
                        String messageBoxPopupKB = String.Empty;
                        messageBoxPopupKB  = "Hey Windows 7 User, we've detected a potential issue of some missing Updates that are required.\n";
                        messageBoxPopupKB += "We found that these Windows Update packages are showing as not installed:\n\n";

                        if (ManagementSearcher.GetInstalledHotFix("KB3020369") == false)
                        {
                            messageBoxPopupKB += "- Update KB3020369\n";
                        }
                        if (ManagementSearcher.GetInstalledHotFix("KB3125574") == false)
                        {
                            messageBoxPopupKB += "- Update KB3125574\n";
                        }

                        messageBoxPopupKB += "\nAditionally, we must add a value to the registry:\n";

                        messageBoxPopupKB += "- HKLM/SYSTEM/CurrentControlSet/Control/SecurityProviders\n/SCHANNEL/Protocols/TLS 1.2/Client\n";
                        messageBoxPopupKB += "- Value: DisabledByDefault -> 0\n\n";

                        messageBoxPopupKB += "Would you like to add those values?";
                        DialogResult replyPatchWin7 = MessageBox.Show(null, messageBoxPopupKB, "SBRW Launcher", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                        if (replyPatchWin7 == DialogResult.Yes)
                        {
                            RegistryKey key = Registry.LocalMachine.CreateSubKey(@"SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client");
                            key.SetValue("DisabledByDefault", 0x0);

                            MessageBox.Show(null, "Registry option set, Remember that the changes may require a system reboot to take effect", "SBRW Launcher", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            FileSettingsSave.Win7UpdatePatches = "1";
                        }
                        else
                        {
                            MessageBox.Show(null, "Roger that, There may be some issues connecting to the servers.", "SBRW Launcher", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            FileSettingsSave.Win7UpdatePatches = "0";
                        }

                        FileSettingsSave.SaveSettings();
                    }
                }

                if (!RedistributablePackage.IsInstalled(RedistributablePackageVersion.VC2015to2019x86))
                {
                    var result = MessageBox.Show(
                        "You do not have the 32-bit 2015-2019 VC++ Redistributable Package installed.\n \nThis will install in the Background\n \nThis may restart your computer. \n \nClick OK to install it.",
                        "Compatibility",
                        MessageBoxButtons.OKCancel,
                        MessageBoxIcon.Warning);

                    if (result != DialogResult.OK)
                    {
                        MessageBox.Show("The game will not be started.", "Compatibility", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        return;
                    }

                    var wc = new WebClient();
                    wc.DownloadFile("https://aka.ms/vs/16/release/VC_redist.x86.exe", "VC_redist.x86.exe");
                    var proc = Process.Start(new ProcessStartInfo
                    {
                        Verb      = "runas",
                        Arguments = "/quiet",
                        FileName  = "VC_redist.x86.exe"
                    });

                    if (proc == null)
                    {
                        MessageBox.Show("Failed to run package installer. The game will not be started.", "Compatibility", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        return;
                    }
                }

                if (Environment.Is64BitOperatingSystem == true)
                {
                    if (!RedistributablePackage.IsInstalled(RedistributablePackageVersion.VC2015to2019x64))
                    {
                        var result = MessageBox.Show(
                            "You do not have the 64-bit 2015-2019 VC++ Redistributable Package installed.\n \nThis will install in the Background\n \nThis may restart your computer. \n \nClick OK to install it.",
                            "Compatibility",
                            MessageBoxButtons.OKCancel,
                            MessageBoxIcon.Warning);

                        if (result != DialogResult.OK)
                        {
                            MessageBox.Show("The game will not be started.", "Compatibility", MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                            return;
                        }

                        var wc = new WebClient();
                        wc.DownloadFile("https://aka.ms/vs/16/release/VC_redist.x64.exe", "VC_redist.x64.exe");
                        var proc = Process.Start(new ProcessStartInfo
                        {
                            Verb      = "runas",
                            Arguments = "/quiet",
                            FileName  = "VC_redist.x64.exe"
                        });

                        if (proc == null)
                        {
                            MessageBox.Show("Failed to run package installer. The game will not be started.", "Compatibility", MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                            return;
                        }
                    }
                }
            }

            Console.WriteLine("Application path: " + Path.GetDirectoryName(Application.ExecutablePath));

            if (!string.IsNullOrEmpty(FileSettingsSave.GameInstallation))
            {
                if (!FunctionStatus.HasWriteAccessToFolder(FileSettingsSave.GameInstallation))
                {
                    MessageBox.Show("This application requires admin priviledge. Restarting...");
                }
            }

            //StaticConfiguration.DisableErrorTraces = false;

            if (!File.Exists("servers.json"))
            {
                try
                {
                    File.WriteAllText("servers.json", "[]");
                }
                catch { /* ignored */ }
            }

            if (Properties.Settings.Default.IsRestarting)
            {
                Properties.Settings.Default.IsRestarting = false;
                Properties.Settings.Default.Save();
                Thread.Sleep(3000);
            }

            Theming.CheckIfThemeExists();

            /* Check If Launcher Failed to Connect to any APIs */
            if (VisualsAPIChecker.WOPLAPI == false)
            {
                DialogResult restartAppNoApis = MessageBox.Show(null, "There's no internet connection, Launcher might crash \n \nClick Yes to Close Launcher \nor \nClick No Continue", "GameLauncher has Stopped, Failed To Connect To API", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                if (restartAppNoApis == DialogResult.No)
                {
                    MessageBox.Show("Good Luck... \n No Really \n ...Good Luck", "GameLauncher Will Continue, When It Failed To Connect To API");
                    Log.Warning("PRE-CHECK: User has Bypassed 'No Internet Connection' Check and Will Continue");
                }

                if (restartAppNoApis == DialogResult.Yes)
                {
                    /* Close Splash Screen (Just in Case) */
                    if (IsSplashScreenLive == true)
                    {
                        _SplashScreen.Abort();
                    }

                    Process.GetProcessById(Process.GetCurrentProcess().Id).Kill();
                }
            }

            LanguageListUpdater.GetList();
            LauncherUpdateCheck.CheckAvailability();

            if (!DetectLinux.LinuxDetected())
            {
                //Install Custom Root Certificate
                CertificateStore.Check();

                if (!File.Exists("GameLauncherUpdater.exe"))
                {
                    Log.Info("LAUNCHER UPDATER: Starting GameLauncherUpdater downloader");
                    try
                    {
                        using (WebClient wc = new WebClient())
                        {
                            wc.DownloadFileCompleted += (object sender, AsyncCompletedEventArgs e) =>
                            {
                                if (new FileInfo("GameLauncherUpdater.exe").Length == 0)
                                {
                                    File.Delete("GameLauncherUpdater.exe");
                                }
                            };
                            wc.DownloadFile(new Uri("https://github.com/SoapboxRaceWorld/GameLauncherUpdater/releases/latest/download/GameLauncherUpdater.exe"), "GameLauncherUpdater.exe");
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error("LAUCHER UPDATER: Failed to download updater. " + ex.Message);
                    }
                }
                else if (File.Exists("GameLauncherUpdater.exe"))
                {
                    String GameLauncherUpdaterLocation = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "GameLauncherUpdater.exe");
                    var    LauncherUpdaterBuild        = FileVersionInfo.GetVersionInfo(GameLauncherUpdaterLocation);
                    var    LauncherUpdaterBuildNumber  = LauncherUpdaterBuild.FileVersion;
                    var    UpdaterBuildNumberResult    = LauncherUpdaterBuildNumber.CompareTo(LatestUpdaterBuildVersion);

                    Log.Build("LAUNCHER UPDATER BUILD: GameLauncherUpdater " + LauncherUpdaterBuildNumber);
                    if (UpdaterBuildNumberResult < 0)
                    {
                        Log.Info("LAUNCHER UPDATER: " + UpdaterBuildNumberResult + " Builds behind latest Updater!");
                    }
                    else
                    {
                        Log.Info("LAUNCHER UPDATER: Latest GameLauncherUpdater!");
                    }

                    if (UpdaterBuildNumberResult < 0)
                    {
                        Log.Info("LAUNCHER UPDATER: Downloading New GameLauncherUpdater.exe");
                        File.Delete("GameLauncherUpdater.exe");

                        try
                        {
                            using (WebClient wc = new WebClient())
                            {
                                wc.DownloadFile(new Uri("https://github.com/SoapboxRaceWorld/GameLauncherUpdater/releases/latest/download/GameLauncherUpdater.exe"), "GameLauncherUpdater.exe");
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Error("LAUNCHER UPDATER: Failed to download new updater. " + ex.Message);
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(FileSettingsSave.GameInstallation))
            {
                var linksPath = Path.Combine(FileSettingsSave.GameInstallation + "\\.links");
                ModNetLinksCleanup.CleanLinks(linksPath);
            }

            /* Check Permission for Launcher Folder and File it Self */
            FileORFolderPermissions.CheckLauncherPerms("Folder", Path.Combine(AppDomain.CurrentDomain.BaseDirectory));

            Log.Info("PROXY: Starting Proxy");
            ServerProxy.Instance.Start();

            /* Check ServerList Status */

            if (FunctionStatus.ServerListStatus != "Loaded")
            {
                ServerListUpdater.GetList();
            }

            /* Close Splash Screen */
            if (IsSplashScreenLive == true)
            {
                _SplashScreen.Abort();
            }

            Log.Visuals("CORE: Starting MainScreen");
            Application.Run(new MainScreen());
        }
コード例 #11
0
        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");
        }