I don't even know anymore

This commit is contained in:
Miskolczi Richárd
2023-03-24 12:01:08 +01:00
parent 911b3fc819
commit 91c6f339ba
10 changed files with 116 additions and 28 deletions

View File

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

View File

@@ -76,8 +76,8 @@
#endregion
private TextBox searchBox;
private ListBox resultList;
private ComboBox profileSelection;
public TextBox searchBox;
public ListBox resultList;
public ComboBox profileSelection;
}
}

View File

@@ -9,12 +9,15 @@ namespace Password_Manager
private void ChangeProfile(object sender, EventArgs e)
{
ComboBox cb = (ComboBox)sender;
Fields.CurrentProfile = Fields.ListOfProfiles.SearchByName(cb.Text);
}
private void UpdateResultList(object sender, EventArgs args)
{
//TODO:
}
}
}

38
Password Manager/IList.cs Normal file
View File

@@ -0,0 +1,38 @@
using System;
namespace Password_Manager
{
abstract class IList<T>
{
protected T[] list;
public int Length
{
get
{
return list.Length;
}
}
public T this[int index]
{
get
{
return list[index];
}
}
public IList()
{
this.list = new T[0];
}
public abstract void Add(T item);
public abstract void Remove(T item);
public abstract T SearchByName(string name);
public void Clear()
{
list = new T[0];
}
}
}

View File

@@ -0,0 +1,14 @@
using System;
namespace Password_Manager
{
sealed class PasswordListBox : ListBox
{
public PasswordListBox() : base() { }
public void ReadFromPath()
{
//read all files from
}
}
}

View File

@@ -8,6 +8,14 @@ namespace Password_Manager
{
public string Name { get; } //the name of the password store profile ("personal", "work", or similar)
public string Path { get; } //path of the folder containing the password store
private Password[] Passwords;
public event PasswordStoreChange Change; //runs if a new password is added, or if one is removed
public Profile(string name, string path, PasswordStoreChange change)
{
Name = name;
Path = path;
Change = change;
}
}
}

View File

@@ -2,32 +2,12 @@
namespace Password_Manager
{
sealed class ProfileList
sealed class ProfileList : IList<Profile>
{
private Profile[] list;
public int Length
{
get
{
return this.list.Length;
}
}
public ProfileList() : base() { }
public Profile this[int index]
{
get
{
return this.list[index];
}
}
public ProfileList()
{
this.list = new Profile[0];
}
public void Add(Profile p)
public override void Add(Profile p)
{
//grow the list by 1 and copy all existing items
Profile[] tmp = new Profile[this.Length + 1];
@@ -44,7 +24,7 @@ namespace Password_Manager
list[this.Length - 1] = p;
}
public void Remove(Profile p)
public override void Remove(Profile p)
{
Profile[] tmp = new Profile[this.Length - 1];
@@ -58,5 +38,27 @@ namespace Password_Manager
this.list = tmp;
}
public override Profile SearchByName(string name)
{
Profile result = null;
for (int i = 0; i < this.Length; i++)
{
if (this[i].Name == name)
{
result = this[i];
}
}
if (result == null)
{
throw new ProfileNotFoundException();
}
else
{
return result;
}
}
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Runtime.CompilerServices;
namespace Password_Manager
{
sealed class ProfileNotFoundException : Exception
{
public ProfileNotFoundException() : base() { }
public ProfileNotFoundException(string message) : base(message) { }
public ProfileNotFoundException(string message, Exception inner) : base(message, inner) { }
}
}