Create a lock file in Temp folder, so it cannot be deleted before MediaInfo is extracted.
This commit is contained in:
parent
831c0e07e5
commit
d4f7e96578
31
src/Main.cpp
31
src/Main.cpp
@ -150,12 +150,13 @@ QString mixp_getAppDataFolder(void)
|
|||||||
return folder;
|
return folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString mixp_getTempFolder()
|
QString mixp_getTempFolder(QFile **lockfile)
|
||||||
{
|
{
|
||||||
|
*lockfile = NULL;
|
||||||
QString tempFolder;
|
QString tempFolder;
|
||||||
|
|
||||||
static const char *TEMP_STR = "Temp";
|
static const char *TEMP_STR = "Temp";
|
||||||
const QString WRITE_TEST_DATA = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.";
|
const QByteArray WRITE_TEST_DATA = QByteArray("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.");
|
||||||
const QString SUB_FOLDER = QUuid::createUuid().toString();
|
const QString SUB_FOLDER = QUuid::createUuid().toString();
|
||||||
|
|
||||||
//Try the %TMP% or %TEMP% directory first
|
//Try the %TMP% or %TEMP% directory first
|
||||||
@ -165,14 +166,16 @@ QString mixp_getTempFolder()
|
|||||||
temp.mkdir(SUB_FOLDER);
|
temp.mkdir(SUB_FOLDER);
|
||||||
if(temp.cd(SUB_FOLDER) && temp.exists())
|
if(temp.cd(SUB_FOLDER) && temp.exists())
|
||||||
{
|
{
|
||||||
QFile testFile(QString("%1/~test.tmp").arg(temp.canonicalPath()));
|
QFile *testFile = new QFile(QString("%1/~lock.tmp").arg(temp.canonicalPath()));
|
||||||
if(testFile.open(QIODevice::ReadWrite))
|
if(testFile->open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Unbuffered))
|
||||||
{
|
{
|
||||||
if(testFile.write(WRITE_TEST_DATA.toLatin1().constData()) >= strlen(WRITE_TEST_DATA.toLatin1().constData()))
|
if(testFile->write(WRITE_TEST_DATA) >= WRITE_TEST_DATA.size())
|
||||||
{
|
{
|
||||||
|
*lockfile = testFile; testFile = NULL;
|
||||||
tempFolder = temp.canonicalPath();
|
tempFolder = temp.canonicalPath();
|
||||||
}
|
}
|
||||||
testFile.remove();
|
if(testFile) testFile->remove();
|
||||||
|
MIXP_DELETE_OBJ(testFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!tempFolder.isEmpty())
|
if(!tempFolder.isEmpty())
|
||||||
@ -200,14 +203,16 @@ QString mixp_getTempFolder()
|
|||||||
localAppData.mkdir(SUB_FOLDER);
|
localAppData.mkdir(SUB_FOLDER);
|
||||||
if(localAppData.cd(SUB_FOLDER) && localAppData.exists())
|
if(localAppData.cd(SUB_FOLDER) && localAppData.exists())
|
||||||
{
|
{
|
||||||
QFile testFile(QString("%1/~test.tmp").arg(localAppData.canonicalPath()));
|
QFile *testFile = new QFile(QString("%1/~lock.tmp").arg(localAppData.canonicalPath()));
|
||||||
if(testFile.open(QIODevice::ReadWrite))
|
if(testFile->open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Unbuffered))
|
||||||
{
|
{
|
||||||
if(testFile.write(WRITE_TEST_DATA.toLatin1().constData()) >= strlen(WRITE_TEST_DATA.toLatin1().constData()))
|
if(testFile->write(WRITE_TEST_DATA) >= WRITE_TEST_DATA.size())
|
||||||
{
|
{
|
||||||
|
*lockfile = testFile; testFile = NULL;
|
||||||
tempFolder = localAppData.canonicalPath();
|
tempFolder = localAppData.canonicalPath();
|
||||||
}
|
}
|
||||||
testFile.remove();
|
if(testFile) testFile->remove();
|
||||||
|
MIXP_DELETE_OBJ(testFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -268,8 +273,10 @@ int mixp_main(int argc, char* argv[])
|
|||||||
qDebug("Copyright (c) 2004-%s LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.", &mixp_buildDate[7]);
|
qDebug("Copyright (c) 2004-%s LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.", &mixp_buildDate[7]);
|
||||||
qDebug("Built with Qt v%s, running with Qt v%s.\n", QT_VERSION_STR, qVersion());
|
qDebug("Built with Qt v%s, running with Qt v%s.\n", QT_VERSION_STR, qVersion());
|
||||||
|
|
||||||
|
QFile *lockFile = NULL;
|
||||||
|
|
||||||
//Get temp folder
|
//Get temp folder
|
||||||
const QString tempFolder = mixp_getTempFolder();
|
const QString tempFolder = mixp_getTempFolder(&lockFile);
|
||||||
qDebug("TEMP folder is:\n%s\n", QDir::toNativeSeparators(tempFolder).toUtf8().constData());
|
qDebug("TEMP folder is:\n%s\n", QDir::toNativeSeparators(tempFolder).toUtf8().constData());
|
||||||
|
|
||||||
//Create application
|
//Create application
|
||||||
@ -287,6 +294,8 @@ int mixp_main(int argc, char* argv[])
|
|||||||
//Clean up
|
//Clean up
|
||||||
MIXP_DELETE_OBJ(mainWindow);
|
MIXP_DELETE_OBJ(mainWindow);
|
||||||
MIXP_DELETE_OBJ(application);
|
MIXP_DELETE_OBJ(application);
|
||||||
|
if(lockFile) lockFile->remove();
|
||||||
|
MIXP_DELETE_OBJ(lockFile);
|
||||||
mixp_clean_folder(tempFolder);
|
mixp_clean_folder(tempFolder);
|
||||||
|
|
||||||
return exit_code;
|
return exit_code;
|
||||||
|
@ -579,6 +579,10 @@ bool CMainWindow::analyzeFile(const QString &filePath)
|
|||||||
if(mediaInfoPath.isEmpty())
|
if(mediaInfoPath.isEmpty())
|
||||||
{
|
{
|
||||||
QMessageBox::critical(this, tr("Failure"), tr("Error: Failed to extract MediaInfo binary!"), QMessageBox::Ok);
|
QMessageBox::critical(this, tr("Failure"), tr("Error: Failed to extract MediaInfo binary!"), QMessageBox::Ok);
|
||||||
|
m_floatingLabel->hide();
|
||||||
|
ui->actionOpen->setEnabled(true);
|
||||||
|
ui->analyzeButton->setEnabled(true);
|
||||||
|
ui->exitButton->setEnabled(true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user