Path: convert remaining funcs to methods, keep fs_charset as std::string
This commit is contained in:
parent
7149a8ae4f
commit
943064bb51
@ -62,7 +62,8 @@ db_save_internal(FILE *fp, const Directory *music_root)
|
|||||||
fprintf(fp, "%s\n", DIRECTORY_INFO_BEGIN);
|
fprintf(fp, "%s\n", DIRECTORY_INFO_BEGIN);
|
||||||
fprintf(fp, DB_FORMAT_PREFIX "%u\n", DB_FORMAT);
|
fprintf(fp, DB_FORMAT_PREFIX "%u\n", DB_FORMAT);
|
||||||
fprintf(fp, "%s%s\n", DIRECTORY_MPD_VERSION, VERSION);
|
fprintf(fp, "%s%s\n", DIRECTORY_MPD_VERSION, VERSION);
|
||||||
fprintf(fp, "%s%s\n", DIRECTORY_FS_CHARSET, path_get_fs_charset());
|
fprintf(fp, "%s%s\n", DIRECTORY_FS_CHARSET,
|
||||||
|
Path::GetFSCharset().c_str());
|
||||||
|
|
||||||
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i)
|
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i)
|
||||||
if (!ignore_tag_items[i])
|
if (!ignore_tag_items[i])
|
||||||
@ -106,7 +107,7 @@ db_load_internal(TextFile &file, Directory *music_root, GError **error)
|
|||||||
|
|
||||||
found_version = true;
|
found_version = true;
|
||||||
} else if (g_str_has_prefix(line, DIRECTORY_FS_CHARSET)) {
|
} else if (g_str_has_prefix(line, DIRECTORY_FS_CHARSET)) {
|
||||||
const char *new_charset, *old_charset;
|
const char *new_charset;
|
||||||
|
|
||||||
if (found_charset) {
|
if (found_charset) {
|
||||||
g_set_error(error, db_quark(), 0,
|
g_set_error(error, db_quark(), 0,
|
||||||
@ -117,14 +118,14 @@ db_load_internal(TextFile &file, Directory *music_root, GError **error)
|
|||||||
found_charset = true;
|
found_charset = true;
|
||||||
|
|
||||||
new_charset = line + sizeof(DIRECTORY_FS_CHARSET) - 1;
|
new_charset = line + sizeof(DIRECTORY_FS_CHARSET) - 1;
|
||||||
old_charset = path_get_fs_charset();
|
const std::string &old_charset = Path::GetFSCharset();
|
||||||
if (old_charset != NULL
|
if (!old_charset.empty()
|
||||||
&& strcmp(new_charset, old_charset)) {
|
&& strcmp(new_charset, old_charset.c_str())) {
|
||||||
g_set_error(error, db_quark(), 0,
|
g_set_error(error, db_quark(), 0,
|
||||||
"Existing database has charset "
|
"Existing database has charset "
|
||||||
"\"%s\" instead of \"%s\"; "
|
"\"%s\" instead of \"%s\"; "
|
||||||
"discarding database file",
|
"discarding database file",
|
||||||
new_charset, old_charset);
|
new_charset, old_charset.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (g_str_has_prefix(line, DB_TAG_PREFIX)) {
|
} else if (g_str_has_prefix(line, DB_TAG_PREFIX)) {
|
||||||
|
@ -417,7 +417,7 @@ int mpd_main(int argc, char *argv[])
|
|||||||
GlobalEvents::Register(GlobalEvents::IDLE, idle_event_emitted);
|
GlobalEvents::Register(GlobalEvents::IDLE, idle_event_emitted);
|
||||||
GlobalEvents::Register(GlobalEvents::SHUTDOWN, shutdown_event_emitted);
|
GlobalEvents::Register(GlobalEvents::SHUTDOWN, shutdown_event_emitted);
|
||||||
|
|
||||||
path_global_init();
|
Path::GlobalInit();
|
||||||
|
|
||||||
if (!glue_mapper_init(&error)) {
|
if (!glue_mapper_init(&error)) {
|
||||||
g_warning("%s", error->message);
|
g_warning("%s", error->message);
|
||||||
@ -554,7 +554,6 @@ int mpd_main(int argc, char *argv[])
|
|||||||
audio_output_all_finish();
|
audio_output_all_finish();
|
||||||
volume_finish();
|
volume_finish();
|
||||||
mapper_finish();
|
mapper_finish();
|
||||||
path_global_finish();
|
|
||||||
delete global_partition;
|
delete global_partition;
|
||||||
command_finish();
|
command_finish();
|
||||||
update_global_finish();
|
update_global_finish();
|
||||||
|
@ -46,14 +46,14 @@
|
|||||||
*/
|
*/
|
||||||
#define MPD_PATH_MAX_UTF8 ((MPD_PATH_MAX - 1) * 4 + 1)
|
#define MPD_PATH_MAX_UTF8 ((MPD_PATH_MAX - 1) * 4 + 1)
|
||||||
|
|
||||||
static char *fs_charset;
|
std::string fs_charset;
|
||||||
|
|
||||||
std::string Path::ToUTF8(const_pointer path_fs)
|
std::string Path::ToUTF8(const_pointer path_fs)
|
||||||
{
|
{
|
||||||
if (path_fs == nullptr)
|
if (path_fs == nullptr)
|
||||||
return std::string();
|
return std::string();
|
||||||
|
|
||||||
GIConv conv = g_iconv_open("utf-8", fs_charset);
|
GIConv conv = g_iconv_open("utf-8", fs_charset.c_str());
|
||||||
if (conv == reinterpret_cast<GIConv>(-1))
|
if (conv == reinterpret_cast<GIConv>(-1))
|
||||||
return std::string();
|
return std::string();
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ Path Path::FromUTF8(const char *path_utf8)
|
|||||||
gchar *p;
|
gchar *p;
|
||||||
|
|
||||||
p = g_convert(path_utf8, -1,
|
p = g_convert(path_utf8, -1,
|
||||||
fs_charset, "utf-8",
|
fs_charset.c_str(), "utf-8",
|
||||||
NULL, NULL, NULL);
|
NULL, NULL, NULL);
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
/* fall back to UTF-8 */
|
/* fall back to UTF-8 */
|
||||||
@ -103,25 +103,24 @@ IsSupportedCharset(const char *charset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
path_set_fs_charset(const char *charset)
|
SetFSCharset(const char *charset)
|
||||||
{
|
{
|
||||||
assert(charset != NULL);
|
assert(charset != NULL);
|
||||||
|
|
||||||
if (!IsSupportedCharset(charset))
|
if (!IsSupportedCharset(charset))
|
||||||
MPD_ERROR("invalid filesystem charset: %s", charset);
|
MPD_ERROR("invalid filesystem charset: %s", charset);
|
||||||
|
|
||||||
g_free(fs_charset);
|
fs_charset = charset;
|
||||||
fs_charset = g_strdup(charset);
|
|
||||||
|
|
||||||
g_debug("path_set_fs_charset: fs charset is: %s", fs_charset);
|
g_debug("SetFSCharset: fs charset is: %s", fs_charset.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *path_get_fs_charset(void)
|
const std::string &Path::GetFSCharset()
|
||||||
{
|
{
|
||||||
return fs_charset;
|
return fs_charset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void path_global_init(void)
|
void Path::GlobalInit()
|
||||||
{
|
{
|
||||||
const char *charset = NULL;
|
const char *charset = NULL;
|
||||||
|
|
||||||
@ -146,14 +145,9 @@ void path_global_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (charset) {
|
if (charset) {
|
||||||
path_set_fs_charset(charset);
|
SetFSCharset(charset);
|
||||||
} else {
|
} else {
|
||||||
g_message("setting filesystem charset to ISO-8859-1");
|
g_message("setting filesystem charset to ISO-8859-1");
|
||||||
path_set_fs_charset("ISO-8859-1");
|
SetFSCharset("ISO-8859-1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void path_global_finish(void)
|
|
||||||
{
|
|
||||||
g_free(fs_charset);
|
|
||||||
}
|
|
||||||
|
@ -44,12 +44,6 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void path_global_init();
|
|
||||||
|
|
||||||
void path_global_finish();
|
|
||||||
|
|
||||||
const char *path_get_fs_charset();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A path name in the native file system character set.
|
* A path name in the native file system character set.
|
||||||
*/
|
*/
|
||||||
@ -165,6 +159,16 @@ public:
|
|||||||
gcc_pure
|
gcc_pure
|
||||||
static std::string ToUTF8(const_pointer path_fs);
|
static std::string ToUTF8(const_pointer path_fs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs global one-time initialization of this class.
|
||||||
|
*/
|
||||||
|
static void GlobalInit();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets file system character set name.
|
||||||
|
*/
|
||||||
|
static const std::string &GetFSCharset();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy a #Path object.
|
* Copy a #Path object.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user