diff --git a/Password Manager/ConfigFileManager.cs b/Password Manager/ConfigFileManager.cs new file mode 100644 index 0000000..47d2ac7 --- /dev/null +++ b/Password Manager/ConfigFileManager.cs @@ -0,0 +1,75 @@ +using Microsoft.VisualBasic.FileIO; + +namespace Password_Manager +{ + static class ConfigFileManager + { + private static string configPath = SpecialDirectories.CurrentUserApplicationData + "\\config.cfg"; + + #region Config flags + /*Configuration: (format: fieldname=value) + + pwdStorePath: path to the folder which contains the .gpg files + recipient: whose public key to use for encryption when a new password is created + */ + private const char DELIMETER = '='; + private const string RECIPIENT = "recipient"; + private const string PATH = "pwdStorePath"; + + #endregion + public static string GetPath() + { + try + { + StreamReader sr = new StreamReader(configPath); + if (sr != null) + { + while (!sr.EndOfStream) + { + string[]? fields = sr.ReadLine().Split(DELIMETER); + if (fields != null) + { + if (fields[0] == PATH) + { + return fields[1]; + } + } + else + { + continue; + } + } + } + else + { + throw new FileNotFoundException(); + } + } + catch (FileNotFoundException) + { + CreateDefaultConfig(); + } + catch (IOException e) + { + MessageBox.Show(e.ToString(), "IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + return @"C:\Users\Typo\pass"; //TODO: temporary default value + } + + private static void CreateDefaultConfig() + { + try + { + StreamWriter sw = new StreamWriter(configPath); + sw.WriteLine(RECIPIENT + DELIMETER + "typo"); + sw.WriteLine(PATH + DELIMETER + @"C:\Users\Typo\pass"); + sw.Close(); + } + catch (Exception e) + { + MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/Password Manager/GeneratePassword.cs b/Password Manager/GeneratePassword.cs index a2f59e2..bd0ac10 100644 --- a/Password Manager/GeneratePassword.cs +++ b/Password Manager/GeneratePassword.cs @@ -34,10 +34,6 @@ namespace Password_Manager { MessageBox.Show("Please enter a valid number for the password's length.", "Error: Invalid field", MessageBoxButtons.OK, MessageBoxIcon.Error); } - catch (ArgumentNullException error) - { - MessageBox.Show(error.ToString(), "Error: No profile path", MessageBoxButtons.OK, MessageBoxIcon.Error); - } catch (IOException error) { MessageBox.Show(error.ToString(), "IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error); diff --git a/Password Manager/MainForm.Designer.cs b/Password Manager/MainForm.Designer.cs index fada28f..042c779 100644 --- a/Password Manager/MainForm.Designer.cs +++ b/Password Manager/MainForm.Designer.cs @@ -1,6 +1,6 @@ namespace Password_Manager { - sealed partial class MainForm : PasswordManagerForm + sealed partial class MainForm : Form { /// /// Required designer variable. @@ -30,9 +30,6 @@ { SearchBox = new TextBox(); ResultList = new PasswordListBox(); - ProfileSelection = new ComboBox(); - AddProfile = new Button(); - DeleteProfile = new Button(); GeneratePassword = new Button(); SuspendLayout(); // @@ -55,43 +52,6 @@ ResultList.Name = "resultList"; ResultList.Size = new Size(225, 274); ResultList.TabIndex = 1; - ResultList.CurrentProfilePathRequest += () => CurrentProfilePathRequest(); - ResultList.SearchQueryRequest += () => SearchBox.Text; - // - // profileSelection - // - ProfileSelection.DisplayMember = "Name"; - ProfileSelection.DropDownHeight = 100; - ProfileSelection.DropDownWidth = 176; - ProfileSelection.FormattingEnabled = true; - ProfileSelection.IntegralHeight = false; - ProfileSelection.Location = new Point(513, 20); - ProfileSelection.Margin = new Padding(3, 2, 3, 2); - ProfileSelection.Name = "profileSelection"; - ProfileSelection.Size = new Size(176, 23); - ProfileSelection.TabIndex = 2; - ProfileSelection.SelectionChangeCommitted += ChangeProfile; - // - // addProfile - // - AddProfile.Location = new Point(513, 45); - AddProfile.Margin = new Padding(3, 2, 3, 2); - AddProfile.Name = "addProfile"; - AddProfile.Size = new Size(83, 22); - AddProfile.TabIndex = 3; - AddProfile.Text = "Add"; - AddProfile.UseVisualStyleBackColor = true; - AddProfile.Click += OpenProfileCreator; - // - // removeProfile - // - DeleteProfile.Location = new Point(605, 45); - DeleteProfile.Margin = new Padding(3, 2, 3, 2); - DeleteProfile.Name = "removeProfile"; - DeleteProfile.Size = new Size(83, 22); - DeleteProfile.TabIndex = 4; - DeleteProfile.Text = "Delete"; - DeleteProfile.UseVisualStyleBackColor = true; // // button1 // @@ -109,9 +69,6 @@ AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(700, 338); Controls.Add(GeneratePassword); - Controls.Add(DeleteProfile); - Controls.Add(AddProfile); - Controls.Add(ProfileSelection); Controls.Add(ResultList); Controls.Add(SearchBox); Margin = new Padding(3, 2, 3, 2); @@ -123,11 +80,8 @@ #endregion - protected override TextBox SearchBox { get; set; } - protected override PasswordListBox ResultList { get; set; } - protected override ComboBox ProfileSelection { get; set; } - protected override Button AddProfile { get; set; } - protected override Button DeleteProfile { get; set; } - protected override Button GeneratePassword { get; set; } + private TextBox SearchBox; + private PasswordListBox ResultList; + private Button GeneratePassword; } } \ No newline at end of file diff --git a/Password Manager/MainForm.Events.cs b/Password Manager/MainForm.Events.cs deleted file mode 100644 index 41067ce..0000000 --- a/Password Manager/MainForm.Events.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Password_Manager -{ - public sealed partial class MainForm : PasswordManagerForm - { - public override event ProfileDataRequest CurrentProfilePathRequest; - public override event ProfileDataRequest CurrentProfileNameRequest; - public override event ProfileList CurrentProfileListRequest; - public override event ProfileChange CurrentProfileChanged; - public override event Save SaveRequest; - public override event NewProfile NewProfileRequest; - - public MainForm( - ProfileDataRequest CurrentProfileNameRequest, - ProfileDataRequest CurrentProfilePathRequest, - ProfileList CurrentProfileListRequest, - ProfileChange CurrentProfileChanged, - Save SaveRequest, - NewProfile NewProfileRequest) - { - this.CurrentProfileNameRequest = CurrentProfileNameRequest; - this.CurrentProfilePathRequest = CurrentProfilePathRequest; - this.CurrentProfileListRequest = CurrentProfileListRequest; - this.CurrentProfileChanged = CurrentProfileChanged; - this.SaveRequest = SaveRequest; - this.NewProfileRequest = NewProfileRequest; - - InitializeComponent(); - RefreshCurrentProfile(); - SaveRequest(); - } - } -} diff --git a/Password Manager/MainForm.cs b/Password Manager/MainForm.cs index 3b7955f..7d43845 100644 --- a/Password Manager/MainForm.cs +++ b/Password Manager/MainForm.cs @@ -1,51 +1,22 @@ -using System.ComponentModel.Design; - namespace Password_Manager { - sealed public partial class MainForm : PasswordManagerForm + sealed public partial class MainForm : Form { - private void OpenProfileCreator(object sender, EventArgs e) + public event DataRequest PathRequest; + + public MainForm(DataRequest PathRequest) { - NewProfileForm npf = new NewProfileForm(); - npf.ReloadMainFormRequest += () => RefreshCurrentProfile(); - npf.SaveRequest += this.SaveRequest; - npf.NewProfileRequest += this.NewProfileRequest; - npf.ShowDialog(); + this.PathRequest = PathRequest; + InitializeComponent(); + + ResultList = new PasswordListBox(PathRequest); + ResultList.ReloadResults(); } private void OpenPasswordGenerator(object sender, EventArgs e) { - string? tmp = CurrentProfilePathRequest(); - if (tmp != null) - { - GeneratePassword gp = new GeneratePassword(SearchBox.Text, tmp); - gp.ShowDialog(); - } - else - { - MessageBox.Show("No path specified", "Event error", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - protected override void ChangeProfile(object sender, EventArgs e) - { - CurrentProfileChanged(ProfileSelection.Text); - } - - public override void RefreshCurrentProfile() - { - ProfileSelection.SelectedIndex = -1; - string[] items = CurrentProfileListRequest(); - for (int i = 0; i < items.Length; i++) - { - ProfileSelection.Items.Add(items[i]); - if (items[i] == CurrentProfileNameRequest()) - { - ProfileSelection.SelectedIndex = i; - } - } - this.Text = CurrentProfileNameRequest(); - ResultList.ReloadResults(); + GeneratePassword gp = new GeneratePassword(SearchBox.Text, PathRequest()); + gp.ShowDialog(); } } } \ No newline at end of file diff --git a/Password Manager/NewProfileForm.Designer.cs b/Password Manager/NewProfileForm.Designer.cs deleted file mode 100644 index 4461b36..0000000 --- a/Password Manager/NewProfileForm.Designer.cs +++ /dev/null @@ -1,108 +0,0 @@ -namespace Password_Manager -{ - partial class NewProfileForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - button1 = new Button(); - button2 = new Button(); - button3 = new Button(); - nameTextBox = new TextBox(); - pathTextBox = new TextBox(); - SuspendLayout(); - // - // button1 - // - button1.Location = new Point(212, 45); - button1.Name = "button1"; - button1.Size = new Size(94, 29); - button1.TabIndex = 0; - button1.Text = "Browse"; - button1.UseVisualStyleBackColor = true; - button1.Click += ChooseFolder; - // - // button2 - // - button2.Location = new Point(161, 78); - button2.Name = "button2"; - button2.Size = new Size(145, 29); - button2.TabIndex = 1; - button2.Text = "Save"; - button2.UseVisualStyleBackColor = true; - button2.Click += Save; - // - // button3 - // - button3.Location = new Point(12, 78); - button3.Name = "button3"; - button3.Size = new Size(145, 29); - button3.TabIndex = 2; - button3.Text = "Cancel"; - button3.UseVisualStyleBackColor = true; - button3.Click += Cancel; - // - // nameTextBox - // - nameTextBox.Location = new Point(12, 12); - nameTextBox.Name = "nameTextBox"; - nameTextBox.PlaceholderText = "Work"; - nameTextBox.Size = new Size(194, 27); - nameTextBox.TabIndex = 3; - // - // pathTextBox - // - pathTextBox.Location = new Point(12, 45); - pathTextBox.Name = "pathTextBox"; - pathTextBox.PlaceholderText = "C:\\Passwords"; - pathTextBox.Size = new Size(194, 27); - pathTextBox.TabIndex = 4; - // - // NewProfileForm - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(317, 127); - Controls.Add(pathTextBox); - Controls.Add(nameTextBox); - Controls.Add(button3); - Controls.Add(button2); - Controls.Add(button1); - Name = "NewProfileForm"; - Text = "Create profile"; - ResumeLayout(false); - PerformLayout(); - } - - #endregion - - private Button button1; - private Button button2; - private Button button3; - private TextBox nameTextBox; - private TextBox pathTextBox; - } -} \ No newline at end of file diff --git a/Password Manager/NewProfileForm.cs b/Password Manager/NewProfileForm.cs deleted file mode 100644 index bcff44a..0000000 --- a/Password Manager/NewProfileForm.cs +++ /dev/null @@ -1,45 +0,0 @@ -namespace Password_Manager -{ - public delegate void ReloadPasswords(); - public partial class NewProfileForm : Form - { - public event NewProfile? NewProfileRequest; - public event ReloadPasswords? ReloadMainFormRequest; - public event Save? SaveRequest; - - public NewProfileForm() - { - InitializeComponent(); - } - - 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 != "") - { - NewProfileRequest?.Invoke(nameTextBox.Text, pathTextBox.Text); - ReloadMainFormRequest?.Invoke(); - this.Close(); - } - else - { - MessageBox.Show("You must fill in all fields to continue.", "Error: Empty fields", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - - SaveRequest?.Invoke(); - } - - private void Cancel(object sender, EventArgs e) - { - this.Close(); - } - } -} diff --git a/Password Manager/NewProfileForm.resx b/Password Manager/NewProfileForm.resx deleted file mode 100644 index f298a7b..0000000 --- a/Password Manager/NewProfileForm.resx +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/Password Manager/Password Manager.csproj.user b/Password Manager/Password Manager.csproj.user index ae9bc42..1516df6 100644 --- a/Password Manager/Password Manager.csproj.user +++ b/Password Manager/Password Manager.csproj.user @@ -7,17 +7,8 @@ Form - - Form - - - Form - Component - - Form - \ No newline at end of file diff --git a/Password Manager/PasswordListBox.cs b/Password Manager/PasswordListBox.cs index c5773a4..bf50d17 100644 --- a/Password Manager/PasswordListBox.cs +++ b/Password Manager/PasswordListBox.cs @@ -1,24 +1,42 @@ -namespace Password_Manager +using System.Runtime.CompilerServices; + +namespace Password_Manager { public delegate string SearchQuery(); public class PasswordListBox : ListBox { - public event ProfileDataRequest? CurrentProfilePathRequest; + public event DataRequest? PathRequest; public event SearchQuery? SearchQueryRequest; - public PasswordListBox() : base() { } + public PasswordListBox(DataRequest PathRequest, SearchQuery? SearchQueryRequest = null) : base() + { + this.PathRequest = PathRequest; + this.SearchQueryRequest = SearchQueryRequest; + } - public void ReloadResults(object sender = null, EventArgs arg = null) + public PasswordListBox() : base() { } + /*do not instantiate this class using this constructor if you want to use the ReloadResults method afterwards. + Use this so that the MainForm.Designer.cs file doesn't have a stroke due to Event References, then re-instantiate the object + afterwards using the other constructor*/ + + public void ReloadResults(object? sender = null, EventArgs? arg = null) { DirectoryInfo d; FileInfo[] files = new FileInfo[0]; try { - d = new DirectoryInfo(CurrentProfilePathRequest?.Invoke()); + if (PathRequest != null) + { + d = new DirectoryInfo(PathRequest()); + } + else + { + throw new InvalidOperationException("You cannot use this method if you instantiated the object using the parameterless constructor"); + } files = d.GetFiles("*.gpg"); } catch (ArgumentNullException e) { - MessageBox.Show(e.ToString(), "Error: Invalid profile path", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(e.ToString(), "Error: Invalid path", MessageBoxButtons.OK, MessageBoxIcon.Error); } string[] arrayTmp = new string[files.Length]; @@ -29,8 +47,8 @@ List elements = new List(arrayTmp); string[] copy = elements.ToArray(); - string searchQuery = SearchQueryRequest?.Invoke(); - if (searchQuery != "") //we have a search query + string? searchQuery = SearchQueryRequest?.Invoke(); + if (searchQuery != null) //we have a search query { foreach (string s in copy) { diff --git a/Password Manager/PasswordManagerForm.cs b/Password Manager/PasswordManagerForm.cs deleted file mode 100644 index a26b545..0000000 --- a/Password Manager/PasswordManagerForm.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace Password_Manager -{ - public delegate void ProfileChange(string profileName); //Fires when we want to change the CurrentProfile field of ProfileHandler based on the combobox selection - public delegate string[] ProfileList(); //Fires when we need a list of Profile names, like for the combobox items - public delegate void Save(); //Fire whenever we want to save the current state of profiles - public delegate void NewProfile(string profileName, string profilePath); //Fires whenever a NewProfileForm has requested the creation of a new profile. This just forwards that request to ProfileHandler - - public abstract class PasswordManagerForm : Form - { - protected abstract ComboBox ProfileSelection { get; set; } - protected abstract PasswordListBox ResultList { get; set; } - protected abstract TextBox SearchBox { get; set; } - protected abstract Button AddProfile { get; set; } - protected abstract Button DeleteProfile { get; set; } - protected abstract Button GeneratePassword { get; set; } - - public abstract event ProfileDataRequest CurrentProfilePathRequest; - public abstract event ProfileDataRequest CurrentProfileNameRequest; - public abstract event ProfileList CurrentProfileListRequest; - public abstract event ProfileChange CurrentProfileChanged; - public abstract event Save SaveRequest; - public abstract event NewProfile NewProfileRequest; - - - protected abstract void ChangeProfile(object sender, EventArgs e); - public abstract void RefreshCurrentProfile(); - } -} diff --git a/Password Manager/Profiles/IList.cs b/Password Manager/Profiles/IList.cs deleted file mode 100644 index bfba39f..0000000 --- a/Password Manager/Profiles/IList.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System.Collections; - -namespace Profiles -{ - abstract class IList : IEnumerable - { - 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]; - } - - public IEnumerator GetEnumerator() - { - return ((IEnumerable)list).GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return list.GetEnumerator(); - } - } -} diff --git a/Password Manager/Profiles/Profile.cs b/Password Manager/Profiles/Profile.cs deleted file mode 100644 index fcbec87..0000000 --- a/Password Manager/Profiles/Profile.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace Profiles -{ - public sealed class Profile - { - 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 - //public event PasswordStoreChange Change; //runs if a new password is added, or if one is removed - - public Profile(string name, string path) - { - Name = name; - Path = path; - //Change = change; - } - } -} diff --git a/Password Manager/Profiles/ProfileHandler.cs b/Password Manager/Profiles/ProfileHandler.cs deleted file mode 100644 index df0fc6b..0000000 --- a/Password Manager/Profiles/ProfileHandler.cs +++ /dev/null @@ -1,142 +0,0 @@ -using Password_Manager; -using Microsoft.VisualBasic.FileIO; - -namespace Profiles -{ - static class ProfileHandler - { - public static Profile CurrentProfile; - public static ProfileList ListOfProfiles; - private static string filePath = SpecialDirectories.CurrentUserApplicationData + "\\Profiles.csv"; - - public static void AddProfile(string profileName, string profilePath) - { - ListOfProfiles.Add(new Profile(profileName, profilePath)); - ChangeProfiles(profileName); - } - - public static void ChangeProfiles(string profileName) - { - try - { - CurrentProfile = ListOfProfiles.SearchByName(profileName); - } catch (ProfileNotFoundException) - { - MessageBox.Show("The selected profile cannot be found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - public static void Init() - { - ListOfProfiles = new ProfileList(); - - if (File.Exists(filePath)) - { - LoadProfilesFile(); - } - else - { - CreateProfilesFile(); - } - } - private static void LoadProfilesFile() - { - try - { - StreamReader sr = new StreamReader(filePath); - string[] lines = sr.ReadToEnd().Split("\n"); - foreach (string line in lines) - { - string[] fields = line.Split(','); - try - { - ListOfProfiles.Add(new Profile(fields[0], fields[1])); - } catch (IndexOutOfRangeException) - { - //File is messed up, creating new one - sr.Close(); - CreateProfilesFile(); - break; - } - } - sr.Close(); - } catch (IOException e) - { - MessageBox.Show(e.ToString(), "IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private static void TrimLastLine() - { - try - { - StreamReader sr = new StreamReader(filePath); - List validLines = new List(); - - while (!sr.EndOfStream) - { - string? line = sr.ReadLine(); - if (line != null) - { - validLines.Add(line); - } - } - - sr.Close(); - File.WriteAllLines(filePath, validLines); - } catch (IOException e) - { - MessageBox.Show(e.ToString(), "IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - } catch (UnauthorizedAccessException e) - { - MessageBox.Show(e.ToString(), "Can't access profiles file", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - public static void SaveProfiles() - { - try - { - StreamWriter sw = new StreamWriter(filePath); - - foreach (Profile p in ListOfProfiles) - { - sw.WriteLine($"{p.Name},{p.Path}"); - } - - sw.Close(); - } catch (IOException e) - { - MessageBox.Show(e.ToString(), "IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - } catch (UnauthorizedAccessException e) - { - MessageBox.Show(e.ToString(), "Can't access profiles file", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private static void CreateProfilesFile() - { - try - { - StreamWriter sw = new StreamWriter(filePath); - - string[] parameters = new string[2]; - - NewProfileForm np = new NewProfileForm(); - np.NewProfileRequest += (string profileName, string profilePath) => - { - Profile firstProfile = new Profile(profileName, profilePath); - ListOfProfiles.Add(firstProfile); - ChangeProfiles(firstProfile.Name); - sw.WriteLine($"{firstProfile.Name},{firstProfile.Path}"); - sw.Close(); - TrimLastLine(); - }; - np.ShowDialog(); - } catch (IOException e) - { - MessageBox.Show(e.ToString(), "IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } -} diff --git a/Password Manager/Profiles/ProfileList.cs b/Password Manager/Profiles/ProfileList.cs deleted file mode 100644 index 5bc1a3c..0000000 --- a/Password Manager/Profiles/ProfileList.cs +++ /dev/null @@ -1,71 +0,0 @@ -namespace Profiles -{ - sealed class ProfileList : IList - { - public ProfileList() : base() { } - - public override void Add(Profile p) - { - //grow the list by 1 and copy all existing items - Profile[] tmp = new Profile[this.Length + 1]; - - for (int i = 0; i < this.Length; i++) - { - tmp[i] = this[i]; - } - - this.list = tmp; - - //-------------------------------------------------------- - - list[this.Length - 1] = p; - } - - public override void Remove(Profile p) - { - Profile[] tmp = new Profile[this.Length - 1]; - - for (int i = 0; i < tmp.Length; i++) - { - if (this[i] != p) - { - tmp[i] = this[i]; - } - } - - 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; - } - } - - public string[] GetNameList() - { - string[] array = new string[this.Length]; - for (int i = 0; i < this.Length; i++) - { - array[i] = this[i].Name; - } - return array; - } - } -} diff --git a/Password Manager/Profiles/ProfileNotFoundException.cs b/Password Manager/Profiles/ProfileNotFoundException.cs deleted file mode 100644 index afcffd5..0000000 --- a/Password Manager/Profiles/ProfileNotFoundException.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Profiles -{ - sealed class ProfileNotFoundException : Exception - { - public ProfileNotFoundException() : base() { } - public ProfileNotFoundException(string message) : base(message) { } - public ProfileNotFoundException(string message, Exception inner) : base(message, inner) { } - - } -} diff --git a/Password Manager/Program.cs b/Password Manager/Program.cs index 5105163..21184a6 100644 --- a/Password Manager/Program.cs +++ b/Password Manager/Program.cs @@ -1,8 +1,6 @@ -using Profiles; - namespace Password_Manager { - public delegate string ProfileDataRequest(); //Fire whenever a specific field of ProfileHandler.CurrentProfile is needed + public delegate string DataRequest(); //Fire whenever a specific field of ProfileHandler.CurrentProfile is needed internal static class Program { /// @@ -12,17 +10,11 @@ namespace Password_Manager static void Main() { ApplicationConfiguration.Initialize(); - ProfileHandler.Init(); Application.Run(mainForm); } public static MainForm mainForm = new MainForm( - () => ProfileHandler.CurrentProfile.Name, - () => ProfileHandler.CurrentProfile.Path, - () => ProfileHandler.ListOfProfiles.GetNameList(), - (profileName) => ProfileHandler.ChangeProfiles(profileName), - () => ProfileHandler.SaveProfiles(), - (profileName, profilePath) => ProfileHandler.AddProfile(profileName, profilePath) + () => ConfigFileManager.GetPath() ); //needed at creation so that MainForm may pass this method down to other classes in its constructor } } \ No newline at end of file