1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * @brief Implementation for DirItem routines
10 #include "UnicodeString.h"
17 * @brief Set filename and path for the item.
18 * @param [in] fullpath Full path to file to set to item.
20 void DirItem::SetFile(const String &fullPath)
22 String ext, filename2, path2;
23 paths::SplitFilename(fullPath, &path2, &filename2, &ext);
31 * @brief Get the full path of the item.
34 String DirItem::GetFile() const
36 return paths::ConcatPath(path.get(), filename.get());
40 * @brief Update fileinfo from given file.
41 * This function updates file's information from given item. Function
42 * does not set filename and path.
43 * @param [in] sFilePath Full path to file/directory to update
44 * @return true if information was updated (item was found).
46 bool DirItem::Update(const String &sFilePath)
50 size = DirItem::FILE_SIZE_NONE;
54 if (!sFilePath.empty())
58 TFile file(sFilePath);
60 mtime = file.getLastModified();
61 // There can be files without modification date.
62 // Then we must use creation date. Of course we assume
63 // creation date then exists...
65 mtime = file.created();
67 // No size for directory ( size remains as -1)
68 if (!file.isDirectory())
69 size = file.getSize();
71 flags.attributes = GetFileAttributes(file.wpath().c_str());
83 * @brief Update filename from given file.
84 * @param [in] sFilePath Full path to file/directory to update
85 * @return true if information was updated (item was found).
87 bool DirItem::UpdateFileName(const String& sFilePath)
90 if (!sFilePath.empty())
94 std::filesystem::path canonicalPath = std::filesystem::canonical(sFilePath);
95 filename = canonicalPath.filename();
106 * @brief Clears FileInfo data.
108 /*void DirItem::Clear()
116 * @brief Clears FileInfo data except path/filename.
118 void DirItem::ClearPartial()
122 size = DirItem::FILE_SIZE_NONE;
127 * @brief Return whether the item is a directory.
128 * @return true if the item is a directory.
130 bool DirItem::IsDirectory() const
132 return ((flags.attributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY);