add func to path manager. fix bitmap handler. add general bitmap handler getter

This commit is contained in:
2023-09-07 21:57:48 +08:00
parent f7f1478ecf
commit 54a3dd7776
11 changed files with 264 additions and 66 deletions

View File

@ -10,7 +10,7 @@ namespace LibCmo::CK2::MgrImpls {
CKPathManager::CKPathManager(CKContext* ctx) :
CKBaseManager(ctx, PATH_MANAGER_GUID, "Path Manager"),
m_TempFolder() {
m_TempFolder(), m_ExtraPathes() {
// preset for temp folder
// todo: add current CKContext pointer as the part of temp path.
// thus multiple CKContext can work.
@ -21,8 +21,15 @@ namespace LibCmo::CK2::MgrImpls {
}
CKPathManager::~CKPathManager() {}
void CKPathManager::SetTempFolder(CKSTRING u8_temp) {
EncodingHelper::U8PathToStdPath(this->m_TempFolder, u8_temp);
bool CKPathManager::SetTempFolder(CKSTRING u8_temp) {
std::filesystem::path cache;
EncodingHelper::U8PathToStdPath(cache, u8_temp);
if (std::filesystem::is_directory(cache)) {
m_TempFolder = cache;
return true;
} else {
return false;
}
}
std::string CKPathManager::GetTempFolder() {
@ -41,8 +48,49 @@ namespace LibCmo::CK2::MgrImpls {
return result;
}
bool CKPathManager::AddPath(CKSTRING u8path) {
if (u8path == nullptr) return;
std::filesystem::path newpath;
EncodingHelper::U8PathToStdPath(newpath, u8path);
if (std::filesystem::is_directory(newpath)) {
m_ExtraPathes.emplace_back(std::move(newpath));
return true;
} else {
return false;
}
}
void CKPathManager::ClearPath() {
m_ExtraPathes.clear();
}
bool CKPathManager::ResolveFileName(std::string& u8_filename) {
// todo: finish resolve file name
std::filesystem::path filepath;
EncodingHelper::U8PathToStdPath(filepath, u8_filename.c_str());
// if it is absolute path, return it directly
if (filepath.is_absolute()) {
return true;
}
// otherwise check it in extra path
for (const auto& extrapath : m_ExtraPathes) {
auto combinedpath = extrapath / filepath;
if (std::filesystem::is_regular_file(combinedpath)) {
// this is correct
EncodingHelper::StdPathToU8Path(u8_filename, combinedpath);
return true;
}
}
// test in temp folder
auto tempfile = m_TempFolder / filepath;
if (std::filesystem::is_regular_file(tempfile)) {
EncodingHelper::StdPathToU8Path(u8_filename, combinedpath);
return true;
}
// failed
return false;
}