13#include <osl/file.hxx>
25 const size_t nIndex(rSrc.rfind(aToken));
26 std::u16string_view aRetval;
28 if (std::u16string_view::npos ==
nIndex)
35 aRetval = rSrc.substr(0,
nIndex);
37 if (rSrc.size() >
nIndex + 1)
39 rRight = rSrc.substr(
nIndex + 1);
48 if (!rBaseURL.isEmpty())
50 FileSharedPtr aBaseFile = std::make_shared<osl::File>(rBaseURL);
52 return (osl::File::E_None == aBaseFile->open(osl_File_OpenFlag_Read));
60 if (!rDirURL.isEmpty())
62 osl::Directory aDirectory(rDirURL);
64 return (osl::FileBase::E_None == aDirectory.open());
71 std::set<std::pair<OUString, OUString>>& rFiles)
73 if (rDirURL.isEmpty())
76 osl::Directory aDirectory(rDirURL);
78 if (osl::FileBase::E_None != aDirectory.open())
81 auto lcl_encodeUriSegment = [](OUString
const& rPath) {
82 return rtl::Uri::encode(rPath, rtl_UriCharClassUricNoSlash, rtl_UriEncodeIgnoreEscapes,
83 RTL_TEXTENCODING_UTF8);
86 osl::DirectoryItem aDirectoryItem;
88 while (osl::FileBase::E_None == aDirectory.getNextItem(aDirectoryItem))
90 osl::FileStatus aFileStatus(osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileName);
92 if (osl::FileBase::E_None == aDirectoryItem.getFileStatus(aFileStatus))
94 if (aFileStatus.isDirectory())
96 const OUString aFileName(aFileStatus.getFileName());
98 if (!aFileName.isEmpty())
100 rDirs.insert(lcl_encodeUriSegment(aFileName));
103 else if (aFileStatus.isRegular())
105 OUString aFileName(aFileStatus.getFileName());
109 if (!aFileName.isEmpty())
111 rFiles.insert(std::pair<OUString, OUString>(lcl_encodeUriSegment(aFileName),
112 lcl_encodeUriSegment(aExtension)));
121 std::set<OUString> aDirs;
122 std::set<std::pair<OUString, OUString>> aFiles;
127 for (
const auto& dir : aDirs)
129 const OUString aNewDirURL(rDirURL +
"/" + dir);
134 for (
const auto& file : aFiles)
136 OUString aNewFileURL(rDirURL +
"/" + file.first);
138 if (!file.second.isEmpty())
140 aNewFileURL +=
"." + file.second;
152 std::u16string_view rTargetDirURL,
153 const std::set<OUString>& rExcludeList)
155 std::set<OUString> aDirs;
156 std::set<std::pair<OUString, OUString>> aFiles;
161 for (
const auto& dir : aDirs)
163 const bool bExcluded(!rExcludeList.empty() && rExcludeList.find(dir) != rExcludeList.end());
167 const OUString aNewSourceDirURL(rSourceDirURL +
"/" + dir);
171 const OUString aNewTargetDirURL(OUString::Concat(rTargetDirURL) +
"/" + dir);
178 bError |= (osl::FileBase::E_None
179 != osl::File::move(aNewSourceDirURL, aNewTargetDirURL));
184 for (
const auto& file : aFiles)
186 OUString aSourceFileURL(rSourceDirURL +
"/" + file.first);
188 if (!file.second.isEmpty())
190 aSourceFileURL +=
"." + file.second;
195 OUString aTargetFileURL(OUString::Concat(rTargetDirURL) +
"/" + file.first);
197 if (!file.second.isEmpty())
199 aTargetFileURL +=
"." + file.second;
207 bError |= (osl::FileBase::E_None != osl::File::move(aSourceFileURL, aTargetFileURL));
static std::u16string_view splitAtLastToken(std::u16string_view rSrc, sal_Unicode aToken, OUString &rRight)
static bool deleteDirRecursively(const OUString &rDirURL)
static bool dirExists(const OUString &rDirURL)
static void scanDirsAndFiles(const OUString &rDirURL, std::set< OUString > &rDirs, std::set< std::pair< OUString, OUString > > &rFiles)
static bool moveDirContent(const OUString &rSourceDirURL, std::u16string_view rTargetDirURL, const std::set< OUString > &rExcludeList)
static bool fileExists(const OUString &rBaseURL)
OUStringBuffer & remove(OUStringBuffer &rIn, sal_Unicode c)
Removes all occurrences of a character from within the source string.
std::shared_ptr< osl::File > FileSharedPtr