Commit a40246d3 authored by Max Kellermann's avatar Max Kellermann

TagFile: use Path instead of const char *

parent 4a5aad09
...@@ -275,7 +275,7 @@ static void ...@@ -275,7 +275,7 @@ static void
decoder_load_replay_gain(Decoder &decoder, const char *path_fs) decoder_load_replay_gain(Decoder &decoder, const char *path_fs)
{ {
ReplayGainInfo info; 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); decoder_replay_gain(decoder, &info);
} }
......
...@@ -73,7 +73,7 @@ Song::LoadFile(const char *path_utf8, Directory *parent) ...@@ -73,7 +73,7 @@ Song::LoadFile(const char *path_utf8, Directory *parent)
* Attempts to load APE or ID3 tags from the specified file. * Attempts to load APE or ID3 tags from the specified file.
*/ */
static bool static bool
tag_scan_fallback(const char *path, tag_scan_fallback(Path path,
const struct tag_handler *handler, void *handler_ctx) const struct tag_handler *handler, void *handler_ctx)
{ {
return tag_ape_scan2(path, handler, handler_ctx) || return tag_ape_scan2(path, handler, handler_ctx) ||
...@@ -94,13 +94,13 @@ Song::UpdateFile() ...@@ -94,13 +94,13 @@ Song::UpdateFile()
return false; return false;
TagBuilder tag_builder; TagBuilder tag_builder;
if (!tag_file_scan(path_fs.c_str(), if (!tag_file_scan(path_fs,
&full_tag_handler, &tag_builder) || &full_tag_handler, &tag_builder) ||
!tag_builder.IsDefined()) !tag_builder.IsDefined())
return false; return false;
if (tag_builder.IsEmpty()) if (tag_builder.IsEmpty())
tag_scan_fallback(path_fs.c_str(), &full_tag_handler, tag_scan_fallback(path_fs, &full_tag_handler,
&tag_builder); &tag_builder);
mtime = st.st_mtime; mtime = st.st_mtime;
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "config.h" #include "config.h"
#include "TagFile.hxx" #include "TagFile.hxx"
#include "fs/Path.hxx"
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "DecoderList.hxx" #include "DecoderList.hxx"
...@@ -29,15 +30,15 @@ ...@@ -29,15 +30,15 @@
#include <assert.h> #include <assert.h>
bool bool
tag_file_scan(const char *path_fs, tag_file_scan(Path path_fs,
const struct tag_handler *handler, void *handler_ctx) const struct tag_handler *handler, void *handler_ctx)
{ {
assert(path_fs != nullptr); assert(!path_fs.IsNull());
assert(handler != nullptr); assert(handler != nullptr);
/* check if there's a suffix and a plugin */ /* 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) if (suffix == nullptr)
return false; return false;
...@@ -52,7 +53,7 @@ tag_file_scan(const char *path_fs, ...@@ -52,7 +53,7 @@ tag_file_scan(const char *path_fs,
do { do {
/* load file tag */ /* load file tag */
if (plugin->ScanFile(path_fs, if (plugin->ScanFile(path_fs.c_str(),
*handler, handler_ctx)) *handler, handler_ctx))
break; break;
...@@ -61,7 +62,8 @@ tag_file_scan(const char *path_fs, ...@@ -61,7 +62,8 @@ tag_file_scan(const char *path_fs,
/* open the InputStream (if not already /* open the InputStream (if not already
open) */ open) */
if (is == nullptr) if (is == nullptr)
is = InputStream::Open(path_fs, mutex, cond, is = InputStream::Open(path_fs.c_str(),
mutex, cond,
IgnoreError()); IgnoreError());
/* now try the stream_tag() method */ /* now try the stream_tag() method */
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "check.h" #include "check.h"
class Path;
struct tag_handler; struct tag_handler;
/** /**
...@@ -29,7 +30,7 @@ struct tag_handler; ...@@ -29,7 +30,7 @@ struct tag_handler;
* but does not invoke the special "APE" and "ID3" scanners. * but does not invoke the special "APE" and "ID3" scanners.
*/ */
bool bool
tag_file_scan(const char *path_fs, tag_file_scan(Path path,
const struct tag_handler *handler, void *handler_ctx); const struct tag_handler *handler, void *handler_ctx);
#endif #endif
...@@ -112,7 +112,7 @@ handle_read_comments(Client &client, gcc_unused int argc, char *argv[]) ...@@ -112,7 +112,7 @@ handle_read_comments(Client &client, gcc_unused int argc, char *argv[])
return CommandResult::ERROR; 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, command_error(client, ACK_ERROR_NO_EXIST,
"Failed to load file"); "Failed to load file");
return CommandResult::ERROR; return CommandResult::ERROR;
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "TagFile.hxx" #include "TagFile.hxx"
#include "cue/CueParser.hxx" #include "cue/CueParser.hxx"
#include "fs/Traits.hxx" #include "fs/Traits.hxx"
#include "fs/AllocatedPath.hxx"
#include "util/ASCII.hxx" #include "util/ASCII.hxx"
#include <assert.h> #include <assert.h>
...@@ -98,13 +99,17 @@ embcue_playlist_open_uri(const char *uri, ...@@ -98,13 +99,17 @@ embcue_playlist_open_uri(const char *uri,
/* only local files supported */ /* only local files supported */
return NULL; return NULL;
const auto path_fs = AllocatedPath::FromUTF8(uri);
if (path_fs.IsNull())
return nullptr;
const auto playlist = new EmbeddedCuePlaylist(); 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()) { 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()) 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()) { if (playlist->cuesheet.empty()) {
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "config.h" #include "config.h"
#include "ApeLoader.hxx" #include "ApeLoader.hxx"
#include "system/ByteOrder.hxx" #include "system/ByteOrder.hxx"
#include "fs/FileSystem.hxx"
#include <glib.h> #include <glib.h>
...@@ -102,11 +103,9 @@ ape_scan_internal(FILE *fp, ApeTagCallback callback) ...@@ -102,11 +103,9 @@ ape_scan_internal(FILE *fp, ApeTagCallback callback)
} }
bool bool
tag_ape_scan(const char *path_fs, ApeTagCallback callback) tag_ape_scan(Path path_fs, ApeTagCallback callback)
{ {
FILE *fp; FILE *fp = FOpen(path_fs, "rb");
fp = fopen(path_fs, "rb");
if (fp == nullptr) if (fp == nullptr)
return false; return false;
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#include <stddef.h> #include <stddef.h>
class Path;
typedef std::function<bool(unsigned long flags, const char *key, typedef std::function<bool(unsigned long flags, const char *key,
const char *value, const char *value,
size_t value_length)> ApeTagCallback; size_t value_length)> ApeTagCallback;
...@@ -38,6 +40,6 @@ typedef std::function<bool(unsigned long flags, const char *key, ...@@ -38,6 +40,6 @@ typedef std::function<bool(unsigned long flags, const char *key,
* present * present
*/ */
bool bool
tag_ape_scan(const char *path_fs, ApeTagCallback callback); tag_ape_scan(Path path_fs, ApeTagCallback callback);
#endif #endif
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "ApeLoader.hxx" #include "ApeLoader.hxx"
#include "ReplayGainInfo.hxx" #include "ReplayGainInfo.hxx"
#include "util/ASCII.hxx" #include "util/ASCII.hxx"
#include "fs/Path.hxx"
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -59,7 +60,7 @@ replay_gain_ape_callback(unsigned long flags, const char *key, ...@@ -59,7 +60,7 @@ replay_gain_ape_callback(unsigned long flags, const char *key,
} }
bool bool
replay_gain_ape_read(const char *path_fs, ReplayGainInfo &info) replay_gain_ape_read(Path path_fs, ReplayGainInfo &info)
{ {
bool found = false; bool found = false;
......
...@@ -22,9 +22,10 @@ ...@@ -22,9 +22,10 @@
#include "check.h" #include "check.h"
class Path;
struct ReplayGainInfo; struct ReplayGainInfo;
bool bool
replay_gain_ape_read(const char *path_fs, ReplayGainInfo &info); replay_gain_ape_read(Path path_fs, ReplayGainInfo &info);
#endif #endif
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "Tag.hxx" #include "Tag.hxx"
#include "TagTable.hxx" #include "TagTable.hxx"
#include "TagHandler.hxx" #include "TagHandler.hxx"
#include "fs/Path.hxx"
#include <string> #include <string>
...@@ -88,7 +89,7 @@ tag_ape_import_item(unsigned long flags, ...@@ -88,7 +89,7 @@ tag_ape_import_item(unsigned long flags,
} }
bool bool
tag_ape_scan2(const char *path_fs, tag_ape_scan2(Path path_fs,
const struct tag_handler *handler, void *handler_ctx) const struct tag_handler *handler, void *handler_ctx)
{ {
bool recognized = false; bool recognized = false;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "TagTable.hxx" #include "TagTable.hxx"
class Path;
struct tag_handler; struct tag_handler;
extern const struct tag_table ape_tags[]; extern const struct tag_table ape_tags[];
...@@ -32,7 +33,7 @@ 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 * @param path_fs the path of the file in filesystem encoding
*/ */
bool bool
tag_ape_scan2(const char *path_fs, tag_ape_scan2(Path path_fs,
const struct tag_handler *handler, void *handler_ctx); const struct tag_handler *handler, void *handler_ctx);
#endif #endif
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include "ConfigGlobal.hxx" #include "ConfigGlobal.hxx"
#include "Riff.hxx" #include "Riff.hxx"
#include "Aiff.hxx" #include "Aiff.hxx"
#include "fs/Path.hxx"
#include "fs/FileSystem.hxx"
#include <glib.h> #include <glib.h>
#include <id3tag.h> #include <id3tag.h>
...@@ -539,9 +541,9 @@ tag_id3_riff_aiff_load(FILE *file) ...@@ -539,9 +541,9 @@ tag_id3_riff_aiff_load(FILE *file)
} }
struct id3_tag * 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) { if (file == nullptr) {
error.FormatErrno("Failed to open file %s", path_fs); error.FormatErrno("Failed to open file %s", path_fs);
return nullptr; return nullptr;
...@@ -559,7 +561,7 @@ tag_id3_load(const char *path_fs, Error &error) ...@@ -559,7 +561,7 @@ tag_id3_load(const char *path_fs, Error &error)
} }
bool bool
tag_id3_scan(const char *path_fs, tag_id3_scan(Path path_fs,
const struct tag_handler *handler, void *handler_ctx) const struct tag_handler *handler, void *handler_ctx)
{ {
Error error; Error error;
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "check.h" #include "check.h"
#include "Compiler.h" #include "Compiler.h"
class Path;
struct tag_handler; struct tag_handler;
struct Tag; struct Tag;
struct id3_tag; struct id3_tag;
...@@ -31,7 +32,7 @@ class Error; ...@@ -31,7 +32,7 @@ class Error;
#ifdef HAVE_ID3TAG #ifdef HAVE_ID3TAG
bool bool
tag_id3_scan(const char *path_fs, tag_id3_scan(Path path_fs,
const struct tag_handler *handler, void *handler_ctx); const struct tag_handler *handler, void *handler_ctx);
Tag * Tag *
...@@ -45,7 +46,7 @@ tag_id3_import(struct id3_tag *); ...@@ -45,7 +46,7 @@ tag_id3_import(struct id3_tag *);
* Error will be set) * Error will be set)
*/ */
struct id3_tag * 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 * Import all tags from the provided id3_tag *tag
...@@ -57,8 +58,10 @@ scan_id3_tag(struct id3_tag *tag, ...@@ -57,8 +58,10 @@ scan_id3_tag(struct id3_tag *tag,
#else #else
#include "fs/Path.hxx"
static inline bool 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 const struct tag_handler *handler,
gcc_unused void *handler_ctx) gcc_unused void *handler_ctx)
{ {
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "ReplayGainInfo.hxx" #include "ReplayGainInfo.hxx"
#include "ConfigGlobal.hxx" #include "ConfigGlobal.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "fs/Path.hxx"
#include <id3tag.h> #include <id3tag.h>
...@@ -56,7 +57,7 @@ int main(int argc, char **argv) ...@@ -56,7 +57,7 @@ int main(int argc, char **argv)
const char *path = argv[1]; const char *path = argv[1];
Error error; 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 (tag == NULL) {
if (error.IsDefined()) if (error.IsDefined())
g_printerr("%s\n", error.GetMessage()); g_printerr("%s\n", error.GetMessage());
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "tag/TagId3.hxx" #include "tag/TagId3.hxx"
#include "tag/ApeTag.hxx" #include "tag/ApeTag.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "fs/Path.hxx"
#include "thread/Cond.hxx" #include "thread/Cond.hxx"
#include "Log.hxx" #include "Log.hxx"
...@@ -221,9 +222,9 @@ int main(int argc, char **argv) ...@@ -221,9 +222,9 @@ int main(int argc, char **argv)
} }
if (empty) { if (empty) {
tag_ape_scan2(path, &print_handler, NULL); tag_ape_scan2(Path::FromFS(path), &print_handler, NULL);
if (empty) if (empty)
tag_id3_scan(path, &print_handler, NULL); tag_id3_scan(Path::FromFS(path), &print_handler, NULL);
} }
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment