BPicture: Fix archive constructor.
[haiku.git] / src / kits / package / DownloadFileRequest.cpp
blob81b40644475c89ccd97b360cd045d07e4438d0d8
1 /*
2 * Copyright 2013, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Ingo Weinhold <ingo_weinhold@gmx.de>
7 */
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)
25 inherited(context),
26 fFileURL(fileURL),
27 fTargetEntry(targetEntry),
28 fChecksum(checksum)
30 if (fInitStatus == B_OK) {
31 if (fFileURL.IsEmpty())
32 fInitStatus = B_BAD_VALUE;
33 else
34 fInitStatus = targetEntry.InitCheck();
39 DownloadFileRequest::~DownloadFileRequest()
44 status_t
45 DownloadFileRequest::CreateInitialJobs()
47 status_t error = InitCheck();
48 if (error != B_OK)
49 return B_NO_INIT;
51 // create the download job
52 FetchFileJob* fetchJob = new (std::nothrow) FetchFileJob(fContext,
53 BString("Downloading ") << fFileURL, fFileURL, fTargetEntry);
54 if (fetchJob == NULL)
55 return B_NO_MEMORY;
57 if ((error = QueueJob(fetchJob)) != B_OK) {
58 delete fetchJob;
59 return error;
62 // create the checksum validation job
63 if (fChecksum.IsEmpty())
64 return B_OK;
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)
72 return B_NO_MEMORY;
74 if ((error = QueueJob(validateJob)) != B_OK) {
75 delete validateJob;
76 return error;
79 return B_OK;
83 } // namespace BPackageKit