OSDN Git Service

Updated Monkey's Audio binary to v4.11 (2013-01-20), including STDERR flush fix.
[lamexp/LameXP.git] / src / Decoder_Wave.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #include "Decoder_Wave.h"
23
24 #include "Global.h"
25
26 #include <QDir>
27 #include <QProcess>
28 #include <QRegExp>
29 #include <Shellapi.h>
30
31 #define FIX_SEPARATORS(STR) for(int i = 0; STR[i]; i++) { if(STR[i] == L'/') STR[i] = L'\\'; }
32
33 WaveDecoder::WaveDecoder(void)
34 {
35 }
36
37 WaveDecoder::~WaveDecoder(void)
38 {
39 }
40
41 bool WaveDecoder::decode(const QString &sourceFile, const QString &outputFile, volatile bool *abortFlag)
42 {
43         emit messageLogged(QString("Copy file \"%1\" to \"%2\"").arg(sourceFile, outputFile));
44         
45         SHFILEOPSTRUCTW fileOperation;
46         memset(&fileOperation, 0, sizeof(SHFILEOPSTRUCTW));
47         fileOperation.wFunc = FO_COPY;
48         fileOperation.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_FILESONLY;
49
50         size_t srcLen = wcslen(reinterpret_cast<const wchar_t*>(sourceFile.utf16())) + 3;
51         wchar_t *srcBuffer = new wchar_t[srcLen];
52         memset(srcBuffer, 0, srcLen * sizeof(wchar_t));
53         wcsncpy_s(srcBuffer, srcLen, reinterpret_cast<const wchar_t*>(sourceFile.utf16()), _TRUNCATE);
54         FIX_SEPARATORS (srcBuffer);
55         fileOperation.pFrom = srcBuffer;
56
57         size_t outLen = wcslen(reinterpret_cast<const wchar_t*>(outputFile.utf16())) + 3;
58         wchar_t *outBuffer = new wchar_t[outLen];
59         memset(outBuffer, 0, outLen * sizeof(wchar_t));
60         wcsncpy_s(outBuffer, outLen, reinterpret_cast<const wchar_t*>(outputFile.utf16()), _TRUNCATE);
61         FIX_SEPARATORS (outBuffer);
62         fileOperation.pTo = outBuffer;
63
64         emit statusUpdated(0);
65         int result = SHFileOperation(&fileOperation);
66         emit statusUpdated(100);
67
68         emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", result));
69
70         delete [] srcBuffer;
71         delete [] outBuffer;
72
73         return (result == 0 && fileOperation.fAnyOperationsAborted == false);
74 }
75
76 bool WaveDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
77 {
78         if(containerType.compare("Wave", Qt::CaseInsensitive) == 0)
79         {
80                 if(formatType.compare("PCM", Qt::CaseInsensitive) == 0)
81                 {
82                         return true;
83                 }
84         }
85
86         return false;
87 }
88
89 QStringList WaveDecoder::supportedTypes(void)
90 {
91         return QStringList() << "Waveform Audio File (*.wav)";
92 }