@@ -235,30 +235,49 @@ int main(int argc, char** argv)
235235 if (parser.isSet (exportEfxOption))
236236 {
237237 Q_INIT_RESOURCE (EffectEngine);
238- QDir directory (" :/effects/" );
239- QDir destDir (exportEfxOption.value (parser));
240- if (directory.exists () && destDir.exists ())
238+ QDir const sourceDir (" :/effects/" );
239+ QDir const destinationDir (exportEfxOption.value (parser));
240+
241+ // Create destination if it does not exist
242+ if (!destinationDir.exists ())
243+ {
244+ std::cout << " Creating target directory: " << destinationDir.absolutePath ().toStdString () << ' \n ' ;
245+ if (!QDir ().mkpath (destinationDir.absolutePath ()))
246+ {
247+ std::cerr << " Failed to create directory: \" " << destinationDir.absolutePath ().toStdString () << " \" , aborting" << ' \n ' ;
248+ return 1 ;
249+ }
250+ }
251+
252+ if (sourceDir.exists ())
241253 {
242- std::cout << " Extract to folder: " << destDir.absolutePath ().toStdString () << std::endl;
243- const QStringList filenames = directory.entryList (QStringList () << " *" , QDir::Files, QDir::Name | QDir::IgnoreCase);
244- QString destFileName;
254+ std::cout << " Extract to folder: " << destinationDir.absolutePath ().toStdString () << ' \n ' ;
255+ const QStringList filenames = sourceDir.entryList (QStringList () << " *" , QDir::Files, QDir::Name | QDir::IgnoreCase);
245256 for (const QString & filename : filenames)
246257 {
247- destFileName = destDir.dirName ()+" /" +filename;
248- if (QFile::exists (destFileName))
258+ QString const sourceFilePath = sourceDir.absoluteFilePath (filename);
259+ QString const destinationFilePath = destinationDir.absoluteFilePath (filename);
260+
261+ if (QFile::exists (destinationFilePath))
262+ {
263+ QFile::remove (destinationFilePath);
264+ }
265+
266+ if (Logger::getLogLevel () == Logger::DEBUG )
249267 {
250- QFile::remove (destFileName) ;
268+ std::cout << " Copy \" " << sourceFilePath. toStdString () << " \" -> \" " << destinationFilePath. toStdString () << " \" " << ' \n ' ;
251269 }
252270
253271 std::cout << " Extract: " << filename.toStdString () << " ... " ;
254- if (QFile::copy (QString ( " :/effects/ " )+filename, destFileName ))
272+ if (QFile::copy (sourceFilePath, destinationFilePath ))
255273 {
256- QFile::setPermissions (destFileName , PERM0664 );
257- std::cout << " OK" << std::endl ;
274+ QFile::setPermissions (destinationFilePath , PERM0664 );
275+ std::cout << " OK" << ' \n ' ;
258276 }
259277 else
260278 {
261- std::cout << " Error, aborting" << std::endl;
279+ std::cerr << " Error copying [" << sourceFilePath.toStdString () << " -> [" << destinationFilePath.toStdString () << " ]" << ' \n ' ;
280+ std::cerr << " Error, aborting" << ' \n ' ;
262281 return 1 ;
263282 }
264283 }
0 commit comments