applied patch by Maurice Kalinowski:
* Add check whether directory to store settings exists. If not, create it. * Use global constant (like in DefaultManager.cpp) for path/file names. * Cleaned up a little bit and made debug output only appear in case debugging is turned on (meaning printf->TRACE). -> Fixes #1531. (I added a few more error checks to the code, maybe there should be even more...) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24089 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
c789abb0e8
commit
c067ed4ea4
@ -2,15 +2,21 @@
|
|||||||
* Copyright 2003, Jérôme Duval. All rights reserved.
|
* Copyright 2003, Jérôme Duval. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#include <Application.h>
|
#include "debug.h"
|
||||||
#include <Autolock.h>
|
|
||||||
#include <MediaFiles.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <storage/FindDirectory.h>
|
|
||||||
#include <storage/Path.h>
|
|
||||||
#include "MMediaFilesManager.h"
|
#include "MMediaFilesManager.h"
|
||||||
#include "MediaSounds.h"
|
#include "MediaSounds.h"
|
||||||
#include "debug.h"
|
|
||||||
|
#include <Application.h>
|
||||||
|
#include <Autolock.h>
|
||||||
|
#include <Directory.h>
|
||||||
|
#include <FindDirectory.h>
|
||||||
|
#include <MediaFiles.h>
|
||||||
|
#include <Path.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
const char *kMediaFilesManagerSettingsDirectory = "Media";
|
||||||
|
const char *kMediaFilesManagerSettingsFile = "MMediaFilesManager";
|
||||||
|
|
||||||
|
|
||||||
MMediaFilesManager::MMediaFilesManager()
|
MMediaFilesManager::MMediaFilesManager()
|
||||||
@ -40,6 +46,7 @@ MMediaFilesManager::MMediaFilesManager()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MMediaFilesManager::~MMediaFilesManager()
|
MMediaFilesManager::~MMediaFilesManager()
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
@ -91,13 +98,15 @@ status_t
|
|||||||
MMediaFilesManager::LoadState()
|
MMediaFilesManager::LoadState()
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
status_t err = B_OK;
|
|
||||||
BPath path;
|
BPath path;
|
||||||
if ((err = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) != B_OK)
|
status_t err = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
||||||
|
if (err >= B_OK)
|
||||||
|
err = path.Append(kMediaFilesManagerSettingsDirectory);
|
||||||
|
if (err >= B_OK)
|
||||||
|
err = path.Append(kMediaFilesManagerSettingsFile);
|
||||||
|
if (err < B_OK)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
path.Append("Media/MMediaFilesManager");
|
|
||||||
|
|
||||||
BFile file(path.Path(), B_READ_ONLY);
|
BFile file(path.Path(), B_READ_ONLY);
|
||||||
|
|
||||||
uint32 category_count;
|
uint32 category_count;
|
||||||
@ -160,13 +169,19 @@ status_t
|
|||||||
MMediaFilesManager::SaveState()
|
MMediaFilesManager::SaveState()
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
status_t err = B_OK;
|
|
||||||
BPath path;
|
BPath path;
|
||||||
if ((err = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) != B_OK)
|
status_t err = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
||||||
|
if (err >= B_OK)
|
||||||
|
err = path.Append(kMediaFilesManagerSettingsDirectory);
|
||||||
|
if (err >= B_OK) {
|
||||||
|
err = create_directory(path.Path(),
|
||||||
|
S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
|
||||||
|
}
|
||||||
|
if (err >= B_OK)
|
||||||
|
err = path.Append(kMediaFilesManagerSettingsFile);
|
||||||
|
if (err < B_OK)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
path.Append("Media/MMediaFilesManager");
|
|
||||||
|
|
||||||
BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE);
|
BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE);
|
||||||
uint32 zero = 0;
|
uint32 zero = 0;
|
||||||
|
|
||||||
@ -206,11 +221,10 @@ void
|
|||||||
MMediaFilesManager::Dump()
|
MMediaFilesManager::Dump()
|
||||||
{
|
{
|
||||||
BAutolock lock(fLocker);
|
BAutolock lock(fLocker);
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
/* for each type, the registry map contains a map of item/entry_ref
|
/* for each type, the registry map contains a map of item/entry_ref
|
||||||
*/
|
*/
|
||||||
printf("MMediaFilesManager: registry map follows\n");
|
TRACE("MMediaFilesManager: registry map follows\n");
|
||||||
BString *type = NULL;
|
BString *type = NULL;
|
||||||
Map<BString, entry_ref> *map;
|
Map<BString, entry_ref> *map;
|
||||||
BString *item = NULL;
|
BString *item = NULL;
|
||||||
@ -221,13 +235,11 @@ MMediaFilesManager::Dump()
|
|||||||
for (map->Rewind(); map->GetNext(&ref);) {
|
for (map->Rewind(); map->GetNext(&ref);) {
|
||||||
map->GetCurrentKey(&item);
|
map->GetCurrentKey(&item);
|
||||||
BPath path(ref);
|
BPath path(ref);
|
||||||
printf(" type \"%s\", item \"%s\", path \"%s\"\n",
|
TRACE(" type \"%s\", item \"%s\", path \"%s\"\n",
|
||||||
type->String(), item->String(), (path.InitCheck() == B_OK) ? path.Path() : "INVALID");
|
type->String(), item->String(), (path.InitCheck() == B_OK) ? path.Path() : "INVALID");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("MMediaFilesManager: list end\n");
|
TRACE("MMediaFilesManager: list end\n");
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user