Esempio n. 1
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            if (m_triggers == null)
            {
                Debug.Assert(false); return;
            }

            GlobalWindowManager.AddWindow(this);
            GlobalWindowManager.CustomizeControl(m_ctxTools);

            BannerFactory.CreateBannerEx(this, m_bannerImage,
                                         Properties.Resources.B48x48_Make_KDevelop, KPRes.Triggers,
                                         KPRes.TriggersDesc);
            this.Text = KPRes.Triggers;
            this.Icon = AppIcons.Default;

            int nWidth = (m_lvTriggers.ClientSize.Width - UIUtil.GetVScrollBarWidth() - 1);

            m_lvTriggers.Columns.Add(KPRes.Triggers, nWidth);

            m_lvTriggers.SmallImageList = m_ilIcons;

            m_cbEnableTriggers.Checked = m_triggers.Enabled;
            UpdateTriggerListEx(false);

            EcasTriggerSystem ts    = Program.TriggerSystem;
            EcasTriggerSystem tsCfg = Program.Config.Application.TriggerSystem;

            if (object.ReferenceEquals(m_triggersInOut, ts) &&
                AppConfigEx.IsOptionEnforced(tsCfg, "Enabled"))
            {
                m_cbEnableTriggers.Enabled = false;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Common program initialization function that can also be
        /// used by applications that use KeePass as a library
        /// (like e.g. KPScript).
        /// </summary>
        public static bool CommonInit()
        {
            m_bDesignMode = false;             // Again, for the ones not calling Main

            m_rndGlobal = CryptoRandom.NewWeakRandom();

            InitEnvSecurity();
            MonoWorkarounds.Initialize();

            // try { NativeMethods.SetProcessDPIAware(); }
            // catch(Exception) { }

            // Do not run as AppX, because of compatibility problems
            // (unless we're a special compatibility build)
            if (WinUtil.IsAppX && !IsBuildType(
                    "CDE75CF0D4CA04D577A5A2E6BF5D19BFD5DDBBCF89D340FBBB0E4592C04496F1"))
            {
                return(false);
            }

            try { SelfTest.TestFipsComplianceProblems(); }
            catch (Exception exFips)
            {
                MessageService.ShowWarning(KPRes.SelfTestFailed, exFips);
                return(false);
            }

            // Set global localized strings
            PwDatabase.LocalizedAppName = PwDefs.ShortProductName;
            KdbxFile.DetermineLanguageId();

            m_appConfig = AppConfigSerializer.Load();
            if (m_appConfig.Logging.Enabled)
            {
                AppLogEx.Open(PwDefs.ShortProductName);
            }

            AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep();

            if (m_appConfig.Security.ProtectProcessWithDacl)
            {
                KeePassLib.Native.NativeMethods.ProtectProcessWithDacl();
            }

            m_appConfig.Apply(AceApplyFlags.All);

            m_ecasTriggers = m_appConfig.Application.TriggerSystem;
            m_ecasTriggers.SetToInitialState();

            string strHelpFile = UrlUtil.StripExtension(WinUtil.GetExecutable()) + ".chm";

            AppHelp.LocalHelpFile = strHelpFile;

            // InitEnvWorkarounds();
            LoadTranslation();

            CustomResourceManager.Override(typeof(KeePass.Properties.Resources));

            return(true);
        }
Esempio n. 3
0
        public bool InitEx(EcasTriggerSystem triggers, ImageList ilIcons)
        {
            m_triggersInOut = triggers;
            m_triggers      = triggers.CloneDeep();

            m_ilIcons = ilIcons;

            return(AppPolicy.Try(AppPolicyId.EditTriggers));
        }
Esempio n. 4
0
        public bool InitEx(EcasTriggerSystem triggers, ImageList ilIcons)
        {
            m_triggersInOut = triggers;
            m_triggers = triggers.CloneDeep();

            m_ilIcons = ilIcons;

            return AppPolicy.Try(AppPolicyId.EditTriggers);
        }
Esempio n. 5
0
        public EcasContext(EcasTriggerSystem coll, EcasTrigger trigger,
            EcasEvent e)
        {
            if(coll == null) throw new ArgumentNullException("coll");
            if(trigger == null) throw new ArgumentNullException("trigger");
            if(e == null) throw new ArgumentNullException("e");

            m_coll = coll;
            m_trigger = trigger;
            m_eOccured = e;
        }
Esempio n. 6
0
        /// <summary>
        /// Common program initialization function that can also be
        /// used by applications that use KeePass as a library
        /// (like e.g. KPScript).
        /// </summary>
        public static bool CommonInit()
        {
            m_bDesignMode = false;             // Again, for the ones not calling Main

            int nRandomSeed = (int)DateTime.UtcNow.Ticks;

            // Prevent overflow (see Random class constructor)
            if (nRandomSeed == int.MinValue)
            {
                nRandomSeed = 17;
            }
            m_rndGlobal = new Random(nRandomSeed);

            InitEnvSecurity();
            MonoWorkarounds.Initialize();

            // try { NativeMethods.SetProcessDPIAware(); }
            // catch(Exception) { }

            try { SelfTest.TestFipsComplianceProblems(); }
            catch (Exception exFips)
            {
                MessageService.ShowWarning(KPRes.SelfTestFailed, exFips);
                return(false);
            }

            // Set global localized strings
            PwDatabase.LocalizedAppName = PwDefs.ShortProductName;
            KdbxFile.DetermineLanguageId();

            m_appConfig = AppConfigSerializer.Load();
            if (m_appConfig.Logging.Enabled)
            {
                AppLogEx.Open(PwDefs.ShortProductName);
            }

            AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep();

            m_appConfig.Apply(AceApplyFlags.All);

            m_ecasTriggers = m_appConfig.Application.TriggerSystem;
            m_ecasTriggers.SetToInitialState();

            string strHelpFile = UrlUtil.StripExtension(WinUtil.GetExecutable()) + ".chm";

            AppHelp.LocalHelpFile = strHelpFile;

            // InitEnvWorkarounds();
            LoadTranslation();

            CustomResourceManager.Override(typeof(KeePass.Properties.Resources));

            return(true);
        }
Esempio n. 7
0
        public EcasContext(EcasTriggerSystem coll, EcasTrigger trigger,
			EcasEvent e, EcasPropertyDictionary props)
        {
            if(coll == null) throw new ArgumentNullException("coll");
            if(trigger == null) throw new ArgumentNullException("trigger");
            if(e == null) throw new ArgumentNullException("e");
            if(props == null) throw new ArgumentNullException("props");

            m_coll = coll;
            m_trigger = trigger;
            m_eOccured = e;
            m_props = props;
        }
Esempio n. 8
0
        /// <summary>
        /// Common program initialization function that can also be
        /// used by applications that use KeePass as a library
        /// (like e.g. KPScript).
        /// </summary>
        public static bool CommonInit()
        {
            int nRandomSeed = (int)DateTime.UtcNow.Ticks;

            // Prevent overflow (see Random class constructor)
            if (nRandomSeed == int.MinValue)
            {
                nRandomSeed = 17;
            }
            m_rndGlobal = new Random(nRandomSeed);

            InitEnvSecurity();

            try { SelfTest.TestFipsComplianceProblems(); }
            catch (Exception exFips)
            {
                MessageService.ShowWarning(KPRes.SelfTestFailed, exFips);
                return(false);
            }

            // Set global localized strings
            PwDatabase.LocalizedAppName = PwDefs.ShortProductName;
            Kdb4File.DetermineLanguageId();

            m_appConfig = AppConfigSerializer.Load();
            if (m_appConfig.Logging.Enabled)
            {
                AppLogEx.Open(PwDefs.ShortProductName);
            }

            AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep();
            IOConnection.SetProxy(m_appConfig.Integration.ProxyType,
                                  m_appConfig.Integration.ProxyAddress, m_appConfig.Integration.ProxyPort,
                                  m_appConfig.Integration.ProxyUserName, m_appConfig.Integration.ProxyPassword);

            m_ecasTriggers = m_appConfig.Application.TriggerSystem;
            m_ecasTriggers.SetToInitialState();

            string strHelpFile = UrlUtil.StripExtension(WinUtil.GetExecutable()) + ".chm";

            AppHelp.LocalHelpFile = strHelpFile;

            LoadTranslation();
            return(true);
        }
Esempio n. 9
0
        /// <summary>
        /// Common program initialization function that can also be
        /// used by applications that use KeePass as a library
        /// (like e.g. KPScript).
        /// </summary>
        public static bool CommonInit()
        {
            int nRandomSeed = (int)DateTime.UtcNow.Ticks;
            // Prevent overflow (see Random class constructor)
            if(nRandomSeed == int.MinValue) nRandomSeed = 17;
            m_rndGlobal = new Random(nRandomSeed);

            InitEnvSecurity();

            try { SelfTest.TestFipsComplianceProblems(); }
            catch(Exception exFips)
            {
                MessageService.ShowWarning(KPRes.SelfTestFailed, exFips);
                return false;
            }

            // Set global localized strings
            PwDatabase.LocalizedAppName = PwDefs.ShortProductName;
            KdbxFile.DetermineLanguageId();

            m_appConfig = AppConfigSerializer.Load();
            if(m_appConfig.Logging.Enabled)
                AppLogEx.Open(PwDefs.ShortProductName);

            AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep();
            IOConnection.SetProxy(m_appConfig.Integration.ProxyType,
                m_appConfig.Integration.ProxyAddress, m_appConfig.Integration.ProxyPort,
                m_appConfig.Integration.ProxyUserName, m_appConfig.Integration.ProxyPassword);

            m_ecasTriggers = m_appConfig.Application.TriggerSystem;
            m_ecasTriggers.SetToInitialState();

            string strHelpFile = UrlUtil.StripExtension(WinUtil.GetExecutable()) + ".chm";
            AppHelp.LocalHelpFile = strHelpFile;

            LoadTranslation();
            return true;
        }
Esempio n. 10
0
        /// <summary>
        /// Common program initialization function that can also be
        /// used by applications that use KeePass as a library
        /// (like e.g. KPScript).
        /// </summary>
        public static bool CommonInit()
        {
            m_bDesignMode = false; // Again, for the ones not calling Main

            int nRandomSeed = (int)DateTime.UtcNow.Ticks;
            // Prevent overflow (see Random class constructor)
            if(nRandomSeed == int.MinValue) nRandomSeed = 17;
            m_rndGlobal = new Random(nRandomSeed);

            InitEnvSecurity();

            // try { NativeMethods.SetProcessDPIAware(); }
            // catch(Exception) { }

            try { SelfTest.TestFipsComplianceProblems(); }
            catch(Exception exFips)
            {
                MessageService.ShowWarning(KPRes.SelfTestFailed, exFips);
                return false;
            }

            // Set global localized strings
            PwDatabase.LocalizedAppName = PwDefs.ShortProductName;
            KdbxFile.DetermineLanguageId();

            m_appConfig = AppConfigSerializer.Load();
            if(m_appConfig.Logging.Enabled)
                AppLogEx.Open(PwDefs.ShortProductName);

            AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep();

            m_appConfig.Apply(AceApplyFlags.All);

            m_ecasTriggers = m_appConfig.Application.TriggerSystem;
            m_ecasTriggers.SetToInitialState();

            string strHelpFile = UrlUtil.StripExtension(WinUtil.GetExecutable()) + ".chm";
            AppHelp.LocalHelpFile = strHelpFile;

            // InitEnvWorkarounds();
            LoadTranslation();

            CustomResourceManager.Override(typeof(KeePass.Properties.Resources));

            return true;
        }
Esempio n. 11
0
		public static void Main(string[] args)
		{
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			Application.DoEvents(); // Required

			InitEnvSecurity();

			int nRandomSeed = (int)DateTime.Now.Ticks;
			// Prevent overflow (see Random class constructor)
			if(nRandomSeed == int.MinValue) nRandomSeed = 17;
			m_rndGlobal = new Random(nRandomSeed);

			// Set global localized strings
			PwDatabase.LocalizedAppName = PwDefs.ShortProductName;
			Kdb4File.DetermineLanguageId();

			m_appConfig = AppConfigSerializer.Load();
			if(m_appConfig.Logging.Enabled)
				AppLogEx.Open(PwDefs.ShortProductName);

			AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep();

			m_ecasTriggers = m_appConfig.Application.TriggerSystem;
			m_ecasTriggers.SetToInitialState();

			string strHelpFile = UrlUtil.StripExtension(WinUtil.GetExecutable()) + ".chm";
			AppHelp.LocalHelpFile = strHelpFile;

			string strLangFile = m_appConfig.Application.LanguageFile;
			if((strLangFile != null) && (strLangFile.Length > 0))
			{
				strLangFile = UrlUtil.GetFileDirectory(WinUtil.GetExecutable(), true,
					false) + strLangFile;

				try
				{
					m_kpTranslation = KPTranslation.LoadFromFile(strLangFile);

					KPRes.SetTranslatedStrings(
						m_kpTranslation.SafeGetStringTableDictionary(
						"KeePass.Resources.KPRes"));
					KLRes.SetTranslatedStrings(
						m_kpTranslation.SafeGetStringTableDictionary(
						"KeePassLib.Resources.KLRes"));

					StrUtil.RightToLeft = m_kpTranslation.Properties.RightToLeft;
				}
				catch(FileNotFoundException) { } // Ignore
				catch(Exception) { Debug.Assert(false); }
			}

			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(
						Path.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;
			}
#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(false); }

			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.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;
			}

			Mutex mSingleLock = TrySingleInstanceLock(AppDefs.MutexName, true);
			if((mSingleLock == null) && m_appConfig.Integration.LimitToSingleInstance)
			{
				ActivatePreviousInstance(args);
				MainCleanUp();
				return;
			}

			Mutex mGlobalNotify = TryGlobalInstanceNotify(AppDefs.MutexNameGlobal);

			AutoType.InitStatic();

			UserActivityNotifyFilter nfActivity = new UserActivityNotifyFilter();
			Application.AddMessageFilter(nfActivity);

#if DEBUG
			m_formMain = new MainForm();
			Application.Run(m_formMain);
#else
			try
			{
				m_formMain = new MainForm();
				Application.Run(m_formMain);
			}
			catch(Exception exPrg) { MessageService.ShowFatal(exPrg); }
#endif

			Application.RemoveMessageFilter(nfActivity);

			Debug.Assert(GlobalWindowManager.WindowCount == 0);
			Debug.Assert(MessageService.CurrentMessageCount == 0);

			MainCleanUp();

			if(mGlobalNotify != null) { GC.KeepAlive(mGlobalNotify); }
			if(mSingleLock != null) { GC.KeepAlive(mSingleLock); }
		}
