ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/oup/current/FileClasses/_MetaManager.pas
(Generate patch)

Comparing oup/current/FileClasses/_MetaManager.pas (file contents):
Revision 215 by alloc, Tue Jun 12 20:31:54 2007 UTC vs.
Revision 229 by alloc, Wed Jun 20 10:57:51 2007 UTC

# Line 1 | Line 1
1   unit _MetaManager;
2   interface
3  
4 < uses _FileTypes,
5 <  ABNA, AGDB, AGQC, AGQG, AGQM, AGQR, AISA, AITR, AIWA, AKAA, AKBA, AKBP, AKDA,
6 <  AKEV, AKOT, AKVA, BINA, CBPI, CBPM, CONS, CRSA, DOOR, DPge, EDIA, ENVP, FILM,
7 <  FXLR, GMAN, HPge, IDXA, IGHH, IGPA, IGPG, IGSA, IGSt, Impt, IPge, KeyI, M3GA,
8 <  M3GM, M3TA, Mtrl, NMSA, OBAN, OBDC, OBLS, OBOA, OFGA, ONCC, ONCP, ONCV, ONFA,
9 <  ONGS, ONIA, ONLD, ONLV, ONMA, ONOA, ONSA, ONSK, ONTA, ONVL, ONWC, OPge, OSBD,
10 <  OTIT, OTLF, PLEA, PNTA, PSpc, PSpL, PSUI, QTNA, QUDA, SNDD, StNA, SUBT, TMFA,
11 <  TMRA, TRAC, TRAM, TRAS, TRBS, TRCM, TRFT, TRGA, TRGE, TRIA, TRIG, TRMA, TRSC,
12 <  TRTA, TSFF, TSFL, TSFT, TSGA, TStr, TURR, TXAN, TXCA, TXMA, TXMB, TXMP, TXPC,
13 <  TxtC, UUEA, UVDL, VCRA, WMCL, WMDD, WMM_, WMMB, WPge,
14 <  _EmptyFile;
15 <
16 < type
17 <  TFileType = class of TFile;
18 <  TFileDesc = record
19 <    ext: String;
20 <    ftype: TFileType;
21 <  end;
22 <
23 < const
24 <  FileDescs: array[0..112] of TFileDesc = (
25 <    (ext: 'ABNA'; ftype: TFile_ABNA),
26 <    (ext: 'AGDB'; ftype: TFile_AGDB),
27 <    (ext: 'AGQC'; ftype: TFile_AGQC),
28 <    (ext: 'AGQG'; ftype: TFile_AGQG),
29 <    (ext: 'AGQM'; ftype: TFile_AGQM),
30 <    (ext: 'AGQR'; ftype: TFile_AGQR),
31 <    (ext: 'AISA'; ftype: TFile_AISA),
32 <    (ext: 'AITR'; ftype: TFile_AITR),
33 <    (ext: 'AIWA'; ftype: TFile_AIWA),
34 <    (ext: 'AKAA'; ftype: TFile_AKAA),
35 <    (ext: 'AKBA'; ftype: TFile_AKBA),
36 <    (ext: 'AKBP'; ftype: TFile_AKBP),
37 <    (ext: 'AKDA'; ftype: TFile_AKDA),
38 <    (ext: 'AKEV'; ftype: TFile_AKEV),
39 <    (ext: 'AKOT'; ftype: TFile_AKOT),
40 <    (ext: 'AKVA'; ftype: TFile_AKVA),
41 <    (ext: 'BINA'; ftype: TFile_BINA),
42 <    (ext: 'CBPI'; ftype: TFile_CBPI),
43 <    (ext: 'CBPM'; ftype: TFile_CBPM),
44 <    (ext: 'CONS'; ftype: TFile_CONS),
45 <    (ext: 'CRSA'; ftype: TFile_CRSA),
46 <    (ext: 'DOOR'; ftype: TFile_DOOR),
47 <    (ext: 'DPge'; ftype: TFile_DPge),
48 <    (ext: 'EDIA'; ftype: TFile_EDIA),
49 <    (ext: 'ENVP'; ftype: TFile_ENVP),
50 <    (ext: 'FILM'; ftype: TFile_FILM),
51 <    (ext: 'FXLR'; ftype: TFile_FXLR),
52 <    (ext: 'GMAN'; ftype: TFile_GMAN),
53 <    (ext: 'HPge'; ftype: TFile_HPge),
54 <    (ext: 'IDXA'; ftype: TFile_IDXA),
55 <    (ext: 'IGHH'; ftype: TFile_IGHH),
56 <    (ext: 'IGPA'; ftype: TFile_IGPA),
57 <    (ext: 'IGPG'; ftype: TFile_IGPG),
58 <    (ext: 'IGSA'; ftype: TFile_IGSA),
59 <    (ext: 'IGSt'; ftype: TFile_IGSt),
60 <    (ext: 'Impt'; ftype: TFile_Impt),
61 <    (ext: 'IPge'; ftype: TFile_IPge),
62 <    (ext: 'KeyI'; ftype: TFile_KeyI),
63 <    (ext: 'M3GA'; ftype: TFile_M3GA),
64 <    (ext: 'M3GM'; ftype: TFile_M3GM),
65 <    (ext: 'M3TA'; ftype: TFile_M3TA),
66 <    (ext: 'Mtrl'; ftype: TFile_Mtrl),
67 <    (ext: 'NMSA'; ftype: TFile_NMSA),
68 <    (ext: 'OBAN'; ftype: TFile_OBAN),
69 <    (ext: 'OBDC'; ftype: TFile_OBDC),
70 <    (ext: 'OBLS'; ftype: TFile_OBLS),
71 <    (ext: 'OBOA'; ftype: TFile_OBOA),
72 <    (ext: 'OFGA'; ftype: TFile_OFGA),
73 <    (ext: 'ONCC'; ftype: TFile_ONCC),
74 <    (ext: 'ONCP'; ftype: TFile_ONCP),
75 <    (ext: 'ONCV'; ftype: TFile_ONCV),
76 <    (ext: 'ONFA'; ftype: TFile_ONFA),
77 <    (ext: 'ONGS'; ftype: TFile_ONGS),
78 <    (ext: 'ONIA'; ftype: TFile_ONIA),
79 <    (ext: 'ONLD'; ftype: TFile_ONLD),
80 <    (ext: 'ONLV'; ftype: TFile_ONLV),
81 <    (ext: 'ONMA'; ftype: TFile_ONMA),
82 <    (ext: 'ONOA'; ftype: TFile_ONOA),
83 <    (ext: 'ONSA'; ftype: TFile_ONSA),
84 <    (ext: 'ONSK'; ftype: TFile_ONSK),
85 <    (ext: 'ONTA'; ftype: TFile_ONTA),
86 <    (ext: 'ONVL'; ftype: TFile_ONVL),
87 <    (ext: 'ONWC'; ftype: TFile_ONWC),
88 <    (ext: 'OPge'; ftype: TFile_OPge),
89 <    (ext: 'OSBD'; ftype: TFile_OSBD),
90 <    (ext: 'OTIT'; ftype: TFile_OTIT),
91 <    (ext: 'OTLF'; ftype: TFile_OTLF),
92 <    (ext: 'PLEA'; ftype: TFile_PLEA),
93 <    (ext: 'PNTA'; ftype: TFile_PNTA),
94 <    (ext: 'PSpc'; ftype: TFile_PSpc),
95 <    (ext: 'PSpL'; ftype: TFile_PSpL),
96 <    (ext: 'PSUI'; ftype: TFile_PSUI),
97 <    (ext: 'QTNA'; ftype: TFile_QTNA),
98 <    (ext: 'QUDA'; ftype: TFile_QUDA),
99 <    (ext: 'SNDD'; ftype: TFile_SNDD),
100 <    (ext: 'StNA'; ftype: TFile_StNA),
101 <    (ext: 'SUBT'; ftype: TFile_SUBT),
102 <    (ext: 'TMFA'; ftype: TFile_TMFA),
103 <    (ext: 'TMRA'; ftype: TFile_TMRA),
104 <    (ext: 'TRAC'; ftype: TFile_TRAC),
105 <    (ext: 'TRAM'; ftype: TFile_TRAM),
106 <    (ext: 'TRAS'; ftype: TFile_TRAS),
107 <    (ext: 'TRBS'; ftype: TFile_TRBS),
108 <    (ext: 'TRCM'; ftype: TFile_TRCM),
109 <    (ext: 'TRFT'; ftype: TFile_TRFT),
110 <    (ext: 'TRGA'; ftype: TFile_TRGA),
111 <    (ext: 'TRGE'; ftype: TFile_TRGE),
112 <    (ext: 'TRIA'; ftype: TFile_TRIA),
113 <    (ext: 'TRIG'; ftype: TFile_TRIG),
114 <    (ext: 'TRMA'; ftype: TFile_TRMA),
115 <    (ext: 'TRSC'; ftype: TFile_TRSC),
116 <    (ext: 'TRTA'; ftype: TFile_TRTA),
117 <    (ext: 'TSFF'; ftype: TFile_TSFF),
118 <    (ext: 'TSFL'; ftype: TFile_TSFL),
119 <    (ext: 'TSFT'; ftype: TFile_TSFT),
120 <    (ext: 'TSGA'; ftype: TFile_TSGA),
121 <    (ext: 'TStr'; ftype: TFile_TStr),
122 <    (ext: 'TURR'; ftype: TFile_TURR),
123 <    (ext: 'TXAN'; ftype: TFile_TXAN),
124 <    (ext: 'TXCA'; ftype: TFile_TXCA),
125 <    (ext: 'TXMA'; ftype: TFile_TXMA),
126 <    (ext: 'TXMB'; ftype: TFile_TXMB),
127 <    (ext: 'TXMP'; ftype: TFile_TXMP),
128 <    (ext: 'TXPC'; ftype: TFile_TXPC),
129 <    (ext: 'TxtC'; ftype: TFile_TxtC),
130 <    (ext: 'UUEA'; ftype: TFile_UUEA),
131 <    (ext: 'UVDL'; ftype: TFile_UVDL),
132 <    (ext: 'VCRA'; ftype: TFile_VCRA),
133 <    (ext: 'WMCL'; ftype: TFile_WMCL),
134 <    (ext: 'WMDD'; ftype: TFile_WMDD),
135 <    (ext: 'WMM_'; ftype: TFile_WMM_),
136 <    (ext: 'WMMB'; ftype: TFile_WMMB),
137 <    (ext: 'WPge'; ftype: TFile_WPge)
138 <  );
4 > uses _MetaTypes;
5  
6   type
7    TMetaManager = class
8      protected
9        FFiles: array of TFile;
10 +      FRoot: TExtensions;
11        FConnectionID: Integer;
12 +      FDataAccess: TObject;
13        function GetFileCount: Integer;
14        function GetFileById(Id: Integer): TFile;
15 +      function GetExt(Ext: String): TExtension;
16 +      procedure AddExt(Ext: String);
17      private
18 <      procedure InitRootFiles;
18 >      procedure InitExts;
19      public
20 <      constructor Create(ConnectionID: Integer);
20 >      constructor Create(ConnectionID: Integer; DataAccess: TObject);
21 >      procedure InitExtFiles(Ext: String);
22        procedure InitFile(id: Integer);
23        procedure InitFileFields(id: Integer);
24  
25 +      property Root: TExtensions read FRoot;
26 +      property RootExt[Ext: String]: TExtension read GetExt;
27        property FileCount: Integer read GetFileCount;
28        property FileById[Id: Integer]: TFile read GetFileById;
29    end;
30  
158 var
159  Meta: TMetaManager;
160
31   implementation
32  
33   uses
34 <  Classes, ConnectionManager, Access_OniArchive, TypeDefs, Dialogs, SysUtils, StrUtils;
34 >  Classes, ConnectionManager, Access_OniArchive, TypeDefs,
35 >  Dialogs, SysUtils, StrUtils, DataAccess;
36  
37   { TFileManager }
38  
39 < constructor TMetaManager.Create(ConnectionID: Integer);
39 > constructor TMetaManager.Create(ConnectionID: Integer; DataAccess: TObject);
40   begin
41    FConnectionID := ConnectionID;
42 <  InitRootFiles;
42 >  FDataAccess := DataAccess;
43 >  SetLength(FFiles, TDataAccess(DataAccess).GetFileCount);
44 >  InitExts;
45 > end;
46 >
47 > function TMetaManager.GetExt(Ext: String): TExtension;
48 > var
49 >  i: Integer;
50 > begin
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;
59 > end;
60 >
61 > procedure TMetaManager.AddExt(Ext: String);
62 > var
63 >  i: Integer;
64 > begin
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);
78   end;
79  
80   function TMetaManager.GetFileById(Id: Integer): TFile;
# Line 197 | Line 103 | begin
103          begin
104            if FileDescs[typei].ext = finfo.Extension then
105            begin
106 <            FFiles[id] := TFileType(FileDescs[typei].ftype).Create(FConnectionID, id);
106 >            FFiles[id] := TFileClass(FileDescs[typei].ftype).Create(FConnectionID, id);
107              Break;
108            end;
109          end;
# Line 223 | Line 129 | begin
129    end;
130   end;
131  
132 < procedure TMetaManager.InitRootFiles;
132 > procedure TMetaManager.InitExtFiles(Ext: String);
133   var
134    files: TStrings;
135    i: Integer;
# Line 252 | Line 158 | begin
158            begin
159              if FileDescs[typei].ext = finfo.Extension then
160              begin
161 <              FFiles[fid] := TFileType(FileDescs[typei].ftype).Create(FConnectionID, fid);
161 >              FFiles[fid] := TFileClass(FileDescs[typei].ftype).Create(FConnectionID, fid);
162                Break;
163              end;
164            end;
# Line 267 | Line 173 | begin
173      TAccess_OniArchive(ConManager.Connection[FConnectionID]).UnloadWhenUnused := True;
174   end;
175  
176 + procedure TMetaManager.InitExts;
177 + var
178 +  files: TStrings;
179 +  i: Integer;
180 +  fid: Integer;
181 +  finfo: TFileInfo;
182 + begin
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;
198 + end;
199 +
200   end.

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)