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();
        }
Beispiel #2
0
        public List <Records.BaseRecord> ParseItems(string bandFilePath, Records.Profile profile)
        {
            List <Records.BaseRecord> records = new List <Records.BaseRecord>();

            if (File.Exists(bandFilePath))
            {
                JsonSerializer serializer = JsonSerializer.Create(new JsonSerializerSettings()
                {
                    Converters = new JsonConverter[] {
                        new Converters.ItemRecordConverter(profile.masterKey),
                        new Converters.DetailsOPDataConverter(),
                        new Converters.EncryptedKeyPairConverter(profile.masterKey),
                        new Converters.OverviewOPDataConverter(profile.overviewKey),
                    }
                });

                using (FileStream fs = File.OpenRead(bandFilePath))
                    using (TextReader tr = new StreamReader(fs))
                    {
                        if (this.findJSONObject(tr))
                        {
                            using (JsonTextReader jtr = new JsonTextReader(tr))
                            {
                                while (jtr.Read())
                                {
                                    if (jtr.TokenType == JsonToken.StartObject && jtr.Depth > 0)
                                    {
                                        records.Add(serializer.Deserialize <Records.ItemRecord>(jtr));
                                    }
                                    else if (jtr.TokenType == JsonToken.EndObject && jtr.Depth == 0)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
            }

            return(records);
        }
Beispiel #3
0
        public Records.AttachmentMetadata ParseAttachments(string attachmentFilePath, Records.Profile profile)
        {
            if (File.Exists(attachmentFilePath))
            {
                JsonSerializer serializer = JsonSerializer.Create(new JsonSerializerSettings()
                {
                    Converters = new JsonConverter[] {
                        new Converters.OverviewOPDataConverter(profile.overviewKey),
                    }
                });

                using (FileStream fs = File.OpenRead(attachmentFilePath))
                {
                    string jsonString = OPVault.OPData.ReadAttachmentMetadata(attachmentFilePath);
                    using (TextReader tr = new StringReader(jsonString))
                        using (JsonTextReader jtr = new JsonTextReader(tr))
                        {
                            return(serializer.Deserialize <Records.AttachmentMetadata>(jtr));
                        }
                }
            }

            return(null);
        }