2015-04-22 19:22:01 +02:00
|
|
|
#ifndef BASICFILEINFO_H
|
|
|
|
#define BASICFILEINFO_H
|
|
|
|
|
2016-08-29 15:43:05 +02:00
|
|
|
#include "./global.h"
|
|
|
|
|
2015-04-22 19:22:01 +02:00
|
|
|
#include <c++utilities/conversion/types.h>
|
2016-12-18 20:17:50 +01:00
|
|
|
#include <c++utilities/io/nativefilestream.h>
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace Media {
|
|
|
|
|
2016-08-29 15:43:05 +02:00
|
|
|
class TAG_PARSER_EXPORT BasicFileInfo
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
|
|
|
public:
|
2016-05-01 20:02:44 +02:00
|
|
|
// constructor, destructor
|
2016-03-12 18:36:10 +01:00
|
|
|
BasicFileInfo(const std::string &path = std::string());
|
2015-04-22 19:22:01 +02:00
|
|
|
BasicFileInfo(const BasicFileInfo &) = delete;
|
|
|
|
BasicFileInfo &operator=(const BasicFileInfo &) = delete;
|
|
|
|
virtual ~BasicFileInfo();
|
|
|
|
|
2016-05-01 20:02:44 +02:00
|
|
|
// methods to control associated file stream
|
2016-03-12 18:36:10 +01:00
|
|
|
void open(bool readOnly = false);
|
2015-04-22 19:22:01 +02:00
|
|
|
void reopen(bool readonly = false);
|
2016-03-12 18:36:10 +01:00
|
|
|
bool isOpen() const;
|
|
|
|
bool isReadOnly() const;
|
2015-04-22 19:22:01 +02:00
|
|
|
void close();
|
2016-03-18 21:43:09 +01:00
|
|
|
void invalidate();
|
2016-12-18 20:17:50 +01:00
|
|
|
IoUtilities::NativeFileStream &stream();
|
|
|
|
const IoUtilities::NativeFileStream &stream() const;
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2016-05-01 20:02:44 +02:00
|
|
|
// methods to get, set path (components)
|
2015-04-22 19:22:01 +02:00
|
|
|
const std::string &path() const;
|
|
|
|
void setPath(const std::string &path);
|
|
|
|
static std::string fileName(const std::string &path, bool cutExtension = false);
|
|
|
|
std::string fileName(bool cutExtension = false) const;
|
|
|
|
static std::string extension(const std::string &path);
|
|
|
|
std::string extension() const;
|
|
|
|
static std::string pathWithoutExtension(const std::string &fullPath);
|
|
|
|
std::string pathWithoutExtension() const;
|
|
|
|
static std::string containingDirectory(const std::string &path);
|
|
|
|
std::string containingDirectory() const;
|
2016-05-01 20:02:44 +02:00
|
|
|
|
|
|
|
// methods to get, set the file size
|
2015-04-22 19:22:01 +02:00
|
|
|
uint64 size() const;
|
|
|
|
void reportSizeChanged(uint64 newSize);
|
2016-05-01 20:02:44 +02:00
|
|
|
void reportPathChanged(const std::string &newPath);
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void invalidated();
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string m_path;
|
2016-12-18 20:17:50 +01:00
|
|
|
IoUtilities::NativeFileStream m_file;
|
2015-04-22 19:22:01 +02:00
|
|
|
uint64 m_size;
|
2016-03-12 18:36:10 +01:00
|
|
|
bool m_readOnly;
|
2015-04-22 19:22:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Indicates whether a std::fstream is open for the current file.
|
|
|
|
*
|
|
|
|
* \sa stream()
|
|
|
|
*/
|
2016-03-12 18:36:10 +01:00
|
|
|
inline bool BasicFileInfo::isOpen() const
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
|
|
|
return m_file.is_open();
|
|
|
|
}
|
|
|
|
|
2016-03-12 18:36:10 +01:00
|
|
|
/*!
|
|
|
|
* \brief Indicates whether the last open()/reopen() call was read-only.
|
|
|
|
*/
|
|
|
|
inline bool BasicFileInfo::isReadOnly() const
|
|
|
|
{
|
|
|
|
return m_readOnly;
|
|
|
|
}
|
|
|
|
|
2015-04-22 19:22:01 +02:00
|
|
|
/*!
|
|
|
|
* \brief Returns the std::fstream for the current instance.
|
|
|
|
*/
|
2016-12-18 20:17:50 +01:00
|
|
|
inline IoUtilities::NativeFileStream &BasicFileInfo::stream()
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
|
|
|
return m_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the std::fstream for the current instance.
|
|
|
|
*/
|
2016-12-18 20:17:50 +01:00
|
|
|
inline const IoUtilities::NativeFileStream &BasicFileInfo::stream() const
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
|
|
|
return m_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the path of the current file.
|
|
|
|
*
|
|
|
|
* \sa setPath()
|
|
|
|
*/
|
|
|
|
inline const std::string &BasicFileInfo::path() const
|
|
|
|
{
|
|
|
|
return m_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns size of the current file in bytes.
|
|
|
|
* \remarks The file needs to be opened. Otherwise zero or the size of the
|
|
|
|
* previously opened file is returned.
|
|
|
|
* The size is not automatically updated when the file is modified.
|
|
|
|
* You might update the size using the reportSizeChanged() method.
|
|
|
|
*/
|
|
|
|
inline uint64 BasicFileInfo::size() const
|
|
|
|
{
|
|
|
|
return m_size;
|
|
|
|
}
|
|
|
|
|
2016-05-01 20:02:44 +02:00
|
|
|
/*!
|
|
|
|
* \brief Call this function to report that the size changed.
|
|
|
|
* \remarks Should be called after writing/truncating the stream().
|
|
|
|
*/
|
|
|
|
inline void BasicFileInfo::reportSizeChanged(uint64 newSize)
|
|
|
|
{
|
|
|
|
m_size = newSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Call this function to report that the path changed.
|
|
|
|
* \remarks Should be called after associating another file to the stream() manually.
|
|
|
|
*/
|
|
|
|
inline void BasicFileInfo::reportPathChanged(const std::string &newPath)
|
|
|
|
{
|
|
|
|
m_path = newPath;
|
|
|
|
}
|
|
|
|
|
2015-04-22 19:22:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // BASICFILEINFO_H
|