root/trunk/Wizards/NewCollection/frame_NCWInpxSource.pas

390438
1
{******************************************************************************}
1
{ ****************************************************************************** }
2
{                                                                              }
2
{ }
3
{ MyHomeLib                                                                    }
3
{ MyHomeLib }
4
{                                                                              }
4
{ }
5
{ Version 0.9                                                                  }
5
{ Version 0.9 }
6
{ 20.08.2008                                                                   }
6
{ 20.08.2008 }
7
{ Copyright (c) Aleksey Penkov  alex.penkov@gmail.com                          }
7
{ Copyright (c) Aleksey Penkov  alex.penkov@gmail.com }
8
{                                                                              }
8
{ }
9
{                                                                              }
9
{ }
10
{******************************************************************************}
10
{ ****************************************************************************** }
11
11
12
unit frame_NCWInpxSource;
12
unit frame_NCWInpxSource;
13
13
...
...
15
15
16
uses
16
uses
17
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
17
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
18
  Dialogs, frame_InteriorPageBase, StdCtrls, ExtCtrls, unit_StaticTip, unit_NCWParams,
18
  Dialogs, frame_InteriorPageBase, StdCtrls, ExtCtrls, unit_StaticTip,
19
  unit_NCWParams,
19
  Mask, RzEdit, RzBtnEdt, ComCtrls;
20
  Mask, RzEdit, RzBtnEdt, ComCtrls;
20
21
21
type
22
type
...
...
40
      Change: TItemChange);
41
      Change: TItemChange);
41
  private
42
  private
42
    FCollections: array of TCollectionDesc;
43
    FCollections: array of TCollectionDesc;
43
    FGroups : array of string;
44
    FGroups: array of string;
44
45
45
    procedure LoadDescriptions;
46
    procedure LoadDescriptions;
46
  public
47
  public
...
...
65
  unit_Helpers,
66
  unit_Helpers,
66
  ZipForge,
67
  ZipForge,
67
  IniFiles;
68
  IniFiles;
68
69
{$R *.dfm}
69
{$R *.dfm}
70
70
71
const
71
const
72
73
  INPX_SECTION = 'INPX';
72
  INPX_SECTION = 'INPX';
74
  INPX_GROUP_SECTION = 'GROUPS';
73
  INPX_GROUP_SECTION = 'GROUPS';
75
  INPX_KEY_PREFIX = 'Inpx';
74
  INPX_KEY_PREFIX = 'Inpx';
76
  INPX_GROUP_KEY_PREFIX = 'Group';
75
  INPX_GROUP_KEY_PREFIX = 'Group';
77
76
78
  DefaultGroups : array [0..2] of string = ('Библиотека Lib.rus.ec','Библиотека flibusta.net','Библиотека Траума');
77
  DefaultGroups: array [0 .. 2] of string = ('Библиотека Lib.rus.ec', 'Библиотека flibusta.net', 'Библиотека Траума');
79
78
80
  DefaultCollections : array [0 .. 8] of TCollectionDesc = (
79
  DefaultCollections: array [0 .. 8] of TCollectionDesc =
81
    (Group: 0; Title: 'Lib.rus.ec [FB2]'; Desc: 'Архивы FB2 (fb2-xxxxxx-xxxxxx.zip)'; INPX: 'librusec.inpx'),
80
  (
82
    (Group: 0; Title: 'Lib.rus.ec [USR]'; Desc: 'Архивы USR (usr-xxxxxx-xxxxxx.zip)'; INPX: 'librusec_usr.inpx'),
81
    (Group: 0; Title: 'Lib.rus.ec [FB2]';        Desc: 'Архивы FB2 (fb2-xxxxxx-xxxxxx.zip)'; INPX: 'librusec.inpx'),
83
    (Group: 0; Title: 'Lib.rus.ec [ALLBOOKS]'; Desc: 'Все архивы (fb2-xxxxxx-xxxxxx.zip и usr-xxxxxx-xxxxxx.zip)'; INPX: 'librusec_allbooks.inpx'),
82
    (Group: 0; Title: 'Lib.rus.ec [USR]';        Desc: 'Архивы USR (usr-xxxxxx-xxxxxx.zip)'; INPX: 'librusec_usr.inpx'),
83
    (Group: 0; Title: 'Lib.rus.ec [ALLBOOKS]';   Desc: 'Все архивы (fb2-xxxxxx-xxxxxx.zip и usr-xxxxxx-xxxxxx.zip)';    INPX: 'librusec_allbooks.inpx'),
84
    (Group: 0; Title: 'Lib.rus.ec Online [FB2]'; Desc: 'Книги скачиваются по запросу с серввера lib.rus.ec (необходима регистрация)'; INPX: 'librusec_online.inpx'),
84
    (Group: 0; Title: 'Lib.rus.ec Online [FB2]'; Desc: 'Книги скачиваются по запросу с серввера lib.rus.ec (необходима регистрация)'; INPX: 'librusec_online.inpx'),
85
    (Group: 1; Title: 'Flibusta OnLine [FB2]'; Desc: 'Книги скачиваются по запросу с сервера flibusta.net'; INPX: 'flibusta_online.inpx'),
85
    (Group: 1; Title: 'Flibusta OnLine [FB2]';   Desc: 'Книги скачиваются по запросу с сервера flibusta.net'; INPX: 'flibusta_online.inpx'),
86
    (Group: 2; Title: 'Traum 2.11 [FB2]'; Desc: 'Библиотека Траума 2.11'; INPX: 'Traum_2-11.inpx'),
86
    (Group: 2; Title: 'Traum 2.11 [FB2]';        Desc: 'Библиотека Траума 2.11'; INPX: 'Traum_2-11.inpx'),
87
    (Group: 2; Title: 'Traum 2.12 [FB2]'; Desc: 'Библиотека Траума 2.12'; INPX: 'Traum_2-12.inpx'),
87
    (Group: 2; Title: 'Traum 2.12 [FB2]';        Desc: 'Библиотека Траума 2.12'; INPX: 'Traum_2-12.inpx'),
88
    (Group: 2; Title: 'Traum 2.13 [FB2]'; Desc: 'Библиотека Траума 2.13 (только FB2)'; INPX: 'Traum_2-13_fb2.inpx'),
88
    (Group: 2; Title: 'Traum 2.13 [FB2]';        Desc: 'Библиотека Траума 2.13 (только FB2)'; INPX: 'Traum_2-13_fb2.inpx'),
89
    (Group: 2; Title: 'Traum 2.13 [ALLBOOKS]'; Desc: 'Библиотека Траума 2.13 (Полная)'; INPX: 'Traum_2-13_full.inpx')
89
    (Group: 2; Title: 'Traum 2.13 [ALLBOOKS]';   Desc: 'Библиотека Траума 2.13 (Полная)'; INPX: 'Traum_2-13_full.inpx')
90
    );
90
  );
