/
DateTimeShift.pas
205 lines (183 loc) · 5.44 KB
/
DateTimeShift.pas
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
unit DateTimeShift;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Mask, Vcl.ExtCtrls,
Vcl.ComCtrls;
type
TFDateTimeShift = class(TForm)
StatusBar1: TStatusBar;
AdvPanel1: TPanel;
LabeledEdit1: TLabeledEdit;
LabeledEdit2: TLabeledEdit;
LabeledEdit3: TLabeledEdit;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
MaskEdit1: TMaskEdit;
Label2: TLabel;
CheckBox4: TCheckBox;
LabeledEdit4: TLabeledEdit;
CheckBox5: TCheckBox;
Button1: TButton;
Button2: TButton;
Label1: TLabel;
procedure FormShow(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure CheckBox4Click(Sender: TObject);
procedure MaskEdit1Change(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
procedure DisplayHint(Sender: TObject);
public
{ Public declarations }
var
ETouts, ETerrs: string;
end;
var
FDateTimeShift: TFDateTimeShift;
implementation
uses Main, ExifTool, DateUtils;
{$R *.dfm}
const
CmdDateOriginal = '-exif:DateTimeOriginal';
CmdDateCreate = '-exif:CreateDate';
CmdDateModify = '-exif:ModifyDate';
var
ETcmd: string;
DTstr: string[23];
DTx: TDateTime;
Y, M, D, hh, mm, ss, tt: word;
DateTimeOK: boolean;
procedure TFDateTimeShift.Button2Click(Sender: TObject);
var
PN: string[3];
begin
if CheckBox4.Checked then
PN := '+='
else
PN := '-=';
if (CheckBox1.Checked) and (CheckBox2.Checked) and (CheckBox3.Checked) then
ETcmd := '-exif:AllDates' + PN + MaskEdit1.EditText + CRLF
else
begin
ETcmd := '';
if CheckBox1.Checked then
ETcmd := CmdDateOriginal + PN + MaskEdit1.EditText + CRLF;
if CheckBox2.Checked then
ETcmd := ETcmd + CmdDateCreate + PN + MaskEdit1.EditText + CRLF;
if CheckBox3.Checked then
ETcmd := ETcmd + CmdDateModify + PN + MaskEdit1.EditText + CRLF;
end;
Y := length(ETcmd);
SetLength(ETcmd, Y - 2); // remove last CRLF
ET_OpenExec(ETcmd, FMain.GetSelectedFiles, ETouts, ETerrs);
FMain.UpdateLogWin(ETouts, ETerrs);
if CheckBox5.Checked then
ET_OpenExec('-FileModifyDate<Exif:DateTimeOriginal', FMain.GetSelectedFiles);
ModalResult := mrOK;
end;
procedure TFDateTimeShift.CheckBox1Click(Sender: TObject);
begin
Button2.Enabled := (CheckBox1.Checked) or (CheckBox2.Checked) or (CheckBox3.Checked);
end;
procedure TFDateTimeShift.CheckBox4Click(Sender: TObject);
begin
with CheckBox4 do
if Checked then
Caption := '=Increment'
else
Caption := '=Decrement';
MaskEdit1Change(Sender);
end;
procedure TFDateTimeShift.DisplayHint(Sender: TObject);
begin
StatusBar1.SimpleText := GetShortHint(Application.Hint);
end;
procedure TFDateTimeShift.FormShow(Sender: TObject);
var
ETResult: TStringList;
begin
ETResult := TStringList.Create;
try
Left := FMain.Left + FMain.GUIBorderWidth + FMain.AdvPageFilelist.Left;
Top := FMain.Top + FMain.GUIBorderHeight;
if FMain.MDontBackup.Checked then
Label1.Caption := 'Backup: OFF'
else
Label1.Caption := 'Backup: ON';
Application.OnHint := DisplayHint;
ETcmd := '-s3' + CRLF + '-f' + CRLF + CmdDateOriginal + CRLF + CmdDateCreate + CRLF + CmdDateModify;
ET_OpenExec(ETcmd, FMain.GetFirstSelectedFile, ETResult);
// .SelectedFiles[0]);
LabeledEdit1.Text := ETResult[0];
LabeledEdit2.Text := ETResult[1];
LabeledEdit3.Text := ETResult[2];
DTstr := LabeledEdit1.Text; // Check DateTimeOriginal
Y := StrToIntDef(Copy(DTstr, 1, 4), 0);
M := StrToIntDef(Copy(DTstr, 6, 2), 0);
D := StrToIntDef(Copy(DTstr, 9, 2), 0);
hh := StrToIntDef(Copy(DTstr, 12, 2), 0);
mm := StrToIntDef(Copy(DTstr, 15, 2), 0);
ss := StrToIntDef(Copy(DTstr, 18, 2), 0);
DateTimeOK := (Y * M * D <> 0);
if DateTimeOK then
begin
DTx := EncodeDateTime(Y, M, D, hh, mm, ss, 0);
LabeledEdit4.Text := LabeledEdit1.Text;
end
else
LabeledEdit4.Clear;
MaskEdit1.Clear;
MaskEdit1.SetFocus;
finally
ETResult.Free;
end;
end;
procedure TFDateTimeShift.MaskEdit1Change(Sender: TObject);
var
Yd, Md, Dd, hhd, mmd, ssd, i: smallint;
NewDT: TDateTime;
begin
if DateTimeOK then
begin
if CheckBox4.Checked then
i := 1
else
i := -1;
DTstr := MaskEdit1.EditText;
Yd := StrToIntDef(Copy(DTstr, 1, 4), 0) * i;
Md := StrToIntDef(Copy(DTstr, 6, 2), 0) * i;
Dd := StrToIntDef(Copy(DTstr, 9, 2), 0) * i;
hhd := StrToIntDef(Copy(DTstr, 12, 2), 0) * i;
mmd := StrToIntDef(Copy(DTstr, 15, 2), 0) * i;
ssd := StrToIntDef(Copy(DTstr, 18, 2), 0) * i;
NewDT := IncYear(DTx, Yd); // get original DateTime here
NewDT := IncMonth(NewDT, Md);
NewDT := IncDay(NewDT, Dd);
NewDT := IncHour(NewDT, hhd);
NewDT := IncMinute(NewDT, mmd);
NewDT := IncSecond(NewDT, ssd);
DecodeDateTime(NewDT, Y, M, D, hh, mm, ss, tt);
DTstr := IntToStr(Y) + ':';
if M < 10 then
DTstr := DTstr + '0';
DTstr := DTstr + IntToStr(M) + ':';
if D < 10 then
DTstr := DTstr + '0';
DTstr := DTstr + IntToStr(D) + ' ';
if hh < 10 then
DTstr := DTstr + '0';
DTstr := DTstr + IntToStr(hh) + ':';
if mm < 10 then
DTstr := DTstr + '0';
DTstr := DTstr + IntToStr(mm) + ':';
if ss < 10 then
DTstr := DTstr + '0';
DTstr := DTstr + IntToStr(ss);
LabeledEdit4.Text := DTstr;
end;
end;
end.