home *** CD-ROM | disk | FTP | other *** search
- Unit STI_DIR;
- {$I-}
- interface
-
- uses
- Crt,Dos,STI_SCRF,STI_STRN;
-
- Var
- Drive : string[3];
- Search,
- Path : string;
-
- function STI_SelectFile(X1,Y1,X2,Y2,Tcol,Pcol,Bcol,TTCol : byte; Border,Mask : string) : string;
-
-
- implementation
-
- const
- MAXDIR = 512;
-
- type
- FileBuffer = record
- Name : string[13];
- end;
- BigBuffer = array[1..MAXDIR] of FileBuffer;
-
- var
- Handle : WindowSave;
- CurrentDir : ^BigBuffer;
- DirCount : Word;
-
- {---------------------------------------------------------------------------}
-
- procedure GetFiles; { get the file in this dir }
-
- var
- F : SearchRec; { used to find files }
-
- begin
- for DirCount := 1 to MAXDIR do { loop over buffer }
- begin
- CurrentDir^[DirCount].Name := ''; { null the name }
- end;
- DirCount := 1; { reset dircount }
- FindFirst(Drive+Path+Search, AnyFile, F); { find any file }
- While((DosError = 0) and (DirCount < MAXDIR)) do { loop over names }
- begin
- CurrentDir^[DirCount].Name := F.Name;{ this is the file name }
- if F.Attr = 16 then
- CurrentDir^[DirCount].Name :=
- CurrentDir^[DirCount].Name + '\'; { add a \ if it's a directory }
- FindNext(F); { get the next file }
- Inc(DirCount); { increment dircount }
- end;
- Dec(DirCount); { dircount is always too big }
- end;
-
- {---------------------------------------------------------------------------}
-
- procedure SortFiles(L,R : Integer); { quicksort the files }
-
- var
- I,J : integer;
- X,Y : FileBuffer;
-
- begin
- I := L; J := R;
- X.Name := CurrentDir^[(L+R) div 2].Name;
- repeat
- while CurrentDir^[I].Name < X.Name do Inc(I);
- while X.Name < CurrentDir^[J].Name do Dec(J);
- if I <= J then
- begin
- Y.Name := CurrentDir^[I].Name;
- CurrentDir^[I].Name := CurrentDir^[J].Name;
- CurrentDir^[J].Name := Y.Name;
- Inc(I);
- Dec(J);
- end;
- until I > J;
- if L < J then SortFiles(L,J);
- if I < R then SortFiles(I,R);
- end;
-
- {---------------------------------------------------------------------------}
-
- procedure Reset_Colors;
-
- begin
- TextColor(White);
- TextReverse(NoReverse);
- end;
-
- {---------------------------------------------------------------------------}
-
- procedure PrintFiles(X1,Y1,X2,Y2,Tcol,Start : Word);
-
- var
- Loop1,Loop2 : Byte;
- Count : Word;
-
- begin
- Reset_Colors;
- GotoXY(X1+2,Y1+1);
- TextColor(TCol);
- Write(MakeStr((X2-X1)-4,32));
- GotoXY(X1+2,Y1+1);
- Write(Copy('Path : '+Drive+Path+Search,1,(X2-X1)-4));
- Count := 0;
- for Loop2 := 1 to (Y2-Y1)-2 do
- begin
- for Loop1 := 1 to (X2-X1) div 15 do
- begin
- GotoXY(X1+((Loop1-1) * 15)+2,Y1+Loop2+1);
- Write(Copy(CurrentDir^[Start+Count].Name+' ',1,13));
- if(Start+Count) <= DirCount then
- Inc(Count);
- end;
- end;
- end;
-
- {---------------------------------------------------------------------------}
-
- function ValidDrive(InString : string) : boolean;
-
- begin
- InString := UpCaseStr(InString);
- ValidDrive := ((InString[2] = ':') and (InString[1] in ['A'..'Z'])) or
- (InString = '');
- end;
-
- {---------------------------------------------------------------------------}
-
- function Select_File_Key(X1,Y1,X2,Y2,Tcol,Pcol : byte) : string;
-
- var
- X,Y : integer;
- Loop,
- Select : word;
- Page : word;
- inch : char;
- Dummy : string;
-
- begin
- HiddenCursor;
- X := X1+2; Y := Y1+2;
- Select := 1;
- Page := 0;
- inch := #0;
- GetFiles;
- if Dircount > 1 then SortFiles(1,DirCount);
- if DirCount >= 1 then
- PrintFiles(X1,Y1,X2,Y2,Tcol,1)
- else
- begin
- Reset_Colors;
- for Loop := Y1+1 to Y2-1 do
- begin
- gotoxy(X1+1,Loop);
- write(MakeStr((X2-X1)-1,32));
- end;
- TextColor(TCol);
- GotoXY(X1+2,Y1+1);
- Write('No Files');
- end;
- repeat
- begin
- Reset_Colors;
- TextColor(PCol);
- GotoXY(X,Y);
- Write(Copy(CurrentDir^[Select+Page].Name+' ',1,13));
- repeat until KeyPressed;
- inch := ReadKey;
- Reset_Colors;
- TextColor(TCol);
- GotoXY(X,Y);
- Write(Copy(CurrentDir^[Select+Page].Name+' ',1,13));
- case UpCase(inch) of
- #70 : begin
- GotoXY(X1+2,Y1+1); Write(MakeStr((X2-X1)-4,32));
- GotoXy(X1+2,Y1+1); Write('File : ');
- Readln(Dummy);
- GotoXY(X1+2,Y1+1); Write(MakeStr((X2-X1)-4,32));
- Select_File_Key := UpCaseStr(Dummy);
- Exit;
- end;
- #27 : begin
- Select_File_Key := '';
- Exit;
- end;
- #68 : begin
- Dummy := 'QQQQ';
- while not(ValidDrive(Dummy)) do
- begin
- GotoXY(X1+2,Y1+1); Write(MakeStr((X2-X1)-4,32));
- GotoXy(X1+2,Y1+1); Write('Drive : ');
- Readln(Dummy);
- GotoXY(X1+2,Y1+1); Write(MakeStr((X2-X1)-4,32));
- Dummy := UpCaseStr(Dummy);
- end;
- if Dummy <> '' then
- Drive := Dummy;
- Path := '\';
- GetFiles;
- if DirCount > 1 then SortFiles(1,DirCount);
- if DirCount >= 1 then
- PrintFiles(X1,Y1,X2,Y2,Tcol,1)
- else
- begin
- Reset_Colors;
- for Loop := Y1+1 to Y2-1 do
- begin
- gotoxy(X1+1,Loop);
- write(MakeStr((X2-X1)-1,32));
- end;
- TextColor(TCol);
- GotoXY(X1+2,Y1+1);
- Write('No Files');
- end;
- Select := 1;
- X := X1+2;
- Y := Y1+2;
- Page := 0;
- end;
- #80 : begin
- GotoXY(X1+2,Y1+1); Write(MakeStr((X2-X1)-4,32));
- GotoXy(X1+2,Y1+1); Write('Path : ');
- Readln(Dummy);
- GotoXY(X1+2,Y1+1); Write(MakeStr((X2-X1)-4,32));
- if Dummy <> '' then
- Path := UpCaseStr(Dummy);
- GetFiles;
- if DirCount > 1 then SortFiles(1,DirCount);
- if DirCount >= 1 then
- PrintFiles(X1,Y1,X2,Y2,Tcol,1)
- else
- begin
- Reset_Colors;
- for Loop := Y1+1 to Y2-1 do
- begin
- gotoxy(X1+1,Loop);
- write(MakeStr((X2-X1)-1,32));
- end;
- TextColor(TCol);
- GotoXY(X1+2,Y1+1);
- Write('No Files');
- end;
- Select := 1;
- X := X1+2;
- Y := Y1+2;
- Page := 0;
- end;
- #77 : begin
- GotoXY(X1+2,Y1+1); Write(MakeStr((X2-X1)-4,32));
- GotoXy(X1+2,Y1+1); Write('Mask : ');
- Readln(Dummy);
- GotoXY(X1+2,Y1+1); Write(MakeStr((X2-X1)-4,32));
- if Dummy <> '' then
- Search := UpCaseStr(Dummy);
- GetFiles;
- if DirCount > 1 then SortFiles(1,DirCount);
- if DirCount >= 1 then
- PrintFiles(X1,Y1,X2,Y2,Tcol,1)
- else
- begin
- Reset_Colors;
- for Loop := Y1+1 to Y2-1 do
- begin
- gotoxy(X1+1,Loop);
- write(MakeStr((X2-X1)-1,32));
- end;
- TextColor(TCol);
- GotoXY(X1+2,Y1+1);
- Write('No Files');
- end;
- Select := 1;
- X := X1+2;
- Y := Y1+2;
- Page := 0;
- end;
- #8 : begin {<-}
- Dec(X,15);
- if X < X1+2 then
- begin
- Inc(X,15);
- end
- else
- if Select + Page > 1 then
- Dec(Select);
- end;
- #10 : begin {down}
- Inc(Y);
- if (Y > Y2-1) then
- begin
- if (Page+Select+((X2-X1) div 15)) < DirCount then
- begin
- Page := Page + ((X2-X1) div 15);
- PrintFiles(X1,Y1,X2,Y2,Tcol,Page+1);
- Dec(Y);
- end
- else
- Dec(Y);
- end
- else
- if (Page + Select + ((X2-X1) div 15)) <= DirCount then
- Inc(Select,((X2-X1) div 15))
- else
- Dec(Y);
- end;
- #11 : begin {up}
- Dec(Y);
- if (Y < Y1+2) then
- begin
- if Page > 0 then
- begin
- Inc(Y);
- Page := Page - ((X2-X1) div 15);
- PrintFiles(X1,Y1,X2,Y2,Tcol,Page+1);
- end
- else
- Inc(Y);
- end
- else
- if (Page + Select) > 1 then
- Dec(Select,((X2-X1) div 15));
- end;
- #12 : begin {->}
- Inc(X,15);
- if X+15 > X2-2 then
- begin
- Dec(X,15);
- end
- else
- if Select + Page < DirCount then
- Inc(Select)
- else
- Dec(X,15);
- end;
- end;{case}
- end;
- until inch = #13;
- Select_File_Key := CurrentDir^[Select+Page].Name;
- end;
-
- {---------------------------------------------------------------------------}
-
- function STI_SelectFile(X1,Y1,X2,Y2,Tcol,Pcol,Bcol,TTcol : byte; Border,Mask : string) : string;
-
- var
- SS,OldPath : string;
-
- begin
- Search := Mask;
- MakeWindow(Handle,X1,Y1,X2,Y2,Tcol,Bcol,TTCol,Border,'Directory');
- SS := Select_File_Key(X1,Y1,X2,Y2,Tcol,Pcol);
- while pos('\',SS) <> 0 do
- begin
- if pos('..',SS)<>0 then
- begin
- Path := OldPath;
- end else
- if pos('.',SS)<>0 then
- begin
- end else
- begin
- OldPath := Path;
- Path := Path + SS;
- end;
- SS := Select_File_Key(X1,Y1,X2,Y2,Tcol,Pcol);
- end;
- STI_SelectFile := Drive+Path+SS;
- DisposeWindow(Handle);
- end;
-
- {--------------------------------------------------------------------------}
-
- begin { program body }
- New(CurrentDir);
- DirCount := 1;
- Drive := '';
- Path := '';
- DirCount := 0;
- end.
-