* Build fix under Haiku (the two max() arguments had different types).
* Improved error reporting in WriteToFile(). * UpdateAttributes() was called twice in WriteToFile(). * Cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34249 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -31,21 +31,16 @@
|
|||||||
|
|
||||||
|
|
||||||
using std::auto_ptr;
|
using std::auto_ptr;
|
||||||
using std::min;
|
|
||||||
using std::max;
|
|
||||||
using std::pair;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*! This file implements the default catalog-type for the opentracker locale
|
||||||
* This file implements the default catalog-type for the opentracker locale
|
kit. Alternatively, this could be used as a full add-on, but currently this
|
||||||
* kit. Alternatively, this could be used as a full add-on, but currently this
|
is provided as part of liblocale.so.
|
||||||
* is provided as part of liblocale.so.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
// several attributes/resource-IDs used within the Locale Kit:
|
||||||
* several attributes/resource-IDs used within the Locale Kit:
|
|
||||||
*/
|
|
||||||
const char *kCatLangAttr = "BEOS:LOCALE_LANGUAGE";
|
const char *kCatLangAttr = "BEOS:LOCALE_LANGUAGE";
|
||||||
// name of catalog language, lives in every catalog file
|
// name of catalog language, lives in every catalog file
|
||||||
const char *kCatSigAttr = "BEOS:LOCALE_SIGNATURE";
|
const char *kCatSigAttr = "BEOS:LOCALE_SIGNATURE";
|
||||||
@@ -60,11 +55,10 @@ static int16 kCatArchiveVersion = 1;
|
|||||||
// version of the catalog archive structure, bump this if you change it!
|
// version of the catalog archive structure, bump this if you change it!
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*! Constructs a DefaultCatalog with given signature and language and reads
|
||||||
* constructs a DefaultCatalog with given signature and language and reads
|
the catalog from disk.
|
||||||
* the catalog from disk.
|
InitCheck() will be B_OK if catalog could be loaded successfully, it will
|
||||||
* InitCheck() will be B_OK if catalog could be loaded successfully, it will
|
give an appropriate error-code otherwise.
|
||||||
* give an appropriate error-code otherwise.
|
|
||||||
*/
|
*/
|
||||||
DefaultCatalog::DefaultCatalog(const char *signature, const char *language,
|
DefaultCatalog::DefaultCatalog(const char *signature, const char *language,
|
||||||
uint32 fingerprint)
|
uint32 fingerprint)
|
||||||
@@ -78,11 +72,10 @@ DefaultCatalog::DefaultCatalog(const char *signature, const char *language,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*! Constructs a DefaultCatalog and reads it from the resources of the
|
||||||
* constructs a DefaultCatalog and reads it from the resources of the
|
given entry-ref (which usually is an app- or add-on-file).
|
||||||
* given entry-ref (which usually is an app- or add-on-file).
|
InitCheck() will be B_OK if catalog could be loaded successfully, it will
|
||||||
* InitCheck() will be B_OK if catalog could be loaded successfully, it will
|
give an appropriate error-code otherwise.
|
||||||
* give an appropriate error-code otherwise.
|
|
||||||
*/
|
*/
|
||||||
DefaultCatalog::DefaultCatalog(entry_ref *appOrAddOnRef)
|
DefaultCatalog::DefaultCatalog(entry_ref *appOrAddOnRef)
|
||||||
:
|
:
|
||||||
@@ -95,10 +88,9 @@ DefaultCatalog::DefaultCatalog(entry_ref *appOrAddOnRef)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*! Constructs an empty DefaultCatalog with given sig and language.
|
||||||
* constructs an empty DefaultCatalog with given sig and language.
|
This is used for editing/testing purposes.
|
||||||
* This is used for editing/testing purposes.
|
InitCheck() will always be B_OK.
|
||||||
* InitCheck() will always be B_OK.
|
|
||||||
*/
|
*/
|
||||||
DefaultCatalog::DefaultCatalog(const char *path, const char *signature,
|
DefaultCatalog::DefaultCatalog(const char *path, const char *signature,
|
||||||
const char *language)
|
const char *language)
|
||||||
@@ -168,9 +160,8 @@ DefaultCatalog::ReadFromFile(const char *path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*! This method is not currently being used, but it may be useful in the
|
||||||
* this method is not currently being used, but it may be useful in the
|
future...
|
||||||
* future...
|
|
||||||
*/
|
*/
|
||||||
status_t
|
status_t
|
||||||
DefaultCatalog::ReadFromAttribute(entry_ref *appOrAddOnRef)
|
DefaultCatalog::ReadFromAttribute(entry_ref *appOrAddOnRef)
|
||||||
@@ -192,33 +183,34 @@ DefaultCatalog::WriteToFile(const char *path)
|
|||||||
BFile catalogFile;
|
BFile catalogFile;
|
||||||
if (path)
|
if (path)
|
||||||
fPath = path;
|
fPath = path;
|
||||||
status_t res = catalogFile.SetTo(fPath.String(),
|
status_t status = catalogFile.SetTo(fPath.String(),
|
||||||
B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
||||||
if (res != B_OK)
|
if (status != B_OK)
|
||||||
return res;
|
return status;
|
||||||
|
|
||||||
BMallocIO mallocIO;
|
BMallocIO mallocIO;
|
||||||
mallocIO.SetBlockSize(max(fCatMap.Size()*20, 256));
|
mallocIO.SetBlockSize(max_c(fCatMap.Size() * 20, 256));
|
||||||
// set a largish block-size in order to avoid reallocs
|
// set a largish block-size in order to avoid reallocs
|
||||||
res = Flatten(&mallocIO);
|
status = Flatten(&mallocIO);
|
||||||
if (res == B_OK) {
|
if (status != B_OK)
|
||||||
ssize_t wsz;
|
return status;
|
||||||
wsz = catalogFile.Write(mallocIO.Buffer(), mallocIO.BufferLength());
|
|
||||||
if (wsz != (ssize_t)mallocIO.BufferLength())
|
ssize_t bytesWritten
|
||||||
return B_FILE_ERROR;
|
= catalogFile.Write(mallocIO.Buffer(), mallocIO.BufferLength());
|
||||||
|
if (bytesWritten < 0)
|
||||||
|
return bytesWritten;
|
||||||
|
if (bytesWritten != (ssize_t)mallocIO.BufferLength())
|
||||||
|
return B_IO_ERROR;
|
||||||
|
|
||||||
// set mimetype-, language- and signature-attributes:
|
// set mimetype-, language- and signature-attributes:
|
||||||
UpdateAttributes(catalogFile);
|
UpdateAttributes(catalogFile);
|
||||||
}
|
|
||||||
if (res == B_OK)
|
return B_OK;
|
||||||
UpdateAttributes(catalogFile);
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*! This method is not currently being used, but it may be useful in the
|
||||||
* this method is not currently being used, but it may be useful in the
|
future...
|
||||||
* future...
|
|
||||||
*/
|
*/
|
||||||
status_t
|
status_t
|
||||||
DefaultCatalog::WriteToAttribute(entry_ref *appOrAddOnRef)
|
DefaultCatalog::WriteToAttribute(entry_ref *appOrAddOnRef)
|
||||||
@@ -234,9 +226,8 @@ DefaultCatalog::WriteToResource(entry_ref *appOrAddOnRef)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*! Writes mimetype, language-name and signature of catalog into the
|
||||||
* writes mimetype, language-name and signature of catalog into the
|
catalog-file.
|
||||||
* catalog-file.
|
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
DefaultCatalog::UpdateAttributes(BFile& catalogFile)
|
DefaultCatalog::UpdateAttributes(BFile& catalogFile)
|
||||||
|
|||||||
Reference in New Issue
Block a user