| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- unit IconRequest;
- interface
- uses
- Classes, SysUtils, IdHTTP, IdComponent, Windows;
- type
- TIconResponseEvent = procedure(AppKey: string; AStream: TStream) of object;
- TIconRequest = class(TThread)
- private
- FApps: IInterfaceList;
- FMemoryStream: TMemoryStream;
- FOnCompleted: TIconResponseEvent;
- protected
- procedure Execute; override;
- public
- constructor Create(AApps: IInterfaceList);
- destructor Destroy; override;
- class function GetMD5Name(AUrl: string): string;
- property OnCompleted: TIconResponseEvent read FOnCompleted write FOnCompleted;
- end;
- const
- ICON_URL: string = 'http://%s:%d%s';
- implementation
- uses
- MD5_32, InterfaceAppCentre, LoggerImport, AppCentreImport, Dialogs, IdURI;
- const
- TEMP_DIR: string = 'Users\';
- { TIconRequest }
- constructor TIconRequest.Create(AApps: IInterfaceList);
- begin
- FApps := AApps;
- FMemoryStream := TMemoryStream.Create;
- FreeOnTerminate := False;
- inherited Create(False);
- end;
- //constructor TIconRequest.Create(AppKey, AUrl: String);
- //begin
- // FAppKey := AppKey;
- // FURL := AUrl;
- // FMD5Name := GetMD5Name(AUrl);
- // FMemoryStream := TMemoryStream.Create;
- // inherited Create(True);
- //end;
- destructor TIconRequest.Destroy;
- begin
- FOnCompleted := nil;
- FApps := nil;
- FreeAndNil(FMemoryStream);
- inherited;
- end;
- procedure TIconRequest.Execute;
- var
- AIdHttp: TIdHTTP;
- iLoop: Integer;
- ADownloadThread: TIconRequest;
- AHotApp: IHotApp;
- AApp: IApp;
- AConfig: IAppCentreConfig;
- AURL: string;
- begin
- AIdHttp := TIdHTTP.Create(nil);
- AIdHttp.Request.CustomHeaders.Values['Content-Type'] := 'application/octet-stream';
- try
- iLoop := 0;
- while (not Terminated) and (FApps <> nil) and (iLoop <= FApps.Count - 1) do
- begin
- if FApps[iLoop].QueryInterface(IHotApp, AHotApp) = S_OK then
- AApp := AHotApp.GetUserApp
- else if FApps[iLoop].QueryInterface(IApp, AApp) = S_OK then
- else
- begin
- inc(iLoop);
- Continue;
- end;
- Inc(iLoop);
- if Length(AApp.GetIcon) = 0 then
- Continue;
- FMemoryStream.Clear;
- AConfig := GetAppCentreConfig;
- // AURL := AApp.GetIcon
- AIdHTTP.Get(AApp.GetIcon, FMemoryStream);
- if Terminated then
- Break;
- if Assigned(FOnCompleted) then
- FOnCompleted(AApp.GetAppKey, FMemoryStream);
- end;
- Debug(IntToStr(ThreadID)+ '-Ö´ÐÐÍê±Ï', 'TIconRequest.Execute');
- except
- on E: Exception do
- begin
- Debug(E.Message, 'TIconRequest.Execute');
- FApps := nil;
- FreeAndNil(AIdHTTP);
- end;
- end;
- FApps := nil;
- FreeAndNil(AIdHTTP);
- end;
- class function TIconRequest.GetMD5Name(AUrl: string): string;
- begin
- Result := '';
- if Length(AUrl) > 0 then
- Result := MD5Print(MD5String(AUrl));
- end;
- end.
|