///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2016 LoRd_MuldeR <MuldeR2@GMX.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// http://www.gnu.org/licenses/gpl-2.0.txt
///////////////////////////////////////////////////////////////////////////////
+//Internal
#include "Decoder_Wave.h"
-
#include "Global.h"
-#include <QDir>
-#include <QProcess>
-#include <QRegExp>
+//MUtils
+#include <MUtils/OSSupport.h>
-//Windows includes
-#define NOMINMAX
-#define WIN32_LEAN_AND_MEAN
-#include <Windows.h>
-#include <Shellapi.h>
+//Qt
+#include <QDir>
-#define FIX_SEPARATORS(STR) for(int i = 0; STR[i]; i++) { if(STR[i] == L'/') STR[i] = L'\\'; }
+//Type
+typedef struct _ProgressData
+{
+ WaveDecoder *const instance;
+ volatile bool *const abrtFlag;
+}
+ProgressData;
WaveDecoder::WaveDecoder(void)
{
bool WaveDecoder::decode(const QString &sourceFile, const QString &outputFile, volatile bool *abortFlag)
{
- emit messageLogged(QString("Copy file \"%1\" to \"%2\"").arg(sourceFile, outputFile));
-
- SHFILEOPSTRUCTW fileOperation;
- memset(&fileOperation, 0, sizeof(SHFILEOPSTRUCTW));
- fileOperation.wFunc = FO_COPY;
- fileOperation.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_FILESONLY;
-
- size_t srcLen = wcslen(reinterpret_cast<const wchar_t*>(sourceFile.utf16())) + 3;
- wchar_t *srcBuffer = new wchar_t[srcLen];
- memset(srcBuffer, 0, srcLen * sizeof(wchar_t));
- wcsncpy_s(srcBuffer, srcLen, reinterpret_cast<const wchar_t*>(sourceFile.utf16()), _TRUNCATE);
- FIX_SEPARATORS (srcBuffer);
- fileOperation.pFrom = srcBuffer;
-
- size_t outLen = wcslen(reinterpret_cast<const wchar_t*>(outputFile.utf16())) + 3;
- wchar_t *outBuffer = new wchar_t[outLen];
- memset(outBuffer, 0, outLen * sizeof(wchar_t));
- wcsncpy_s(outBuffer, outLen, reinterpret_cast<const wchar_t*>(outputFile.utf16()), _TRUNCATE);
- FIX_SEPARATORS (outBuffer);
- fileOperation.pTo = outBuffer;
-
+ emit messageLogged(QString("Copy file \"%1\" to \"%2\"").arg(QDir::toNativeSeparators(sourceFile), QDir::toNativeSeparators(outputFile)));
emit statusUpdated(0);
- int result = SHFileOperation(&fileOperation);
+
+ ProgressData progressData = { this, abortFlag };
+ const bool okay = MUtils::OS::copy_file(sourceFile, outputFile, true, progressHandler, &progressData);
+
emit statusUpdated(100);
- emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", result));
+ if(okay)
+ {
+ emit messageLogged("File copied successfully.");
+ }
+ else
+ {
+ emit messageLogged("Failed to copy file!");
+ }
+
+ return okay;
+}
- delete [] srcBuffer;
- delete [] outBuffer;
+bool WaveDecoder::progressHandler(const double &progress, void *const data)
+{
+ if(data)
+ {
+ //qWarning("Copy progress: %.2f", progress);
+ reinterpret_cast<ProgressData*>(data)->instance->updateProgress(progress);
+ return (!(*reinterpret_cast<ProgressData*>(data)->abrtFlag));
+ }
+ return true;
+}
- return (result == 0 && fileOperation.fAnyOperationsAborted == false);
+void WaveDecoder::updateProgress(const double &progress)
+{
+ emit statusUpdated(qBound(0, qRound(progress * 100.0), 100));
}
bool WaveDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
return false;
}
-QStringList WaveDecoder::supportedTypes(void)
+const AbstractDecoder::supportedType_t *WaveDecoder::supportedTypes(void)
{
- return QStringList() << "Waveform Audio File (*.wav)";
+ static const char *exts[] =
+ {
+ "wav", NULL
+ };
+
+ static const supportedType_t s_supportedTypes[] =
+ {
+ { "Waveform Audio File", exts },
+ { NULL, NULL }
+ };
+
+ return s_supportedTypes;
}