91
91
92
function TframeNCWInpxSource.Activate(LoadData: Boolean): Boolean;
92
function TframeNCWInpxSource.Activate(LoadData: Boolean): Boolean;
93
begin
93
begin
...
...
127
  end;
127
  end;
128
end;
128
end;
129
129
130
131
132
procedure TframeNCWInpxSource.FillList;
130
procedure TframeNCWInpxSource.FillList;
133
var
131
var
134
  I: Integer;
132
  I: integer;
135
  G : TListGroup;
133
  G: TListGroup;
136
  Item: TListItem;
134
  Item: TListItem;
137
begin
135
begin
138
  LoadDescriptions;
136
  LoadDescriptions;
139
  lvCollections.Groups.Clear;
140
  lvCollections.Items.Clear;
141
  for I := 0 to High(FGroups) do
142
  begin
143
    G := lvCollections.Groups.Add;
144
    G.Header := FGroups[i];
145
  end;
146
137
147
  for I := 0 to High(FCollections) do
138
  lvCollections.Items.BeginUpdate;
148
  begin
139
  try
149
    Item := lvCollections.Items.Add;
140
    lvCollections.Groups.Clear;
150
    Item.Caption := FCollections[i].Title;
141
    lvCollections.Items.Clear;
151
    Item.GroupID := FCollections[i].Group;
142
143
    for I := 0 to High(FGroups) do
144
    begin
145
      G := lvCollections.Groups.Add;
146
      G.Header := FGroups[I];
147
    end;
148
149
    for I := 0 to High(FCollections) do
150
    begin
151
      Item := lvCollections.Items.Add;
152
      Item.Caption := FCollections[I].Title;
153
      Item.GroupID := FCollections[I].Group;
154
    end;
155
  finally
156
    lvCollections.Items.EndUpdate;
152
  end;
157
  end;
153
154
end;
158
end;
155
159
156
procedure TframeNCWInpxSource.LoadDescriptions;
160
procedure TframeNCWInpxSource.LoadDescriptions;
157
var
161
var
158
  i: Integer;
162
  I: integer;
159
  sl: TStringList;
163
  sl: TStringList;
160
  slHelper: TStringList;
164
  slHelper: TStringList;
161
  INIFile: TMemIniFile;
165
  INIFile: TMemIniFile;
162
begin
166
begin
167
  INIFile := TMemIniFile.Create(Settings.WorkPath + 'collections.ini');
163
  try
168
  try
164
    INIFile := TMemIniFile.Create(Settings.WorkPath + 'collections.ini');
165
    INIFile.Encoding := TEncoding.UTF8;
169
    INIFile.Encoding := TEncoding.UTF8;
166
170
167
    sl := TStringList.Create;
171
    sl := TStringList.Create;
172
    try
173
      INIFile.ReadSection(INPX_GROUP_SECTION, sl);
174
      // обрабатываем файл
175
      if sl.Count > 0 then
176
      begin
177
        SetLength(FGroups, sl.Count);
178
        for I := 0 to sl.Count - 1 do
179
          if Pos(INPX_GROUP_KEY_PREFIX, sl[I]) = 1 then
180
            FGroups[I] := INIFile.ReadString(INPX_GROUP_SECTION, sl[I], '');
181
      end // if
182
      else
183
      begin
184
        // Добавим группы по умолчанию
185
      end;
