Add AppFolders class
This commit is contained in:
85
openVulkanoCpp/IO/AppFolders.cpp
Normal file
85
openVulkanoCpp/IO/AppFolders.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "AppFolders.hpp"
|
||||
#include "PlatformFolders.hpp"
|
||||
|
||||
namespace openVulkanoCpp
|
||||
{
|
||||
AppFolders AppFolders::INSTANCE = AppFolders("openVulkano");
|
||||
|
||||
void AppFolders::Init(std::string_view appName)
|
||||
{
|
||||
#ifndef __APPLE__
|
||||
INSTANCE = AppFolders(appName);
|
||||
#endif
|
||||
}
|
||||
|
||||
void AppFolders::Init(const std::filesystem::path& dir, std::optional<std::string_view> appName)
|
||||
{
|
||||
#ifndef __APPLE__
|
||||
INSTANCE = AppFolders(dir, appName);
|
||||
#endif
|
||||
}
|
||||
|
||||
AppFolders::AppFolders(std::string_view appName)
|
||||
: appDataHome(PlatformFolders::GetDataHomeDir() / appName)
|
||||
, appConfigHome(PlatformFolders::GetConfigHomeDir() / appName)
|
||||
, appState(PlatformFolders::GetStateDir() / appName)
|
||||
, appDataCache(PlatformFolders::GetCacheDir() / appName)
|
||||
, appTemp(PlatformFolders::GetTempDir() / appName)
|
||||
{
|
||||
}
|
||||
|
||||
AppFolders::AppFolders(const std::filesystem::path& dir, std::optional<std::string_view> appName)
|
||||
: appDataHome(dir / appName.value_or(""))
|
||||
, appConfigHome(dir / appName.value_or(""))
|
||||
, appState(dir / appName.value_or("") / "state")
|
||||
, appDataCache(dir / appName.value_or("") / "cache")
|
||||
, appTemp(dir / appName.value_or("") / "tmp")
|
||||
{
|
||||
}
|
||||
|
||||
const std::filesystem::path& AppFolders::GetAppDataHomeDir()
|
||||
{
|
||||
#ifndef __APPLE__
|
||||
std::filesystem::create_directories(INSTANCE.appDataHome);
|
||||
#endif
|
||||
return INSTANCE.appDataHome;
|
||||
}
|
||||
|
||||
const std::filesystem::path& AppFolders::GetAppConfigHomeDir()
|
||||
{
|
||||
#ifndef __APPLE__
|
||||
std::filesystem::create_directories(INSTANCE.appConfigHome);
|
||||
#endif
|
||||
return INSTANCE.appConfigHome;
|
||||
}
|
||||
|
||||
const std::filesystem::path& AppFolders::GetAppStateDir()
|
||||
{
|
||||
#ifndef __APPLE__
|
||||
std::filesystem::create_directories(INSTANCE.appState);
|
||||
#endif
|
||||
return INSTANCE.appState;
|
||||
}
|
||||
|
||||
const std::filesystem::path& AppFolders::GetAppCacheDir()
|
||||
{
|
||||
#ifndef __APPLE__
|
||||
std::filesystem::create_directories(INSTANCE.appDataCache);
|
||||
#endif
|
||||
return INSTANCE.appDataCache;
|
||||
}
|
||||
|
||||
const std::filesystem::path& AppFolders::GetAppTempDir()
|
||||
{
|
||||
#ifndef __APPLE__
|
||||
std::filesystem::create_directories(INSTANCE.appTemp);
|
||||
#endif
|
||||
return INSTANCE.appTemp;
|
||||
}
|
||||
}
|
||||
38
openVulkanoCpp/IO/AppFolders.hpp
Normal file
38
openVulkanoCpp/IO/AppFolders.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <optional>
|
||||
|
||||
namespace openVulkanoCpp
|
||||
{
|
||||
class AppFolders
|
||||
{
|
||||
static AppFolders INSTANCE;
|
||||
std::filesystem::path appDataHome, appConfigHome, appState, appDataCache, appTemp;
|
||||
|
||||
AppFolders(std::string_view appName);
|
||||
|
||||
AppFolders(const std::filesystem::path& dir, std::optional<std::string_view> appName);
|
||||
|
||||
public:
|
||||
static void Init(std::string_view appName);
|
||||
|
||||
static void Init(const std::filesystem::path& dir, std::optional<std::string_view> appName);
|
||||
|
||||
[[nodiscard]] static const std::filesystem::path& GetAppDataHomeDir();
|
||||
|
||||
[[nodiscard]] static const std::filesystem::path& GetAppConfigHomeDir();
|
||||
|
||||
[[nodiscard]] static const std::filesystem::path& GetAppStateDir();
|
||||
|
||||
[[nodiscard]] static const std::filesystem::path& GetAppCacheDir();
|
||||
|
||||
[[nodiscard]] static const std::filesystem::path& GetAppTempDir();
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user