private static string GetObjectXmlPathRec(object oContainer, Type tContainer, object oNeedle, string strCurPath) { if (oContainer == null) { Debug.Assert(false); return(null); } if (oNeedle == null) { Debug.Assert(false); return(null); } Debug.Assert(oContainer.GetType() == tContainer); PropertyInfo[] vProps = tContainer.GetProperties(); foreach (PropertyInfo pi in vProps) { if ((pi == null) || !pi.CanRead) { continue; } object[] vPropAttribs = pi.GetCustomAttributes(true); if (XmlSerializerEx.GetAttribute <XmlIgnoreAttribute>( vPropAttribs) != null) { continue; } object oSub = pi.GetValue(oContainer, null); if (oSub == null) { continue; } string strPropName = XmlSerializerEx.GetXmlName(pi); string strSubPath = strCurPath + GoxpSep + strPropName; if (oSub == oNeedle) { return(strSubPath); } Type tSub = oSub.GetType(); string strPrimarySubType; string strPropTypeCS = XmlSerializerEx.GetFullTypeNameCS(tSub, out strPrimarySubType); if (XmlSerializerEx.TypeIsArray(strPropTypeCS) || XmlSerializerEx.TypeIsList(strPropTypeCS)) { continue; } if (strPropTypeCS.StartsWith("System.")) { continue; } string strSubFound = GetObjectXmlPathRec(oSub, tSub, oNeedle, strSubPath); if (strSubFound != null) { return(strSubFound); } } return(null); }
private void OnFileOpen(object sender, EventArgs e) { OpenFileDialogEx ofd = UIUtil.CreateOpenFileDialog("Open KeePass Translation", m_strFileFilter, 1, null, false, AppDefs.FileDialogContext.Attachments); if (ofd.ShowDialog() != DialogResult.OK) { return; } KPTranslation kpTrl = null; try { XmlSerializerEx xs = new XmlSerializerEx(typeof(KPTranslation)); kpTrl = KPTranslation.Load(ofd.FileName, xs); } catch (Exception ex) { MessageBox.Show(this, ex.Message, TrlUtilName, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } m_strFile = ofd.FileName; StringBuilder sbUnusedText = new StringBuilder(); if (kpTrl.UnusedText.Length > 0) { if (kpTrl.UnusedText.EndsWith("\r") || kpTrl.UnusedText.EndsWith("\n")) { sbUnusedText.Append(kpTrl.UnusedText); } else { sbUnusedText.AppendLine(kpTrl.UnusedText); } } m_trl.Properties = kpTrl.Properties; foreach (KPStringTable kpstNew in kpTrl.StringTables) { foreach (KPStringTable kpstInto in m_trl.StringTables) { if (kpstInto.Name == kpstNew.Name) { MergeInStringTable(kpstInto, kpstNew, sbUnusedText); } } } FormTrlMgr.MergeForms(m_trl.Forms, kpTrl.Forms, sbUnusedText); m_tbNameEng.Text = m_trl.Properties.NameEnglish; m_tbNameLcl.Text = m_trl.Properties.NameNative; m_tbLangID.Text = m_trl.Properties.Iso6391Code; m_tbAuthorName.Text = m_trl.Properties.AuthorName; m_tbAuthorContact.Text = m_trl.Properties.AuthorContact; m_cbRtl.Checked = m_trl.Properties.RightToLeft; m_rtbUnusedText.Text = sbUnusedText.ToString(); this.UpdateStringTableUI(); this.UpdateStatusImages(null); this.UpdatePreviewForm(); }
private static void MainPriv(string[] args) { #if DEBUG // Program.DesignMode should not be queried before executing // Main (e.g. by a static Control) when running the program // normally Debug.Assert(!m_bDesignModeQueried); #endif m_bDesignMode = false; // Designer doesn't call Main method m_cmdLineArgs = new CommandLineArgs(args); // Before loading the configuration string strWaDisable = m_cmdLineArgs[ AppDefs.CommandLineOptions.WorkaroundDisable]; if (!string.IsNullOrEmpty(strWaDisable)) { MonoWorkarounds.SetEnabled(strWaDisable, false); } try { DpiUtil.ConfigureProcess(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.DoEvents(); // Required } catch (Exception) { Debug.Assert(MonoWorkarounds.IsRequired(106)); } #if DEBUG string strInitialWorkDir = WinUtil.GetWorkingDirectory(); #endif if (!CommonInit()) { CommonTerminate(); return; } if (m_appConfig.Application.Start.PluginCacheClearOnce) { PlgxCache.Clear(); m_appConfig.Application.Start.PluginCacheClearOnce = false; AppConfigSerializer.Save(Program.Config); } if (m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtRegister] != null) { ShellUtil.RegisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId, KPRes.FileExtName2, WinUtil.GetExecutable(), PwDefs.ShortProductName, false); MainCleanUp(); return; } if (m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtUnregister] != null) { ShellUtil.UnregisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId); MainCleanUp(); return; } if (m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoad] != null) { // All important .NET assemblies are in memory now already try { SelfTest.Perform(); } catch (Exception) { Debug.Assert(false); } MainCleanUp(); return; } /* if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoadRegister] != null) * { * string strPreLoadPath = WinUtil.GetExecutable().Trim(); * if(strPreLoadPath.StartsWith("\"") == false) * strPreLoadPath = "\"" + strPreLoadPath + "\""; * ShellUtil.RegisterPreLoad(AppDefs.PreLoadName, strPreLoadPath, * @"--" + AppDefs.CommandLineOptions.PreLoad, true); * MainCleanUp(); * return; * } * if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoadUnregister] != null) * { * ShellUtil.RegisterPreLoad(AppDefs.PreLoadName, string.Empty, * string.Empty, false); * MainCleanUp(); * return; * } */ if ((m_cmdLineArgs[AppDefs.CommandLineOptions.Help] != null) || (m_cmdLineArgs[AppDefs.CommandLineOptions.HelpLong] != null)) { AppHelp.ShowHelp(AppDefs.HelpTopics.CommandLine, null); MainCleanUp(); return; } if (m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigSetUrlOverride] != null) { Program.Config.Integration.UrlOverride = m_cmdLineArgs[ AppDefs.CommandLineOptions.ConfigSetUrlOverride]; AppConfigSerializer.Save(Program.Config); MainCleanUp(); return; } if (m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigClearUrlOverride] != null) { Program.Config.Integration.UrlOverride = string.Empty; AppConfigSerializer.Save(Program.Config); MainCleanUp(); return; } if (m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigGetUrlOverride] != null) { try { string strFileOut = UrlUtil.EnsureTerminatingSeparator( UrlUtil.GetTempPath(), false) + "KeePass_UrlOverride.tmp"; string strContent = ("[KeePass]\r\nKeeURLOverride=" + Program.Config.Integration.UrlOverride + "\r\n"); File.WriteAllText(strFileOut, strContent); } catch (Exception) { Debug.Assert(false); } MainCleanUp(); return; } if (m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigAddUrlOverride] != null) { bool bAct = (m_cmdLineArgs[AppDefs.CommandLineOptions.Activate] != null); Program.Config.Integration.UrlSchemeOverrides.AddCustomOverride( m_cmdLineArgs[AppDefs.CommandLineOptions.Scheme], m_cmdLineArgs[AppDefs.CommandLineOptions.Value], bAct, bAct); AppConfigSerializer.Save(Program.Config); MainCleanUp(); return; } if (m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigRemoveUrlOverride] != null) { Program.Config.Integration.UrlSchemeOverrides.RemoveCustomOverride( m_cmdLineArgs[AppDefs.CommandLineOptions.Scheme], m_cmdLineArgs[AppDefs.CommandLineOptions.Value]); AppConfigSerializer.Save(Program.Config); MainCleanUp(); return; } if (m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigSetLanguageFile] != null) { Program.Config.Application.LanguageFile = m_cmdLineArgs[ AppDefs.CommandLineOptions.ConfigSetLanguageFile]; AppConfigSerializer.Save(Program.Config); MainCleanUp(); return; } if (m_cmdLineArgs[AppDefs.CommandLineOptions.PlgxCreate] != null) { PlgxPlugin.CreateFromCommandLine(); MainCleanUp(); return; } if (m_cmdLineArgs[AppDefs.CommandLineOptions.PlgxCreateInfo] != null) { PlgxPlugin.CreateInfoFile(m_cmdLineArgs.FileName); MainCleanUp(); return; } if (m_cmdLineArgs[AppDefs.CommandLineOptions.ShowAssemblyInfo] != null) { MessageService.ShowInfo(Assembly.GetExecutingAssembly().ToString()); MainCleanUp(); return; } if (m_cmdLineArgs[AppDefs.CommandLineOptions.MakeXmlSerializerEx] != null) { XmlSerializerEx.GenerateSerializers(m_cmdLineArgs); MainCleanUp(); return; } if (m_cmdLineArgs[AppDefs.CommandLineOptions.MakeXspFile] != null) { XspArchive.CreateFile(m_cmdLineArgs.FileName, m_cmdLineArgs["d"]); MainCleanUp(); return; } if (m_cmdLineArgs[AppDefs.CommandLineOptions.Version] != null) { Console.WriteLine(PwDefs.ShortProductName + " " + PwDefs.VersionString); Console.WriteLine(PwDefs.Copyright); MainCleanUp(); return; } #if DEBUG if (m_cmdLineArgs[AppDefs.CommandLineOptions.TestGfx] != null) { List <Image> lImg = new List <Image>(); lImg.Add(Properties.Resources.B16x16_Browser); lImg.Add(Properties.Resources.B48x48_Keyboard_Layout); ImageArchive aHighRes = new ImageArchive(); aHighRes.Load(Properties.Resources.Images_Client_HighRes); lImg.Add(aHighRes.GetForObject("C12_IRKickFlash")); if (File.Exists("Test.png")) { lImg.Add(Image.FromFile("Test.png")); } Image img = GfxUtil.ScaleTest(lImg.ToArray()); img.Save("GfxScaleTest.png", ImageFormat.Png); return; } #endif // #if (DEBUG && !KeePassLibSD) // if(m_cmdLineArgs[AppDefs.CommandLineOptions.MakePopularPasswordTable] != null) // { // PopularPasswords.MakeList(); // MainCleanUp(); // return; // } // #endif try { m_nAppMessage = NativeMethods.RegisterWindowMessage(m_strWndMsgID); } catch (Exception) { Debug.Assert(NativeLib.IsUnix()); } if (m_cmdLineArgs[AppDefs.CommandLineOptions.ExitAll] != null) { BroadcastAppMessageAndCleanUp(AppMessage.Exit); return; } if (m_cmdLineArgs[AppDefs.CommandLineOptions.AutoType] != null) { BroadcastAppMessageAndCleanUp(AppMessage.AutoType); return; } if (m_cmdLineArgs[AppDefs.CommandLineOptions.AutoTypePassword] != null) { BroadcastAppMessageAndCleanUp(AppMessage.AutoTypePassword); return; } if (m_cmdLineArgs[AppDefs.CommandLineOptions.AutoTypeSelected] != null) { BroadcastAppMessageAndCleanUp(AppMessage.AutoTypeSelected); return; } if (m_cmdLineArgs[AppDefs.CommandLineOptions.OpenEntryUrl] != null) { string strEntryUuid = m_cmdLineArgs[AppDefs.CommandLineOptions.Uuid]; if (!string.IsNullOrEmpty(strEntryUuid)) { IpcParamEx ipUrl = new IpcParamEx(IpcUtilEx.CmdOpenEntryUrl, strEntryUuid, null, null, null, null); IpcUtilEx.SendGlobalMessage(ipUrl, false); } MainCleanUp(); return; } if (m_cmdLineArgs[AppDefs.CommandLineOptions.LockAll] != null) { BroadcastAppMessageAndCleanUp(AppMessage.Lock); return; } if (m_cmdLineArgs[AppDefs.CommandLineOptions.UnlockAll] != null) { BroadcastAppMessageAndCleanUp(AppMessage.Unlock); return; } if (m_cmdLineArgs[AppDefs.CommandLineOptions.Cancel] != null) { BroadcastAppMessageAndCleanUp(AppMessage.Cancel); return; } string strIpc = m_cmdLineArgs[AppDefs.CommandLineOptions.IpcEvent]; string strIpc1 = m_cmdLineArgs[AppDefs.CommandLineOptions.IpcEvent1]; if ((strIpc != null) || (strIpc1 != null)) { bool bIpc1 = (strIpc1 != null); string strName = (bIpc1 ? strIpc1 : strIpc); if (strName.Length != 0) { string[] vFlt = KeyUtil.MakeCtxIndependent(args); IpcParamEx ipcP = new IpcParamEx(IpcUtilEx.CmdIpcEvent, strName, CommandLineArgs.SafeSerialize(vFlt), null, null, null); IpcUtilEx.SendGlobalMessage(ipcP, bIpc1); } MainCleanUp(); return; } // Mutex mSingleLock = TrySingleInstanceLock(AppDefs.MutexName, true); bool bSingleLock = GlobalMutexPool.CreateMutex(AppDefs.MutexName, true); // if((mSingleLock == null) && m_appConfig.Integration.LimitToSingleInstance) if (!bSingleLock && m_appConfig.Integration.LimitToSingleInstance) { ActivatePreviousInstance(args); MainCleanUp(); return; } Mutex mGlobalNotify = TryGlobalInstanceNotify(AppDefs.MutexNameGlobal); AutoType.InitStatic(); CustomMessageFilterEx cmfx = new CustomMessageFilterEx(); Application.AddMessageFilter(cmfx); #if DEBUG if (m_cmdLineArgs[AppDefs.CommandLineOptions.DebugThrowException] != null) { throw new Exception(AppDefs.CommandLineOptions.DebugThrowException); } m_formMain = new MainForm(); Application.Run(m_formMain); #else try { if (m_cmdLineArgs[AppDefs.CommandLineOptions.DebugThrowException] != null) { throw new Exception(AppDefs.CommandLineOptions.DebugThrowException); } m_formMain = new MainForm(); Application.Run(m_formMain); } catch (Exception exPrg) { ShowFatal(exPrg); } #endif Application.RemoveMessageFilter(cmfx); Debug.Assert(GlobalWindowManager.WindowCount == 0); Debug.Assert(MessageService.CurrentMessageCount == 0); MainCleanUp(); #if DEBUG string strEndWorkDir = WinUtil.GetWorkingDirectory(); Debug.Assert(strEndWorkDir.Equals(strInitialWorkDir, StrUtil.CaseIgnoreCmp)); #endif if (mGlobalNotify != null) { GC.KeepAlive(mGlobalNotify); } // if(mSingleLock != null) { GC.KeepAlive(mSingleLock); } }
protected static Sp3dToDataGroupMapping read(string mapFilePath) => XmlSerializerEx.FromXmlFile <Sp3dToDataGroupMapping>(mapFilePath);
private static bool SaveConfigFileEx(AppConfigEx tConfig, string strFilePath, bool bRemoveConfigPref) { tConfig.OnSavePre(); XmlSerializerEx xmlSerial = new XmlSerializerEx(typeof(AppConfigEx)); bool bResult = true; // FileStream fs = null; IOConnectionInfo iocPath = IOConnectionInfo.FromPath(strFilePath); FileTransactionEx fts = new FileTransactionEx(iocPath, true); Stream fs = null; // Temporarily remove user file preference (restore after saving) bool bConfigPref = tConfig.Meta.PreferUserConfiguration; if (bRemoveConfigPref) { tConfig.Meta.PreferUserConfiguration = false; } XmlWriterSettings xws = new XmlWriterSettings(); xws.Encoding = StrUtil.Utf8; xws.Indent = true; xws.IndentChars = "\t"; try { // fs = new FileStream(strFilePath, FileMode.Create, // FileAccess.Write, FileShare.None); fs = fts.OpenWrite(); if (fs == null) { throw new InvalidOperationException(); } XmlWriter xw = XmlWriter.Create(fs, xws); xmlSerial.Serialize(xw, tConfig); xw.Close(); } catch (Exception) { bResult = false; } // Do not assert if (fs != null) { fs.Close(); fs = null; } if (bResult) { try { fts.CommitWrite(); } catch (Exception) { Debug.Assert(false); } } if (bRemoveConfigPref) { tConfig.Meta.PreferUserConfiguration = bConfigPref; } tConfig.OnSavePost(); return(bResult); }
public static void Main(string[] args) { #if DEBUG // Program.DesignMode should not be queried before executing // Main (e.g. by a static Control) when running the program // normally Debug.Assert(!m_bDesignModeQueried); #endif m_bDesignMode = false; // Designer doesn't call Main method Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.DoEvents(); // Required #if DEBUG string strInitialWorkDir = WinUtil.GetWorkingDirectory(); #endif if (!CommonInit()) { CommonTerminate(); return; } if (m_appConfig.Application.Start.PluginCacheClearOnce) { PlgxCache.Clear(); m_appConfig.Application.Start.PluginCacheClearOnce = false; AppConfigSerializer.Save(Program.Config); } m_cmdLineArgs = new CommandLineArgs(args); if (m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtRegister] != null) { ShellUtil.RegisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId, KPRes.FileExtName, WinUtil.GetExecutable(), PwDefs.ShortProductName, false); MainCleanUp(); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtUnregister] != null) { ShellUtil.UnregisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId); MainCleanUp(); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoad] != null) { // All important .NET assemblies are in memory now already try { SelfTest.Perform(); } catch (Exception) { Debug.Assert(false); } MainCleanUp(); return; } /* else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoadRegister] != null) * { * string strPreLoadPath = WinUtil.GetExecutable().Trim(); * if(strPreLoadPath.StartsWith("\"") == false) * strPreLoadPath = "\"" + strPreLoadPath + "\""; * ShellUtil.RegisterPreLoad(AppDefs.PreLoadName, strPreLoadPath, * @"--" + AppDefs.CommandLineOptions.PreLoad, true); * MainCleanUp(); * return; * } * else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoadUnregister] != null) * { * ShellUtil.RegisterPreLoad(AppDefs.PreLoadName, string.Empty, * string.Empty, false); * MainCleanUp(); * return; * } */ else if ((m_cmdLineArgs[AppDefs.CommandLineOptions.Help] != null) || (m_cmdLineArgs[AppDefs.CommandLineOptions.HelpLong] != null)) { AppHelp.ShowHelp(AppDefs.HelpTopics.CommandLine, null); MainCleanUp(); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigSetUrlOverride] != null) { Program.Config.Integration.UrlOverride = m_cmdLineArgs[ AppDefs.CommandLineOptions.ConfigSetUrlOverride]; AppConfigSerializer.Save(Program.Config); MainCleanUp(); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigClearUrlOverride] != null) { Program.Config.Integration.UrlOverride = string.Empty; AppConfigSerializer.Save(Program.Config); MainCleanUp(); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigGetUrlOverride] != null) { try { string strFileOut = UrlUtil.EnsureTerminatingSeparator( UrlUtil.GetTempPath(), false) + "KeePass_UrlOverride.tmp"; string strContent = ("[KeePass]\r\nKeeURLOverride=" + Program.Config.Integration.UrlOverride + "\r\n"); File.WriteAllText(strFileOut, strContent); } catch (Exception) { Debug.Assert(false); } MainCleanUp(); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigSetLanguageFile] != null) { Program.Config.Application.LanguageFile = m_cmdLineArgs[ AppDefs.CommandLineOptions.ConfigSetLanguageFile]; AppConfigSerializer.Save(Program.Config); MainCleanUp(); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.PlgxCreate] != null) { PlgxPlugin.CreateFromCommandLine(); MainCleanUp(); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.PlgxCreateInfo] != null) { PlgxPlugin.CreateInfoFile(m_cmdLineArgs.FileName); MainCleanUp(); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.ShowAssemblyInfo] != null) { MessageService.ShowInfo(Assembly.GetExecutingAssembly().ToString()); MainCleanUp(); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.MakeXmlSerializerEx] != null) { XmlSerializerEx.GenerateSerializers(m_cmdLineArgs); MainCleanUp(); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.Version] != null) { Console.WriteLine(PwDefs.ShortProductName + " " + PwDefs.VersionString); Console.WriteLine(PwDefs.Copyright); MainCleanUp(); return; } // #if (DEBUG && !KeePassLibSD) // else if(m_cmdLineArgs[AppDefs.CommandLineOptions.MakePopularPasswordTable] != null) // { // PopularPasswords.MakeList(); // MainCleanUp(); // return; // } // #endif try { m_nAppMessage = NativeMethods.RegisterWindowMessage(m_strWndMsgID); } catch (Exception) { Debug.Assert(NativeLib.IsUnix()); } if (m_cmdLineArgs[AppDefs.CommandLineOptions.ExitAll] != null) { BroadcastAppMessageAndCleanUp(AppMessage.Exit); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.AutoType] != null) { BroadcastAppMessageAndCleanUp(AppMessage.AutoType); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.AutoTypeSelected] != null) { BroadcastAppMessageAndCleanUp(AppMessage.AutoTypeSelected); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.OpenEntryUrl] != null) { string strEntryUuid = m_cmdLineArgs[AppDefs.CommandLineOptions.Uuid]; if (!string.IsNullOrEmpty(strEntryUuid)) { IpcParamEx ipUrl = new IpcParamEx(IpcUtilEx.CmdOpenEntryUrl, strEntryUuid, null, null, null, null); IpcUtilEx.SendGlobalMessage(ipUrl); } MainCleanUp(); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.LockAll] != null) { BroadcastAppMessageAndCleanUp(AppMessage.Lock); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.UnlockAll] != null) { BroadcastAppMessageAndCleanUp(AppMessage.Unlock); return; } else if (m_cmdLineArgs[AppDefs.CommandLineOptions.IpcEvent] != null) { string strName = m_cmdLineArgs[AppDefs.CommandLineOptions.IpcEvent]; if (!string.IsNullOrEmpty(strName)) { string[] vFlt = KeyUtil.MakeCtxIndependent(args); IpcParamEx ipEvent = new IpcParamEx(IpcUtilEx.CmdIpcEvent, strName, CommandLineArgs.SafeSerialize(vFlt), null, null, null); IpcUtilEx.SendGlobalMessage(ipEvent); } MainCleanUp(); return; } // Mutex mSingleLock = TrySingleInstanceLock(AppDefs.MutexName, true); bool bSingleLock = GlobalMutexPool.CreateMutex(AppDefs.MutexName, true); // if((mSingleLock == null) && m_appConfig.Integration.LimitToSingleInstance) if (!bSingleLock && m_appConfig.Integration.LimitToSingleInstance) { ActivatePreviousInstance(args); MainCleanUp(); return; } Mutex mGlobalNotify = TryGlobalInstanceNotify(AppDefs.MutexNameGlobal); AutoType.InitStatic(); UserActivityNotifyFilter nfActivity = new UserActivityNotifyFilter(); Application.AddMessageFilter(nfActivity); #if DEBUG if (m_cmdLineArgs[AppDefs.CommandLineOptions.DebugThrowException] != null) { throw new Exception(AppDefs.CommandLineOptions.DebugThrowException); } m_formMain = new MainForm(); Application.Run(m_formMain); #else try { if (m_cmdLineArgs[AppDefs.CommandLineOptions.DebugThrowException] != null) { throw new Exception(AppDefs.CommandLineOptions.DebugThrowException); } m_formMain = new MainForm(); Application.Run(m_formMain); } catch (Exception exPrg) { // Catch message box exception; // https://sourceforge.net/p/keepass/patches/86/ try { MessageService.ShowFatal(exPrg); } catch (Exception) { Console.Error.WriteLine(exPrg.ToString()); } } #endif Application.RemoveMessageFilter(nfActivity); Debug.Assert(GlobalWindowManager.WindowCount == 0); Debug.Assert(MessageService.CurrentMessageCount == 0); MainCleanUp(); #if DEBUG string strEndWorkDir = WinUtil.GetWorkingDirectory(); Debug.Assert(strEndWorkDir.Equals(strInitialWorkDir, StrUtil.CaseIgnoreCmp)); #endif if (mGlobalNotify != null) { GC.KeepAlive(mGlobalNotify); } // if(mSingleLock != null) { GC.KeepAlive(mSingleLock); } }