2023-09-04 22:58:53 +08:00
|
|
|
#pragma once
|
|
|
|
|
2024-08-17 20:43:27 +08:00
|
|
|
#include "../../VTInternal.hpp"
|
2023-09-04 22:58:53 +08:00
|
|
|
#include "CKBaseManager.hpp"
|
2023-09-06 10:42:23 +08:00
|
|
|
#include <filesystem>
|
2023-09-04 22:58:53 +08:00
|
|
|
|
|
|
|
namespace LibCmo::CK2::MgrImpls {
|
|
|
|
|
|
|
|
class CKPathManager : public CKBaseManager {
|
|
|
|
public:
|
2023-09-06 10:42:23 +08:00
|
|
|
CKPathManager(CKContext* ctx);
|
|
|
|
virtual ~CKPathManager();
|
2024-08-17 20:43:27 +08:00
|
|
|
YYCC_DEL_CLS_COPY_MOVE(CKPathManager);
|
2023-09-06 10:42:23 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set the temp folder of current context.
|
2023-09-07 21:57:48 +08:00
|
|
|
* @param u8_temp The temp folder you need to assign
|
|
|
|
* @return true if success.
|
2023-09-06 10:42:23 +08:00
|
|
|
*/
|
2023-09-07 21:57:48 +08:00
|
|
|
bool SetTempFolder(CKSTRING u8_temp);
|
2023-09-06 10:42:23 +08:00
|
|
|
/**
|
|
|
|
* @brief Get current temp folder.
|
|
|
|
* @return
|
|
|
|
*/
|
2023-09-16 18:31:25 +08:00
|
|
|
XContainer::XString GetTempFolder();
|
2023-09-06 10:42:23 +08:00
|
|
|
/**
|
|
|
|
* @brief Get the path of temp file.
|
|
|
|
* @param u8_filename The relative path of file.
|
|
|
|
* @return The path of given path based on temp folder.
|
|
|
|
*/
|
2023-09-16 18:31:25 +08:00
|
|
|
XContainer::XString GetTempFilePath(CKSTRING u8_filename);
|
2023-09-06 10:42:23 +08:00
|
|
|
|
2023-09-07 21:57:48 +08:00
|
|
|
/**
|
|
|
|
* @brief Add extra path for ResolveFileName
|
|
|
|
* @param u8path The added path.
|
|
|
|
* @return true if success.
|
|
|
|
*/
|
|
|
|
bool AddPath(CKSTRING u8path);
|
|
|
|
/**
|
|
|
|
* @brief Clear all extra path.
|
|
|
|
*/
|
|
|
|
void ClearPath();
|
|
|
|
|
2023-09-06 10:42:23 +08:00
|
|
|
/**
|
|
|
|
* @brief Finds a file in the paths
|
|
|
|
* @param u8_filename[inout] The given file path. overwritten by the final path if success.
|
2023-09-07 21:57:48 +08:00
|
|
|
* @remark
|
|
|
|
* We match file in following order.
|
|
|
|
* + Whether given file is absolute path. return if true.
|
|
|
|
* + Virtools temp folder.
|
2023-09-30 16:01:39 +08:00
|
|
|
* + User provided extra path.
|
2023-09-06 10:42:23 +08:00
|
|
|
* @return true if success
|
|
|
|
*/
|
2023-09-16 18:31:25 +08:00
|
|
|
bool ResolveFileName(XContainer::XString& u8_filename);
|
2023-09-04 22:58:53 +08:00
|
|
|
|
2023-09-24 20:56:23 +08:00
|
|
|
/**
|
|
|
|
* @brief Get file name part of given path.
|
|
|
|
* @param u8path[inout] The given path. overwritten by the gotten file name.
|
|
|
|
*/
|
|
|
|
void GetFileName(XContainer::XString& u8path);
|
|
|
|
|
2023-09-10 21:33:43 +08:00
|
|
|
/**
|
|
|
|
* @brief Returns the file extension including period (.)
|
2023-09-24 20:56:23 +08:00
|
|
|
* @param u8path[inout] The given path. overwritten by the gotten extension.
|
2023-09-10 21:33:43 +08:00
|
|
|
*/
|
2023-09-16 18:31:25 +08:00
|
|
|
void GetExtension(XContainer::XString& u8path);
|
2023-09-10 21:33:43 +08:00
|
|
|
|
2023-09-04 22:58:53 +08:00
|
|
|
protected:
|
2023-09-06 10:42:23 +08:00
|
|
|
std::filesystem::path m_TempFolder;
|
2023-09-07 21:57:48 +08:00
|
|
|
XContainer::XArray<std::filesystem::path> m_ExtraPathes;
|
2023-09-04 22:58:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|