|
1
|
1 #include "foobar2000-sdk-pch.h"
|
|
|
2 #include "titleformat.h"
|
|
|
3 #include "file_info_impl.h"
|
|
|
4 #include "input.h"
|
|
|
5
|
|
|
6 double metadb_handle::get_length()
|
|
|
7 {
|
|
|
8 return this->get_info_ref()->info().get_length();
|
|
|
9 }
|
|
|
10
|
|
|
11 t_filetimestamp metadb_handle::get_filetimestamp()
|
|
|
12 {
|
|
|
13 return get_filestats().m_timestamp;
|
|
|
14 }
|
|
|
15
|
|
|
16 t_filesize metadb_handle::get_filesize()
|
|
|
17 {
|
|
|
18 return get_filestats().m_size;
|
|
|
19 }
|
|
|
20
|
|
|
21 bool metadb_handle::format_title_legacy(titleformat_hook * p_hook,pfc::string_base & p_out,const char * p_spec,titleformat_text_filter * p_filter)
|
|
|
22 {
|
|
|
23 service_ptr_t<titleformat_object> script;
|
|
|
24 if (titleformat_compiler::get()->compile(script,p_spec)) {
|
|
|
25 return format_title(p_hook,p_out,script,p_filter);
|
|
|
26 } else {
|
|
|
27 p_out.reset();
|
|
|
28 return false;
|
|
|
29 }
|
|
|
30 }
|
|
|
31
|
|
|
32
|
|
|
33 bool metadb_handle::g_should_reload_ex(const t_filestats& p_old_stats, const t_filestats& p_new_stats, t_filetimestamp p_readtime) {
|
|
|
34 if (p_new_stats.m_timestamp == filetimestamp_invalid) {
|
|
|
35 return p_readtime != filetimestamp_invalid;//SNAFU: some locations don't have timestamps at all, let's always accept hints for those when readtime is valid
|
|
|
36 } else if (p_old_stats.m_timestamp == filetimestamp_invalid) {
|
|
|
37 return true;
|
|
|
38 } else if (p_new_stats.m_timestamp > p_old_stats.m_timestamp) {
|
|
|
39 return true;
|
|
|
40 } else if (p_new_stats.m_timestamp < p_old_stats.m_timestamp) {
|
|
|
41 //special case - file has possibly been replaced with older version - check read time
|
|
|
42 if (p_readtime == filetimestamp_invalid) return false;
|
|
|
43 else return p_readtime > p_old_stats.m_timestamp;
|
|
|
44 } else {//timestamps match
|
|
|
45 return false;
|
|
|
46 }
|
|
|
47 }
|
|
|
48 bool metadb_handle::g_should_reload(const t_filestats & p_old_stats,const t_filestats & p_new_stats,bool p_fresh)
|
|
|
49 {
|
|
|
50 if (p_new_stats.m_timestamp == filetimestamp_invalid) return p_fresh;
|
|
|
51 else if (p_fresh) return p_old_stats!= p_new_stats;
|
|
|
52 else return p_old_stats.m_timestamp < p_new_stats.m_timestamp;
|
|
|
53 }
|
|
|
54
|
|
|
55 bool metadb_handle::should_reload(const t_filestats & p_new_stats, bool p_fresh) const
|
|
|
56 {
|
|
|
57 if (!is_info_loaded_async()) return true;
|
|
|
58 else return g_should_reload(get_filestats(),p_new_stats,p_fresh);
|
|
|
59 }
|
|
|
60
|
|
|
61
|
|
|
62 bool metadb_handle::get_browse_info_merged(file_info & infoMerged) const {
|
|
|
63 bool rv = true;
|
|
|
64 metadb_info_container::ptr info, browse;
|
|
|
65 this->get_browse_info_ref(info, browse);
|
|
|
66 if (info.is_valid() && browse.is_valid()) {
|
|
|
67 infoMerged = info->info();
|
|
|
68 infoMerged.merge_fallback( browse->info() );
|
|
|
69 } else if (info.is_valid()) {
|
|
|
70 infoMerged = info->info();
|
|
|
71 } else if (browse.is_valid()) {
|
|
|
72 infoMerged = browse->info();
|
|
|
73 } else {
|
|
|
74 infoMerged.reset();
|
|
|
75 rv = false;
|
|
|
76 }
|
|
|
77 return rv;
|
|
|
78 }
|
|
|
79
|
|
|
80 namespace {
|
|
|
81 class metadb_info_container_impl : public metadb_info_container {
|
|
|
82 public:
|
|
|
83 metadb_info_container_impl() : m_stats( filestats_invalid ), m_partial() {}
|
|
|
84 file_info const & info() {
|
|
|
85 return m_info;
|
|
|
86 }
|
|
|
87 t_filestats const & stats() {
|
|
|
88 return m_stats;
|
|
|
89 }
|
|
|
90 bool isInfoPartial() {
|
|
|
91 return m_partial;
|
|
|
92 }
|
|
|
93
|
|
|
94 file_info_impl m_info;
|
|
|
95 t_filestats m_stats;
|
|
|
96 bool m_partial;
|
|
|
97
|
|
|
98 };
|
|
|
99 }
|
|
|
100
|
|
|
101 metadb_info_container::ptr metadb_handle::get_full_info_ref( abort_callback & aborter ) const {
|
|
|
102 {
|
|
|
103 metadb_info_container::ptr info;
|
|
|
104 if (this->get_info_ref( info ) ) {
|
|
|
105 if (!info->isInfoPartial()) return info;
|
|
|
106 }
|
|
|
107 }
|
|
|
108
|
|
|
109
|
|
|
110 input_info_reader::ptr reader;
|
|
|
111 input_entry::g_open_for_info_read( reader, NULL, this->get_path(), aborter );
|
|
|
112
|
|
|
113 service_ptr_t< metadb_info_container_impl > obj = new service_impl_t<metadb_info_container_impl>();
|
|
|
114 obj->m_stats = reader->get_file_stats( aborter );
|
|
|
115 reader->get_info( this->get_subsong_index(), obj->m_info, aborter );
|
|
|
116 return obj;
|
|
|
117 }
|
|
|
118
|
|
|
119 t_filestats2 metadb_info_container::stats2_() {
|
|
|
120 t_filestats2 ret;
|
|
|
121 metadb_info_container_v2::ptr v2;
|
|
|
122 if (v2 &= this) ret = v2->stats2();
|
|
|
123 else {
|
|
|
124 auto & s = this->stats();
|
|
|
125 ret.m_size = s.m_size;
|
|
|
126 ret.m_timestamp = s.m_timestamp;
|
|
|
127 }
|
|
|
128 return ret;
|
|
|
129 }
|
|
|
130
|
|
|
131 namespace fb2k {
|
|
|
132 pfc::string_formatter formatTrackList( metadb_handle_list_cref lst ) {
|
|
|
133 pfc::string_formatter ret;
|
|
|
134 auto cnt = lst.get_count();
|
|
|
135 if ( cnt == 0 ) ret << "[Empty track list]\n";
|
|
|
136 else {
|
|
|
137 if (cnt == 1) ret << "[Track list: 1 track]\n";
|
|
|
138 else ret << "[Track list: " << cnt << " tracks]\n";
|
|
|
139 for( size_t walk = 0; walk < cnt; ++ walk ) {
|
|
|
140 ret << " " << lst[walk]->get_location() << "\n";
|
|
|
141 }
|
|
|
142 ret << "[Track list end]";
|
|
|
143 }
|
|
|
144 return ret;
|
|
|
145 }
|
|
|
146 pfc::string_formatter formatTrackTitle(metadb_handle_ptr item, const char * script ) {
|
|
|
147 pfc::string_formatter ret;
|
|
|
148 item->format_title_legacy(NULL,ret,script,NULL);
|
|
|
149 return ret;
|
|
|
150 }
|
|
|
151 pfc::string_formatter formatTrackTitle(metadb_handle_ptr item,service_ptr_t<class titleformat_object> script) {
|
|
|
152 pfc::string_formatter ret;
|
|
|
153 item->format_title(NULL,ret,script,NULL);
|
|
|
154 return ret;
|
|
|
155 }
|
|
|
156 }
|
|
|
157
|
|
|
158 t_filestats2 metadb_handle::get_stats2_() const {
|
|
|
159 metadb_handle_v2::ptr v2;
|
|
|
160 if (v2 &= const_cast<metadb_handle*>(this)) return v2->get_stats2();
|
|
|
161 else return t_filestats2::from_legacy(this->get_filestats());
|
|
|
162 }
|
|
|
163
|
|
|
164 metadb_v2_rec_t metadb_handle::query_v2_() {
|
|
|
165 #if FOOBAR2000_TARGET_VERSION >= 81
|
|
|
166 return static_cast<const metadb_handle_v2*>(this)->query_v2();
|
|
|
167 #else
|
|
|
168 metadb_handle_v2::ptr v2;
|
|
|
169 if (v2 &= this) return v2->query_v2();
|
|
|
170
|
|
|
171 metadb_v2_rec_t ret;
|
|
|
172 this->get_browse_info_ref(ret.info, ret.infoBrowse);
|
|
|
173 return ret;
|
|
|
174 #endif
|
|
|
175 }
|
|
|
176
|
|
|
177 void metadb_handle::formatTitle_v2_(const metadb_v2_rec_t& rec, titleformat_hook* p_hook, pfc::string_base& p_out, const service_ptr_t<titleformat_object>& p_script, titleformat_text_filter* p_filter) {
|
|
|
178 #if FOOBAR2000_TARGET_VERSION >= 81
|
|
|
179 static_cast<metadb_handle_v2*>(this)->formatTitle_v2(rec, p_hook, p_out, p_script, p_filter);
|
|
|
180 #else
|
|
|
181 metadb_handle_v2::ptr v2;
|
|
|
182 if (v2 &= this) {
|
|
|
183 v2->formatTitle_v2(rec, p_hook, p_out, p_script, p_filter); return;
|
|
|
184 }
|
|
|
185
|
|
|
186 // closest approximate using old APIs
|
|
|
187 if (rec.info.is_valid()) {
|
|
|
188 this->format_title_from_external_info(rec.info->info(), p_hook, p_out, p_script, p_filter);
|
|
|
189 } else {
|
|
|
190 this->format_title(p_hook, p_out, p_script, p_filter);
|
|
|
191 }
|
|
|
192 #endif
|
|
|
193 } |