Workaround to remove temp files, even if they have the read-only attribute set.

This commit is contained in:
LoRd_MuldeR 2010-12-21 01:09:25 +01:00
parent 658efda273
commit 09691eb254
4 changed files with 47 additions and 11 deletions

View File

@ -25,7 +25,7 @@
#define VER_LAMEXP_MAJOR 4
#define VER_LAMEXP_MINOR_HI 0
#define VER_LAMEXP_MINOR_LO 0
#define VER_LAMEXP_BUILD 174
#define VER_LAMEXP_BUILD 175
#define VER_LAMEXP_SUFFIX TechPreview
/*

View File

@ -677,22 +677,23 @@ const QString &lamexp_temp_folder(void)
bool lamexp_clean_folder(const QString folderPath)
{
QDir tempFolder(folderPath);
QFileInfoList entryList = tempFolder.entryInfoList();
QFileInfoList entryList = tempFolder.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot);
for(int i = 0; i < entryList.count(); i++)
{
if(entryList.at(i).fileName().compare(".") == 0 || entryList.at(i).fileName().compare("..") == 0)
{
continue;
}
if(entryList.at(i).isDir())
{
lamexp_clean_folder(entryList.at(i).canonicalFilePath());
}
else
{
QFile::remove(entryList.at(i).canonicalFilePath());
for(int j = 0; j < 3; j++)
{
if(lamexp_remove_file(entryList.at(i).canonicalFilePath()))
{
break;
}
}
}
}
@ -722,7 +723,10 @@ void lamexp_finalization(void)
{
for(int i = 0; i < 100; i++)
{
if(lamexp_clean_folder(g_lamexp_temp_folder)) break;
if(lamexp_clean_folder(g_lamexp_temp_folder))
{
break;
}
Sleep(125);
}
g_lamexp_temp_folder.clear();
@ -913,6 +917,37 @@ QString lamexp_known_folder(lamexp_known_folder_t folder_id)
return folder;
}
/*
* Safely remove a file
*/
bool lamexp_remove_file(const QString &filename)
{
if(!QFileInfo(filename).exists() || !QFileInfo(filename).isFile())
{
return true;
}
else
{
if(!QFile::remove(filename))
{
DWORD attributes = GetFileAttributesW(reinterpret_cast<const wchar_t*>(filename.utf16()));
SetFileAttributesW(reinterpret_cast<const wchar_t*>(filename.utf16()), (attributes & (~FILE_ATTRIBUTE_READONLY)));
if(!QFile::remove(filename))
{
qWarning("Could not delete \"%s\"", filename.toLatin1().constData());
return false;
}
else
{
return true;
}
}
else
{
return true;
}
}
}
/*
* Get number private bytes [debug only]

View File

@ -96,6 +96,7 @@ bool lamexp_clean_folder(const QString folderPath);
const QString lamexp_version2string(const QString &pattern, unsigned int version);
QString lamexp_known_folder(lamexp_known_folder_t folder_id);
__int64 lamexp_free_diskspace(const QString &path);
bool lamexp_remove_file(const QString &filename);
//Debug-only functions
SIZE_T lamexp_dbg_private_bytes(void);

View File

@ -70,7 +70,7 @@ ProcessThread::~ProcessThread(void)
{
while(!m_tempFiles.isEmpty())
{
QFile::remove(m_tempFiles.takeFirst());
lamexp_remove_file(m_tempFiles.takeFirst());
}
LAMEXP_DELETE(m_encoder);