From fd6a750f4eff8bb098a81859102a13f29ded2503 Mon Sep 17 00:00:00 2001 From: Ted John Date: Wed, 7 Dec 2016 16:28:07 +0000 Subject: [PATCH] Add PlatformEnvironment implementation --- src/PlatformEnvironment.cpp | 116 +++++++++++++++++++++++++++++++++++- src/PlatformEnvironment.h | 8 ++- 2 files changed, 119 insertions(+), 5 deletions(-) diff --git a/src/PlatformEnvironment.cpp b/src/PlatformEnvironment.cpp index 1fdc881fc6..1568589c4e 100644 --- a/src/PlatformEnvironment.cpp +++ b/src/PlatformEnvironment.cpp @@ -14,18 +14,128 @@ *****************************************************************************/ #pragma endregion +#include "core/Exception.hpp" +#include "core/Guard.hpp" +#include "core/Path.hpp" +#include "core/String.hpp" #include "PlatformEnvironment.h" +extern "C" +{ + #include "openrct2.h" + #include "platform/platform.h" +} + class PlatformEnvironment : public IPlatformEnvironment { +private: + std::string _basePath[4]; + public: - std::string GetDirectoryPath(DIRBASE base, DIRID did) override + PlatformEnvironment(const std::string basePaths[4]) { - + for (int i = 0; i < 4; i++) + { + _basePath[i] = basePaths[i]; + } } - std::string GetFilePath(PATHID pathid) override + std::string GetDirectoryPath(DIRBASE base, DIRID did) const override { + const utf8 * basePath = _basePath[base].c_str(); + const utf8 * directoryName; + switch (base) { + default: + case DIRBASE_RCT1: + throw Exception("Not implemented"); + case DIRBASE_RCT2: + directoryName = DirectoryNamesRCT2[did]; + break; + case DIRBASE_OPENRCT2: + case DIRBASE_USER: + directoryName = DirectoryNamesOpenRCT2[did]; + break; + } + utf8 path[260]; + String::Set(path, sizeof(path), basePath); + Path::Append(path, sizeof(path), directoryName); + return std::string(path); } + + std::string GetFilePath(PATHID pathid) const override + { + const utf8 * basePath = _basePath[DIRBASE_USER].c_str(); + const utf8 * fileName = FileNames[pathid]; + + utf8 path[260]; + String::Set(path, sizeof(path), basePath); + Path::Append(path, sizeof(path), fileName); + return std::string(path); + } + +private: + static const char * DirectoryNamesRCT2[]; + static const char * DirectoryNamesOpenRCT2[]; + static const char * FileNames[]; +}; + +IPlatformEnvironment * CreatePlatformEnvironment() +{ + utf8 path[260]; + std::string basePaths[4]; + basePaths[DIRBASE_RCT2] = std::string(gRCT2AddressAppPath); + platform_get_openrct_data_path(path, sizeof(path)); + basePaths[DIRBASE_OPENRCT2] = std::string(path); + platform_get_user_directory(path, NULL, sizeof(path)); + basePaths[DIRBASE_USER] = std::string(path); + return new PlatformEnvironment(basePaths); +} + +const char * PlatformEnvironment::DirectoryNamesRCT2[] = +{ + "Data", // DIRID_DATA + "Landscapes", // DIRID_LANDSCAPE + nullptr, // DIRID_LANGUAGE + nullptr, // DIRID_LOG_CHAT + nullptr, // DIRID_LOG_SERVER + nullptr, // DIRID_NETWORK_KEY + "ObjData", // DIRID_OBJECT + "Saved Games", // DIRID_SAVE + "Scenarios", // DIRID_SCENARIO + nullptr, // DIRID_SCREENSHOT + nullptr, // DIRID_SEQUENCE + nullptr, // DIRID_SHADER + nullptr, // DIRID_THEME + "Tracks", // DIRID_TRACK +}; + +const char * PlatformEnvironment::DirectoryNamesOpenRCT2[] = +{ + "data", // DIRID_DATA + "landscape", // DIRID_LANDSCAPE + "language", // DIRID_LANGUAGE + "chatlogs", // DIRID_LOG_CHAT + "serverlogs", // DIRID_LOG_SERVER + "keys", // DIRID_NETWORK_KEY + "object", // DIRID_OBJECT + "save", // DIRID_SAVE + "scenario", // DIRID_SCENARIO + "screenshot", // DIRID_SCREENSHOT + "sequence", // DIRID_SEQUENCE + "shader", // DIRID_SHADER + "themes", // DIRID_THEME + "track", // DIRID_TRACK +}; + +const char * PlatformEnvironment::FileNames[] = +{ + "config.ini", // PATHID_CONFIG + "hotkeys.dat", // PATHID_CONFIG_KEYBOARD + "objects.idx", // PATHID_CACHE_OBJECTS + "tracks.idx", // PATHID_CACHE_TRACKS + "groups.json", // PATHID_NETWORK_GROUPS + "servers.cfg", // PATHID_NETWORK_SERVERS + "users.json", // PATHID_NETWORK_USERS + "highscores.dat", // PATHID_SCORES }; diff --git a/src/PlatformEnvironment.h b/src/PlatformEnvironment.h index cce3ef05fa..81548d38a7 100644 --- a/src/PlatformEnvironment.h +++ b/src/PlatformEnvironment.h @@ -31,6 +31,7 @@ enum DIRID { DIRID_DATA, // Contains g1.dat, music etc. DIRID_LANDSCAPE, // Contains scenario editor landscapes (SC6). + DIRID_LANGUAGE, // Contains language packs. DIRID_LOG_CHAT, // Contains chat logs. DIRID_LOG_SERVER, // Contains server logs. DIRID_NETWORK_KEY, // Contains the user's public and private keys. @@ -39,6 +40,7 @@ enum DIRID DIRID_SCENARIO, // Contains scenarios (SC6). DIRID_SCREENSHOT, // Contains screenshots. DIRID_SEQUENCE, // Contains title sequences. + DIRID_SHADER, // Contains OpenGL shaders. DIRID_THEME, // Contains interface themes. DIRID_TRACK, // Contains track designs. }; @@ -62,6 +64,8 @@ interface IPlatformEnvironment { virtual ~IPlatformEnvironment() = default; - virtual std::string GetDirectoryPath(DIRBASE base, DIRID did) abstract; - virtual std::string GetFilePath(PATHID pathid) abstract; + virtual std::string GetDirectoryPath(DIRBASE base, DIRID did) const abstract; + virtual std::string GetFilePath(PATHID pathid) const abstract; }; + +IPlatformEnvironment * CreatePlatformEnvironment();