Esempio n. 12
0
        /// <summary>
        /// Common program initialization function that can also be
        /// used by applications that use KeePass as a library
        /// (like e.g. KPScript).
        /// </summary>
        public static bool CommonInit()
        {
            m_bDesignMode = false;             // Again, for the ones not calling Main

            m_rndGlobal = CryptoRandom.NewWeakRandom();

            InitEnvSecurity();
            MonoWorkarounds.Initialize();

            // Do not run as AppX, because of compatibility problems
            if (WinUtil.IsAppX)
            {
                return(false);
            }

            try { SelfTest.TestFipsComplianceProblems(); }
            catch (Exception exFips)
            {
                MessageService.ShowWarning(KPRes.SelfTestFailed, exFips);
                return(false);
            }

            // Set global localized strings
            PwDatabase.LocalizedAppName = PwDefs.ShortProductName;
            KdbxFile.DetermineLanguageId();

            m_appConfig = AppConfigSerializer.Load();
            if (m_appConfig.Logging.Enabled)
            {
                AppLogEx.Open(PwDefs.ShortProductName);
            }

            AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep();
            AppPolicy.ApplyToConfig();

            if (m_appConfig.Security.ProtectProcessWithDacl)
            {
                KeePassLib.Native.NativeMethods.ProtectProcessWithDacl();
            }

            m_appConfig.Apply(AceApplyFlags.All);

            m_ecasTriggers = m_appConfig.Application.TriggerSystem;
            m_ecasTriggers.SetToInitialState();

            // InitEnvWorkarounds();
            LoadTranslation();

            CustomResourceManager.Override(typeof(KeePass.Properties.Resources));

#if KP_DEVSNAP
            if (!m_bAsmResReg)
            {
                AppDomain.CurrentDomain.AssemblyResolve += Program.AssemblyResolve;
                m_bAsmResReg = true;
            }
            else
            {
                Debug.Assert(false);
            }
#endif

            return(true);
        }
