diff --git a/1P2KeePass/1P2KeePass.csproj b/1P2KeePass/1P2KeePass.csproj index a238676..327b18a 100644 --- a/1P2KeePass/1P2KeePass.csproj +++ b/1P2KeePass/1P2KeePass.csproj @@ -43,6 +43,7 @@ Newtonsoft.Json.dll false + diff --git a/1P2KeePass/1P2KeePass.csproj.user b/1P2KeePass/1P2KeePass.csproj.user index 7faa659..0436969 100644 --- a/1P2KeePass/1P2KeePass.csproj.user +++ b/1P2KeePass/1P2KeePass.csproj.user @@ -2,7 +2,7 @@ Program - Y:\Projects\Plugin.1P2KeePass\KeePassDistribution\KeePass.exe - Y:\Projects\Plugin.1P2KeePass\KeePassDistribution\ + D:\Dev\git\1P2KeePass\KeePassDistribution\KeePass.exe + D:\Dev\git\1P2KeePass\KeePassDistribution\ \ No newline at end of file diff --git a/1P2KeePass/Plugin/Controllers/PIFImporter.cs b/1P2KeePass/Plugin/Controllers/PIFImporter.cs index cc2d236..48dfcfe 100644 --- a/1P2KeePass/Plugin/Controllers/PIFImporter.cs +++ b/1P2KeePass/Plugin/Controllers/PIFImporter.cs @@ -7,34 +7,119 @@ namespace _1Password2KeePass { + public class subfolder + { + public subfolder() { } + + public String folderName { get; set; } + public PwIcon folderIcon { get; set; } + public List recordList { get; set; } + } + public class PIFImporter { - public void Import(List baseRecords, PwDatabase storage, IStatusLogger status) + public void Import(List baseRecords, PwDatabase storage, IStatusLogger status, bool createSubfolders = false) { - var records = new List(); - var trashedRecords = new List(); - baseRecords.ForEach(record => + var loginRecords = new List(); + var walletRecords = new List(); + var accountsRecords = new List(); + var softwareRecords = new List(); + var secureNoteRecords = new List(); + var identityRecords = new List(); + var RecordsList = new List(); + + var records = new List(); + var trashedRecords = new List(); + + if ( createSubfolders) + { + RecordsList.Add(new subfolder { folderName = "Logins", folderIcon = PwIcon.World, recordList = loginRecords }); + RecordsList.Add(new subfolder { folderName = "Wallet", folderIcon = PwIcon.Money, recordList = walletRecords }); + RecordsList.Add(new subfolder { folderName = "Accounts", folderIcon = PwIcon.NetworkServer, recordList = accountsRecords }); + RecordsList.Add(new subfolder { folderName = "Software", folderIcon = PwIcon.MultiKeys, recordList = softwareRecords }); + RecordsList.Add(new subfolder { folderName = "Secure Notes", folderIcon = PwIcon.Notepad, recordList = secureNoteRecords }); + RecordsList.Add(new subfolder { folderName = "identites", folderIcon = PwIcon.Identity, recordList = identityRecords }); + } + + baseRecords.ForEach(record => { if (record.trashed) + { trashedRecords.Add(record); + } else - records.Add(record); + { + if (!createSubfolders) + { + records.Add(record); + } + else + { + if (record.GetType() == typeof(WebFormRecord)) + { + loginRecords.Add(record); + } + else if ( record.GetType() == typeof(BankAccountRecord) + || record.GetType() == typeof(CreditCardRecord) + || record.GetType() == typeof(MembershipRecord) + || record.GetType() == typeof(SocialSecurityNumberRecord) ) + { + walletRecords.Add(record); + } + else if ( record.GetType() == typeof(DatabaseConnectionRecord) + || record.GetType() == typeof(EmailAccountRecord) + || record.GetType() == typeof(FtpAccountRecord) + || record.GetType() == typeof(GenericAccountRecord) + || record.GetType() == typeof(UnixServerRecord) + || record.GetType() == typeof(RouterRecord) ) + { + accountsRecords.Add(record); + } + else if (record.GetType() == typeof(ComputerLicenseRecord)) + { + softwareRecords.Add(record); + } + else if (record.GetType() == typeof(SecureNoteRecord)) + { + secureNoteRecords.Add(record); + } + else if (record.GetType() == typeof(IndentityRecord)) + { + identityRecords.Add(record); + } + } + } }); - - var tree = BuildTree(records); - status.SetText("Importing records..", LogStatusType.Info); - PwGroup root = new PwGroup(true, true); root.Name = "1Password Import on " + DateTime.Now.ToString(); - - foreach (var node in tree) - { - ImportRecord(node, root, storage); - } + if ( createSubfolders) + { + foreach ( var category in RecordsList) + { + PwGroup categoryGroup = new PwGroup(true, true); + categoryGroup.Name = category.folderName; + categoryGroup.IconId = category.folderIcon; + + var tree = BuildTree(category.recordList); + foreach (var node in tree) + { + ImportRecord(node, categoryGroup, storage); + } + root.AddGroup(categoryGroup, true); + } + } + else + { + var tree = BuildTree(records); + foreach (var node in tree) + { + ImportRecord(node, root, storage); + } + } if (trashedRecords.Count > 0) { diff --git a/1P2KeePass/Plugin/_1PasswordPifFormatProvider.cs b/1P2KeePass/Plugin/_1PasswordPifFormatProvider.cs index 7a54dec..bbb1ea8 100644 --- a/1P2KeePass/Plugin/_1PasswordPifFormatProvider.cs +++ b/1P2KeePass/Plugin/_1PasswordPifFormatProvider.cs @@ -3,6 +3,7 @@ using KeePass.DataExchange; using KeePassLib; using KeePassLib.Interfaces; +using System.Windows.Forms; namespace _1Password2KeePass { @@ -54,8 +55,14 @@ public override System.Drawing.Image SmallIcon public override void Import(PwDatabase storage, Stream input, IStatusLogger status) { status.SetText("Parsing .pif ...", LogStatusType.Info); + var res = MessageBox.Show("Create seperate subfolders for each 1PW category (like Logins, Accounts ...)?","Create Subfolders?",MessageBoxButtons.YesNo); + bool createSubfolder = false; + if ( res == DialogResult.Yes) + { + createSubfolder = true; + } List baseRecords = _pifParser.Parse(input); - _pifImporter.Import(baseRecords, storage, status); + _pifImporter.Import(baseRecords, storage, status, createSubfolder); } } } \ No newline at end of file