3 #include <c++utilities/conversion/stringconversion.h> 26 BasicFileInfo::BasicFileInfo(
const std::string &path)
31 m_file.exceptions(ios_base::failbit | ios_base::badbit);
65 m_file.open(startsWith(m_path,
"file:/") ? m_path.data() + 6 : m_path.data(),
66 (m_readOnly = readOnly) ? ios_base::in | ios_base::binary : ios_base::in | ios_base::out | ios_base::binary);
67 m_file.seekg(0, ios_base::end);
68 m_size =
static_cast<uint64
>(m_file.tellg());
69 m_file.seekg(0, ios_base::beg);
100 if (
path != m_path) {
114 size_t lastSlash =
path.rfind(
'/');
115 size_t lastBackSlash =
path.rfind(
'\\');
116 size_t lastPoint = cutExtension ?
path.rfind(
'.') : string::npos;
117 size_t lastSeparator;
118 if (lastSlash == string::npos && lastBackSlash == string::npos) {
119 return (lastPoint == string::npos) ?
path :
path.substr(0, lastPoint);
120 }
else if (lastSlash == string::npos) {
121 lastSeparator = lastBackSlash;
122 }
else if (lastBackSlash == string::npos) {
123 lastSeparator = lastSlash;
125 lastSeparator = lastSlash > lastBackSlash ? lastSlash : lastBackSlash;
127 return (lastPoint != string::npos) ?
path.substr(lastSeparator + 1, lastPoint - lastSeparator - 1) :
path.substr(lastSeparator + 1);
137 return fileName(m_path, cutExtension);
147 size_t lastPoint =
path.rfind(
'.');
148 if (lastPoint == string::npos) {
151 return path.substr(lastPoint);
168 size_t lastPoint = fullPath.rfind(
'.');
169 return lastPoint != string::npos ? fullPath.substr(0, lastPoint) : fullPath;
185 size_t lastSlash =
path.rfind(
'/');
186 size_t lastBackSlash =
path.rfind(
'\\');
187 size_t lastSeparator;
188 if (lastSlash == string::npos && lastBackSlash == string::npos) {
190 }
else if (lastSlash == string::npos) {
191 lastSeparator = lastBackSlash;
192 }
else if (lastBackSlash == string::npos) {
193 lastSeparator = lastSlash;
195 lastSeparator = lastSlash > lastBackSlash ? lastSlash : lastBackSlash;
197 if (lastSeparator > 0) {
198 return path.substr(0, lastSeparator);
void setPath(const std::string &path)
Sets the current file.
void open(bool readOnly=false)
Opens a std::fstream for the current file.
std::string extension() const
Returns the extension of the current file.
const std::string & path() const
Returns the path of the current file.
virtual void invalidated()
This function is called when the BasicFileInfo gets invalidated.
void invalidate()
Invalidates the file info manually.
std::string containingDirectory() const
Returns the path of the directory containing the current file.
static std::string fileName(const std::string &path, bool cutExtension=false)
Returns the file name of the given file.
virtual ~BasicFileInfo()
Destroys the BasicFileInfo.
void reopen(bool readonly=false)
Opens a std::fstream for the current file.
void close()
A possibly opened std::fstream will be closed.
std::string pathWithoutExtension() const
Returns the path of the current file without the extension/suffix.
bool isOpen() const
Indicates whether a std::fstream is open for the current file.