Esempio n. 13
0
        public static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.DoEvents();             // Required

            InitEnvSecurity();

            int nRandomSeed = (int)DateTime.Now.Ticks;

            // Prevent overflow (see Random class constructor)
            if (nRandomSeed == int.MinValue)
            {
                nRandomSeed = 17;
            }
            m_rndGlobal = new Random(nRandomSeed);

            // Set global localized strings
            PwDatabase.LocalizedAppName = PwDefs.ShortProductName;
            Kdb4File.DetermineLanguageId();

            m_appConfig = AppConfigSerializer.Load();
            if (m_appConfig.Logging.Enabled)
            {
                AppLogEx.Open(PwDefs.ShortProductName);
            }

            AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep();

            m_ecasTriggers = m_appConfig.Application.TriggerSystem;
            m_ecasTriggers.SetToInitialState();

            string strHelpFile = UrlUtil.StripExtension(WinUtil.GetExecutable()) + ".chm";

            AppHelp.LocalHelpFile = strHelpFile;

            string strLangFile = m_appConfig.Application.LanguageFile;

            if ((strLangFile != null) && (strLangFile.Length > 0))
            {
                strLangFile = UrlUtil.GetFileDirectory(WinUtil.GetExecutable(), true,
                                                       false) + strLangFile;

                try
                {
                    m_kpTranslation = KPTranslation.LoadFromFile(strLangFile);

                    KPRes.SetTranslatedStrings(
                        m_kpTranslation.SafeGetStringTableDictionary(
                            "KeePass.Resources.KPRes"));
                    KLRes.SetTranslatedStrings(
                        m_kpTranslation.SafeGetStringTableDictionary(
                            "KeePassLib.Resources.KLRes"));

                    StrUtil.RightToLeft = m_kpTranslation.Properties.RightToLeft;
                }
                catch (FileNotFoundException) { }                // Ignore
                catch (Exception) { Debug.Assert(false); }
            }

            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(
                        Path.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;
            }
