1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 07:43:01 +01:00

Move path related functions to Context.cpp

- rct2_init_directories
- get_file_path
This commit is contained in:
Ted John
2017-07-28 19:11:12 +01:00
parent 8bc4e52ae9
commit e6e503a853
9 changed files with 183 additions and 175 deletions

View File

@@ -18,6 +18,7 @@
#include <SDL.h>
#include <speex/speex_resampler.h>
#include <list>
#include <openrct2/Context.h>
#include <openrct2/core/Guard.hpp>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/Memory.hpp>
@@ -207,7 +208,7 @@ namespace OpenRCT2 { namespace Audio
IAudioSource * source = _musicSources[pathId];
if (source == nullptr)
{
const utf8 * path = get_file_path((sint32)pathId);
const utf8 * path = context_get_path_legacy((sint32)pathId);
source = AudioSource::CreateMemoryFromWAV(path, &_format);
if (source == nullptr)
{
@@ -238,7 +239,7 @@ namespace OpenRCT2 { namespace Audio
private:
void LoadAllSounds()
{
const utf8 * css1Path = get_file_path(PATH_ID_CSS1);
const utf8 * css1Path = context_get_path_legacy(PATH_ID_CSS1);
for (size_t i = 0; i < Util::CountOf(_css1Sources); i++)
{
auto source = AudioSource::CreateMemoryFromCSS1(css1Path, i, &_format);

View File

@@ -173,6 +173,81 @@ namespace OpenRCT2
window_save_prompt_open();
}
std::string GetPathLegacy(sint32 pathId) override
{
static const char * const LegacyFileNames[PATH_ID_END] =
{
nullptr,
nullptr,
"css1.dat",
"css2.dat",
"css4.dat",
"css5.dat",
"css6.dat",
"css7.dat",
"css8.dat",
"css9.dat",
"css11.dat",
"css12.dat",
"css13.dat",
"css14.dat",
"css15.dat",
"css3.dat",
"css17.dat",
"css18.dat",
"css19.dat",
"css20.dat",
"css21.dat",
"css22.dat",
nullptr,
"css23.dat",
"css24.dat",
"css25.dat",
"css26.dat",
"css27.dat",
"css28.dat",
"css29.dat",
"css30.dat",
"css31.dat",
"css32.dat",
"css33.dat",
"css34.dat",
"css35.dat",
"css36.dat",
"css37.dat",
"css38.dat",
"CUSTOM1.WAV",
"CUSTOM2.WAV",
"css39.dat",
"css40.dat",
"css41.dat",
nullptr,
"css42.dat",
"css43.dat",
"css44.dat",
"css45.dat",
"css46.dat",
"css50.dat"
};
std::string result;
if (pathId == PATH_ID_CSS50)
{
auto dataPath = _env->GetDirectoryPath(DIRBASE::RCT1, DIRID::DATA);
result = Path::Combine(dataPath, "css17.dat");
}
else if (pathId >= 0 && pathId < PATH_ID_END)
{
auto fileName = LegacyFileNames[pathId];
if (fileName != nullptr)
{
auto dataPath = _env->GetDirectoryPath(DIRBASE::RCT2, DIRID::DATA);
result = Path::Combine(dataPath, fileName);
}
}
return result;
}
bool Initialise() final override
{
if (_initialised)
@@ -218,11 +293,12 @@ namespace OpenRCT2
}
}
if (!rct2_init_directories())
auto rct2InstallPath = GetOrPromptRCT2Path();
if (rct2InstallPath.empty())
{
return false;
}
_env->SetBasePath(DIRBASE::RCT2, gRCT2AddressAppPath);
_env->SetBasePath(DIRBASE::RCT2, rct2InstallPath);
if (!gOpenRCT2Headless)
{
@@ -302,6 +378,32 @@ namespace OpenRCT2
}
private:
std::string GetOrPromptRCT2Path()
{
auto result = std::string();
if (String::IsNullOrEmpty(gCustomRCT2DataPath))
{
// Check install directory
if (gConfigGeneral.rct2_path == nullptr || !platform_original_game_data_exists(gConfigGeneral.rct2_path))
{
log_verbose("install directory does not exist or invalid directory selected, %s", gConfigGeneral.rct2_path);
if (!config_find_or_browse_install_directory())
{
utf8 path[MAX_PATH];
config_get_default_path(path, sizeof(path));
Console::Error::WriteLine("An RCT2 install directory must be specified! Please edit \"game_path\" in %s.\n", path);
return std::string();
}
}
result = std::string(gConfigGeneral.rct2_path);
}
else
{
result = std::string(gCustomRCT2DataPath);
}
return result;
}
bool LoadBaseGraphics()
{
if (!gfx_load_g1(_env))
@@ -867,6 +969,14 @@ extern "C"
GetContext()->Quit();
}
const utf8 * context_get_path_legacy(sint32 pathId)
{
static utf8 result[MAX_PATH];
auto path = GetContext()->GetPathLegacy(pathId);
String::Set(result, sizeof(result), path.c_str());
return result;
}
bool platform_open_common_file_dialog(utf8 * outFilename, file_dialog_desc * desc, size_t outSize)
{
try

View File

@@ -99,6 +99,11 @@ namespace OpenRCT2
virtual void Open(const std::string &path) abstract;
virtual void Finish() abstract;
virtual void Quit() abstract;
/**
* This is deprecated, use IPlatformEnvironment.
*/
virtual std::string GetPathLegacy(sint32 pathId) abstract;
};
IContext * CreateContext();
@@ -120,6 +125,65 @@ enum
GAME_UPDATE_MAX_THRESHOLD = GAME_UPDATE_TIME_MS * GAME_MAX_UPDATES,
};
/**
* Legacy get_file_path IDs.
* Remove when context_get_path_legacy is removed.
*/
enum
{
PATH_ID_G1,
PATH_ID_PLUGIN,
PATH_ID_CSS1,
PATH_ID_CSS2,
PATH_ID_CSS4,
PATH_ID_CSS5,
PATH_ID_CSS6,
PATH_ID_CSS7,
PATH_ID_CSS8,
PATH_ID_CSS9,
PATH_ID_CSS11,
PATH_ID_CSS12,
PATH_ID_CSS13,
PATH_ID_CSS14,
PATH_ID_CSS15,
PATH_ID_CSS3,
PATH_ID_CSS17,
PATH_ID_CSS18,
PATH_ID_CSS19,
PATH_ID_CSS20,
PATH_ID_CSS21,
PATH_ID_CSS22,
PATH_ID_SCORES,
PATH_ID_CSS23,
PATH_ID_CSS24,
PATH_ID_CSS25,
PATH_ID_CSS26,
PATH_ID_CSS27,
PATH_ID_CSS28,
PATH_ID_CSS29,
PATH_ID_CSS30,
PATH_ID_CSS31,
PATH_ID_CSS32,
PATH_ID_CSS33,
PATH_ID_CSS34,
PATH_ID_CSS35,
PATH_ID_CSS36,
PATH_ID_CSS37,
PATH_ID_CSS38,
PATH_ID_CUSTOM1,
PATH_ID_CUSTOM2,
PATH_ID_CSS39,
PATH_ID_CSS40,
PATH_ID_CSS41,
PATH_ID_SIXFLAGS_MAGICMOUNTAIN,
PATH_ID_CSS42,
PATH_ID_CSS43,
PATH_ID_CSS44,
PATH_ID_CSS45,
PATH_ID_CSS46,
PATH_ID_CSS50,
PATH_ID_END,
};
#ifdef __cplusplus
extern "C"
@@ -149,6 +213,7 @@ extern "C"
void context_input_handle_keyboard(bool isTitle);
bool context_read_bmp(void * * outPixels, uint32 * outWidth, uint32 * outHeight, const utf8 * path);
void context_quit();
const utf8 * context_get_path_legacy(sint32 pathId);
#ifdef __cplusplus
}
#endif

View File

@@ -143,7 +143,7 @@ void * Mixer_Play_Music(sint32 pathId, sint32 loop, sint32 streaming)
{
if (streaming)
{
const utf8 * path = get_file_path(pathId);
const utf8 * path = context_get_path_legacy(pathId);
IAudioContext * audioContext = GetContext()->GetAudioContext();
IAudioSource * source = audioContext->CreateStreamFromWAV(path);

View File

@@ -359,7 +359,7 @@ void audio_init_ride_sounds_and_info()
for (size_t m = 0; m < Util::CountOf(gRideMusicInfoList); m++)
{
rct_ride_music_info *rideMusicInfo = gRideMusicInfoList[m];
const utf8 *path = get_file_path(rideMusicInfo->path_id);
const utf8 * path = context_get_path_legacy(rideMusicInfo->path_id);
if (File::Exists(path))
{
try

View File

@@ -24,108 +24,8 @@
#include "platform/platform.h"
#include "util/util.h"
// rct2: 0x0097F67C
static const char * const RCT2FilePaths[PATH_ID_END] = {
"Data" PATH_SEPARATOR "g1.dat",
"Data" PATH_SEPARATOR "plugin.dat",
"Data" PATH_SEPARATOR "css1.dat",
"Data" PATH_SEPARATOR "css2.dat",
"Data" PATH_SEPARATOR "css4.dat",
"Data" PATH_SEPARATOR "css5.dat",
"Data" PATH_SEPARATOR "css6.dat",
"Data" PATH_SEPARATOR "css7.dat",
"Data" PATH_SEPARATOR "css8.dat",
"Data" PATH_SEPARATOR "css9.dat",
"Data" PATH_SEPARATOR "css11.dat",
"Data" PATH_SEPARATOR "css12.dat",
"Data" PATH_SEPARATOR "css13.dat",
"Data" PATH_SEPARATOR "css14.dat",
"Data" PATH_SEPARATOR "css15.dat",
"Data" PATH_SEPARATOR "css3.dat",
"Data" PATH_SEPARATOR "css17.dat",
"Data" PATH_SEPARATOR "css18.dat",
"Data" PATH_SEPARATOR "css19.dat",
"Data" PATH_SEPARATOR "css20.dat",
"Data" PATH_SEPARATOR "css21.dat",
"Data" PATH_SEPARATOR "css22.dat",
"Saved Games" PATH_SEPARATOR "scores.dat",
"Data" PATH_SEPARATOR "css23.dat",
"Data" PATH_SEPARATOR "css24.dat",
"Data" PATH_SEPARATOR "css25.dat",
"Data" PATH_SEPARATOR "css26.dat",
"Data" PATH_SEPARATOR "css27.dat",
"Data" PATH_SEPARATOR "css28.dat",
"Data" PATH_SEPARATOR "css29.dat",
"Data" PATH_SEPARATOR "css30.dat",
"Data" PATH_SEPARATOR "css31.dat",
"Data" PATH_SEPARATOR "css32.dat",
"Data" PATH_SEPARATOR "css33.dat",
"Data" PATH_SEPARATOR "css34.dat",
"Data" PATH_SEPARATOR "css35.dat",
"Data" PATH_SEPARATOR "css36.dat",
"Data" PATH_SEPARATOR "css37.dat",
"Data" PATH_SEPARATOR "css38.dat",
"Data" PATH_SEPARATOR "CUSTOM1.WAV",
"Data" PATH_SEPARATOR "CUSTOM2.WAV",
"Data" PATH_SEPARATOR "css39.dat",
"Data" PATH_SEPARATOR "css40.dat",
"Data" PATH_SEPARATOR "css41.dat",
"Scenarios" PATH_SEPARATOR "Six Flags Magic Mountain.SC6",
"Data" PATH_SEPARATOR "css42.dat",
"Data" PATH_SEPARATOR "css43.dat",
"Data" PATH_SEPARATOR "css44.dat",
"Data" PATH_SEPARATOR "css45.dat",
"Data" PATH_SEPARATOR "css46.dat",
"Data" PATH_SEPARATOR "css50.dat"
};
uint32 gCurrentDrawCount = 0;
uint8 gScreenFlags;
uint32 gScreenAge;
uint8 gSavePromptMode;
char gRCT2AddressAppPath[MAX_PATH];
/**
*
* rct2: 0x00683499
*/
sint32 rct2_init_directories()
{
if (str_is_null_or_empty(gCustomRCT2DataPath)) {
// check install directory
if (gConfigGeneral.rct2_path == NULL || !platform_original_game_data_exists(gConfigGeneral.rct2_path)) {
log_verbose("install directory does not exist or invalid directory selected, %s", gConfigGeneral.rct2_path);
if (!config_find_or_browse_install_directory()) {
utf8 path[MAX_PATH];
config_get_default_path(path, sizeof(path));
fprintf(stderr, "An RCT2 install directory must be specified! Please edit \"game_path\" in %s.\n", path);
return 0;
}
}
safe_strcpy(gRCT2AddressAppPath, gConfigGeneral.rct2_path, sizeof(gRCT2AddressAppPath));
} else {
safe_strcpy(gRCT2AddressAppPath, gCustomRCT2DataPath, sizeof(gRCT2AddressAppPath));
}
path_end_with_separator(gRCT2AddressAppPath, sizeof(gRCT2AddressAppPath));
return 1;
}
/**
*
* rct2: 0x00674E6C
*/
const utf8 *get_file_path(sint32 pathId)
{
static utf8 path[MAX_PATH];
if (pathId == PATH_ID_CSS50 && !str_is_null_or_empty(gConfigGeneral.rct1_path)) {
safe_strcpy(path, gConfigGeneral.rct1_path, sizeof(path));
safe_strcat_path(path, RCT2FilePaths[PATH_ID_CSS17], sizeof(path));
} else {
safe_strcpy(path, gRCT2AddressAppPath, sizeof(path));
safe_strcat_path(path, RCT2FilePaths[pathId], sizeof(path));
}
return path;
}

View File

@@ -88,76 +88,15 @@ enum {
#define SCREEN_FLAGS_EDITOR (SCREEN_FLAGS_SCENARIO_EDITOR | SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER)
enum {
PATH_ID_G1,
PATH_ID_PLUGIN,
PATH_ID_CSS1,
PATH_ID_CSS2,
PATH_ID_CSS4,
PATH_ID_CSS5,
PATH_ID_CSS6,
PATH_ID_CSS7,
PATH_ID_CSS8,
PATH_ID_CSS9,
PATH_ID_CSS11,
PATH_ID_CSS12,
PATH_ID_CSS13,
PATH_ID_CSS14,
PATH_ID_CSS15,
PATH_ID_CSS3,
PATH_ID_CSS17,
PATH_ID_CSS18,
PATH_ID_CSS19,
PATH_ID_CSS20,
PATH_ID_CSS21,
PATH_ID_CSS22,
PATH_ID_SCORES,
PATH_ID_CSS23,
PATH_ID_CSS24,
PATH_ID_CSS25,
PATH_ID_CSS26,
PATH_ID_CSS27,
PATH_ID_CSS28,
PATH_ID_CSS29,
PATH_ID_CSS30,
PATH_ID_CSS31,
PATH_ID_CSS32,
PATH_ID_CSS33,
PATH_ID_CSS34,
PATH_ID_CSS35,
PATH_ID_CSS36,
PATH_ID_CSS37,
PATH_ID_CSS38,
PATH_ID_CUSTOM1,
PATH_ID_CUSTOM2,
PATH_ID_CSS39,
PATH_ID_CSS40,
PATH_ID_CSS41,
PATH_ID_SIXFLAGS_MAGICMOUNTAIN,
PATH_ID_CSS42,
PATH_ID_CSS43,
PATH_ID_CSS44,
PATH_ID_CSS45,
PATH_ID_CSS46,
PATH_ID_CSS50,
PATH_ID_END
};
#ifdef __cplusplus
extern "C" {
#endif
extern uint32 gCurrentDrawCount;
extern uint8 gScreenFlags;
extern uint32 gScreenAge;
extern uint8 gSavePromptMode;
extern char gRCT2AddressAppPath[];
sint32 rct2_init_directories();
const char *get_file_path(sint32 pathId);
#ifdef __cplusplus
}
#endif

View File

@@ -595,13 +595,6 @@ private:
Console::Error::WriteLine("Unable to save highscores to '%s'", path.c_str());
}
}
static utf8 * GetRCT2Directory(utf8 * buffer, size_t bufferSize)
{
String::Set(buffer, bufferSize, gRCT2AddressAppPath);
Path::Append(buffer, bufferSize, "Scenarios");
return buffer;
}
};
static ScenarioRepository * _scenarioRepository;

View File

@@ -1426,7 +1426,7 @@ static void window_options_dropdown(rct_window *w, rct_widgetindex widgetIndex,
window_invalidate(w);
break;
case WIDX_TITLE_MUSIC_DROPDOWN:
if ((dropdownIndex == 1 || dropdownIndex == 3) && !platform_file_exists(get_file_path(PATH_ID_CSS50))) {
if ((dropdownIndex == 1 || dropdownIndex == 3) && !platform_file_exists(context_get_path_legacy(PATH_ID_CSS50))) {
window_error_open(STR_OPTIONS_MUSIC_ERR_CSS50_NOT_FOUND, STR_OPTIONS_MUSIC_ERR_CSS50_NOT_FOUND_HINT);
}
else {