diff --git a/src/Config.h b/src/Config.h index 041990ff..cbd2cfac 100644 --- a/src/Config.h +++ b/src/Config.h @@ -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 /* diff --git a/src/Global.cpp b/src/Global.cpp index 6e8b6958..36d6b54c 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -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(filename.utf16())); + SetFileAttributesW(reinterpret_cast(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] diff --git a/src/Global.h b/src/Global.h index 81849019..31783591 100644 --- a/src/Global.h +++ b/src/Global.h @@ -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); diff --git a/src/Thread_Process.cpp b/src/Thread_Process.cpp index 1dfab9a0..7f5b9ef7 100644 --- a/src/Thread_Process.cpp +++ b/src/Thread_Process.cpp @@ -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);