static void Main() { bool mono = DetectLinux.MonoDetected(); bool wine = DetectLinux.WineDetected(); bool linux = DetectLinux.NativeLinuxDetected(); Directory.SetCurrentDirectory(Path.GetDirectoryName(Application.ExecutablePath)); if (Self.isTempFolder(Directory.GetCurrentDirectory())) { MessageBox.Show(null, "Please, extract me and my DLL files before executing...", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Stop); Environment.Exit(0); } if (!Directory.Exists("Languages")) { Directory.CreateDirectory("Languages"); } try { File.Delete("Languages/Default.lng"); File.WriteAllText("Languages/Default.lng", ExtractResource.AsString("GameLauncher.Language.Default.lng")); } catch { } try { File.Delete(Directory.GetCurrentDirectory() + "\\tempname.zip"); } catch { } if (!File.Exists("LZMA.dll")) { File.WriteAllBytes("LZMA.dll", ExtractResource.AsByte("GameLauncher.LZMA.LZMA.dll")); } if (!linux && !File.Exists("discord-rpc.dll")) { File.WriteAllBytes("discord-rpc.dll", ExtractResource.AsByte("GameLauncher.Discord.discord-rpc.dll")); } if (linux && !File.Exists("libdiscord-rpc.so")) { File.WriteAllBytes("libdiscord-rpc.so", ExtractResource.AsByte("GameLauncher.Discord.libdiscord-rpc.so")); } if (File.Exists("GameLauncherUpdater.exe")) { File.Delete("GameLauncherUpdater.exe"); } try { File.Delete("GL_Update.exe"); File.WriteAllBytes("GL_Update.exe", ExtractResource.AsByte("GameLauncher.Updater.GL_Update.exe")); } catch { } if (!File.Exists("servers.txt")) { try { File.Create("servers.txt"); } catch { } } if (Debugger.IsAttached) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new mainScreen()); } 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(); } Mutex mutex = new Mutex(false, "GameLauncherNFSW-MeTonaTOR"); try { if (mutex.WaitOne(0, false)) { String[] files = { "Newtonsoft.Json.dll", "INIFileParser.dll", "Microsoft.WindowsAPICodePack.dll", "Microsoft.WindowsAPICodePack.Shell.dll" }; List <string> missingfiles = new List <string>(); foreach (string file in files) { if (!File.Exists(file)) { missingfiles.Add(file); } } if (missingfiles.Count != 0) { string message = "Cannot launch GameLauncher. The following files are missing:\n\n"; foreach (string file in missingfiles) { message += "• " + file + "\n"; } message += "\nCurrent directory: " + Directory.GetCurrentDirectory(); MessageBox.Show(null, message, "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new mainScreen()); } else { MessageBox.Show(null, "An instance of the application is already running.", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error); } } finally { if (mutex != null) { mutex.Close(); mutex = null; } } } }
static void Main() { int SysVersion = (int)Environment.OSVersion.Platform; bool mono = DetectLinux.MonoDetected(); bool wine = DetectLinux.WineDetected(); bool linux = DetectLinux.LinuxDetected(); //Discord fix Directory.SetCurrentDirectory(Path.GetDirectoryName(Application.ExecutablePath)); //Languages if (!File.Exists("Languages")) { Directory.CreateDirectory("Languages"); File.WriteAllText("Languages/Dutch.lng", ExtractResource.AsString("GameLauncher.Languages.Dutch.lng")); File.WriteAllText("Languages/English.lng", ExtractResource.AsString("GameLauncher.Languages.English.lng")); File.WriteAllText("Languages/French.lng", ExtractResource.AsString("GameLauncher.Languages.French.lng")); File.WriteAllText("Languages/German_Formal.lng", ExtractResource.AsString("GameLauncher.Languages.German_Formal.lng")); File.WriteAllText("Languages/German_Informal.lng", ExtractResource.AsString("GameLauncher.Languages.German_Informal.lng")); File.WriteAllText("Languages/Polish.lng", ExtractResource.AsString("GameLauncher.Languages.Polish.lng")); File.WriteAllText("Languages/Portuguese.lng", ExtractResource.AsString("GameLauncher.Languages.Portuguese.lng")); File.WriteAllText("Languages/Spanish.lng", ExtractResource.AsString("GameLauncher.Languages.Spanish.lng")); File.WriteAllText("Languages/Swedish.lng", ExtractResource.AsString("GameLauncher.Languages.Swedish.lng")); } //Remove zip file try { File.Delete(Directory.GetCurrentDirectory() + "\\tempname.zip"); } catch { } //Console log with warning if (mono == true) { MessageBox.Show(null, "Mono support is still under alpha stage. Therefore, launcher could not launch.", "GameLauncher.exe", MessageBoxButtons.OK, MessageBoxIcon.Warning); } //Add LZMA.dll on the fly (used for decompression of section{int}.dll files) if (!File.Exists("LZMA.dll")) { File.WriteAllBytes("LZMA.dll", ExtractResource.AsByte("GameLauncher.LZMA.LZMA.dll")); } //Add GameLauncherUpdater.exe on the fly if (!File.Exists("GameLauncherUpdater.exe")) { File.WriteAllBytes("GameLauncherUpdater.exe", ExtractResource.AsByte("GameLauncher.Updater.GameLauncherUpdater.exe")); } //Detect if NFSW is launched 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(); } Mutex mutex = new Mutex(false, "GameLauncherNFSW-MeTonaTOR"); //Forgot about other launchers... try { if (mutex.WaitOne(0, false)) { //First of all, we need to check if files exists String[] files = { "Newtonsoft.Json.dll", "LZMA.dll", "ICSharpCode.SharpZipLib.dll" }; List <string> missingfiles = new List <string>(); foreach (string file in files) { if (!File.Exists(file)) { missingfiles.Add(file); } } if (missingfiles.Count != 0) { string message = "Cannot launch GameLauncher. The following files are missing:\n\n"; foreach (string file in missingfiles) { message += "• " + file + "\n"; } message += "\nCurrent directory: " + Directory.GetCurrentDirectory(); message += "\nYou will be moved to the project page for re-download."; MessageBox.Show(null, message, "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error); Process.Start(@"https://github.com/SoapboxRaceWorld/GameLauncher_NFSW/releases"); Environment.Exit(1); } if (Environment.OSVersion.Version.Major >= 6) { User32.SetProcessDPIAware(); } //try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new mainScreen()); //} catch(Exception) { //Temporarely we gonna kill it. // Process.GetProcessById(Process.GetCurrentProcess().Id).Kill(); //} } else { MessageBox.Show(null, "An instance of the application is already running.", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error); } } finally { if (mutex != null) { mutex.Close(); mutex = null; } } }
static void Main() { int SysVersion = (int)Environment.OSVersion.Platform; bool mono = DetectLinux.MonoDetected(); bool wine = DetectLinux.WineDetected(); bool linux = DetectLinux.NativeLinuxDetected(); try { } catch { MessageBox.Show("This should fake antivirus :v"); } /*if(Environment.OSVersion.Version.Major <= 5 && !linux) { * MessageBox.Show(null, "Windows XP Support has been terminated. Please upgrade your Operating System to 'Vista' or newer.", "GameLauncher.exe", MessageBoxButtons.OK, MessageBoxIcon.Warning); * Environment.Exit(Environment.ExitCode); * }*/ Directory.SetCurrentDirectory(Path.GetDirectoryName(Application.ExecutablePath)); if (!Directory.Exists("Languages")) { Directory.CreateDirectory("Languages"); } try { File.Delete("Languages/Default.lng"); File.WriteAllText("Languages/Default.lng", ExtractResource.AsString("GameLauncher.Language.Default.lng")); } catch { } try { File.Delete(Directory.GetCurrentDirectory() + "\\tempname.zip"); } catch { } if (linux) { MessageBox.Show(null, "Native Linux support is still under alpha stage. Therefore, launcher or game could crash.", "GameLauncher.exe", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (mono == true) { MessageBox.Show(null, "Mono support is still under alpha stage. Therefore, launcher could not launch.", "GameLauncher.exe", MessageBoxButtons.OK, MessageBoxIcon.Warning); } if (!File.Exists("LZMA.dll")) { File.WriteAllBytes("LZMA.dll", ExtractResource.AsByte("GameLauncher.LZMA.LZMA.dll")); } if (!linux && !File.Exists("discord-rpc.dll")) { File.WriteAllBytes("discord-rpc.dll", ExtractResource.AsByte("GameLauncher.Discord.discord-rpc.dll")); } if (linux && !File.Exists("libdiscord-rpc.so")) { File.WriteAllBytes("libdiscord-rpc.so", ExtractResource.AsByte("GameLauncher.Discord.libdiscord-rpc.so")); } if (File.Exists("GameLauncherUpdater.exe")) { File.Delete("GameLauncherUpdater.exe"); } try { File.Delete("GL_Update.exe"); File.WriteAllBytes("GL_Update.exe", ExtractResource.AsByte("GameLauncher.Updater.GL_Update.exe")); } catch { } if (!File.Exists("servers.txt")) { try { File.Create("servers.txt"); } catch { } } if (Debugger.IsAttached) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new mainScreen()); } 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(); } Mutex mutex = new Mutex(false, "GameLauncherNFSW-MeTonaTOR"); try { if (mutex.WaitOne(0, false)) { String[] files = { "Newtonsoft.Json.dll", "LZMA.dll" }; List <string> missingfiles = new List <string>(); foreach (string file in files) { if (!File.Exists(file)) { missingfiles.Add(file); } } if (missingfiles.Count != 0) { string message = "Cannot launch GameLauncher. The following files are missing:\n\n"; foreach (string file in missingfiles) { message += "• " + file + "\n"; } message += "\nCurrent directory: " + Directory.GetCurrentDirectory(); message += "\nYou will be moved to the project page for re-download."; MessageBox.Show(null, message, "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error); Process.Start(@"https://github.com/SoapboxRaceWorld/GameLauncher_NFSW/releases"); Environment.Exit(1); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new mainScreen()); } else { MessageBox.Show(null, "An instance of the application is already running.", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error); } } finally { if (mutex != null) { mutex.Close(); mutex = null; } } } }
static void Main() { int SysVersion = (int)Environment.OSVersion.Platform; bool mono = DetectLinux.MonoDetected(); bool wine = DetectLinux.WineDetected(); bool linux = DetectLinux.LinuxDetected(); //Remove zip file File.Delete(Directory.GetCurrentDirectory() + "\\tempname.zip"); //Console log with warning if (mono == true) { //It will never work under pure mono... so... Application.Exit(); } else if (wine == true) { MessageBox.Show(null, "Wine support is still under alpha stage. Therefore, launcher could not launch.", "GameLauncher.exe", MessageBoxButtons.OK, MessageBoxIcon.Warning); } //Add LZMA.dll on the fly (used for decompression of section{int}.dll files) if (!File.Exists("LZMA.dll")) { File.WriteAllBytes("LZMA.dll", ExtractResource.AsByte("GameLauncher.LZMA.LZMA.dll")); } //Add GameLauncherUpdater.exe on the fly if (!File.Exists("GameLauncherUpdater.exe")) { File.WriteAllBytes("GameLauncherUpdater.exe", ExtractResource.AsByte("GameLauncher.Updater.GameLauncherUpdater.exe")); } //Detect if NFSW is launched Mutex detectRunningNFSW = new Mutex(false, "Global\\{3E34CEFB-7B34-4e62-8034-33256B8BC2F7}"); try { if (!detectRunningNFSW.WaitOne(0, false)) { MessageBox.Show(null, "An instance of Need for Speed: World is already running", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Environment.Exit(0); } } finally { if (detectRunningNFSW != null) { detectRunningNFSW.Close(); detectRunningNFSW = null; } } Mutex mutex = new Mutex(false, "GameLauncherNFSW-MeTonaTOR"); //Forgot about other launchers... try { if (mutex.WaitOne(0, false)) { //First of all, we need to check if files exists String[] files = { "Microsoft.WindowsAPICodePack.dll", "Microsoft.WindowsAPICodePack.Shell.dll", "Newtonsoft.Json.dll", "LZMA.dll", "ICSharpCode.SharpZipLib.dll" }; List <string> missingfiles = new List <string>(); foreach (string file in files) { if (!File.Exists(file)) { missingfiles.Add(file); } } if (missingfiles.Count != 0) { string message = "Cannot launch GameLauncher. The following files are missing:\n\n"; foreach (string file in missingfiles) { message += "• " + file + "\n"; } message += "\nCurrent directory: " + Directory.GetCurrentDirectory(); message += "\nYou will be moved to the project page for re-download."; MessageBox.Show(null, message, "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error); Process.Start(@"https://github.com/metonator/GameLauncher_NFSW/releases"); Environment.Exit(1); } if (Environment.OSVersion.Version.Major >= 6) { User32.SetProcessDPIAware(); } //try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new mainScreen()); //} catch(Exception ex) { // if(linux == true) { // extraLinuxInfo = "\n\nAditionally, please report that you're using Wine/Mono Runtime and your Linux Distro"; // } // MessageBox.Show(null, "Failed to launch GameLauncher. " + ex.Message + "\n\nStack Trace:\n" + ex.StackTrace + extraLinuxInfo, "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error); // Environment.Exit(1); //} } else { MessageBox.Show(null, "An instance of the application is already running.", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error); } } finally { if (mutex != null) { mutex.Close(); mutex = null; } } }