Line data Source code
1 : /* Copyright (C) 2025 Wildfire Games. 2 : * This file is part of 0 A.D. 3 : * 4 : * 0 A.D. is free software: you can redistribute it and/or modify 5 : * it under the terms of the GNU General Public License as published by 6 : * the Free Software Foundation, either version 2 of the License, or 7 : * (at your option) any later version. 8 : * 9 : * 0 A.D. is distributed in the hope that it will be useful, 10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 : * GNU General Public License for more details. 13 : * 14 : * You should have received a copy of the GNU General Public License 15 : * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 : */ 17 : 18 : #ifndef INCLUDED_PS_GAMESETUP_PATHS 19 : #define INCLUDED_PS_GAMESETUP_PATHS 20 : 21 : #include "lib/os_path.h" 22 : 23 : class CmdLineArgs; 24 : 25 : /** 26 : * Wrapper class for OS paths used by the game 27 : */ 28 : class Paths 29 : { 30 : public: 31 : Paths(const CmdLineArgs& args); 32 : 33 : /** 34 : * Returns the game's root directory 35 : */ 36 : const OsPath& Root() const 37 : { 38 : return m_root; 39 : } 40 : 41 : /** 42 : * Returns directory for read-only data installed with the game 43 : */ 44 0 : const OsPath& RData() const 45 : { 46 0 : return m_rdata; 47 : } 48 : 49 : /** 50 : * Returns directory for game-managed data and mods 51 : */ 52 : const OsPath& GameData() const 53 : { 54 : return m_gameData; 55 : } 56 : 57 : /** 58 : * Returns directory for user-created data 59 : * Only things created in response to an explicit user action should go here. 60 : * (note: only Windows currently treats this differently than GameData) 61 : */ 62 0 : const OsPath& UserData() const 63 : { 64 0 : return m_userData; 65 : } 66 : 67 : /** 68 : * Returns config file directory 69 : */ 70 0 : const OsPath& Config() const 71 : { 72 0 : return m_config; 73 : } 74 : 75 : /** 76 : * Returns cache directory 77 : */ 78 0 : const OsPath& Cache() const 79 : { 80 0 : return m_cache; 81 : } 82 : 83 : /** 84 : * Returns logs directory 85 : */ 86 0 : const OsPath& Logs() const 87 : { 88 0 : return m_logs; 89 : } 90 : 91 : private: 92 : static OsPath Root(const OsPath& argv0); 93 : static OsPath RootData(const OsPath& argv0); 94 : static OsPath XDG_Path(const char* envname, const OsPath& home, const OsPath& defaultPath); 95 : 96 : // read-only directories, fixed paths relative to executable 97 : OsPath m_root; 98 : OsPath m_rdata; 99 : 100 : // writable directories 101 : OsPath m_gameData; 102 : OsPath m_userData; 103 : OsPath m_config; 104 : OsPath m_cache; 105 : OsPath m_logs; // special-cased in single-root-folder installations 106 : }; 107 : 108 : #endif // #ifndef INCLUDED_PS_GAMESETUP_PATHS