OSDN Git Service

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