|
| 1 | +// |
| 2 | + |
| 3 | +// Created by carlo on 2024-11-22. |
| 4 | +// |
| 5 | + |
| 6 | +#ifndef OS_HPP |
| 7 | +#define OS_HPP |
| 8 | + |
| 9 | +namespace SYSTEMS |
| 10 | +{ |
| 11 | + |
| 12 | + class OS |
| 13 | + { |
| 14 | + public: |
| 15 | + OS() |
| 16 | + { |
| 17 | + workingDir = std::filesystem::current_path(); |
| 18 | + projectPath = GetProjectPath(workingDir); |
| 19 | + shadersPath = projectPath / "src" / "Shaders"; |
| 20 | + assetsPath = projectPath / "Resources"/"Assets"; |
| 21 | + engineResourcesPath = projectPath / "Resources"/"Engine"; |
| 22 | + |
| 23 | + } |
| 24 | + |
| 25 | + |
| 26 | + static OS* GetInstance() |
| 27 | + { |
| 28 | + if (instance == nullptr) |
| 29 | + { |
| 30 | + instance = new OS; |
| 31 | + } |
| 32 | + return instance; |
| 33 | + } |
| 34 | + |
| 35 | + std::string ReadFile(std::string path) |
| 36 | + { |
| 37 | + std::ifstream inFile(path); |
| 38 | + std::string data; |
| 39 | + |
| 40 | + while (std::getline(inFile, data)) |
| 41 | + { |
| 42 | + } |
| 43 | + return data; |
| 44 | + } |
| 45 | + |
| 46 | + std::filesystem::path GetProjectPath(std::filesystem::path& workDir) |
| 47 | + { |
| 48 | + std::filesystem::path projectPath = workDir; |
| 49 | + bool solutionPathFind = false; |
| 50 | + while (!solutionPathFind) |
| 51 | + { |
| 52 | + for (auto element : std::filesystem::directory_iterator(projectPath)) |
| 53 | + { |
| 54 | + if (element.path().filename() == ".gitignore") |
| 55 | + { |
| 56 | + solutionPathFind = true; |
| 57 | + break; |
| 58 | + } |
| 59 | + } |
| 60 | + if (solutionPathFind) |
| 61 | + { |
| 62 | + break; |
| 63 | + } |
| 64 | + |
| 65 | + projectPath = projectPath.parent_path(); |
| 66 | + if (projectPath == workDir.root_path()) |
| 67 | + { |
| 68 | + break; |
| 69 | + } |
| 70 | + } |
| 71 | + assert(solutionPathFind && "The project dir was not find"); |
| 72 | + |
| 73 | + return projectPath; |
| 74 | + } |
| 75 | + bool IsPathAbsolute(std::string path) |
| 76 | + { |
| 77 | + if (!std::filesystem::exists(path)) |
| 78 | + { |
| 79 | + return false; |
| 80 | + } |
| 81 | + return true; |
| 82 | + } |
| 83 | + std::string GetEngineResourcesPath() |
| 84 | + { |
| 85 | + return engineResourcesPath.string(); |
| 86 | + } |
| 87 | + |
| 88 | + std::string GetAssetsPath() |
| 89 | + { |
| 90 | + return assetsPath.string(); |
| 91 | + } |
| 92 | + std::string GetShadersPath() |
| 93 | + { |
| 94 | + return shadersPath.string(); |
| 95 | + } |
| 96 | + std::filesystem::path workingDir; |
| 97 | + std::filesystem::path projectPath; |
| 98 | + std::filesystem::path engineResourcesPath; |
| 99 | + std::filesystem::path assetsPath; |
| 100 | + std::filesystem::path shadersPath; |
| 101 | + static OS* instance; |
| 102 | + }; |
| 103 | + |
| 104 | + OS* OS::instance = nullptr; |
| 105 | +} |
| 106 | + |
| 107 | +#endif //OS_HPP |
0 commit comments