diff --git a/Nuake/src/Core/FileSystem.cpp b/Nuake/src/Core/FileSystem.cpp index 60f01ea8..796da7b1 100644 --- a/Nuake/src/Core/FileSystem.cpp +++ b/Nuake/src/Core/FileSystem.cpp @@ -1,6 +1,7 @@ #include "FileSystem.h" #include "Engine.h" +#include "OS.h" #include @@ -197,6 +198,17 @@ namespace Nuake return std::filesystem::remove_all(path.c_str()); } + std::string FileSystem::GetConfigFolderPath() + { + std::string subFolderPath = OS::GetConfigFolderPath().append("/Nuake/"); + if (!DirectoryExists(subFolderPath)) + { + MakeDirectory(subFolderPath); + } + + return subFolderPath; + } + Ref FileSystem::GetFileTree() { return RootDirectory; diff --git a/Nuake/src/Core/FileSystem.h b/Nuake/src/Core/FileSystem.h index 3546d264..9be0b67f 100644 --- a/Nuake/src/Core/FileSystem.h +++ b/Nuake/src/Core/FileSystem.h @@ -50,6 +50,7 @@ namespace Nuake static void EndWriteFile(); static uintmax_t DeleteFileFromPath(const std::string& path); static uintmax_t DeleteFolder(const std::string& path); + static std::string GetConfigFolderPath(); }; enum class FileType diff --git a/Nuake/src/Core/OS.cpp b/Nuake/src/Core/OS.cpp index e44711c5..15a05909 100644 --- a/Nuake/src/Core/OS.cpp +++ b/Nuake/src/Core/OS.cpp @@ -3,9 +3,19 @@ #include "Engine.h" #ifdef NK_WIN - #define GLFW_EXPOSE_NATIVE_WIN32 - #include +#define GLFW_EXPOSE_NATIVE_WIN32 +#include +#include +#include +#include + +#endif + +#ifdef NK_LINUX + +#include + #endif #include "GLFW/glfw3.h" @@ -92,6 +102,37 @@ namespace Nuake { #endif } + std::string OS::GetConfigFolderPath() + { + std::string path; + +#ifdef NK_WIN + TCHAR appDataPath[64]; + // Get the path to the AppData folder + if (SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, appDataPath) >= 0) + { + std::wstring wideString(appDataPath); + path = std::string(wideString.begin(), wideString.end()); + // Now, 'appDataPath' contains the path to the AppData folder + path.erase(std::remove_if(path.begin(), path.end(), [](char c) + { + return c == '\0'; + }), path.end()); + std::replace(path.begin(), path.end(), '\\', '/'); + } + else + { + path = ""; + } +#endif + +#ifdef NK_LINUX + path = "~/.config/"; +#endif + + return path; + } + void OS::OpenURL(const std::string& url) { #ifdef NK_WIN diff --git a/Nuake/src/Core/OS.h b/Nuake/src/Core/OS.h index a2e4c3b4..1d73fe98 100644 --- a/Nuake/src/Core/OS.h +++ b/Nuake/src/Core/OS.h @@ -17,5 +17,6 @@ namespace Nuake static void ShowInFileExplorer(const std::string& filePath); static void OpenTrenchbroomMap(const std::string& filePath); static void OpenURL(const std::string& url); + static std::string GetConfigFolderPath(); }; } diff --git a/Nuake/src/Scene/Components/ModelComponent.h b/Nuake/src/Scene/Components/ModelComponent.h index c93e39d3..a60c04dc 100644 --- a/Nuake/src/Scene/Components/ModelComponent.h +++ b/Nuake/src/Scene/Components/ModelComponent.h @@ -23,7 +23,10 @@ namespace Nuake { BEGIN_SERIALIZE(); SERIALIZE_VAL(ModelPath); - SERIALIZE_OBJECT(ModelResource); + if (ModelResource) + { + SERIALIZE_OBJECT(ModelResource); + } END_SERIALIZE(); }