2 * Copyright 2011-2015, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Oliver Tappe <zooey@hirschkaefer.de>
12 #include <package/Context.h>
13 #include <package/TempfileManager.h>
15 #include <Directory.h>
16 #include <FindDirectory.h>
21 namespace BPackageKit
{
24 using BPrivate::TempfileManager
;
27 BDecisionProvider::~BDecisionProvider()
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();
54 delete fTempfileManager
;
59 BContext::InitCheck() const
66 BContext::GetNewTempfile(const BString
& baseName
, BEntry
* entry
) const
70 if (fTempfileManager
== NULL
)
72 *entry
= fTempfileManager
->Create(baseName
);
73 return entry
->InitCheck();
77 BSupportKit::BJobStateListener
&
78 BContext::JobStateListener() const
80 return fJobStateListener
;
85 BContext::DecisionProvider() const
87 return fDecisionProvider
;
92 BContext::_Initialize()
94 fTempfileManager
= new (std::nothrow
) TempfileManager();
95 if (fTempfileManager
== NULL
)
99 status_t result
= find_directory(B_SYSTEM_TEMP_DIRECTORY
, &tempPath
, true);
102 BDirectory
tempDirectory(tempPath
.Path());
103 if ((result
= tempDirectory
.InitCheck()) != B_OK
)
106 BString contextName
= BString("pkgkit-context-") << find_thread(NULL
)
107 << "-" << system_time();
108 BDirectory baseDirectory
;
109 result
= tempDirectory
.CreateDirectory(contextName
.String(),
114 fTempfileManager
->SetBaseDirectory(baseDirectory
);
120 } // namespace BPackageKit