2 * Copyright 2013, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Ingo Weinhold <ingo_weinhold@gmx.de>
10 #include <package/DownloadFileRequest.h>
12 #include <package/FetchFileJob.h>
13 #include <package/ValidateChecksumJob.h>
16 namespace BPackageKit
{
19 using namespace BPrivate
;
22 DownloadFileRequest::DownloadFileRequest(const BContext
& context
,
23 const BString
& fileURL
, const BEntry
& targetEntry
, const BString
& checksum
)
27 fTargetEntry(targetEntry
),
30 if (fInitStatus
== B_OK
) {
31 if (fFileURL
.IsEmpty())
32 fInitStatus
= B_BAD_VALUE
;
34 fInitStatus
= targetEntry
.InitCheck();
39 DownloadFileRequest::~DownloadFileRequest()
45 DownloadFileRequest::CreateInitialJobs()
47 status_t error
= InitCheck();
51 // create the download job
52 FetchFileJob
* fetchJob
= new (std::nothrow
) FetchFileJob(fContext
,
53 BString("Downloading ") << fFileURL
, fFileURL
, fTargetEntry
);
57 if ((error
= QueueJob(fetchJob
)) != B_OK
) {
62 // create the checksum validation job
63 if (fChecksum
.IsEmpty())
66 ValidateChecksumJob
* validateJob
= new (std::nothrow
) ValidateChecksumJob(
67 fContext
, BString("Validating checksum for ") << fFileURL
,
68 new (std::nothrow
) StringChecksumAccessor(fChecksum
),
69 new (std::nothrow
) GeneralFileChecksumAccessor(fTargetEntry
, true));
71 if (validateJob
== NULL
)
74 if ((error
= QueueJob(validateJob
)) != B_OK
) {
83 } // namespace BPackageKit