refactor(new_editor): continue architecture closeout
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
#include "ProjectBrowserModelInternal.h"
|
||||
|
||||
#include "Support/StringEncoding.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <system_error>
|
||||
|
||||
namespace XCEngine::UI::Editor::App::ProjectBrowserModelInternal {
|
||||
|
||||
std::string ToLowerCopy(std::string value) {
|
||||
std::transform(
|
||||
value.begin(),
|
||||
value.end(),
|
||||
value.begin(),
|
||||
[](unsigned char character) {
|
||||
return static_cast<char>(std::tolower(character));
|
||||
});
|
||||
return value;
|
||||
}
|
||||
|
||||
std::string PathToUtf8String(const std::filesystem::path& path) {
|
||||
return Support::WideToUtf8(path.native());
|
||||
}
|
||||
|
||||
std::string NormalizePathSeparators(std::string value) {
|
||||
std::replace(value.begin(), value.end(), '\\', '/');
|
||||
return value;
|
||||
}
|
||||
|
||||
std::string BuildRelativeItemId(
|
||||
const std::filesystem::path& path,
|
||||
const std::filesystem::path& assetsRoot) {
|
||||
const std::filesystem::path relative =
|
||||
std::filesystem::relative(path, assetsRoot.parent_path());
|
||||
const std::string normalized =
|
||||
NormalizePathSeparators(PathToUtf8String(relative.lexically_normal()));
|
||||
return normalized.empty() ? std::string(kAssetsRootId) : normalized;
|
||||
}
|
||||
|
||||
std::string BuildAssetDisplayName(const std::filesystem::path& path, bool directory) {
|
||||
if (directory) {
|
||||
return PathToUtf8String(path.filename());
|
||||
}
|
||||
|
||||
const std::string filename = PathToUtf8String(path.filename());
|
||||
const std::size_t extensionOffset = filename.find_last_of('.');
|
||||
if (extensionOffset == std::string::npos || extensionOffset == 0u) {
|
||||
return filename;
|
||||
}
|
||||
|
||||
return filename.substr(0u, extensionOffset);
|
||||
}
|
||||
|
||||
bool IsMetaFile(const std::filesystem::path& path) {
|
||||
return ToLowerCopy(path.extension().string()) == ".meta";
|
||||
}
|
||||
|
||||
bool HasChildDirectories(const std::filesystem::path& folderPath) {
|
||||
std::error_code errorCode = {};
|
||||
const std::filesystem::directory_iterator end = {};
|
||||
for (std::filesystem::directory_iterator iterator(folderPath, errorCode);
|
||||
!errorCode && iterator != end;
|
||||
iterator.increment(errorCode)) {
|
||||
if (iterator->is_directory(errorCode)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::filesystem::path> CollectSortedChildDirectories(
|
||||
const std::filesystem::path& folderPath) {
|
||||
std::vector<std::filesystem::path> paths = {};
|
||||
std::error_code errorCode = {};
|
||||
const std::filesystem::directory_iterator end = {};
|
||||
for (std::filesystem::directory_iterator iterator(folderPath, errorCode);
|
||||
!errorCode && iterator != end;
|
||||
iterator.increment(errorCode)) {
|
||||
if (iterator->is_directory(errorCode)) {
|
||||
paths.push_back(iterator->path());
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(
|
||||
paths.begin(),
|
||||
paths.end(),
|
||||
[](const std::filesystem::path& lhs, const std::filesystem::path& rhs) {
|
||||
return ToLowerCopy(PathToUtf8String(lhs.filename())) <
|
||||
ToLowerCopy(PathToUtf8String(rhs.filename()));
|
||||
});
|
||||
return paths;
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor::App::ProjectBrowserModelInternal
|
||||
Reference in New Issue
Block a user