Files
MaaAssistantArknights/src/MaaCore/Utils/WorkingDir.hpp
2022-12-02 00:22:47 +08:00

36 lines
897 B
C++

#pragma once
#include "Platform.hpp"
#include "SingletonHolder.hpp"
namespace asst
{
enum class WorkingDirType
{
Res,
User,
};
template <WorkingDirType type>
class WorkingDir : public SingletonHolder<WorkingDir<type>>
{
public:
bool empty() const noexcept { return dir_.empty(); }
const std::filesystem::path& get() const noexcept { return dir_; }
bool set(std::filesystem::path dir)
{
if (!std::filesystem::exists(dir) || !std::filesystem::is_directory(dir)) {
return false;
}
dir_ = std::move(dir);
return true;
}
private:
std::filesystem::path dir_;
};
static auto& ResDir = WorkingDir<WorkingDirType::Res>::get_instance();
static auto& UserDir = WorkingDir<WorkingDirType::User>::get_instance();
} // namespace asst