/// <summary> /// Executes the specified delegate on the thread that owns the control's underlying window handle. /// </summary> /// <returns>The delegate being invoked has no return value.</returns> /// <param name="Control_Form">Name of the Control</param> /// <param name="Action_Refresh">Parameters to be set for this Control</param> /// <param name="Window_Name">Name of the Parent Form</param> static public void SafeInvokeAction(this Control Control_Form, Action Action_Refresh, Form Window_Name) { try { if (!string.IsNullOrWhiteSpace(Window_Name.Name)) { if (!(Application.OpenForms[Window_Name.Name] != null ? Application.OpenForms[Window_Name.Name].Disposing : true) && !Application.OpenForms[Window_Name.Name].IsDisposed) { if (!Control_Form.IsDisposed || (Control_Form.IsHandleCreated && Control_Form.FindForm().IsHandleCreated)) { if (!Control_Form.Disposing) { if (Control_Form.InvokeRequired) { Control_Form.Invoke(Action_Refresh); } else { Action_Refresh(); } } else { Log.Function("SafeInvokeAction".ToUpper() + "Control: " + Control_Form.Name + " is being Disposed"); } } else if (!Application.OpenForms[Window_Name.Name].IsDisposed) { Window_Name.Controls.Add(Control_Form); SafeInvokeAction(Control_Form, Action_Refresh); Log.Function("SafeInvokeAction: ".ToUpper() + "Control: " + Control_Form.Name + " was added to the Form: " + Window_Name.Name); } else if (EnableInsiderDeveloper.Allowed() || EnableInsiderBetaTester.Allowed()) { Log.Function("SafeInvokeAction: ".ToUpper() + "Control: " + Control_Form + " <- Handle hasn't been Created or has been Disposed | Action: " + Action_Refresh + " Form: " + Window_Name); } } } else if (EnableInsiderDeveloper.Allowed() || EnableInsiderBetaTester.Allowed()) { Log.Function("SafeInvokeAction: ".ToUpper() + "Control: " + Control_Form + " Action: " + Action_Refresh + " Form: " + Window_Name + " <- Is Null"); } } catch (Exception Error) { LogToFileAddons.OpenLog("Safe Invoker Action", null, Error, null, true); } }
public static string Database(string Text_Request) { if (EnableInsiderDeveloper.Allowed() || EnableInsiderBetaTester.Allowed()) { Log.Function("DATABASE: Requested: " + Text_Request + " Lang: " + Application_Language); } try { if (Lang_Launcher == null || ResetCache) { switch (UI(Application_Language)) { default: Lang_Launcher = new ResourceManager("GameLauncher.App.Languages.English_Texts", Assembly.GetExecutingAssembly()); break; } ResetCache = false; } try { if (!string.IsNullOrWhiteSpace(Text_Request) && Lang_Launcher != null) { return(Regex.Unescape(Lang_Launcher.GetString(Text_Request))); } else { return("Languages Programer ERROR"); } } catch (Exception Error) { LogToFileAddons.OpenLog("Translations Database Selection", null, Error, null, true); return("Languages Program ERROR"); } } catch (Exception Error) { LogToFileAddons.OpenLog("Translations Database", null, Error, null, true); return("Languages ERROR"); } }
public UpdatePopup() { DiscordLauncherPresence.Status("Start Up", "New Version Is Available: " + LauncherUpdateCheck.LatestLauncherBuild); InitializeComponent(); SetVisuals(); if (VisualsAPIChecker.GitHubAPI) { try { ChangelogText.Text = (EnableInsiderDeveloper.Allowed() || EnableInsiderBetaTester.Allowed()) ? JsonConvert.DeserializeObject <List <GitHubRelease> >(LauncherUpdateCheck.VersionJSON)[0].Body.Replace("\r", Environment.NewLine) : JsonConvert.DeserializeObject <GitHubRelease>(LauncherUpdateCheck.VersionJSON).Body.Replace("\r", Environment.NewLine); } catch (Exception Error) { LogToFileAddons.OpenLog("Update Popup", null, Error, null, true); ChangelogText.Text = "\n" + Error.Message; ChangelogBox.Text = "Changelog Error:"; } } else { ChangelogText.Text = "\nUnable to Retrieve Changelog"; ChangelogBox.Text = "Changelog Error:"; } ChangelogText.Select(0, 0); ChangelogText.SelectionLength = 0; ChangelogText.TabStop = false; Bitmap bitmap1 = Bitmap.FromHicon(SystemIcons.Information.Handle); UpdateIcon.Image = bitmap1; UpdateText.Text = "An update is available. Would you like to update?\nYour version: " + Application.ProductVersion + "\nUpdated version: " + LauncherUpdateCheck.LatestLauncherBuild; this.UpdateButton.DialogResult = DialogResult.OK; this.IgnoreButton.DialogResult = DialogResult.Cancel; this.SkipButton.DialogResult = DialogResult.Ignore; }
/// <summary> /// Executes the specified delegate on the thread that owns the control's underlying window handle. /// </summary> /// <returns>The delegate being invoked has no return value.</returns> /// <param name="Control_Form">Name of the Control</param> /// <param name="Action_Refresh">Parameters to be set for this Control</param> static public void SafeInvokeAction(this Control Control_Form, Action Action_Refresh) { try { if (!string.IsNullOrWhiteSpace(Control_Form.Name)) { if (!Control_Form.IsDisposed || (Control_Form.IsHandleCreated && Control_Form.FindForm().IsHandleCreated)) { if (Control_Form.InvokeRequired) { Control_Form.Invoke(Action_Refresh); } else { Action_Refresh(); } } else if (!Control_Form.FindForm().IsDisposed) { Control_Form.FindForm().Controls.Add(Control_Form); SafeInvokeAction(Control_Form, Action_Refresh); Log.Function("SafeInvokeAction: ".ToUpper() + "Control: " + Control_Form.Name + " was added to the Form: " + Control_Form.FindForm().Name); } else if (EnableInsiderDeveloper.Allowed() || EnableInsiderBetaTester.Allowed()) { Log.Function("SafeInvokeAction: ".ToUpper() + "Control: " + Control_Form + " <- Handle hasn't been Created or has been Disposed | Action: " + Action_Refresh); } } else if (EnableInsiderDeveloper.Allowed() || EnableInsiderBetaTester.Allowed()) { Log.Function("SafeInvokeAction: ".ToUpper() + "Control: " + Control_Form + " <- Is Null | Action: " + Action_Refresh); } } catch (Exception Error) { LogToFileAddons.OpenLog("Safe Invoker Action [Control Only]", null, Error, null, true); } }
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(); } } }
public static void Latest() { Log.Checking("LAUNCHER UPDATE: Is Version Up to Date or not"); DiscordLauncherPresence.Status("Start Up", "Checking Latest Launcher Release Information"); try { Uri URLCall = new Uri((EnableInsiderBetaTester.Allowed() || EnableInsiderDeveloper.Allowed()) ? URLs.GitHub_Launcher_Beta : URLs.GitHub_Launcher_Stable); ServicePointManager.FindServicePoint(URLCall).ConnectionLeaseTimeout = (int)TimeSpan.FromMinutes(1).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 + " (+https://github.com/SoapBoxRaceWorld/GameLauncher_NFSW)"); } try { VersionJSON = Client.DownloadString(URLCall); VisualsAPIChecker.GitHubAPI = true; } catch (WebException Error) { APIChecker.StatusCodes(URLCall.GetComponents(UriComponents.HttpRequestUrl, UriFormat.SafeUnescaped), Error, (HttpWebResponse)Error.Response); } catch (Exception Error) { LogToFileAddons.OpenLog("LAUNCHER UPDATE [GITHUB]", null, Error, null, true); } finally { if (Client != null) { Client.Dispose(); } } if (IsJSONValid.ValidJson(VersionJSON) && VisualsAPIChecker.GitHubAPI) { LatestLauncherBuild = (EnableInsiderDeveloper.Allowed() || EnableInsiderBetaTester.Allowed()) ? JsonConvert.DeserializeObject <List <GitHubRelease> >(VersionJSON)[0].TagName : JsonConvert.DeserializeObject <GitHubRelease>(VersionJSON).TagName; Log.Info("LAUNCHER UPDATE: GitHub Latest Version -> " + LatestLauncherBuild); ValidJSONDownload = true; } else { Log.Error("LAUNCHER UPDATE: Failed to retrieve Latest Build information from GitHub"); ValidJSONDownload = false; } } catch (Exception Error) { LogToFileAddons.OpenLog("LAUNCHER UPDATE [GITHUB]", null, Error, null, true); } Log.Completed("LAUNCHER UPDATE: Done"); if (!UpdateStatusResult()) { Log.Info("FIRST TIME RUN: Moved to Function"); /* Do First Time Run Checks */ FunctionStatus.FirstTimeRun(); } else { if (DiscordLauncherPresence.Running()) { DiscordLauncherPresence.Stop("Close"); } if (ServerProxy.Running()) { ServerProxy.Instance.Stop("Force Close"); } Application.Exit(); } }
public void ChangeVisualStatus() { if (!string.IsNullOrWhiteSpace(LatestLauncherBuild)) { if (Revisions > 0) { string WhatBuildAmI; if (EnableInsiderDeveloper.Allowed()) { WhatBuildAmI = Translations.Database("LauncherUpdateCheck_VS_Insider_Dev"); } else if (EnableInsiderBetaTester.Allowed()) { WhatBuildAmI = Translations.Database("LauncherUpdateCheck_VS_Insider_Beta"); } else { WhatBuildAmI = Translations.Database("LauncherUpdateCheck_VS_Insider_Unofficial"); } text.Text = Translations.Database("LauncherUpdateCheck_VS_Insider") + "\n - " + WhatBuildAmI + " " + Translations.Database("LauncherUpdateCheck_VS_Insider_Text_Build"); status.BackgroundImage = Theming.UpdateIconWarning; text.ForeColor = Theming.Warning; description.Text = Translations.Database("LauncherUpdateCheck_VS_Insider_Text_Stable") + " " + LatestLauncherBuild + "\n" + Translations.Database("LauncherUpdateCheck_VS_Insider_Text_Current") + " " + Application.ProductVersion; if (!string.IsNullOrWhiteSpace(FileSettingsSave.IgnoreVersion)) { FileSettingsSave.IgnoreVersion = String.Empty; FileSettingsSave.SaveSettings(); Log.Info("IGNOREUPDATEVERSION: Cleared OLD IgnoreUpdateVersion Build Number. " + "You are currenly using a " + WhatBuildAmI + " Build!"); } } else if (Revisions == 0) { text.Text = Translations.Database("LauncherUpdateCheck_VS_Text_No_Update"); status.BackgroundImage = Theming.UpdateIconSuccess; text.ForeColor = Theming.Sucess; description.Text = Translations.Database("LauncherUpdateCheck_VS_Text_Version") + " " + Application.ProductVersion; if (FileSettingsSave.IgnoreVersion == Application.ProductVersion) { FileSettingsSave.IgnoreVersion = String.Empty; FileSettingsSave.SaveSettings(); Log.Info("IGNOREUPDATEVERSION: Cleared OLD IgnoreUpdateVersion Build Number. You're now on the Latest Game Launcher!"); } } else { text.Text = Translations.Database("LauncherUpdateCheck_VS_Text_Update"); status.BackgroundImage = Theming.UpdateIconWarning; text.ForeColor = Theming.Warning; description.Text = Translations.Database("LauncherUpdateCheck_VS_Text_Update_New") + " " + LatestLauncherBuild + "\n" + Translations.Database("LauncherUpdateCheck_VS_Insider_Text_Current") + " " + Application.ProductVersion; UpgradeAvailable = true; if (SkipAvailableUpgrade) { FileSettingsSave.IgnoreVersion = LatestLauncherBuild; FileSettingsSave.SaveSettings(); Log.Info("IGNOREUPDATEVERSION: User had skipped latest Launcher Version!"); } } } else if (VisualsAPIChecker.GitHubAPI && !ValidJSONDownload) { text.Text = Translations.Database("LauncherUpdateCheck_VS_Text_Invalid_JSON"); status.BackgroundImage = Theming.UpdateIconError; text.ForeColor = Theming.Error; description.Text = Translations.Database("LauncherUpdateCheck_VS_Text_Version") + " " + Application.ProductVersion; } else { text.Text = Translations.Database("LauncherUpdateCheck_VS_Text_Invalid_Error"); status.BackgroundImage = Theming.UpdateIconUnknown; text.ForeColor = Theming.ThirdTextForeColor; description.Text = Translations.Database("LauncherUpdateCheck_VS_Text_Version") + " " + Application.ProductVersion; } }
private static bool UpdateStatusResult() { bool StatusUpdate = false; if (!string.IsNullOrWhiteSpace(LatestLauncherBuild)) { Revisions = CurrentLauncherBuild.CompareTo(LatestLauncherBuild); if (Revisions < 0) { Log.Info("LAUNCHER POPUP: Checking if Popup is Required"); if (FileSettingsSave.IgnoreVersion != LatestLauncherBuild) { FunctionStatus.LoadingComplete = true; SplashScreen.ThreadStatus("Stop"); UpdatePopupStoppedSplashScreen = true; DialogResult UserResult = new UpdatePopup().ShowDialog(); if (UserResult == DialogResult.OK) { StatusUpdate = true; string UpdaterPath = Strings.Encode(Path.Combine(Locations.LauncherFolder, Locations.NameUpdater)); if (File.Exists(UpdaterPath)) { Process.Start(UpdaterPath, Process.GetCurrentProcess().Id.ToString() + " " + (EnableInsiderBetaTester.Allowed() || EnableInsiderDeveloper.Allowed() ? "Preview" : "Stable")); } else { Process.Start(@"https://github.com/SoapboxRaceWorld/GameLauncher_NFSW/releases/latest"); MessageBox.Show(null, Translations.Database("LauncherUpdateCheck_FS"), "GameLauncher", MessageBoxButtons.OK); } } else if (UserResult == DialogResult.Ignore) { /* Save and Allow Version Update Skip Once user Reaches Main Screen */ SkipAvailableUpgrade = true; } } else { Log.Completed("LAUNCHER POPUP: User Saved Skip Version Detected"); } } else { Log.Completed("LAUNCHER POPUP: Update to Date"); } } else { Log.Completed("LAUNCHER POPUP: Unable to run Update Popup (Null String)"); } if (VersionJSON != null) { VersionJSON = null; } return(StatusUpdate); }
/// <summary>Creates all the NullSafe Values for Settings.ini</summary> public static void NullSafeSettings() { /* Pervent Removal of Login Info Before Main Screen (Temporary Boolean) */ FileAccountSave.SaveLoginInformation = true; /* Migrate old Key Entries */ if (settingFile.KeyExists("Server")) { FileAccountSave.ChoosenGameServer = settingFile.Read("Server"); settingFile.DeleteKey("Server"); FileAccountSave.SaveAccount(); } if (settingFile.KeyExists("AccountEmail")) { FileAccountSave.UserRawEmail = settingFile.Read("AccountEmail"); settingFile.DeleteKey("AccountEmail"); FileAccountSave.SaveAccount(); } if (settingFile.KeyExists("Password")) { FileAccountSave.UserHashedPassword = settingFile.Read("Password"); settingFile.DeleteKey("Password"); FileAccountSave.SaveAccount(); } /* Reset This Value as its now Safe to Do So */ FileAccountSave.SaveLoginInformation = false; if (settingFile.KeyExists("Firewall")) { FirewallLauncherStatus = settingFile.Read("Firewall"); FirewallGameStatus = FirewallLauncherStatus; settingFile.DeleteKey("Firewall"); } if (settingFile.KeyExists("WindowsDefender")) { DefenderLauncherStatus = settingFile.Read("WindowsDefender"); DefenderGameStatus = DefenderLauncherStatus; settingFile.DeleteKey("WindowsDefender"); } /* Check if any Entries are missing */ if (UnixOS.Detected() && !settingFile.KeyExists("InstallationDirectory")) { settingFile.Write("InstallationDirectory", "GameFiles"); } else if (!settingFile.KeyExists("InstallationDirectory")) { settingFile.Write("InstallationDirectory", GameInstallation); } if (UnixOS.Detected() && settingFile.KeyExists("OldInstallationDirectory")) { settingFile.DeleteKey("OldInstallationDirectory"); } else if (!UnixOS.Detected() && !settingFile.KeyExists("OldInstallationDirectory")) { settingFile.Write("OldInstallationDirectory", GameInstallationOld); } if (!settingFile.KeyExists("CDN")) { settingFile.Write("CDN", CDN); } else if (settingFile.KeyExists("CDN")) { if (CDN.EndsWith("/")) { char[] charsToTrim = { '/' }; string FinalCDNURL = CDN.TrimEnd(charsToTrim); settingFile.Write("CDN", FinalCDNURL); } } if (!settingFile.KeyExists("Language")) { settingFile.Write("Language", Lang); } if (!settingFile.KeyExists("DisableProxy")) { settingFile.Write("DisableProxy", Proxy); } if (!settingFile.KeyExists("DisableRPC")) { settingFile.Write("DisableRPC", RPC); } if (!settingFile.KeyExists("IgnoreUpdateVersion")) { settingFile.Write("IgnoreUpdateVersion", IgnoreVersion); } if (!settingFile.KeyExists("FilePermission") && !UnixOS.Detected()) { settingFile.Write("FilePermission", FilePermissionStatus); } else if (settingFile.KeyExists("FilePermission") && UnixOS.Detected()) { settingFile.DeleteKey("FilePermission"); } if (!settingFile.KeyExists("GameIntegrity")) { settingFile.Write("GameIntegrity", GameIntegrity); } if (!settingFile.KeyExists("ProxyPort")) { settingFile.Write("ProxyPort", string.Empty); } if (!settingFile.KeyExists("WebCallMethod")) { settingFile.Write("WebCallMethod", WebCallMethod); } if (!settingFile.KeyExists("ThemeSupport")) { settingFile.Write("ThemeSupport", ThemeSupport); } if (!settingFile.KeyExists("StreamingSupport")) { settingFile.Write("StreamingSupport", StreamingSupport); } if (!settingFile.KeyExists("Insider")) { settingFile.Write("Insider", Insider); } else if (settingFile.KeyExists("Insider") && !EnableInsiderBetaTester.Allowed()) { Log.Core("Insider Status: ".ToUpper() + "Opted Into the Beta Preview -> " + EnableInsiderBetaTester.Allowed(Insider == "1")); } if (!UnixOS.Detected()) { if (!settingFile.KeyExists("FirewallLauncher")) { settingFile.Write("FirewallLauncher", FirewallLauncherStatus); } if (!settingFile.KeyExists("FirewallGame")) { settingFile.Write("FirewallGame", FirewallGameStatus); } if (WindowsProductVersion.GetWindowsNumber() >= 10.0) { if (!settingFile.KeyExists("DefenderLauncher")) { settingFile.Write("DefenderLauncher", DefenderLauncherStatus); } if (!settingFile.KeyExists("DefenderGame")) { settingFile.Write("DefenderGame", DefenderGameStatus); } } else if (WindowsProductVersion.GetWindowsNumber() < 10.0) { if (settingFile.KeyExists("DefenderLauncher") || !string.IsNullOrWhiteSpace(settingFile.Read("DefenderLauncher"))) { settingFile.DeleteKey("DefenderLauncher"); } if (settingFile.KeyExists("DefenderGame") || !string.IsNullOrWhiteSpace(settingFile.Read("DefenderGame"))) { settingFile.DeleteKey("DefenderGame"); } } if (WindowsProductVersion.GetWindowsNumber() == 6.1 && !settingFile.KeyExists("PatchesApplied")) { settingFile.Write("PatchesApplied", Win7UpdatePatches); } else if ((UnixOS.Detected() || WindowsProductVersion.GetWindowsNumber() != 6.1) && settingFile.KeyExists("PatchesApplied")) { settingFile.DeleteKey("PatchesApplied"); } } /* Key Entries to Convert into Boolens */ /** Proxy Port Number **/ bool UsingCustomProxyPort = false; if (!string.IsNullOrWhiteSpace(settingFile.Read("ProxyPort"))) { bool isNumeric = int.TryParse(settingFile.Read("ProxyPort"), out int Port); if (isNumeric) { if (Port > 0) { ServerProxy.ProxyPort = Port; UsingCustomProxyPort = true; Log.Info("SETTINGS FILE: Custom Proxy Port -> " + Port); } } } if (!UsingCustomProxyPort) { bool isNumeric = int.TryParse(DateTime.Now.Year.ToString(), out int Port); if (isNumeric) { ServerProxy.ProxyPort = new Random().Next(2017, Port); } else { ServerProxy.ProxyPort = new Random().Next(2017, 2021); } Log.Info("SETTINGS FILE: Random Generated Default Port -> " + ServerProxy.ProxyPort); } if (!string.IsNullOrWhiteSpace(WebCallMethod)) { Log.Info("SETTINGS FILE: Choosen WebCall Method -> " + WebCallMethod); } /* Key Entries to Remove (No Longer Needed) */ if (settingFile.KeyExists("LauncherPosX")) { settingFile.DeleteKey("LauncherPosX"); } if (settingFile.KeyExists("LauncherPosY")) { settingFile.DeleteKey("LauncherPosY"); } if (settingFile.KeyExists("DisableVerifyHash")) { settingFile.DeleteKey("DisableVerifyHash"); } if (settingFile.KeyExists("TracksHigh")) { settingFile.DeleteKey("TracksHigh"); } if (settingFile.KeyExists("ModNetDisabled")) { settingFile.DeleteKey("ModNetDisabled"); } if (settingFile.KeyExists("ModNetZip")) { settingFile.DeleteKey("ModNetZip"); } settingFile = new IniFile("Settings.ini"); }
public static string NodeReader(XmlDocument LocationData, string Type, string FullNodePath, string AttributeName) { try { if (EnableInsiderDeveloper.Allowed() || EnableInsiderBetaTester.Allowed()) { Log.Info("XMLSERVERCORE: Attmempting to Read XML [NodePath: '" + FullNodePath + "' Attribute: '" + AttributeName + "']"); } if (Type == "InnerText") { if (string.IsNullOrWhiteSpace(LocationData.SelectSingleNode(FullNodePath) != null ? LocationData.SelectSingleNode(FullNodePath).InnerText : string.Empty)) { if (EnableInsiderDeveloper.Allowed() || EnableInsiderBetaTester.Allowed()) { Log.Info("XMLSERVERCORE: EMPTY VALUE - LAUNCHER"); } return("EMPTY VALUE - LAUNCHER"); } return(LocationData.SelectSingleNode(FullNodePath).InnerText); } else if (Type == "NodeOnly") { if ((LocationData.SelectSingleNode(FullNodePath) ?? null) == null) { if (EnableInsiderDeveloper.Allowed() || EnableInsiderBetaTester.Allowed()) { Log.Info("XMLSERVERCORE: INVALID NODE - LAUNCHER"); } return("INVALID NODE - LAUNCHER"); } return("VAILD NODE - LAUNCHER"); } else { return("UNKNOWN TYPE - LAUNCHER"); } } catch (Exception Error) { if (EnableInsiderDeveloper.Allowed() || EnableInsiderBetaTester.Allowed()) { Log.Error("XMLSERVERCORE: Unable to Read XML [NodePath: '" + FullNodePath + "' Attribute: '" + AttributeName + "']" + Error.Message); Log.ErrorIC("XMLSERVERCORE: " + Error.HResult); Log.ErrorFR("XMLSERVERCORE: " + Error.ToString()); } if (Type == "InnerText") { if (EnableInsiderDeveloper.Allowed() || EnableInsiderBetaTester.Allowed()) { Log.Error("XMLSERVERCORE: ERROR VALUE - LAUNCHER"); } return("ERROR VALUE - LAUNCHER"); } else if (Type == "NodeOnly") { if (EnableInsiderDeveloper.Allowed() || EnableInsiderBetaTester.Allowed()) { Log.Error("XMLSERVERCORE: ERROR NODE - LAUNCHER"); } return("ERROR NODE - LAUNCHER"); } else { return("ERROR UNKNOWN TYPE - LAUNCHER"); } } }
public static void CleanLinks(string LinksFile, string GamePath) { try { if (File.Exists(LinksFile)) { Log.Info("CLEANLINKS: Found Server Mod Files to remove {Process}"); string dir = Strings.Encode(GamePath); string linksPath = Strings.Encode(Path.Combine(GamePath, ".links")); foreach (var readLine in File.ReadLines(linksPath)) { var parts = readLine.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length != 2) { continue; } string loc = parts[0]; int type = int.Parse(parts[1]); string realLoc = Path.Combine(dir, loc); if (type == 0) { string origPath = realLoc + ".orig"; if (IsSymbolic(realLoc) && File.Exists(realLoc)) { File.Delete(realLoc); if (EnableInsiderDeveloper.Allowed() || EnableInsiderBetaTester.Allowed()) { Log.Info("CLEANLINKS: Removed Symbolic File " + realLoc); } continue; } else if (!File.Exists(realLoc)) { FileErrors++; if (!File.Exists(origPath)) { Log.Warning("CLEANLINKS: .links file includes nonexistent file, but there is no .orig file: [" + realLoc + "] Skipping File"); continue; } else if (File.Exists(origPath)) { Log.Error("CLEANLINKS: Found .orig file that should not be present. Deleting File: " + origPath); File.Delete(origPath); continue; } else { Log.Error("CLEANLINKS: .links file includes nonexistent file. Skipping File: " + realLoc); continue; } } else if (!File.Exists(origPath)) { if (File.Exists(realLoc)) { File.Delete(realLoc); } continue; } try { if (File.Exists(realLoc)) { File.Delete(realLoc); } File.Move(origPath, realLoc); } catch (Exception Error) { FileErrors++; Log.Error("CLEANLINKS: Error while deleting a file: {realLoc}"); LogToFileAddons.OpenLog("CLEANLINKS", null, Error, null, true); } } else { if (IsSymbolic(realLoc) && Directory.Exists(realLoc)) { Directory.Delete(realLoc, true); if (EnableInsiderDeveloper.Allowed() || EnableInsiderBetaTester.Allowed()) { Log.Info("CLEANLINKS: Removed Symbolic Folder " + realLoc); } continue; } else if (!Directory.Exists(realLoc)) { FileErrors++; Log.Error("CLEANLINKS: .links file includes nonexistent directory. Skipping Directory: " + realLoc); continue; } if (Directory.Exists(realLoc)) { Directory.Delete(realLoc, true); } } } if (FileErrors > 0) { FileSettingsSave.GameIntegrity = "Bad"; FileSettingsSave.SaveSettings(); FileErrors = 0; } File.Delete(linksPath); } } catch (Exception Error) { LogToFileAddons.OpenLog("CLEANLINKS", null, Error, null, true); } }