Inheritance: System.EventArgs
Esempio n. 1
0
        private void OnFileNew(object sender, EventArgs e)
        {
            if(!AppPolicy.Try(AppPolicyId.NewFile)) return;
            if(!AppPolicy.Try(AppPolicyId.SaveFile)) return;

            SaveFileDialog sfd = UIUtil.CreateSaveFileDialog(KPRes.CreateNewDatabase,
                KPRes.NewDatabaseFileName, UIUtil.CreateFileTypeFilter(
                AppDefs.FileExtension.FileExt, KPRes.KdbxFiles, true), 1,
                AppDefs.FileExtension.FileExt, false, true);

            GlobalWindowManager.AddDialog(sfd);
            DialogResult dr = sfd.ShowDialog();
            GlobalWindowManager.RemoveDialog(sfd);

            string strPath = sfd.FileName;

            if(dr != DialogResult.OK) return;

            KeyCreationForm kcf = new KeyCreationForm();
            kcf.InitEx(IOConnectionInfo.FromPath(strPath), true);
            dr = kcf.ShowDialog();
            if((dr == DialogResult.Cancel) || (dr == DialogResult.Abort))
            {
                UIUtil.DestroyForm(kcf);
                return;
            }

            PwDocument dsPrevActive = m_docMgr.ActiveDocument;
            PwDatabase pd = m_docMgr.CreateNewDocument(true).Database;
            pd.New(IOConnectionInfo.FromPath(strPath), kcf.CompositeKey);

            UIUtil.DestroyForm(kcf);

            DatabaseSettingsForm dsf = new DatabaseSettingsForm();
            dsf.InitEx(true, pd);
            dr = dsf.ShowDialog();
            if((dr == DialogResult.Cancel) || (dr == DialogResult.Abort))
            {
                m_docMgr.CloseDatabase(pd);
                try { m_docMgr.ActiveDocument = dsPrevActive; }
                catch(Exception) { } // Fails if no database is open now
                UpdateUI(false, null, true, null, true, null, false);
                UIUtil.DestroyForm(dsf);
                return;
            }
            UIUtil.DestroyForm(dsf);

            // AutoEnableVisualHiding();

            PwGroup pg = new PwGroup(true, true, KPRes.General, PwIcon.Folder);
            pd.RootGroup.AddGroup(pg, true);

            pg = new PwGroup(true, true, KPRes.WindowsOS, PwIcon.DriveWindows);
            pd.RootGroup.AddGroup(pg, true);

            pg = new PwGroup(true, true, KPRes.Network, PwIcon.NetworkServer);
            pd.RootGroup.AddGroup(pg, true);

            pg = new PwGroup(true, true, KPRes.Internet, PwIcon.World);
            pd.RootGroup.AddGroup(pg, true);

            pg = new PwGroup(true, true, KPRes.EMail, PwIcon.EMail);
            pd.RootGroup.AddGroup(pg, true);

            pg = new PwGroup(true, true, KPRes.Homebanking, PwIcon.Homebanking);
            pd.RootGroup.AddGroup(pg, true);

            PwEntry pe = new PwEntry(true, true);
            pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pd.MemoryProtection.ProtectTitle,
                KPRes.SampleEntry));
            pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pd.MemoryProtection.ProtectUserName,
                KPRes.UserName));
            pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pd.MemoryProtection.ProtectUrl,
                @"http://www.somesite.com/"));
            pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pd.MemoryProtection.ProtectPassword,
                KPRes.Password));
            pe.Strings.Set(PwDefs.NotesField, new ProtectedString(pd.MemoryProtection.ProtectNotes,
                KPRes.Notes));
            pe.AutoType.Add(new AutoTypeAssociation(KPRes.TargetWindow,
                @"{USERNAME}{TAB}{PASSWORD}{TAB}{ENTER}"));
            pd.RootGroup.AddEntry(pe, true);

            pe = new PwEntry(true, true);
            pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pd.MemoryProtection.ProtectTitle,
                KPRes.SampleEntry + " #2"));
            pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pd.MemoryProtection.ProtectUserName,
                "Michael321"));
            pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pd.MemoryProtection.ProtectUrl,
                @"http://keepass.info/help/kb/kb090406_testform.html"));
            pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pd.MemoryProtection.ProtectPassword,
                "12345"));
            pe.AutoType.Add(new AutoTypeAssociation("Test Form - KeePass*", string.Empty));
            pd.RootGroup.AddEntry(pe, true);

            #if DEBUG
            Random r = Program.GlobalRandom;
            for(uint iSamples = 0; iSamples < 1500; ++iSamples)
            {
                pg = pd.RootGroup.Groups.GetAt(iSamples % 5);

                pe = new PwEntry(true, true);

                pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pd.MemoryProtection.ProtectTitle,
                    Guid.NewGuid().ToString()));
                pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pd.MemoryProtection.ProtectUserName,
                    Guid.NewGuid().ToString()));
                pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pd.MemoryProtection.ProtectUrl,
                    Guid.NewGuid().ToString()));
                pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pd.MemoryProtection.ProtectPassword,
                    Guid.NewGuid().ToString()));
                pe.Strings.Set(PwDefs.NotesField, new ProtectedString(pd.MemoryProtection.ProtectNotes,
                    Guid.NewGuid().ToString()));

                pe.IconId = (PwIcon)r.Next(0, (int)PwIcon.Count);

                pg.AddEntry(pe, true);
            }

            pd.CustomData.Set("Sample Custom Data 1", "0123456789");
            pd.CustomData.Set("Sample Custom Data 2", @"µy data");
            #endif

            UpdateUI(true, null, true, null, true, null, true);

            if(this.FileCreated != null)
            {
                FileCreatedEventArgs ea = new FileCreatedEventArgs(pd);
                this.FileCreated(this, ea);
            }
        }
