-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPETag.cpp
More file actions
71 lines (53 loc) · 1.86 KB
/
APETag.cpp
File metadata and controls
71 lines (53 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Version 3, 29 June 2007
//
// Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
//
// Everyone is permitted to copy and distribute verbatim copies of this license
// document, but changing it is not allowed.
//
// This version of the GNU Lesser General Public License incorporates the terms
// and conditions of version 3 of the GNU General Public License, supplemented
// by the additional permissions listed below.
#include "stdafx.h"
#include "APETag.h"
CAPETag* CAPETag::FindTag(CMPAStream* stream, bool is_appended,
unsigned begin_offset, unsigned end_offset) {
assert(stream);
unsigned offset;
if (!is_appended) {
// stands at the beginning of file (complete header is 32 bytes)
offset = begin_offset;
} else {
// stands at the end of the file (complete footer is 32 bytes)
offset = end_offset - 32U;
}
const unsigned char* buffer{stream->ReadBytes(8U, offset, false)};
// APEv2 only.
if (memcmp("APETAGEX", buffer, 8U) == 0)
return new CAPETag{stream, is_appended, offset};
return nullptr;
}
CAPETag::CAPETag(CMPAStream* stream, bool is_appended, unsigned offset)
: CTag{stream, _T("APE"), is_appended, offset} {
// skip APETAGEX
offset += 8U;
const unsigned version{stream->ReadLEValue(4U, offset)};
// first byte is version number
m_fVersion = version / 1000.0f;
// get size
m_dwSize = stream->ReadLEValue(4, offset);
m_dwNumItems = stream->ReadLEValue(4U, offset);
// only valid for version 2
const unsigned flag{stream->ReadLEValue(4U, offset)};
bool is_header, is_footer;
if (m_fVersion > 1.0f) {
is_header = flag >> 31U & 0x1U;
is_footer = flag >> 30U & 0x1U;
} else {
is_header = false;
is_footer = true;
}
if (is_header) m_dwSize += 32U; // add header
if (is_appended || is_footer) m_dwOffset -= (m_dwSize - 32);
}
CAPETag::~CAPETag() {}