2016-09-17 00:40:29 +02:00
|
|
|
#pragma once
|
|
|
|
|
2017-10-12 11:55:03 +02:00
|
|
|
// qt includes
|
|
|
|
#include <QFile>
|
2016-10-13 21:59:10 +02:00
|
|
|
#include <QString>
|
2017-10-12 11:55:03 +02:00
|
|
|
#include <QByteArray>
|
|
|
|
|
|
|
|
// util includes
|
|
|
|
#include "Logger.h"
|
2016-09-03 15:54:33 +02:00
|
|
|
|
|
|
|
namespace FileUtils {
|
|
|
|
|
2020-08-08 23:12:43 +02:00
|
|
|
QString getBaseName(const QString& sourceFile);
|
|
|
|
QString getDirName(const QString& sourceFile);
|
2016-09-15 20:42:58 +02:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
///
|
|
|
|
/// @brief remove directory recursive given by path
|
|
|
|
/// @param[in] path Path to directory
|
|
|
|
bool removeDir(const QString& path, Logger* log);
|
|
|
|
|
2017-10-12 11:55:03 +02:00
|
|
|
///
|
|
|
|
/// @brief check if the file exists
|
|
|
|
/// @param[in] path The file path to check
|
|
|
|
/// @param[in] log The logger of the caller to print errors
|
|
|
|
/// @param[in] ignError Ignore errors during file read (no log output)
|
|
|
|
/// @return true on success else false
|
|
|
|
///
|
|
|
|
bool fileExists(const QString& path, Logger* log, bool ignError=false);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief read a file given by path.
|
|
|
|
/// @param[in] path The file path to read
|
|
|
|
/// @param[out] data The read data o success
|
|
|
|
/// @param[in] log The logger of the caller to print errors
|
|
|
|
/// @param[in] ignError Ignore errors during file read (no log output)
|
|
|
|
/// @return true on success else false
|
|
|
|
///
|
|
|
|
bool readFile(const QString& path, QString& data, Logger* log, bool ignError=false);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// write a file given by path.
|
|
|
|
/// @param[in] path The file path to read
|
|
|
|
/// @param[in] data The data to write
|
|
|
|
/// @param[in] log The logger of the caller to print errors
|
|
|
|
/// @return true on success else false
|
|
|
|
///
|
|
|
|
bool writeFile(const QString& path, const QByteArray& data, Logger* log);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief delete a file by given path
|
|
|
|
/// @param[in] path The file path to delete
|
|
|
|
/// @param[in] log The logger of the caller to print errors
|
2018-12-27 23:11:32 +01:00
|
|
|
/// @param[in] ignError Ignore errors during file delete (no log output)
|
2017-10-12 11:55:03 +02:00
|
|
|
/// @return true on success else false
|
|
|
|
///
|
2018-12-27 23:11:32 +01:00
|
|
|
bool removeFile(const QString& path, Logger* log, bool ignError=false);
|
2017-10-12 11:55:03 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief resolve the file error and print a message
|
|
|
|
/// @param[in] file The file which caused the error
|
|
|
|
/// @param[in] log The logger of the caller
|
|
|
|
///
|
|
|
|
void resolveFileError(const QFile& file, Logger* log);
|
2020-05-25 21:51:11 +02:00
|
|
|
}
|