OSDN Git Service

Don't check for updates when application is run for the very first time (after instal...
[lamexp/LameXP.git] / src / Encoder_Wave.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2011 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 "Encoder_Wave.h"
23
24 #include "Global.h"
25 #include "Model_Settings.h"
26
27 #include <QDir>
28 #include <Shellapi.h>
29
30 #define max(a,b) (((a) > (b)) ? (a) : (b))
31 #define min(a,b) (((a) < (b)) ? (a) : (b))
32 #define FIX_SEPARATORS(STR) for(int i = 0; STR[i]; i++) { if(STR[i] == L'/') STR[i] = L'\\'; }
33
34 WaveEncoder::WaveEncoder(void)
35 {
36 }
37
38 WaveEncoder::~WaveEncoder(void)
39 {
40 }
41
42 bool WaveEncoder::encode(const QString &sourceFile, const AudioFileModel &metaInfo, const QString &outputFile, volatile bool *abortFlag)
43 {
44         SHFILEOPSTRUCTW fileOperation;
45         memset(&fileOperation, 0, sizeof(SHFILEOPSTRUCTW));
46         fileOperation.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_FILESONLY;
47
48         emit messageLogged(QString("Copy file \"%1\" to \"%2\"").arg(sourceFile, outputFile));
49         fileOperation.wFunc = FO_COPY;
50
51         /*
52         if(lamexp_temp_folder().compare(QFileInfo(sourceFile).canonicalPath(), Qt::CaseInsensitive) == 0)
53         {
54                 //If the source is in the TEMP folder take shortcut and move the file
55                 emit messageLogged(QString("Moving file \"%1\" to \"%2\"").arg(sourceFile, outputFile));
56                 fileOperation.wFunc = FO_MOVE;
57         }
58         else
59         {
60                 //...otherwise we actually copy the file in order to keep the source
61                 emit messageLogged(QString("Copy file \"%1\" to \"%2\"").arg(sourceFile, outputFile));
62                 fileOperation.wFunc = FO_COPY;
63         }
64         */
65         
66         size_t srcLen = wcslen(reinterpret_cast<const wchar_t*>(sourceFile.utf16())) + 3;
67         wchar_t *srcBuffer = new wchar_t[srcLen];
68         memset(srcBuffer, 0, srcLen * sizeof(wchar_t));
69         wcsncpy_s(srcBuffer, srcLen, reinterpret_cast<const wchar_t*>(sourceFile.utf16()), _TRUNCATE);
70         FIX_SEPARATORS (srcBuffer);
71         fileOperation.pFrom = srcBuffer;
72
73         size_t outLen = wcslen(reinterpret_cast<const wchar_t*>(outputFile.utf16())) + 3;
74         wchar_t *outBuffer = new wchar_t[outLen];
75         memset(outBuffer, 0, outLen * sizeof(wchar_t));
76         wcsncpy_s(outBuffer, outLen, reinterpret_cast<const wchar_t*>(outputFile.utf16()), _TRUNCATE);
77         FIX_SEPARATORS (outBuffer);
78         fileOperation.pTo = outBuffer;
79
80         emit statusUpdated(0);
81         int result = SHFileOperation(&fileOperation);
82         emit statusUpdated(100);
83
84         emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", result));
85
86         delete [] srcBuffer;
87         delete [] outBuffer;
88
89         return (result == 0 && fileOperation.fAnyOperationsAborted == false);
90 }
91
92 QString WaveEncoder::extension(void)
93 {
94         return "wav";
95 }
96
97 bool WaveEncoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
98 {
99         if(containerType.compare("Wave", Qt::CaseInsensitive) == 0)
100         {
101                 if(formatType.compare("PCM", Qt::CaseInsensitive) == 0)
102                 {
103                         return true;
104                 }
105         }
106         return false;
107 }