1 | unit FormCompare;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, DataFile,
|
---|
7 | VCardFile, VCard, Common, RegistryEx, FormEx;
|
---|
8 |
|
---|
9 | type
|
---|
10 |
|
---|
11 | { TFormCompare }
|
---|
12 |
|
---|
13 | TFormCompare = class(TFormEx)
|
---|
14 | ButtonBrowse: TButton;
|
---|
15 | ButtonCancel: TButton;
|
---|
16 | ButtonCompare: TButton;
|
---|
17 | CheckBoxNormalizePhoneNumbers: TCheckBox;
|
---|
18 | CheckBoxRemoveExactDuplicates: TCheckBox;
|
---|
19 | CheckBoxSortContacts: TCheckBox;
|
---|
20 | CheckBoxWithoutPhotos: TCheckBox;
|
---|
21 | EditAnotherFile: TEdit;
|
---|
22 | Label1: TLabel;
|
---|
23 | OpenDialog1: TOpenDialog;
|
---|
24 | ScrollBox1: TScrollBox;
|
---|
25 | procedure ButtonBrowseClick(Sender: TObject);
|
---|
26 | procedure ButtonCompareClick(Sender: TObject);
|
---|
27 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
28 | procedure FormCreate(Sender: TObject);
|
---|
29 | procedure FormDestroy(Sender: TObject);
|
---|
30 | procedure FormShow(Sender: TObject);
|
---|
31 | private
|
---|
32 | LeftVCard: TVCardFile;
|
---|
33 | RightVCard: TVCardFile;
|
---|
34 | procedure CompareInternal;
|
---|
35 | procedure CompareExternal;
|
---|
36 | procedure LoadConfig;
|
---|
37 | procedure SaveConfig;
|
---|
38 | end;
|
---|
39 |
|
---|
40 |
|
---|
41 | implementation
|
---|
42 |
|
---|
43 | {$R *.lfm}
|
---|
44 |
|
---|
45 | uses
|
---|
46 | Core, FormCompareSideBySide, VCardProcessor;
|
---|
47 |
|
---|
48 | resourcestring
|
---|
49 | SCompareToolNotFound = 'Compare tool ''%s'' not found. Select valid compare tool in the application settings.';
|
---|
50 |
|
---|
51 | { TFormCompare }
|
---|
52 |
|
---|
53 | procedure TFormCompare.FormCreate(Sender: TObject);
|
---|
54 | begin
|
---|
55 | LeftVCard := TVCardFile.Create(nil);
|
---|
56 | RightVCard := TVCardFile.Create(nil);
|
---|
57 | end;
|
---|
58 |
|
---|
59 | procedure TFormCompare.FormDestroy(Sender: TObject);
|
---|
60 | begin
|
---|
61 | FreeAndNil(LeftVCard);
|
---|
62 | FreeAndNil(RightVCard);
|
---|
63 | end;
|
---|
64 |
|
---|
65 | procedure TFormCompare.FormClose(Sender: TObject; var CloseAction: TCloseAction
|
---|
66 | );
|
---|
67 | begin
|
---|
68 | SaveConfig;
|
---|
69 | end;
|
---|
70 |
|
---|
71 | procedure TFormCompare.ButtonCompareClick(Sender: TObject);
|
---|
72 | var
|
---|
73 | VCardProcessor: TVCardProcessor;
|
---|
74 | begin
|
---|
75 | LeftVCard.Assign(TVCardFile(Core.Core.DataFile));
|
---|
76 | RightVCard.LoadFromFile(EditAnotherFile.Text);
|
---|
77 |
|
---|
78 | VCardProcessor := TVCardProcessor.Create(nil);
|
---|
79 | with VCardProcessor do
|
---|
80 | try
|
---|
81 | DefaultPhoneCountryCode := Core.Core.DefaultPhoneCountryCode;
|
---|
82 | RemovePhotos := CheckBoxWithoutPhotos.Checked;
|
---|
83 | RemovePhoneSpaces := CheckBoxNormalizePhoneNumbers.Checked;
|
---|
84 | AddDefaultPhoneCountryPrefix := CheckBoxNormalizePhoneNumbers.Checked;
|
---|
85 | RemoveExactDuplicates := CheckBoxRemoveExactDuplicates.Checked;
|
---|
86 | Order := CheckBoxSortContacts.Checked;
|
---|
87 | finally
|
---|
88 | Free;
|
---|
89 | end;
|
---|
90 |
|
---|
91 | LeftVCard.VCard.Contacts.Sort;
|
---|
92 | RightVCard.VCard.Contacts.Sort;
|
---|
93 |
|
---|
94 | CompareExternal;
|
---|
95 | end;
|
---|
96 |
|
---|
97 | procedure TFormCompare.ButtonBrowseClick(Sender: TObject);
|
---|
98 | var
|
---|
99 | TempFile: TDataFile;
|
---|
100 | begin
|
---|
101 | TempFile := Core.Core.DefaultDataFileClass.Create(nil);
|
---|
102 | try
|
---|
103 | OpenDialog1.Filter := TempFile.GetFileFilter;
|
---|
104 | finally
|
---|
105 | TempFile.Free;
|
---|
106 | end;
|
---|
107 |
|
---|
108 | OpenDialog1.DefaultExt := '';
|
---|
109 | OpenDialog1.InitialDir := ExtractFileDir(EditAnotherFile.Text);
|
---|
110 | OpenDialog1.FileName := ExtractFileName(EditAnotherFile.Text);
|
---|
111 | OpenDialog1.Options := OpenDialog1.Options - [ofAllowMultiSelect];
|
---|
112 | if OpenDialog1.Execute then begin
|
---|
113 | EditAnotherFile.Text := OpenDialog1.FileName;
|
---|
114 | end;
|
---|
115 | end;
|
---|
116 |
|
---|
117 | procedure TFormCompare.FormShow(Sender: TObject);
|
---|
118 | begin
|
---|
119 | LoadConfig;
|
---|
120 | end;
|
---|
121 |
|
---|
122 | procedure TFormCompare.CompareInternal;
|
---|
123 | var
|
---|
124 | TempFileName: string;
|
---|
125 | begin
|
---|
126 | with TFormCompareSideBySide.Create(nil) do
|
---|
127 | try
|
---|
128 | TempFileName := Core.Core.GetTempDir +
|
---|
129 | DirectorySeparator + 'Compare' + VCardFileExt;
|
---|
130 | ForceDirectories(ExtractFileDir(TempFileName));
|
---|
131 | TVCardFile(Core.Core.DataFile).SaveToFile(TempFileName);
|
---|
132 | LoadFileLeft(TempFileName);
|
---|
133 | LoadFileRight(EditAnotherFile.Text);
|
---|
134 | ShowModal;
|
---|
135 | finally
|
---|
136 | Free;
|
---|
137 | end;
|
---|
138 | end;
|
---|
139 |
|
---|
140 | procedure CompareText(TextLeft, TextRight: string; FileNameLeft: string = 'FileLeft.txt';
|
---|
141 | FileNameRight: string = 'FileRight.txt');
|
---|
142 | var
|
---|
143 | TempFileRight: string;
|
---|
144 | TempFileLeft: string;
|
---|
145 | begin
|
---|
146 | if not DirectoryExists(Core.Core.GetTempDir) then
|
---|
147 | CreateDir(Core.Core.GetTempDir);
|
---|
148 | TempFileLeft := Core.Core.GetTempDir + DirectorySeparator + FileNameLeft;
|
---|
149 | TempFileRight := Core.Core.GetTempDir + DirectorySeparator + FileNameRight;
|
---|
150 | SaveStringToFile(TextLeft, TempFileLeft);
|
---|
151 | SaveStringToFile(TextRight, TempFileRight);
|
---|
152 | if FileExists(Core.Core.CompareTool) then
|
---|
153 | ExecuteProgram(Core.Core.CompareTool, [TempFileLeft, TempFileRight])
|
---|
154 | else ShowMessage(Format(SCompareToolNotFound, [Core.Core.CompareTool]));
|
---|
155 | end;
|
---|
156 |
|
---|
157 | procedure TFormCompare.CompareExternal;
|
---|
158 | begin
|
---|
159 | CompareText(LeftVCard.VCard.AsString, RightVCard.VCard.AsString,
|
---|
160 | ExtractFileName(LeftVCard.FileName), ExtractFileName(EditAnotherFile.Text));
|
---|
161 | end;
|
---|
162 |
|
---|
163 | procedure TFormCompare.LoadConfig;
|
---|
164 | begin
|
---|
165 | with TRegistryEx.Create do
|
---|
166 | try
|
---|
167 | CurrentContext := Core.Core.ApplicationInfo1.GetRegistryContext;
|
---|
168 | EditAnotherFile.Text := ReadStringWithDefault('LastCompareFileName', '');
|
---|
169 | CheckBoxWithoutPhotos.Checked := ReadBoolWithDefault('WithoutPhotos', True);
|
---|
170 | CheckBoxSortContacts.Checked := ReadBoolWithDefault('SortContacts', True);
|
---|
171 | CheckBoxNormalizePhoneNumbers.Checked := ReadBoolWithDefault('NormalizePhoneNumbers', True);
|
---|
172 | CheckBoxRemoveExactDuplicates.Checked := ReadBoolWithDefault('RemoveExactDuplicates', True);
|
---|
173 | finally
|
---|
174 | Free;
|
---|
175 | end;
|
---|
176 | end;
|
---|
177 |
|
---|
178 | procedure TFormCompare.SaveConfig;
|
---|
179 | begin
|
---|
180 | with TRegistryEx.Create do
|
---|
181 | try
|
---|
182 | CurrentContext := Core.Core.ApplicationInfo1.GetRegistryContext;
|
---|
183 | WriteString('LastCompareFileName', EditAnotherFile.Text);
|
---|
184 | WriteBool('WithoutPhotos', CheckBoxWithoutPhotos.Checked);
|
---|
185 | WriteBool('SortContacts', CheckBoxSortContacts.Checked);
|
---|
186 | WriteBool('NormalizePhoneNumbers', CheckBoxNormalizePhoneNumbers.Checked);
|
---|
187 | WriteBool('RemoveExactDuplicates', CheckBoxRemoveExactDuplicates.Checked);
|
---|
188 | finally
|
---|
189 | Free;
|
---|
190 | end;
|
---|
191 | end;
|
---|
192 |
|
---|
193 | end.
|
---|
194 |
|
---|