* Construct the MIME data base directories lazily.
* Automatic whitespace cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34399 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -20,8 +20,8 @@ namespace Storage {
|
|||||||
namespace Mime {
|
namespace Mime {
|
||||||
|
|
||||||
// Database directory
|
// Database directory
|
||||||
extern const std::string kDatabaseDir;
|
const std::string get_database_directory();
|
||||||
extern const std::string kApplicationDatabaseDir;
|
const std::string get_application_database_directory();
|
||||||
|
|
||||||
// Attribute Prefixes
|
// Attribute Prefixes
|
||||||
extern const char *kMiniIconAttrPrefix;
|
extern const char *kMiniIconAttrPrefix;
|
||||||
|
|||||||
@@ -38,15 +38,6 @@ namespace BPrivate {
|
|||||||
namespace Storage {
|
namespace Storage {
|
||||||
namespace Mime {
|
namespace Mime {
|
||||||
|
|
||||||
static const char *get_user_settings_dir(BPath &path);
|
|
||||||
|
|
||||||
static BPath sSettingsDirPath;
|
|
||||||
static const std::string sSettingsDir = get_user_settings_dir(sSettingsDirPath);
|
|
||||||
|
|
||||||
static const char *sHaikuDBDirName = "beos_mime";
|
|
||||||
// when running natively under Haiku
|
|
||||||
const std::string kDatabaseDir = sSettingsDir + "/" + sHaikuDBDirName;
|
|
||||||
const std::string kApplicationDatabaseDir = kDatabaseDir + "/application";
|
|
||||||
|
|
||||||
#define ATTR_PREFIX "META:"
|
#define ATTR_PREFIX "META:"
|
||||||
#define MINI_ICON_ATTR_PREFIX ATTR_PREFIX "M:"
|
#define MINI_ICON_ATTR_PREFIX ATTR_PREFIX "M:"
|
||||||
@@ -103,27 +94,47 @@ const char *kMetaMimeType = "application/x-vnd.Be-meta-mime";
|
|||||||
// Error codes
|
// Error codes
|
||||||
const status_t kMimeGuessFailureError = B_ERRORS_END+1;
|
const status_t kMimeGuessFailureError = B_ERRORS_END+1;
|
||||||
|
|
||||||
// get_settings_dir
|
static pthread_once_t sDatabaseDirectoryInitOnce = PTHREAD_ONCE_INIT;
|
||||||
/*! \brief Sets the supplied BPath to the user settings directory and returns
|
static std::string sDatabaseDirectory;
|
||||||
it as C string.
|
static std::string sApplicationDatabaseDirectory;
|
||||||
\param path BPath to be set to the user settings path.
|
|
||||||
\return the user settings path as C string (\code path.Path() \endcode).
|
|
||||||
*/
|
static void
|
||||||
static
|
init_database_directories()
|
||||||
const char*
|
|
||||||
get_user_settings_dir(BPath &path)
|
|
||||||
{
|
{
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
BPath path;
|
||||||
path.SetTo("/boot/home/config/settings");
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK)
|
||||||
return path.Path();
|
sDatabaseDirectory = path.Path();
|
||||||
|
else
|
||||||
|
sDatabaseDirectory = "/boot/home/config/settings";
|
||||||
|
|
||||||
|
sDatabaseDirectory += "/beos_mime";
|
||||||
|
sApplicationDatabaseDirectory = sDatabaseDirectory + "/application";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const std::string
|
||||||
|
get_database_directory()
|
||||||
|
{
|
||||||
|
pthread_once(&sDatabaseDirectoryInitOnce, &init_database_directories);
|
||||||
|
return sDatabaseDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const std::string
|
||||||
|
get_application_database_directory()
|
||||||
|
{
|
||||||
|
pthread_once(&sDatabaseDirectoryInitOnce, &init_database_directories);
|
||||||
|
return sApplicationDatabaseDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// type_to_filename
|
// type_to_filename
|
||||||
//! Converts the given MIME type to an absolute path in the MIME database.
|
//! Converts the given MIME type to an absolute path in the MIME database.
|
||||||
std::string
|
std::string
|
||||||
type_to_filename(const char *type)
|
type_to_filename(const char *type)
|
||||||
{
|
{
|
||||||
return kDatabaseDir + "/" + BPrivate::Storage::to_lower(type);
|
return get_database_directory() + "/" + BPrivate::Storage::to_lower(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// open_type
|
// open_type
|
||||||
@@ -183,7 +194,7 @@ open_or_create_type(const char *type, BNode *result, bool *didCreate)
|
|||||||
uint32 pos = typeLower.find_first_of('/');
|
uint32 pos = typeLower.find_first_of('/');
|
||||||
if (pos == std::string::npos) {
|
if (pos == std::string::npos) {
|
||||||
// Supertype == directory
|
// Supertype == directory
|
||||||
BDirectory parent(kDatabaseDir.c_str());
|
BDirectory parent(get_database_directory().c_str());
|
||||||
err = parent.InitCheck();
|
err = parent.InitCheck();
|
||||||
if (!err)
|
if (!err)
|
||||||
err = parent.CreateDirectory(typeLower.c_str(), NULL);
|
err = parent.CreateDirectory(typeLower.c_str(), NULL);
|
||||||
@@ -191,7 +202,7 @@ open_or_create_type(const char *type, BNode *result, bool *didCreate)
|
|||||||
// Non-supertype == file
|
// Non-supertype == file
|
||||||
std::string super(typeLower, 0, pos);
|
std::string super(typeLower, 0, pos);
|
||||||
std::string sub(typeLower, pos+1);
|
std::string sub(typeLower, pos+1);
|
||||||
BDirectory parent((kDatabaseDir + "/" + super).c_str());
|
BDirectory parent((get_database_directory() + "/" + super).c_str());
|
||||||
err = parent.InitCheck();
|
err = parent.InitCheck();
|
||||||
if (!err)
|
if (!err)
|
||||||
err = parent.CreateFile(sub.c_str(), NULL);
|
err = parent.CreateFile(sub.c_str(), NULL);
|
||||||
|
|||||||
@@ -331,7 +331,7 @@ AssociatedTypes::BuildAssociatedTypesTable()
|
|||||||
fAssociatedTypes.clear();
|
fAssociatedTypes.clear();
|
||||||
|
|
||||||
BDirectory root;
|
BDirectory root;
|
||||||
status_t err = root.SetTo(kDatabaseDir.c_str());
|
status_t err = root.SetTo(get_database_directory().c_str());
|
||||||
if (!err) {
|
if (!err) {
|
||||||
root.Rewind();
|
root.Rewind();
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -393,7 +393,7 @@ AssociatedTypes::BuildAssociatedTypesTable()
|
|||||||
} else {
|
} else {
|
||||||
DBG(OUT("Mime::AssociatedTypes::BuildAssociatedTypesTable(): "
|
DBG(OUT("Mime::AssociatedTypes::BuildAssociatedTypesTable(): "
|
||||||
"Failed opening mime database directory '%s'\n",
|
"Failed opening mime database directory '%s'\n",
|
||||||
kDatabaseDir.c_str()));
|
get_database_directory().c_str()));
|
||||||
}
|
}
|
||||||
if (!err) {
|
if (!err) {
|
||||||
fHaveDoneFullBuild = true;
|
fHaveDoneFullBuild = true;
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ CreateAppMetaMimeThread::DoMimeUpdate(const entry_ref* ref, bool* _entryIsDir)
|
|||||||
path.ToLower();
|
path.ToLower();
|
||||||
// Signatures and MIME types are case insensitive, but we want to
|
// Signatures and MIME types are case insensitive, but we want to
|
||||||
// preserve the case wherever possible
|
// preserve the case wherever possible
|
||||||
path.Prepend(kDatabaseDir.c_str());
|
path.Prepend(get_database_directory().c_str());
|
||||||
|
|
||||||
status = typeNode.SetTo(path.String());
|
status = typeNode.SetTo(path.String());
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ Database::Database()
|
|||||||
fDeferredInstallNotifications()
|
fDeferredInstallNotifications()
|
||||||
{
|
{
|
||||||
// Do some really minor error checking
|
// Do some really minor error checking
|
||||||
BEntry entry(kDatabaseDir.c_str());
|
BEntry entry(get_database_directory().c_str());
|
||||||
fStatus = entry.Exists() ? B_OK : B_BAD_VALUE;
|
fStatus = entry.Exists() ? B_OK : B_BAD_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -382,7 +382,7 @@ InstalledTypes::_BuildInstalledTypesList()
|
|||||||
|
|
||||||
BDirectory root;
|
BDirectory root;
|
||||||
if (!err)
|
if (!err)
|
||||||
err = root.SetTo(kDatabaseDir.c_str());
|
err = root.SetTo(get_database_directory().c_str());
|
||||||
if (!err) {
|
if (!err) {
|
||||||
root.Rewind();
|
root.Rewind();
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -452,7 +452,7 @@ InstalledTypes::_BuildInstalledTypesList()
|
|||||||
} else {
|
} else {
|
||||||
DBG(OUT("Mime::InstalledTypes::BuildInstalledTypesList(): "
|
DBG(OUT("Mime::InstalledTypes::BuildInstalledTypesList(): "
|
||||||
"Failed opening mime database directory '%s'\n",
|
"Failed opening mime database directory '%s'\n",
|
||||||
kDatabaseDir.c_str()));
|
get_database_directory().c_str()));
|
||||||
}
|
}
|
||||||
fHaveDoneFullBuild = true;
|
fHaveDoneFullBuild = true;
|
||||||
return err;
|
return err;
|
||||||
|
|||||||
@@ -334,7 +334,7 @@ SnifferRules::BuildRuleList()
|
|||||||
ssize_t bytesNeeded = 0;
|
ssize_t bytesNeeded = 0;
|
||||||
BDirectory root;
|
BDirectory root;
|
||||||
|
|
||||||
status_t err = root.SetTo(kDatabaseDir.c_str());
|
status_t err = root.SetTo(get_database_directory().c_str());
|
||||||
if (!err) {
|
if (!err) {
|
||||||
root.Rewind();
|
root.Rewind();
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -400,7 +400,7 @@ SnifferRules::BuildRuleList()
|
|||||||
} else {
|
} else {
|
||||||
DBG(OUT("Mime::SnifferRules::BuildRuleList(): "
|
DBG(OUT("Mime::SnifferRules::BuildRuleList(): "
|
||||||
"Failed opening mime database directory '%s'\n",
|
"Failed opening mime database directory '%s'\n",
|
||||||
kDatabaseDir.c_str()));
|
get_database_directory().c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ SupportingApps::BuildSupportingAppsTable()
|
|||||||
fStrandedTypes.clear();
|
fStrandedTypes.clear();
|
||||||
|
|
||||||
BDirectory dir;
|
BDirectory dir;
|
||||||
status_t status = dir.SetTo(kApplicationDatabaseDir.c_str());
|
status_t status = dir.SetTo(get_application_database_directory().c_str());
|
||||||
|
|
||||||
// Build the supporting apps table based on the mime database
|
// Build the supporting apps table based on the mime database
|
||||||
if (status == B_OK) {
|
if (status == B_OK) {
|
||||||
|
|||||||
Reference in New Issue
Block a user