168
186
169
    iniFile.ReadSection(INPX_GROUP_SECTION, sl);
187
      INIFile.ReadSection(INPX_SECTION, sl);
170
    //     обрабатываем файл
188
      // обрабатываем файл
171
    if sl.Count > 0 then
189
      if sl.Count > 0 then
172
    begin
190
      begin
173
      SetLength(FGroups, sl.Count);
191
        SetLength(FCollections, sl.Count);
174
      for i := 0 to sl.Count - 1 do
192
        slHelper := TStringList.Create;
175
        if Pos(INPX_GROUP_KEY_PREFIX, sl[i]) = 1 then
193
        try
176
            FGroups[i] := iniFile.ReadString(INPX_GROUP_SECTION, sl[i], '');
194
          slHelper.QuoteChar := '"';
177
195
          slHelper.Delimiter := ';';
178
    end // if
196
          slHelper.StrictDelimiter := True;
179
    else
197
          for I := 0 to sl.Count - 1 do
180
    begin
181
      //     Добавим группы по умолчанию
182
    end;
183
184
185
    iniFile.ReadSection(INPX_SECTION, sl);
186
    //     обрабатываем файл
187
    if sl.Count > 0 then
188
    begin
189
      SetLength(FCollections, sl.Count);
190
      slHelper := TStringList.Create;
191
      try
192
        slHelper.QuoteChar := '"';
193
        slHelper.Delimiter := ';';
194
        slHelper.StrictDelimiter := True;
195
        for i := 0 to sl.Count - 1 do
196
        begin
197
          if Pos(INPX_KEY_PREFIX, sl[i]) = 1 then
198
          begin
198
          begin
199
            slHelper.DelimitedText := iniFile.ReadString(INPX_SECTION, sl[i], '');
199
            if Pos(INPX_KEY_PREFIX, sl[I]) = 1 then
200
            if slHelper.Count > 4 then
201
            begin
200
            begin
202
              FCollections[i].Group := StrToInt(slHelper[0]);
201
              slHelper.DelimitedText := INIFile.ReadString(INPX_SECTION, sl[I], '');
203
              FCollections[i].Title := slHelper[1];
202
              if slHelper.Count > 4 then
204
              FCollections[i].Desc  := slHelper[2];
203
              begin
205
              FCollections[i].Inpx  := slHelper[3];
204
                FCollections[I].Group := StrToInt(slHelper[0]);
205
                FCollections[I].Title := slHelper[1];
206
                FCollections[I].Desc := slHelper[2];
207
                FCollections[I].INPX := slHelper[3];
208
              end;
206
            end;
209
            end;
207
          end;
210
          end;
211
        finally
212
          slHelper.Free;
208
        end;
213
        end;
209
      finally
214
      end // if
210
        slHelper.Free;
215
      else
216
      begin
217
        // Добавим inpx по умолчанию
218
        // SetLength(FCollections, 9);
219
        // FCollections := DefaultCollections;
211
      end;
220
      end;
212
    end // if
221
    finally
213
    else
222
      sl.Free;
214
    begin
215
      //     Добавим inpx по умолчанию
216
//      SetLength(FCollections, 9);
217
//      FCollections := DefaultCollections;
218
    end;
223
    end;
219
  finally
224
  finally
220
    sl.Free;
225
    INIFile.Free;
221
    IniFile.Free;
222
  end;
226
  end;
223
end;
227
end;
224
228
225
procedure TframeNCWInpxSource.lvCollectionsChange(Sender: TObject;
229
procedure TframeNCWInpxSource.lvCollectionsChange(Sender: TObject; Item: TListItem; Change: TItemChange);
226
  Item: TListItem; Change: TItemChange);
227
begin
230
begin
228
  pageHint.Caption := FCollections[Item.Index].Desc;
231
  pageHint.Caption := FCollections[Item.Index].Desc;
229
  FPParams^.INPXFile := Settings.WorkPath + FCollections[Item.Index].INPX;
232
  FPParams^.INPXFile := Settings.WorkPath + FCollections[Item.Index].INPX;
230
  FPPArams^.INPXUrl := Settings.InpxURL + FCollections[Item.Index].INPX;
233
  FPParams^.INPXUrl := Settings.INPXUrl + FCollections[Item.Index].INPX;
231
end;
234
end;
232
235
233
procedure TframeNCWInpxSource.OnSetCollectionType(Sender: TObject);
236
procedure TframeNCWInpxSource.OnSetCollectionType(Sender: TObject);
234
begin
237
begin
235
  if Sender = rbLocal then
238
  if Sender = rbLocal then
236
    pageHint.Caption := LOCAL
239
    pageHint.Caption := LOCAL
237
  else pageHint.Caption := SERVERDOWNLOAD;
240
  else
241
    pageHint.Caption := SERVERDOWNLOAD;
238
242
239
  edINPXPath.Enabled := rbLocal.Checked;
243
  edINPXPath.Enabled := rbLocal.Checked;
240
  lvCollections.Enabled := rbDownload.Checked;
244
  lvCollections.Enabled := rbDownload.Checked;
241
end;
245
end;
242
246
243
end.
247
end.
244