Ignore:
Timestamp:
Jun 20, 2007, 12:57:51 PM (17 years ago)
Author:
alloc
Message:
 
Location:
oup/current/FileClasses
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • oup/current/FileClasses/_Extensions.pas

    r228 r229  
    77    private
    88      FConnectionID: Integer;
     9      FExt: String;
    910      FFiles: array of Integer;
    1011      function GetFile(ID: Integer): Integer;
     
    1314      constructor Create(ConnectionID: Integer; Ext: String); virtual;
    1415      procedure InitList;
     16      property Ext: String read FExt;
    1517      property Files[ID: Integer]: Integer read GetFile;
    1618      property FileCount: Integer read GetFileCount;
    1719  end;
     20
     21  TExtensions = array of TExtension;
     22                     
    1823
    1924
     
    2631
    2732constructor TExtension.Create(ConnectionID: Integer; Ext: String);
     33begin
     34  FConnectionID := ConnectionID;
     35  FExt := Ext;
     36end;
     37
     38function TExtension.GetFile(ID: Integer): Integer;
     39begin
     40  Result := FFiles[ID];
     41end;
     42
     43function TExtension.GetFileCount: Integer;
     44begin
     45  Result := Length(FFiles);
     46end;
     47
     48procedure TExtension.InitList;
    2849var
    2950  files: TStrings;
     
    5071end;
    5172
    52 function TExtension.GetFile(ID: Integer): Integer;
    53 begin
    54   Result := FFiles[ID];
    55 end;
    56 
    57 function TExtension.GetFileCount: Integer;
    58 begin
    59   Result := Length(FFiles);
    60 end;
    61 
    62 procedure TExtension.InitList;
    63 begin
    64 Exit;
    65 end;
    66 
    6773end.
  • oup/current/FileClasses/_MetaManager.pas

    r228 r229  
    88    protected
    99      FFiles: array of TFile;
    10       FRoot: array of TExtension;
     10      FRoot: TExtensions;
    1111      FConnectionID: Integer;
     12      FDataAccess: TObject;
    1213      function GetFileCount: Integer;
    1314      function GetFileById(Id: Integer): TFile;
     15      function GetExt(Ext: String): TExtension;
     16      procedure AddExt(Ext: String);
    1417    private
    15       procedure InitRootFiles;
     18      procedure InitExts;
    1619    public
    17       constructor Create(ConnectionID: Integer);
     20      constructor Create(ConnectionID: Integer; DataAccess: TObject);
     21      procedure InitExtFiles(Ext: String);
    1822      procedure InitFile(id: Integer);
    1923      procedure InitFileFields(id: Integer);
    2024
     25      property Root: TExtensions read FRoot;
     26      property RootExt[Ext: String]: TExtension read GetExt;
    2127      property FileCount: Integer read GetFileCount;
    2228      property FileById[Id: Integer]: TFile read GetFileById;
    2329  end;
    2430
    25 var
    26   Meta: TMetaManager;
    27 
    2831implementation
    2932
    3033uses
    3134  Classes, ConnectionManager, Access_OniArchive, TypeDefs,
    32   Dialogs, SysUtils, StrUtils;
     35  Dialogs, SysUtils, StrUtils, DataAccess;
    3336
    3437{ TFileManager }
    3538
    36 constructor TMetaManager.Create(ConnectionID: Integer);
     39constructor TMetaManager.Create(ConnectionID: Integer; DataAccess: TObject);
    3740begin
    3841  FConnectionID := ConnectionID;
    39   InitRootFiles;
     42  FDataAccess := DataAccess;
     43  SetLength(FFiles, TDataAccess(DataAccess).GetFileCount);
     44  InitExts;
     45end;
     46
     47function TMetaManager.GetExt(Ext: String): TExtension;
     48var
     49  i: Integer;
     50begin
     51  Result := nil;
     52  if Length(FRoot) > 0 then
     53    for i := 0 to High(FRoot) do
     54      if FRoot[i].Ext = Ext then
     55      begin
     56        Result := FRoot[i];
     57        Break;
     58      end;
     59end;
     60
     61procedure TMetaManager.AddExt(Ext: String);
     62var
     63  i: Integer;
     64begin
     65  SetLength(FRoot, Length(FRoot) + 1);
     66  for i := High(FRoot) downto 1 do
     67  begin
     68    if FRoot[i-1].Ext < Ext then
     69    begin
     70      FRoot[i] := TExtension.Create(FConnectionID, Ext);
     71      Break;
     72    end
     73    else
     74      FRoot[i] := FRoot[i-1];
     75  end;
     76  if i = 0 then
     77    FRoot[0] := TExtension.Create(FConnectionID, Ext);
    4078end;
    4179
     
    92130end;
    93131
    94 procedure TMetaManager.InitRootFiles;
     132procedure TMetaManager.InitExtFiles(Ext: String);
    95133var
    96134  files: TStrings;
     
    136174end;
    137175
     176procedure TMetaManager.InitExts;
     177var
     178  files: TStrings;
     179  i: Integer;
     180  fid: Integer;
     181  finfo: TFileInfo;
     182begin
     183  files := TStringList.Create;
     184  files := TDataAccess(FDataAccess).GetFilesList('', '', False, ST_IDAsc);
     185  SetLength(FRoot, 0);
     186  if files.Count > 0 then
     187  begin
     188    for i := 0 to files.Count - 1 do
     189    begin
     190      fid := StrToInt(MidStr(files.Strings[i], 1, 5));
     191      finfo := TDataAccess(FDataAccess).GetFileInfo(fid);
     192      if Length(finfo.Name) > 0 then
     193        if not Assigned(GetExt(finfo.Extension)) then
     194          AddExt(finfo.Extension);
     195    end;
     196  end;
     197  files.Free;
     198end;
     199
    138200end.
  • oup/current/FileClasses/_MetaTypes.pas

    r228 r229  
    1919  TFile_Empty = _EmptyFile.TFile_Empty;
    2020  TExtension = _Extensions.TExtension;
     21  TExtensions = _Extensions.TExtensions;
    2122
    2223  TFileClass = class of TFile;
Note: See TracChangeset for help on using the changeset viewer.