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 157 by alloc, Sun Apr 1 23:47:18 2007 UTC vs.
Revision 159 by alloc, Mon Apr 2 00:29:55 2007 UTC

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

Diff Legend

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