Add convenience methods BPackageInfo::ReadFromPackageFile()
This commit is contained in:
@@ -28,9 +28,8 @@ namespace BPackageKit {
|
||||
/*
|
||||
* Keeps a list of package info elements (e.g. name, version, vendor, ...) which
|
||||
* will be converted to package attributes when creating a package. Usually,
|
||||
* these elements have been parsed from a ".PackageInfo"-file.
|
||||
* Alternatively, the package reader populates a BPackageInfo object by
|
||||
* collecting package attributes from an existing package.
|
||||
* these elements have been parsed from a ".PackageInfo" file.
|
||||
* Alternatively, they can be read from an existing package file.
|
||||
*/
|
||||
class BPackageInfo {
|
||||
public:
|
||||
@@ -52,6 +51,8 @@ public:
|
||||
status_t ReadFromConfigString(
|
||||
const BString& packageInfoString,
|
||||
ParseErrorListener* listener = NULL);
|
||||
status_t ReadFromPackageFile(const char* path);
|
||||
status_t ReadFromPackageFile(int fd);
|
||||
|
||||
status_t InitCheck() const;
|
||||
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
|
||||
#include <File.h>
|
||||
#include <Entry.h>
|
||||
#include <package/hpkg/NoErrorOutput.h>
|
||||
#include <package/hpkg/PackageReader.h>
|
||||
#include <package/PackageInfoContentHandler.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
@@ -903,6 +906,34 @@ BPackageInfo::ReadFromConfigString(const BString& packageInfoString,
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BPackageInfo::ReadFromPackageFile(const char* path)
|
||||
{
|
||||
BHPKG::BNoErrorOutput errorOutput;
|
||||
BHPKG::BPackageReader packageReader(&errorOutput);
|
||||
status_t error = packageReader.Init(path);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
BPackageInfoContentHandler handler(*this);
|
||||
return packageReader.ParseContent(&handler);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BPackageInfo::ReadFromPackageFile(int fd)
|
||||
{
|
||||
BHPKG::BNoErrorOutput errorOutput;
|
||||
BHPKG::BPackageReader packageReader(&errorOutput);
|
||||
status_t error = packageReader.Init(fd, false);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
BPackageInfoContentHandler handler(*this);
|
||||
return packageReader.ParseContent(&handler);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BPackageInfo::InitCheck() const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user