diff --git a/openVulkanoCpp/IO/AppFolders.cpp b/openVulkanoCpp/IO/AppFolders.cpp new file mode 100644 index 0000000..13eb03c --- /dev/null +++ b/openVulkanoCpp/IO/AppFolders.cpp @@ -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 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 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; + } +} \ No newline at end of file diff --git a/openVulkanoCpp/IO/AppFolders.hpp b/openVulkanoCpp/IO/AppFolders.hpp new file mode 100644 index 0000000..519f7c2 --- /dev/null +++ b/openVulkanoCpp/IO/AppFolders.hpp @@ -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 +#include + +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 appName); + + public: + static void Init(std::string_view appName); + + static void Init(const std::filesystem::path& dir, std::optional 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(); + }; +}