/// <summary> /// Gets an instance of a <see cref="Messager"/> to use to talk to the running instance of the client. /// </summary> /// <param name="p_eifEnvironmentInfo">The application's envrionment info.</param> /// <param name="p_gmdGameModeInfo">The descriptor of the game mode for which mods are being managed.</param> /// <returns>An instance of a <see cref="Messager"/> to use to talk to the running instance of the client, /// or <c>null</c> if no valid <see cref="Messager"/> could be created.</returns> public static IMessager GetMessager(EnvironmentInfo p_eifEnvironmentInfo, IGameModeDescriptor p_gmdGameModeInfo) { if (m_cchMessagerChannel == null) { System.Collections.IDictionary properties = new System.Collections.Hashtable(); properties["exclusiveAddressUse"] = false; m_cchMessagerChannel = new IpcClientChannel(); ChannelServices.RegisterChannel(m_cchMessagerChannel, true); } else throw new InvalidOperationException("The IPC Channel has already been created as a CLIENT."); string strMessagerUri = String.Format("ipc://{0}-{1}IpcServer/{1}Listener", p_eifEnvironmentInfo.Settings.ModManagerName, p_gmdGameModeInfo.ModeId); IMessager msgMessager = null; try { Trace.TraceInformation(String.Format("Getting listener on: {0}", strMessagerUri)); msgMessager = (IMessager)Activator.GetObject(typeof(IMessager), strMessagerUri); //Just because a messager has been returned, dosn't mean it exists. //All you've really done at this point is create an object wrapper of type "Messager" which has the same methods, properties etc... //You wont know if you've got a real object, until you invoke something, hence the post (Power on self test) method. msgMessager.Post(); } catch (RemotingException e) { Trace.TraceError("Could not get Messager: {0}", strMessagerUri); TraceUtil.TraceException(e); return null; } return new MessagerClient(msgMessager); }
/// <summary> /// Starts up the IPC listner channel to wait for message from other instances. /// </summary> /// <param name="p_eifEnvironmentInfo">The application's envrionment info.</param> /// <param name="p_gmdGameModeInfo">The descriptor of the game mode for which mods are being managed.</param> /// <param name="p_mmgModManager">The mod manager to use to manage mods.</param> /// <param name="p_frmMainForm">The main application form.</param> public static IMessager InitializeListener(EnvironmentInfo p_eifEnvironmentInfo, IGameModeDescriptor p_gmdGameModeInfo, ModManager p_mmgModManager, MainForm p_frmMainForm) { if (m_schMessagerChannel != null) throw new InvalidOperationException("The IPC Channel has already been created as a SERVER."); string strUri = String.Format("{0}-{1}IpcServer", p_eifEnvironmentInfo.Settings.ModManagerName, p_gmdGameModeInfo.ModeId); m_schMessagerChannel = new IpcServerChannel(strUri); ChannelServices.RegisterChannel(m_schMessagerChannel, true); MessagerServer msgMessager = new MessagerServer(p_mmgModManager, p_frmMainForm); string strEndpoint = String.Format("{0}Listener", p_gmdGameModeInfo.ModeId); RemotingServices.Marshal(msgMessager, strEndpoint, typeof(IMessager)); strUri += "/" + strEndpoint; string strTraceInfo = String.Format("Setting up listener on {0} at {1}", strUri, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Trace.TraceInformation(strTraceInfo); return msgMessager; }
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(); } }
/// <summary> /// A simple constructor that initializes the object with the given values. /// </summary> /// <param name="p_eifEnvironmentInfo">The application's envrionment info.</param> /// <param name="p_nfrFontSetResolver">The <see cref="NexusFontSetResolver"/> to use.</param> public ApplicationInitializer(EnvironmentInfo p_eifEnvironmentInfo, NexusFontSetResolver p_nfrFontSetResolver) { EnvironmentInfo = p_eifEnvironmentInfo; FontSetResolver = p_nfrFontSetResolver; LoginUser = delegate { return false; }; ShowMessage = delegate { return DialogResult.Cancel; }; ConfirmMakeWritable = delegate(IEnvironmentInfo eif, string file, out bool remember) { remember = false; return false; }; ShowView = delegate { return DialogResult.Cancel; }; }
/// <summary> /// Sets the path to the external compression library. /// </summary> /// <param name="p_eifEnvironmentInfo">The application's envrionment info.</param> protected void SetCompressorPath(EnvironmentInfo p_eifEnvironmentInfo) { string str7zPath = Path.Combine(p_eifEnvironmentInfo.ProgrammeInfoDirectory, p_eifEnvironmentInfo.Is64BitProcess ? "7z-64bit.dll" : "7z-32bit.dll"); SevenZipCompressor.SetLibraryPath(str7zPath); }
/// <summary> /// A simple constructor that initializes the object with the given values. /// </summary> /// <param name="p_eifEnvironmentInfo">The application's envrionment info.</param> public Bootstrapper(EnvironmentInfo p_eifEnvironmentInfo) { m_eifEnvironmentInfo = p_eifEnvironmentInfo; }
/// <summary> /// Checks to see if a sandbox is interfering with dynamic code generation. /// </summary> /// <param name="p_eifEnvironmentInfo">The application's envrionment info.</param> /// <returns><c>true</c> if the check passed; /// <c>false</c> otherwise.</returns> protected bool SandboxCheck(EnvironmentInfo p_eifEnvironmentInfo) { try { new XmlSerializer(typeof(WindowPositions)); } catch (InvalidOperationException) { string strMessage = "{0} has detected that it is running in a sandbox." + Environment.NewLine + "The sandbox is preventing {0} from performing" + Environment.NewLine + "important operations. Please run {0} again," + Environment.NewLine + "without the sandbox."; string strDetails = "This error commonly occurs on computers running Comodo Antivirus.<br/>" + "If you are running Comodo or any antivirus, please add {0} and its folders to the exception list.<br/><br/>"; ExtendedMessageBox.Show(null, String.Format(strMessage, p_eifEnvironmentInfo.Settings.ModManagerName), "Sandbox Detected", String.Format(strDetails, p_eifEnvironmentInfo.Settings.ModManagerName), MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } catch (System.Runtime.InteropServices.ExternalException) { string strMessage = "{0} has detected that it is running in a sandbox." + Environment.NewLine + "The sandbox is preventing {0} from performing" + Environment.NewLine + "important operations. Please run {0} again," + Environment.NewLine + "without the sandbox."; string strDetails = "This error commonly occurs on computers running Zone Alarm.<br/>" + "If you are running Zone Alarm or any similar security suite, please add {0} and its folders to the exception list.<br/><br/>"; ExtendedMessageBox.Show(null, String.Format(strMessage, p_eifEnvironmentInfo.Settings.ModManagerName), "Sandbox Detected", String.Format(strDetails, p_eifEnvironmentInfo.Settings.ModManagerName), MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } return true; }
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) { 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(); } } }
/// <summary> /// A simple constructor that initializes the object with the given values. /// </summary> /// <param name="environmentInfo">The application's environment info.</param> public Bootstrapper(EnvironmentInfo environmentInfo) { _environmentInfo = environmentInfo; }
/// <summary> /// Sets the path to the external compression library. /// </summary> /// <param name="environmentInfo">The application's envrionment info.</param> protected void SetCompressorPath(EnvironmentInfo environmentInfo) { var sevenZipPath = Path.Combine(environmentInfo.ProgrammeInfoDirectory, environmentInfo.Is64BitProcess ? "7z-64bit.dll" : "7z-32bit.dll"); SevenZipCompressor.SetLibraryPath(sevenZipPath); }