2 * Copyright 2011-2013, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Oliver Tappe <zooey@hirschkaefer.de>
10 #include <package/RepositoryConfig.h>
16 #include <Directory.h>
17 #include <driver_settings.h>
19 #include <FindDirectory.h>
22 #include <DriverSettings.h>
25 namespace BPackageKit
{
28 BRepositoryConfig::BRepositoryConfig()
30 fInitStatus(B_NO_INIT
),
31 fPriority(kUnsetPriority
),
32 fIsUserSpecific(false)
37 BRepositoryConfig::BRepositoryConfig(const BEntry
& entry
)
43 BRepositoryConfig::BRepositoryConfig(const BString
& name
,
44 const BString
& baseURL
, uint8 priority
)
50 fIsUserSpecific(false)
55 BRepositoryConfig::~BRepositoryConfig()
61 BRepositoryConfig::Store(const BEntry
& entry
) const
63 BFile
file(&entry
, B_WRITE_ONLY
| B_CREATE_FILE
| B_ERASE_FILE
);
64 status_t result
= file
.InitCheck();
70 << "url=" << fBaseURL
<< "\n"
71 << "priority=" << fPriority
<< "\n";
73 int32 size
= configString
.Length();
74 if ((result
= file
.Write(configString
.String(), size
)) < size
)
75 return (result
>= 0) ? B_ERROR
: result
;
82 BRepositoryConfig::InitCheck() const
89 BRepositoryConfig::SetTo(const BEntry
& entry
)
92 fInitStatus
= B_NO_INIT
;
95 status_t result
= entry
.GetRef(&ref
);
99 BDriverSettings driverSettings
;
100 result
= driverSettings
.Load(ref
);
104 const char* url
= driverSettings
.GetParameterValue("url");
105 const char* priorityString
= driverSettings
.GetParameterValue("priority");
107 if (url
== NULL
|| *url
== '\0')
110 fName
= entry
.Name();
112 fPriority
= priorityString
== NULL
113 ? kUnsetPriority
: atoi(priorityString
);
115 BPath userSettingsPath
;
116 if (find_directory(B_USER_SETTINGS_DIRECTORY
, &userSettingsPath
) == B_OK
) {
117 BDirectory
userSettingsDir(userSettingsPath
.Path());
118 fIsUserSpecific
= userSettingsDir
.Contains(&entry
);
120 fIsUserSpecific
= false;
129 BRepositoryConfig::Name() const
136 BRepositoryConfig::BaseURL() const
143 BRepositoryConfig::Priority() const
150 BRepositoryConfig::IsUserSpecific() const
152 return fIsUserSpecific
;
157 BRepositoryConfig::Entry() const
164 BRepositoryConfig::PackagesURL() const
166 if (fBaseURL
.IsEmpty())
168 return BString().SetToFormat("%s/packages", fBaseURL
.String());
173 BRepositoryConfig::SetName(const BString
& name
)
180 BRepositoryConfig::SetBaseURL(const BString
& baseURL
)
187 BRepositoryConfig::SetPriority(uint8 priority
)
189 fPriority
= priority
;
194 BRepositoryConfig::SetIsUserSpecific(bool isUserSpecific
)
196 fIsUserSpecific
= isUserSpecific
;
200 } // namespace BPackageKit