Ejemplo n.º 1
0
        static void Main()
        {
            CultureInfo.DefaultThreadCurrentCulture     = CultureInfo.GetCultureInfo(InformationCache.Lang.Name);
            CultureInfo.DefaultThreadCurrentUICulture   = CultureInfo.GetCultureInfo(Translations.UI(Translations.Application_Language = InformationCache.Lang.Name));
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            Application.ThreadException += Application_ThreadException;
            Application.EnableVisualStyles();
            /* We need to set these once and Forget about it (Unless there is a bug such as HttpWebClient) */
            AppContext.SetSwitch("Switch.System.Net.DontEnableSchUseStrongCrypto", false);
            AppContext.SetSwitch("Switch.System.Net.DontEnableSystemDefaultTlsVersions", false);
            ServicePointManager.DnsRefreshTimeout = (int)TimeSpan.FromSeconds(30).TotalMilliseconds;
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.ServerCertificateValidationCallback = (Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) =>
            {
                bool isOk = true;
                if (sslPolicyErrors != SslPolicyErrors.None)
                {
                    for (int i = 0; i < chain.ChainStatus.Length; i++)
                    {
                        if (chain.ChainStatus[i].Status == X509ChainStatusFlags.RevocationStatusUnknown)
                        {
                            continue;
                        }
                        chain.ChainPolicy.RevocationFlag      = X509RevocationFlag.EntireChain;
                        chain.ChainPolicy.RevocationMode      = X509RevocationMode.Online;
                        chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 0, 15);
                        chain.ChainPolicy.VerificationFlags   = X509VerificationFlags.AllFlags;
                        bool chainIsValid = chain.Build((X509Certificate2)certificate);
                        if (!chainIsValid)
                        {
                            isOk = false;
                            break;
                        }
                    }
                }
                return(isOk);
            };

            if (Debugger.IsAttached && !NFSW.IsRunning())
            {
                Start();
            }
            else
            {
                if (NFSW.IsRunning())
                {
                    if (NFSW.DetectGameProcess())
                    {
                        MessageBox.Show(null, Translations.Database("Program_TextBox_GameIsRunning"), "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else if (NFSW.DetectGameLauncherSimplified())
                    {
                        MessageBox.Show(null, Translations.Database("Program_TextBox_SimplifiedIsRunning"), "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        MessageBox.Show(null, Translations.Database("Program_TextBox_SBRWIsRunning"), "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }

                    FunctionStatus.LauncherForceClose = true;
                }

                if (FunctionStatus.LauncherForceClose)
                {
                    FunctionStatus.ErrorCloseLauncher("User Tried to Launch SBRW Launcher with one Running Already", false);
                }
                else
                {
                    /* Check if File needs to be Downloaded */
                    string LZMAPath = Strings.Encode(Path.Combine(Locations.LauncherFolder, Locations.NameLZMA));

                    if (File.Exists(LZMAPath))
                    {
                        try
                        {
                            if (new FileInfo(LZMAPath).Length == 0)
                            {
                                File.Delete(LZMAPath);
                            }
                        }
                        catch { }
                    }

                    /* 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
                        {
                            Uri URLCall = new Uri(URLs.File + "/LZMA.dll");
                            ServicePointManager.FindServicePoint(URLCall).ConnectionLeaseTimeout = (int)TimeSpan.FromMinutes(1).TotalMilliseconds;
                            WebClient Client = new WebClient
                            {
                                Encoding = Encoding.UTF8
                            };
                            Client.Headers.Add("user-agent", "SBRW Launcher " +
                                               Application.ProductVersion + " (+https://github.com/SoapBoxRaceWorld/GameLauncher_NFSW)");
                            Client.DownloadFileCompleted += (object sender, AsyncCompletedEventArgs e) =>
                            {
                                if (File.Exists(LZMAPath))
                                {
                                    try
                                    {
                                        if (new FileInfo(LZMAPath).Length == 0)
                                        {
                                            File.Delete(LZMAPath);
                                        }
                                    }
                                    catch { }
                                }
                            };

                            FunctionStatus.LauncherForceClose = true;

                            try
                            {
                                Client.DownloadFile(URLCall, LZMAPath);

                                if (MessageBox.Show(null, Translations.Database("Program_TextBox_LZMA_Redownloaded"),
                                                    "GameLauncher Restart Required",
                                                    MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                                {
                                    LauncherMustRestart = true;
                                }
                            }
                            catch (Exception Error)
                            {
                                FunctionStatus.LauncherForceCloseReason = Error.Message;
                            }
                            finally
                            {
                                if (Client != null)
                                {
                                    Client.Dispose();
                                }
                            }
                        }
                        catch { }
                    }

                    if (FunctionStatus.LauncherForceClose)
                    {
                        FunctionStatus.ErrorCloseLauncher("Closing From Downloaded Missing LZMA", LauncherMustRestart);
                    }
                    else
                    {
                        Mutex No_Java = new Mutex(false, "GameLauncherNFSW-MeTonaTOR");
                        try
                        {
                            if (No_Java.WaitOne(0, false))
                            {
                                if (!UnixOS.Detected())
                                {
                                    /* MONO Hates this... */
                                    string[] File_List =
                                    {
                                        "CommandLine.dll - 2.8.0",
                                        "DiscordRPC.dll - 1.0.175.0",
                                        "Flurl.dll - 3.0.2",
                                        "Flurl.Http.dll - 3.2.0",
                                        "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 - 13.0.1",
                                        "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 - 2.1.4.81"
                                    };

                                    List <string> Missing_File_List = new List <string>();

                                    foreach (string File_String in File_List)
                                    {
                                        string[] Split_File_Version = File_String.Split(new string[] { " - " }, StringSplitOptions.None);

                                        if (!File.Exists(Path.Combine(Directory.GetCurrentDirectory(), Split_File_Version[0])))
                                        {
                                            Missing_File_List.Add(Split_File_Version[0] + " - " + Translations.Database("Program_TextBox_File_NotFound"));
                                        }
                                        else
                                        {
                                            try
                                            {
                                                FileVersionInfo Version_Info  = FileVersionInfo.GetVersionInfo(Split_File_Version[0]);
                                                string[]        Version_Split = Version_Info.ProductVersion.Split('+');
                                                string          File_Version  = Version_Split[0];

                                                if (File_Version == "")
                                                {
                                                    Missing_File_List.Add(Split_File_Version[0] + " - " + Translations.Database("Program_TextBox_File_Invalid"));
                                                }
                                                else
                                                {
                                                    if (!HardwareInfo.CheckArchitectureFile(Split_File_Version[0]))
                                                    {
                                                        Missing_File_List.Add(Split_File_Version[0] + " - " + Translations.Database("Program_TextBox_File_Invalid_CPU"));
                                                    }
                                                    else
                                                    {
                                                        if (File_Version != Split_File_Version[1])
                                                        {
                                                            Missing_File_List.Add(Split_File_Version[0] + " - " + Translations.Database("Program_TextBox_File_Invalid_Version") +
                                                                                  "(" + Split_File_Version[1] + " != " + File_Version + ")");
                                                        }
                                                    }
                                                }
                                            }
                                            catch
                                            {
                                                Missing_File_List.Add(Split_File_Version[0] + " - " + Translations.Database("Program_TextBox_File_Invalid"));
                                            }
                                        }
                                    }

                                    if (Missing_File_List.Count != 0)
                                    {
                                        string Message_Display = Translations.Database("Program_TextBox_File_Invalid_Start");

                                        foreach (string File_String in Missing_File_List)
                                        {
                                            Message_Display += "• " + File_String + "\n";
                                        }

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

                                if (FunctionStatus.LauncherForceClose)
                                {
                                    FunctionStatus.ErrorCloseLauncher("Closing From Missing .dll Files Check", LauncherMustRestart);
                                }
                                else
                                {
                                    Start();
                                }
                            }
                            else
                            {
                                MessageBox.Show(null, Translations.Database("Program_TextBox_SBRWIsRunning"),
                                                "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                        finally
                        {
                            No_Java.Close();
                            No_Java.Dispose();
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (NFSW.IsNFSWRunning())
            {
                if (NFSW.DetectGameProcess())
                {
                    MessageBox.Show(null, "An instance of Need for Speed: World is already running", UserAgent.AgentAltName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    MessageBox.Show(null, "An instance of SBRW Launcher is already running.", UserAgent.AgentAltName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                Process.GetProcessById(Process.GetCurrentProcess().Id).Kill();
            }
            else
            {
                var mutex = new Mutex(false, UserAgent.AgentName);
                try
                {
                    if (mutex.WaitOne(0, false))
                    {
                        if (!File.Exists("nfsw.exe"))
                        {
                            MessageBox.Show("nfsw.exe not found! Please put this launcher in the game directory. " +
                                            "If you don't have the game installed, Use the Vanilla Launcher to install it (visit https://soapboxrace.world/)",
                                            UserAgent.AgentAltName, MessageBoxButtons.OK, MessageBoxIcon.Error);

                            Process.GetProcessById(Process.GetCurrentProcess().Id).Kill();
                        }
                        else
                        {
                            if (!canAccesGameData())
                            {
                                MessageBox.Show("This application requires admin priviledge. Restarting...");
                                runAsAdmin();
                                return;
                            }

                            if (SHA.HashFile("nfsw.exe") != "7C0D6EE08EB1EDA67D5E5087DDA3762182CDE4AC")
                            {
                                MessageBox.Show("Invalid file was detected, please restore original nfsw.exe", UserAgent.AgentAltName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            else
                            {
                                if (File.Exists(".links"))
                                {
                                    var linksPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "\\.links");
                                    ModNetLinksCleanup.CleanLinks(linksPath);
                                }

                                ServicePointManager.Expect100Continue = true;
                                ServicePointManager.SecurityProtocol |= SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

                                ServerListUpdater.GetList();

                                Application.Run(new Form1());
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show(null, "An instance of Launcher is already running.", UserAgent.AgentAltName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                finally
                {
                    mutex.Close();
                }
            }
        }