I'm literally on fire rn

This commit is contained in:
Miskolczi Richárd
2023-03-24 14:03:09 +01:00
parent b06568fb27
commit 99498ed660
10 changed files with 85 additions and 51 deletions

Binary file not shown.

View File

@@ -1,10 +0,0 @@
using System;
namespace Password_Manager
{
static class Fields
{
public static Profile CurrentProfile;
public static ProfileList ListOfProfiles;
}
}

View File

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

View File

@@ -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)

View File

@@ -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();
}

View File

@@ -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();
}
}
}

View File

@@ -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();
}
}
}

View File

@@ -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();
}
}

View File

@@ -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<string> elements = new List<string>(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();
}
}
}