Esempio n. 2
0
 private void OnFileCreated(object sender, FileCreatedEventArgs e) {
     m_uploadToolItem.Enabled = true;
     m_downToolItem.Enabled = false;
 }
Esempio n. 3
0
 private void OnKPDBCreated(object sender, FileCreatedEventArgs e)
 {
     e.Database.CustomData.Set("KeePassRPC.KeeFox.configVersion", CurrentConfigVersion);
     EnsureDBIconIsInKPRPCIconCache();
     //KeePassRPCService.ensureDBisOpenEWH.Set(); // signal that DB is now open so any waiting JSONRPC thread can go ahead
     SignalAllManagedRPCClients(KeePassRPC.DataExchangeModel.Signal.DATABASE_OPEN);
 }
Esempio n. 4
0
		private void OnFileNew(object sender, EventArgs e)
		{
			if(!AppPolicy.Try(AppPolicyId.NewFile)) return;
			if(!AppPolicy.Try(AppPolicyId.SaveFile)) return;

			SaveFileDialogEx sfd = UIUtil.CreateSaveFileDialog(KPRes.CreateNewDatabase,
				KPRes.NewDatabaseFileName, UIUtil.CreateFileTypeFilter(
				AppDefs.FileExtension.FileExt, KPRes.KdbxFiles, true), 1,
				AppDefs.FileExtension.FileExt, AppDefs.FileDialogContext.Database);

			GlobalWindowManager.AddDialog(sfd.FileDialog);
			DialogResult dr = sfd.ShowDialog();
			GlobalWindowManager.RemoveDialog(sfd.FileDialog);

			string strPath = sfd.FileName;

			if(dr != DialogResult.OK) return;

			KeyCreationForm kcf = new KeyCreationForm();
			kcf.InitEx(IOConnectionInfo.FromPath(strPath), true);
			dr = kcf.ShowDialog();
			if((dr == DialogResult.Cancel) || (dr == DialogResult.Abort))
			{
				UIUtil.DestroyForm(kcf);
				return;
			}

			PwDocument dsPrevActive = m_docMgr.ActiveDocument;
			PwDatabase pd = m_docMgr.CreateNewDocument(true).Database;
			pd.New(IOConnectionInfo.FromPath(strPath), kcf.CompositeKey);

			UIUtil.DestroyForm(kcf);

			DatabaseSettingsForm dsf = new DatabaseSettingsForm();
			dsf.InitEx(true, pd);
			dr = dsf.ShowDialog();
			if((dr == DialogResult.Cancel) || (dr == DialogResult.Abort))
			{
				m_docMgr.CloseDatabase(pd);
				try { m_docMgr.ActiveDocument = dsPrevActive; }
				catch(Exception) { } // Fails if no database is open now
				UpdateUI(false, null, true, null, true, null, false);
				UIUtil.DestroyForm(dsf);
				return;
			}
			UIUtil.DestroyForm(dsf);

			// AutoEnableVisualHiding();

			PwGroup pg = new PwGroup(true, true, KPRes.General, PwIcon.Folder);
			// for(int i = 0; i < 30; ++i) pg.CustomData.Set("Test" + i.ToString("D2"), "12345");
			pd.RootGroup.AddGroup(pg, true);

			pg = new PwGroup(true, true, KPRes.WindowsOS, PwIcon.DriveWindows);
			pd.RootGroup.AddGroup(pg, true);

			pg = new PwGroup(true, true, KPRes.Network, PwIcon.NetworkServer);
			pd.RootGroup.AddGroup(pg, true);

			pg = new PwGroup(true, true, KPRes.Internet, PwIcon.World);
			// pg.CustomData.Set("GroupTestItem", "TestValue");
			pd.RootGroup.AddGroup(pg, true);

			pg = new PwGroup(true, true, KPRes.EMail, PwIcon.EMail);
			pd.RootGroup.AddGroup(pg, true);

			pg = new PwGroup(true, true, KPRes.Homebanking, PwIcon.Homebanking);
			pd.RootGroup.AddGroup(pg, true);

			PwEntry pe = new PwEntry(true, true);
			pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pd.MemoryProtection.ProtectTitle,
				KPRes.SampleEntry));
			pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pd.MemoryProtection.ProtectUserName,
				KPRes.UserName));
			pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pd.MemoryProtection.ProtectUrl,
				PwDefs.HomepageUrl));
			pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pd.MemoryProtection.ProtectPassword,
				KPRes.Password));
			pe.Strings.Set(PwDefs.NotesField, new ProtectedString(pd.MemoryProtection.ProtectNotes,
				KPRes.Notes));
			pe.AutoType.Add(new AutoTypeAssociation(KPRes.TargetWindow,
				@"{USERNAME}{TAB}{PASSWORD}{TAB}{ENTER}"));
			// for(int i = 0; i < 30; ++i) pe.CustomData.Set("Test" + i.ToString("D2"), "12345");
			pd.RootGroup.AddEntry(pe, true);

			pe = new PwEntry(true, true);
			pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pd.MemoryProtection.ProtectTitle,
				KPRes.SampleEntry + " #2"));
			pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pd.MemoryProtection.ProtectUserName,
				"Michael321"));
			pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pd.MemoryProtection.ProtectUrl,
				@"http://keepass.info/help/kb/testform.html"));
			pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pd.MemoryProtection.ProtectPassword,
				"12345"));
			pe.AutoType.Add(new AutoTypeAssociation("*Test Form - KeePass*", string.Empty));
			pd.RootGroup.AddEntry(pe, true);

