
#include "cleanconfig.h"
#include <QFile>
#include <QDir>

#define DO_REMOVE
//#define REMOVE_FILE_SETTINGS

void CleanConfig::clean(const QString & config_path) {
	qDebug("CleanConfig::clean");

	QStringList files;
	files << "smplayer.ini" << "styles.ass" << "smplayer_files.ini"
          << "ytcode.script" << "yt.js" << "sig.ini" << "player_info.ini"
          << "device_info.ini" << "hdpi.ini" << "playlist.ini";

	QStringList files_to_delete;

	foreach(QString f, files) {
		QString s = config_path +"/"+ f;
		if (QFile::exists(s)) files_to_delete << s;
	}

#ifdef REMOVE_FILE_SETTINGS
	QString s = config_path + "/file_settings";
	if (QFile::exists(s)) files_to_delete << listDir(s);
#endif

	printf("Deleting files:\n");
	for (int n = 0; n < files_to_delete.count(); n++) {
		printf("Delete: %s\n", files_to_delete[n].toUtf8().constData());
		#ifdef DO_REMOVE
		QFile::remove(files_to_delete[n]);
		#endif
	}
}

QStringList CleanConfig::listDir(const QString &path) {
	QDir dir(path);
	QStringList file_list;

	foreach(QString file, dir.entryList(QDir::Files)) {
		file_list << QFileInfo(dir, file).absoluteFilePath();
	}

	foreach(QString sub_dir, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
		file_list << listDir(path +"/"+ sub_dir);
	}

	return file_list;
}

