-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathNewKeyKdb2x.cs
100 lines (87 loc) · 3.59 KB
/
NewKeyKdb2x.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using KeePass.App;
using KeePass.DataExchange;
using KeePass.Forms;
using KeePassLib;
using KeePassLib.Interfaces;
using KeePassLib.Serialization;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace KeePassNewKeyExport
{
internal sealed class NewKeyKdb2x : FileFormatProvider
{
public override bool SupportsImport { get { return false; } }
public override bool SupportsExport { get { return true; } }
public override string FormatName { get { return string.Format("KeePass KDBX (2.x) ({0})", KeePass.Resources.KPRes.ChangeMasterKey); } }
public override string DefaultExtension { get { return AppDefs.FileExtension.FileExt; } }
public override string ApplicationGroup { get { return PwDefs.ShortProductName; } }
public override Image SmallIcon
{
get { return Properties.Resources.B16x16_KeePassPlus; }
}
public override bool Export(PwExportInfo pwExportInfo, Stream sOutput,
IStatusLogger slLogger)
{
//Debugger.Launch();
//ask for the database key
KeyCreationForm kcf = new KeyCreationForm();
DialogResult dr = kcf.ShowDialog();
if (dr == DialogResult.Cancel || dr == DialogResult.Abort)
{
return false;
}
PwDatabase pd = new PwDatabase();
pd.New(new IOConnectionInfo(), kcf.CompositeKey);
//copy settings
pd.Color = pwExportInfo.ContextDatabase.Color;
pd.Compression = pwExportInfo.ContextDatabase.Compression;
pd.DataCipherUuid = pwExportInfo.ContextDatabase.DataCipherUuid;
pd.DefaultUserName = pwExportInfo.ContextDatabase.DefaultUserName;
pd.Description = pwExportInfo.ContextDatabase.Description;
pd.HistoryMaxItems = pwExportInfo.ContextDatabase.HistoryMaxItems;
pd.HistoryMaxSize = pwExportInfo.ContextDatabase.HistoryMaxSize;
//pd.KeyEncryptionRounds = pwExportInfo.ContextDatabase.KeyEncryptionRounds; // Removed in KeePass 2.35
pd.MaintenanceHistoryDays = pwExportInfo.ContextDatabase.MaintenanceHistoryDays;
pd.MasterKeyChangeForce = pwExportInfo.ContextDatabase.MasterKeyChangeForce;
pd.MasterKeyChangeRec = pwExportInfo.ContextDatabase.MasterKeyChangeRec;
//pd.MemoryProtection.ProtectTitle = pwExportInfo.ContextDatabase.MemoryProtection.ProtectTitle;
//pd.MemoryProtection.ProtectUserName = pwExportInfo.ContextDatabase.MemoryProtection.ProtectUserName;
//pd.MemoryProtection.ProtectPassword = pwExportInfo.ContextDatabase.MemoryProtection.ProtectPassword;
//pd.MemoryProtection.ProtectUrl = pwExportInfo.ContextDatabase.MemoryProtection.ProtectUrl;
//pd.MemoryProtection.ProtectNotes = pwExportInfo.ContextDatabase.MemoryProtection.ProtectNotes;
pd.Name = pwExportInfo.ContextDatabase.Name;
pd.RecycleBinEnabled = pwExportInfo.ContextDatabase.RecycleBinEnabled;
//pd.UseFileLocks = pwExportInfo.ContextDatabase.UseFileLocks;
//pd.UseFileTransactions = pwExportInfo.ContextDatabase.UseFileTransactions;
//get used custom icons
pwExportInfo.DataGroup.TraverseTree(
TraversalMethod.PreOrder,
null,
e =>
{
if (!e.CustomIconUuid.Equals(PwUuid.Zero))
{
pd.CustomIcons.AddRange(pwExportInfo.ContextDatabase.CustomIcons.Where(i => i.Uuid.Equals(e.CustomIconUuid)));
}
return true;
}
);
//get other database settings
DatabaseSettingsForm dsf = new DatabaseSettingsForm();
dsf.InitEx(true, pd);
dr = dsf.ShowDialog();
if (dr == DialogResult.Cancel || dr == DialogResult.Abort)
{
pd.Close();
return false;
}
//and save the new database
KdbxFile kdbx = new KdbxFile(pd);
kdbx.Save(sOutput, pwExportInfo.DataGroup, KdbxFormat.Default, slLogger);
return true;
}
}
}