TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicdbplconfigmanager.cpp
Go to the documentation of this file.
2 
3 static constexpr int PLAYLIST_MAJOR_VER = 1;
4 static constexpr int PLAYLIST_MINOR_VER = 1;
5 
9 {
10 
11 }
12 
13 bool MusicDBPLConfigManager::readBuffer(MusicSongItemList &items)
14 {
15  const QFileInfo fin(m_file.fileName());
16  MusicSongItem item;
17  item.m_itemName = fin.baseName();
18 
19  // read 4-byte signature
20  char magic[5] = {0};
21  m_file.read(magic, 4);
22  if(strncmp(magic, "DBPL", 4))
23  {
24  return false;
25  }
26 
27  TTKUInt8 majorver = 0;
28  m_file.read((char*)&majorver, 1);
29  if(majorver != PLAYLIST_MAJOR_VER)
30  {
31  return false;
32  }
33 
34  TTKUInt8 minorver = 0;
35  m_file.read((char*)&minorver, 1);
36  if(minorver < PLAYLIST_MINOR_VER)
37  {
38  return false;
39  }
40 
41  TTKUInt32 cnt = 0;
42  m_file.read((char*)&cnt, 4);
43  for(TTKUInt32 i = 0; i < cnt; ++i)
44  {
45  TTKUInt32 v = 0;
46  QString filePath;
47 
48  if(minorver <= 2)
49  {
50  // fname
51  if(m_file.read((char*)&v, 2) != 2)
52  {
53  return false;
54  }
55 
56  char uri[v + 1];
57  memset(uri, 0, sizeof(char) * (v + 1));
58 
59  if(m_file.read(uri, v) != v)
60  {
61  return false;
62  }
63 
64  filePath = uri;
65  // decoder
66  if(m_file.read((char*)&v, 1) != 1)
67  {
68  return false;
69  }
70 
71  if(v >= 20)
72  {
73  return false;
74  }
75 
76  char decoder[20] = {0};
77  if(v && m_file.read((char*)&decoder, v) != v)
78  {
79  return false;
80  }
81  // tracknum
82  if(m_file.read((char*)&v, 2) != 2)
83  {
84  return false;
85  }
86  }
87 
88  if(m_file.read((char*)&v, 4) != 4)
89  {
90  return false;
91  }
92 
93  if(m_file.read((char*)&v, 4) != 4)
94  {
95  return false;
96  }
97 
98  float duration = 0;
99  if(m_file.read((char*)&duration, 4) != 4)
100  {
101  return false;
102  }
103 
104  item.m_songs << MusicSong(filePath, TTKTime::formatDuration((int)duration * TTK_DN_S2MS));
105  if(minorver <= 2)
106  {
107  // legacy filetype support
108  if(m_file.read((char*)&v, 1) != 1)
109  {
110  return false;
111  }
112 
113  if(v)
114  {
115  char ftype[v + 1];
116  memset(ftype, 0, sizeof(char) * (v + 1));
117 
118  if(m_file.read(ftype, v) != v)
119  {
120  return false;
121  }
122  }
123 
124  if(m_file.read((char*)&v, 4) != 4)
125  {
126  return false;
127  }
128 
129  if(m_file.read((char*)&v, 4) != 4)
130  {
131  return false;
132  }
133 
134  if(m_file.read((char*)&v, 4) != 4)
135  {
136  return false;
137  }
138 
139  if(m_file.read((char*)&v, 4) != 4)
140  {
141  return false;
142  }
143  }
144 
145  if(minorver >= 2 && m_file.read((char*)&v, 4) != 4)
146  {
147  return false;
148  }
149 
150  TTKUInt16 nm = 0;
151  if(m_file.read((char*)&nm, 2) != 2)
152  {
153  return false;
154  }
155 
156  for(int j = 0; j < nm; j++)
157  {
158  if(m_file.read((char*)&v, 2) != 2)
159  {
160  return false;
161  }
162 
163  if(v >= 20000)
164  {
165  return false;
166  }
167 
168  char key[v + 1];
169  memset(key, 0, sizeof(char) * (v + 1));
170 
171  if(m_file.read(key, v) != v)
172  {
173  return false;
174  }
175 
176  if(m_file.read((char*)&v, 2) != 2)
177  {
178  return false;
179  }
180 
181  if(v >= 20000)
182  {
183  continue;
184  }
185 
186  char value[v + 1];
187  memset(value, 0, sizeof(char) * (v + 1));
188 
189  if(m_file.read((char*)&value, v) != v)
190  {
191  return false;
192  }
193  }
194  }
195 
196  if(!item.m_songs.isEmpty())
197  {
198  items << item;
199  }
200  return true;
201 }
202 
203 bool MusicDBPLConfigManager::writeBuffer(const MusicSongItemList &items)
204 {
205  Q_UNUSED(items);
206  return false;
207 }
static constexpr wchar_t key[]
static constexpr int PLAYLIST_MAJOR_VER
unsigned char TTKUInt8
Definition: ttkglobal.h:107
virtual bool writeBuffer(const MusicSongItemList &items) overridefinal
unsigned int TTKUInt32
Definition: ttkglobal.h:111
unsigned short TTKUInt16
Definition: ttkglobal.h:109
virtual bool readBuffer(MusicSongItemList &items) overridefinal
The class of the read write interface.
#define TTK_DN_S2MS
Definition: ttkglobal.h:276
The class of the music song item.
Definition: musicsong.h:161
QString m_itemName
Definition: musicsong.h:164
static constexpr int PLAYLIST_MINOR_VER
The class of the music song info.
Definition: musicsong.h:28
The class of the ttk file interface.
static qint64 formatDuration(const QString &time) noexcept
Definition: ttktime.cpp:123