2016-12-07 16:49:29 +01:00
|
|
|
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
|
|
|
|
/*****************************************************************************
|
|
|
|
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
|
|
|
*
|
|
|
|
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
|
|
|
|
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
|
|
|
|
*
|
|
|
|
* OpenRCT2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* A full copy of the GNU General Public License can be found in licence.txt
|
|
|
|
*****************************************************************************/
|
|
|
|
#pragma endregion
|
|
|
|
|
2016-12-07 17:28:07 +01:00
|
|
|
#include "core/Exception.hpp"
|
|
|
|
#include "core/Guard.hpp"
|
|
|
|
#include "core/Path.hpp"
|
|
|
|
#include "core/String.hpp"
|
2016-12-07 16:49:29 +01:00
|
|
|
#include "PlatformEnvironment.h"
|
|
|
|
|
2016-12-07 17:28:07 +01:00
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#include "platform/platform.h"
|
|
|
|
}
|
|
|
|
|
2016-12-07 16:49:29 +01:00
|
|
|
class PlatformEnvironment : public IPlatformEnvironment
|
|
|
|
{
|
2016-12-07 17:28:07 +01:00
|
|
|
private:
|
2016-12-12 03:16:08 +01:00
|
|
|
std::string _basePath[DIRBASE_COUNT];
|
2016-12-07 17:28:07 +01:00
|
|
|
|
2016-12-07 16:49:29 +01:00
|
|
|
public:
|
2016-12-12 03:16:08 +01:00
|
|
|
PlatformEnvironment(DIRBASE_VALUES basePaths)
|
2016-12-07 16:49:29 +01:00
|
|
|
{
|
2017-01-04 22:17:08 +01:00
|
|
|
for (sint32 i = 0; i < 4; i++)
|
2016-12-07 17:28:07 +01:00
|
|
|
{
|
|
|
|
_basePath[i] = basePaths[i];
|
|
|
|
}
|
|
|
|
}
|
2016-12-07 16:49:29 +01:00
|
|
|
|
2016-12-07 17:28:07 +01:00
|
|
|
std::string GetDirectoryPath(DIRBASE base, DIRID did) const override
|
|
|
|
{
|
2016-12-08 12:42:21 +01:00
|
|
|
const utf8 * basePath = _basePath[(size_t)base].c_str();
|
2016-12-07 17:28:07 +01:00
|
|
|
const utf8 * directoryName;
|
|
|
|
switch (base) {
|
|
|
|
default:
|
2016-12-08 12:42:21 +01:00
|
|
|
case DIRBASE::RCT1:
|
|
|
|
case DIRBASE::RCT2:
|
|
|
|
directoryName = DirectoryNamesRCT2[(size_t)did];
|
2016-12-07 17:28:07 +01:00
|
|
|
break;
|
2016-12-08 12:42:21 +01:00
|
|
|
case DIRBASE::OPENRCT2:
|
|
|
|
case DIRBASE::USER:
|
|
|
|
directoryName = DirectoryNamesOpenRCT2[(size_t)did];
|
2016-12-07 17:28:07 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
utf8 path[260];
|
|
|
|
String::Set(path, sizeof(path), basePath);
|
|
|
|
Path::Append(path, sizeof(path), directoryName);
|
|
|
|
return std::string(path);
|
2016-12-07 16:49:29 +01:00
|
|
|
}
|
|
|
|
|
2016-12-07 17:28:07 +01:00
|
|
|
std::string GetFilePath(PATHID pathid) const override
|
2016-12-07 16:49:29 +01:00
|
|
|
{
|
2016-12-08 12:42:21 +01:00
|
|
|
const utf8 * fileName = FileNames[(size_t)pathid];
|
2016-12-10 20:20:32 +01:00
|
|
|
const utf8 * basePath = _basePath[(size_t)DIRBASE::USER].c_str();
|
|
|
|
if (pathid == PATHID::SCORES_RCT2)
|
|
|
|
{
|
|
|
|
basePath = _basePath[(size_t)DIRBASE::RCT2].c_str();
|
|
|
|
}
|
2016-12-07 16:49:29 +01:00
|
|
|
|
2016-12-07 17:28:07 +01:00
|
|
|
utf8 path[260];
|
|
|
|
String::Set(path, sizeof(path), basePath);
|
|
|
|
Path::Append(path, sizeof(path), fileName);
|
|
|
|
return std::string(path);
|
2016-12-07 16:49:29 +01:00
|
|
|
}
|
2016-12-07 17:28:07 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
static const char * DirectoryNamesRCT2[];
|
|
|
|
static const char * DirectoryNamesOpenRCT2[];
|
|
|
|
static const char * FileNames[];
|
|
|
|
};
|
|
|
|
|
2016-12-12 03:16:08 +01:00
|
|
|
IPlatformEnvironment * CreatePlatformEnvironment(DIRBASE_VALUES basePaths)
|
2016-12-07 17:28:07 +01:00
|
|
|
{
|
|
|
|
return new PlatformEnvironment(basePaths);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * PlatformEnvironment::DirectoryNamesRCT2[] =
|
|
|
|
{
|
2016-12-08 12:42:21 +01:00
|
|
|
"Data", // DATA
|
|
|
|
"Landscapes", // LANDSCAPE
|
|
|
|
nullptr, // LANGUAGE
|
|
|
|
nullptr, // LOG_CHAT
|
|
|
|
nullptr, // LOG_SERVER
|
|
|
|
nullptr, // NETWORK_KEY
|
|
|
|
"ObjData", // OBJECT
|
|
|
|
"Saved Games", // SAVE
|
|
|
|
"Scenarios", // SCENARIO
|
|
|
|
nullptr, // SCREENSHOT
|
|
|
|
nullptr, // SEQUENCE
|
|
|
|
nullptr, // SHADER
|
|
|
|
nullptr, // THEME
|
|
|
|
"Tracks", // TRACK
|
2016-12-07 17:28:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const char * PlatformEnvironment::DirectoryNamesOpenRCT2[] =
|
|
|
|
{
|
2016-12-08 12:42:21 +01:00
|
|
|
"data", // DATA
|
|
|
|
"landscape", // LANDSCAPE
|
|
|
|
"language", // LANGUAGE
|
|
|
|
"chatlogs", // LOG_CHAT
|
|
|
|
"serverlogs", // LOG_SERVER
|
|
|
|
"keys", // NETWORK_KEY
|
|
|
|
"object", // OBJECT
|
|
|
|
"save", // SAVE
|
|
|
|
"scenario", // SCENARIO
|
|
|
|
"screenshot", // SCREENSHOT
|
|
|
|
"sequence", // SEQUENCE
|
|
|
|
"shader", // SHADER
|
|
|
|
"themes", // THEME
|
|
|
|
"track", // TRACK
|
2016-12-07 17:28:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const char * PlatformEnvironment::FileNames[] =
|
|
|
|
{
|
2016-12-08 12:42:21 +01:00
|
|
|
"config.ini", // CONFIG
|
|
|
|
"hotkeys.dat", // CONFIG_KEYBOARD
|
|
|
|
"objects.idx", // CACHE_OBJECTS
|
|
|
|
"tracks.idx", // CACHE_TRACKS
|
|
|
|
"groups.json", // NETWORK_GROUPS
|
|
|
|
"servers.cfg", // NETWORK_SERVERS
|
|
|
|
"users.json", // NETWORK_USERS
|
|
|
|
"highscores.dat", // SCORES
|
2016-12-10 20:20:32 +01:00
|
|
|
"scores.dat", // SCORES (LEGACY)
|
|
|
|
"Saved Games" PATH_SEPARATOR "scores.dat", // SCORES (RCT2)
|
2016-12-07 16:49:29 +01:00
|
|
|
};
|