Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to create a subfolder for each 1PW category #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 1P2KeePass/1P2KeePass.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<HintPath>Newtonsoft.Json.dll</HintPath>
<IncludeInPackage>false</IncludeInPackage>
</Reference>
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="Common\DateTimeExt.cs" />
Expand Down
4 changes: 2 additions & 2 deletions 1P2KeePass/1P2KeePass.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartAction>Program</StartAction>
<StartProgram>Y:\Projects\Plugin.1P2KeePass\KeePassDistribution\KeePass.exe</StartProgram>
<StartWorkingDirectory>Y:\Projects\Plugin.1P2KeePass\KeePassDistribution\</StartWorkingDirectory>
<StartProgram>D:\Dev\git\1P2KeePass\KeePassDistribution\KeePass.exe</StartProgram>
<StartWorkingDirectory>D:\Dev\git\1P2KeePass\KeePassDistribution\</StartWorkingDirectory>
</PropertyGroup>
</Project>
113 changes: 99 additions & 14 deletions 1P2KeePass/Plugin/Controllers/PIFImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,119 @@

namespace _1Password2KeePass
{
public class subfolder
{
public subfolder() { }

public String folderName { get; set; }
public PwIcon folderIcon { get; set; }
public List<BaseRecord> recordList { get; set; }
}

public class PIFImporter
{
public void Import(List<BaseRecord> baseRecords, PwDatabase storage, IStatusLogger status)
public void Import(List<BaseRecord> baseRecords, PwDatabase storage, IStatusLogger status, bool createSubfolders = false)
{
var records = new List<BaseRecord>();
var trashedRecords = new List<BaseRecord>();

baseRecords.ForEach(record =>
var loginRecords = new List<BaseRecord>();
var walletRecords = new List<BaseRecord>();
var accountsRecords = new List<BaseRecord>();
var softwareRecords = new List<BaseRecord>();
var secureNoteRecords = new List<BaseRecord>();
var identityRecords = new List<BaseRecord>();
var RecordsList = new List<subfolder>();

var records = new List<BaseRecord>();
var trashedRecords = new List<BaseRecord>();

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)
{
Expand Down
9 changes: 8 additions & 1 deletion 1P2KeePass/Plugin/_1PasswordPifFormatProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using KeePass.DataExchange;
using KeePassLib;
using KeePassLib.Interfaces;
using System.Windows.Forms;

namespace _1Password2KeePass
{
Expand Down Expand Up @@ -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<BaseRecord> baseRecords = _pifParser.Parse(input);
_pifImporter.Import(baseRecords, storage, status);
_pifImporter.Import(baseRecords, storage, status, createSubfolder);
}
}
}