static void Main(string[] p_strArgs) { Mutex mtxAppRunningMutex = null; try { mtxAppRunningMutex = new Mutex(false, "Global\\6af12c54-643b-4752-87d0-8335503010de"); bool booTrace = false; foreach (string strArg in p_strArgs) { if (strArg.ToLower().Equals("/trace") || strArg.ToLower().Equals("-trace")) { booTrace = true; break; } } foreach (string strArg in p_strArgs) { string[] strArgParts = strArg.Split('='); if (strArgParts[0].ToLower().Equals("/u") || strArgParts[0].ToLower().Equals("-u")) { string strGuid = strArgParts[1]; string strPath = Environment.GetFolderPath(Environment.SpecialFolder.System); ProcessStartInfo psiInfo = new ProcessStartInfo(strPath + @"\msiexec.exe", "/x " + strGuid); Process.Start(psiInfo); return; } } #if DEBUG Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, true); #else Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, false); #endif Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); UpgradeSettings(Properties.Settings.Default); EnvironmentInfo = new EnvironmentInfo(Properties.Settings.Default); if (!Directory.Exists(EnvironmentInfo.ApplicationPersonalDataFolderPath)) { Directory.CreateDirectory(EnvironmentInfo.ApplicationPersonalDataFolderPath); } EnableTracing(EnvironmentInfo, booTrace); #if !DEBUG try { #endif Bootstrapper btsInitializer = new Bootstrapper(EnvironmentInfo); try { btsInitializer.RunMainForm(p_strArgs); } catch (MissingMethodException e) { if (MessageBox.Show("You're running an older version of the .Net Framework!" + Environment.NewLine + "Please download .Net Framework 4.6 from the Microsoft website or using Windows Update." + Environment.NewLine + Environment.NewLine + "Click YES if you want Nexus Mod Manager to automatically take you to the download page on your default browser." + Environment.NewLine + "Click NO if you want to close the program and download it later.", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { Process.Start("https://www.microsoft.com/en-us/download/details.aspx?id=48137"); } Application.Exit(); } #if !DEBUG } catch (Exception e) { HandleException(e); } #endif Trace.TraceInformation(String.Format("Running Threads ({0})", TrackedThreadManager.Threads.Length)); Trace.Indent(); TrackedThread[] thdThreads = TrackedThreadManager.Threads; foreach (TrackedThread thdThread in thdThreads) { Trace.TraceInformation(String.Format("{0} ({1}) ", thdThread.Thread.ManagedThreadId, thdThread.Thread.Name)); Trace.Indent(); if (thdThread.Thread.IsAlive) { Trace.TraceInformation("Aborted"); thdThread.Thread.Abort(); } else { Trace.TraceInformation("Ended Cleanly"); } Trace.Unindent(); } Trace.Unindent(); } catch (ConfigurationErrorsException e) { var userChoice = MessageBox.Show("It seems your Nexus Mod Manager application settings file has been corrupted, we can reset this file for you.\n\n" + "Yes: Will reset your NMM related settings (scanned game locations, mod storage path, etc.) but will not remove your installed mods.\n\n" + "No: Your settings will remain corrupted and NMM will crash when trying to start.", "Settings file corrupted", MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); if (userChoice == DialogResult.Yes) { var filename = e.Filename; if (string.IsNullOrEmpty(filename) && e.InnerException.GetType() == typeof(ConfigurationErrorsException)) { var inner = e.InnerException as ConfigurationErrorsException; filename = inner.Filename; } try { File.Delete(filename); MessageBox.Show("We've deleted your corrupted settings file, please restart Nexus Mod Manager.", "Settings reset", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); } catch { MessageBox.Show("Something went wrong when trying to delete the settings file \"" + filename + "\".", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("Nothing has been done, Nexus Mod Manager will now shut down.", "Settings unchanged", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); } } finally { if (mtxAppRunningMutex != null) { mtxAppRunningMutex.Close(); } } }
static void Main(string[] p_strArgs) { Mutex mtxAppRunningMutex = null; try { mtxAppRunningMutex = new Mutex(false, "Global\\6af12c54-643b-4752-87d0-8335503010de"); bool booTrace = false; foreach (string strArg in p_strArgs) if (strArg.ToLower().Equals("/trace") || strArg.ToLower().Equals("-trace")) { booTrace = true; break; } foreach (string strArg in p_strArgs) { string[] strArgParts = strArg.Split('='); if (strArgParts[0].ToLower().Equals("/u") || strArgParts[0].ToLower().Equals("-u")) { string strGuid = strArgParts[1]; string strPath = Environment.GetFolderPath(Environment.SpecialFolder.System); ProcessStartInfo psiInfo = new ProcessStartInfo(strPath + @"\msiexec.exe", "/x " + strGuid); Process.Start(psiInfo); return; } } #if DEBUG Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, true); #else Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, false); #endif Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); UpgradeSettings(Properties.Settings.Default); EnvironmentInfo = new EnvironmentInfo(Properties.Settings.Default); if (!Directory.Exists(EnvironmentInfo.ApplicationPersonalDataFolderPath)) Directory.CreateDirectory(EnvironmentInfo.ApplicationPersonalDataFolderPath); EnableTracing(EnvironmentInfo, booTrace); #if !DEBUG try { #endif Bootstrapper btsInitializer = new Bootstrapper(EnvironmentInfo); btsInitializer.RunMainForm(p_strArgs); #if !DEBUG } catch (Exception e) { HandleException(e); } #endif Trace.TraceInformation(String.Format("Running Threads ({0})", TrackedThreadManager.Threads.Length)); Trace.Indent(); TrackedThread[] thdThreads = TrackedThreadManager.Threads; foreach (TrackedThread thdThread in thdThreads) { Trace.TraceInformation(String.Format("{0} ({1}) ", thdThread.Thread.ManagedThreadId, thdThread.Thread.Name)); Trace.Indent(); if (thdThread.Thread.IsAlive) { Trace.TraceInformation("Aborted"); thdThread.Thread.Abort(); } else Trace.TraceInformation("Ended Cleanly"); Trace.Unindent(); } Trace.Unindent(); } finally { if (mtxAppRunningMutex != null) mtxAppRunningMutex.Close(); } }
static void Main(string[] p_strArgs) { Mutex mtxAppRunningMutex = null; try { mtxAppRunningMutex = new Mutex(false, "Global\\6af12c54-643b-4752-87d0-8335503010de"); bool booTrace = false; foreach (string strArg in p_strArgs) { if (strArg.ToLower().Equals("/trace") || strArg.ToLower().Equals("-trace")) { booTrace = true; break; } } foreach (string strArg in p_strArgs) { string[] strArgParts = strArg.Split('='); if (strArgParts[0].ToLower().Equals("/u") || strArgParts[0].ToLower().Equals("-u")) { string strGuid = strArgParts[1]; string strPath = Environment.GetFolderPath(Environment.SpecialFolder.System); ProcessStartInfo psiInfo = new ProcessStartInfo(strPath + @"\msiexec.exe", "/x " + strGuid); Process.Start(psiInfo); return; } } #if DEBUG Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, true); #else Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, false); #endif Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); UpgradeSettings(Properties.Settings.Default); EnvironmentInfo = new EnvironmentInfo(Properties.Settings.Default); if (!Directory.Exists(EnvironmentInfo.ApplicationPersonalDataFolderPath)) { Directory.CreateDirectory(EnvironmentInfo.ApplicationPersonalDataFolderPath); } EnableTracing(EnvironmentInfo, booTrace); #if !DEBUG try { #endif Bootstrapper btsInitializer = new Bootstrapper(EnvironmentInfo); btsInitializer.RunMainForm(p_strArgs); #if !DEBUG } catch (Exception e) { HandleException(e); } #endif Trace.TraceInformation(String.Format("Running Threads ({0})", TrackedThreadManager.Threads.Length)); Trace.Indent(); TrackedThread[] thdThreads = TrackedThreadManager.Threads; foreach (TrackedThread thdThread in thdThreads) { Trace.TraceInformation(String.Format("{0} ({1}) ", thdThread.Thread.ManagedThreadId, thdThread.Thread.Name)); Trace.Indent(); if (thdThread.Thread.IsAlive) { Trace.TraceInformation("Aborted"); thdThread.Thread.Abort(); } else { Trace.TraceInformation("Ended Cleanly"); } Trace.Unindent(); } Trace.Unindent(); } finally { if (mtxAppRunningMutex != null) { mtxAppRunningMutex.Close(); } } }