TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicextractwrapper.cpp
Go to the documentation of this file.
1 #include "musicextractwrapper.h"
3 #include "musicimageutils.h"
4 
5 #include "ttkzip/zip.h"
6 #include "ttkzip/unzip.h"
7 
8 #include <QFile>
9 
10 #define WIN_NAME_MAX_LENGTH TTK_LOW_BUFFER
11 #ifndef FILE_ATTRIBUTE_DIRECTORY
12 #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
13 #endif
14 #ifndef FILE_ATTRIBUTE_ARCHIVE
15 #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
16 #endif
17 
18 bool MusicExtractWrapper::outputThunderSkin(QPixmap &image, const QString &input)
19 {
20  const unzFile &zFile = unzOpen64(qPrintable(input));
21  if(!zFile)
22  {
23  return false;
24  }
25 
26  unz_file_info64 fInfo;
27  unz_global_info64 gInfo;
28  if(unzGetGlobalInfo64(zFile, &gInfo) != UNZ_OK)
29  {
30  unzClose(zFile);
31  return false;
32  }
33 
34  for(ZPOS64_T i = 0; i < gInfo.number_entry; ++i)
35  {
36  char com[TTK_HIGH_BUFFER] = {0};
37  char name[WIN_NAME_MAX_LENGTH] = {0};
38  char ext[WIN_NAME_MAX_LENGTH] = {0};
39 
40  if(unzGetCurrentFileInfo64(zFile, &fInfo, name, sizeof(name), ext, WIN_NAME_MAX_LENGTH, com, TTK_HIGH_BUFFER) != UNZ_OK ||
41  unzOpenCurrentFile(zFile) != UNZ_OK)
42  {
43  break;
44  }
45 
46  int size = 0;
47  char dt[TTK_HIGH_BUFFER] = {0};
48 
49  const QString &module = name;
50  if(module.toLower().contains("image/bkg"))
51  {
52  QByteArray buffer;
53  while(true)
54  {
55  size= unzReadCurrentFile(zFile, dt, sizeof(dt));
56  if(size <= 0)
57  {
58  break;
59  }
60  buffer.append(dt, size);
61  }
62  image.loadFromData(buffer);
63  }
64 
65  unzCloseCurrentFile(zFile);
66 
67  if(i < gInfo.number_entry - 1 && unzGoToNextFile(zFile) != UNZ_OK)
68  {
69  unzClose(zFile);
70  return false;
71  }
72  }
73 
74  unzClose(zFile);
75  return true;
76 }
77 
78 bool MusicExtractWrapper::outputBinary(const QString &input, const QString &output, QStringList &path)
79 {
80  const unzFile &zFile = unzOpen64(qPrintable(input));
81  if(!zFile)
82  {
83  return false;
84  }
85 
86  unz_file_info64 fInfo;
87  unz_global_info64 gInfo;
88  if(unzGetGlobalInfo64(zFile, &gInfo) != UNZ_OK)
89  {
90  unzClose(zFile);
91  return false;
92  }
93 
94  QDir dir;
95  dir.mkpath(output);
96  dir.cd(output);
97 
98  for(ZPOS64_T i = 0; i < gInfo.number_entry; ++i)
99  {
100  char com[TTK_HIGH_BUFFER] = {0};
101  char name[WIN_NAME_MAX_LENGTH] = {0};
102  char ext[WIN_NAME_MAX_LENGTH] = {0};
103 
104  if(unzGetCurrentFileInfo64(zFile, &fInfo, name, sizeof(name), ext, WIN_NAME_MAX_LENGTH, com, TTK_HIGH_BUFFER) != UNZ_OK ||
105  unzOpenCurrentFile(zFile) != UNZ_OK)
106  {
107  break;
108  }
109 
111  {
112  dir.mkpath(QFileInfo(name).path());
113  }
114  else
115  {
116  int size = 0;
117  char dt[TTK_HIGH_BUFFER] = {0};
118 
119  QFile file(output + name);
120  if(file.open(QIODevice::WriteOnly))
121  {
122  while(true)
123  {
124  size= unzReadCurrentFile(zFile, dt, sizeof(dt));
125  if(size <= 0)
126  {
127  break;
128  }
129  file.write(dt, size);
130  }
131 
132  file.close();
133  path << file.fileName();
134  unzCloseCurrentFile(zFile);
135  }
136  }
137 
138  if(i < gInfo.number_entry - 1 && unzGoToNextFile(zFile) != UNZ_OK)
139  {
140  unzClose(zFile);
141  return false;
142  }
143  }
144 
145  unzClose(zFile);
146  return true;
147 }
148 
149 bool MusicExtractWrapper::outputSkin(MusicBackgroundImage *image, const QString &input)
150 {
151  const unzFile &zFile = unzOpen64(qPrintable(input));
152  if(!zFile)
153  {
154  return false;
155  }
156 
157  unz_file_info64 fInfo;
158  unz_global_info64 gInfo;
159  if(unzGetGlobalInfo64(zFile, &gInfo) != UNZ_OK)
160  {
161  unzClose(zFile);
162  return false;
163  }
164 
165  for(ZPOS64_T i = 0; i < gInfo.number_entry; ++i)
166  {
167  char com[TTK_HIGH_BUFFER] = {0};
168  char name[WIN_NAME_MAX_LENGTH] = {0};
169  char ext[WIN_NAME_MAX_LENGTH] = {0};
170 
171  if(unzGetCurrentFileInfo64(zFile, &fInfo, name, sizeof(name), ext, WIN_NAME_MAX_LENGTH, com, TTK_HIGH_BUFFER) != UNZ_OK ||
172  unzOpenCurrentFile(zFile) != UNZ_OK)
173  {
174  break;
175  }
176 
177  int size = 0;
178  char dt[TTK_HIGH_BUFFER] = {0};
179 
180  QByteArray buffer;
181  const QString &module = name;
182  if(module.toLower().contains(SKN_FILE))
183  {
184  while(true)
185  {
186  size= unzReadCurrentFile(zFile, dt, sizeof(dt));
187  if(size <= 0)
188  {
189  break;
190  }
191  buffer.append(dt, size);
192  }
193 
194  QPixmap pix;
195  pix.loadFromData(buffer);
196  image->m_pix = pix;
197  }
198  else if(module.toLower().contains(XML_FILE))
199  {
200  while(true)
201  {
202  size= unzReadCurrentFile(zFile, dt, sizeof(dt));
203  if(size <= 0)
204  {
205  break;
206  }
207  buffer.append(dt, size);
208  }
209 
210  MusicSkinConfigManager manager;
211  if(manager.fromByteArray(buffer))
212  {
213  MusicSkinItem item;
214  manager.readBuffer(item);
215  image->m_item = item;
216  }
217  }
218 
219  unzCloseCurrentFile(zFile);
220 
221  if(i < gInfo.number_entry - 1 && unzGoToNextFile(zFile) != UNZ_OK)
222  {
223  unzClose(zFile);
224  return false;
225  }
226  }
227 
228  unzClose(zFile);
229  return true;
230 }
231 
232 bool MusicExtractWrapper::inputSkin(MusicBackgroundImage *image, const QString &output)
233 {
234  const zipFile &zFile = zipOpen64(qPrintable(output), 0);
235  if(!zFile)
236  {
237  return false;
238  }
239 
240  const int level = 5;
241  const QString &prefix = QFileInfo(output).baseName();
242 
243  zip_fileinfo fInfo;
244  memset(&fInfo, 0, sizeof(fInfo));
246 
247  zipOpenNewFileInZip(zFile, qPrintable(prefix + SKN_FILE), &fInfo, nullptr, 0, nullptr, 0, nullptr, Z_DEFLATED, level);
248  QByteArray data = TTK::Image::generatePixmapData(image->m_pix);
249  zipWriteInFileInZip(zFile, data.constData(), data.length());
250  zipCloseFileInZip(zFile);
251 
252  MusicSkinConfigManager manager;
253  manager.load(TTK_IMAGE_FILE);
254  manager.writeBuffer(image->m_item);
255  data = manager.toByteArray();
256 
257  zipOpenNewFileInZip(zFile, qPrintable(prefix + XML_FILE), &fInfo, nullptr, 0, nullptr, 0, nullptr, Z_DEFLATED, level);
258  zipWriteInFileInZip(zFile, data.constData(), data.length());
259  zipCloseFileInZip(zFile);
260  QFile::remove(TTK_IMAGE_FILE);
261 
262  zipClose(zFile, nullptr);
263  return true;
264 }
265 
266 bool MusicExtractWrapper::outputData(QByteArray &data, const QString &input)
267 {
268  const unzFile &zFile = unzOpen64(qPrintable(input));
269  if(!zFile)
270  {
271  return false;
272  }
273 
274  unz_file_info64 fInfo;
275  unz_global_info64 gInfo;
276  if(unzGetGlobalInfo64(zFile, &gInfo) != UNZ_OK)
277  {
278  unzClose(zFile);
279  return false;
280  }
281 
282  for(ZPOS64_T i = 0; i < gInfo.number_entry; ++i)
283  {
284  char com[TTK_HIGH_BUFFER] = {0};
285  char name[WIN_NAME_MAX_LENGTH] = {0};
286  char ext[WIN_NAME_MAX_LENGTH] = {0};
287 
288  if(unzGetCurrentFileInfo64(zFile, &fInfo, name, sizeof(name), ext, WIN_NAME_MAX_LENGTH, com, TTK_HIGH_BUFFER) != UNZ_OK ||
289  unzOpenCurrentFile(zFile) != UNZ_OK)
290  {
291  break;
292  }
293 
294  int size = 0;
295  char dt[TTK_HIGH_BUFFER] = {0};
296 
297  while(true)
298  {
299  size= unzReadCurrentFile(zFile, dt, sizeof(dt));
300  if(size <= 0)
301  {
302  break;
303  }
304  data.append(dt, size);
305  }
306 
307  unzCloseCurrentFile(zFile);
308 
309  if(i < gInfo.number_entry - 1 && unzGoToNextFile(zFile) != UNZ_OK)
310  {
311  unzClose(zFile);
312  return false;
313  }
314  }
315 
316  unzClose(zFile);
317  return true;
318 }
319 
320 bool MusicExtractWrapper::inputData(const QByteArray &data, const QString &output)
321 {
322  if(data.isEmpty())
323  {
324  TTK_ERROR_STREAM("Input byte data is empty");
325  return false;
326  }
327 
328  const zipFile &zFile = zipOpen64(qPrintable(output), 0);
329  if(!zFile)
330  {
331  return false;
332  }
333 
334  const int level = 5;
335  const QString &prefix = QFileInfo(output).baseName();
336 
337  zip_fileinfo fInfo;
338  memset(&fInfo, 0, sizeof(fInfo));
340 
341  zipOpenNewFileInZip(zFile, qPrintable(prefix), &fInfo, nullptr, 0, nullptr, 0, nullptr, Z_DEFLATED, level);
342  zipWriteInFileInZip(zFile, data.constData(), data.length());
343  zipCloseFileInZip(zFile);
344  zipClose(zFile, nullptr);
345  return true;
346 }
ZEXTERN int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info)
Definition: unzip.c:828
virtual bool readBuffer(MusicSkinItem &items) overridefinal
static bool outputBinary(const QString &input, const QString &output, QStringList &path)
ZEXTERN int ZEXPORT zipCloseFileInZip(zipFile file)
Definition: zip.c:1750
static bool inputData(const QByteArray &data, const QString &output)
voidp unzFile
Definition: unzip.h:70
#define UNZ_OK
Definition: unzip.h:74
ZEXTERN int ZEXPORT unzCloseCurrentFile(unzFile file)
Definition: unzip.c:2004
voidpf void uLong size
Definition: ioapi.h:136
static bool outputThunderSkin(QPixmap &image, const QString &input)
ZEXTERN unzFile ZEXPORT unzOpen64(const void *path)
Definition: unzip.c:798
#define FILE_ATTRIBUTE_DIRECTORY
ZEXTERN int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
Definition: unzip.c:1124
uLong external_fa
Definition: zip.h:106
virtual bool writeBuffer(const MusicSkinItem &items) overridefinal
#define qPrintable(s)
Definition: ttkqtglobal.h:36
#define XML_FILE
Definition: musicobject.h:67
voidp zipFile
Definition: zip.h:69
TTK_MODULE_EXPORT QByteArray generatePixmapData(const QPixmap &input)
The class of the skin backgroud image.
const char * name
Definition: http_parser.c:458
#define TTK_IMAGE_FILE
uLong external_fa
Definition: unzip.h:127
#define Z_DEFLATED
Definition: zlib.h:209
static bool outputData(QByteArray &data, const QString &input)
The class of the skin item.
bool fromByteArray(const QByteArray &data)
ZEXTERN zipFile ZEXPORT zipOpen64(const void *pathname, int append)
Definition: zip.c:953
ZEXTERN int ZEXPORT unzGoToNextFile(unzFile file)
Definition: unzip.c:1199
unsigned long long int ZPOS64_T
Definition: ioapi.h:100
QByteArray toByteArray() const
ZEXTERN int ZEXPORT zipClose(zipFile file, const char *global_comment)
Definition: zip.c:1882
The class of the skin XML config manager.
bool load(const QString &name)
static bool outputSkin(MusicBackgroundImage *image, const QString &input)
#define WIN_NAME_MAX_LENGTH
static bool inputSkin(MusicBackgroundImage *image, const QString &output)
#define TTK_HIGH_BUFFER
Definition: ttkglobal.h:261
ZEXTERN int ZEXPORT zipOpenNewFileInZip(zipFile file, const char *filename, const zip_fileinfo *zipfi, const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, uInt size_extrafield_global, const char *comment, int method, int level)
Definition: zip.c:1350
ZEXTERN int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, unsigned int len)
Definition: zip.c:1402
#define SKN_FILE
Definition: musicobject.h:61
#define TTK_ERROR_STREAM(msg)
Definition: ttklogger.h:69
#define FILE_ATTRIBUTE_ARCHIVE
ZEXTERN int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len)
Addition for GDAL : END.
Definition: unzip.c:1684
ZEXTERN int ZEXPORT unzClose(unzFile file)
Definition: unzip.c:808
ZEXTERN int ZEXPORT unzOpenCurrentFile(unzFile file)
Definition: unzip.c:1641
ZPOS64_T number_entry
Definition: unzip.h:98