OSDN Git Service

Added SPP related codes (draft)
[winbottle/winbottle.git] / bottleclient / SppList.pas
1 {
2  SppList - SPP\83v\83\89\83O\83C\83\93\82ð\8c\9f\8dõ\82µ\82Ä\95Û\8e\9d\82·\82é
3 }
4
5 unit SppList;
6
7 interface
8
9 uses Classes, Windows, SysUtils, Contnrs, Dialogs, SppTypes, Graphics;
10
11 type
12   TSppList = class(TObjectList)
13   public
14     constructor Create(OwnsObject: boolean);
15     procedure LoadFromDirectory(Dir: String);
16     function TryGetImage(const Ghost: String; const Surface: integer;
17       Bitmap: TBitmap): boolean;
18   end;
19
20 var
21   Spps: TSppList;
22
23 implementation
24
25
26 { TSppList }
27
28 constructor TSppList.Create(OwnsObject: boolean);
29 begin
30   inherited Create(true);
31   if OwnsObject = false then
32     raise Exception.Create('OwnsObject must be set to true');
33 end;
34
35 procedure TSppList.LoadFromDirectory(Dir: String);
36 var F: TSearchRec;
37     i: integer;
38     Item: TSurfacePreviewPlugin;
39 begin
40   i := FindFirst(Dir + '\spp\*.dll', 0, F);
41   if i = 0 then begin
42     repeat
43       try
44         Item := TSurfacePreviewPlugin.Create(F.Name);
45         Self.Add(Item);
46       except
47         on E: ESppException do
48         begin
49           ShowMessage('SSP\83v\83\89\83O\83C\83\93\83\8d\81[\83h\8e¸\94s:'#13#10 + E.Message);
50         end;
51       end;
52       i := FindNext(F);
53     until i <> 0;
54   end;
55   FindClose(F);
56 end;
57
58 function TSppList.TryGetImage(const Ghost: String; const Surface: integer;
59   Bitmap: TBitmap): boolean;
60 var i: integer;
61 begin
62   Result := false;
63   for i := 0 to Self.Count-1 do
64   begin
65     if (Items[i] as TSurfacePreviewPlugin).SetSizeAndGetImage(Ghost,
66       Surface, Bitmap) then
67     begin
68       Result := true;
69       Break;
70     end;
71   end;
72 end;
73
74 initialization
75
76 Spps := TSppList.Create(true);
77
78 finalization
79
80 Spps.Free;
81
82 end.