2010-11-06 23:04:47 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// LameXP - Audio Encoder Front-End
|
2022-06-19 13:50:46 +02:00
|
|
|
// Copyright (C) 2004-2022 LoRd_MuldeR <MuldeR2@GMX.de>
|
2010-11-06 23:04:47 +01:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
2020-03-28 15:31:01 +01:00
|
|
|
// it under the terms of the GNU GENERAL PUBLIC LICENSE as published by
|
2010-11-06 23:04:47 +01:00
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
2020-03-28 15:31:01 +01:00
|
|
|
// (at your option) any later version; always including the non-optional
|
|
|
|
// LAMEXP GNU GENERAL PUBLIC LICENSE ADDENDUM. See "License.txt" file!
|
2010-11-06 23:04:47 +01:00
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
//
|
|
|
|
// http://www.gnu.org/licenses/gpl-2.0.txt
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "LockedFile.h"
|
2015-08-30 13:47:08 +02:00
|
|
|
|
|
|
|
//Internal
|
2010-11-06 23:04:47 +01:00
|
|
|
#include "Global.h"
|
2015-08-30 13:47:08 +02:00
|
|
|
#include "FileHash.h"
|
2010-11-06 23:04:47 +01:00
|
|
|
|
2014-11-24 19:33:12 +01:00
|
|
|
//MUtils
|
2014-11-30 21:32:23 +01:00
|
|
|
#include <MUtils/OSSupport.h>
|
|
|
|
#include <MUtils/Exception.h>
|
2014-11-24 19:33:12 +01:00
|
|
|
|
|
|
|
//Qt
|
2010-11-06 23:04:47 +01:00
|
|
|
#include <QResource>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QCryptographicHash>
|
|
|
|
|
2015-08-30 13:47:08 +02:00
|
|
|
//CRT
|
2011-06-26 19:21:00 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <io.h>
|
|
|
|
#include <fcntl.h>
|
2013-10-18 20:49:22 +02:00
|
|
|
#include <stdexcept>
|
2011-06-26 19:21:00 +02:00
|
|
|
|
2013-10-06 19:28:12 +02:00
|
|
|
//Windows includes
|
|
|
|
#define NOMINMAX
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <Windows.h>
|
|
|
|
|
2017-04-16 23:59:11 +02:00
|
|
|
//Const
|
|
|
|
static const quint32 MAX_LOCK_DELAY = 16384U;
|
|
|
|
|
2011-06-26 19:21:00 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// WARNING: Passing file descriptors into Qt does NOT work with dynamically linked CRT!
|
|
|
|
#ifdef QT_NODLL
|
2013-11-02 01:06:15 +01:00
|
|
|
static const bool g_useFileDescrForQFile = true;
|
2011-06-26 19:21:00 +02:00
|
|
|
#else
|
2013-11-02 01:06:15 +01:00
|
|
|
static const bool g_useFileDescrForQFile = false;
|
2011-06-26 19:21:00 +02:00
|
|
|
#endif
|
|
|
|
|
2015-04-01 21:11:09 +02:00
|
|
|
#define VALID_HANDLE(H) (((H) != NULL) && ((H) != INVALID_HANDLE_VALUE))
|
|
|
|
|
2017-04-16 23:59:11 +02:00
|
|
|
static __forceinline quint32 NEXT_DELAY(const quint32 delay)
|
|
|
|
{
|
|
|
|
return (delay > 0U) ? (delay * 2U) : 1U;
|
|
|
|
}
|
|
|
|
|
2015-11-26 23:15:31 +01:00
|
|
|
static bool PROTECT_HANDLE(const HANDLE &h, const bool &lock)
|
|
|
|
{
|
|
|
|
if (SetHandleInformation(h, HANDLE_FLAG_PROTECT_FROM_CLOSE, (lock ? HANDLE_FLAG_PROTECT_FROM_CLOSE : 0U)))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-30 21:32:23 +01:00
|
|
|
static void CLOSE_HANDLE(HANDLE &h)
|
|
|
|
{
|
2015-04-01 21:11:09 +02:00
|
|
|
if(VALID_HANDLE(h))
|
2014-11-30 21:32:23 +01:00
|
|
|
{
|
2015-11-26 23:15:31 +01:00
|
|
|
PROTECT_HANDLE(h, false);
|
2014-11-30 21:32:23 +01:00
|
|
|
CloseHandle(h);
|
|
|
|
}
|
2015-11-26 23:15:31 +01:00
|
|
|
h = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CLOSE_FILE(int &fd)
|
|
|
|
{
|
|
|
|
if (fd >= 0)
|
|
|
|
{
|
|
|
|
PROTECT_HANDLE((HANDLE)_get_osfhandle(fd), false);
|
|
|
|
_close(fd);
|
|
|
|
}
|
|
|
|
fd = -1;
|
2014-11-30 21:32:23 +01:00
|
|
|
}
|
|
|
|
|
2011-06-26 19:21:00 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-30 13:47:08 +02:00
|
|
|
static __forceinline void doWriteOutput(QFile &outFile, const QResource *const resource)
|
2011-07-02 16:38:46 +02:00
|
|
|
{
|
2017-04-16 23:59:11 +02:00
|
|
|
for (quint32 delay = 0U; delay <= MAX_LOCK_DELAY; delay = NEXT_DELAY(delay))
|
2011-07-02 16:38:46 +02:00
|
|
|
{
|
2017-04-16 23:59:11 +02:00
|
|
|
if (delay > 0U)
|
2011-07-02 16:38:46 +02:00
|
|
|
{
|
2017-04-16 23:59:11 +02:00
|
|
|
if (delay <= 1U)
|
|
|
|
{
|
|
|
|
qWarning("Failed to open file on first attempt, retrying...");
|
|
|
|
}
|
|
|
|
MUtils::OS::sleep_ms(delay);
|
2011-07-02 16:38:46 +02:00
|
|
|
}
|
2017-04-16 23:59:11 +02:00
|
|
|
if(outFile.open(QIODevice::WriteOnly))
|
2015-08-30 13:47:08 +02:00
|
|
|
{
|
2017-04-16 23:59:11 +02:00
|
|
|
break; /*file opened successfully*/
|
2015-08-30 13:47:08 +02:00
|
|
|
}
|
2011-06-23 16:50:02 +02:00
|
|
|
}
|
2010-11-06 23:04:47 +01:00
|
|
|
|
|
|
|
//Write data to file
|
2011-06-23 16:50:02 +02:00
|
|
|
if(outFile.isOpen() && outFile.isWritable())
|
2010-11-06 23:04:47 +01:00
|
|
|
{
|
2013-10-18 20:49:22 +02:00
|
|
|
if(outFile.write(reinterpret_cast<const char*>(resource->data()), resource->size()) != resource->size())
|
2010-11-06 23:04:47 +01:00
|
|
|
{
|
2010-11-15 22:07:46 +01:00
|
|
|
QFile::remove(QFileInfo(outFile).canonicalFilePath());
|
2014-11-30 21:32:23 +01:00
|
|
|
MUTILS_THROW_FMT("File '%s' could not be written!", MUTILS_UTF8(QFileInfo(outFile).fileName()));
|
2010-11-06 23:04:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-30 21:32:23 +01:00
|
|
|
MUTILS_THROW_FMT("File '%s' could not be created!", MUTILS_UTF8(QFileInfo(outFile).fileName()));
|
2010-11-06 23:04:47 +01:00
|
|
|
}
|
|
|
|
|
2013-11-01 19:32:47 +01:00
|
|
|
//Close file after it has been written
|
|
|
|
outFile.close();
|
2015-08-30 13:47:08 +02:00
|
|
|
}
|
2013-11-01 19:32:47 +01:00
|
|
|
|
2015-08-30 13:47:08 +02:00
|
|
|
static __forceinline void doValidateFileExists(const QString &filePath)
|
|
|
|
{
|
|
|
|
QFileInfo existingFileInfo(filePath);
|
|
|
|
existingFileInfo.setCaching(false);
|
|
|
|
|
|
|
|
//Make sure the file exists, before we try to lock it
|
|
|
|
if((!existingFileInfo.exists()) || (!existingFileInfo.isFile()) || filePath.isEmpty())
|
|
|
|
{
|
|
|
|
MUTILS_THROW_FMT("File '%s' does not exist!", MUTILS_UTF8(filePath));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static __forceinline void doLockFile(HANDLE &fileHandle, const QString &filePath, QFile *const outFile)
|
|
|
|
{
|
2015-11-22 17:36:54 +01:00
|
|
|
bool success = false;
|
|
|
|
fileHandle = INVALID_HANDLE_VALUE;
|
|
|
|
|
|
|
|
//Try to open the file!
|
2017-04-16 23:59:11 +02:00
|
|
|
for(quint32 delay = 0U; delay <= MAX_LOCK_DELAY; delay = NEXT_DELAY(delay))
|
2011-06-21 14:35:46 +02:00
|
|
|
{
|
2017-04-16 23:59:11 +02:00
|
|
|
if (delay > 0U)
|
|
|
|
{
|
|
|
|
if (delay <= 1U)
|
|
|
|
{
|
|
|
|
qWarning("Failed to open file on first attempt, retrying...");
|
|
|
|
}
|
|
|
|
MUtils::OS::sleep_ms(delay);
|
|
|
|
}
|
2015-11-22 17:36:54 +01:00
|
|
|
const HANDLE hTemp = CreateFileW(MUTILS_WCHR(QDir::toNativeSeparators(filePath)), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
|
|
|
|
if(VALID_HANDLE(hTemp))
|
2015-08-30 13:47:08 +02:00
|
|
|
{
|
2015-11-26 23:15:31 +01:00
|
|
|
PROTECT_HANDLE(fileHandle = hTemp, true);
|
2015-11-22 17:36:54 +01:00
|
|
|
break; /*file opened successfully*/
|
2015-08-30 13:47:08 +02:00
|
|
|
}
|
2011-06-21 14:35:46 +02:00
|
|
|
}
|
2011-06-21 16:23:42 +02:00
|
|
|
|
2015-11-22 17:36:54 +01:00
|
|
|
//Now try to actually lock the file!
|
|
|
|
if (VALID_HANDLE(fileHandle))
|
|
|
|
{
|
2017-04-16 23:59:11 +02:00
|
|
|
for (quint32 delay = 0U; delay <= MAX_LOCK_DELAY; delay = NEXT_DELAY(delay))
|
2015-11-22 17:36:54 +01:00
|
|
|
{
|
|
|
|
LARGE_INTEGER fileSize;
|
2017-04-16 23:59:11 +02:00
|
|
|
if (delay > 0U)
|
|
|
|
{
|
|
|
|
if (delay <= 1U)
|
|
|
|
{
|
|
|
|
qWarning("Failed to lock file on first attempt, retrying...");
|
|
|
|
}
|
|
|
|
MUtils::OS::sleep_ms(delay);
|
|
|
|
}
|
2015-11-22 17:36:54 +01:00
|
|
|
if (GetFileSizeEx(fileHandle, &fileSize))
|
|
|
|
{
|
|
|
|
OVERLAPPED overlapped = { 0U, 0U, 0U, 0U, 0U };
|
|
|
|
if (LockFileEx(fileHandle, LOCKFILE_FAIL_IMMEDIATELY, 0, fileSize.LowPart, fileSize.HighPart, &overlapped))
|
|
|
|
{
|
|
|
|
success = true;
|
|
|
|
break; /*file locked successfully*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-21 16:23:42 +02:00
|
|
|
//Locked successfully?
|
2015-11-22 17:36:54 +01:00
|
|
|
if(!success)
|
2010-11-06 23:04:47 +01:00
|
|
|
{
|
2015-11-22 17:36:54 +01:00
|
|
|
CLOSE_HANDLE(fileHandle);
|
2015-08-30 13:47:08 +02:00
|
|
|
if(outFile)
|
|
|
|
{
|
|
|
|
QFile::remove(QFileInfo(*outFile).canonicalFilePath());
|
|
|
|
}
|
|
|
|
MUTILS_THROW_FMT("File '%s' could not be locked!", MUTILS_UTF8(QFileInfo(filePath).fileName()));
|
2010-11-06 23:04:47 +01:00
|
|
|
}
|
2015-08-30 13:47:08 +02:00
|
|
|
}
|
2010-11-06 23:04:47 +01:00
|
|
|
|
2015-08-30 13:47:08 +02:00
|
|
|
static __forceinline void doInitFileDescriptor(const HANDLE &fileHandle, int &fileDescriptor)
|
|
|
|
{
|
|
|
|
fileDescriptor = _open_osfhandle(reinterpret_cast<intptr_t>(fileHandle), _O_RDONLY | _O_BINARY);
|
|
|
|
if(fileDescriptor < 0)
|
2011-06-26 19:21:00 +02:00
|
|
|
{
|
2014-11-30 21:32:23 +01:00
|
|
|
MUTILS_THROW_FMT("Failed to obtain C Runtime file descriptor!");
|
2011-06-26 19:21:00 +02:00
|
|
|
}
|
2015-08-30 13:47:08 +02:00
|
|
|
}
|
2013-11-01 19:32:47 +01:00
|
|
|
|
2015-08-30 13:47:08 +02:00
|
|
|
static __forceinline void doValidateHash(HANDLE &fileHandle, const int &fileDescriptor, const QByteArray &expectedHash, const QString &filePath)
|
|
|
|
{
|
2013-11-01 19:32:47 +01:00
|
|
|
QFile checkFile;
|
|
|
|
|
|
|
|
//Now re-open the file for reading
|
2013-11-02 01:06:15 +01:00
|
|
|
if(g_useFileDescrForQFile)
|
2011-06-26 19:21:00 +02:00
|
|
|
{
|
2015-08-30 13:47:08 +02:00
|
|
|
checkFile.open(fileDescriptor, QIODevice::ReadOnly);
|
2013-11-02 01:06:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-30 13:47:08 +02:00
|
|
|
checkFile.setFileName(filePath);
|
2017-04-16 23:59:11 +02:00
|
|
|
for (quint32 delay = 0U; delay <= MAX_LOCK_DELAY; delay = NEXT_DELAY(delay))
|
2011-06-26 19:21:00 +02:00
|
|
|
{
|
2017-04-16 23:59:11 +02:00
|
|
|
if (delay > 0U)
|
|
|
|
{
|
|
|
|
if (delay <= 1U)
|
|
|
|
{
|
|
|
|
qWarning("Failed to open file on first attempt, retrying...");
|
|
|
|
}
|
|
|
|
MUtils::OS::sleep_ms(delay);
|
|
|
|
}
|
|
|
|
if (checkFile.open(QIODevice::ReadOnly))
|
|
|
|
{
|
|
|
|
break; /*file locked successfully*/
|
|
|
|
}
|
2011-06-26 19:21:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-01 19:32:47 +01:00
|
|
|
//Opened successfully
|
2015-11-22 17:36:54 +01:00
|
|
|
if((!checkFile.isOpen()) || checkFile.peek(1).isEmpty())
|
2011-06-21 14:35:46 +02:00
|
|
|
{
|
2015-08-30 13:47:08 +02:00
|
|
|
QFile::remove(filePath);
|
|
|
|
MUTILS_THROW_FMT("File '%s' could not be read!", MUTILS_UTF8(QFileInfo(filePath).fileName()));
|
2011-06-21 14:35:46 +02:00
|
|
|
}
|
2010-11-06 23:04:47 +01:00
|
|
|
|
2013-11-01 19:32:47 +01:00
|
|
|
//Verify file contents
|
2015-08-30 13:47:08 +02:00
|
|
|
const QByteArray hash = FileHash::computeHash(checkFile);
|
2013-11-01 19:32:47 +01:00
|
|
|
checkFile.close();
|
|
|
|
|
2011-02-23 02:19:50 +01:00
|
|
|
//Compare hashes
|
2011-07-02 16:38:46 +02:00
|
|
|
if(hash.isNull() || _stricmp(hash.constData(), expectedHash.constData()))
|
2010-11-06 23:04:47 +01:00
|
|
|
{
|
2011-07-06 23:30:43 +02:00
|
|
|
qWarning("\nFile checksum error:\n A = %s\n B = %s\n", expectedHash.constData(), hash.constData());
|
2014-11-30 21:32:23 +01:00
|
|
|
CLOSE_HANDLE(fileHandle);
|
2015-08-30 13:47:08 +02:00
|
|
|
QFile::remove(filePath);
|
|
|
|
MUTILS_THROW_FMT("File '%s' is corruputed, take care!", MUTILS_UTF8(QFileInfo(filePath).fileName()));
|
2010-11-11 22:58:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-31 22:53:19 +02:00
|
|
|
static __forceinline bool doRemoveFile(const QString &filePath)
|
|
|
|
{
|
2017-04-16 23:59:11 +02:00
|
|
|
for (quint32 delay = 0U; delay <= MAX_LOCK_DELAY / 4; delay = NEXT_DELAY(delay))
|
2015-08-31 22:53:19 +02:00
|
|
|
{
|
2017-04-16 23:59:11 +02:00
|
|
|
if (delay > 0U)
|
|
|
|
{
|
|
|
|
if (delay <= 1U)
|
|
|
|
{
|
|
|
|
qWarning("Failed to delete file on first attempt, retrying...");
|
|
|
|
}
|
|
|
|
MUtils::OS::sleep_ms(delay);
|
|
|
|
}
|
2015-08-31 22:53:19 +02:00
|
|
|
if(MUtils::remove_file(filePath))
|
|
|
|
{
|
2017-04-16 23:59:11 +02:00
|
|
|
return true; /*file removed successfully*/
|
2015-08-31 22:53:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-30 13:47:08 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
LockedFile::LockedFile(QResource *const resource, const QString &outPath, const QByteArray &expectedHash, const bool bOwnsFile)
|
2013-11-01 19:32:47 +01:00
|
|
|
:
|
|
|
|
m_bOwnsFile(bOwnsFile),
|
2015-08-30 13:47:08 +02:00
|
|
|
m_filePath(QFileInfo(outPath).absoluteFilePath())
|
2010-11-11 22:58:02 +01:00
|
|
|
{
|
2013-11-01 19:32:47 +01:00
|
|
|
m_fileDescriptor = -1;
|
|
|
|
HANDLE fileHandle = NULL;
|
2015-08-30 13:47:08 +02:00
|
|
|
|
|
|
|
//Make sure the resource is valid
|
|
|
|
if(!(resource->isValid() && resource->data()))
|
|
|
|
{
|
|
|
|
MUTILS_THROW_FMT("The resource at %p is invalid!", resource);
|
|
|
|
}
|
2013-11-01 19:32:47 +01:00
|
|
|
|
2015-08-30 13:47:08 +02:00
|
|
|
//Write data to output file
|
|
|
|
QFile outFile(m_filePath);
|
|
|
|
doWriteOutput(outFile, resource);
|
|
|
|
|
|
|
|
//Now lock the file!
|
|
|
|
doLockFile(fileHandle, m_filePath, &outFile);
|
|
|
|
|
|
|
|
//Get file descriptor
|
|
|
|
doInitFileDescriptor(fileHandle, m_fileDescriptor);
|
|
|
|
|
|
|
|
//Validate file hash
|
|
|
|
doValidateHash(fileHandle, m_fileDescriptor, expectedHash, m_filePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
LockedFile::LockedFile(const QString &filePath, const QByteArray &expectedHash, const bool bOwnsFile)
|
|
|
|
:
|
|
|
|
m_bOwnsFile(bOwnsFile),
|
|
|
|
m_filePath(QFileInfo(filePath).absoluteFilePath())
|
|
|
|
{
|
|
|
|
m_fileDescriptor = -1;
|
|
|
|
HANDLE fileHandle = NULL;
|
2010-11-11 22:58:02 +01:00
|
|
|
|
2011-02-23 02:19:50 +01:00
|
|
|
//Make sure the file exists, before we try to lock it
|
2015-08-30 13:47:08 +02:00
|
|
|
doValidateFileExists(m_filePath);
|
|
|
|
|
|
|
|
//Now lock the file!
|
|
|
|
doLockFile(fileHandle, m_filePath, NULL);
|
|
|
|
|
|
|
|
//Get file descriptor
|
|
|
|
doInitFileDescriptor(fileHandle, m_fileDescriptor);
|
|
|
|
|
|
|
|
//Validate file hash
|
|
|
|
doValidateHash(fileHandle, m_fileDescriptor, expectedHash, m_filePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
LockedFile::LockedFile(const QString &filePath, const bool bOwnsFile)
|
|
|
|
:
|
|
|
|
m_bOwnsFile(bOwnsFile),
|
|
|
|
m_filePath(QFileInfo(filePath).canonicalFilePath())
|
|
|
|
{
|
|
|
|
m_fileDescriptor = -1;
|
|
|
|
HANDLE fileHandle = NULL;
|
2010-11-11 22:58:02 +01:00
|
|
|
|
2015-08-30 13:47:08 +02:00
|
|
|
//Make sure the file exists, before we try to lock it
|
|
|
|
doValidateFileExists(m_filePath);
|
2010-11-11 22:58:02 +01:00
|
|
|
|
2015-08-30 13:47:08 +02:00
|
|
|
//Now lock the file!
|
|
|
|
doLockFile(fileHandle, m_filePath, NULL);
|
2013-11-01 19:32:47 +01:00
|
|
|
|
|
|
|
//Get file descriptor
|
2015-08-30 13:47:08 +02:00
|
|
|
doInitFileDescriptor(fileHandle, m_fileDescriptor);
|
2010-11-06 23:04:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
LockedFile::~LockedFile(void)
|
|
|
|
{
|
2015-11-26 23:15:31 +01:00
|
|
|
CLOSE_FILE(m_fileDescriptor);
|
2013-11-01 19:32:47 +01:00
|
|
|
if(m_bOwnsFile)
|
|
|
|
{
|
2015-08-31 22:53:19 +02:00
|
|
|
doRemoveFile(m_filePath);
|
2013-11-01 19:32:47 +01:00
|
|
|
}
|
2010-11-06 23:04:47 +01:00
|
|
|
}
|
|
|
|
|
2015-11-22 17:36:54 +01:00
|
|
|
const QString LockedFile::filePath(void)
|
2010-11-06 23:04:47 +01:00
|
|
|
{
|
2015-11-22 17:36:54 +01:00
|
|
|
if (m_fileDescriptor >= 0)
|
|
|
|
{
|
2015-11-26 23:15:31 +01:00
|
|
|
if (GetFileType((HANDLE)_get_osfhandle(m_fileDescriptor)) == FILE_TYPE_UNKNOWN)
|
2015-11-22 17:36:54 +01:00
|
|
|
{
|
2015-11-26 23:15:31 +01:00
|
|
|
MUTILS_THROW_FMT("Failed to validate file handle!");
|
2015-11-22 17:36:54 +01:00
|
|
|
}
|
|
|
|
}
|
2010-11-06 23:04:47 +01:00
|
|
|
return m_filePath;
|
2012-11-27 01:02:55 +01:00
|
|
|
}
|