-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnit1.pas
841 lines (725 loc) · 27.8 KB
/
Unit1.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ExtCtrls, ImgList, ShellCtrls, Jpeg,Exif, ToolWin,
ActnMan, ActnCtrls, ExtActns, StdActns, ActnList, ActnMenus, XPStyleActnCtrls,Registry,
Unit2,Unit3,unit4,CommCtrl;
type
TMyListView = class(TListView)
protected
procedure WndProc(var Message: TMessage);
override;
end;
//end;
TForm1 = class(TForm)
ImageList1: TImageList;
ShellTreeView1: TShellTreeView;
Splitter1: TSplitter;
ActionManager1: TActionManager;
ActionMainMenuBar1: TActionMainMenuBar;
ActionToolBar1: TActionToolBar;
Arefresh: TAction;
ImageList2: TImageList;
Select_all: TAction;
Select_none: TAction;
BrowseURL1: TBrowseURL;
About: TAction;
use_exif: TCheckBox;
A_rename: TAction;
StatusBar1: TStatusBar;
ProgressBar1: TProgressBar;
A_language: TAction;
procedure ListView1_prevDblClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure A_languageExecute(Sender: TObject);
procedure ShellTreeView1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure ListView1Change(Sender: TObject; Item: TListItem;
Change: TItemChange);
procedure A_renameExecute(Sender: TObject);
procedure ListView1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Select_noneExecute(Sender: TObject);
procedure ArefreshExecute(Sender: TObject);
procedure Select_allExecute(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure LoadFiles();
procedure RefreshLanguage();
procedure refresh_statusbar();
procedure TraiteMessage(var Msg: TMsg; var Handled: Boolean);
procedure FormDestroy(Sender: TObject);
procedure ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
procedure ListView1Data(Sender: TObject; Item: TListItem);
procedure ShellTreeView1Change(Sender: TObject; Node: TTreeNode);
private
{ Private 宣言 }
FTmpStream: TFileStream; // 縮小画像を保管するストリーム
FSeekPosition: TStringList; // 縮小画像のSeek位置(-1:読込失敗 0>:Seek位置)
FFileList: TStringList; // ファイル名
ListView1: TMyListView;
procedure LVBGImage;
procedure CreateThumbnail(Path: String);
public
{ Public 宣言 }
end;
var
Form1: TForm1;
Version: string;
implementation
uses ShellAPI, ImageExtract, ComObj;
{$R *.DFM}
//{$R stringtable.res}
type
TLVBKIMAGE = packed record
ulFlags : longint;
hbm : HBitmap;
pszImage: PChar;
cchImageMax : word;
xOffsetPercent : integer;
yOffsetPercent : integer;
end;
const
CLR_NONE = $FFFFFFFF;
LVM_FIRST = $1000;
LVM_SETTEXTBKCOLOR = (LVM_FIRST + 38);
LVM_SETBKIMAGE = (LVM_FIRST + 68);
LVBKIF_SOURCE_NONE = 0;
LVBKIF_SOURCE_HBITMAP = 1;
LVBKIF_SOURCE_URL = 2;
LVBKIF_SOURCE_MASK = 3;
LVBKIF_STYLE_NORMAL = 0;
LVBKIF_STYLE_TILE = 16;
LVBKIF_STYLE_MASK = 16;
procedure TmyListView.WndProc(var Message: TMessage);
begin
if Message.msg = WM_ERASEBKGND then
DefaultHandler(Message)
else
inherited WndProc(Message);
end;
procedure TForm1.TraiteMessage(var Msg: TMsg; var Handled: Boolean); // Dans FormCreate, on a mis Application.OnMessage := TraiteMessage;
// c'est donc cette proc馘ure qui est appel馥 chaque fois que se d馗lenche l'騅鈩ement OnMessage (c'est dire chaque fois que Windows envoie un message l'application)
// faire attention cette proc馘ure est appel tr鑚 souvent par Windows d'o le if d駸 le d駱art.
var
NombreDeFichiers,size,i:integer;
NomDuFichierStr:string;
NomDuFichier:array[0..255] of char;
begin
if Msg.message=WM_DROPFILES then
begin
NombreDeFichiers:= DragQueryFile( Msg.wParam, $FFFFFFFF, NomDuFichier, sizeof(NomDuFichier));// r馗up駻ation du nombre de fichiers
// for i:=0 to NombreDeFichiers-1 do
// begin
size:= DragQueryFile( Msg.wParam, 0, NomDuFichier, sizeof(NomDuFichier) );// r馗up駻ation du nom du fichier
NomDuFichierStr:=NomDuFichier; // tansformation du tableau de char en STRING
// DragQueryPoint(Msg.wParam,PointDuLache); // r馗up駻ation du point de lach
// Memo1.Lines.add(NomDuFichierStr); //+' X='+IntToStr(PointDuLache.x)+' Y='+ IntToStr(PointDuLache.y));
//DessineIcone(NomDuFichier,PointDuLache);
if DirectoryExists(NomDuFichierStr) then ShelltreeView1.Path:=NomDuFichierStr;
// end;
end;
end;
//****************************************
// サムネイルをファイルストリーム上に作成
//****************************************
procedure TForm1.CreateThumbnail(Path: String);
var
I: Integer;
FilePath: String;
SeekPos: Integer;
AWidth, AHeight, bmpWidth, bmpHeight, HMargin, VMargin: Integer;
Bmp: TBitmap;
SHFileInfo: TSHFileInfo;
IconHandle: HICON;
begin
FTmpStream.Size := 0;
FSeekPosition.Clear;
// 描画領域の大きさ
AWidth := ListView1.LargeImages.Width;
AHeight := ListView1.LargeImages.Height;
if ListView1.Items.Count <>0 then begin
ProgressBar1.Min:=0; ProgressBar1.Max:=ListView1.Items.Count -1;
end;
for I := 0 to ListView1.Items.Count -1 do
begin
if ListView1.Items.Count <>0 then
Begin
ProgressBar1.Position:=I;
StatusBar1.Panels[1].text:=inttostr(I+1)+'/'+inttostr(ListView1.Items.Count)+' - '+ LoadStringLanguage(11);
end;
StatusBar1.Refresh;
FSeekPosition.Add('-1');
// 縮小画像作成
FilePath := Path + '\' + FFileList[I];
Bmp := TBitmap.Create;
try
Bmp.Width := AWidth;
Bmp.Height :=AHeight;
if ExtractImage(FilePath, Bmp) = False then
begin
Continue;
end;
// 縮小画像とその位置を保存
SeekPos := FTmpStream.Size;
FSeekPosition.Strings[I] := IntToStr(SeekPos);
FTmpStream.Seek(0, soFromEnd);
Bmp.SaveToStream(FTmpStream);
finally
Bmp.Free;
end;
if ListView1.Items.Count <>0 then ProgressBar1.Position:=0;
end;
refresh_statusbar;
end;
procedure installer;
var
Language:string;
Registre : TRegistry;
begin
Registre:=TRegistry.Create;
Registre.RootKey:=HKEY_CURRENT_USER;
If not(Registre.OpenKey('SOFTWARE\Ledadu\Cronos Rename', false))
then
Begin //-- si pas install du tout ou chang chemin
// chemin
Registre.CloseKey();
Registre.OpenKey('SOFTWARE\Ledadu\Cronos Rename', true);
Registre.WriteString('Language','EN');
Registre.WriteString('Patern','Photo *');
Registre.Free;
with TForm2.Create(Form1) do ShowModal;
Form1.RefreshLanguage;
end;
end;
procedure TForm1.RefreshLanguage;
var
a : array[0..255] of char;
StrTblOfs : integer;
begin
StrTblOfs := 0;
if GetLanguage = 'EN' then StrTblOfs := 0;
if GetLanguage = 'FR' then StrTblOfs := 50;
//----------
//Use exif
if LoadString(hInstance,StrTblOfs + 1,a,sizeof(a)) <> 0 then
use_exif.Caption := StrPas(a);
//deselect
if LoadString(hInstance,StrTblOfs + 2,a,sizeof(a)) <> 0 then
ActionManager1.ActionBars.ActionBars[0].Items.ActionClients[5].Caption:= StrPas(a);
ActionManager1.ActionBars.ActionBars[1].Items.ActionClients[0].Items.ActionClients[1].Caption:= StrPas(a);
//select all
if LoadString(hInstance,StrTblOfs + 3,a,sizeof(a)) <> 0 then
ActionManager1.ActionBars.ActionBars[0].Items.ActionClients[4].Caption:= StrPas(a);
ActionManager1.ActionBars.ActionBars[1].Items.ActionClients[0].Items.ActionClients[0].Caption:= StrPas(a);
// Refresh
if LoadString(hInstance,StrTblOfs + 4,a,sizeof(a)) <> 0 then
ActionManager1.ActionBars.ActionBars[0].Items.ActionClients[2].Caption:= StrPas(a);
// Rename
if LoadString(hInstance,StrTblOfs + 5,a,sizeof(a)) <> 0 then
ActionManager1.ActionBars.ActionBars[0].Items.ActionClients[0].Caption:= StrPas(a);
// Edit
if LoadString(hInstance,StrTblOfs + 6,a,sizeof(a)) <> 0 then
ActionManager1.ActionBars.ActionBars[1].Items.ActionClients[0].Caption:= StrPas(a);
// Help
if LoadString(hInstance,StrTblOfs + 7,a,sizeof(a)) <> 0 then
ActionManager1.ActionBars.ActionBars[1].Items.ActionClients[1].Caption:= StrPas(a);
//Online Help
if LoadString(hInstance,StrTblOfs + 8,a,sizeof(a)) <> 0 then
ActionManager1.ActionBars.ActionBars[1].Items.ActionClients[1].Items.ActionClients[0].Caption:= StrPas(a);
//Choose language
if LoadString(hInstance,StrTblOfs + 9,a,sizeof(a)) <> 0 then
ActionManager1.ActionBars.ActionBars[1].Items.ActionClients[0].Items.ActionClients[2].Caption:= StrPas(a);
//----------
end;
procedure TForm1.LVBGImage;
var
BKimg : TLVBKIMAGE;
bmpfond:Tbitmap;
Res: TResourceStream;
Jpeg: TJpegImage;
begin
FillChar(BKimg, SizeOf(BKimg), 0);
BKimg.ulFlags := LVBKIF_SOURCE_URL or LVBKIF_STYLE_TILE;
//BKimg.ulFlags := LVBKIF_SOURCE_HBITMAP or LVBKIF_STYLE_TILE;
bmpfond := TBitmap.Create;
bmpfond.Width := 466;
bmpfond.Height :=416;
Res:=TResourceStream.Create(0,'IMAGE001','JPG');
Jpeg:=TJpegImage.Create;
Jpeg.LoadFromStream(res);
bmpfond.Canvas.StretchDraw(bmpfond.Canvas.ClipRect,Jpeg);
//if ExtractImage('C:\Documents and Settings\Lenny\Bureau\Crofoname\fond.jpg', bmpfond) = False then
// begin
// Continue;
// end;
bmpfond.SaveToFile(GetEnvironmentVariable('TEMP')+'\fondexport.bitmap');
BKimg.pszImage := PChar(GetEnvironmentVariable('TEMP')+'\fondexport.bitmap');
BKimg.xOffsetPercent := 0;
BKimg.yOffsetPercent := 0;
SendMessage(listview1.Handle, LVM_SETTEXTBKCOLOR, 0, CLR_NONE);
SendMessage(listview1.Handle, LVM_SETBKIMAGE, 0, integer(@BKimg));
end;
procedure TForm1.FormCreate(Sender: TObject);
BEGIN
ListView1 := TMyListView.Create(Self);
with ListView1 do
begin
Parent := Self;
Left := 183;
Top := 70;
Width := 485;
//ViewStyle:=vsList;
Height := 418;
Align := alClient;
LargeImages := ImageList1;
SmallImages := ImageList1;
Font.Charset := ANSI_CHARSET;
Font.Color := clWindowText;
Font.Height := -9;
Font.Name := 'MS P????';
Font.Style := [];
Font.Size:=9;
IconOptions.AutoArrange := false;
MultiSelect := True;
OwnerData := True;
OwnerDraw := True;
ParentFont := False;
TabOrder := 0;
OnChange := ListView1Change;
OnCustomDrawItem := ListView1CustomDrawItem;
OnData := ListView1Data;
OnKeyUp := ListView1KeyUp;
OnDblClick:=ListView1_prevDblClick;
end;
Registre:=TRegistry.Create;
Registre.RootKey:=HKEY_CURRENT_USER;
Registre.OpenKey('SOFTWARE\Ledadu\Cronos Rename', false);
If Registre.ValueExists('TreeViewWhidth') then ShellTreeView1.Width:=Registre.ReadInteger('TreeViewWhidth');
If Registre.ValueExists('WindowState') then form1.WindowState:=TWindowState(Registre.ReadInteger('WindowState'));
If Registre.ValueExists('Width') then self.Width:=Registre.ReadInteger('Width');
If Registre.ValueExists('Height') then self.Height:=Registre.ReadInteger('Height');
Registre.Free;
Version:='1.06';
Form1.Caption:='Crofoname '+ version;
Left:=(Screen.Width-Width) div 2;
Top:=(Screen.Height-Height) div 2;
RefreshLanguage;
LVBGImage;
FTmpStream := TFileStream.Create(GetEnvironmentVariable('TEMP') +'\Crofoname-FTmpStream.dat', fmCreate);
FSeekPosition := TStringList.Create;
FFileList := TStringList.Create;
// indique la fen黎re o pourra se faire le lach. On peut y mettre tout type de fen黎re
DragAcceptFiles(ListView1.Handle,true);
DragAcceptFiles(ShellTreeView1.Handle,true);
Application.OnMessage := TraiteMessage; // c'est la proc馘ure TraiteMessage qui va traiter les messages
StatusBar1.ControlStyle := StatusBar1.ControlStyle + [csAcceptsControls];
ProgressBar1.Parent := StatusBar1;
ProgressBar1.SetBounds(0, 2, 300, 16);
ProgressBar1.BringToFront;
if paramcount>0 then if DirectoryExists(paramstr(1)) then ShelltreeView1.Path:=paramstr(1);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Registre:=TRegistry.Create;
Registre.RootKey:=HKEY_CURRENT_USER;
Registre.OpenKey('SOFTWARE\Ledadu\Cronos Rename', true);
Registre.WriteInteger('TreeViewWhidth',self.ShellTreeView1.Width);
Registre.WriteInteger('Width',self.Width);
Registre.WriteInteger('Height',self.Height);
Registre.WriteInteger('WindowState',Ord(self.WindowState));
Registre.Free;
FTmpStream.Size := 0;
FTmpStream.Free;
FSeekPosition.Free;
FFileList.Free;
end;
//****************************************
// リストビューのカスタム描画イベントで、縮小画像を自前で描画
//****************************************
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
var
SeekPos: Integer;
SHFileInfo: TSHFileInfo;
IconHandle: HICON;
Bmp: TBitmap;
ARect, BRect: TRect;
coef : Real;
begin
// ListView1.Canvas.Brush.Color := GetSysColor(COLOR_WINDOW);
ListView1.Canvas.Font.Color:= clblack;
ARect := Item.DisplayRect(drIcon);
ARect.Left := ARect.Left + Trunc((ARect.Right - ARect.Left - ImageList1.Width) / 2);
ARect.Right := ARect.Left + ImageList1.Width;
ARect.Top := ARect.Top + Trunc((ARect.Bottom - ARect.Top - ImageList1.Height) / 2);
ARect.Bottom := ARect.Top + ImageList1.Height;
ListView1.Canvas.FillRect(ARect);
SeekPos := StrToInt(FSeekPosition.Strings[Item.Index]);
Bmp := TBitmap.Create;
Bmp.LoadFromStream(FTmpStream);
BRect := Classes.Rect(0, 0, Bmp.Width, Bmp.Height);
ListView1.Canvas.CopyRect(ARect, Bmp.Canvas, BRect);
Bmp.Free;
if SeekPos = -1 then
begin
// アイコン描画
SHGetFileInfo(
PChar(ExtractFileExt(Item.Caption)),
0, SHFileInfo, Sizeof(TSHFileInfo),
SHGFI_SYSICONINDEX or SHGFI_USEFILEATTRIBUTES or
SHGFI_ICON or SHGFI_TYPENAME);
IconHandle := SHFileInfo.hIcon;
DrawIconEx(
ListView1.Canvas.Handle,
ARect.Left + (ARect.Right - ARect.Left - 32) div 2,
ARect.Top + (ARect.Bottom - ARect.Top - 32) div 2,
IconHandle, 32, 32, 0, 0,
DI_NORMAL);
DestroyIcon(IconHandle);
end
else
begin
// 縮小画像をストリームからロードして表示
Bmp := TBitmap.Create;
try
FTmpStream.Seek(SeekPos, soFromBeginning);
Bmp.Width := ARect.Right - ARect.Left;
Bmp.LoadFromStream(FTmpStream);
Bmp.Height := ARect.Bottom - ARect.Top;
//bmp.Canvas.Brush.Color:=clnone;
bmp.Canvas.Pen.Color := clwhite;
bmp.Canvas.Pen.Width := 5;
bmp.Canvas.MoveTo(0, 0);
bmp.Canvas.LineTo(99, 0);
bmp.Canvas.LineTo(99, 99);
bmp.Canvas.LineTo(0, 99);
bmp.Canvas.LineTo(0, 0);
BRect := Classes.Rect(0, 0, Bmp.Width , Bmp.Height);
ListView1.Canvas.CopyRect(ARect, Bmp.Canvas, BRect);
finally
Bmp.Free;
end;
end;
// 選択状態を示す四角を描画
if cdsSelected in State then
begin
ListView1.Canvas.Pen.Color := rgb(192,192,255);
ListView1.Canvas.Pen.Width := 8;
ListView1.Canvas.MoveTo(ARect.Left, ARect.Top+2);
ListView1.Canvas.LineTo(ARect.Left, ARect.Bottom-1+2);
ListView1.Canvas.LineTo(ARect.Right-1, ARect.Bottom-1+2);
ListView1.Canvas.LineTo(ARect.Right-1, ARect.Top+2);
ListView1.Canvas.LineTo(ARect.Left, ARect.Top+2);
end
else begin
ListView1.Canvas.Pen.Color := Clwhite;
ListView1.Canvas.Pen.Width := 5;
ListView1.Canvas.MoveTo(ARect.Left, ARect.Top+3);
ListView1.Canvas.LineTo(ARect.Left, ARect.Bottom-1+3);
ListView1.Canvas.LineTo(ARect.Right-1, ARect.Bottom-1+3);
ListView1.Canvas.LineTo(ARect.Right-1, ARect.Top+3);
ListView1.Canvas.LineTo(ARect.Left, ARect.Top+3);
end;
SetBkMode(ListView1.Canvas.Handle, TRANSPARENT);
ListView_SetTextBkColor(ListView1.Handle, CLR_NONE);
ListView_SetBKColor(ListView1.Handle, CLR_NONE);
end;
//****************************************
// リストビューのOwnerDataをTrueにしている場合、
// OnDataイベントで自前で処理する必要がある
//****************************************
procedure TForm1.ListView1Data(Sender: TObject; Item: TListItem);
begin
Item.Caption := FFileList[Item.index];
end;
procedure TForm1.LoadFiles;
var
SearchRec: TSearchRec;
begin
if ShellTreeView1.Path ='' then Exit;
ListView1.Items.Clear;
FFileList.Clear;
// ファイル一覧作成
if FindFirst(ShellTreeView1.Path + '\*.jpg', faDirectory, SearchRec) = 0 then
begin
repeat
//if (SearchRec.Attr and faDirectory) = 0 then
begin
FFileList.Add(SearchRec.Name);
ListView1.Items.Add;
end;
until FindNext(SearchRec) <> 0;
FindClose(SearchRec);
end;
end;
// サムネイル用のファイル作成
//****************************************
// ディレクトリ変更
//****************************************
procedure TForm1.ShellTreeView1Change(Sender: TObject; Node: TTreeNode);
BEGIN
LoadFiles;
CreateThumbnail(ShellTreeView1.Path);
end;
procedure TForm1.Select_allExecute(Sender: TObject);
var
ax:integer;
begin
ProgressBar1.Min:=0;ProgressBar1.Position:=0;ProgressBar1.Max:=ListView1.Items.Count-1;
//listview1.SelectAll;
for ax:=0 to ListView1.Items.Count-1 do
begin
ProgressBar1.Position:=ax;
StatusBar1.Panels[1].text:=inttostr(ProgressBar1.Position)+'/'+inttostr(ProgressBar1.max)+' - '+LoadStringLanguage(12);
StatusBar1.Refresh;
ListView1.Items.item[ax].Selected:=true;
end;
listview1.SetFocus;
ProgressBar1.Position:=0;
end;
procedure TForm1.ArefreshExecute(Sender: TObject);
begin
LoadFiles;
CreateThumbnail(ShellTreeView1.Path);
end;
procedure TForm1.Select_noneExecute(Sender: TObject);
begin
listview1.Selected:=nil;
listview1.SetFocus;
end;
procedure TForm1.ListView1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key= VK_ESCAPE then
BEGIN
listview1.Selected:=nil;
listview1.SetFocus;
end;
if key= VK_F5 then
BEGIN
LoadFiles;
CreateThumbnail(ShellTreeView1.Path);
end;
end;
function string_digit(digit,nbr:integer):string ;
var nbr_digit : integer;
begin
nbr_digit:=0;
while nbr>=10 do
begin
nbr_digit:=nbr_digit+1;
nbr:=nbr div 10;
end;
Result:= StringOfChar('0',digit-nbr_digit)
end;
procedure TForm1.A_renameExecute(Sender: TObject);
var
Photos : Tform3.photarrtyp;
aax,ax,bbx,bx,count,countselected,digit,decplus: Integer;s : string;
JPegName,Sdate,newfilename:string;
ExifImage : TExif;
ImageSource:Tgraphic;
Tmpbitmap: Tbitmap;
AFormat: Word;
AData: THandle;
APalette: HPALETTE;
TFF:boolean;
Registre : TRegistry;
errorcode : Boolean;
inc_retry :integer;
rf: TForm3;
resultmodal:integer;
dummy : integer;
label
RetryRename1,
RetryRename2,
RetryRename3;
begin
rf := Tform3.passinfo(ListView1.Items,Photos, self,ShellTreeView1.Path,use_exif.Checked);
with TForm3.Create(self) do resultmodal:=ShowModal;
if resultmodal = 80 then
BEGIN
countselected:=0; digit:=0;
for ax := 0 to ListView1.Items.Count-1 do
if ListView1.Items.Item[ax].Selected then countselected:=countselected+1;
ProgressBar1.Position:=0;ProgressBar1.Min:=0; ProgressBar1.Max:=countselected;
SetLength(Photos,ListView1.Items.Count);
for ax := 0 to ListView1.Items.Count-1 do
begin
if ListView1.Items.Item[ax].Selected then begin
// s:= s + #10#13 + '(' +ListView1.Items.Item[ax].caption + ') -> ' + ShellTreeView1.Path + '\' + ListView1.Items.Item[ax].caption;
JPegName:=ShellTreeView1.Path + '\' + ListView1.Items.Item[ax].caption;
// s:= s + ListView1.Items.Item[ax].caption + chr(9) + ' -> ' + 'Date prise de vue = '+ ExifImage.DateTimeOriginal + chr(9) + ' File date : ' + DateToStr(FileDateToDateTime(FileAge(JPegName))) + chr(9) + TimeToStr(FileDateToDateTime(FileAge(JPegName))) + chr(13);
if use_exif.Checked then begin
ExifImage := TExif.Create;
// MessageBox(0,pchar(JPegName),'Infos',MB_OK);
ExifImage.ReadFromFile(JPegName);
Sdate:=ExifImage.DateTimeOriginal;
ExifImage.Free;
end;
if Sdate<>'?' then Sdate:=copy(Sdate,9,2) + '/' + copy(Sdate,6,2)+ '/' + copy(Sdate,1,4) + '_' + copy(Sdate,12,8);
if (use_exif.Checked=false) or (Sdate='?') then
Sdate:=DateToStr(FileDateToDateTime(FileAge(JPegName))) + '_' + TimeToStr(FileDateToDateTime(FileAge(JPegName)));
// Sdate:= StringReplace(Sdate,'/','-',[rfReplaceAll, rfIgnoreCase]);
Sdate:= StringReplace(Sdate,':','.',[rfReplaceAll, rfIgnoreCase]);
Sdate:=copy(Sdate,7,4)+'-'+copy(Sdate,4,2)+'-'+copy(Sdate,1,2)+'_'+copy(Sdate,12,8);
Photos[Ax].filename:= ListView1.Items.Item[ax].caption;
Photos[Ax].ssdate:=Sdate;
// s:= s + ListView1.Items.Item[ax].caption + chr(9) + ' -> ' + 'Date prise de vue = '+ Sdate + chr(13);
ProgressBar1.Position:=ProgressBar1.Position+1;ProgressBar1.Refresh;
StatusBar1.Panels[1].text:=inttostr(ProgressBar1.Position)+'/'+inttostr(ProgressBar1.max)+' - '+LoadStringLanguage(13);
StatusBar1.Refresh;
end;
Sdate:='';
end;
// MessageBox(0,PChar(s),'Infos',MB_OK);
Registre:=TRegistry.Create;
Registre.RootKey:=HKEY_CURRENT_USER;
Registre.OpenKey('SOFTWARE\Ledadu\Cronos Rename', true);
newfilename:=Registre.ReadString('Patern');
// Registre.Free;
//if InputQuery('Rename',LoadStringLanguage(10), newfilename) then
// BEGIN
ProgressBar1.Position:=0; // ProgressBar1.Step:=countselected div 10;
dummy:=countselected;
while dummy>=10 do
begin
digit:=digit+1;
dummy:=dummy div 10;
end;
// --- order general (*)
for ax := 0 to ListView1.Items.Count-1 do
if ListView1.Items.Item[ax].Selected then Photos[ax].samedate:=false;
count:=1;
for ax := 0 to ListView1.Items.Count-1 do
if ListView1.Items.Item[ax].Selected then
BEGIN
for bx := 0 to ListView1.Items.Count-1 do
if ListView1.Items.Item[bx].Selected then
begin
if Photos[ax].ssdate > Photos[bx].ssdate then count:=count+1;
if (Photos[ax].ssdate = Photos[bx].ssdate) and (Photos[bx].samedate=false) then begin count:=count+1;Photos[ax].samedate:=true;end; // recherche date identique technique astuce :D
end;
Photos[ax].order:=count-1;
count:=1;
ProgressBar1.Position:=ProgressBar1.Position+1;ProgressBar1.Refresh;
StatusBar1.Panels[1].text:=inttostr(ProgressBar1.Position)+'/'+inttostr(ProgressBar1.max)+' - '+LoadStringLanguage(14);
StatusBar1.Refresh;
Photos[ax].orderDate:=1; //init 1... orderdate (profiteur)
END;
// --- order DATE (? + *)
if (StrScan(PChar(newfilename),'?') <> nil) then begin
ProgressBar1.Position:=0;
for ax := 2 to ListView1.Items.Count do
for bx := 0 to ListView1.Items.Count-1 do
if Photos[bx].order=ax then
for bbx :=0 to ListView1.Items.Count-1 do // recherche date identique technique boucle
if Photos[bbx].order=ax-1 then BEGIN
if copy(Photos[bbx].ssdate,1,10)=copy(Photos[bx].ssdate,1,10) then Photos[bx].orderDate:=1+Photos[bbx].orderDate ;
// fo un break plus rapid.. c trouV
ProgressBar1.Position:=ProgressBar1.Position+1;ProgressBar1.Refresh;
StatusBar1.Panels[1].text:=inttostr(ProgressBar1.Position)+'/'+inttostr(ProgressBar1.max)+' - '+LoadStringLanguage(15);
StatusBar1.Refresh;
END;
end;
s:='';
ProgressBar1.Position:=0;
for ax := 0 to ListView1.Items.Count-1 do
if ListView1.Items.Item[ax].Selected then
BEGIN
// only *
if (StrScan(PChar(newfilename),'*') <> nil) and (StrScan(PChar(newfilename),'?') = nil) and (StrScan(PChar(newfilename),'%') = nil) then
BEgin
// inc_retry:=0; errorcode:=false;
// while (not errorcode) and (inc_retry<10) do begin
// inc_retry:=inc_retry+1;
errorcode:=RenameFile(
ShellTreeView1.Path + '\' + Photos[ax].filename,
ShellTreeView1.Path + '\' + StringReplace(newfilename,'*',string_digit(digit,Photos[ax].order)+ IntToStr(Photos[ax].order),[])+'.jpg'
);
// s:= s + Photos[ax].filename + chr(9) +newfilename + ' / ' + BoolToStr(errorcode)+ ' / ' + IntToStr(Photos[ax].order) + chr(10) ;
// end;
ENd;
// DATE + TIME
if (StrScan(PChar(newfilename),'*') = nil) and (StrScan(PChar(newfilename),'?') <> nil) and (StrScan(PChar(newfilename),'%') <> nil) then
RenameFile(
ShellTreeView1.Path + '\' + Photos[ax].filename,
ShellTreeView1.Path + '\' + StringReplace(StringReplace(newfilename,'?',copy(Photos[ax].ssdate,1,10),[rfReplaceAll, rfIgnoreCase]),'%',copy(Photos[ax].ssdate,12,8),[rfReplaceAll, rfIgnoreCase])+'.jpg'
);
// DATE + *
if (StrScan(PChar(newfilename),'*') <> nil) and (StrScan(PChar(newfilename),'?') <> nil) and (StrScan(PChar(newfilename),'%') = nil) then
BEgin
RenameFile(
ShellTreeView1.Path + '\' + Photos[ax].filename,
ShellTreeView1.Path + '\' + StringReplace(StringReplace(newfilename,'?',copy(Photos[ax].ssdate,1,10),[rfReplaceAll, rfIgnoreCase]),'*',string_digit(digit,Photos[ax].orderDate)+ IntToStr(Photos[ax].orderDate),[rfReplaceAll, rfIgnoreCase])+'.jpg'
);
ENd;
ProgressBar1.Position:=ProgressBar1.Position+1;ProgressBar1.Refresh;
StatusBar1.Panels[1].text:=inttostr(ProgressBar1.Position)+'/'+inttostr(ProgressBar1.max)+' - '+LoadStringLanguage(16);
StatusBar1.Refresh;
//=s+newfilename+string_digit(digit,Photos[ax].order)+ IntToStr(Photos[ax].order)+chr(13);
END; //fini renomage
// MessageBox(0,PChar(s),'Infos',MB_OK);
Registre.WriteString('Patern',newfilename);
LoadFiles;
CreateThumbnail(ShellTreeView1.Path);
END; // ValidedForm
Registre.Free;
ProgressBar1.Position:=0;
// END;
end;
procedure TForm1.ListView1Change(Sender: TObject; Item: TListItem;
Change: TItemChange);
begin
refresh_statusbar;
end;
procedure TForm1.refresh_statusbar;
var ax,count:integer;
pluriel:string;
BEGIN
count:=0;
for ax := 0 to ListView1.Items.Count-1 do
if ListView1.Items.Item[ax].Selected then count:=count+1;
pluriel:='';
if count>1 then StatusBar1.Panels[1].text:=IntToStr(count)+' '+ LoadStringLanguage(17) + 's '+LoadStringLanguage(18)
else StatusBar1.Panels[1].text:=IntToStr(count)+' '+ LoadStringLanguage(17) + ' '+LoadStringLanguage(19);
if count=0 then A_rename.Enabled:=false;
if count>0 then A_rename.Enabled:=true;
end;
procedure TForm1.ShellTreeView1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key= VK_F5 then
BEGIN
ShellTreeView1.Refresh(shellTreeView1.Topitem);
end;
end;
procedure TForm1.A_languageExecute(Sender: TObject);
begin
with TForm2.Create(self) do ShowModal;
RefreshLanguage;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
installer;
end;
procedure TForm1.ListView1_prevDblClick(Sender: TObject);
var
I: Integer;
begin
// if there is a selected item
if ListView1.Selected <> nil then
begin
// create and show a description
for I := 0 to ListView1.Items.Count -1 do
if ListView1.Items.Item[I].Selected then
begin
// ShowMessage (ShelltreeView1.Path + '\'+ListView1.Items.Item[I].caption);
ShellExecute(Handle, 'open', PChar( ShelltreeView1.Path + '\'+ListView1.Items.Item[I].caption), nil, nil, SW_SHOW);
break;
end;
end;
end;
end.