-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMario.pas
More file actions
executable file
·2203 lines (2061 loc) · 66.8 KB
/
Mario.pas
File metadata and controls
executable file
·2203 lines (2061 loc) · 66.8 KB
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
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit Mario;//V0.60
//A unit with usefull Methods
interface
uses
Windows, SysUtils, Classes, IniFiles, Registry, ShlObj, Tlhelp32, ShellApi,
JclMime, Jpeg, Graphics, URLMon, JclShell, Controls, ImgList, TntClasses,
JvBalloonHint, JvDialogs, JvComCtrls, Forms, ExtCtrls, TntStdCtrls,
JvFormWallpaper, JvPanel;
type
PHICON = ^HICON;
TIntArr8 = array [0..7] of integer;
//------------------------------------------------------------------------------
////////Procedures that use's basic units////////
//------------------------------------------------------------------------------
//Procedure SerielFileCreate1(Sender:TObject;MyFile:String);
Function MatInt2Bool(I:integer):Boolean;
Function MatBool2Int(bl:Boolean):integer;
Function MatBool2Str(bl:Boolean):String;
Procedure MatDirSubStructure(StartDir,WildCard:String;Var FileList:TStringList;
Var DirList:TStringList;IncludeDetails:Boolean);
Procedure MatDirCopy(StartDir:String;Destination:String);
Procedure MatDirMirrorCopy(StartDir:String;Destination:String);
Function MatDirLocal(StarDir:String;Destination:String):String;
Function MatStringDelete(Var StrLine:String;SubtractStr:String):Boolean;
Procedure MatStringDeleteFirstChar(Var StrLine:String;ExistingStr:String); Overload;
Procedure MatStringDeleteFirstChar(Var StrLine:WideString;ExistingStr:WideString); overload;
Procedure MatStringDeleteLastChar(Var StrLine:String;ExistingStr:String); Overload;
Procedure MatStringDeleteLastChar(Var StrLine:WideString;ExistingStr:WideString); Overload;
Procedure MatStringDelete2End(Var StrLine:String;SubtractStr:String); Overload;
Procedure MatStringDelete2End(Var StrLine:WideString;SubtractStr:WideString); Overload;
Procedure MatStringDeleteUp2(Var StrLine:String;SubtractStr:String;Xtra:integer=-1); Overload;
Procedure MatStringDeleteUp2(Var StrLine:WideString;SubtractStr:WideString;Xtra:integer=-1); Overload;
Procedure MatStringDirCheck(Var Dir:String);
Procedure MatStringReplace(Var Str:string;ExistingStr :String; ReplaceWith:String;Single:Boolean=false); Overload;
Procedure MatStringReplace(Var Str:WideString;ExistingStr :WideString; ReplaceWith:WideString;Single:Boolean=false); Overload;
Procedure MatWideStringReplace(Var Str:WideString;ExistingStr :WideString;
ReplaceWith:WideString);
Procedure MatStringsReplace(Var StrList:TstringList;ExistingStr :String;
ReplaceWith:String);
Procedure MatStringsDelete2End(var StrList:TStringList;ExistingStr:String);
Procedure MatStringAddComa(Var Str:String); Overload;
Procedure MatStringAddComa(Var Str:WideString); Overload;
function stringListTostrings(listData:TStringList):TStrings;
function stringsTostringList(listData:TStrings):TStringList;
function matStringCopyRemoveBack(Str:String;SearchCharacter:String):String;
function matStringCopyRemoveFrontBack(Str:String;SearchCharacter:String):String;
procedure MatDelay(msec:longint);
function matStringListNotEmpty(aList:TStringList):TStringList;
Function MatString2List(source, Delimiter:String):TStringList;
Function MatString2TntList(source, Delimiter:String;IgnDublicates:Boolean=False):TTntStringList;
Procedure MatStringFindLastSen(Var StrLine:string;DeleteChar:String);
function MatProcessKill(ExeFileName: string): Integer; //Uses Tlhelp32
Function MatStrToList(s,Delimiter:String):Tstringlist; Overload;
Function MatStrToList(s,Delimiter:WideString):TTntStringList; Overload;
function matListToStr(listData:tstringlist;Delimiter:string):string; Overload;
function matListToStr(listData:tstrings;Delimiter:string):string; overload;
function CountInLine(Str: string): Integer;
function stripEmptyLines(list:TTntStringList):TTntStringList;
//This takes the system settings into consideration
function floatString2DateTime(str:string):TDateTime;
function GetCharFromVirtualKey(Key: Word): string;
//------------------------------------------------------------------------------
////////Strip Procedures////////
//------------------------------------------------------------------------------
function stripStringIntegers(s:string; var intarr: TIntArr8):integer;
function getBORCommand(borline : string):string;
//------------------------------------------------------------------------------
////////Url Functions////////
//------------------------------------------------------------------------------
function MatUrlgetUrlList(aString:String):TStringList; Overload;
//------------------------------------------------------------------------------
////////Procedures that use the Files////////
//------------------------------------------------------------------------------
function MatTextLineFind(const AFileName: string; ALine: Integer): String;
function MatGetFileSize(const FileName: string): Integer;
function matFileStripExt(aFileName:String):String;
function matFileGetExt(aFileName:String):String;
procedure MatProcessRunWait(FileName,Paramters:String);
Procedure MatProcessRun( cmdline: String; hidden: Boolean );
function MatFileInUse(fName : string ) : Boolean;
Function MatGetfilesizeEx( const filename: String ): int64;
Function MatCompareFile2Stream(mmstrem:TMemoryStream;filename:String):Boolean;
//------------------------------------------------------------------------------
////////Procedures that use the SHELLAPI////////
//------------------------------------------------------------------------------
//Function executeApplication(FileName:String):Boolean; Overload
//Function executeApplicationzz(ProgramName, Paramaters : String; Wait: Boolean):Boolean;
Function exeAppBor(ProgramName : String; Paramaters:String=''; Wait: Boolean=False;UseProgramDir:Boolean=false):Boolean;
Function exeApp2(ProgramName : String):Boolean; overload;
Function exeApp(ProgramName : String; Paramaters:String=''; Wait: Boolean=False;UseProgramDir:Boolean=false):Boolean; overload;
//------------------------------------------------------------------------------
////////Procedures that use the JPEG unit////////
//------------------------------------------------------------------------------
Procedure MatJpeg2Bmp(JpgImage:TJPEGImage;Var ConvertedBmp:TBitmap);
//------------------------------------------------------------------------------
////////Procedures that use the UNIT "Registry"////////
//------------------------------------------------------------------------------
Procedure MatRegistryStartup(AddEntry:Boolean;Title:String;ProgramFile:string);
procedure MatRegistryAssociate(CMyExt:string;CMyFileType:string;
ProgramFile:string); //Also uses "ShlObj"
//------------------------------------------------------------------------------
////////Procedures that use the UNIT "URLMon"////////
//------------------------------------------------------------------------------
function DownloadFile(SourceFile, DestFile: string): Boolean;
function GetSystemDir: TFileName;
Function Component2String(Component: TComponent): string;
Function String2Component(Value: string;aComp: Tobject): TComponent;
procedure GetAssociatedIcon(FileName: TFilename;
PLargeIcon, PSmallIcon: PHICON);
//------------------------------------------------------------------------------
////////Balloon////////
//------------------------------------------------------------------------------
Procedure matMessageMouse(aMessage,Heading:String;Delay:Integer=2000;sender:TJvBalloonHint=nil);
//------------------------------------------------------------------------------
////////Jv Dialogs////////
//------------------------------------------------------------------------------
Procedure odSetExtension(oDialog:TJvOpenDialog;ext:WideString); overload;
Procedure odSetExtension(oDialog:TJvOpenDialog;ext:WideString;extDescription:Widestring); overload;
//------------------------------------------------------------------------------
////////Other////////
//------------------------------------------------------------------------------
Function isValidBitmap(aFileName:String):Boolean;
Procedure pcSetFont(pController:TJvPageControl;newFont:TFont);
procedure centreFisrtInsideSecond(var innerPanel:TPanel; outerObject:TObject; innersubheight:integer = 0); Overload;
procedure centreFisrtInsideSecond(var innerPanel:TjvPanel; outerObject:TObject; top:integer=0; innersubheight:integer=0); Overload;
procedure centreFisrtInsideSecond(var innerMemo:TTntMemo; outerObject:TObject; innersubheight:integer=0); Overload;
//------------------------------------------------------------------------------
////////Dates////////
//------------------------------------------------------------------------------
function stripDateTime(isDate:Boolean;fDateTime:TDateTime):TDateTime;
function CopyDir(const fromDir, toDir: string): Boolean;
function MoveDir(const fromDir, toDir: string): Boolean;
function DelDir(dir: string): Boolean;
implementation
uses VarCmplx;
//Create a proccess and locks until its closed
{Function executeApplication(FileName:String):Boolean;
var
StartupInfo: TStartupinfo;
ProcessInfo: TProcessInformation;
ShortFileName, DirNme, s : String;
begin
Try
If FileName = '' then
exit;
Result := True;
FillChar(Startupinfo,Sizeof(TStartupinfo),0);
Startupinfo.cb:=Sizeof(TStartupInfo);
StartupInfo.wShowWindow := SW_HIDE ; //add this to start it hidden
ShortFileName := LowerCase(ExtractFileName(FileName));
DirNme := LowerCase(ExtractFilePath(FileName));
s := ShellFindExecutable(ShortFileName,DirNme);
If s <> '' then begin
ShortFileName := ExtractFileName(s);
DirNme := ExtractFilePath(s);
s := DirNme + ShortFileName + ' "' + FileName + '"';
if CreateProcess(nil,
pchar(s),
nil,
nil,
false,
normal_priority_class,
nil,
pchar(DirNme),
Startupinfo,
ProcessInfo) then
begin
WaitforSingleObject(Processinfo.hProcess, infinite);
CloseHandle(ProcessInfo.hProcess);
Result := True;
end;
end
else
Result := False;
Except
Result := False;
end;
end;}
Procedure MatJpeg2Bmp(JpgImage:TJPEGImage;Var ConvertedBmp:TBitmap);
Begin
try
ConvertedBmp.Assign(JpgImage);
finally
end;
End;
//What It Does
//Deletes from the begining of a string up to the intended character
Procedure MatStringDeleteUp2(Var StrLine:String;SubtractStr:String;Xtra:integer=-1);
Begin
If Pos(SubtractStr,StrLine) <> 0 then
Begin
if Xtra <> -1 then
Delete(StrLine,1,Pos(SubtractStr,StrLine)+Xtra)
else
Delete(StrLine,1,Pos(SubtractStr,StrLine));
End;
End;
Procedure MatStringDeleteUp2(Var StrLine:WideString;SubtractStr:WideString;Xtra:integer=-1); Overload;
Begin
If Pos(SubtractStr,StrLine) <> 0 then
Begin
if Xtra <> -1 then
Delete(StrLine,1,Pos(SubtractStr,StrLine)+Xtra)
else
Delete(StrLine,1,Pos(SubtractStr,StrLine));
End;
End;
//What It Does
//Checks if a file is currently being used by a program
function MatFileInUse(fName : string ) : boolean;
var
HFileRes : HFILE;
begin
Result := false;
if not FileExists(fName) then
exit;
HFileRes := CreateFile(pchar(fName), GENERIC_READ or GENERIC_WRITE,0, nil, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, 0);
Result := (HFileRes = INVALID_HANDLE_VALUE);
if not Result then
CloseHandle(HFileRes);
end;
Function MatGetfilesizeEx( const filename: String ): int64;
Var
SRec: TSearchrec;
converter: packed record
case Boolean of
false: ( n: int64 );
true : ( low, high: DWORD );
end;
Begin
If FindFirst( filename, faAnyfile, SRec ) = 0 Then Begin
converter.low := SRec.FindData.nFileSizeLow;
converter.high:= SRec.FindData.nFileSizeHigh;
Result:= converter.n;
FindClose( SRec );
End
Else
Result := -1;
End;
Function MatCompareFile2Stream(mmstrem:TMemoryStream;filename:String):Boolean;
Var
aStream: TMemoryStream;
Begin
try
if FileExists(filename) then Begin
aStream := TMemoryStream.Create;
aStream.LoadFromFile(filename);
if aStream.Size = mmstrem.Size then
Result := true
Else
Result := false;
FreeAndNil(aStream);
End else
Result := false;
except
Result := false;
end;
End;
//What it does
//Can run a dos command and include writing the results to a file with the
// ' > c:\file.txt ' command
Procedure MatProcessRun( cmdline: String; hidden: Boolean );
Const
flags : Array [Boolean] of Integer = (SW_SHOWNORMAL, SW_HIDE);
Var
cmdbuffer: Array [0..MAX_PATH] of Char;
Begin
GetEnvironmentVariable( 'COMSPEC', cmdBUffer, Sizeof(cmdBuffer));
StrCat( cmdbuffer, ' /C ');
StrPCopy( StrEnd(cmdbuffer), cmdline );
WinExec( cmdbuffer, flags[hidden] );
End;
//What It Does
//Starts a program and waits until it has finished running then carry's on
//Notes
//Has A String length limit not to sure how much yet
procedure MatProcessRunWait(FileName,Paramters:String);
var
StartupInfo: TStartupinfo;
ProcessInfo: TProcessInformation;
cmdbuffer: Array [0..MAX_PATH] of Char;
FileDetailz :WideString;
Filez :PAnsiChar;
begin
FileDetailz := FileName + ' ' + Paramters;
StrPCopy( StrEnd(cmdbuffer), FileDetailz );
Filez := PAnsichar(FileName + ' ' + Paramters);
FillChar(Startupinfo,Sizeof(TStartupinfo),0);
Startupinfo.cb:=Sizeof(TStartupInfo);
//StartupInfo.wShowWindow := SW_HIDE ; //add this to start it hidden
CreateProcess(nil,
cmdbuffer,
nil,
nil,
false,
normal_priority_class,
nil,
Nil,
Startupinfo,
ProcessInfo);
begin
WaitforSingleObject(Processinfo.hProcess, infinite);
CloseHandle(ProcessInfo.hProcess);
end;
End;
function MatGetFileSize(const FileName: string): Integer;
var
SearchRec: TSearchRec;
OldMode: Cardinal;
begin
Result := -1;
OldMode := SetErrorMode(SEM_FAILCRITICALERRORS);
try
if FindFirst(FileName, faAnyFile, SearchRec) = 0 then
begin
Result := SearchRec.Size;
SysUtils.FindClose(SearchRec);
end;
finally
SetErrorMode(OldMode);
end;
End;
Procedure MatStringReplace(Var Str:string;ExistingStr :String;
ReplaceWith:String;Single:Boolean=false);
Var
j :Integer;
Begin
j := Pos(Lowercase(ExistingStr),Lowercase(Str));
If Single = false then Begin
While j <> 0 Do
Begin
//Keep finding and replaceing the string
delete(Str,j,length(ExistingStr));
Insert(ReplaceWith, Str,j);
j := Pos(Lowercase(ExistingStr),Lowercase(Str));
End;
End Else Begin
delete(Str,j,length(ExistingStr));
Insert(ReplaceWith, Str,j);
End;
End;
Procedure MatStringReplace(Var Str:WideString;ExistingStr :WideString; ReplaceWith:WideString;Single:Boolean=false); Overload;
Var
j :Integer;
Begin
j := Pos(Lowercase(ExistingStr),Lowercase(Str));
If Single = false then Begin
While j <> 0 Do
Begin
//Keep finding and replaceing the string
delete(Str,j,length(ExistingStr));
Insert(ReplaceWith, Str,j);
j := Pos(Lowercase(ExistingStr),Lowercase(Str));
End;
End Else Begin
delete(Str,j,length(ExistingStr));
Insert(ReplaceWith, Str,j);
End;
End;
Procedure MatWideStringReplace(Var Str:WideString;ExistingStr :WideString;
ReplaceWith:WideString);
Var
j :Integer;
Begin
j := Pos(Lowercase(ExistingStr),Lowercase(Str));
While j <> 0 Do
Begin
//Keep finding and replaceing the string
delete(Str,j,length(ExistingStr));
Insert(ReplaceWith, Str,j);
j := Pos(Lowercase(ExistingStr),Lowercase(Str));
End;
End;
//What It Does
//retrieves a line from a text file in a real high speed manner
function MatTextLineFind(const AFileName: string; ALine: Integer): string;
var
fs: TFileStream;
buf: packed array[0..4095] of Char;
bufRead: Integer;
bufPos: PChar;
lineStart: PChar;
tmp: string;
begin
fs := TFileStream.Create(AFileName, fmOpenRead);
try
Dec(ALine);
bufRead := 0;
bufPos := nil;
{ read the first line specially }
if ALine = 0 then
begin
bufRead := fs.Read(buf, SizeOf(buf));
if bufRead = 0 then
raise Exception.Create('Line not found');
bufPos := buf;
end else
while ALine > 0 do
begin
{ read in a buffer }
bufRead := fs.Read(buf, SizeOf(buf));
if bufRead = 0 then
raise Exception.Create('Line not found');
bufPos := buf;
while (bufRead > 0) and (ALine > 0) do
begin
if bufPos^ = #10 then
Dec(ALine);
Inc(bufPos);
Dec(bufRead);
end;
end;
{ Found the beginning of the line at bufPos... scan for end.
2 cases:
1) we'll find it before the end of this buffer
2) it'll go beyond this buffer and into n more buffers}
lineStart := bufPos;
while (bufRead > 0) and (bufPos^ <> #10) do
begin
Inc(bufPos);
Dec(bufRead);
end;
{ if bufRead is positive, we'll have found the end and we can leave. }
SetString(Result, lineStart, bufPos - lineStart);
{ determine if there are more buffers to process }
while bufRead = 0 do
begin
bufRead := fs.Read(buf, SizeOf(buf));
lineStart := buf;
bufPos := buf;
while (bufRead > 0) and (bufPos^ <> #10) do
begin
Inc(bufPos);
Dec(bufRead);
end;
SetString(tmp, lineStart, bufPos - lineStart);
Result := Result + tmp;
end;
finally
fs.Free;
end;
end;
//What it does
//shuts down a chosen running program
//Seems to only work with NT OS's
function MatProcessKill(ExeFileName: string): integer;
const
PROCESS_TERMINATE=$0001;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
result := 0;
FSnapshotHandle := CreateToolhelp32Snapshot
(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle,
FProcessEntry32);
while integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
UpperCase(ExeFileName))
or (UpperCase(FProcessEntry32.szExeFile) =
UpperCase(ExeFileName))) then
Result := Integer(TerminateProcess(OpenProcess(
PROCESS_TERMINATE, BOOL(0),
FProcessEntry32.th32ProcessID), 0));
ContinueLoop := Process32Next(FSnapshotHandle,
FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
End;
//What it does
//Associates file type with a program
//Example - MatRegistryAssociate('.Dxi','Calculater File','c:\Calculate.exe')
procedure MatRegistryAssociate(CMyExt:string;CMyFileType:string;ProgramFile:string);
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
try
// Set the root key to HKEY_CLASSES_ROOT
Reg.RootKey := HKEY_CLASSES_ROOT;
// Now open the key, with the possibility to create
// the key if it doesn't exist.
Reg.OpenKey(cMyExt, True);
// Write my file type to it.
// This adds HKEY_CLASSES_ROOT\.abc\(Default) = 'Project1.FileType'
Reg.WriteString('', cMyFileType);
Reg.CloseKey;
// Now create an association for that file type
Reg.OpenKey(cMyFileType, True);
// This adds HKEY_CLASSES_ROOT\Project1.FileType\(Default)
// = 'Project1 File'
// This is what you see in the file type description for
// the a file's properties.
Reg.WriteString('', 'Project1 File');
Reg.CloseKey;
// Now write the default icon for my file type
// This adds HKEY_CLASSES_ROOT\Project1.FileType\DefaultIcon
// \(Default) = 'Application Dir\Project1.exe,0'
Reg.OpenKey(cMyFileType + '\DefaultIcon', True);
Reg.WriteString('', ProgramFile + ',0');
Reg.CloseKey;
// Now write the open action in explorer
Reg.OpenKey(cMyFileType + '\Shell\Open', True);
Reg.WriteString('', '&Open');
Reg.CloseKey;
// Write what application to open it with
// This adds HKEY_CLASSES_ROOT\Project1.FileType\Shell\Open\Command
// (Default) = '"Application Dir\Project1.exe" "%1"'
// Your application must scan the command line parameters
// to see what file was passed to it.
Reg.OpenKey(cMyFileType + '\Shell\Open\Command', True);
Reg.WriteString('', '"' + ProgramFile + '" "%1"');
Reg.CloseKey;
// Finally, we want the Windows Explorer to realize we added
// our file type by using the SHChangeNotify API.
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
finally
Reg.Free;
end;
end;
//What it Does
//Add or remove program to windows startup in the registry
//If u say false then it removes it from the registry
//Example - MatRegistryStartup(True,'Windows Manager','C:\ProgrammStartetr.exe');
Procedure MatRegistryStartup(AddEntry:Boolean;Title:String;ProgramFile:string);
var
reg: TRegistry;
begin
Try
reg := TRegistry.Create;
reg.RootKey := HKEY_LOCAL_MACHINE;
reg.LazyWrite := false;
reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Run',false);
reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Run',
false);
//If true then add to startup
If AddEntry = true then
reg.WriteString(Title, ProgramFile)
Else
//If false then remove from startup
If reg.ValueExists(Title) then
Reg.DeleteValue(Title);
Finally
reg.CloseKey;
reg.free;
End;
End;
//What it does
//Causes a delay
procedure MatDelay(msec:longint);
var
start,stop:longint;
begin
start := gettickcount;
repeat
stop := gettickcount;
//application.processmessages;
until (stop - start ) >= msec;
end;
function matStringListNotEmpty(aList:TStringList):TStringList;
Var
i : Integer;
s : string;
Begin
i := 0;
while i < aList.Count do Begin
s := aList.Strings[i];
if s = ' ' then
aList.Delete(i)
Else
inc(i);
End;
Result := aList;
End;
//Example MatStringList('Edit1\bob\sweet\what','\')
Function MatString2List(source, Delimiter:String):TStringList;
Var
list : TStringList;
s,s1 : String;
Begin
If source = '' then exit;
If Delimiter = '' then exit;
list := TStringList.Create;
s := source;
s1 := source;
While pos(Delimiter,s1) >0 do Begin
MatStringDelete2End(s,Delimiter);
list.Add(s);
MatStringDeleteUp2(s1,Delimiter);
s := s1
End;
If s1 <> '' then
list.Add(s1);
Result := list;
End;
Function MatString2TntList(source, Delimiter:String;IgnDublicates:Boolean=False):TTntStringList;
Var
list : TTntStringList;
s,s1 : String;
Begin
If source = '' then exit;
If Delimiter = '' then exit;
list := TTntStringList.Create;
if IgnDublicates = true then Begin
list.Sorted := true;
List.Duplicates := dupIgnore;
End;
s := source;
s1 := source;
While pos(Delimiter,s1) >0 do Begin
MatStringDelete2End(s,Delimiter);
list.Add(s);
MatStringDeleteUp2(s1,Delimiter);
s := s1
End;
If s1 <> '' then
list.Add(s1);
Result := list;
End;
//What it does
//It deletes a section from the given string and returns it
Function MatStringDelete(Var StrLine:String;SubtractStr:String):Boolean;
Begin
If Pos(SubtractStr,StrLine) <> 0 then
Begin
Delete(StrLine,Pos(SubtractStr,StrLine),Length(SubtractStr));
Result := true;
End
Else
Result := False;
End;
//What it does
//It deletes to the end of a given string and returns it
Procedure MatStringDeleteFirstChar(Var StrLine:String;ExistingStr:String);
Var
s : String;
Begin
if StrLine <> '' then Begin
s := StrLine[1];
While s = ExistingStr do Begin
Delete(StrLine,1,1);
s := StrLine[1];
End;
end;
End;
Procedure MatStringDeleteFirstChar(Var StrLine:WideString;ExistingStr:WideString); overload;
Var
s : WideString;
Begin
s := StrLine[1];
While s = ExistingStr do Begin
Delete(StrLine,1,1);
s := StrLine[1];
End;
End;
Procedure MatStringDeleteLastChar(Var StrLine:String;ExistingStr:String);
Var
s : String;
Begin
s := StrLine;
if s <> '' then Begin
if Length(StrLine) > 1 then
s := StrLine[Length(StrLine)]
else
s := StrLine;
While (s = ExistingStr) and
(s <> '') do Begin
Delete(StrLine,Length(StrLine),1);
if s <> '' then
s := StrLine[Length(StrLine)];
End;
end;
End;
Procedure MatStringDeleteLastChar(Var StrLine:WideString;ExistingStr:WideString); Overload;
Var
s : WideString;
Begin
s := StrLine;
if s <> '' then Begin
if Length(StrLine) > 1 then
s := StrLine[Length(StrLine)]
else
s := StrLine;
While s = ExistingStr do Begin
Delete(StrLine,Length(StrLine),1);
s := StrLine[Length(StrLine)];
End;
end;
End;
Procedure MatStringDelete2End(Var StrLine:String;SubtractStr:String);
Begin
If Pos(SubtractStr,StrLine) <> 0 then
Begin
Delete(StrLine,Pos(SubtractStr,StrLine),50000);
End;
End;
Procedure MatStringDelete2End(Var StrLine:WideString;SubtractStr:WideString); Overload;
Begin
If Pos(SubtractStr,StrLine) <> 0 then
Begin
Delete(StrLine,Pos(SubtractStr,StrLine),50000);
End;
End;
//What it does
//Checks if the last line of a dir is a \ or not then adds if needed.
Procedure MatStringDirCheck(Var Dir:String);
Begin
If Dir[Length(Dir)] = '\' then
Dir := Dir
Else
Dir := Dir+'\';
End;
Function MatInt2Bool(I:integer):Boolean;
Begin
If I = 1 then
Result := True
Else
Result := False;
End;
Function MatBool2Int(bl:Boolean):integer;
Begin
If bl = true then
Result := 1
Else
Result := 0;
End;
Function MatBool2Str(bl:Boolean):String;
Begin
if bl = true then
result := 'True'
Else
Result := 'False';
End;
//Fully operational, however I think that it can still be optimized.
//what it does
//it scan's the given directory and returns
//a file list and a directory list
//Not Yet - Also you can Ask for file sizes aswell
Procedure MatDirSubStructure(StartDir, WildCard:String;Var FileList:TStringList;Var DirList:TStringList;IncludeDetails:Boolean);
Var
FileDetails : TSearchRec;
DirToCheckList :TstringList;
i : Integer;
TmpStr01 :String;
Begin
Try
if FileList = nil then
FileList := TStringList.Create;
if DirList = nil then
DirList := TStringList.Create;
//Sort File/Dir list and don't allow duplicates
If FileList.Sorted = False then
Begin
FileList.Sorted := True;
FileList.Duplicates := dupIgnore;
End;
If DirList.Sorted = False then
Begin
DirList.Sorted := True;
DirList.Duplicates := dupIgnore;
End;
If StartDir[Length(StartDir)] = '\' then
StartDir := StartDir
Else
StartDir := StartDir +'\';
DirList.Add(StartDir);
//Create a list for sub directorys to be checked
DirToCheckList := TStringList.Create;
DirToCheckList.Sorted := True;
DirToCheckList.Duplicates := dupIgnore;
//Find the first file/dir of selected dir
FindFirst(StartDir + WildCard, faAnyFile, FileDetails);
// If (FileDetails.Size > 0) then
If FileExists(StartDir + FileDetails.Name) then
Begin
//Add the existing file into the file list with all its details
If IncludeDetails = false then
FileList.Add(StartDir
+ FileDetails.Name)
Else
FileList.Add(StartDir
+ FileDetails.Name
+ #09
+ IntToStr(FileDetails.size));
End
Else
//Add the existing Directory into the Dir list with all its details
If (FileDetails.Name <> '.') then
If (FileDetails.Name <> '..') then
If DirectoryExists(StartDir + FileDetails.Name) then
Begin
DirList.Add(StartDir
+ FileDetails.Name
+ '\');
DirToCheckList.Add(StartDir
+ FileDetails.Name
+ '\');
End;
//Repeat until all files/dirs have been found
While (FindNext(FileDetails)) = 0 do
Begin
// If (FileDetails.Size > 0) then
If FileExists(StartDir + FileDetails.Name) then
Begin
//Add the existing file into the file list with all its details
If IncludeDetails = false then
FileList.Add(StartDir
+ FileDetails.Name)
Else
FileList.Add(StartDir
+ FileDetails.Name
+ #09
+ IntToStr(FileDetails.size));
End
Else
If (FileDetails.Name <> '.') then
If (FileDetails.Name <> '..') then
If DirectoryExists(StartDir + FileDetails.Name) then
Begin
//Add the existing Directory into the Dir list with all its details
DirList.Add(StartDir
+ FileDetails.Name
+ '\');
DirToCheckList.Add(StartDir
+ FileDetails.Name
+'\');
End;
End;
FindClose(FileDetails);
//Recall this procedure to find all subdirectorys
i := 0;
While i < DirToCheckList.Count do
Begin
TmpStr01 := DirToCheckList.Strings[i];
MatDirSubStructure(DirToCheckList.Strings[i],'*.*',FileList,DirList,IncludeDetails);
Inc(i);
End;
Finally
DirToCheckList.Free;
End;
End;
//What it does
//Copy's the given dir and subdirs to the destination dir
Procedure MatDirCopy(StartDir:String;Destination:String);
Var
MySourceFileList, MySourceDirList :TstringList;
MyDestFileList, MyDestDirList :TstringList;
TmpStr01,TmpStr02 :String;
i :Integer;
Begin
Try
//Create all file lists
MySourceFileList := TStringList.Create;
MySourceFileList.Sorted := True;
MySourceDirList := TStringList.Create;
MyDestFileList := TStringList.Create;
MyDestFileList.Sorted := True;
MyDestDirList := TStringList.Create;
// Make sure the startdir is set right
If StartDir[Length(StartDir)] = '\' then
StartDir := StartDir
Else
StartDir := StartDir +'\';
// Make sure the startdir is set right
If Destination[Length(Destination)] = '\' then
Destination := Destination
Else
Destination := Destination +'\';
//Find all files/dirs and subdirs
MatDirSubStructure(StartDir,'*.*',MySourceFileList,MySourceDirList,False);
For i := 0 to MySourceFileList.Count -1 do
Begin
//Make sure all destination files are to be saved at the right places
TmpStr01 := MySourceFileList.Strings[i];
MatStringDelete(TmpStr01,StartDir);
TmpStr02 := ExtractFileDir(Startdir);
TmpStr02 := ExtractFileName(TmpStr02);
MyDestFileList.Add(Destination
+TmpStr02
+'\'
+TmpStr01);
End;
For i := 0 to MySourceDirList.Count -1 do
Begin
//Make sure all destination Directories are to be saved at the right places
TmpStr01 := MySourceDirList.Strings[i];
MatStringDelete(TmpStr01,StartDir);
TmpStr02 := ExtractFileDir(Startdir);
TmpStr02 := ExtractFileName(TmpStr02);
If i <> 0 then
MyDestDirList.Add(Destination
+TmpStr02
+'\'
+TmpStr01)
Else
MyDestDirList.Add(Destination
+TmpStr02);
End;
For i := 0 to MyDestDirList.Count -1 do
Begin
//Create all needed directories
If not DirectoryExists(MyDestDirList.Strings[i]) then
CreateDirectory(Pchar(MyDestDirList.Strings[i]),nil);
End;
For i := 0 to MyDestFileList.Count -1 do
Begin
//Copy All Files
CopyFile(pchar(MySourceFileList.Strings[i]),pchar(MyDestFileList.strings[i]),False);
End;
// MyDestFileList.SaveToFile('c:\DestFile');
// MyDestDirList.SaveToFile('c:\DestDir');
Finally
MySourceFileList.Free;
MySourceDirList.Free;
MyDestFileList.Free;
MyDestDirList.Free;
End;
End;
//What It Does
//Compares and Copy's Diff. files/Dirs/SubDirs
//It will only copy a file if it either doesn't exist or if it's Diff.
Procedure MatDirMirrorCopy(StartDir:String;Destination:String);
Var
MySourceFileList, MySourceDirList :TstringList;