home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Multimed / Multimed.zip / mp3osr05.zip / src / nonfpc.inc < prev    next >
Text File  |  1999-12-22  |  4KB  |  176 lines

  1. (*
  2.  * part of MPEG searcher project
  3.  *  (c) 1999 by Alexander Trunov, 2:5069/10, jnc@mail.ru
  4.  *)
  5.  
  6. {$ifndef fpc}
  7.  
  8. // these functions are under copyright of FreePascal development team
  9.  
  10. function ExtractFileName(AFile: FNameStr): NameStr;
  11. var
  12.   D: DirStr;
  13.   N: NameStr;
  14.   E: ExtStr;
  15. begin
  16.   FSplit(AFile, D, N, E);
  17.   ExtractFileName := N;
  18. end;
  19.  
  20. function ExtractFileExt(AFile: FNameStr): NameStr;
  21. var
  22.   D: DirStr;
  23.   N: NameStr;
  24.   E: ExtStr;
  25. begin
  26.   FSplit(AFile, D, N, E);
  27.   ExtractFileExt := E;
  28. end;
  29.  
  30. function TrimmedName(const Name: String; Limit: Byte): String;
  31. var
  32.   B, E, L: Integer;
  33.   S: String;
  34. begin
  35.   L := Length(Name);
  36.   if L <= Limit then TrimmedName := Name
  37.   else
  38.   begin
  39.     B := 1;
  40.     while (B < L) and (Name[B] <> '\') do Inc(B);
  41.     while (B < L) and (Name[B] =  '\') do Inc(B);
  42.     E := B;
  43.     while (E < L) and (L - (E - B) + 3 > Limit) do Inc(E);
  44.     while (E < L) and (Name[E] <> '\') do Inc(E);
  45.     if Name[E] = '\' then
  46.     begin
  47.       S := Name;
  48.       Delete(S, B, E - B);
  49.       Insert('...', S, B);
  50.     end
  51.     else S := ExtractFileName(Name) + ExtractFileExt(Name);
  52.     if Length(S) > Limit then S[0] := Char(Limit);
  53.     TrimmedName := S;
  54.   end;
  55. end;
  56.  
  57.  
  58. function ShrinkPath(AFile: FNameStr; MaxLen: Byte): FNameStr;
  59. begin
  60.   Result := TrimmedName(AFile, MaxLen);
  61. end;
  62. {
  63. var
  64.   D1: DirStr;
  65.   N1: NameStr;
  66.   E1: ExtStr;
  67.   i: Longint;
  68. begin
  69.   if Length(AFile) > MaxLen then
  70.   begin
  71.     FSplit(FExpand(AFile), D1, N1, E1);
  72.     AFile := Copy(D1, 1, 3) + '..' + '\';
  73.     i := Pred(Length(D1));
  74.     while (i > 0) and (D1[i] <> '\') do
  75.       Dec(i);
  76.     if (i = 0) then
  77.       AFile := AFile + D1
  78.     else AFile := AFile + Copy(D1, Succ(i), Length(D1) - i);
  79.     if AFile[Length(AFile)] <> '\' then
  80.       AFile := AFile + '\';
  81.     AFile := AFile + N1 + E1;
  82.   end;
  83.   ShrinkPath := AFile;
  84. end;
  85. }
  86.  
  87. function FileExists (AFile : FNameStr) : Boolean;
  88. begin
  89.   FileExists := (FSearch(AFile,'') <> '');
  90. end;
  91.  
  92. function OpenFile (var AFile : FNameStr; HistoryID : Byte) : Boolean;
  93. var
  94.   Dlg : PFileDialog;
  95. begin
  96.   Dlg := New(PFileDialog,Init('*.*', 'Open a file..','~N~ame',
  97.         fdOkButton, 0));
  98.   PHistory(Dlg^.FileName^.Next^.Next)^.HistoryID := HistoryID;
  99.   OpenFile := (Application^.ExecuteDialog(Dlg, @AFile) = cmFileOpen);
  100. end;
  101.  
  102. function SelectDir(var ADir: DirStr; HistoryID: Byte): Boolean;
  103. var
  104.   Dir, Rec: DirStr;
  105.   Dlg: PEditChDirDialog;
  106. begin
  107.   {$I-}
  108.   GetDir(0, Dir);
  109.   {$I+}
  110.   Rec := FExpand(Dir);
  111.   Dlg := New(PEditChDirDialog, Init(0, HistoryID));
  112.   if (Application^.ExecuteDialog(Dlg, @Rec) = cmOk) then
  113.   begin
  114.     SelectDir := True;
  115.     ADir := Rec;
  116.   end
  117.   else SelectDir := False;
  118. end;
  119.  
  120. type
  121.   PStringRec = record
  122.     AString : PString;
  123.   end;
  124.  
  125. function ReplaceFileQuery(AFile: FNameStr): Boolean;
  126. var
  127.   Rec: PStringRec;
  128. begin
  129.   AFile := ShrinkPath(AFile, 33);
  130.   Rec.AString := PString(@AFile);
  131.   ReplaceFileQuery :=
  132.      (MsgBox.MessageBox(#3'Replace file?'#13#10#13#3'%s',
  133.        @Rec, mfConfirmation or mfOkCancel) = cmOk);
  134. end;
  135.  
  136. function SaveAs(var AFile: FNameStr; HistoryID: Word): Boolean;
  137. var
  138.   Dlg: PFileDialog;
  139. begin
  140.   SaveAs := False;
  141.   Dlg := New(PFileDialog, Init('*.*', 'Save As', 'S~a~ve as...',
  142.         fdOkButton or fdHelpButton, 0));
  143.   PHistory(Dlg^.FileName^.Next^.Next)^.HistoryID := HistoryID;
  144.   Dlg^.HelpCtx := hcSaveAs;
  145.   if (Application^.ExecuteDialog(Dlg, @AFile) = cmFileOpen) and
  146.      ((not FileExists(AFile)) or ReplaceFileQuery(AFile)) then
  147.     SaveAs := True;
  148. end;
  149.  
  150. function ExtractDir(AFile: FNameStr): DirStr;
  151. var
  152.   D: DirStr;
  153.   N: NameStr;
  154.   E: ExtStr;
  155. begin
  156.   FSplit(AFile, D, N, E);
  157.   if D = '' then
  158.   begin
  159.     ExtractDir := '';
  160.     Exit;
  161.   end;
  162.   if D[Byte(D[0])] <> '\' then
  163.     D := D + '\';
  164.   ExtractDir := D;
  165. end;
  166.  
  167. {$endif}
  168.  
  169. function IntToStr (L: Longint): string;
  170. var
  171.   S: string;
  172. begin
  173.   Str(L, S);
  174.   IntToStr := S;
  175. end;
  176.