WaveEncoder: Use MUtils::OS::copy_file() function instead of SHFileOperation(). Gives actual progress and is less clunky to use.

This commit is contained in:
LoRd_MuldeR 2016-04-07 21:01:21 +02:00
parent ce37f51a3d
commit b6b0413e86
5 changed files with 43 additions and 47 deletions

View File

@ -84,6 +84,7 @@
<h1 id="lamexp-v4.xx-history"><span class="header-section-number">1</span> LameXP v4.xx History</h1>
<h2 id="lamexp-v4.14-2016--" class="unnumbered">LameXP v4.14 [2016-??-??]</h2>
<ul>
<li>Upgraded build environment to Microsoft Visual Studio 2015 with Update-2</li>
<li>Fixed the location of temporary intermediate files for SoX-based audio effects</li>
<li>Enabled the &quot;built-in&quot; resampler for QAAC encoder</li>
<li>The &quot;Algorithm Quality&quot; slider now also affects the QAAC encoder</li>

View File

@ -4,6 +4,7 @@
## LameXP v4.14 [2016-??-??] ## {-}
* Upgraded build environment to Microsoft Visual Studio 2015 with Update-2
* Fixed the location of temporary intermediate files for SoX-based audio effects
* Enabled the "built-in" resampler for QAAC encoder
* The "Algorithm Quality" slider now also affects the QAAC encoder

View File

@ -34,8 +34,8 @@
#define VER_LAMEXP_MINOR_HI 1
#define VER_LAMEXP_MINOR_LO 4
#define VER_LAMEXP_TYPE Alpha
#define VER_LAMEXP_PATCH 7
#define VER_LAMEXP_BUILD 1876
#define VER_LAMEXP_PATCH 8
#define VER_LAMEXP_BUILD 1878
#define VER_LAMEXP_CONFG 1818
///////////////////////////////////////////////////////////////////////////////

View File

@ -22,18 +22,18 @@
#include "Encoder_Wave.h"
#include <MUtils/Global.h>
#include <MUtils/OSSupport.h>
#include "Global.h"
#include "Model_Settings.h"
#include <QDir>
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <Shellapi.h>
#define FIX_SEPARATORS(STR) for(int i = 0; STR[i]; i++) { if(STR[i] == L'/') STR[i] = L'\\'; }
typedef struct _callback_t
{
WaveEncoder *pInstance;
volatile bool *abortFlag;
}
callback_t;
///////////////////////////////////////////////////////////////////////////////
// Encoder Info
@ -134,52 +134,42 @@ WaveEncoder::~WaveEncoder(void)
bool WaveEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo &metaInfo, const unsigned int duration, const QString &outputFile, volatile bool *abortFlag)
{
SHFILEOPSTRUCTW fileOperation;
memset(&fileOperation, 0, sizeof(SHFILEOPSTRUCTW));
fileOperation.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_FILESONLY;
emit messageLogged(QString("Copy file \"%1\" to \"%2\"\n").arg(sourceFile, outputFile));
emit messageLogged(QString("Copy file \"%1\" to \"%2\"").arg(sourceFile, outputFile));
fileOperation.wFunc = FO_COPY;
callback_t callbackData;
callbackData.abortFlag = abortFlag;
callbackData.pInstance = this;
/*
if(lamexp_temp_folder().compare(QFileInfo(sourceFile).canonicalPath(), Qt::CaseInsensitive) == 0)
emit statusUpdated(0);
const bool success = MUtils::OS::copy_file(sourceFile, outputFile, true, progressCallback, &callbackData);
emit statusUpdated(100);
if (success)
{
//If the source is in the TEMP folder take shortcut and move the file
emit messageLogged(QString("Moving file \"%1\" to \"%2\"").arg(sourceFile, outputFile));
fileOperation.wFunc = FO_MOVE;
emit messageLogged(QLatin1String("File copied successfully."));
}
else
{
//...otherwise we actually copy the file in order to keep the source
emit messageLogged(QString("Copy file \"%1\" to \"%2\"").arg(sourceFile, outputFile));
fileOperation.wFunc = FO_COPY;
emit messageLogged((*abortFlag) ? QLatin1String("Operation cancelled by user!") : QLatin1String("Error: Failed to copy file!"));
}
*/
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;
return success;
}
emit statusUpdated(0);
int result = SHFileOperation(&fileOperation);
emit statusUpdated(100);
bool WaveEncoder::progressCallback(const double &progress, void *const userData)
{
const callback_t *const ptr = reinterpret_cast<callback_t*>(userData);
if (*(ptr->abortFlag))
{
return false; /*user aborted*/
}
ptr->pInstance->updateProgress(progress);
return true;
}
emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", result));
delete [] srcBuffer;
delete [] outBuffer;
return (result == 0 && fileOperation.fAnyOperationsAborted == false);
void WaveEncoder::updateProgress(const double &progress)
{
emit statusUpdated(qRound(progress * 100.0));
}
bool WaveEncoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)

View File

@ -40,4 +40,8 @@ public:
//Encoder info
virtual const AbstractEncoderInfo *toEncoderInfo(void) const { return getEncoderInfo(); }
static const AbstractEncoderInfo *getEncoderInfo(void);
private:
static bool progressCallback(const double &progress, void *const userData);
void updateProgress(const double &progress);
};