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

Comparing oup/current/DataAccess/Access_OUP_ADB.pas (file contents):
Revision 156 by alloc, Sun Apr 1 22:49:17 2007 UTC vs.
Revision 157 by alloc, Sun Apr 1 23:47:18 2007 UTC

# Line 213 | Line 213 | end;
213  
214  
215  
216  function CompareItems(List: TStringList; I1, I2: Integer): Integer;
217  var
218    fin: Boolean;
219    pos: Integer;
220    s1, s2: String;
221  begin
222    fin := False;
223    s1 := MidStr(List[I1], 1, PosEx(';', List[I1], 6) - 1);
224    s2 := MidStr(List[I2], 1, PosEx(';', List[I2], 6) - 1);
225    pos := 1;
226    Result := 0;
227    repeat
228      if Ord(s1[pos]) < Ord(s2[pos]) then
229      begin
230        Result := -1;
231        fin := True;
232      end
233      else if Ord(s1[pos]) > Ord(s2[pos]) then
234      begin
235        Result := 1;
236        fin := True;
237      end;
238      Inc(pos);
239    until fin or (pos > Length(s1)) or (pos > Length(s2));
240
241    if not fin then
242    begin
243      if pos > Length(s1) then
244        Result := -1
245      else
246        Result := 1;
247    end;
248  end;
249
216   function TAccess_OUP_ADB.GetFilesList(ext: String; pattern: String;
217    NoEmptyFiles: Boolean; SortType: TSortType): TStrings;
218   var
# Line 285 | Line 251 | var
251    end;
252  
253   begin
254 <  list := TStringList.Create;
289 <  if SortType in [ST_ExtNameAsc, ST_ExtNameDesc] then
290 <    list.Sorted := False
291 <  else
292 <    list.Sorted := True;
293 <  for i := 0 to GetFileCount - 1 do
254 >  if not (SortType in [ST_ExtNameAsc, ST_ExtNameDesc]) then
255    begin
256 <    if ((Length(ext) = 0) or (Pos(Fdat_files[i].Extension, ext) > 0)) and
257 <      ((Length(pattern) = 0) or
258 <      (Pos(UpperCase(pattern), UpperCase(Fdat_files[i].Name)) > 0)) then
256 >    list := TStringList.Create;
257 >    list.Sorted := True;
258 >    for i := 0 to GetFileCount - 1 do
259      begin
260 <      if (NoEmptyFiles = False) or ((Fdat_files[i].FileType and $02) = 0) then
260 >      if ((Length(ext) = 0) or (Pos(Fdat_files[i].Extension, ext) > 0)) and
261 >        ((Length(pattern) = 0) or
262 >        (Pos(UpperCase(pattern), UpperCase(Fdat_files[i].Name)) > 0)) then
263        begin
264 <        id := FormatNumber(Fdat_files[i].ID, 5, '0');
265 <        name := Fdat_files[i].Name;
266 <        extension := Fdat_files[i].Extension;
267 <
268 <        case SortType of
269 <          ST_IDAsc, ST_IDDesc:     list.Add(id + ';' + name + ';' + extension);
270 <          ST_NameAsc, ST_NameDesc: list.Add(name + ';' + id + ';' + extension);
271 <          ST_ExtAsc, ST_ExtDesc:   list.Add(extension + ';' + id + ';' + name);
272 <          ST_ExtNameAsc, ST_ExtNameDesc: list.Add(extension + ';' + name + ';' + id);
264 >        if (NoEmptyFiles = False) or ((Fdat_files[i].FileType and $02) = 0) then
265 >        begin
266 >          id := FormatNumber(Fdat_files[i].ID, 5, '0');
267 >          name := Fdat_files[i].Name;
268 >          extension := Fdat_files[i].Extension;
269 >
270 >          case SortType of
271 >            ST_IDAsc, ST_IDDesc:     list.Add(id + ';' + name + ';' + extension);
272 >            ST_NameAsc, ST_NameDesc: list.Add(name + ';' + id + ';' + extension);
273 >            ST_ExtAsc, ST_ExtDesc:   list.Add(extension + ';' + id + ';' + name);
274 >            ST_ExtNameAsc, ST_ExtNameDesc: list.Add(extension + ';' + name + ';' + id);
275 >          end;
276          end;
277        end;
278      end;
279 <  end;
280 <  if SortType in [ST_ExtNameAsc, ST_ExtNameDesc] then
281 <    list.CustomSort(CompareItems);
282 <  if not Assigned(Result) then
283 <    Result := TStringList.Create;
284 <  if list.Count > 0 then
279 >    if not Assigned(Result) then
280 >      Result := TStringList.Create;
281 >    if list.Count > 0 then
282 >    begin
283 >      fields := TStringList.Create;
284 >      if SortType in [ST_IDAsc, ST_NameAsc, ST_ExtAsc, ST_ExtNameAsc] then
285 >        for i := 0 to list.Count - 1 do
286 >        begin
287 >          getfields;
288 >          Result.Add(id + '-' + name + '.' + extension);
289 >        end
290 >      else
291 >        for i := list.Count - 1 downto 0 do
292 >        begin
293 >          getfields;
294 >          Result.Add(id + '-' + name + '.' + extension);
295 >        end;
296 >      fields.Free;
297 >    end;
298 >    list.Free;
299 >  end
300 >  else
301    begin
302 <    fields := TStringList.Create;
303 <    if SortType in [ST_IDAsc, ST_NameAsc, ST_ExtAsc, ST_ExtNameAsc] then
304 <      for i := 0 to list.Count - 1 do
305 <      begin
306 <        getfields;
307 <        Result.Add(id + '-' + name + '.' + extension);
308 <      end
309 <    else
310 <      for i := list.Count - 1 downto 0 do
311 <      begin
312 <        getfields;
313 <        Result.Add(id + '-' + name + '.' + extension);
314 <      end;
315 <    fields.Free;
302 >    FQuery.SQL.Text := 'SELECT id, name, extension FROM datfiles ' +
303 >        'WHERE Length(name) > 0 ORDER BY extension ASC, name ASC;';
304 >    FQuery.Open;
305 >    if not Assigned(Result) then
306 >      Result := TStringList.Create;
307 >    if FQuery.RecordCount > 0 then
308 >    begin
309 >      FQuery.First;
310 >      repeat
311 >        name := FormatNumber(FQuery.FieldByName('id').AsInteger, 5, '0') +
312 >              '-' + FQuery.FieldByName('name').AsString + '.' +
313 >              FQuery.FieldByName('extension').AsString;
314 >        if SortType = ST_ExtNameAsc then
315 >          Result.Add(name)
316 >        else
317 >          Result.Insert(0, name);
318 >        FQuery.Next;
319 >      until FQuery.EOF;
320 >    end;
321 >    FQuery.Close;
322    end;
335  list.Free;
323   end;
324  
325  

Diff Legend

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