TagFile: use Path instead of const char *

This commit is contained in:
Max Kellermann 2013-10-26 15:14:54 +02:00
parent 4a5aad0948
commit a40246d312
16 changed files with 52 additions and 32 deletions

View File

@ -275,7 +275,7 @@ static void
decoder_load_replay_gain(Decoder &decoder, const char *path_fs)
{
ReplayGainInfo info;
if (replay_gain_ape_read(path_fs, info))
if (replay_gain_ape_read(Path::FromFS(path_fs), info))
decoder_replay_gain(decoder, &info);
}

View File

@ -73,7 +73,7 @@ Song::LoadFile(const char *path_utf8, Directory *parent)
* Attempts to load APE or ID3 tags from the specified file.
*/
static bool
tag_scan_fallback(const char *path,
tag_scan_fallback(Path path,
const struct tag_handler *handler, void *handler_ctx)
{
return tag_ape_scan2(path, handler, handler_ctx) ||
@ -94,13 +94,13 @@ Song::UpdateFile()
return false;
TagBuilder tag_builder;
if (!tag_file_scan(path_fs.c_str(),
if (!tag_file_scan(path_fs,
&full_tag_handler, &tag_builder) ||
!tag_builder.IsDefined())
return false;
if (tag_builder.IsEmpty())
tag_scan_fallback(path_fs.c_str(), &full_tag_handler,
tag_scan_fallback(path_fs, &full_tag_handler,
&tag_builder);
mtime = st.st_mtime;

View File

@ -19,6 +19,7 @@
#include "config.h"
#include "TagFile.hxx"
#include "fs/Path.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
#include "DecoderList.hxx"
@ -29,15 +30,15 @@
#include <assert.h>
bool
tag_file_scan(const char *path_fs,
tag_file_scan(Path path_fs,
const struct tag_handler *handler, void *handler_ctx)
{
assert(path_fs != nullptr);
assert(!path_fs.IsNull());
assert(handler != nullptr);
/* check if there's a suffix and a plugin */
const char *suffix = uri_get_suffix(path_fs);
const char *suffix = uri_get_suffix(path_fs.c_str());
if (suffix == nullptr)
return false;
@ -52,7 +53,7 @@ tag_file_scan(const char *path_fs,
do {
/* load file tag */
if (plugin->ScanFile(path_fs,
if (plugin->ScanFile(path_fs.c_str(),
*handler, handler_ctx))
break;
@ -61,7 +62,8 @@ tag_file_scan(const char *path_fs,
/* open the InputStream (if not already
open) */
if (is == nullptr)
is = InputStream::Open(path_fs, mutex, cond,
is = InputStream::Open(path_fs.c_str(),
mutex, cond,
IgnoreError());
/* now try the stream_tag() method */

View File

@ -22,6 +22,7 @@
#include "check.h"
class Path;
struct tag_handler;
/**
@ -29,7 +30,7 @@ struct tag_handler;
* but does not invoke the special "APE" and "ID3" scanners.
*/
bool
tag_file_scan(const char *path_fs,
tag_file_scan(Path path,
const struct tag_handler *handler, void *handler_ctx);
#endif

View File

@ -112,7 +112,7 @@ handle_read_comments(Client &client, gcc_unused int argc, char *argv[])
return CommandResult::ERROR;
}
if (!tag_file_scan(path_fs.c_str(), &print_comment_handler, &client)) {
if (!tag_file_scan(path_fs, &print_comment_handler, &client)) {
command_error(client, ACK_ERROR_NO_EXIST,
"Failed to load file");
return CommandResult::ERROR;

View File

@ -35,6 +35,7 @@
#include "TagFile.hxx"
#include "cue/CueParser.hxx"
#include "fs/Traits.hxx"
#include "fs/AllocatedPath.hxx"
#include "util/ASCII.hxx"
#include <assert.h>
@ -98,13 +99,17 @@ embcue_playlist_open_uri(const char *uri,
/* only local files supported */
return NULL;
const auto path_fs = AllocatedPath::FromUTF8(uri);
if (path_fs.IsNull())
return nullptr;
const auto playlist = new EmbeddedCuePlaylist();
tag_file_scan(uri, &embcue_tag_handler, playlist);
tag_file_scan(path_fs, &embcue_tag_handler, playlist);
if (playlist->cuesheet.empty()) {
tag_ape_scan2(uri, &embcue_tag_handler, playlist);
tag_ape_scan2(path_fs, &embcue_tag_handler, playlist);
if (playlist->cuesheet.empty())
tag_id3_scan(uri, &embcue_tag_handler, playlist);
tag_id3_scan(path_fs, &embcue_tag_handler, playlist);
}
if (playlist->cuesheet.empty()) {

View File

@ -20,6 +20,7 @@
#include "config.h"
#include "ApeLoader.hxx"
#include "system/ByteOrder.hxx"
#include "fs/FileSystem.hxx"
#include <glib.h>
@ -102,11 +103,9 @@ ape_scan_internal(FILE *fp, ApeTagCallback callback)
}
bool
tag_ape_scan(const char *path_fs, ApeTagCallback callback)
tag_ape_scan(Path path_fs, ApeTagCallback callback)
{
FILE *fp;
fp = fopen(path_fs, "rb");
FILE *fp = FOpen(path_fs, "rb");
if (fp == nullptr)
return false;

View File

@ -26,6 +26,8 @@
#include <stddef.h>
class Path;
typedef std::function<bool(unsigned long flags, const char *key,
const char *value,
size_t value_length)> ApeTagCallback;
@ -38,6 +40,6 @@ typedef std::function<bool(unsigned long flags, const char *key,
* present
*/
bool
tag_ape_scan(const char *path_fs, ApeTagCallback callback);
tag_ape_scan(Path path_fs, ApeTagCallback callback);
#endif

View File

@ -22,6 +22,7 @@
#include "ApeLoader.hxx"
#include "ReplayGainInfo.hxx"
#include "util/ASCII.hxx"
#include "fs/Path.hxx"
#include <string.h>
#include <stdlib.h>
@ -59,7 +60,7 @@ replay_gain_ape_callback(unsigned long flags, const char *key,
}
bool
replay_gain_ape_read(const char *path_fs, ReplayGainInfo &info)
replay_gain_ape_read(Path path_fs, ReplayGainInfo &info)
{
bool found = false;

View File

@ -22,9 +22,10 @@
#include "check.h"
class Path;
struct ReplayGainInfo;
bool
replay_gain_ape_read(const char *path_fs, ReplayGainInfo &info);
replay_gain_ape_read(Path path_fs, ReplayGainInfo &info);
#endif

View File

@ -23,6 +23,7 @@
#include "Tag.hxx"
#include "TagTable.hxx"
#include "TagHandler.hxx"
#include "fs/Path.hxx"
#include <string>
@ -88,7 +89,7 @@ tag_ape_import_item(unsigned long flags,
}
bool
tag_ape_scan2(const char *path_fs,
tag_ape_scan2(Path path_fs,
const struct tag_handler *handler, void *handler_ctx)
{
bool recognized = false;

View File

@ -22,6 +22,7 @@
#include "TagTable.hxx"
class Path;
struct tag_handler;
extern const struct tag_table ape_tags[];
@ -32,7 +33,7 @@ extern const struct tag_table ape_tags[];
* @param path_fs the path of the file in filesystem encoding
*/
bool
tag_ape_scan2(const char *path_fs,
tag_ape_scan2(Path path_fs,
const struct tag_handler *handler, void *handler_ctx);
#endif

View File

@ -29,6 +29,8 @@
#include "ConfigGlobal.hxx"
#include "Riff.hxx"
#include "Aiff.hxx"
#include "fs/Path.hxx"
#include "fs/FileSystem.hxx"
#include <glib.h>
#include <id3tag.h>
@ -539,9 +541,9 @@ tag_id3_riff_aiff_load(FILE *file)
}
struct id3_tag *
tag_id3_load(const char *path_fs, Error &error)
tag_id3_load(Path path_fs, Error &error)
{
FILE *file = fopen(path_fs, "rb");
FILE *file = FOpen(path_fs, "rb");
if (file == nullptr) {
error.FormatErrno("Failed to open file %s", path_fs);
return nullptr;
@ -559,7 +561,7 @@ tag_id3_load(const char *path_fs, Error &error)
}
bool
tag_id3_scan(const char *path_fs,
tag_id3_scan(Path path_fs,
const struct tag_handler *handler, void *handler_ctx)
{
Error error;

View File

@ -23,6 +23,7 @@
#include "check.h"
#include "Compiler.h"
class Path;
struct tag_handler;
struct Tag;
struct id3_tag;
@ -31,7 +32,7 @@ class Error;
#ifdef HAVE_ID3TAG
bool
tag_id3_scan(const char *path_fs,
tag_id3_scan(Path path_fs,
const struct tag_handler *handler, void *handler_ctx);
Tag *
@ -45,7 +46,7 @@ tag_id3_import(struct id3_tag *);
* Error will be set)
*/
struct id3_tag *
tag_id3_load(const char *path_fs, Error &error);
tag_id3_load(Path path_fs, Error &error);
/**
* Import all tags from the provided id3_tag *tag
@ -57,8 +58,10 @@ scan_id3_tag(struct id3_tag *tag,
#else
#include "fs/Path.hxx"
static inline bool
tag_id3_scan(gcc_unused const char *path_fs,
tag_id3_scan(gcc_unused Path path_fs,
gcc_unused const struct tag_handler *handler,
gcc_unused void *handler_ctx)
{

View File

@ -23,6 +23,7 @@
#include "ReplayGainInfo.hxx"
#include "ConfigGlobal.hxx"
#include "util/Error.hxx"
#include "fs/Path.hxx"
#include <id3tag.h>
@ -56,7 +57,7 @@ int main(int argc, char **argv)
const char *path = argv[1];
Error error;
struct id3_tag *tag = tag_id3_load(path, error);
struct id3_tag *tag = tag_id3_load(Path::FromFS(path), error);
if (tag == NULL) {
if (error.IsDefined())
g_printerr("%s\n", error.GetMessage());

View File

@ -28,6 +28,7 @@
#include "tag/TagId3.hxx"
#include "tag/ApeTag.hxx"
#include "util/Error.hxx"
#include "fs/Path.hxx"
#include "thread/Cond.hxx"
#include "Log.hxx"
@ -221,9 +222,9 @@ int main(int argc, char **argv)
}
if (empty) {
tag_ape_scan2(path, &print_handler, NULL);
tag_ape_scan2(Path::FromFS(path), &print_handler, NULL);
if (empty)
tag_id3_scan(path, &print_handler, NULL);
tag_id3_scan(Path::FromFS(path), &print_handler, NULL);
}
return 0;