#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(false); }

            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.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;
            }

            Mutex mSingleLock = TrySingleInstanceLock(AppDefs.MutexName, true);
            if ((mSingleLock == null) && m_appConfig.Integration.LimitToSingleInstance)
            {
                ActivatePreviousInstance(args);
                MainCleanUp();
                return;
            }

            Mutex mGlobalNotify = TryGlobalInstanceNotify(AppDefs.MutexNameGlobal);

            AutoType.InitStatic();

            UserActivityNotifyFilter nfActivity = new UserActivityNotifyFilter();
            Application.AddMessageFilter(nfActivity);

#if DEBUG
            m_formMain = new MainForm();
            Application.Run(m_formMain);
#else
            try
            {
                m_formMain = new MainForm();
                Application.Run(m_formMain);
            }
            catch (Exception exPrg) { MessageService.ShowFatal(exPrg); }
#endif

            Application.RemoveMessageFilter(nfActivity);

            Debug.Assert(GlobalWindowManager.WindowCount == 0);
            Debug.Assert(MessageService.CurrentMessageCount == 0);

            MainCleanUp();

            if (mGlobalNotify != null)
            {
                GC.KeepAlive(mGlobalNotify);
            }
            if (mSingleLock != null)
            {
                GC.KeepAlive(mSingleLock);
            }
        }