Should now play much nicer with broken settings files. Fixes bug #165.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16768 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2006-03-13 18:22:59 +00:00
parent 58d9acf59e
commit ae99c86041
2 changed files with 22 additions and 22 deletions

View File

@ -1,4 +1,5 @@
/*
* Copyright (c) 2003-2006, Haiku, Inc. All Rights Reserved.
* Copyright (c) 2004 Daniel Furrer <assimil8or@users.sourceforge.net>
* Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
* Copyright (c) 1998,99 Kazuho Okui and Takashi Murai.
@ -29,7 +30,7 @@
/*
* Startup preference settings.
*/
static const prefDefaults kTermDefaults[] = {
static const pref_defaults kTermDefaults[] = {
{ PREF_COLS, "80" },
{ PREF_ROWS, "25" },
@ -70,9 +71,11 @@ PrefHandler::PrefHandler()
:
fContainer('Pref')
{
_LoadFromDefault(kTermDefaults);
BPath path;
GetDefaultPath(path);
OpenText(path.Path(), kTermDefaults);
OpenText(path.Path());
_ConfirmFont(PREF_HALF_FONT_FAMILY, be_fixed_font);
_ConfirmFont(PREF_FULL_FONT_FAMILY, be_fixed_font);
@ -108,24 +111,16 @@ PrefHandler::GetDefaultPath(BPath& path)
status_t
PrefHandler::Open(const char *path, const prefDefaults *defaults)
PrefHandler::Open(const char *path)
{
BEntry entry(path);
if (entry.Exists())
return _LoadFromFile(&entry);
return _LoadFromDefault(defaults);
return _LoadFromFile(path);
}
status_t
PrefHandler::OpenText(const char *path, const prefDefaults *defaults)
PrefHandler::OpenText(const char *path)
{
BEntry entry(path);
if (entry.Exists())
return _LoadFromTextFile(path);
return _LoadFromDefault(defaults);
return _LoadFromTextFile(path);
}
@ -341,12 +336,16 @@ PrefHandler::_ConfirmFont(const char *key, const BFont *fallback)
status_t
PrefHandler::_LoadFromFile(BEntry *entry)
PrefHandler::_LoadFromFile(const char* path)
{
// Future: It would be nice if we could simply use a flatened BMessage to
// save the settings. (Who cares about compatibility in this case anyway?)
BFile file(entry, B_READ_ONLY);
BFile file(path, B_READ_ONLY);
status_t status = file.InitCheck();
if (status != B_OK)
return status;
//fContainer.MakeEmpty();
//fContainer.Unflatten(&file);
@ -384,7 +383,7 @@ PrefHandler::_LoadFromFile(BEntry *entry)
status_t
PrefHandler::_LoadFromDefault(const prefDefaults* defaults)
PrefHandler::_LoadFromDefault(const pref_defaults* defaults)
{
if (defaults == NULL)
return B_ERROR;

View File

@ -1,4 +1,5 @@
/*
* Copyright (c) 2003-2006, Haiku, Inc. All Rights Reserved.
* Copyright (c) 2004 Daniel Furrer <assimil8or@users.sourceforge.net>
* Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
* Copyright (c) 1998,99 Kazuho Okui and Takashi Murai.
@ -43,7 +44,7 @@ struct termprefs {
char unknown[3];
};
struct prefDefaults {
struct pref_defaults {
const char *key;
char *item;
};
@ -60,8 +61,8 @@ class PrefHandler {
PrefHandler();
~PrefHandler();
status_t Open(const char *name, const prefDefaults *defaults = NULL);
status_t OpenText(const char *path, const prefDefaults *defaults = NULL);
status_t Open(const char *name);
status_t OpenText(const char *path);
status_t Save(const char *name);
void SaveAsText(const char *path, const char *minmtype = NULL,
const char *signature = NULL);
@ -84,8 +85,8 @@ class PrefHandler {
private:
void _ConfirmFont(const char *key, const BFont *fallback);
status_t _LoadFromFile(BEntry *ent);
status_t _LoadFromDefault(const prefDefaults* defaluts = NULL);
status_t _LoadFromFile(const char* path);
status_t _LoadFromDefault(const pref_defaults* defaults = NULL);
status_t _LoadFromTextFile(const char * path);
BMessage fContainer;