BPicture: Fix archive constructor.
[haiku.git] / src / kits / package / Context.cpp
bloba5e212c6740e592a8ec9cfb5640ad645b8492292
1 /*
2 * Copyright 2011-2015, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Oliver Tappe <zooey@hirschkaefer.de>
7 */
10 #include <new>
12 #include <package/Context.h>
13 #include <package/TempfileManager.h>
15 #include <Directory.h>
16 #include <FindDirectory.h>
17 #include <OS.h>
18 #include <Path.h>
21 namespace BPackageKit {
24 using BPrivate::TempfileManager;
27 BDecisionProvider::~BDecisionProvider()
32 bool
33 BDecisionProvider::YesNoDecisionNeeded(const BString& description,
34 const BString& question, const BString& yes, const BString& no,
35 const BString& defaultChoice)
37 return defaultChoice == yes;
41 BContext::BContext(BDecisionProvider& decisionProvider,
42 BSupportKit::BJobStateListener& jobStateListener)
44 fDecisionProvider(decisionProvider),
45 fJobStateListener(jobStateListener),
46 fTempfileManager(NULL)
48 fInitStatus = _Initialize();
52 BContext::~BContext()
54 delete fTempfileManager;
58 status_t
59 BContext::InitCheck() const
61 return fInitStatus;
65 status_t
66 BContext::GetNewTempfile(const BString& baseName, BEntry* entry) const
68 if (entry == NULL)
69 return B_BAD_VALUE;
70 if (fTempfileManager == NULL)
71 return B_NO_INIT;
72 *entry = fTempfileManager->Create(baseName);
73 return entry->InitCheck();
77 BSupportKit::BJobStateListener&
78 BContext::JobStateListener() const
80 return fJobStateListener;
84 BDecisionProvider&
85 BContext::DecisionProvider() const
87 return fDecisionProvider;
91 status_t
92 BContext::_Initialize()
94 fTempfileManager = new (std::nothrow) TempfileManager();
95 if (fTempfileManager == NULL)
96 return B_NO_MEMORY;
98 BPath tempPath;
99 status_t result = find_directory(B_SYSTEM_TEMP_DIRECTORY, &tempPath, true);
100 if (result != B_OK)
101 return result;
102 BDirectory tempDirectory(tempPath.Path());
103 if ((result = tempDirectory.InitCheck()) != B_OK)
104 return result;
106 BString contextName = BString("pkgkit-context-") << find_thread(NULL)
107 << "-" << system_time();
108 BDirectory baseDirectory;
109 result = tempDirectory.CreateDirectory(contextName.String(),
110 &baseDirectory);
111 if (result != B_OK)
112 return result;
114 fTempfileManager->SetBaseDirectory(baseDirectory);
116 return B_OK;
120 } // namespace BPackageKit