public override void Import(PwDatabase pwDatabase, Stream input, IStatusLogger statusLogger) { ConfigurationForm configurationForm = new ConfigurationForm(); statusLogger.StartLogging("OPVault file import", true); if (configurationForm.ShowDialog() == DialogResult.OK) { statusLogger.SetText("Parsing OPVault file...", LogStatusType.Info); string defaultDir = Path.Combine(configurationForm.ImportDirPath, "default"); Records.Profile profile = oneVaultParser.ParseProfile(Path.Combine(defaultDir, "profile.js"), configurationForm.MasterPassword); if (profile == null) { MessageBox.Show("Could not read profile file.", "Invalid OPVault", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (profile.masterKey == null || profile.overviewKey == null) { MessageBox.Show("Please check the master password is correct.", "Error processing OPVault", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { List <Records.BaseRecord> records = oneVaultParser.ParseFolders(Path.Combine(defaultDir, "folders.js"), profile); Dictionary <string, Records.AttachmentMetadata> attachments = new Dictionary <string, Records.AttachmentMetadata>(); for (int i = 0; i < 16; i++) { records.AddRange(oneVaultParser.ParseItems(Path.Combine(defaultDir, string.Format("band_{0:X}.js", i)), profile)); } foreach (string attachmentFilePath in Directory.GetFiles(defaultDir, "*.attachment")) { Records.AttachmentMetadata attachmentMetadata = oneVaultParser.ParseAttachments(attachmentFilePath, profile); Records.BaseRecord item = records.Find(r => r.uuid.Equals(attachmentMetadata.itemUUID)); if (item is Records.ItemRecord) { (item as Records.ItemRecord).AddAttachment(attachmentFilePath, attachmentMetadata); } } statusLogger.SetText(string.Format("Importing {0} parsed records...", records.Count), LogStatusType.Info); oneVaultImporter.Import(records, pwDatabase, statusLogger, configurationForm.GetUserPrefs()); statusLogger.SetText("Finished import.", LogStatusType.Info); } } else { statusLogger.SetText("Import cancelled.", LogStatusType.Info); } statusLogger.EndLogging(); }
private void importRecord(TreeNode <Records.BaseRecord> currentNode, PwGroup pwGroupAddTo, PwDatabase pwDatabase, UserPrefs userPrefs) { Records.BaseRecord record = currentNode.AssociatedObject; if (record is Records.RegularFolderRecord) { PwGroup folder = (record as Records.RegularFolderRecord).CreatePwGroup(); if (folder != null) { pwGroupAddTo.AddGroup(folder, true); foreach (TreeNode <Records.BaseRecord> child in currentNode.Children) { importRecord(child, folder, pwDatabase, userPrefs); } } } else { Records.ItemRecord itemRecord = record as Records.ItemRecord; PwEntry entry = itemRecord.CreatePwEntry(pwDatabase, userPrefs); if (entry != null) { PwCustomIcon customIcon = itemRecord.GetPwCustomIcon(); if (customIcon != null) { if (!pwDatabase.CustomIcons.Exists(icon => icon.Uuid.Equals(customIcon.Uuid))) { pwDatabase.CustomIcons.Add(customIcon); } pwDatabase.UINeedsIconUpdate = true; } pwGroupAddTo.AddEntry(entry, true); } } }