#if DEBUG
			Random r = Program.GlobalRandom;
			long lTimeMin = (new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc)).ToBinary();
			long lTimeMax = (new DateTime(2030, 11, 25, 11, 58, 58, DateTimeKind.Utc)).ToBinary();
			Debug.Assert(lTimeMin < lTimeMax);
			PwProfile prf = new PwProfile();
			prf.CharSet = new PwCharSet(PwCharSet.UpperCase + PwCharSet.LowerCase +
				PwCharSet.Digits + PwCharSet.PrintableAsciiSpecial);
			prf.GeneratorType = PasswordGeneratorType.CharSet;
			for(uint iSamples = 0; iSamples < 1500; ++iSamples)
			{
				pg = pd.RootGroup.Groups.GetAt(iSamples % 5);

				pe = new PwEntry(true, true);

				ProtectedString ps;
				PwGenerator.Generate(out ps, prf, null, null);
				pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pd.MemoryProtection.ProtectTitle,
					ps.ReadString()));
				PwGenerator.Generate(out ps, prf, null, null);
				pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pd.MemoryProtection.ProtectUserName,
					ps.ReadString()));
				PwGenerator.Generate(out ps, prf, null, null);
				pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pd.MemoryProtection.ProtectUrl,
					ps.ReadString()));
				PwGenerator.Generate(out ps, prf, null, null);
				pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pd.MemoryProtection.ProtectPassword,
					ps.ReadString()));
				PwGenerator.Generate(out ps, prf, null, null);
				pe.Strings.Set(PwDefs.NotesField, new ProtectedString(pd.MemoryProtection.ProtectNotes,
					ps.ReadString()));

				pe.CreationTime = DateTime.FromBinary(lTimeMin + (long)(r.NextDouble() *
					(lTimeMax - lTimeMin)));
				pe.LastModificationTime = DateTime.FromBinary(lTimeMin + (long)(r.NextDouble() *
					(lTimeMax - lTimeMin)));
				pe.LastAccessTime = DateTime.FromBinary(lTimeMin + (long)(r.NextDouble() *
					(lTimeMax - lTimeMin)));
				pe.ExpiryTime = DateTime.FromBinary(lTimeMin + (long)(r.NextDouble() *
					(lTimeMax - lTimeMin)));
				pe.LocationChanged = DateTime.FromBinary(lTimeMin + (long)(r.NextDouble() *
					(lTimeMax - lTimeMin)));

				pe.IconId = (PwIcon)r.Next(0, (int)PwIcon.Count);

				pg.AddEntry(pe, true);
			}

			pd.CustomData.Set("Sample Custom Data 1", "0123456789");
			pd.CustomData.Set("Sample Custom Data 2", "\u00B5y data");

			// pd.PublicCustomData.SetString("Sample Custom Data", "Sample Value");
