From 99498ed660c1ea16aac42f3a387739efdde466e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miskolczi=20Rich=C3=A1rd?= Date: Fri, 24 Mar 2023 14:03:09 +0100 Subject: [PATCH] I'm literally on fire rn --- .../DesignTimeBuild/.dtbcache.v2 | Bin 96557 -> 96557 bytes .vs/Password Manager/v17/.suo | Bin 54272 -> 62976 bytes Password Manager/Fields.cs | 10 ------ Password Manager/MainForm.Designer.cs | 20 ++++++------ Password Manager/MainForm.cs | 18 ++--------- Password Manager/NewProfileForm.Designer.cs | 12 +++++--- Password Manager/NewProfileForm.cs | 23 +++++++++++++- Password Manager/ProfileHandler.cs | 16 ++++++++++ Password Manager/Program.cs | 8 +++-- Password Manager/ResultListBox.cs | 29 ++++++++++++++---- 10 files changed, 85 insertions(+), 51 deletions(-) delete mode 100644 Password Manager/Fields.cs create mode 100644 Password Manager/ProfileHandler.cs diff --git a/.vs/Password Manager/DesignTimeBuild/.dtbcache.v2 b/.vs/Password Manager/DesignTimeBuild/.dtbcache.v2 index cea98f0909ab8c5c1a6db168b33969213ca9c552..659f5ccbd2b92c96d7b0fc5cd592e157b44f5b2b 100644 GIT binary patch delta 146 zcmZ4ciFNHKRwfRHiA;VDiI%3u$!QiA7Dh?QrWR?&sfH%r%?whFO_R)wj8e^$ zk}OS4l2Q%L4K0CECZ;B7sfK3eMiwb1iK#{tCrHRM85=W5Ip^o(q$Za*<|XD-R;3md kyQCIprssuZ=B7@*_(N)PL9+j3qh#@BcgF4RjEv990lE$=AOHXW diff --git a/.vs/Password Manager/v17/.suo b/.vs/Password Manager/v17/.suo index 239d30e6e43df6dec48b8a04773f04a3cc41159e..51f1b4eef8dfd0eb88a761d11dfc45ef177f7ad9 100644 GIT binary patch delta 7542 zcmeGg3s{s@_P;X&4DoP~aU4d}0a+vi{D&D{N;1HRfPjNymSGGEC^>>V1Nm;icV({r zr?%bw%#?J~tu13T*Il(iwC|HGl(MaCS1mKObYD0^SY1vEzZ1gF8*;32|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-U1}UTNQdp(w)BC2uH(UcE#ET$|7`=n;NM1P z_K&Xo^riaYcYaa+O5fSv%N8oGEPiTJ>*t&2&Doz&JhgJFD=T6f@ahW#;es4O`c}IF Md}6deH2pp6KMq_@I{*Lx diff --git a/Password Manager/Fields.cs b/Password Manager/Fields.cs deleted file mode 100644 index e9d82c3..0000000 --- a/Password Manager/Fields.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; - -namespace Password_Manager -{ - static class Fields - { - public static Profile CurrentProfile; - public static ProfileList ListOfProfiles; - } -} diff --git a/Password Manager/MainForm.Designer.cs b/Password Manager/MainForm.Designer.cs index a8d5bb5..cf66e95 100644 --- a/Password Manager/MainForm.Designer.cs +++ b/Password Manager/MainForm.Designer.cs @@ -42,19 +42,20 @@ searchBox.PlaceholderText = "Search for a password"; searchBox.Size = new Size(257, 27); searchBox.TabIndex = 0; - searchBox.TextChanged += UpdateResultList; + searchBox.TextChanged += resultList.ReloadResults; // // resultList // resultList.FormattingEnabled = true; resultList.ItemHeight = 20; - resultList.Location = new Point(12, 99); + resultList.Location = new Point(12, 60); resultList.Name = "resultList"; - resultList.Size = new Size(150, 104); + resultList.Size = new Size(257, 364); resultList.TabIndex = 1; // // profileSelection // + profileSelection.DisplayMember = "Name"; profileSelection.DropDownHeight = 100; profileSelection.DropDownWidth = 200; profileSelection.FormattingEnabled = true; @@ -63,7 +64,7 @@ profileSelection.Name = "profileSelection"; profileSelection.Size = new Size(200, 28); profileSelection.TabIndex = 2; - profileSelection.SelectedIndexChanged += ClearSearchBox; + profileSelection.SelectedIndexChanged += ProfileHandler.ProfileChange; // // addProfile // @@ -74,12 +75,11 @@ addProfile.Text = "Add"; addProfile.UseVisualStyleBackColor = true; addProfile.Click += AddProfile; - // - // button2 + // removeProfile // removeProfile.Location = new Point(691, 60); - removeProfile.Name = "button2"; + removeProfile.Name = "removeProfile"; removeProfile.Size = new Size(95, 29); removeProfile.TabIndex = 4; removeProfile.Text = "Delete"; @@ -96,7 +96,7 @@ Controls.Add(resultList); Controls.Add(searchBox); Name = "MainForm"; - Text = "Form1"; + Text = "Password Manager"; ResumeLayout(false); PerformLayout(); } @@ -106,7 +106,7 @@ public TextBox searchBox; public ResultListBox resultList; public ComboBox profileSelection; - private Button addProfile; - private Button removeProfile; + public Button addProfile; + public Button removeProfile; } } \ No newline at end of file diff --git a/Password Manager/MainForm.cs b/Password Manager/MainForm.cs index c297d1f..d33ce4c 100644 --- a/Password Manager/MainForm.cs +++ b/Password Manager/MainForm.cs @@ -10,23 +10,9 @@ namespace Password_Manager private void ChangeProfile(object sender, EventArgs e) { ComboBox cb = (ComboBox)sender; - Fields.CurrentProfile = Fields.ListOfProfiles.SearchByName(cb.Text); - } - - private void ClearSearchBox(object sender, EventArgs e) //needed because declaring an anonymous method and subscribing that onto the delegate didn't work for some reason - { + ProfileHandler.CurrentProfile = ProfileHandler.ListOfProfiles.SearchByName(cb.Text); searchBox.Clear(); - } - - private void UpdateResultList(object sender, EventArgs args) - { - resultList.Refresh(); - } - - private void ProfileChange(object sender, EventArgs e) - { - searchBox.Clear(); - resultList.Refresh(); + this.Text = ProfileHandler.CurrentProfile == null ? "Password Manager" : $"Current profile: {ProfileHandler.CurrentProfile.Name}"; } private void AddProfile(object sender, EventArgs e) diff --git a/Password Manager/NewProfileForm.Designer.cs b/Password Manager/NewProfileForm.Designer.cs index 9aff248..4461b36 100644 --- a/Password Manager/NewProfileForm.Designer.cs +++ b/Password Manager/NewProfileForm.Designer.cs @@ -53,6 +53,7 @@ button2.TabIndex = 1; button2.Text = "Save"; button2.UseVisualStyleBackColor = true; + button2.Click += Save; // // button3 // @@ -62,19 +63,20 @@ button3.TabIndex = 2; button3.Text = "Cancel"; button3.UseVisualStyleBackColor = true; + button3.Click += Cancel; // - // textBox1 + // nameTextBox // nameTextBox.Location = new Point(12, 12); - nameTextBox.Name = "textBox1"; + nameTextBox.Name = "nameTextBox"; nameTextBox.PlaceholderText = "Work"; nameTextBox.Size = new Size(194, 27); nameTextBox.TabIndex = 3; // - // textBox2 + // pathTextBox // pathTextBox.Location = new Point(12, 45); - pathTextBox.Name = "textBox2"; + pathTextBox.Name = "pathTextBox"; pathTextBox.PlaceholderText = "C:\\Passwords"; pathTextBox.Size = new Size(194, 27); pathTextBox.TabIndex = 4; @@ -90,7 +92,7 @@ Controls.Add(button2); Controls.Add(button1); Name = "NewProfileForm"; - Text = "NewProfileForm"; + Text = "Create profile"; ResumeLayout(false); PerformLayout(); } diff --git a/Password Manager/NewProfileForm.cs b/Password Manager/NewProfileForm.cs index d3202ba..7b0407b 100644 --- a/Password Manager/NewProfileForm.cs +++ b/Password Manager/NewProfileForm.cs @@ -18,12 +18,33 @@ namespace Password_Manager } private void ChooseFolder(object sender, EventArgs e) - { + { FolderBrowserDialog dialog = new FolderBrowserDialog(); if (dialog.ShowDialog() == DialogResult.OK) { pathTextBox.Text = dialog.SelectedPath; } } + + private void Save(object sender, EventArgs e) + { + if (nameTextBox.Text != "" && pathTextBox.Text != "") + { + Profile profile = new Profile(nameTextBox.Text, pathTextBox.Text); + ProfileHandler.ListOfProfiles.Add(profile); + ProfileHandler.CurrentProfile = profile; + Program.mainForm.resultList.ReloadResults(); + this.Close(); + } + else + { + MessageBox.Show("You must fill in all fields to continue.", "Error: Empty fields", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void Cancel(object sender, EventArgs e) + { + this.Close(); + } } } diff --git a/Password Manager/ProfileHandler.cs b/Password Manager/ProfileHandler.cs new file mode 100644 index 0000000..dfdc3cd --- /dev/null +++ b/Password Manager/ProfileHandler.cs @@ -0,0 +1,16 @@ +using System; + +namespace Password_Manager +{ + static class ProfileHandler + { + public static Profile CurrentProfile; + public static ProfileList ListOfProfiles; + + public static void ProfileChange(object sender, EventArgs e) + { + Program.mainForm.searchBox.Clear(); + Program.mainForm.resultList.ReloadResults(); + } + } +} diff --git a/Password Manager/Program.cs b/Password Manager/Program.cs index 30bed6f..f0634cd 100644 --- a/Password Manager/Program.cs +++ b/Password Manager/Program.cs @@ -8,9 +8,11 @@ namespace Password_Manager [STAThread] static void Main() { - Fields.ListOfProfiles = new ProfileList(); + ProfileHandler.ListOfProfiles = new ProfileList(); ApplicationConfiguration.Initialize(); - Application.Run(new MainForm()); - } + Application.Run(mainForm); + } + + public static MainForm mainForm = new MainForm(); } } \ No newline at end of file diff --git a/Password Manager/ResultListBox.cs b/Password Manager/ResultListBox.cs index 0a31a23..1cb2027 100644 --- a/Password Manager/ResultListBox.cs +++ b/Password Manager/ResultListBox.cs @@ -6,18 +6,35 @@ namespace Password_Manager { public ResultListBox() : base() { } - public void Refresh() + public void ReloadResults() { - DirectoryInfo d = new DirectoryInfo(Fields.CurrentProfile.Path); //Assuming Test is your Folder + DirectoryInfo d = new DirectoryInfo(ProfileHandler.CurrentProfile.Path); FileInfo[] files = d.GetFiles("*.gpg"); - string[] elements = new string[files.Length]; - - for (int i = 0; i < elements.Length; i++) + string[] arrayTmp = new string[files.Length]; + for (int i = 0; i < arrayTmp.Length; i++) { - elements[i] = files[i].Name; + arrayTmp[i] = files[i].Name; + } + List elements = new List(arrayTmp); + + string[] copy = elements.ToArray(); + if (Program.mainForm.searchBox.Text != "") //we have a search query + { + foreach (string s in copy) + { + if (!s.Contains(Program.mainForm.searchBox.Text)) + { + elements.Remove(s); + } + } } this.DataSource = elements; } + + public void ReloadResults(object o, EventArgs e) //needed so that I can subscribe this method to a delegate in MainForm + { + ReloadResults(); + } } }