#endif

			UpdateUI(true, null, true, null, true, null, true);

			if(this.FileCreated != null)
			{
				FileCreatedEventArgs ea = new FileCreatedEventArgs(pd);
				this.FileCreated(this, ea);
			}
		}
Esempio n. 5
0
 private void OnKPDBOpen(object sender, FileCreatedEventArgs e)
 {
     EnsureDBIconIsInKPRPCIconCache();
     //KeePassRPCService.ensureDBisOpenEWH.Set(); // signal that DB is now open so any waiting JSONRPC thread can go ahead
     SignalAllManagedRPCClients(KeePassRPC.DataExchangeModel.Signal.DATABASE_OPEN);
 }
 /// <summary>
 /// Handler for when a database file is created by KeePass.  For some
 /// reason, the open event doesn't fire when a new database is created,
 /// so we must enable menu options after a file is created.
 /// </summary>
 /// <param name="sender">Information about the sender.</param>
 /// <param name="e">Event information.</param>
 private void OnFileCreated(object sender, FileCreatedEventArgs e)
 {
     m_backupNowToolItem.Enabled = true;
 }
Esempio n. 7
0
        private void OnFileNew(object sender, EventArgs e)
        {
            if(!AppPolicy.Try(AppPolicyId.SaveFile)) return;

            // OnFileClose(sender, e);
            // if(m_pwDatabase.IsOpen) return;

            SaveFileDialog sfd = UIUtil.CreateSaveFileDialog(KPRes.CreateNewDatabase,
                KPRes.NewDatabaseFileName, UIUtil.CreateFileTypeFilter("kdbx",
                KPRes.KdbxFiles, true), 1, "kdbx", false);

            GlobalWindowManager.AddDialog(sfd);
            DialogResult dr = sfd.ShowDialog();
            GlobalWindowManager.RemoveDialog(sfd);

            string strPath = sfd.FileName;

            if(dr != DialogResult.OK) return;

            KeyCreationForm kcf = new KeyCreationForm();
            kcf.InitEx(true, strPath);
            dr = kcf.ShowDialog();
            if((dr == DialogResult.Cancel) || (dr == DialogResult.Abort)) return;

            DocumentStateEx dsPrevActive = m_docMgr.ActiveDocument;
            PwDatabase pd = m_docMgr.CreateNewDocument(true).Database;
            pd.New(IOConnectionInfo.FromPath(strPath), kcf.CompositeKey);

            DatabaseSettingsForm dsf = new DatabaseSettingsForm();
            dsf.InitEx(true, pd);
            dr = dsf.ShowDialog();
            if((dr == DialogResult.Cancel) || (dr == DialogResult.Abort))
            {
                m_docMgr.CloseDatabase(pd);
                m_docMgr.ActiveDocument = dsPrevActive;
                UpdateUI(false, null, true, null, true, null, false);
                return;
            }

            AutoEnableVisualHiding();

            PwGroup pg = new PwGroup(true, true, KPRes.General, PwIcon.Folder);
            pd.RootGroup.AddGroup(pg, true);

            pg = new PwGroup(true, true, KPRes.WindowsOS, PwIcon.DriveWindows);
            pd.RootGroup.AddGroup(pg, true);

            pg = new PwGroup(true, true, KPRes.Network, PwIcon.NetworkServer);
            pd.RootGroup.AddGroup(pg, true);

            pg = new PwGroup(true, true, KPRes.Internet, PwIcon.World);
            pd.RootGroup.AddGroup(pg, true);

            pg = new PwGroup(true, true, KPRes.EMail, PwIcon.EMail);
            pd.RootGroup.AddGroup(pg, true);

            pg = new PwGroup(true, true, KPRes.Homebanking, PwIcon.Homebanking);
            pd.RootGroup.AddGroup(pg, true);

            PwEntry pe = new PwEntry(true, true);
            pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pd.MemoryProtection.ProtectTitle,
                KPRes.SampleEntry));
            pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pd.MemoryProtection.ProtectUserName,
                KPRes.UserName));
            pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pd.MemoryProtection.ProtectUrl,
                @"http://www.somesite.com/"));
            pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pd.MemoryProtection.ProtectPassword,
                KPRes.Password));
            pe.Strings.Set(PwDefs.NotesField, new ProtectedString(pd.MemoryProtection.ProtectNotes,
                KPRes.Notes));
            pe.AutoType.Set(KPRes.TargetWindow, @"{USERNAME}{TAB}{PASSWORD}{TAB}{ENTER}");
            pd.RootGroup.AddEntry(pe, true);

            #if DEBUG
            Random r = Program.GlobalRandom;
            for(uint iSamples = 0; iSamples < 1500; ++iSamples)
            {
                pg = pd.RootGroup.Groups.GetAt(iSamples % 5);

                pe = new PwEntry(true, true);

                pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pd.MemoryProtection.ProtectTitle,
                    Guid.NewGuid().ToString()));
                pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pd.MemoryProtection.ProtectUserName,
                    Guid.NewGuid().ToString()));
                pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pd.MemoryProtection.ProtectUrl,
                    Guid.NewGuid().ToString()));
                pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pd.MemoryProtection.ProtectPassword,
                    Guid.NewGuid().ToString()));
                pe.Strings.Set(PwDefs.NotesField, new ProtectedString(pd.MemoryProtection.ProtectNotes,
                    Guid.NewGuid().ToString()));

                pe.IconId = (PwIcon)r.Next(0, (int)PwIcon.Count);

                pg.AddEntry(pe, true);
            }
            #endif

            UpdateUI(true, null, true, null, true, null, true);

            if(this.FileCreated != null)
            {
                FileCreatedEventArgs ea = new FileCreatedEventArgs(pd);
                this.FileCreated(this, ea);
            }
        }